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 translator cannot handle spectral_axis in 3D cube #60

Closed
pllim opened this issue Jan 20, 2022 · 4 comments · Fixed by #68
Closed

Spectrum1D translator cannot handle spectral_axis in 3D cube #60

pllim opened this issue Jan 20, 2022 · 4 comments · Fixed by #68
Labels
bug Something isn't working

Comments

@pllim
Copy link
Contributor

pllim commented Jan 20, 2022

I am not sure what is the proper fix. I don't want to spend time hacking it only to be told it is wrong. Please advise. Thanks!

import numpy as np
from astropy import units as u
from specutils import Spectrum1D

from glue_astronomy.translators.spectrum1d import Specutils1DHandler

sh = Specutils1DHandler()
spec = Spectrum1D(spectral_axis=np.arange(10) * u.pix, flux=np.ones((2, 2, 10)) * u.Jy)
obj = sh.to_data(spec)
.../glue_astronomy/translators/spectrum1d.py in to_data(self, obj)
    127         # Spectrum1D does it automatically on initialization.
    128         if len(obj.flux.shape) == 3:
--> 129             data = Data(coords=obj.wcs.swapaxes(-1, 0))
    130             data['flux'] = np.swapaxes(obj.flux, -1, 0)
    131             data.get_component('flux').units = str(obj.unit)

AttributeError: 'SpectralGWCS' object has no attribute 'swapaxes'

This is because when I pass spectral_axis into Spectrum1D, it creates a GWCS using https://github.com/astropy/specutils/blob/08de408d18d709a857b67e10ca2752d548eb3100/specutils/utils/wcs_utils.py#L185 and GWCS does not seem to understand swapaxes.

cc @astrofrog @rosteen

This blocks spacetelescope/jdaviz#1040

Also see spacetelescope/gwcs#397

@astrofrog
Copy link
Member

If only specutils did not mess with the axis order 😆

One solution might be to add a model to the GWCS to reorder the axes, though @nden will have to give advice on this as I'm not familiar enough with GWCS.

@nden
Copy link

nden commented Jan 27, 2022

Here's the relevant discussion in gwcs: spacetelescope/gwcs#269
IIRC I ran into difficulties due to the way the HighLevelWCSAPI was defined in astropy but I don't remember the details.

@rosteen
Copy link
Contributor

rosteen commented Jan 27, 2022

@astrofrog I have a draft PR (#61) open to fix this but it needs more work. I'm going to tag you in some questions there in a moment.

@pllim
Copy link
Contributor Author

pllim commented Jan 27, 2022

Also might be relevant:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
5 participants