musevlt / mpdaf

MUSE Python Data Analysis Framework
BSD 3-Clause "New" or "Revised" License
15 stars 4 forks source link

Image Object error when computing (detected) source residuals #28

Closed jortiz12 closed 2 years ago

jortiz12 commented 2 years ago

Dear MPDAF community,

I´m tryng to replicate the "Image Object tutorial" with a 3D MUSE Datacube:

Once sources (6) are detected, when trying to run the following,

from mpdaf.obj import gauss_image, moffat_image

gfitim = gauss_image(wcs=source.wcs, gauss=gfit)
mfitim = moffat_image(wcs=source.wcs, moffat=mfit)
gresiduals = source-gfitim
mresiduals = source-mfitim

, I get an error related to the coordinate units. Both, source and the fits have the same WCS coordinate system, so I'm not sure why I´m getting this error.

---------------------------------------------------------------------------

UnitConversionError                       Traceback (most recent call last)

<ipython-input-46-f8c84ec021f0> in <module>()
      3 gfitim = gauss_image(wcs=source.wcs, gauss=gfit)
      4 mfitim = moffat_image(wcs=source.wcs, moffat=mfit)
----> 5 gresiduals = source-gfitim
      6 mresiduals = source-mfitim
      7 

9 frames

/usr/local/lib/python3.7/dist-packages/astropy/units/core.py in _apply_equivalencies(self, unit, other, equivalencies)
   1024 
   1025         raise UnitConversionError(
-> 1026             f"{unit_str} and {other_str} are not convertible")
   1027 
   1028     def _get_converter(self, other, equivalencies=[]):

UnitConversionError: '' (dimensionless) and 'erg / (Angstrom cm2 s)' (power density/spectral flux density wav) are not convertible

Thanks in advance. Jose

saimn commented 2 years ago

It's because your image has units ('erg / (Angstrom cm2 s)'), which is not the case for the tutorial image. So your should create a Gaussian/Moffat image with the same unit, i.e.:

gfitim = gauss_image(wcs=source.wcs, gauss=gfit, unit=source.unit)

Then the subtraction should work. Another workaround when dealing with unit issues is to do the operation with a Numpy array instead of the Mpdaf object. Here you could use source - gfitim.data (don't use this for object that have a variance array, which is not the case for the gfitim image).

jortiz12 commented 2 years ago

Much appreciated Simon.

Un Saludo

José A. Ortiz

On Tue, Jul 12, 2022 at 6:06 PM Simon Conseil @.***> wrote:

It's because your image has units ('erg / (Angstrom cm2 s)'), which is not the case for the tutorial image. So your should create a Gaussian/Moffat image with the same unit, i.e.:

gfitim = gauss_image(wcs=source.wcs, gauss=gfit, unit=source.unit)

Then the subtraction should work. Another workaround when dealing with unit issues is to do the operation with a Numpy array instead of the Mpdaf object. Here you could use source

  • gfitim.data (don't use this for object that have a variance array, which is not the case for the gfitim image).

— Reply to this email directly, view it on GitHub https://github.com/musevlt/mpdaf/issues/28#issuecomment-1181957473, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAUYA6TZFHUSIGTZX3QN7QLVTWJXPANCNFSM53IKJ4VA . You are receiving this because you authored the thread.Message ID: @.***>