summaryrefslogtreecommitdiff
path: root/distortion/utils.py
diff options
context:
space:
mode:
authordencheva <dencheva@stsci.edu>2010-01-25 17:13:05 -0500
committerdencheva <dencheva@stsci.edu>2010-01-25 17:13:05 -0500
commit1c380263a895a6ce91ef24ee9c2c0445df7bbebb (patch)
tree75a3f18b0fd58d6ac5adfb1d3af7520967f3a67d /distortion/utils.py
parentadd5bab6ddb69e48bc6f95e2f0b38e60c4fb9fed (diff)
downloadstwcs_hcf-1c380263a895a6ce91ef24ee9c2c0445df7bbebb.tar.gz
- If idc table is not found and idc model cannot be restored from SIP, idcmodel is always set to None.
- Two cases are considered when output_wcs is created and idcmodel for the reference image is None: -- if idcmodel can be found, a RuntimeError will be raised and the user prompted to run 'updatewcs' or pass 'undistort=False' kw. -- if idcmodel cannot be found, the original WCS for the reference object will be returned and used as an output WCS. git-svn-id: http://svn.stsci.edu/svn/ssb/stsci_python/stsci_python/trunk/stwcs@8640 fe389314-cf27-0410-b35b-8c050e845b92
Diffstat (limited to 'distortion/utils.py')
-rw-r--r--distortion/utils.py31
1 files changed, 29 insertions, 2 deletions
diff --git a/distortion/utils.py b/distortion/utils.py
index 06bf5f8..bc25daf 100644
--- a/distortion/utils.py
+++ b/distortion/utils.py
@@ -1,9 +1,11 @@
from __future__ import division # confidence high
+import os
import numpy as np
import pywcs
import pyfits
from stwcs import wcsutil
from numpy import sqrt, arctan2
+from pytools import fileutil
def output_wcs(list_of_wcsobj, ref_wcs=None, outwcs=None, undistort=True):
fra_dec = np.vstack([w.calcFootprint() for w in list_of_wcsobj])
@@ -52,6 +54,18 @@ def undistortWCS(wcsobj):
import coeff_converter
cx, cy = coeff_converter.sip2idc(wcsobj)
+ # cx, cy can be None because either there is no model available
+ # or updatewcs was not run.
+ if cx == None or cy == None:
+ if foundIDCTAB(wcsobj.idctab):
+ m = """IDCTAB is present but distortion model is missing.
+ Run updatewcs() to update the headers or
+ pass 'undistort=False' keyword to output_wcs().\n
+ """
+ raise RuntimeError, m
+ else:
+ print 'Distortion model is not available, using input reference image for output WCS.\n'
+ return wcsobj.copy()
crpix1 = wcsobj.wcs.crpix[0]
crpix2 = wcsobj.wcs.crpix[1]
xy = np.array([(crpix1,crpix2),(crpix1+1.,crpix2),(crpix1,crpix2+1.)],dtype=np.double)
@@ -75,8 +89,8 @@ def undistortWCS(wcsobj):
if ( _det == 0.0):
print 'Singular matrix in updateWCS, aborting ...'
return
- #lin_wcsobj = wcsutil.HSTWCS(instrument=wcsobj.instrument)
- lin_wcsobj = pywcs.WCS() #instrument=wcsobj.instrument)
+
+ lin_wcsobj = pywcs.WCS()
cd_inv = np.linalg.inv(cd_mat)
lin_wcsobj.wcs.cd = np.dot(wcsobj.wcs.cd, cd_inv)
@@ -120,4 +134,17 @@ def apply_idc(pixpos, cx, cy, pixref, pscale= None, order=None):
return c
+def foundIDCTAB(idctab):
+ idctab_found = True
+ try:
+ idctab = fileutil.osfn(idctab)
+ if idctab == 'N/A' or idctab == "":
+ idctab_found = False
+ if os.path.exists(idctab):
+ idctab_found = True
+ else:
+ idctab_found = False
+ except KeyError:
+ idctab_found = False
+ return idctab_found