diff options
author | dencheva <dencheva@stsci.edu> | 2010-09-23 16:46:28 -0400 |
---|---|---|
committer | dencheva <dencheva@stsci.edu> | 2010-09-23 16:46:28 -0400 |
commit | eeb95498b61fae9ae48a8d18abe668b1021ee26c (patch) | |
tree | 4066622383676cf36b2f5c84e3e9f03cc4a80240 | |
parent | 41c0f740305f584bb8d75c978450a08948a98f12 (diff) | |
download | stwcs_hcf-eeb95498b61fae9ae48a8d18abe668b1021ee26c.tar.gz |
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
-rw-r--r-- | updatewcs/__init__.py | 28 | ||||
-rw-r--r-- | updatewcs/apply_corrections.py | 24 |
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 |