Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compatibility astropy #35

Open
nfbouche opened this issue Feb 22, 2024 · 1 comment
Open

compatibility astropy #35

nfbouche opened this issue Feb 22, 2024 · 1 comment

Comments

@nfbouche
Copy link

for unit=u.Unit('nanomaggy'), the line

fits.py:170 dsthdr['BUNIT'] = (unit.to_string('fits'), 'data unit type')

failes inside a try/except.

fix is replacing line fits.py:171 by
except:
instead of
except u.format.fits.UnitScaleError:

@nfbouche
Copy link
Author

File ~/.local/lib/python3.9/site-packages/mpdaf/obj/data.py:412, in DataArray.getstate(self)
407 # Try to determine if the object has some wcs/wave information but not
408 # available in the FITS header. In this case we add the wcs info in the
409 # data header.
410 if ((self._has_wcs and self.wcs is not None) or
411 (self._has_wave and self.wave is not None)):
--> 412 hdu = self.get_data_hdu(convert_float32=False)
413 state['data_header'] = hdu.header
415 return state

File ~/.local/lib/python3.9/site-packages/mpdaf/obj/data.py:1070, in DataArray.get_data_hdu(self, name, savemask, convert_float32)
1067 else:
1068 data = data.data
-> 1070 hdr = copy_header(self.data_header, self.get_wcs_header(),
1071 exclude=('CD*', 'PC*', 'CDELT*', 'CRPIX*', 'CRVAL*',
1072 'CSYER*', 'CTYPE*', 'CUNIT*', 'NAXIS*',
1073 'RADESYS', 'LATPOLE', 'LONPOLE'),
1074 unit=self.unit)
1075 return fits.ImageHDU(name=name, data=data, header=hdr)

File ~/.local/lib/python3.9/site-packages/mpdaf/tools/fits.py:170, in copy_header(srchdr, dsthdr, exclude, unit)
168 if unit is not None:
169 try:
--> 170 dsthdr['BUNIT'] = (unit.to_string('fits'), 'data unit type')
171 except u.format.fits.UnitScaleError:
172 dsthdr['BUNIT'] = (fix_unit_write(str(unit)), 'data unit type')

File ~/Python/anaconda3/envs/musex/lib/python3.9/site-packages/astropy/units/core.py:791, in UnitBase.to_string(self, format, **kwargs)
749 r"""Output the unit in the given format as a string.
750
751 Parameters
(...)
788 s
789 """
790 f = unit_format.get_format(format)
--> 791 return f.to_string(self, **kwargs)

File ~/Python/anaconda3/envs/musex/lib/python3.9/site-packages/astropy/units/format/fits.py:111, in Fits.to_string(cls, unit, fraction)
108 @classmethod
109 def to_string(cls, unit, fraction=False):
110 # Remove units that aren't known to the format
--> 111 unit = utils.decompose_to_known_units(unit, cls._get_unit_name)
113 parts = []
115 base = np.log10(unit.scale)

File ~/Python/anaconda3/envs/musex/lib/python3.9/site-packages/astropy/units/format/utils.py:109, in decompose_to_known_units(unit, func)
107 except ValueError:
108 if isinstance(unit, core.Unit):
--> 109 return decompose_to_known_units(unit._represents, func)
110 raise
111 return unit

File ~/Python/anaconda3/envs/musex/lib/python3.9/site-packages/astropy/units/format/utils.py:102, in decompose_to_known_units(unit, func)
100 new_unit = core.Unit(unit.scale)
101 for base, power in zip(unit.bases, unit.powers):
--> 102 new_unit = new_unit * decompose_to_known_units(base, func) ** power
103 return new_unit
104 elif isinstance(unit, core.NamedUnit):

File ~/Python/anaconda3/envs/musex/lib/python3.9/site-packages/astropy/units/format/utils.py:106, in decompose_to_known_units(unit, func)
104 elif isinstance(unit, core.NamedUnit):
105 try:
--> 106 func(unit)
107 except ValueError:
108 if isinstance(unit, core.Unit):

File ~/Python/anaconda3/envs/musex/lib/python3.9/site-packages/astropy/units/format/fits.py:105, in Fits._get_unit_name(cls, unit)
102 @classmethod
103 def _get_unit_name(cls, unit):
104 name = super()._get_unit_name(unit)
--> 105 cls._validate_unit(name)
106 return name

File ~/Python/anaconda3/envs/musex/lib/python3.9/site-packages/astropy/units/format/fits.py:80, in Fits._validate_unit(cls, unit, detailed_exception)
78 if unit not in cls._units:
79 if detailed_exception:
---> 80 raise ValueError(
81 f"Unit '{unit}' not supported by the FITS standard. "
82 + utils.did_you_mean_units(
83 unit,
84 cls._units,
85 cls._deprecated_units,
86 cls._to_decomposed_alternative,
87 ),
88 )
89 else:
90 raise ValueError()

ValueError: Unit 'mgy' not supported by the FITS standard. Did you mean MG, Mg, mG or mg?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant