diff options
author | embray <embray@stsci.edu> | 2011-12-09 11:36:08 -0500 |
---|---|---|
committer | embray <embray@stsci.edu> | 2011-12-09 11:36:08 -0500 |
commit | 57ffdc72dd743f29750d2613366d6a68b35f5c6e (patch) | |
tree | e11436ed02cdb969b862712e47565075defa61f2 | |
parent | f5e720fa9cb1a5e9d0c4bc9658cbd3455ef327e3 (diff) | |
download | stwcs_hcf-57ffdc72dd743f29750d2613366d6a68b35f5c6e.tar.gz |
Fix a lot of DeprecationWarnings.
git-svn-id: http://svn.stsci.edu/svn/ssb/stsci_python/stsci_python/trunk/stwcs@14056 fe389314-cf27-0410-b35b-8c050e845b92
-rw-r--r-- | lib/stwcs/updatewcs/det2im.py | 94 | ||||
-rw-r--r-- | lib/stwcs/wcsutil/headerlet.py | 40 |
2 files changed, 67 insertions, 67 deletions
diff --git a/lib/stwcs/updatewcs/det2im.py b/lib/stwcs/updatewcs/det2im.py index 5e03f74..b658d53 100644 --- a/lib/stwcs/updatewcs/det2im.py +++ b/lib/stwcs/updatewcs/det2im.py @@ -10,43 +10,43 @@ logger = logging.getLogger('stwcs.updatewcs.Det2IM') class DET2IMCorr(object): """ - Stores a small correction to the detector coordinates as a d2imarr + Stores a small correction to the detector coordinates as a d2imarr extension in the science file. - + Notes ----- For the case of ACS/WFC every 68th column is wider than the rest. - To compensate for this a small correction needs to be applied to the - detector coordinates. We call this a detector to image transformation. - The so obtained image coordinates are the input to all other distortion - corrections. The correction is originally stored in an external - reference file pointed to by 'D2IMFILE' keyword in the primary header. - This class attaches the correction array as an extension to the science - file with extname = `d2imarr`. - + To compensate for this a small correction needs to be applied to the + detector coordinates. We call this a detector to image transformation. + The so obtained image coordinates are the input to all other distortion + corrections. The correction is originally stored in an external + reference file pointed to by 'D2IMFILE' keyword in the primary header. + This class attaches the correction array as an extension to the science + file with extname = `d2imarr`. + Other keywords used in this correction are: - `AXISCORR`: integer (1 or 2) - axis to which the detector to image + `AXISCORR`: integer (1 or 2) - axis to which the detector to image correction is applied - + `D2IMEXT`: string = name of reference file which was used to create the lookup table extension - + `D2IMERR`: float, optional - maximum value of the correction - + """ def updateWCS(cls, fobj): """ Parameters ---------- fobj: pyfits object - Science file, for which a detector to image correction + Science file, for which a detector to image correction is available - + Notes ----- - Uses the file pointed to in the primary header keyword 'D2IMFILE' - to create an extension with a detector to image correction. + Uses the file pointed to in the primary header keyword 'D2IMFILE' + to create an extension with a detector to image correction. """ logger.info("\n\tStarting Det2IM Correction: %s" % time.asctime()) try: @@ -54,7 +54,7 @@ class DET2IMCorr(object): except AssertionError: logger.exception('\n\tInput must be a pyfits.HDUList object') raise - + d2imfile = fileutil.osfn(fobj[0].header['D2IMFILE']) axiscorr = cls.getAxisCorr(d2imfile) d2imerr = pyfits.getdata(d2imfile, ext=1).max() @@ -64,15 +64,15 @@ class DET2IMCorr(object): new_kw = {'D2IMEXT': d2imfile, 'AXISCORR': axiscorr, 'D2IMERR': d2imerr} cls.applyDet2ImCorr(fobj,axiscorr) cls.updatehdr(fobj, new_kw) - - updateWCS = classmethod(updateWCS) - + + updateWCS = classmethod(updateWCS) + def getAxisCorr(cls, refname): try: direction = pyfits.getval(refname, 'EXTNAME', ext=1) if direction == 'DX': return 1 elif direction == 'DY': return 2 - else: + else: logger.warning('\n\tDET2IM correction expects the reference file to have \ an EXTNAME keyword of value "DX" or "DY", EXTNAMe %s detected' % direction) return None @@ -82,7 +82,7 @@ class DET2IMCorr(object): direction = None return direction getAxisCorr = classmethod(getAxisCorr) - + def applyDet2ImCorr(cls,fobj, axiscorr): binned = utils.getBinning(fobj) hdu = cls.createDgeoHDU(fobj, axiscorr, binned) @@ -92,7 +92,7 @@ class DET2IMCorr(object): else: fobj.append(hdu) applyDet2ImCorr = classmethod(applyDet2ImCorr) - + def getD2imIndex(cls,fobj): index = None for e in range(len(fobj)): @@ -104,43 +104,43 @@ class DET2IMCorr(object): index = e return index getD2imIndex = classmethod(getD2imIndex) - + def createDgeoHDU(cls, fobj, axiscorr, binned=1): d2imfile = fileutil.osfn(fobj[0].header['D2IMFILE']) d2im_data = pyfits.getdata(d2imfile, ext=1) sci_hdr = fobj['sci',1].header d2im_hdr = cls.createDet2ImHdr(fobj, binned) hdu = pyfits.ImageHDU(header=d2im_hdr, data=d2im_data) - + return hdu - + createDgeoHDU = classmethod(createDgeoHDU) - - def createDet2ImHdr(cls, fobj, binned=1): + + def createDet2ImHdr(cls, fobj, binned=1): """ - Creates a header for the D2IMARR extension based on the + Creates a header for the D2IMARR extension based on the reference file recorded in D2IMFILE keyword in the primary header. fobj - the science file - + """ d2imfile = fileutil.osfn(fobj[0].header['D2IMFILE']) axiscorr = cls.getAxisCorr(d2imfile) sci_hdr = fobj[1].header data_shape = pyfits.getdata(d2imfile, ext=1).shape naxis = pyfits.getval(d2imfile, 'NAXIS', ext=1 ) - - kw = { 'NAXIS': 'Size of the axis', - 'CRPIX': 'Coordinate system reference pixel', + + kw = { 'NAXIS': 'Size of the axis', + 'CRPIX': 'Coordinate system reference pixel', 'CRVAL': 'Coordinate system value at reference pixel', 'CDELT': 'Coordinate increment along axis'} - + kw_comm1 = {} kw_val1 = {} for key in kw.keys(): for i in range(1, naxis+1): si = str(i) kw_comm1[key+si] = kw[key] - + for i in range(1, naxis+1): si = str(i) kw_val1['NAXIS'+si] = data_shape[i-1] @@ -148,8 +148,8 @@ class DET2IMCorr(object): kw_val1['CDELT'+si] = 1./binned kw_val1['CRVAL'+si] = (sci_hdr.get('NAXIS'+si, 1)/2. + \ sci_hdr.get('LTV'+si, 0.)) / binned - - + + kw_comm0 = {'XTENSION': 'Image extension', 'BITPIX': 'IEEE floating point', 'NAXIS': 'Number of axes', @@ -158,7 +158,7 @@ class DET2IMCorr(object): 'PCOUNT': 'Special data area of size 0', 'GCOUNT': 'One data group', 'AXISCORR': 'Direction in which the det2im correction is applied'} - + kw_val0 = { 'XTENSION': 'IMAGE', 'BITPIX': -32, 'NAXIS': naxis, @@ -168,8 +168,8 @@ class DET2IMCorr(object): 'GCOUNT': 1, 'AXISCORR': axiscorr } - - + + cdl = pyfits.CardList() for key in kw_comm0.keys(): cdl.append(pyfits.Card(key=key, value=kw_val0[key], comment=kw_comm0[key])) @@ -189,15 +189,15 @@ class DET2IMCorr(object): if start_indx >= 0: for card in d2im_phdr[start_indx:end_indx]: cdl.append(card) - + hdr = pyfits.Header(cards=cdl) return hdr - + createDet2ImHdr = classmethod(createDet2ImHdr) - + def updatehdr(cls, fobj, kwdict): """ - Update extension headers to keep record of the files used for the + Update extension headers to keep record of the files used for the detector to image correction. """ for ext in fobj: @@ -211,4 +211,4 @@ class DET2IMCorr(object): else: continue updatehdr = classmethod(updatehdr) - + diff --git a/lib/stwcs/wcsutil/headerlet.py b/lib/stwcs/wcsutil/headerlet.py index fd4c287..c2567c2 100644 --- a/lib/stwcs/wcsutil/headerlet.py +++ b/lib/stwcs/wcsutil/headerlet.py @@ -432,7 +432,7 @@ def update_ref_files(source, dest): wind = dest.ascard.index_of('HISTORY') else: wind = len(dest) - + for key in phdukw.keys(): try: srckey = source.ascard[key] @@ -596,9 +596,9 @@ def extract_headerlet(filename, output, extnum=None, hdrname=None, String input formats supported include use of wild-cards, IRAF-style '@'-files (given as '@<filename>') and comma-separated list of names. - An input filename (str) will be expanded as necessary to interpret + An input filename (str) will be expanded as necessary to interpret any environmental variables included in the filename. - If a list of filenames has been specified, it will extract a + If a list of filenames has been specified, it will extract a headerlet from the same extnum from all filenames. output: string Filename or just rootname of output headerlet FITS file @@ -649,7 +649,7 @@ def extract_headerlet(filename, output, extnum=None, hdrname=None, if output is None: output = frootname - + if '.fits' in output: outname = output else: @@ -660,7 +660,7 @@ def extract_headerlet(filename, output, extnum=None, hdrname=None, if close_fobj: fobj.close() -def write_headerlet(filename, hdrname, output=None, sciext='SCI', +def write_headerlet(filename, hdrname, output=None, sciext='SCI', wcsname=None, wcskey=None, destim=None, sipname=None, npolfile=None, d2imfile=None, author=None, descrip=None, history=None, @@ -686,13 +686,13 @@ def write_headerlet(filename, hdrname, output=None, sciext='SCI', will be created and written out. String input formats supported include use of wild-cards, IRAF-style '@'-files (given as '@<filename>') and comma-separated list of names. - An input filename (str) will be expanded as necessary to interpret + An input filename (str) will be expanded as necessary to interpret any environmental variables included in the filename. hdrname: string Unique name for this headerlet, stored as HDRNAME keyword output: string or None Filename or just rootname of output headerlet FITS file - If string does not contain '.fits', it will create a filename + If string does not contain '.fits', it will create a filename starting with the science filename and ending with '_hlet.fits'. If None, a default filename based on the input filename will be generated for the headerlet FITS filename @@ -800,8 +800,8 @@ def write_headerlet(filename, hdrname, output=None, sciext='SCI', hdrletobj = create_headerlet(fobj, sciext=sciext, wcsname=wname, wcskey=wcskey, hdrname=hdrname, - sipname=sipname, npolfile=npolfile, - d2imfile=d2imfile, author=author, + sipname=sipname, npolfile=npolfile, + d2imfile=d2imfile, author=author, descrip=descrip, history=history, rms_ra=rms_ra, rms_dec=rms_dec, nmatch=nmatch, catalog=catalog, @@ -871,7 +871,7 @@ def create_headerlet(filename, sciext='SCI', hdrname=None, destim=None, If string - a valid EXTNAME is expected If int - specifies an extension with a valid WCS, such as 0 for a simple FITS file - If list - a list of FITS extension numbers or strings representing + If list - a list of FITS extension numbers or strings representing extension tuples, e.g. ('SCI, 1') is expected. hdrname: string value of HDRNAME keyword @@ -1132,7 +1132,7 @@ def create_headerlet(filename, sciext='SCI', hdrname=None, destim=None, comment='Velocity aberration plate scale factor')) h.insert(0, pyfits.Card(key='EXTNAME', value='SIPWCS', comment='Extension name')) - if isinstance(fext, int): + if isinstance(fext, int): if 'extver' in fobj[fext].header: val = fobj[fext].header['extver'] else: @@ -1140,7 +1140,7 @@ def create_headerlet(filename, sciext='SCI', hdrname=None, destim=None, else: val = fext[1] h.insert(1, pyfits.Card(key='EXTVER', value=val, comment='Extension version')) - h.append(pyfits.Card(key="SCIEXT", value=e, + h.append(pyfits.Card(key="SCIEXT", value=e, comment="Target science data extension")) fhdr = fobj[fext].header.ascard if npolfile is not 'NOMODEL': @@ -1870,7 +1870,7 @@ class Headerlet(pyfits.HDUList): self.hverify() fobj, fname, close_dest = parse_filename(fobj, mode='update') if self.verify_dest(fobj): - + # Check to see whether the distortion model in the destination # matches the distortion model in the headerlet being applied dist_models_equal = True @@ -1883,7 +1883,7 @@ class Headerlet(pyfits.HDUList): """ % (self[0].header['DISTNAME'], fobj[0].header['DISTNAME']) logger.critical(message) dist_models_equal = False - + if not dist_models_equal and not force: raise ValueError @@ -1914,7 +1914,7 @@ class Headerlet(pyfits.HDUList): wcsextn = int(wcsextn) except ValueError: wcsextn = fu.parseExtn(wcsextn) - + if hdrname not in hdrlet_extnames: # - if WCS has not been saved, write out WCS as headerlet extension # Create a headerlet for the original Primary WCS data in the file, @@ -1929,7 +1929,7 @@ class Headerlet(pyfits.HDUList): orig_hlt_hdu = HeaderletHDU.fromheaderlet(orig_hlt) numhlt += 1 orig_hlt_hdu.header.update('EXTVER', numhlt) - + if dist_models_equal: # Use the WCSNAME to determine whether or not to archive # Primary WCS as altwcs @@ -2106,7 +2106,7 @@ class Headerlet(pyfits.HDUList): wname = wcsname else: wname = self[0].header['WCSNAME'] - + sciext = self[('SIPWCS', 1)].header['SCIEXT'] try: sciext = int(sciext) @@ -2125,7 +2125,7 @@ class Headerlet(pyfits.HDUList): if close_dest: fobj.close() raise ValueError(mess) - + #numhlt = countExtn(fobj, 'HDRLET') numsip = countExtn(self, 'SIPWCS') for idx in range(1, numsip + 1): @@ -2136,7 +2136,7 @@ class Headerlet(pyfits.HDUList): sciext = fu.parseExtn(sciext) fhdr = fobj[sciext].header siphdr = self[('SIPWCS', idx)].header.ascard - + # a minimal attempt to get the position of the WCS keywords group # in the header by looking for the PA_APER kw. # at least make sure the WCS kw are written before the HISTORY kw @@ -2214,7 +2214,7 @@ class Headerlet(pyfits.HDUList): message += " * Image %s already has headerlet " % (fname) message += "with HDRNAME='%s'\n" % (self.hdrname) logger.critical(message) - + if close_dest: fobj.close() |