summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordencheva <dencheva@stsci.edu>2009-04-28 17:07:43 -0400
committerdencheva <dencheva@stsci.edu>2009-04-28 17:07:43 -0400
commit3b873f14d1ec709fe6df3ab053ecff3f363c7510 (patch)
tree4627d70f41ade03c3eafbe6a580be9847080f78e
parent9b7a13403e5ba2039a0f66682ad609d9fb2c685b (diff)
downloadstwcs_hcf-3b873f14d1ec709fe6df3ab053ecff3f363c7510.tar.gz
These changes allow the HSTWCS object ot be used for transformations and when updating the headers
git-svn-id: http://svn.stsci.edu/svn/ssb/stsci_python/development/trunk/updatewcs@7974 fe389314-cf27-0410-b35b-8c050e845b92
-rw-r--r--hstwcs/__init__.py7
-rw-r--r--hstwcs/apply_corrections.py2
-rw-r--r--hstwcs/det2im.py19
-rw-r--r--wcsutil/__init__.py9
4 files changed, 28 insertions, 9 deletions
diff --git a/hstwcs/__init__.py b/hstwcs/__init__.py
index 7de38fe..bf47cdc 100644
--- a/hstwcs/__init__.py
+++ b/hstwcs/__init__.py
@@ -81,11 +81,8 @@ def makecorr(fname, allowed_corr):
utils.write_archive(f[nrefext].header)
if 'DET2IMCorr' in allowed_corr:
- kw2update = det2im.DET2IMCorr.updateWCS(f)
- for kw in kw2update:
- #these kw are written to the primary header
- f[0].header.update(kw, kw2update[kw])
-
+ det2im.DET2IMCorr.updateWCS(f)
+
for i in range(len(f))[1:]:
# Perhaps all ext headers should be corrected (to be consistent)
extn = f[i]
diff --git a/hstwcs/apply_corrections.py b/hstwcs/apply_corrections.py
index c54725c..88d997e 100644
--- a/hstwcs/apply_corrections.py
+++ b/hstwcs/apply_corrections.py
@@ -159,7 +159,7 @@ def applyD2ImCorr(fname, d2imcorr):
return applyD2IMCorr
try:
# get DGEOEXT kw from first extension header
- fd2imext = pyfits.getval(fname, 'D2IMEXT', ext=0)
+ fd2imext = pyfits.getval(fname, 'D2IMEXT', ext=1)
fd2imext = fileutil.osfn(fd2imext)
if fd2imext and fileutil.findFile(fd2imext):
if fd2im0 != fd2imext:
diff --git a/hstwcs/det2im.py b/hstwcs/det2im.py
index 164eff6..90c9f28 100644
--- a/hstwcs/det2im.py
+++ b/hstwcs/det2im.py
@@ -20,7 +20,7 @@ class DET2IMCorr(object):
else:
new_kw = {'D2IMEXT': d2imfile, 'AXISCORR': axiscorr, 'D2IMERR': d2imerr}
cls.applyDet2ImCorr(fobj, axiscorr)
- return new_kw
+ cls.updatehdr(fobj, new_kw)
updateWCS = classmethod(updateWCS)
@@ -135,4 +135,21 @@ class DET2IMCorr(object):
return hdr
createDet2ImHdr = classmethod(createDet2ImHdr)
+
+ def updatehdr(cls, fobj, kwdict):
+ """
+ Update extension headers to keep record of the files used for the
+ detector to image correction.
+ """
+ for ext in fobj:
+ try:
+ extname = ext.header['EXTNAME'].lower()
+ except KeyError:
+ continue
+ if extname == 'sci':
+ for kw in kwdict:
+ ext.header.update(kw, kwdict[kw])
+ else:
+ continue
+ updatehdr = classmethod(updatehdr)
\ No newline at end of file
diff --git a/wcsutil/__init__.py b/wcsutil/__init__.py
index 4e43529..bad0607 100644
--- a/wcsutil/__init__.py
+++ b/wcsutil/__init__.py
@@ -119,7 +119,7 @@ class HSTWCS(WCS):
self.ra_targ = primhdr.get('RA_TARG', None)
self.dec_targ = primhdr.get('DEC_TARG', None)
self.det2imfile = primhdr.get('D2IMFILE', None)
- self.det2imext = primhdr.get('D2IMEXT', None)
+ self.det2imext = ehdr.get('D2IMEXT', None)
self.axiscorr = primhdr.get('AXISCORR', None)
self.d2imerr = primhdr.get('D2IMERR', 0.0)
try:
@@ -346,7 +346,12 @@ class HSTWCS(WCS):
"""
Create a paper IV type lookup table from a reference file
"""
- d2im_data = pyfits.getdata(self.filename, ext=('D2IMARR', 1))
+ if self.det2imext in [None, "", 'N/A']:
+ return None
+ try:
+ d2im_data = pyfits.getdata(self.filename, ext=('D2IMARR', 1))
+ except KeyError:
+ return None
d2im_data = np.array([d2im_data])
d2im_hdr = pyfits.getheader(self.filename, ext=('D2IMARR', 1))