summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--updatewcs/__init__.py28
-rw-r--r--updatewcs/apply_corrections.py24
2 files changed, 27 insertions, 25 deletions
diff --git a/updatewcs/__init__.py b/updatewcs/__init__.py
index c973cb1..8992b69 100644
--- a/updatewcs/__init__.py
+++ b/updatewcs/__init__.py
@@ -78,6 +78,11 @@ def updatewcs(input, vacorr=True, tddcorr=True, dgeocorr=True, d2imcorr=True,
acorr = apply_corrections.setCorrections(f, vacorr=vacorr, \
tddcorr=tddcorr,dgeocorr=dgeocorr, d2imcorr=d2imcorr)
+ if 'MakeWCS' in acorr and newIDCTAB(fname):
+ print "New IDCTAB file detected. This invalidates all WCS's."
+ print "Deleting all previous WCS's"
+ cleanWCS(fname)
+
#restore the original WCS keywords
#wcsutil.restoreWCS(f, ext=[], wcskey='O', clobber=True)
makecorr(f, acorr, wkey=wcskey, wname=wcsname, clobber=False)
@@ -287,7 +292,28 @@ def checkFiles(input):
return newfiles
-
+def newIDCTAB(fname):
+ #When this is called we know there's a kw IDCTAB in the header
+ idctab = fileutil.osfn(pyfits.getval(fname, 'IDCTAB'))
+ try:
+ #check for the presence of IDCTAB in the first extension
+ oldidctab = fileutil.osfn(pyfits.getval(fname, 'IDCTAB', ext=1))
+ except KeyError:
+ return False
+ if idctab == oldidctab:
+ return False
+ else:
+ return True
+
+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.
+ keys = altwcs.wcskeys(pyfits.getheader(fname, ext=1))
+ f = pyfits.open(fname, mode='update')
+ fext = range(len(f))
+ for key in keys:
+ altwcs.deleteWCS(fname, ext=fext,wcskey=key)
+
def getCorrections(instrument):
"""
Print corrections available for an instrument
diff --git a/updatewcs/apply_corrections.py b/updatewcs/apply_corrections.py
index 9d3573e..0c49923 100644
--- a/updatewcs/apply_corrections.py
+++ b/updatewcs/apply_corrections.py
@@ -48,17 +48,6 @@ def setCorrections(fname, vacorr=True, tddcorr=True, dgeocorr=True, d2imcorr=Tru
if 'TDDCorr' in acorr: acorr.remove('TDDCorr')
if 'MakeWCS' in acorr: acorr.remove('MakeWCS')
if 'CompSIP' in acorr: acorr.remove('CompSIP')
-
- # A new IDCTAB means all previously computed WCS's are invalid
- # We are deleting all of them except the original OPUS WCS.
- if 'MakeWCS' in acorr and newIDCTAB(fname):
- print "New IDCTAB file detected. This invalidates all WCS's."
- print "Deleting all previous WCS's"
- keys = altwcs.wcskeys(pyfits.getheader(fname, ext=1))
- if 'O' in keys:
- keys.remove('O')
- for key in keys:
- altwcs.deleteWCS(fname, key)
if 'VACorr' in acorr and vacorr==False: acorr.remove('VACorr')
if 'TDDCorr' in acorr:
@@ -224,16 +213,3 @@ def applyD2ImCorr(fname, d2imcorr):
applyD2IMCorr = False
return applyD2IMCorr
-def newIDCTAB(fname):
- #When this is called we know there's a kw IDCTAB in the header
- idctab = fileutil.osfn(pyfits.getval(fname, 'IDCTAB'))
- try:
- #check for the presence of IDCTAB in the first extension
- oldidctab = fileutil.osfn(pyfits.getval(fname, 'IDCTAB', ext=1))
- except KeyError:
- return False
- if idctab == oldidctab:
- return False
- else:
- return True
- \ No newline at end of file