specutils icon indicating copy to clipboard operation
specutils copied to clipboard

Spectrum1D.with_spectral_unit does not change spectral unit and overwrites WCS

Open kecnry opened this issue 4 years ago • 2 comments

Spectrum1D.with_spectral_unit seems create a copy of the Spectrum1D object with meta-data storing the original unit and with a newly created WCS from the original spectral_axis (so would overwrite any original WCS if it had been provided), but does not actually change units.

import specutils
import astropy.units as u

sp = specutils.Spectrum1D(spectral_axis=[0,1,2,3]*u.cm, flux=[0.1, 0.2, 0.3, 0.4]*u.erg/u.AA/u.cm**2/u.s)

sp.spectral_axis.unit
# Angstroms

sp.wcs.unit
# Angstroms

sp_wsu = sp.with_spectral_unit(u.um)

sp_wsu.spectral_axis.unit
# Angstroms

sp_wsu.wcs.unit
# Angstroms

kecnry avatar Oct 20 '21 18:10 kecnry

See #676 for earlier discussion about this.

rosteen avatar Oct 21 '21 14:10 rosteen

That sure looks like a bug to me... sp_wsu = sp.with_spectral_unit(u.um) should definitely give a spectrum with um units.

@rosteen pointed out out-of-band that this may be a relic of the switch to the APE14 API.

One other thing, though, part of the confusion might be this method's name: with_spectral_unit could mean "spectral axis units" or it could mean "spectral units as in the units one traditionally uses for flux" (also intertwines a bit with #890). So it might be that fixing this provides an excuse to rename to with_spectral_axis_unit? I.e. rename this method to with_spectral_axis_unit, but leave a with_spectral_unit which calls with_spectral_axis_unit but yields a DeprecationWarning?

eteq avatar Oct 21 '21 15:10 eteq

Closed by #1119

rosteen avatar Feb 01 '24 21:02 rosteen