diff options
-rw-r--r-- | lib/stwcs/wcsutil/headerlet.py | 32 | ||||
-rw-r--r-- | lib/stwcs/wcsutil/hstwcs.py | 47 | ||||
-rw-r--r-- | lib/stwcs/wcsutil/wcscorr.py | 2 |
3 files changed, 64 insertions, 17 deletions
diff --git a/lib/stwcs/wcsutil/headerlet.py b/lib/stwcs/wcsutil/headerlet.py index 2138406..37738f9 100644 --- a/lib/stwcs/wcsutil/headerlet.py +++ b/lib/stwcs/wcsutil/headerlet.py @@ -677,7 +677,7 @@ 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, - rms_ra=None, rms_dec=None, nmatch=None, catalog=None, + nmatch=None, catalog=None, attach=True, clobber=False, logging=False): """ @@ -814,7 +814,6 @@ def write_headerlet(filename, hdrname, output=None, sciext='SCI', sipname=sipname, npolfile=npolfile, d2imfile=d2imfile, author=author, descrip=descrip, history=history, - rms_ra=rms_ra, rms_dec=rms_dec, nmatch=nmatch, catalog=catalog, logging=False) @@ -865,7 +864,7 @@ def create_headerlet(filename, sciext='SCI', hdrname=None, destim=None, wcskey=" ", wcsname=None, sipname=None, npolfile=None, d2imfile=None, author=None, descrip=None, history=None, - rms_ra=None, rms_dec = None, nmatch=None, catalog=None, + nmatch=None, catalog=None, logging=False, logmode='w'): """ Create a headerlet from a WCS in a science file @@ -1041,9 +1040,9 @@ def create_headerlet(filename, sciext='SCI', hdrname=None, destim=None, distname = utils.build_distname(sipname, npolfile, d2imfile) logger.info("Setting distname to %s" % distname) rms_ra = get_header_kw_vals(fobj[wcsext].header, - ("RMS_RA"+wcskey).rstrip(), rms_ra, default=0) + ("CRDER1"+wcskey).rstrip(), None, default=0) rms_dec = get_header_kw_vals(fobj[wcsext].header, - ("RMS_DEC"+wcskey).rstrip(), rms_dec, default=0) + ("CRDER2"+wcskey).rstrip(), None, default=0) nmatch = get_header_kw_vals(fobj[wcsext].header, ("NMATCH"+wcskey).rstrip(), nmatch, default=0) catalog = get_header_kw_vals(fobj[wcsext].header, @@ -1114,10 +1113,6 @@ def create_headerlet(filename, sciext='SCI', hdrname=None, destim=None, h = hwcs.wcs2header(sip2hdr=True) if hasattr(hwcs, 'orientat'): h.update('ORIENTAT', hwcs.orientat, comment=orient_comment) - h.update('RMS_RA', rms_ra, - comment='RMS in RA at ref pix of headerlet solution') - h.update('RMS_DEC', rms_dec, - comment='RMS in Dec at ref pix of headerlet solution') h.update('NMATCH', nmatch, comment='Number of sources used for headerlet solution') h.update('CATALOG', catalog, @@ -1669,7 +1664,7 @@ def archive_as_headerlet(filename, hdrname, sciext='SCI', wcsname=None, wcskey=None, destim=None, sipname=None, npolfile=None, d2imfile=None, author=None, descrip=None, history=None, - rms_ra=None, rms_dec=None, nmatch=None, catalog=None, + nmatch=None, catalog=None, logging=False, logmode='w'): """ Save a WCS as a headerlet extension and write it out to a file. @@ -1775,7 +1770,6 @@ def archive_as_headerlet(filename, hdrname, sciext='SCI', sipname=sipname, npolfile=npolfile, d2imfile=d2imfile, author=author, descrip=descrip, history=history, - rms_ra=rms_ra, rms_dec=rms_dec, nmatch=nmatch, catalog=catalog, logging=False) hlt_hdu = HeaderletHDU.fromheaderlet(hdrletobj) @@ -1838,7 +1832,7 @@ class Headerlet(pyfits.HDUList): self.author = self[0].header["AUTHOR"] self.descrip = self[0].header["DESCRIP"] - self.fit_kws = ['HDRNAME', 'RMS_RA', 'RMS_DEC', 'NMATCH', 'CATALOG'] + self.fit_kws = ['HDRNAME', 'NMATCH', 'CATALOG'] self.history = '' for card in self[0].header['HISTORY*']: self.history += card.value+'\n' @@ -2027,6 +2021,12 @@ class Headerlet(pyfits.HDUList): update_cpdis = True else: pass + # Update WCS with optional CRDER (error) kws from headerlet + if 'crder1' in siphdr: + for kw in siphdr['crder*']: + fhdr.update(kw.key, kw.value, comment=kw.comment, + after='WCSNAME') + # Update WCS with HDRNAME as well for kw in self.fit_kws: fhdr.update(kw, self[0].header[kw], after='WCSNAME') @@ -2373,9 +2373,9 @@ class Headerlet(pyfits.HDUList): """ Builds the DISTNAME for dest based on reference file names. """ - sipname = utils.build_sipname(destim) - npolname = utils.build_npolname(destim) - d2imname = utils.build_d2imname(destim) + sipname = utils.build_sipname(dest) + npolname = utils.build_npolname(dest) + d2imname = utils.build_d2imname(dest) dname = utils.build_distname(sipname,npolname,d2imname) return dname @@ -2450,7 +2450,7 @@ class Headerlet(pyfits.HDUList): (ext.name, ext._extver)) dkeys = altwcs.wcskeys(ext.header) if 'O' in dkeys: dkeys.remove('O') # Do not remove wcskey='O' values - for fitkw in ['RMS_RA', 'RMS_DEC', 'NMATCH', 'CATALOG']: + for fitkw in ['NMATCH', 'CATALOG']: for k in dkeys: fkw = (fitkw+k).rstrip() if fkw in ext.header: diff --git a/lib/stwcs/wcsutil/hstwcs.py b/lib/stwcs/wcsutil/hstwcs.py index d90b4a5..d138f08 100644 --- a/lib/stwcs/wcsutil/hstwcs.py +++ b/lib/stwcs/wcsutil/hstwcs.py @@ -17,6 +17,46 @@ from mappings import basic_wcs __docformat__ = 'restructuredtext' +# +#### Utility functions copied from 'updatewcs.utils' to avoid circular imports +# +def extract_rootname(kwvalue,suffix=""): + """ Returns the rootname from a full reference filename + + If a non-valid value (any of ['','N/A','NONE','INDEF',None]) is input, + simply return a string value of 'NONE' + + This function will also replace any 'suffix' specified with a blank. + """ + # check to see whether a valid kwvalue has been provided as input + if kwvalue.strip() in ['','N/A','NONE','INDEF',None]: + return 'NONE' # no valid value, so return 'NONE' + + # for a valid kwvalue, parse out the rootname + # strip off any environment variable from input filename, if any are given + if '$' in kwvalue: + fullval = kwvalue[kwvalue.find('$')+1:] + else: + fullval = kwvalue + # Extract filename without path from kwvalue + fname = os.path.basename(fullval).strip() + + # Now, rip out just the rootname from the full filename + rootname = fileutil.buildNewRootname(fname) + + # Now, remove any known suffix from rootname + rootname = rootname.replace(suffix,'') + return rootname.strip() + +def build_default_wcsname(idctab): + + idcname = extract_rootname(idctab,suffix='_idc') + wcsname = 'IDC_' + idcname + return wcsname + +# +#### HSTWCS Class definition +# class HSTWCS(WCS): def __init__(self, fobj=None, ext=None, minerr=0.0, wcskey=" "): @@ -283,6 +323,13 @@ class HSTWCS(WCS): if self.wcs.has_cd(): h = altwcs.pc2cd(h, key=self.wcskey) + if 'wcsname' not in h: + if self.idctab is not None: + wname = build_default_wcsname(self.idctab) + else: + wname = 'DEFAULT' + h.update('wcsname',value=wname) + if idc2hdr: for card in self._idc2hdr(): h.update(card.key,value=card.value,comment=card.comment) diff --git a/lib/stwcs/wcsutil/wcscorr.py b/lib/stwcs/wcsutil/wcscorr.py index bdca38e..7c5b387 100644 --- a/lib/stwcs/wcsutil/wcscorr.py +++ b/lib/stwcs/wcsutil/wcscorr.py @@ -12,7 +12,7 @@ DEFAULT_WCS_KEYS = ['CRVAL1','CRVAL2','CRPIX1','CRPIX2', 'CD1_1','CD1_2','CD2_1','CD2_2', 'CTYPE1','CTYPE2','ORIENTAT'] DEFAULT_PRI_KEYS = ['HDRNAME','SIPNAME','NPOLNAME','D2IMNAME','DESCRIP'] -COL_FITSKW_DICT = {'RMS_RA':'sci.rms_ra','RMS_DEC':'sci.rms_dec', +COL_FITSKW_DICT = {'RMS_RA':'sci.crder1','RMS_DEC':'sci.crder2', 'NMatch':'sci.nmatch','Catalog':'sci.catalog'} ### |