From f95aaac222c61f886e27f7029ed592a76b31eeed Mon Sep 17 00:00:00 2001 From: dencheva Date: Thu, 24 Sep 2009 19:05:32 +0000 Subject: Added code which allows to create an HSTWCS object without the requirement to tie it to an instrument and detector (WCS headerlets). Also better handling of iraf type fits names git-svn-id: http://svn.stsci.edu/svn/ssb/stsci_python/stsci_python/trunk/stwcs@8308 fe389314-cf27-0410-b35b-8c050e845b92 --- wcsutil/__init__.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'wcsutil/__init__.py') diff --git a/wcsutil/__init__.py b/wcsutil/__init__.py index a275a18..a7045c2 100644 --- a/wcsutil/__init__.py +++ b/wcsutil/__init__.py @@ -61,7 +61,7 @@ class HSTWCS(WCS): if not isinstance(fobj, pyfits.HDUList): phdu.close() - + self.instrument ='DEFAULT' self.setInstrSpecKw(hdr0, ehdr) self.setPscale() self.setOrient() @@ -82,20 +82,27 @@ class HSTWCS(WCS): if ext != None: filename = f - extnum = ext + if isinstance(ext,tuple): + if ext[0] == '': + extnum = ext[1] # handle ext=('',1) + else: + extnum = ext + else: + extnum = int(ext) elif ext == None: - filename, extname = fileutil.parseFilename(f) - if extname == None: - #data may be in the primary array - extnum = 0 + filename, ext = fileutil.parseFilename(f) + ext = fileutil.parseExtn(ext) + if ext[0] == '': + extnum = int(ext[1]) #handle ext=('',extnum) else: - extnum = fileutil.parseExtn(extname) + extnum = ext phdu = pyfits.open(filename) hdr0 = pyfits.getheader(filename) try: ehdr = pyfits.getheader(filename, ext=extnum) - except IndexError: - print 'Unable to get extension %d. /n' % ext + except (IndexError,KeyError): + print 'Unable to get extension.', extnum + raise elif isinstance(f, pyfits.HDUList): phdu = f -- cgit