From eeb95498b61fae9ae48a8d18abe668b1021ee26c Mon Sep 17 00:00:00 2001 From: dencheva Date: Thu, 23 Sep 2010 20:46:28 +0000 Subject: Moved deleteing of WCS's when a new idctab is detected to updatewcs git-svn-id: http://svn.stsci.edu/svn/ssb/stsci_python/stsci_python/trunk/stwcs@10384 fe389314-cf27-0410-b35b-8c050e845b92 --- updatewcs/__init__.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'updatewcs/__init__.py') 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 -- cgit