Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes issue #35 - FITS CUNIT 'M/S' header. #36

Merged
merged 4 commits into from
May 25, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions Tigger/Coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down