dullemond / radmc3d-2.0

66 stars 36 forks source link

Given a convolved image, writeFits does not save values in the units of Jy/beam #19

Open shengjunlin opened 2 years ago

shengjunlin commented 2 years ago

In lines 373 ~ 376 at radmc3dPy/image.py, radmc3dImage.writeFits() has a wrong unit conversion for images which has been convolved by radmc3dImage.imConv().

        if len(self.fwhm) == 0:
            # Conversion from erg/s/cm/cm/ster to Jy/pixel
            conv = self.sizepix_x * self.sizepix_y / (dpc * nc.pc)**2. * 1e23
        else:
            # If the image has already been convolved with a gaussian psf then self.image has
            # already the unit of erg/s/cm/cm/beam, so we need to multiply it by 10^23 to get
            # to Jy/beam
            conv = 1e23

In the convolved radmc3dImage object returned by imConv(), its self.image still has the unit of erg/s/cm/cm/ster. In fact, this design is consistent with the behavior of image.plotImage(bunit='jy/beam'), which correctly first convert the values in self.image from erg/s/cm/cm/ster to Jy/pixel, and then convert it to Jy/beam in lines 1466 ~1487. This bug in radmc3dImage.writeFits() could be fixed by changing things to

        if len(self.fwhm) == 0:
            # Conversion from erg/s/cm/cm/ster to Jy/pixel
            conv = self.sizepix_x * self.sizepix_y / (dpc * nc.pc)**2. * 1e23
        else:
            # Conversion from erg/s/cm/cm/ster to Jy/beam
            beam_area_sqasec = self.fwhm[0] * self.fwhm[1] * np.pi / 4. / np.log(2.0)
            beam_area_sr = beam_area_sqasec * (np.pi/180./3600.)**2
            conv = beam_area_sr * 1e23
dullemond commented 2 years ago

Dear Sheng-Jun Lin,

thanks for pointing this out. This is a Python package that I did not write, so it is hard for me to judge what the author meant with this. But it does seem you are right. I'll keep this issue open and see if someone else (who uses radmc3dPy with the convolution) confirms your suggestion. Then I'll build it in the way you suggest.

Best wishes, Kees

shengjunlin commented 2 years ago

Dear Kees,

Thank you for your reply!

Best wishes, Sheng-Jun

j6626 commented 1 year ago

Incidentally, I agree with Sheng-Jun Lin's proposed fix.