summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/stwcs/updatewcs/__init__.py10
-rw-r--r--lib/stwcs/wcsutil/hstwcs.py26
2 files changed, 33 insertions, 3 deletions
diff --git a/lib/stwcs/updatewcs/__init__.py b/lib/stwcs/updatewcs/__init__.py
index d09f5a8..9509dbd 100644
--- a/lib/stwcs/updatewcs/__init__.py
+++ b/lib/stwcs/updatewcs/__init__.py
@@ -347,7 +347,7 @@ def newIDCTAB(fname):
def cleanWCS(fname):
# A new IDCTAB means all previously computed WCS's are invalid
- # We are deleting all of them except the original OPUS WCS.nvalidates all WCS's.
+ # We are deleting all of them except the original OPUS WCS.
f = fits.open(fname, mode='update')
keys = wcsutil.wcskeys(f[1].header)
# Remove the primary WCS from the list
@@ -355,9 +355,13 @@ def cleanWCS(fname):
keys.remove(' ')
except ValueError:
pass
- fext = list(range(len(f)))
+ fext = list(range(1, len(f)))
for key in keys:
- wcsutil.deleteWCS(fname, ext=fext, wcskey=key)
+ try:
+ wcsutil.deleteWCS(fname, ext=fext, wcskey=key)
+ except KeyError:
+ # Some extensions don't have the alternate (or any) WCS keywords
+ continue
def getCorrections(instrument):
"""
diff --git a/lib/stwcs/wcsutil/hstwcs.py b/lib/stwcs/wcsutil/hstwcs.py
index a71c33a..bda6561 100644
--- a/lib/stwcs/wcsutil/hstwcs.py
+++ b/lib/stwcs/wcsutil/hstwcs.py
@@ -142,6 +142,10 @@ class HSTWCS(WCS):
self.instrument = 'DEFAULT'
else:
self.instrument = instrument_name
+ # Set the correct reference frame
+ refframe = determine_refframe(hdr0)
+ ehdr['RADESYS'] = refframe
+
WCS.__init__(self, ehdr, fobj=phdu, minerr=self.minerr,
key=self.wcskey)
if self.instrument == 'DEFAULT':
@@ -960,3 +964,25 @@ adaptive=False, detect_divergence=False, quiet=False)
print('NAXIS : %d %d' % (self.naxis1, self.naxis2))
print('Plate Scale : %r' % self.pscale)
print('ORIENTAT : %r' % self.orientat)
+
+
+def determine_refframe(phdr):
+ """
+ Determine the reference frame in standard FITS WCS terms.
+
+ Parameters
+ ----------
+ phdr : `astropy.io.fits.Header`
+ Primary Header of an HST observation
+
+ In HST images the reference frame is recorded in the primary extension as REFFRAME.
+ Values are "GSC1" which means FK5 or ICRS (for GSC2 observations).
+ """
+ try:
+ refframe = phdr['REFFRAME']
+ except KeyError:
+ refframe = " "
+ if refframe == "GSC1":
+ refframe = "FK5"
+ return refframe
+