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

Spectrum1D.with_spectral_unit does not change spectral unit and overwrites WCS #889

Closed
kecnry opened this issue Oct 20, 2021 · 3 comments
Closed

Comments

@kecnry
Copy link
Member

kecnry commented Oct 20, 2021

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
@rosteen
Copy link
Contributor

rosteen commented Oct 21, 2021

See #676 for earlier discussion about this.

@eteq
Copy link
Member

eteq commented Oct 21, 2021

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?

@rosteen
Copy link
Contributor

rosteen commented Feb 1, 2024

Closed by #1119

@rosteen rosteen closed this as completed Feb 1, 2024
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

3 participants