From e88d4ce148bd7ea094591543874724cd430b0c59 Mon Sep 17 00:00:00 2001 From: hack Date: Fri, 4 Nov 2011 21:07:32 +0000 Subject: The WCSCORR table update will not crash anymore (based on my testing) when WCSNAME is missing from the image PRIMARY WCS. This required adding a new function to define the default WCSNAME value based on the IDCTAB so that it could be called upon initialization of the table, and when updating it if WCSNAME is missing. git-svn-id: http://svn.stsci.edu/svn/ssb/stsci_python/stsci_python/trunk/stwcs@13961 fe389314-cf27-0410-b35b-8c050e845b92 --- lib/stwcs/updatewcs/utils.py | 6 ++++++ lib/stwcs/wcsutil/wcscorr.py | 10 +++++----- 2 files changed, 11 insertions(+), 5 deletions(-) (limited to 'lib/stwcs') diff --git a/lib/stwcs/updatewcs/utils.py b/lib/stwcs/updatewcs/utils.py index f851522..0e7d77b 100644 --- a/lib/stwcs/updatewcs/utils.py +++ b/lib/stwcs/updatewcs/utils.py @@ -99,6 +99,12 @@ def build_distname(sipname,npolname,d2imname): return distname +def build_default_wcsname(idctab): + + idcname = extract_rootname(idctab,suffix='_idc') + wcsname = 'IDC_' + idcname + return wcsname + def build_sipname(fobj): try: sipname = fobj[0].header["SIPNAME"] diff --git a/lib/stwcs/wcsutil/wcscorr.py b/lib/stwcs/wcsutil/wcscorr.py index 96883c5..3071d0d 100644 --- a/lib/stwcs/wcsutil/wcscorr.py +++ b/lib/stwcs/wcsutil/wcscorr.py @@ -134,10 +134,7 @@ def init_wcscorr(input, force=False): wcskey=uwkey) wcshdr = wcs.wcs2header() if 'WCSNAME' + uwkey not in wcshdr: - idctab = fileutil.osfn(fimg[0].header['idctab']) - idcname = os.path.split(idctab)[-1] - idcname = idcname[:idcname.find('_')] - wcsid = 'IDC_' + idcname + wcsid = utils.build_default_wcsname(fimg[0].header['idctab']) else: wcsid = wcshdr['WCSNAME' + uwkey] @@ -300,7 +297,10 @@ def update_wcscorr(dest, source=None, extname='SCI', wcs_id=None, active=True): else: tab_extver = extver hdr = source[extn].header - wcsname = hdr['WCSNAME' + wcs_key] + if 'WCSNAME'+wcs_key in hdr: + wcsname = hdr['WCSNAME' + wcs_key] + else: + wcsname = utils.build_default_wcsname(hdr['idctab']) selection = {'WCS_ID': wcsname, 'EXTVER': tab_extver, 'SIPNAME':sipname, 'HDRNAME': hdrname, 'NPOLNAME': npolname, 'D2IMNAME':d2imname -- cgit