summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordencheva <dencheva@stsci.edu>2010-07-14 16:33:07 -0400
committerdencheva <dencheva@stsci.edu>2010-07-14 16:33:07 -0400
commitb1c0cae4cb1d23e69228ecb1da96dd8ac359c23d (patch)
tree18cabd15bfdf0d322524c630751c9843a76da93c
parent36281d4b8086a8488c113aaffaa9919c94573a6b (diff)
downloadstwcs_hcf-b1c0cae4cb1d23e69228ecb1da96dd8ac359c23d.tar.gz
Pywcs was changed not to set the WCS values for a default object (header is None) and these are the corresponing changes in wcsutil.And some other minor bug fixes.
git-svn-id: http://svn.stsci.edu/svn/ssb/stsci_python/stsci_python/trunk/stwcs@9839 fe389314-cf27-0410-b35b-8c050e845b92
-rw-r--r--distortion/utils.py19
-rw-r--r--updatewcs/corrections.py4
-rw-r--r--updatewcs/makewcs.py8
-rw-r--r--wcsutil/__init__.py9
4 files changed, 25 insertions, 15 deletions
diff --git a/distortion/utils.py b/distortion/utils.py
index bc25daf..676156e 100644
--- a/distortion/utils.py
+++ b/distortion/utils.py
@@ -19,12 +19,13 @@ def output_wcs(list_of_wcsobj, ref_wcs=None, outwcs=None, undistort=True):
crval = np.array([crval1,crval2])
if outwcs is None:
if ref_wcs == None:
- ref_wcs = list_of_wcsobj[0]
+ ref_wcs = list_of_wcsobj[0].deepcopy()
if undistort:
outwcs = undistortWCS(ref_wcs)
else:
- outwcs = ref_wcs.copy()
+ outwcs = ref_wcs.deepcopy()
outwcs.wcs.crval = crval
+ outwcs.wcs.set()
outwcs.pscale = sqrt(outwcs.wcs.cd[0,0]**2 + outwcs.wcs.cd[1,0]**2)*3600.
outwcs.orientat = arctan2(outwcs.wcs.cd[0,1],outwcs.wcs.cd[1,1]) * 180./np.pi
else:
@@ -37,13 +38,16 @@ def output_wcs(list_of_wcsobj, ref_wcs=None, outwcs=None, undistort=True):
outwcs.naxis2 = int(np.ceil(tanpix[:,1].max() - tanpix[:,1].min()))
crpix = np.array([outwcs.naxis1/2., outwcs.naxis2/2.])
outwcs.wcs.crpix = crpix
-
+ outwcs.wcs.set()
+ return outwcs
+"""
tanpix = outwcs.wcs.s2p(fra_dec, 1)['pixcrd']
newcrpix = np.array([crpix[0]+np.ceil(tanpix[:,0].min()), crpix[1]+np.ceil(tanpix[:,1].min())])
newcrval = outwcs.wcs.p2s([newcrpix], 1)['world'][0]
outwcs.wcs.crval = newcrval
+ outwcs.wcs.set()
return outwcs
-
+ """
def undistortWCS(wcsobj):
"""
Creates an undistorted linear WCS by applying the IDCTAB distortion model
@@ -90,13 +94,16 @@ def undistortWCS(wcsobj):
print 'Singular matrix in updateWCS, aborting ...'
return
- lin_wcsobj = pywcs.WCS()
+ lin_wcsobj = pywcs.WCS()
cd_inv = np.linalg.inv(cd_mat)
lin_wcsobj.wcs.cd = np.dot(wcsobj.wcs.cd, cd_inv)
-
+ lin_wcsobj.set()
lin_wcsobj.orientat = arctan2(lin_wcsobj.wcs.cd[0,1],lin_wcsobj.wcs.cd[1,1]) * 180./np.pi
lin_wcsobj.pscale = sqrt(lin_wcsobj.wcs.cd[0,0]**2 + lin_wcsobj.wcs.cd[1,0]**2)*3600.
+ lin_wcsobj.wcs.crval = np.array([0.,0.])
+ lin_wcsobj.wcs.crpix = np.array([0.,0.])
+ lin_wcsobj.wcs.set()
return lin_wcsobj
def apply_idc(pixpos, cx, cy, pixref, pscale= None, order=None):
diff --git a/updatewcs/corrections.py b/updatewcs/corrections.py
index fa0a290..3d504ca 100644
--- a/updatewcs/corrections.py
+++ b/updatewcs/corrections.py
@@ -168,8 +168,8 @@ class CompSIP(object):
if n >= m and n>=2:
idcval = np.array([[cx[n,m]],[cy[n,m]]])
sipval = np.dot(imatr, idcval)
- akeys1[m,n-m] = sipval[0]
- bkeys1[m,n-m] = sipval[1]
+ akeys1[m,n-m] = sipval[0] * ext_wcs.binned
+ bkeys1[m,n-m] = sipval[1] * ext_wcs.binned
Akey="A_%d_%d" % (m,n-m)
Bkey="B_%d_%d" % (m,n-m)
kw2update[Akey] = sipval[0,0]
diff --git a/updatewcs/makewcs.py b/updatewcs/makewcs.py
index b455640..77c8aa9 100644
--- a/updatewcs/makewcs.py
+++ b/updatewcs/makewcs.py
@@ -82,9 +82,9 @@ class MakeWCS(object):
off = sqrt((v2-v2ref)**2 + (v3-v3ref)**2)/(R_scale*3600.0)
if v3 == v3ref:
- theta=0.0
+ theta=0.0
else:
- theta = atan2(ext_wcs.parity[0][0]*(v2-v2ref), ext_wcs.parity[1][1]*(v3-v3ref))
+ theta = atan2(ext_wcs.parity[0][0]*(v2-v2ref), ext_wcs.parity[1][1]*(v3-v3ref))
if ref_wcs.idcmodel.refpix['THETA']: theta += ref_wcs.idcmodel.refpix['THETA']*pi/180.0
@@ -106,9 +106,9 @@ class MakeWCS(object):
# Account for subarray offset
# Angle of chip relative to chip
if ext_wcs.idcmodel.refpix['THETA']:
- dtheta = ext_wcs.idcmodel.refpix['THETA'] - ref_wcs.idcmodel.refpix['THETA']
+ dtheta = ext_wcs.idcmodel.refpix['THETA'] - ref_wcs.idcmodel.refpix['THETA']
else:
- dtheta = 0.0
+ dtheta = 0.0
rrmat = fileutil.buildRotMatrix(dtheta)
# Rotate the vectors
diff --git a/wcsutil/__init__.py b/wcsutil/__init__.py
index 791f3aa..ee93668 100644
--- a/wcsutil/__init__.py
+++ b/wcsutil/__init__.py
@@ -52,7 +52,6 @@ class HSTWCS(WCS):
self.instrument = hdr0['INSTRUME']
WCS.__init__(self, ehdr, fobj=phdu, minerr=minerr)
-
# If input was a pyfits HDUList object, it's the user's
# responsibility to close it, otherwise, it's closed here.
if not isinstance(fobj, pyfits.HDUList):
@@ -67,8 +66,11 @@ class HSTWCS(WCS):
# create a default HSTWCS object
self.instrument = 'DEFAULT'
WCS.__init__(self, minerr=minerr)
+ self.wcs.cd = np.array([[1.0, 0.0], [0.0, 1.0]], np.double)
+ self.wcs.crval = np.zeros((self.naxis,), np.double)
+ self.wcs.crpix = np.zeros((self.naxis,), np.double)
+ self.wcs.set()
self.setInstrSpecKw()
-
self.setPscale()
self.setOrient()
@@ -178,6 +180,7 @@ class HSTWCS(WCS):
cd22 = -cd11
cdmat = np.array([[cd11, cd12],[cd21,cd22]])
self.wcs.cd = cdmat * self.pscale/3600
+ self.wcs.set()
def readModel(self, update=False, header=None):
@@ -283,7 +286,7 @@ class HSTWCS(WCS):
cdl.append(card)
h = pyfits.Header(cdl)
- wprm = Wcsprm("".join([str(x) for x in h.ascardlist()]))
+ wprm = Wcsprm(str(h.ascardlist()))
self.wcs = wprm
self.setPscale()
self.setOrient()