From c41b232483ee6e89d62591720cfb6764213aa44e Mon Sep 17 00:00:00 2001 From: dencheva Date: Wed, 16 Feb 2011 22:36:49 +0000 Subject: 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 --- wcsutil/getinput.py | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 wcsutil/getinput.py (limited to 'wcsutil/getinput.py') 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 -- cgit