diff --git a/astropy/wcs/wcsapi/fitswcs.py b/astropy/wcs/wcsapi/fitswcs.py index 58705d1865ac..47ef8f7b3e10 100644 --- a/astropy/wcs/wcsapi/fitswcs.py +++ b/astropy/wcs/wcsapi/fitswcs.py @@ -401,7 +401,12 @@ def _get_components_and_classes(self): kwargs = {} kwargs['frame'] = celestial_frame - kwargs['unit'] = u.deg + # Very occasionally (TAB) wcs does not convert the units + # We call set here to make sure any unit conversion which is + # going to happen has been done. + self.wcs.set() + kwargs['unit'] = (u.Unit(self.wcs.cunit[self.wcs.lng]), + u.Unit(self.wcs.cunit[self.wcs.lat])) classes['celestial'] = (SkyCoord, (), kwargs) @@ -431,7 +436,7 @@ def _get_components_and_classes(self): earth_location = EarthLocation(*self.wcs.obsgeo[:3], unit=u.m) # Get the time scale from TIMESYS or fall back to 'utc' - tscale = self.wcs.timesys or 'utc' + tscale = self.wcs.timesys.lower() or 'utc' if np.isnan(self.wcs.mjdavg): obstime = Time(self.wcs.mjdobs, format='mjd', scale=tscale, @@ -630,8 +635,8 @@ def value_from_spectralcoord(spectralcoord): # Initialize delta reference_time_delta = None - # Extract time scale - scale = self.wcs.ctype[i].lower() + # Extract time scale, and remove any algorithm code + scale = self.wcs.ctype[i].split("-")[0].lower() if scale == 'time': if self.wcs.timesys: