From b5f4204747f7e4105049713b40d7bca0fae052e5 Mon Sep 17 00:00:00 2001 From: hack Date: Tue, 25 Oct 2011 21:25:35 +0000 Subject: Merging changes from 'stwcs_hdrlet' branch (r18787 - r13909) into trunk. This version of STWCS (0.9.1) provides support for headerlets based on 'Headerlet Design' wiki document, and includes TEAL interfaces for all public headerlet functions. It also moves the TEAL interface for 'updatewcs' from 'astrodither' to this package. The TEAL interaces have been included as a new 'gui' sub-package in order to keep them separate from the remainder of the package's functionality. git-svn-id: http://svn.stsci.edu/svn/ssb/stsci_python/stsci_python/trunk/stwcs@13910 fe389314-cf27-0410-b35b-8c050e845b92 --- lib/stwcs/updatewcs/utils.py | 53 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 48 insertions(+), 5 deletions(-) (limited to 'lib/stwcs/updatewcs/utils.py') diff --git a/lib/stwcs/updatewcs/utils.py b/lib/stwcs/updatewcs/utils.py index b7fe7c4..b761efc 100644 --- a/lib/stwcs/updatewcs/utils.py +++ b/lib/stwcs/updatewcs/utils.py @@ -57,7 +57,7 @@ def extract_rootname(kwvalue): else: rootname = fname - return rootname + return rootname.strip() def construct_distname(fobj,wcsobj): """ @@ -73,15 +73,24 @@ def construct_distname(fobj,wcsobj): if idcname is None and wcsobj.sip is not None: idcname = 'UNKNOWN' - npolname = extract_rootname(fobj[0].header.get('NPOLFILE', "NONE")) + npolname = build_npolname(fobj) if npolname is None and wcsobj.cpdis1 is not None: npolname = 'UNKNOWN' - d2imname = extract_rootname(fobj[0].header.get('D2IMFILE', "NONE")) + d2imname = build_d2imname(fobj) if d2imname is None and wcsobj.det2im is not None: d2imname = 'UNKNOWN' - sipname = '%s_%s'%(fobj[0].header.get('rootname',""),idcname) + sipname = build_sipname(fobj) + + distname = build_distname(sipname,npolname,d2imname) + return {'DISTNAME':distname,'SIPNAME':sipname} + +def build_distname(sipname,npolname,d2imname): + """ + Core function to build DISTNAME keyword value without the HSTWCS input. + """ + distname = sipname.strip() if npolname != 'NONE' or d2imname != 'NONE': if d2imname != 'NONE': @@ -89,4 +98,38 @@ def construct_distname(fobj,wcsobj): else: distname+='-'+npolname.strip() - return {'DISTNAME':distname,'SIPNAME':sipname} \ No newline at end of file + return distname + +def build_sipname(fobj): + try: + sipname = fobj[0].header["SIPNAME"] + except KeyError: + try: + sipname = fobj[0].header['rootname']+'_'+ \ + extract_rootname(fobj[0].header["IDCTAB"]) + except KeyError: + if 'A_ORDER' in fobj[1].header or 'B_ORDER' in fobj[1].header: + sipname = 'UNKNOWN' + else: + sipname = 'NOMODEL' + return sipname + +def build_npolname(fobj): + try: + npolfile = extract_rootname(fobj[0].header["NPOLFILE"]) + except KeyError: + if countExtn(f, 'WCSDVARR'): + npolfile = 'UNKNOWN' + else: + npolfile = 'NOMODEL' + return npolfile + +def build_d2imname(fobj): + try: + d2imfile = extract_rootname(fobj[0].header["D2IMFILE"]) + except KeyError: + if countExtn(f, 'D2IMARR'): + d2imfile = 'UNKNOWN' + else: + d2imfile = 'NOMODEL' + return d2imfile \ No newline at end of file -- cgit