specutils icon indicating copy to clipboard operation
specutils copied to clipboard

Bug in wcs1d-fits reader and flux_unit

Open kelle opened this issue 6 months ago • 3 comments

I'm pretty sure there's a bug in the wcs1d-fits reader. I have some spectra that have BUNIT = erg/A/s/cm2. This is not able to be parsed into erg / (Angstrom s cm2), which I am "ok" with but the bigger issue is that if I give flux_unit = u.Unit("erg / (angstrom s cm2)") , I get an "unable to convert" error. The expected behavior is for flux_unit to IGNORE BUNIT, not try to convert to it. I'll upload an example file later.

kelle avatar Jun 28 '25 01:06 kelle

Is it getting confused by angstrom versus Angstrom?

weaverba137 avatar Jun 28 '25 18:06 weaverba137

No, it's the A. It doesn't assume A = angstrom

kelle avatar Jul 01 '25 13:07 kelle

The expected behavior is for flux_unit to IGNORE BUNIT, not try to convert to it.

Converting from BUNIT to the input flux_unit is the documented intended behavior, based on the docstring:

flux_unit: str or `~astropy.Unit`, optional

        Units of the flux for this spectrum. If not given (or None), the unit will be inferred
        from the BUNIT keyword in the header. Note that this unit will attempt to convert
        from BUNIT if BUNIT is present

and from the top level of the wcs1d-fits loader docstring:

The flux unit of the spectrum is
determined by the 'BUNIT' keyword of the HDU (if present), while the
spectral axis unit is set by the WCS's 'CUNIT'.

rosteen avatar Jul 03 '25 18:07 rosteen