summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordencheva <dencheva@stsci.edu>2011-02-16 17:36:49 -0500
committerdencheva <dencheva@stsci.edu>2011-02-16 17:36:49 -0500
commitc41b232483ee6e89d62591720cfb6764213aa44e (patch)
treea1add8088d6e4e077b109c2d83e78036001b5240
parent0dde41dd926eabfbb1da892b90e9d461b34514d5 (diff)
downloadstwcs_hcf-c41b232483ee6e89d62591720cfb6764213aa44e.tar.gz
Pulled the code which deals with input into a separate module. Changes to the HSTWCS module are related to using it with headerlets, as well as with observations from other telescopes.
git-svn-id: http://svn.stsci.edu/svn/ssb/stsci_python/stsci_python/trunk/stwcs@11958 fe389314-cf27-0410-b35b-8c050e845b92
-rw-r--r--wcsutil/getinput.py59
-rw-r--r--wcsutil/hstwcs.py87
2 files changed, 88 insertions, 58 deletions
diff --git a/wcsutil/getinput.py b/wcsutil/getinput.py
new file mode 100644
index 0000000..22ed492
--- /dev/null
+++ b/wcsutil/getinput.py
@@ -0,0 +1,59 @@
+import pyfits
+from pytools import irafglob, fileutil, parseinput
+
+def parseSingleInput(f=None, ext=None):
+ if isinstance(f, str):
+ # create an HSTWCS object from a filename
+ if ext != None:
+ filename = f
+ if isinstance(ext,tuple):
+ if ext[0] == '':
+ extnum = ext[1] # handle ext=('',1)
+ else:
+ extnum = ext
+ else:
+ extnum = int(ext)
+ elif ext == None:
+ filename, ext = fileutil.parseFilename(f)
+ ext = fileutil.parseExtn(ext)
+ if ext[0] == '':
+ extnum = int(ext[1]) #handle ext=('',extnum)
+ else:
+ extnum = ext
+ phdu = pyfits.open(filename)
+ hdr0 = pyfits.getheader(filename)
+ try:
+ ehdr = pyfits.getheader(filename, ext=extnum)
+ except (IndexError,KeyError):
+ print 'Unable to get extension.', extnum
+ raise
+
+ elif isinstance(f, pyfits.HDUList):
+ phdu = f
+ if ext == None:
+ extnum = 0
+ else:
+ extnum = ext
+ ehdr = f[extnum].header
+ hdr0 = f[0].header
+ filename = hdr0.get('FILENAME', "")
+
+ return filename, hdr0, ehdr, phdu
+
+
+def parseMultipleInput(input):
+ if isinstance(input, str):
+ if input[0] == '@':
+ # input is an @ file
+ filelist = irafglob.irafglob(input)
+ else:
+ try:
+ filelist, output = parseinput.parseinput(input)
+ except IOError: raise
+ elif isinstance(input, list):
+ if isinstance(input[0], wcsutil.HSTWCS):
+ # a list of HSTWCS objects
+ return input
+ else:
+ filelist = input[:]
+ return filelist \ No newline at end of file
diff --git a/wcsutil/hstwcs.py b/wcsutil/hstwcs.py
index f3731b5..00a27f4 100644
--- a/wcsutil/hstwcs.py
+++ b/wcsutil/hstwcs.py
@@ -10,6 +10,7 @@ import numpy as np
from pytools import fileutil
from pytools.fileutil import DEGTORAD, RADTODEG
+import getinput
import mappings
from mappings import inst_mappings, ins_spec_kw
from mappings import basic_wcs
@@ -21,7 +22,7 @@ __version__ = '0.7'
class HSTWCS(WCS):
- def __init__(self, fobj='DEFAULT', ext=None, minerr=0.0, wcskey=" "):
+ def __init__(self, fobj=None, ext=None, minerr=0.0, wcskey=" "):
"""
Create a WCS object based on the instrument.
@@ -51,10 +52,10 @@ class HSTWCS(WCS):
self.minerr = minerr
self.wcskey = wcskey
- if fobj != 'DEFAULT':
- filename, hdr0, ehdr, phdu = self._parseInput(f=fobj, ext=ext)
+ if fobj != None:
+ filename, hdr0, ehdr, phdu = getinput.parseSingleInput(f=fobj, ext=ext)
self.filename = filename
- self.instrument = hdr0['INSTRUME']
+ self.instrument = hdr0.get('INSTRUME', 'DEFAULT')
WCS.__init__(self, ehdr, fobj=phdu, minerr=self.minerr, key=self.wcskey)
# If input was a pyfits HDUList object, it's the user's
@@ -70,54 +71,10 @@ class HSTWCS(WCS):
# create a default HSTWCS object
self.instrument = 'DEFAULT'
WCS.__init__(self, minerr=self.minerr, key=self.wcskey)
- 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.pc2cd()
self.setInstrSpecKw()
self.setPscale()
self.setOrient()
-
- def _parseInput(self, f=None, ext=None):
- if isinstance(f, str):
- # create an HSTWCS object from a filename
-
- if ext != None:
- filename = f
- if isinstance(ext,tuple):
- if ext[0] == '':
- extnum = ext[1] # handle ext=('',1)
- else:
- extnum = ext
- else:
- extnum = int(ext)
- elif ext == None:
- filename, ext = fileutil.parseFilename(f)
- ext = fileutil.parseExtn(ext)
- if ext[0] == '':
- extnum = int(ext[1]) #handle ext=('',extnum)
- else:
- extnum = ext
- phdu = pyfits.open(filename)
- hdr0 = pyfits.getheader(filename)
- try:
- ehdr = pyfits.getheader(filename, ext=extnum)
- except (IndexError,KeyError):
- print 'Unable to get extension.', extnum
- raise
-
- elif isinstance(f, pyfits.HDUList):
- phdu = f
- if ext == None:
- extnum = 0
- else:
- extnum = ext
- ehdr = f[extnum].header
- hdr0 = f[0].header
- filename = hdr0.get('FILENAME', "")
-
- return filename, hdr0, ehdr, phdu
-
def readIDCCoeffs(self, header):
"""
@@ -165,18 +122,30 @@ class HSTWCS(WCS):
"""
Calculates the plate scale from the CD matrix
"""
- cd11 = self.wcs.cd[0][0]
- cd21 = self.wcs.cd[1][0]
- self.pscale = np.sqrt(np.power(cd11,2)+np.power(cd21,2)) * 3600.
-
+ try:
+ cd11 = self.wcs.cd[0][0]
+ cd21 = self.wcs.cd[1][0]
+ self.pscale = np.sqrt(np.power(cd11,2)+np.power(cd21,2)) * 3600.
+ except AttributeError:
+ print "This file has a PC matrix. You may want to convert it \n \
+ to a CD matrix, if reasonable, by running pc2.cd() method.\n \
+ The plate scale can be set then by calling setPscale() method.\n"
+ self.pscale = None
+
def setOrient(self):
"""
Computes ORIENTAT from the CD matrix
"""
- cd12 = self.wcs.cd[0][1]
- cd22 = self.wcs.cd[1][1]
- self.orientat = RADTODEG(np.arctan2(cd12,cd22))
-
+ try:
+ cd12 = self.wcs.cd[0][1]
+ cd22 = self.wcs.cd[1][1]
+ self.orientat = RADTODEG(np.arctan2(cd12,cd22))
+ except AttributeError:
+ print "This file has a PC matrix. You may want to convert it \n \
+ to a CD matrix, if reasonable, by running pc2.cd() method.\n \
+ The orientation can be set then by calling setOrient() method.\n"
+ self.pscale = None
+
def updatePscale(self, scale):
"""
Updates the CD matrix with a new plate scale
@@ -337,7 +306,9 @@ class HSTWCS(WCS):
cards.append(card)
return cards
-
+ def pc2cd(self):
+ self.wcs.cd = self.wcs.pc.copy()
+
def _updatehdr(self, ext_hdr):
#kw2add : OCX10, OCX11, OCY10, OCY11
# record the model in the header for use by pydrizzle