From 40952e7c118511b6485ea1622fa401d51fecd122 Mon Sep 17 00:00:00 2001 From: Raz Date: Tue, 10 May 2022 14:22:19 +0100 Subject: [PATCH] Fixes issue #35 - FITS CUNIT 'M/S' header. --- Tigger/Coordinates.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/Tigger/Coordinates.py b/Tigger/Coordinates.py index 6f35dc1..a75dcc4 100644 --- a/Tigger/Coordinates.py +++ b/Tigger/Coordinates.py @@ -24,6 +24,8 @@ # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # from __future__ import print_function, division, absolute_import + +from astropy.wcs.wcs import InvalidTransformError import Tigger from Tigger import startup_dprint @@ -348,12 +350,28 @@ def __init__(self, header): # pix2world then fails expecting N x 4. Using astropy wcs methods and not sub-classing FITSWCSpix # avoids the error and a reliance on naxis. - # get astropy WCS - self.wcs = WCS(header) - # get number of axis naxis = header['NAXIS'] + # get astropy WCS + try: + self.wcs = WCS(header) + except InvalidTransformError as e: + if 'CUNIT' in str(e): + # check header for incorrect CUNIT entry 'M/S' + for iaxis in range(naxis): + name = header.get("CUNIT%d" % (iaxis + 1), '').upper() + if name.startswith("M/S"): + # correct the header + header.set("CUNIT%d" % (iaxis + 1), 'm/s') + # re-load WCS + try: + self.wcs = WCS(header) + except InvalidTransformError as e: + raise RuntimeError(f"Error WCS header {e}") + else: + raise RuntimeError(f"Error WCS header {e}") + # get ra and dec axis self.ra_axis = self.dec_axis = None for iaxis in range(naxis):