astropy / specutils

An Astropy coordinated package for astronomical spectroscopy. Maintainers: @rosteen @keflavich @eteq
http://specutils.readthedocs.io/en/latest/
170 stars 128 forks source link

'SpectralGWCS' object has no attribute 'to_fits' #735

Open bmiszalski opened 4 years ago

bmiszalski commented 4 years ago

Loading an SDSS spectrum with the 'SDSS-I/II spSpec' format loader and then writing to fits using format "wcs1d-fits" writer raises error:

ValueError: Only Spectrum1D objects with valid WCS can be written as wcs1d: 'SpectralGWCS' object has no attribute 'to_fits'

Please see attached fits file and minimum example script. We include in the script the output of running the script and environment info. SpectralGWCSBug.tar.gz

aragilar commented 4 years ago

I think I tracked down the bug: the gwcs wcs is not API compatible with the astropy wcs, and wcs1d-fits assumes that spec.wcs is the astropy one. As the SDSS-I/II spSpec does not specify a wcs, it instead uses the gwcs wcs system, even though the astropy one would be sufficient. There are three possible fixes that I can see (ordered by how invasive they are):

  1. Set the wcs in the SDSS-I/II spSpec loader (thought this does not fix other cases where the gwcs wcs is defaulted to).
  2. Switch the default wcs in specutils to the astropy one (as based on reading the gwcs docs, you only need gwcs when you want a more general wcs system, which doesn't make sense as the default).
  3. Have gwcs ensure its API matches that of astropy (which may be more of a challenge in terms of maintenance, but to me seems to be required if we allow spec.wcs to be anything other than an astropy wcs object).

I can provide a PR with the first fix, but it seems like 2 or 3 are the real solution to fixing the bug.