summaryrefslogtreecommitdiff
path: root/wcsutil/getinput.py
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 /wcsutil/getinput.py
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
Diffstat (limited to 'wcsutil/getinput.py')
-rw-r--r--wcsutil/getinput.py59
1 files changed, 59 insertions, 0 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