Skip to content

Commit

Permalink
Extend list of hacks for reading non-standard complied 1d WCS fits files
Browse files Browse the repository at this point in the history
In the current code, there is a hack to allow "LINEAR" as a spectral
axis. That's clearly not complient with the FITS WCS standard as defined in
https://www.aanda.org/articles/aa/full/2006/05/aa3818-05/aa3818-05.html
and might just be motivated by the GMOS spectrum currently used as
example for this loader.
This code change makes ths list of keywords that will be treated as
spectral extensible and adds "Wavelength" (which is much closer to
"WAVE" as required in the standard than "LINEAR").
  • Loading branch information
hamogu committed Nov 28, 2018
1 parent 1cd8841 commit a5b6730
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions specutils/wcs/adapters/fitswcs_adapter.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import warnings
import astropy.units as u
from astropy.wcs import (WCS, WCSSUB_CELESTIAL, WCSSUB_CUBEFACE,
WCSSUB_LATITUDE, WCSSUB_LONGITUDE, WCSSUB_SPECTRAL,
WCSSUB_STOKES, InvalidSubimageSpecificationError)

from astropy.utils.exceptions import AstropyUserWarning
# Use this once in specutils
from ...utils.wcs_utils import (convert_spectral_axis,
determine_ctype_from_vconv)
Expand All @@ -18,6 +20,8 @@ class FITSWCSAdapter(WCSAdapter):
wrapped_class = WCS
axes = None

substitute_spec_axis_names = ['LINEAR', 'Wavelength']

def __init__(self, wcs):
super(FITSWCSAdapter, self).__init__(wcs)
self._spec_axis = None
Expand Down Expand Up @@ -71,17 +75,18 @@ def spec_axis(self):
"""
self._spec_axis = self.wcs.wcs.spec

if self._spec_axis < 0:
try:
idx = list(self.wcs.wcs.ctype).index('LINEAR')
except ValueError:
if (self._spec_axis < 0) and (self._wcs.wcs.spec) < 0:
ctypelist = list(self.wcs.wcs.ctype)
for n in self.substitute_spec_axis_names:
if n in ctypelist:
self._spec_axis = ctypelist.index(n)
warnings.warn("WCS has no standard complient spectral axis, 'ctypes' might not be correct. I'm guessing that axis {} labelled '{}' might be spectral and proceed with that.".format(self._spec_axis, n), AstropyUserWarning)
break
else:
raise InvalidSubimageSpecificationError(
"Cannot find a spectral axis in the provided WCS."
"Are your 'ctype's correct?")

if self._wcs.wcs.spec < 0:
self._spec_axis = idx

return self._spec_axis

@property
Expand Down

0 comments on commit a5b6730

Please sign in to comment.