diff options
Diffstat (limited to 'lib/stwcs/distortion')
-rw-r--r-- | lib/stwcs/distortion/coeff_converter.py | 18 | ||||
-rw-r--r-- | lib/stwcs/distortion/models.py | 24 | ||||
-rw-r--r-- | lib/stwcs/distortion/mutil.py | 38 | ||||
-rw-r--r-- | lib/stwcs/distortion/utils.py | 15 |
4 files changed, 48 insertions, 47 deletions
diff --git a/lib/stwcs/distortion/coeff_converter.py b/lib/stwcs/distortion/coeff_converter.py index aace72f..415b512 100644 --- a/lib/stwcs/distortion/coeff_converter.py +++ b/lib/stwcs/distortion/coeff_converter.py @@ -1,4 +1,4 @@ -from __future__ import division # confidence high +from __future__ import division, print_function # confidence high import numpy as np from astropy.io import fits @@ -20,7 +20,7 @@ def sip2idc(wcs): order = wcs.get('A_ORDER', None) sipa, sipb = _read_sip_kw(wcs) if None in [ocx10, ocx11, ocy10, ocy11, sipa, sipb]: - print 'Cannot convert SIP to IDC coefficients.\n' + print('Cannot convert SIP to IDC coefficients.\n') return None, None elif isinstance(wcs, pywcs.WCS): try: @@ -29,29 +29,29 @@ def sip2idc(wcs): ocy10 = wcs.ocy10 ocy11 = wcs.ocy11 except AttributeError: - print 'First order IDCTAB coefficients are not available.\n' - print 'Cannot convert SIP to IDC coefficients.\n' + print('First order IDCTAB coefficients are not available.\n') + print('Cannot convert SIP to IDC coefficients.\n') return None, None try: sipa = wcs.sip.a sipb = wcs.sip.b except AttributeError: - print 'SIP coefficients are not available.' - print 'Cannot convert SIP to IDC coefficients.\n' + print('SIP coefficients are not available.') + print('Cannot convert SIP to IDC coefficients.\n') return None, None try: order = wcs.sip.a_order except AttributeError: - print 'SIP model order unknown, exiting ...\n' + print('SIP model order unknown, exiting ...\n') return None, None else: - print 'Input to sip2idc must be a PyFITS header or a wcsutil.HSTWCS object\n' + print('Input to sip2idc must be a PyFITS header or a wcsutil.HSTWCS object\n') return if None in [ocx10, ocx11, ocy10, ocy11]: - print 'First order IDC coefficients not found, exiting ...\n' + print('First order IDC coefficients not found, exiting ...\n') return None, None idc_coeff = np.array([[ocx11, ocx10], [ocy11, ocy10]]) cx = np.zeros((order+1,order+1), dtype=np.double) diff --git a/lib/stwcs/distortion/models.py b/lib/stwcs/distortion/models.py index 3e7d2b4..231a9f1 100644 --- a/lib/stwcs/distortion/models.py +++ b/lib/stwcs/distortion/models.py @@ -1,11 +1,11 @@ -from __future__ import division # confidence high +from __future__ import absolute_import, division, print_function # confidence high + -import types -# Import PyDrizzle utility modules -import mutil import numpy as np -import mutil -from mutil import combin + +# Import PyDrizzle utility modules +from . import mutil +from .mutil import combin yes = True no = False @@ -76,14 +76,14 @@ class GeometryModel: _cys = np.zeros(shape=self.cy.shape,dtype=self.cy.dtype) _k = self.norder + 1 # loop over each input coefficient - for m in xrange(_k): - for n in xrange(_k): + for m in range(_k): + for n in range(_k): if m >= n: # For this coefficient, shift by xs/ys. - _ilist = range(m, _k) + _ilist = list(range(m, _k)) # sum from m to k for i in _ilist: - _jlist = range(n, i - (m-n)+1) + _jlist = list(range(n, i - (m-n)+1)) # sum from n to i-(m-n) for j in _jlist: _cxs[m,n] += self.cx[i,j]*combin(j,n)*combin((i-j),(m-n))*pow(xs,(j-n))*pow(ys,((i-j)-(m-n))) @@ -156,7 +156,7 @@ class GeometryModel: elif self.norder==5: lines.append('quintic\n') else: - raise ValueError, "Drizzle cannot handle poly distortions of order %d"%self.norder + raise ValueError("Drizzle cannot handle poly distortions of order %d" % self.norder) str = '%16.8f %16.8g %16.8g %16.8g %16.8g \n'% (x0,cx[1,1],cx[1,0],cx[2,2],cx[2,1]) lines.append(str) @@ -219,7 +219,7 @@ class GeometryModel: _cx[0,0] = 0. _cy[0,0] = 0. - if isinstance(_p,types.ListType) or isinstance(_p,types.TupleType): + if isinstance(_p, list) or isinstance(_p, tuple): _p = np.array(_p,dtype=np.float64) _convert = yes diff --git a/lib/stwcs/distortion/mutil.py b/lib/stwcs/distortion/mutil.py index d116bbf..aa9d167 100644 --- a/lib/stwcs/distortion/mutil.py +++ b/lib/stwcs/distortion/mutil.py @@ -1,4 +1,4 @@ -from __future__ import division # confidence high +from __future__ import division, print_function # confidence high from stsci.tools import fileutil import numpy as np @@ -34,7 +34,7 @@ def readIDCtab (tabname, chip=1, date=None, direction='forward', # Return a default geometry model if no IDCTAB filename # is given. This model will not distort the data in any way. if tabname == None: - print 'Warning: No IDCTAB specified! No distortion correction will be applied.' + print('Warning: No IDCTAB specified! No distortion correction will be applied.') return defaultModel() # Implement default values for filters here to avoid the default @@ -62,7 +62,7 @@ def readIDCtab (tabname, chip=1, date=None, direction='forward', err_str += "present run will continue using the old coefficients provided in \n" err_str += "the Dither Package (ca. 1995-1998). \n" err_str += "------------------------------------------------------------------------ \n" - raise IOError,err_str + raise IOError(err_str) #First thing we need, is to read in the coefficients from the IDC # table and populate the Fx and Fy matrices. @@ -108,7 +108,7 @@ def readIDCtab (tabname, chip=1, date=None, direction='forward', # Loop over all the rows looking for the one which corresponds # to the value of CCDCHIP we are working on... - for i in xrange(fshape[0]): + for i in range(fshape[0]): try: # Match FILTER combo to appropriate row, @@ -178,9 +178,9 @@ def readIDCtab (tabname, chip=1, date=None, direction='forward', err_str += ' FILTERS: '+filtstr+'\n' ftab.close() del ftab - raise LookupError,err_str + raise LookupError(err_str) else: - print '- IDCTAB: Distortion model from row',str(row+1),'for chip',detchip,':',filtstr + print('- IDCTAB: Distortion model from row',str(row+1),'for chip',detchip,':',filtstr) # Read in V2REF and V3REF: this can either come from current table, # or from an OFFTAB if time-dependent (i.e., for WFPC2) @@ -227,9 +227,9 @@ def readIDCtab (tabname, chip=1, date=None, direction='forward', cxstr = 'A' cystr = 'B' - for i in xrange(norder+1): + for i in range(norder+1): if i > 0: - for j in xrange(i+1): + for j in range(i+1): xcname = cxstr+str(i)+str(j) ycname = cystr+str(i)+str(j) fx[i,j] = ftab[1].data.field(xcname)[row] @@ -307,7 +307,7 @@ def read_tdd_coeffs(phdr, chip=1): if "TDDORDER" in phdr: n = int(phdr["TDDORDER"]) else: - print ('TDDORDER kw not present, using default TDD correction') + print('TDDORDER kw not present, using default TDD correction') return None a = np.zeros((n+1,), np.float64) @@ -316,7 +316,7 @@ def read_tdd_coeffs(phdr, chip=1): a[i] = phdr.get(("TDD_A%d" % i), 0.0) b[i] = phdr.get(("TDD_B%d" % i), 0.0) if (a==0).all() and (b==0).all(): - print ('Warning: TDD_A and TDD_B coeffiecients have values of 0, \n \ + print('Warning: TDD_A and TDD_B coeffiecients have values of 0, \n \ but TDDORDER is %d.' % TDDORDER) skew_coeffs['TDDORDER'] = n @@ -346,7 +346,7 @@ def readOfftab(offtab, date, chip=None): try: ftab = fileutil.openImage(offtab) except: - raise IOError,"Offset table '%s' not valid as specified!" % offtab + raise IOError("Offset table '%s' not valid as specified!" % offtab) #Determine row from which to get the coefficients. # How many rows do we have in the table... @@ -365,7 +365,7 @@ def readOfftab(offtab, date, chip=None): num_date = convertDate(date) # Loop over all the rows looking for the one which corresponds # to the value of CCDCHIP we are working on... - for ri in xrange(fshape[0]): + for ri in range(fshape[0]): i = fshape[0] - ri - 1 if 'DETCHIP' in colnames: detchip = ftab[1].data.field('DETCHIP')[i] @@ -405,12 +405,12 @@ def readOfftab(offtab, date, chip=None): del ftab if row_start == None and row_end == None: - print 'Row corresponding to DETCHIP of ',detchip,' was not found!' + print('Row corresponding to DETCHIP of ',detchip,' was not found!') raise LookupError elif row_start == None: - print '- OFFTAB: Offset defined by row',str(row_end+1) + print('- OFFTAB: Offset defined by row',str(row_end+1)) else: - print '- OFFTAB: Offset interpolated from rows',str(row_start+1),'and',str(row_end+1) + print('- OFFTAB: Offset interpolated from rows',str(row_start+1),'and',str(row_end+1)) # Now, do the interpolation for v2ref, v3ref, and theta if row_start == None or row_end == row_start: @@ -476,16 +476,16 @@ def readWCSCoeffs(header): cxstr = 'A_' cystr = 'B_' # Read coeffs into their own matrix - for i in xrange(_xorder+1): - for j in xrange(i+1): + for i in range(_xorder+1): + for j in range(i+1): xcname = cxstr+str(j)+'_'+str(i-j) if xcname in header: fx[i,j] = header[xcname] # Extract Y coeffs separately as a different order may # have been used to fit it. - for i in xrange(_yorder+1): - for j in xrange(i+1): + for i in range(_yorder+1): + for j in range(i+1): ycname = cystr+str(j)+'_'+str(i-j) if ycname in header: fy[i,j] = header[ycname] diff --git a/lib/stwcs/distortion/utils.py b/lib/stwcs/distortion/utils.py index 5e0bf79..449bc18 100644 --- a/lib/stwcs/distortion/utils.py +++ b/lib/stwcs/distortion/utils.py @@ -1,4 +1,5 @@ -from __future__ import division # confidence high +from __future__ import division, print_function # confidence high + import os import numpy as np from astropy import wcs as pywcs @@ -92,7 +93,7 @@ def undistortWCS(wcsobj): plate scale in the undistorted frame. """ assert isinstance(wcsobj, pywcs.WCS) - import coeff_converter + from . import coeff_converter cx, cy = coeff_converter.sip2idc(wcsobj) # cx, cy can be None because either there is no model available @@ -103,9 +104,9 @@ def undistortWCS(wcsobj): Run updatewcs() to update the headers or pass 'undistort=False' keyword to output_wcs().\n """ - raise RuntimeError, m + raise RuntimeError(m) else: - print 'Distortion model is not available, using input reference image for output WCS.\n' + 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] @@ -128,7 +129,7 @@ def undistortWCS(wcsobj): # Check the determinant for singularity _det = (am * dm) - (bm * cm) if ( _det == 0.0): - print 'Singular matrix in updateWCS, aborting ...' + print('Singular matrix in updateWCS, aborting ...') return lin_wcsobj = pywcs.WCS() @@ -160,10 +161,10 @@ def apply_idc(pixpos, cx, cy, pixref, pscale= None, order=None): return pixpos if order is None: - print 'Unknown order of distortion model \n' + print('Unknown order of distortion model \n') return pixpos if pscale is None: - print 'Unknown model plate scale\n' + print('Unknown model plate scale\n') return pixpos # Apply in the same way that 'drizzle' would... |