summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordencheva <dencheva@stsci.edu>2009-12-18 12:01:35 -0500
committerdencheva <dencheva@stsci.edu>2009-12-18 12:01:35 -0500
commit2ef0aacf55807bf346014b224f2139d9c67a4522 (patch)
tree95a6ca7cd006f4ad458682224977cef1555e2d12
parenta37eae582268a4689e96008be8eb3599685812d2 (diff)
downloadstwcs_hcf-2ef0aacf55807bf346014b224f2139d9c67a4522.tar.gz
Minor refactoring and cleaning; fixed a problem when ORIENTAT is not present in the header. Tests against makewcs pass for all instruments.
git-svn-id: http://svn.stsci.edu/svn/ssb/stsci_python/stsci_python/trunk/stwcs@8507 fe389314-cf27-0410-b35b-8c050e845b92
-rw-r--r--lib/utils.py5
-rw-r--r--updatewcs/apply_corrections.py15
-rw-r--r--wcsutil/__init__.py62
-rw-r--r--wcsutil/instruments.py111
-rw-r--r--wcsutil/mappings.py5
5 files changed, 131 insertions, 67 deletions
diff --git a/lib/utils.py b/lib/utils.py
index 2731f87..504d609 100644
--- a/lib/utils.py
+++ b/lib/utils.py
@@ -68,7 +68,10 @@ def write_archive(header):
cmt = 'archived value'
for kw in basic_wcs:
nkw = 'O'+kw
- header.update(nkw[:8], header[kw], comment=cmt)
+ try:
+ header.update(nkw[:8], header[kw], comment=cmt)
+ except KeyError: #ORIENTAT is not always present in headers
+ pass
header.update('WCSCDATE', fileutil.getLTime(), comment='Local time the WCS kw were archived')
diff --git a/updatewcs/apply_corrections.py b/updatewcs/apply_corrections.py
index be9fac7..ab05d7d 100644
--- a/updatewcs/apply_corrections.py
+++ b/updatewcs/apply_corrections.py
@@ -27,15 +27,18 @@ def setCorrections(fname, vacorr=True, tddcorr=True, dgeocorr=True, d2imcorr=Tru
for the instrument, which are defined in mappings.py.
"""
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')
+ if 'TDDCorr' in acorr:
+ tddcorr = applyTDDCorr(fname, tddcorr)
+ if tddcorr == False: acorr.remove('TDDCorr')
+ if 'DGEOCorr' in acorr:
+ dgeocorr = applyDgeoCorr(fname, dgeocorr)
+ if dgeocorr == False: acorr.remove('DGEOCorr')
+ if 'DET2IMCorr' in acorr:
+ d2imcorr = applyD2ImCorr(fname, d2imcorr)
+ if d2imcorr == False: acorr.remove('DET2IMCorr')
return acorr
def applyTDDCorr(fname, utddcorr):
diff --git a/wcsutil/__init__.py b/wcsutil/__init__.py
index a7045c2..12d302b 100644
--- a/wcsutil/__init__.py
+++ b/wcsutil/__init__.py
@@ -26,7 +26,7 @@ class HSTWCS(WCS):
It also uses the primary and extension header to define
instrument specific attributes.
"""
- def __init__(self, fobj=None, ext=None, instrument=None, detector=None, minerr=0.0):
+ def __init__(self, fobj='DEFAULT', ext=None, minerr=0.0):
"""
:Parameters:
`fobj`: string or PyFITS HDUList object or None
@@ -36,13 +36,7 @@ class HSTWCS(WCS):
`ext`: int or None
extension number
if ext==None, it is assumed the data is in the primary hdu
- `instrument`: string
- one of 'ACS', 'NICMOS', 'WFPC2', 'STIS', 'WFC3'
- Used only to define a default HSTWCS object, when fobj==None
- `detector`: string
- for example 'WFC'
- If instrument and detector parameters are given, a default HSTWCS
- instrument is created. Used only with fobj==None
+
`minerr`: float
minimum value a distortion correction must have in order to be applied.
If CPERRja, CQERRja are smaller than minerr, the corersponding
@@ -51,31 +45,33 @@ class HSTWCS(WCS):
self.inst_kw = ins_spec_kw
self.minerr = minerr
- if instrument == None:
+
+ if fobj != 'DEFAULT':
filename, hdr0, ehdr, phdu = self.parseInput(f=fobj, ext=ext)
self.filename = filename
- self.setHDR0kw(hdr0, ehdr)
+ self.instrument = hdr0['INSTRUME']
+
WCS.__init__(self, ehdr, fobj=phdu, minerr=minerr)
+
# If input was a pyfits HDUList object, it's the user's
# responsibility to close it, otherwise, it's closed here.
if not isinstance(fobj, pyfits.HDUList):
phdu.close()
-
- self.instrument ='DEFAULT'
+
self.setInstrSpecKw(hdr0, ehdr)
- self.setPscale()
- self.setOrient()
self.readIDCCoeffs(ehdr)
extname = ehdr.get('EXTNAME', "")
extnum = ehdr.get('EXTVER', None)
self.extname = (extname, extnum)
else:
- # create a default HSTWCS object based on
- #instrument and detector parameters
- self.instrument = instrument
- self.detector = detector
+ # create a default HSTWCS object
+ self.instrument = 'DEFAULT'
+ WCS.__init__(self, minerr=minerr)
self.setInstrSpecKw()
-
+
+ self.setPscale()
+ self.setOrient()
+
def parseInput(self, f=None, ext=None):
if isinstance(f, str):
# create an HSTWCS object from a filename
@@ -115,27 +111,7 @@ class HSTWCS(WCS):
filename = hdr0.get('FILENAME', "")
return filename, hdr0, ehdr, phdu
-
- def setHDR0kw(self, primhdr, ehdr):
- # Set attributes from kw defined in the primary header.
- self.instrument = primhdr.get('INSTRUME', None)
- self.offtab = primhdr.get('OFFTAB', None)
- self.idctab = primhdr.get('IDCTAB', None)
- self.date_obs = primhdr.get('DATE-OBS', None)
- self.ra_targ = primhdr.get('RA_TARG', None)
- self.dec_targ = primhdr.get('DEC_TARG', None)
- self.det2imfile = primhdr.get('D2IMFILE', None)
- self.det2imext = ehdr.get('D2IMEXT', None)
- try:
- self.pav3 = primhdr['PA_V3']
-
- except KeyError:
- print 'Keyword PA_V3 not found in primary header.'
- print 'This is typical for some old files. Please retrieve the files from the archive again.'
- #print 'Quitting ...'
- #raise
-
-
+
def readIDCCoeffs(self, header):
"""
@@ -152,6 +128,7 @@ class HSTWCS(WCS):
inst_kl = inst_mappings[self.instrument]
inst_kl = instruments.__dict__[inst_kl]
insobj = inst_kl(prim_hdr, ext_hdr)
+
for key in self.inst_kw:
try:
self.__setattr__(key, insobj.__getattribute__(key))
@@ -162,6 +139,7 @@ class HSTWCS(WCS):
raise
else:
pass
+
else:
raise KeyError, "Unsupported instrument - %s" %self.instrument
@@ -305,8 +283,8 @@ def help():
Example:\n
w = wcsutil.HSTWCS('j9irw4b1q_flt.fits', ext=2)\n\n
- 4. Create a template HSTWCS object for an instrument/detector combination.]n
+ 4. Create a template HSTWCS object for a DEFAULT object.\n
Example:\n
- w = wcsutil.HSTWCS(instrument='ACS', detector='WFC'\n\n
+ w = wcsutil.HSTWCS(instrument='DEFAULT')\n\n
"""
diff --git a/wcsutil/instruments.py b/wcsutil/instruments.py
index ac7982f..c02c32d 100644
--- a/wcsutil/instruments.py
+++ b/wcsutil/instruments.py
@@ -19,6 +19,14 @@ class InstrWCS(object):
There should be a set_kw method for all kw listed in
mappings.ins_spec_kw
"""
+ self.set_idctab()
+ self.set_offtab()
+ self.set_date_obs()
+ self.set_ra_targ()
+ self.set_dec_targ()
+ self.set_pav3()
+ #self.set_d2imfile()
+
self.set_detector()
self.set_filter1()
self.set_filter2()
@@ -31,43 +39,114 @@ class InstrWCS(object):
self.set_chip()
self.set_parity()
-
+ def set_idctab(self):
+ try:
+ self.idctab = self.primhdr['IDCTAB']
+ except (KeyError, TypeError):
+ self.idctab = None
+
+ def set_offtab(self):
+ try:
+ self.offtab = self.primhdr['OFFTAB']
+ except (KeyError, TypeError):
+ self.offtab = None
+
+ def set_date_obs(self):
+ try:
+ self.date_obs = self.primhdr['DATE-OBS']
+ except (KeyError, TypeError):
+ self.date_obs = None
+
+ def set_ra_targ(self):
+ try:
+ self.ra_targ = self.primhdr['RA-TARG']
+ except (KeyError, TypeError):
+ self.ra_targ = None
+
+ def set_dec_targ(self):
+ try:
+ self.dec_targ = self.primhdr['DEC-TARG']
+ except (KeyError, TypeError):
+ self.dec_targ = None
+ """
+ def set_d2imfile(self):
+ try:
+ self.d2imfile = self.primhdr['D2IMFILE']
+ except (KeyError, TypeError):
+ self.d2imfile = None
+ """
+ def set_pav3(self):
+ try:
+ self.pav3 = self.primhdr['PA_V3']
+ except (KeyError, TypeError):
+ self.pav3 = None
+
def set_filter1(self):
- self.filter1 = self.primhdr.get('FILTER1', None)
-
+ #self.filter1 = self.primhdr.get('FILTER1', None)
+ try:
+ self.filter1 = self.primhdr['FILTER1']
+ except:
+ self.filter1 = None
+
def set_filter2(self):
- self.filter2 = self.primhdr.get('FILTER2', None)
-
+ #self.filter2 = self.primhdr.get('FILTER2', None)
+ try:
+ self.filter2 = self.primhdr['FILTER2']
+ except (KeyError, TypeError):
+ self.filter2 = None
+
def set_vafactor(self):
- self.vafactor = self.exthdr.get('vafactor', 1)
-
+ #self.vafactor = self.exthdr.get('vafactor', 1)
+ try:
+ self.vafactor = self.exthdr['VAFACTOR']
+ except (KeyError, TypeError):
+ self.vafactor = 1
+
def set_naxis1(self):
try:
self.naxis1 = self.exthdr['naxis1']
- except:
+ except (KeyError, TypeError):
try:
self.naxis1 = self.exthdr['npix1']
- except:
+ except (KeyError, TypeError):
self.naxis1 = None
+
def set_naxis2(self):
try:
self.naxis2 = self.exthdr['naxis2']
- except:
+ except (KeyError, TypeError):
try:
self.naxis2 = self.exthdr['npix2']
- except:
+ except (KeyError, TypeError):
self.naxis2 = None
+
def set_ltv1(self):
- self.ltv1 = self.exthdr.get('ltv1', 0.0)
+ #self.ltv1 = self.exthdr.get('ltv1', 0.0)
+ try:
+ self.ltv1 = self.exthdr['LTV1']
+ except (KeyError, TypeError):
+ self.ltv1 = 0.0
def set_ltv2(self):
- self.ltv2 = self.exthdr.get('ltv2', 0.0)
-
+ #self.ltv2 = self.exthdr.get('ltv2', 0.0)
+ try:
+ self.ltv2 = self.exthdr['LTV2']
+ except (KeyError, TypeError):
+ self.ltv2 = 0.0
+
def set_binned(self):
- self.binned = self.exthdr.get('BINAXIS1', 1)
+ #self.binned = self.exthdr.get('BINAXIS1', 1)
+ try:
+ self.binned = self.exthdr['BINAXIS1']
+ except (KeyError, TypeError):
+ self.binned = 1
def set_chip(self):
- self.chip = self.exthdr.get('CCDCHIP', 1)
+ #self.chip = self.exthdr.get('CCDCHIP', 1)
+ try:
+ self.chip = self.exthdr['CCDCHIP']
+ except (KeyError, TypeError):
+ self.chip = 1
def set_parity(self):
self.parity = [[1.0,0.0],[0.0,-1.0]]
diff --git a/wcsutil/mappings.py b/wcsutil/mappings.py
index 72059a3..32d6391 100644
--- a/wcsutil/mappings.py
+++ b/wcsutil/mappings.py
@@ -15,8 +15,9 @@ inst_mappings={'WFPC2': 'WFPC2WCS',
# A list of instrument specific keywords
# Every instrument class must have methods which define each of these
# as class attributes.
-ins_spec_kw = [ 'detector', 'ltv1', 'ltv2', 'parity', 'binned','vafactor', 'chip',
- 'naxis1', 'naxis2', 'filter1', 'filter2']
+ins_spec_kw = [ 'idctab', 'offtab', 'date_obs', 'ra_targ', 'dec_targ', 'pav3', \
+ 'detector', 'ltv1', 'ltv2', 'parity', 'binned','vafactor', \
+ 'chip', 'naxis1', 'naxis2', 'filter1', 'filter2']
# A list of keywords defined in the primary header.
# The HSTWCS class sets this as attributes