diff --git a/specutils/wcs/adapters/fitswcs_adapter.py b/specutils/wcs/adapters/fitswcs_adapter.py index 300e4044a..af4ce5b5d 100644 --- a/specutils/wcs/adapters/fitswcs_adapter.py +++ b/specutils/wcs/adapters/fitswcs_adapter.py @@ -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) @@ -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 @@ -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