summaryrefslogtreecommitdiff
path: root/lib/stwcs/wcsutil/headerlet.py
diff options
context:
space:
mode:
authorhack <hack@stsci.edu>2012-01-23 15:02:13 -0500
committerhack <hack@stsci.edu>2012-01-23 15:02:13 -0500
commitd93af18d08a2becf9a9407987b1d7b6b3595ddd5 (patch)
treecb0db59cd161d5138d9f6e78fb706adf902839c6 /lib/stwcs/wcsutil/headerlet.py
parente53ec440b68523bce0d66d69d777f3814e067234 (diff)
downloadstwcs_hcf-d93af18d08a2becf9a9407987b1d7b6b3595ddd5.tar.gz
This update fixes problems with applying a headerlet to an image which has not yet been updated with updatewcs. The problems arose from 'DISTNAME' not being present in the header of the image to be updated. The changes were tested using the 'apply_headerlet' user interface (through TEAL) on a WFC3/UVIS image prior to running 'updatewcs.updatewcs()' on it.
git-svn-id: http://svn.stsci.edu/svn/ssb/stsci_python/stsci_python/trunk/stwcs@14461 fe389314-cf27-0410-b35b-8c050e845b92
Diffstat (limited to 'lib/stwcs/wcsutil/headerlet.py')
-rw-r--r--lib/stwcs/wcsutil/headerlet.py48
1 files changed, 44 insertions, 4 deletions
diff --git a/lib/stwcs/wcsutil/headerlet.py b/lib/stwcs/wcsutil/headerlet.py
index 5e53eed..2138406 100644
--- a/lib/stwcs/wcsutil/headerlet.py
+++ b/lib/stwcs/wcsutil/headerlet.py
@@ -1878,13 +1878,15 @@ class Headerlet(pyfits.HDUList):
# Check to see whether the distortion model in the destination
# matches the distortion model in the headerlet being applied
dist_models_equal = True
- if self[0].header['DISTNAME'] != fobj[0].header['DISTNAME']:
+ if not self.verify_model(fobj):
+ if 'distname' not in fobj[0].header:
+ dname = self.build_distname(fobj)
if self.logging:
message = """
Distortion model in headerlet not the same as destination model
Headerlet model : %s
Destination model: %s
- """ % (self[0].header['DISTNAME'], fobj[0].header['DISTNAME'])
+ """ % (self[0].header['DISTNAME'], dname)
logger.critical(message)
dist_models_equal = False
@@ -2088,8 +2090,11 @@ class Headerlet(pyfits.HDUList):
distname = fobj[0].header['DISTNAME']
else:
# perhaps call 'updatewcs.utils.construct_distname()' instead
- distname = 'UNKNOWN'
-
+ try:
+ distname = self.build_distname(fobj)
+ except:
+ distname = 'UNKNOWN'
+
if distname == 'UNKNOWN' or self.distname != distname:
message = """
Observation %s cannot be updated with headerlet %s
@@ -2316,6 +2321,31 @@ class Headerlet(pyfits.HDUList):
logger.debug("verify_hdrname() returned %s"%unique)
return unique
+ def verify_model(self, dest):
+ """
+ Verifies that the headerlet can be applied to the observation
+
+ Determines whether or not the file specifies the same distortion
+ model/reference files.
+ """
+ destim_opened = False
+ if not isinstance(dest, pyfits.HDUList):
+ destim = pyfits.open(dest)
+ destim_opened = True
+ else:
+ destim = dest
+
+ if 'distname' in destim[0].header:
+ dname = destim[0].header['DISTNAME']
+ else:
+ dname = self.build_distname(dest)
+ if destim_opened:
+ destim.close()
+ if dname == self[0].header['DISTNAME']:
+ return True
+ else:
+ return False
+
def verify_dest(self, dest):
"""
verifies that the headerlet can be applied to the observation
@@ -2339,6 +2369,16 @@ class Headerlet(pyfits.HDUList):
logger.debug("verify_destim() returned False")
return False
+ def build_distname(self, dest):
+ """
+ Builds the DISTNAME for dest based on reference file names.
+ """
+ sipname = utils.build_sipname(destim)
+ npolname = utils.build_npolname(destim)
+ d2imname = utils.build_d2imname(destim)
+ dname = utils.build_distname(sipname,npolname,d2imname)
+ return dname
+
def tofile(self, fname, destim=None, hdrname=None, clobber=False):
"""
Write this headerlet to a file