diff options
Diffstat (limited to 'lib/stwcs/updatewcs')
-rw-r--r-- | lib/stwcs/updatewcs/__init__.py | 45 | ||||
-rw-r--r-- | lib/stwcs/updatewcs/apply_corrections.py | 80 | ||||
-rw-r--r-- | lib/stwcs/updatewcs/det2im.py | 18 | ||||
-rw-r--r-- | lib/stwcs/updatewcs/npol.py | 138 |
4 files changed, 145 insertions, 136 deletions
diff --git a/lib/stwcs/updatewcs/__init__.py b/lib/stwcs/updatewcs/__init__.py index 4859343..622ac35 100644 --- a/lib/stwcs/updatewcs/__init__.py +++ b/lib/stwcs/updatewcs/__init__.py @@ -11,7 +11,7 @@ try: from pywcs import __version__ as pywcsversion except: pywcsversion = 'UNKNOWN' - + import utils, corrections, makewcs import npol, det2im from stsci.tools import parseinput, fileutil @@ -100,7 +100,7 @@ def updatewcs(input, vacorr=True, tddcorr=True, npolcorr=True, d2imcorr=True, cleanWCS(f) makecorr(f, acorr) - + return files def makecorr(fname, allowed_corr): @@ -153,14 +153,14 @@ def makecorr(fname, allowed_corr): utils.extract_rootname(idcname,suffix='_idc')]) else: wname = " " hdr.update('WCSNAME', wname) - + elif extname in ['err', 'dq', 'sdq', 'samp', 'time']: cextver = extn.header['extver'] if cextver == sciextver: hdr = f[('SCI',sciextver)].header w = pywcs.WCS(hdr, f) copyWCS(w, extn.header) - + else: continue @@ -170,28 +170,30 @@ def makecorr(fname, allowed_corr): f[1].header.update(kw, kw2update[kw]) # Finally record the version of the software which updated the WCS if f[0].header.has_key('HISTORY'): - f[0].header.update(key='UPWCSVER', value=stwcsversion, + f[0].header.update(key='UPWCSVER', value=stwcsversion, comment="Version of STWCS used to updated the WCS", before='HISTORY') - f[0].header.update(key='PYWCSVER', value=pywcsversion, + f[0].header.update(key='PYWCSVER', value=pywcsversion, comment="Version of PYWCS used to updated the WCS", before='HISTORY') elif f[0].header.has_key('ASN_MTYP'): - f[0].header.update(key='UPWCSVER', value=stwcsversion, + f[0].header.update(key='UPWCSVER', value=stwcsversion, comment="Version of STWCS used to updated the WCS", after='ASN_MTYP') - f[0].header.update(key='PYWCSVER', value=pywcsversion, + f[0].header.update(key='PYWCSVER', value=pywcsversion, comment="Version of PYWCS used to updated the WCS", after='ASN_MTYP') else: # Find index of last non-blank card, and insert this new keyword after that card - for i in range(len(f[0].header.ascard)-1,0,-1): - if f[0].header[i].strip() != '': - break - f[0].header.update(key='UPWCSVER', value=stwcsversion, - comment="Version of STWCS used to updated the WCS",after=i) - f[0].header.update(key='PYWCSVER', value=pywcsversion, - comment="Version of PYWCS used to updated the WCS",after=i) + for i in range(len(f[0].header) - 1, 0, -1): + if f[0].header[i].strip() != '': + break + f[0].header.set('UPWCSVER', stwcsversion, + "Version of STWCS used to updated the WCS", + after=i) + f[0].header.set('PYWCSVER', pywcsversion, + "Version of PYWCS used to updated the WCS", + after=i) # add additional keywords to be used by headerlets distdict = utils.construct_distname(f,rwcs) - f[0].header.update('DISTNAME', distdict['DISTNAME']) - f[0].header.update('SIPNAME', distdict['SIPNAME']) + f[0].header['DISTNAME'] = distdict['DISTNAME'] + f[0].header['SIPNAME'] = distdict['SIPNAME'] f.close() def copyWCS(w, ehdr): @@ -330,10 +332,11 @@ def checkFiles(input): def newIDCTAB(fname): #When this is called we know there's a kw IDCTAB in the header - idctab = fileutil.osfn(pyfits.getval(fname, 'IDCTAB')) + hdul = pyfits.open(fname) + idctab = fileutil.osfn(hdul[0].header['IDCTAB']) try: #check for the presence of IDCTAB in the first extension - oldidctab = fileutil.osfn(pyfits.getval(fname, 'IDCTAB', ext=1)) + oldidctab = fileutil.osfn(hdul[1].header['IDCTAB']) except KeyError: return False if idctab == oldidctab: @@ -344,11 +347,11 @@ def newIDCTAB(fname): def cleanWCS(fname): # A new IDCTAB means all previously computed WCS's are invalid # We are deleting all of them except the original OPUS WCS.nvalidates all WCS's. - keys = wcsutil.wcskeys(pyfits.getheader(fname, ext=1)) f = pyfits.open(fname, mode='update') + keys = wcsutil.wcskeys(f[1].header) fext = range(len(f)) for key in keys: - wcsutil.deleteWCS(fname, ext=fext,wcskey=key) + wcsutil.deleteWCS(fname, ext=fext, wcskey=key) def getCorrections(instrument): """ diff --git a/lib/stwcs/updatewcs/apply_corrections.py b/lib/stwcs/updatewcs/apply_corrections.py index fbcb502..fe1c1af 100644 --- a/lib/stwcs/updatewcs/apply_corrections.py +++ b/lib/stwcs/updatewcs/apply_corrections.py @@ -31,7 +31,7 @@ cnames = {'DET2IMCorr': 'Detector to Image Correction', 'VACorr': 'Velocity Aberration Correction', 'NPOLCorr': 'Lookup Table Distortion' } - + def setCorrections(fname, vacorr=True, tddcorr=True, npolcorr=True, d2imcorr=True): """ Creates a list of corrections to be applied to a file @@ -41,20 +41,20 @@ def setCorrections(fname, vacorr=True, tddcorr=True, npolcorr=True, d2imcorr=Tru instrument = pyfits.getval(fname, 'INSTRUME') # make a copy of this list ! acorr = allowed_corrections[instrument][:] - + # Check if idctab is present on disk - # If kw IDCTAB is present in the header but the file is + # If kw IDCTAB is present in the header but the file is # not found on disk, do not run TDDCorr, MakeCWS and CompSIP if not foundIDCTAB(fname): if 'TDDCorr' in acorr: acorr.remove('TDDCorr') if 'MakeWCS' in acorr: acorr.remove('MakeWCS') - if 'CompSIP' in acorr: acorr.remove('CompSIP') - + if 'CompSIP' in acorr: acorr.remove('CompSIP') + if 'VACorr' in acorr and vacorr==False: acorr.remove('VACorr') if 'TDDCorr' in acorr: tddcorr = applyTDDCorr(fname, tddcorr) if tddcorr == False: acorr.remove('TDDCorr') - + if 'NPOLCorr' in acorr: npolcorr = applyNpolCorr(fname, npolcorr) if npolcorr == False: acorr.remove('NPOLCorr') @@ -69,13 +69,13 @@ def foundIDCTAB(fname): idctab = fileutil.osfn(pyfits.getval(fname, 'IDCTAB')) except KeyError: return False - if idctab == 'N/A' or idctab == "": + if idctab == 'N/A' or idctab == "": return False if os.path.exists(idctab): return True else: return False - + def applyTDDCorr(fname, utddcorr): """ The default value of tddcorr for all ACS images is True. @@ -84,20 +84,22 @@ def applyTDDCorr(fname, utddcorr): - the detector is WFC - the idc table specified in the primary header is available. """ - instrument = pyfits.getval(fname, 'INSTRUME') + + phdr = pyfits.getheader(fname) + instrument = phdr['INSTRUME'] try: - detector = pyfits.getval(fname, 'DETECTOR') + detector = phdr['DETECTOR'] except KeyError: detector = None try: - tddswitch = pyfits.getval(fname, 'TDDCORR') + tddswitch = phdr['TDDCORR'] except KeyError: tddswitch = 'PERFORM' - + if instrument == 'ACS' and detector == 'WFC' and utddcorr == True and tddswitch == 'PERFORM': tddcorr = True try: - idctab = pyfits.getval(fname, 'IDCTAB') + idctab = phdr['IDCTAB'] except KeyError: tddcorr = False #print "***IDCTAB keyword not found - not applying TDD correction***\n" @@ -106,21 +108,21 @@ def applyTDDCorr(fname, utddcorr): else: tddcorr = False #print "***IDCTAB file not found - not applying TDD correction***\n" - else: + else: tddcorr = False return tddcorr def applyNpolCorr(fname, unpolcorr): """ - Determines whether non-polynomial distortion lookup tables should be added - as extensions to the science file based on the 'NPOLFILE' keyword in the + Determines whether non-polynomial distortion lookup tables should be added + as extensions to the science file based on the 'NPOLFILE' keyword in the primary header and NPOLEXT kw in the first extension. This is a default correction and will always run in the pipeline. - The file used to generate the extensions is + The file used to generate the extensions is recorded in the NPOLEXT keyword in the first science extension. - If 'NPOLFILE' in the primary header is different from 'NPOLEXT' in the - extension header and the file exists on disk and is a 'new type' npolfile, + If 'NPOLFILE' in the primary header is different from 'NPOLEXT' in the + extension header and the file exists on disk and is a 'new type' npolfile, then the lookup tables will be updated as 'WCSDVARR' extensions. """ applyNPOLCorr = True @@ -136,7 +138,7 @@ def applyNpolCorr(fname, unpolcorr): """ % fnpol0 logger.critical(msg) applyNPOLCorr = False - return applyNPOLCorr + return applyNPOLCorr try: # get NPOLEXT kw from first extension header fnpol1 = pyfits.getval(fname, 'NPOLEXT', ext=1) @@ -149,32 +151,34 @@ def applyNpolCorr(fname, unpolcorr): NPOL correction will not be applied.""" logger.info(msg) applyNPOLCorr = False - else: + else: # npl file defined in first extension may not be found - # but if a valid kw exists in the primary header, non-polynomial + # but if a valid kw exists in the primary header, non-polynomial #distortion correction should be applied. applyNPOLCorr = True except KeyError: - # the case of "NPOLFILE" kw present in primary header but "NPOLEXT" missing + # the case of "NPOLFILE" kw present in primary header but "NPOLEXT" missing # in first extension header applyNPOLCorr = True except KeyError: logger.info('\n\t"NPOLFILE" keyword not found in primary header') applyNPOLCorr = False - return applyNPOLCorr - + return applyNPOLCorr + if isOldStyleDGEO(fname, fnpol0): - applyNPOLCorr = False + applyNPOLCorr = False return (applyNPOLCorr and unpolcorr) def isOldStyleDGEO(fname, dgname): - # checks if the file defined in a NPOLFILE kw is a full size + # checks if the file defined in a NPOLFILE kw is a full size # (old style) image - - sci_naxis1 = pyfits.getval(fname, 'NAXIS1', ext=1) - sci_naxis2 = pyfits.getval(fname, 'NAXIS2', ext=1) - dg_naxis1 = pyfits.getval(dgname, 'NAXIS1', ext=1) - dg_naxis2 = pyfits.getval(dgname, 'NAXIS2', ext=1) + + sci_hdr = pyfits.getheader(fname, ext=1) + dgeo_hdr = pyfits.getheader(dgname, ext=1) + sci_naxis1 = sci_hdr['NAXIS1'] + sci_naxis2 = sci_hdr['NAXIS2'] + dg_naxis1 = dgeo_hdr['NAXIS1'] + dg_naxis2 = dgeo_hdr['NAXIS2'] if sci_naxis1 <= dg_naxis1 or sci_naxis2 <= dg_naxis2: msg = """\n\tOnly full size (old style) DGEO file was found.\n Non-polynomial distortion correction will not be applied.""" @@ -182,7 +186,7 @@ def isOldStyleDGEO(fname, dgname): return True else: return False - + def applyD2ImCorr(fname, d2imcorr): applyD2IMCorr = True try: @@ -197,7 +201,7 @@ def applyD2ImCorr(fname, d2imcorr): logger.critical(msg) print msg applyD2IMCorr = False - return applyD2IMCorr + return applyD2IMCorr try: # get D2IMEXT kw from first extension header fd2imext = pyfits.getval(fname, 'D2IMEXT', ext=1) @@ -207,17 +211,17 @@ def applyD2ImCorr(fname, d2imcorr): applyD2IMCorr = True else: applyD2IMCorr = False - else: + else: # D2IM file defined in first extension may not be found - # but if a valid kw exists in the primary header, + # but if a valid kw exists in the primary header, # detector to image correction should be applied. applyD2IMCorr = True except KeyError: - # the case of D2IMFILE kw present in primary header but D2IMEXT missing + # the case of D2IMFILE kw present in primary header but D2IMEXT missing # in first extension header applyD2IMCorr = True except KeyError: print 'D2IMFILE keyword not found in primary header' applyD2IMCorr = False - return applyD2IMCorr + return applyD2IMCorr diff --git a/lib/stwcs/updatewcs/det2im.py b/lib/stwcs/updatewcs/det2im.py index b658d53..8235d83 100644 --- a/lib/stwcs/updatewcs/det2im.py +++ b/lib/stwcs/updatewcs/det2im.py @@ -126,8 +126,11 @@ class DET2IMCorr(object): 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 ) + d2im = pyfits.open(d2imfile) + data_shape = d2im[1].shape + naxis = d2im[1].header['NAXIS'] + d2im_phdr = d2im[0].header + d2im.close() kw = { 'NAXIS': 'Size of the axis', 'CRPIX': 'Coordinate system reference pixel', @@ -170,24 +173,23 @@ class DET2IMCorr(object): } - cdl = pyfits.CardList() + cdl = [] for key in kw_comm0.keys(): - cdl.append(pyfits.Card(key=key, value=kw_val0[key], comment=kw_comm0[key])) + cdl.append((key, kw_val0[key], kw_comm0[key])) for key in kw_comm1.keys(): - cdl.append(pyfits.Card(key=key, value=kw_val1[key], comment=kw_comm1[key])) + cdl.append((key, kw_val1[key], kw_comm1[key])) # Now add keywords from NPOLFILE header to document source of calibration # include all keywords after and including 'FILENAME' from header - d2im_phdr = pyfits.getheader(d2imfile) start_indx = -1 end_indx = 0 - for c,i in zip(d2im_phdr,range(len(d2im_phdr))): + for i, c in enumerate(d2im_phdr): if c == 'FILENAME': start_indx = i if c == '': # remove blanks from end of header end_indx = i+1 break if start_indx >= 0: - for card in d2im_phdr[start_indx:end_indx]: + for card in d2im_phdr.cards[start_indx:end_indx]: cdl.append(card) hdr = pyfits.Header(cards=cdl) diff --git a/lib/stwcs/updatewcs/npol.py b/lib/stwcs/updatewcs/npol.py index 2607e48..a7b84da 100644 --- a/lib/stwcs/updatewcs/npol.py +++ b/lib/stwcs/updatewcs/npol.py @@ -11,35 +11,35 @@ logger = logging.getLogger('stwcs.updatewcs.npol') class NPOLCorr(object): """ Defines a Lookup table prior distortion correction as per WCS paper IV. - It uses a reference file defined by the NPOLFILE (suffix 'NPL') keyword + It uses a reference file defined by the NPOLFILE (suffix 'NPL') keyword in the primary header. - + Notes ----- - - Using extensions in the reference file create a WCSDVARR extensions + - Using extensions in the reference file create a WCSDVARR extensions and add them to the science file. - - Add record-valued keywords to the science extension header to describe + - Add record-valued keywords to the science extension header to describe the lookup tables. - Add a keyword 'NPOLEXT' to the science extension header to store the name of the reference file used to create the WCSDVARR extensions. - - If WCSDVARR extensions exist and `NPOLFILE` is different from `NPOLEXT`, - a subsequent update will overwrite the existing extensions. + + If WCSDVARR extensions exist and `NPOLFILE` is different from `NPOLEXT`, + a subsequent update will overwrite the existing extensions. If WCSDVARR extensions were not found in the science file, they will be added. - + It is assumed that the NPL reference files were created to work with IDC tables - but will be applied with SIP coefficients. A transformation is applied to correct + but will be applied with SIP coefficients. A transformation is applied to correct for the fact that the lookup tables will be applied before the first order coefficients which are in the CD matrix when the SIP convention is used. """ - + def updateWCS(cls, fobj): """ Parameters ---------- fobj: pyfits object Science file, for which a distortion correction in a NPOLFILE is available - + """ logger.info("\n\tStarting CompSIP: %s" %time.asctime()) try: @@ -47,14 +47,14 @@ class NPOLCorr(object): except AssertionError: logger.exception('\n\tInput must be a pyfits.HDUList object') raise - + cls.applyNPOLCorr(fobj) nplfile = fobj[0].header['NPOLFILE'] - + new_kw = {'NPOLEXT': nplfile} return new_kw - - updateWCS = classmethod(updateWCS) + + updateWCS = classmethod(updateWCS) def applyNPOLCorr(cls, fobj): """ @@ -79,15 +79,15 @@ class NPOLCorr(object): # get the data arrays from the reference file and transform them for use with SIP dx,dy = cls.getData(nplfile, ccdchip) idccoeffs = cls.getIDCCoeffs(header) - + if idccoeffs != None: dx, dy = cls.transformData(dx,dy, idccoeffs) - + # Determine EXTVER for the WCSDVARR extension from the NPL file (EXTNAME, EXTVER) kw. # This is used to populate DPj.EXTVER kw wcsdvarr_x_version = 2 * extversion -1 - wcsdvarr_y_version = 2 * extversion - + wcsdvarr_y_version = 2 * extversion + for ename in zip(['DX', 'DY'], [wcsdvarr_x_version,wcsdvarr_y_version],[dx, dy]): cls.addSciExtKw(header, wdvarr_ver=ename[1], npol_extname=ename[0]) hdu = cls.createNpolHDU(header, npolfile=nplfile, \ @@ -96,14 +96,14 @@ class NPOLCorr(object): fobj[wcsdvarr_ind[ename[1]]] = hdu else: fobj.append(hdu) - - + + applyNPOLCorr = classmethod(applyNPOLCorr) - + def getWCSIndex(cls, fobj): - + """ - If fobj has WCSDVARR extensions: + If fobj has WCSDVARR extensions: returns a mapping of their EXTVER kw to file object extension numbers if fobj does not have WCSDVARR extensions: an empty dictionary is returned @@ -118,19 +118,19 @@ class NPOLCorr(object): wcsd[fobj[e].header['EXTVER']] = e logger.debug("A map of WSCDVARR externsions %s" % wcsd) return wcsd - + getWCSIndex = classmethod(getWCSIndex) - + def addSciExtKw(cls, hdr, wdvarr_ver=None, npol_extname=None): """ Adds kw to sci extension to define WCSDVARR lookup table extensions - + """ if npol_extname =='DX': j=1 else: j=2 - + cperror = 'CPERROR%s' %j cpdis = 'CPDIS%s' %j dpext = 'DP%s.' %j + 'EXTVER' @@ -140,24 +140,24 @@ class NPOLCorr(object): keys = [cperror, cpdis, dpext, dpnaxes, dpaxis1, dpaxis2] values = {cperror: 0.0, cpdis: 'Lookup', dpext: wdvarr_ver, dpnaxes: 2, dpaxis1: 1, dpaxis2: 2} - - comments = {cperror: 'Maximum error of NPOL correction for axis %s' % j, - cpdis: 'Prior distortion funcion type', - dpext: 'Version number of WCSDVARR extension containing lookup distortion table', + + comments = {cperror: 'Maximum error of NPOL correction for axis %s' % j, + cpdis: 'Prior distortion funcion type', + dpext: 'Version number of WCSDVARR extension containing lookup distortion table', dpnaxes: 'Number of independent variables in distortion function', - dpaxis1: 'Axis number of the jth independent variable in a distortion function', + dpaxis1: 'Axis number of the jth independent variable in a distortion function', dpaxis2: 'Axis number of the jth independent variable in a distortion function' } # Look for HISTORY keywords. If present, insert new keywords before them - before_key = 'HISTORY' - if before_key not in hdr.ascard: + before_key = 'HISTORY' + if before_key not in hdr: before_key = None for key in keys: hdr.update(key=key, value=values[key], comment=comments[key], before=before_key) - + addSciExtKw = classmethod(addSciExtKw) - + def getData(cls,nplfile, ccdchip): """ Get the data arrays from the reference NPOL files @@ -178,7 +178,7 @@ class NPOLCorr(object): npl.close() return xdata, ydata getData = classmethod(getData) - + def transformData(cls, dx, dy, coeffs): """ Transform the NPOL data arrays for use with SIP @@ -187,9 +187,9 @@ class NPOLCorr(object): ndx.shape = dx.shape ndy.shape=dy.shape return ndx, ndy - + transformData = classmethod(transformData) - + def getIDCCoeffs(cls, header): """ Return a matrix of the scaled first order IDC coefficients. @@ -209,11 +209,11 @@ class NPOLCorr(object): except KeyError: logger.exception("IDCSCALE not found in header - setting it to 1.") idcscale = 1 - + return np.linalg.inv(coeffs/idcscale) - + getIDCCoeffs = classmethod(getIDCCoeffs) - + def createNpolHDU(cls, sciheader, npolfile=None, wdvarr_ver=1, npl_extname=None,data = None, ccdchip=1, binned=1): """ Creates an HDU to be added to the file object. @@ -221,15 +221,15 @@ class NPOLCorr(object): hdr = cls.createNpolHdr(sciheader, npolfile=npolfile, wdvarr_ver=wdvarr_ver, npl_extname=npl_extname, ccdchip=ccdchip, binned=binned) hdu=pyfits.ImageHDU(header=hdr, data=data) return hdu - + createNpolHDU = classmethod(createNpolHDU) - + def createNpolHdr(cls, sciheader, npolfile, wdvarr_ver, npl_extname, ccdchip, binned): """ - Creates a header for the WCSDVARR extension based on the NPOL reference file + Creates a header for the WCSDVARR extension based on the NPOL reference file and sci extension header. The goal is to always work in image coordinates - (also for subarrays and binned images. The WCS for the WCSDVARR extension - i ssuch that a full size npol table is created and then shifted or scaled + (also for subarrays and binned images. The WCS for the WCSDVARR extension + i ssuch that a full size npol table is created and then shifted or scaled if the science image is a subarray or binned image. """ npl = pyfits.open(npolfile) @@ -247,30 +247,30 @@ class NPOLCorr(object): else: continue npl.close() - - naxis = pyfits.getval(npolfile, 'NAXIS', ext=1) + + naxis = npl[1].header['NAXIS'] ccdchip = nplextname #npol_header['CCDCHIP'] - - kw = { 'NAXIS': 'Size of the axis', + + kw = { 'NAXIS': 'Size of the axis', 'CDELT': 'Coordinate increment along axis', - 'CRPIX': 'Coordinate system reference pixel', + 'CRPIX': 'Coordinate system reference pixel', 'CRVAL': 'Coordinate system value at reference pixel', } - + 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] = npol_header.get('NAXIS'+si) kw_val1['CDELT'+si] = npol_header.get('CDELT'+si, 1.0) kw_val1['CRPIX'+si] = npol_header.get('CRPIX'+si, 0.0) kw_val1['CRVAL'+si] = npol_header.get('CRVAL'+si, 0.0) - + kw_comm0 = {'XTENSION': 'Image extension', 'BITPIX': 'IEEE floating point', 'NAXIS': 'Number of axes', @@ -279,7 +279,7 @@ class NPOLCorr(object): 'PCOUNT': 'Special data area of size 0', 'GCOUNT': 'One data group', } - + kw_val0 = { 'XTENSION': 'IMAGE', 'BITPIX': -32, 'NAXIS': naxis, @@ -289,32 +289,32 @@ class NPOLCorr(object): 'GCOUNT': 1, 'CCDCHIP': ccdchip, } - - cdl = pyfits.CardList() + + cdl = [] for key in kw_comm0.keys(): - cdl.append(pyfits.Card(key=key, value=kw_val0[key], comment=kw_comm0[key])) + cdl.append((key, kw_val0[key], kw_comm0[key])) for key in kw_comm1.keys(): - cdl.append(pyfits.Card(key=key, value=kw_val1[key], comment=kw_comm1[key])) + cdl.append((key, kw_val1[key], kw_comm1[key])) # Now add keywords from NPOLFILE header to document source of calibration # include all keywords after and including 'FILENAME' from header start_indx = -1 end_indx = 0 - for c,i in zip(npol_phdr,range(len(npol_phdr))): + for i, c in enumerate(npol_phdr): if c == 'FILENAME': start_indx = i if c == '': # remove blanks from end of header end_indx = i+1 break if start_indx >= 0: - for card in npol_phdr[start_indx:end_indx]: + for card in npol_phdr.cards[start_indx:end_indx]: cdl.append(card) - + hdr = pyfits.Header(cards=cdl) - + return hdr - + createNpolHdr = classmethod(createNpolHdr) - + def get_ccdchip(cls, fobj, extname, extver): """ Given a science file or npol file determine CCDCHIP @@ -331,6 +331,6 @@ class NPOLCorr(object): elif fobj[0].header['INSTRUME'] == 'NICMOS': ccdchip = fobj[extname, extver].header['CAMERA'] return ccdchip - + get_ccdchip = classmethod(get_ccdchip) -
\ No newline at end of file + |