specutils icon indicating copy to clipboard operation
specutils copied to clipboard

Preserving units in FITS-WCS

Open astrofrog opened this issue 5 months ago • 4 comments

I just wanted to raise awareness of a new feature I've added to astropy.wcs which is to ensure that units in WCSes get preserved rather than converted to meters or Hz:

https://docs.astropy.org/en/latest/whatsnew/7.2.html#preserving-units-in-fits-wcs

This seems like it would be useful in specutils. It would be good to check:

  • That specutils works as expected if one passes it a FITS WCS object with preserve_units=True to make sure specutils isn't assuming Hz or meters anywhere (if you always only use APE-14 API I doubt there will be any issues)
  • Whether there are any places (e.g. loaders) where it would make sense for specutils to switch to using this by default once it's available in stable versions of astropy

astrofrog avatar Jul 25 '25 13:07 astrofrog

@astrofrog I just started testing with this (sorry for the delay!), and ran into the fact that even when using this, using wcs.spectral always results in meters. We could work around that (see https://github.com/astropy/specutils/pull/1273), but perhaps in the case that preserve_units was set to True the conversion in wcs.spectral shouldn't happen.

rosteen avatar Sep 24 '25 20:09 rosteen

Good catch, I agree that wcs.spectral, wcs.celestial, and more generally wcs.sub should pass the preserve_units option to any new instance.

astrofrog avatar Sep 24 '25 21:09 astrofrog

@rosteen - would you be able to try out https://github.com/astropy/astropy/pull/18655 to see if this fixes the issues you were seeing?

astrofrog avatar Sep 30 '25 11:09 astrofrog

@rosteen - would you be able to try out astropy/astropy#18655 to see if this fixes the issues you were seeing?

Will do, thanks!

rosteen avatar Sep 30 '25 13:09 rosteen