summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordencheva <dencheva@stsci.edu>2009-03-17 16:35:57 -0400
committerdencheva <dencheva@stsci.edu>2009-03-17 16:35:57 -0400
commit0bc834376d0e7cb66c1b7f5e27d14402b84235d9 (patch)
treea2c8d2c80b33c79d7da2d872dabe22a89f24cbca
parent2f388a86de97f76640063aa521389bdd5ddf2ee6 (diff)
downloadstwcs_hcf-0bc834376d0e7cb66c1b7f5e27d14402b84235d9.tar.gz
Added code which populates the science file with information about detector to image correction - header keywords and a lookup table extension. Cleaned coed.
git-svn-id: http://svn.stsci.edu/svn/ssb/stsci_python/development/trunk/updatewcs@7770 fe389314-cf27-0410-b35b-8c050e845b92
-rw-r--r--hstwcs/__init__.py9
-rw-r--r--hstwcs/apply_corrections.py42
-rw-r--r--hstwcs/dgeo.py3
-rw-r--r--wcsutil/__init__.py8
-rw-r--r--wcsutil/instruments.py4
5 files changed, 56 insertions, 10 deletions
diff --git a/hstwcs/__init__.py b/hstwcs/__init__.py
index 926d4c3..8b83e1e 100644
--- a/hstwcs/__init__.py
+++ b/hstwcs/__init__.py
@@ -6,7 +6,7 @@ from updatewcs.wcsutil import HSTWCS
#from .. mappings import allowed_corrections
from updatewcs import utils
import corrections, makewcs
-import dgeo
+import dgeo, det2im
import time
from pytools import parseinput, fileutil
import apply_corrections
@@ -80,6 +80,11 @@ def makecorr(fname, allowed_corr):
ref_wcs = HSTWCS(fobj=f, ext=nrefext)
ref_wcs.readModel(update=True,header=f[nrefext].header)
utils.write_archive(f[nrefext].header)
+
+ if 'DET2IMCorr' in allowed_corr:
+ kw2update = det2im.DET2IMCorr.updateWCS(f)
+ for kw in kw2update:
+ f[1].header.update(kw, kw2update[kw])
for i in range(len(f))[1:]:
# Perhaps all ext headers should be corrected (to be consistent)
@@ -91,7 +96,7 @@ def makecorr(fname, allowed_corr):
ext_wcs = HSTWCS(fobj=f, ext=i)
ext_wcs.readModel(update=True,header=hdr)
for c in allowed_corr:
- if c != 'DGEOCorr':
+ if c != 'DGEOCorr' and c != 'DET2IMCorr':
corr_klass = corrections.__getattribute__(c)
kw2update = corr_klass.updateWCS(ext_wcs, ref_wcs)
for kw in kw2update:
diff --git a/hstwcs/apply_corrections.py b/hstwcs/apply_corrections.py
index 92aa755..c54725c 100644
--- a/hstwcs/apply_corrections.py
+++ b/hstwcs/apply_corrections.py
@@ -12,13 +12,13 @@ __docformat__ = 'restructuredtext'
# These are the default corrections applied also in the pipeline.
allowed_corrections={'WFPC2': ['MakeWCS','CompSIP', 'VACorr', 'DGEOCorr'],
- 'ACS': ['TDDCorr', 'MakeWCS', 'CompSIP','VACorr', 'DGEOCorr'],
+ 'ACS': ['DET2IMCorr', 'TDDCorr', 'MakeWCS', 'CompSIP','VACorr', 'DGEOCorr'],
'STIS': ['MakeWCS', 'CompSIP','VACorr'],
'NICMOS': ['MakeWCS', 'CompSIP','VACorr'],
'WFC3': ['MakeWCS', 'CompSIP','VACorr'],
}
-def setCorrections(fname, vacorr=True, tddcorr=True, dgeocorr=True):
+def setCorrections(fname, vacorr=True, tddcorr=True, dgeocorr=True, d2imcorr=True):
"""
Purpose
=======
@@ -29,11 +29,14 @@ def setCorrections(fname, vacorr=True, tddcorr=True, dgeocorr=True):
instrument = pyfits.getval(fname, 'INSTRUME')
tddcorr = applyTDDCorr(fname, tddcorr)
dgeocorr = applyDgeoCorr(fname, dgeocorr)
+ d2imcorr = applyD2ImCorr(fname, d2imcorr)
# make a copy of this list !
acorr = allowed_corrections[instrument][:]
if 'VACorr' in acorr and vacorr==False: acorr.remove('VACorr')
if 'TDDCorr' in acorr and tddcorr==False: acorr.remove('TDDCorr')
if 'DGEOCorr' in acorr and dgeocorr==False: acorr.remove('DGEOCorr')
+ if 'DET2IMCorr' in acorr and d2imcorr==False: acorr.remove('DET2IMCorr')
+
return acorr
def applyTDDCorr(fname, utddcorr):
@@ -141,3 +144,38 @@ def isOldStyleDGEO(fname, dgname):
else:
return False
+def applyD2ImCorr(fname, d2imcorr):
+ applyD2IMCorr = True
+ try:
+ # get DGEOFILE kw from primary header
+ fd2im0 = pyfits.getval(fname, 'D2IMFILE')
+ if fd2im0 == 'N/A':
+ return False
+ fd2im0 = fileutil.osfn(fd2im0)
+ if not fileutil.findFile(fd2im0):
+ print 'Kw D2IMFILE exists in primary header but file %s not found\n' % fd2im0
+ print 'DGEO correction will not be applied\n'
+ applyD2IMCorr = False
+ return applyD2IMCorr
+ try:
+ # get DGEOEXT kw from first extension header
+ fd2imext = pyfits.getval(fname, 'D2IMEXT', ext=0)
+ fd2imext = fileutil.osfn(fd2imext)
+ if fd2imext and fileutil.findFile(fd2imext):
+ if fd2im0 != fd2imext:
+ applyD2IMCorr = True
+ else:
+ applyD2IMCorr = False
+ else:
+ # dgeo file defined in first extension may not be found
+ # but if a valid kw exists in the primary header, dgeo should be applied.
+ applyD2IMCorr = True
+ except KeyError:
+ # the case of DGEOFILE kw present in primary header but DGEOEXT missing
+ # in first extension header
+ applyD2IMCorr = True
+ except KeyError:
+ print 'D2IMFILE keyword not found in primary header'
+ applyD2IMCorr = False
+ return applyD2IMCorr
+ \ No newline at end of file
diff --git a/hstwcs/dgeo.py b/hstwcs/dgeo.py
index a97290d..d6313d7 100644
--- a/hstwcs/dgeo.py
+++ b/hstwcs/dgeo.py
@@ -52,7 +52,6 @@ class DGEOCorr(object):
- add/update DGEOEXT keyword
"""
dgfile = fileutil.osfn(fobj[0].header['DGEOFILE'])
- instrument = fobj[0].header.get('INSTRUME', None)
# Map WCSDVARR EXTVER numbers to extension numbers
wcsdvarr_ind = cls.getWCSIndex(fobj)
for ext in fobj:
@@ -209,7 +208,7 @@ class DGEOCorr(object):
comments = {'XTENSION': 'Image extension',
'BITPIX': 'IEEE floating point',
- 'NAXIS': 'Number of image columns',
+ 'NAXIS': 'Number of axes',
'NAXIS1': 'Number of image columns',
'NAXIS2': 'Number of image rows',
'EXTNAME': 'WCS distortion array',
diff --git a/wcsutil/__init__.py b/wcsutil/__init__.py
index 894abad..05790f8 100644
--- a/wcsutil/__init__.py
+++ b/wcsutil/__init__.py
@@ -224,28 +224,28 @@ class HSTWCS(WCS):
def all_pix2sky(self, *args, **kwargs):
origin = self.get_origin(*args)
- if self.det2imfile != None:
+ if self.det2imext != None:
return WCS.all_pix2sky(self, self.det2im(*args),origin )
else:
return WCS.all_pix2sky(self, *args)
def pix2foc(self, *args, **kwargs):
origin = self.get_origin(*args)
- if self.det2imfile != None:
+ if self.det2imext != None:
return WCS.pix2foc(self, self.det2im(*args), origin)
else:
return WCS.pix2foc(self, *args)
def p4_pix2foc(self, *args, **kwargs):
origin = self.get_origin(*args)
- if self.det2imfile != None:
+ if self.det2imext != None:
return WCS.p4_pix2foc(self, self.det2im(*args), origin)
else:
return WCS.p4_pix2foc(self, *args)
def wcs_pix2sky(self, *args, **kwargs):
origin = self.get_origin(*args)
- if self.det2imfile != None:
+ if self.det2imext != None:
return WCS.wcs_pix2sky(self, self.det2im(*args), origin)
else:
return WCS.wcs_pix2sky(self, *args)
diff --git a/wcsutil/instruments.py b/wcsutil/instruments.py
index 4491079..6d41e2a 100644
--- a/wcsutil/instruments.py
+++ b/wcsutil/instruments.py
@@ -105,6 +105,10 @@ class ACSWCS(InstrWCS):
except KeyError:
print 'ERROR: Detector kw not found.\n'
raise
+ except TypeError:
+ #this is the case of creating a default HSTWCS object by
+ #providing 'instrument' and 'detector'
+ pass
def set_parity(self):
parity = {'WFC':[[1.0,0.0],[0.0,-1.0]],