diff options
author | dencheva <dencheva@stsci.edu> | 2008-08-22 13:59:11 -0400 |
---|---|---|
committer | dencheva <dencheva@stsci.edu> | 2008-08-22 13:59:11 -0400 |
commit | b003de463c45950a475892c8f5316c2f13a7536f (patch) | |
tree | 773f31bc7fe0149be7576667d2403c4c53fa771c /wcsutil/__init__.py | |
parent | 33107fbdd5bba3625c63bf944cfb7a927f18cd1e (diff) | |
download | stwcs_hcf-b003de463c45950a475892c8f5316c2f13a7536f.tar.gz |
- HSTWCS class was modified to
- not keep the headers as attributes
- accept an adittional paramter fobj, consistent with SIP and WCS classes.
- The restore method was renamed to get_archive and moved to utils
- corrections classes:
- updateWCS were turned into classmethods
- diff_abgles was moved to utils
- restoreWCS() was moved to utils
git-svn-id: http://svn.stsci.edu/svn/ssb/stsci_python/development/trunk/hstwcs@6973 fe389314-cf27-0410-b35b-8c050e845b92
Diffstat (limited to 'wcsutil/__init__.py')
-rw-r--r-- | wcsutil/__init__.py | 115 |
1 files changed, 41 insertions, 74 deletions
diff --git a/wcsutil/__init__.py b/wcsutil/__init__.py index 46ad42e..9482a48 100644 --- a/wcsutil/__init__.py +++ b/wcsutil/__init__.py @@ -16,34 +16,34 @@ class HSTWCS(SIP): """ Purpose ======= - Create a wcs object based on the instrument. + Create a WCS object based on the instrument. It has all basic WCS kw as attribbutes (set by pywcs). It also uses the primary and extension header to define instrument specific attributes needed by the correction classes. """ - def __init__(self, hdr0, hdr): + def __init__(self, hdr0, ehdr, fobj=None): """ :Parameters: `hdr0`: Pyfits Header primary header - `hdr`: Pyfits Header + `ehdr`: Pyfits Header extension header + `fobj`: PyFITS HDUList object or None + pyfits file object """ - self.hdr = hdr - self.hdr0 = hdr0 - SIP.__init__(self, self.hdr) + SIP.__init__(self, ehdr, fobj=fobj) self.setHDR0kw(hdr0) - self.detector = self.setDetector() + self.detector = self.setDetector(hdr0) self.inst_kw = ins_spec_kw - self.setInstrSpecKw() + self.setInstrSpecKw(hdr0, ehdr) self.pscale = self.setPscale() self.orientat = self.setOrient() def setHDR0kw(self, primhdr): - #sets attributes from kw defined in the primary header + # 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) @@ -53,34 +53,35 @@ class HSTWCS(SIP): self.dec_targ = primhdr.get('DEC_TARG', None) - def setDetector(self): - #sets detector attribute for instuments which have more than one detector + def setDetector(self, header): + # Set detector attribute for instuments which have more than one detector if self.instrument in ['ACS', 'WFC3']: - return self.hdr0.get('DETECTOR', None) - - - def setInstrSpecKw(self): - #Based on the instrument kw creates an instalnce of an instrument WCS class - #and sets attributes from instrument specific kw + return header.get('DETECTOR', None) + else: + return None + + def setInstrSpecKw(self, prim_hdr, ext_hdr): + # Based on the instrument kw creates an instalnce of an instrument WCS class + # and sets attributes from instrument specific kw if self.instrument in inst_mappings.keys(): inst_kl = inst_mappings[self.instrument] inst_kl = instruments.__dict__[inst_kl] - insobj = inst_kl(self.hdr0, self.hdr) + insobj = inst_kl(prim_hdr, ext_hdr) for key in self.inst_kw: self.__setattr__(key, insobj.__getattribute__(key)) else: raise KeyError, "Unsupported instrument - %s" %self.instrument def setPscale(self): - #Calculates the plate scale from the cd matrix - #this may not be needed now and shoufl probably be done after all + # Calculates the plate scale from the cd matrix + # this may not be needed now and shoufl probably be done after all # corrections cd11 = self.cd[0][0] cd21 = self.cd[1][0] return N.sqrt(N.power(cd11,2)+N.power(cd21,2)) * 3600. def setOrient(self): - #same as setPscale + # Recompute ORIENTAT cd12 = self.cd[0][1] cd22 = self.cd[1][1] return RADTODEG(N.arctan2(cd12,cd22)) @@ -91,7 +92,7 @@ class HSTWCS(SIP): def verifyKw(self): """verify that all required kw have meaningful values""" - def readModel(self): + def readModel(self, header): """ Purpose ======= @@ -106,61 +107,27 @@ class HSTWCS(SIP): offtab=self.offtab, binned=self.binned) - self.updatehdr() + self.updatehdr(header) - def updatehdr(self, newkeywords=None): + def updatehdr(self, ext_hdr, newkeywords=None): #kw2add : OCX10, OCX11, OCY10, OCY11 # record the model in the header for use by pydrizzle - self.hdr.update('OCX10', self.idcmodel.cx[1,0]) - self.hdr.update('OCX11', self.idcmodel.cx[1,1]) - self.hdr.update('OCY10', self.idcmodel.cy[1,0]) - self.hdr.update('OCY11', self.idcmodel.cy[1,1]) - self.hdr.update('IDCSCALE', self.idcmodel.refpix['PSCALE']) - self.hdr.update('IDCTHETA', self.idcmodel.refpix['THETA']) - self.hdr.update('IDCXREF', self.idcmodel.refpix['XREF']) - self.hdr.update('IDCYREF', self.idcmodel.refpix['YREF']) - self.hdr.update('IDCV2REF', self.idcmodel.refpix['V2REF']) - self.hdr.update('IDCV3REF', self.idcmodel.refpix['V3REF']) - self.hdr.update('IDCXSIZE', self.idcmodel.refpix['XSIZE']) - self.hdr.update('IDCYSIZE', self.idcmodel.refpix['YSIZE']) - self.hdr.update('IDCXDELT', self.idcmodel.refpix['XDELTA']) - self.hdr.update('IDCYDELT', self.idcmodel.refpix['YDELTA']) - self.hdr.update('CENTERED', self.idcmodel.refpix['centered']) + ext_hdr.update('OCX10', self.idcmodel.cx[1,0]) + ext_hdr.update('OCX11', self.idcmodel.cx[1,1]) + ext_hdr.update('OCY10', self.idcmodel.cy[1,0]) + ext_hdr.update('OCY11', self.idcmodel.cy[1,1]) + ext_hdr.update('IDCSCALE', self.idcmodel.refpix['PSCALE']) + ext_hdr.update('IDCTHETA', self.idcmodel.refpix['THETA']) + ext_hdr.update('IDCXREF', self.idcmodel.refpix['XREF']) + ext_hdr.update('IDCYREF', self.idcmodel.refpix['YREF']) + ext_hdr.update('IDCV2REF', self.idcmodel.refpix['V2REF']) + ext_hdr.update('IDCV3REF', self.idcmodel.refpix['V3REF']) + ext_hdr.update('IDCXSIZE', self.idcmodel.refpix['XSIZE']) + ext_hdr.update('IDCYSIZE', self.idcmodel.refpix['YSIZE']) + ext_hdr.update('IDCXDELT', self.idcmodel.refpix['XDELTA']) + ext_hdr.update('IDCYDELT', self.idcmodel.refpix['YDELTA']) + ext_hdr.update('CENTERED', self.idcmodel.refpix['centered']) - def restore(self): - """ - restores basic wcs keywords from archive - this should be modified to always return a populated - dictionary, although the values may be None. - """ - - backup = {} - for k in basic_wcs: - try: - nkw = ('O'+k)[:7] - #backup[k] = self.hdr.__getitem__('O'+k) - backup[k] = self.hdr[nkw] - #self.__setattr__(k, self.hdr.__getitem__('O'+k)) - self.__setattr__(k, self.hdr[nkw]) - except KeyError: - print 'Keyword %s not found' % k - - return backup - - def archive_kw(self): - """ - archive original WCS kw before recalculating them. - """ - backup_kw = self.restore() - if backup_kw != {}: - return - else: - # keep the archived kw 8 characters long - cmt = 'archived value' - for kw in basic_wcs: - nkw = 'O'+kw - self.hdr.update(nkw[:7], self.hdr[kw], comment=cmt) - - +
\ No newline at end of file |