diff options
-rw-r--r-- | lib/stwcs/gui/pars/write_headerlet.cfg | 4 | ||||
-rw-r--r-- | lib/stwcs/gui/pars/write_headerlet.cfgspc | 4 | ||||
-rw-r--r-- | lib/stwcs/gui/write_headerlet.py | 17 | ||||
-rw-r--r-- | lib/stwcs/wcsutil/headerlet.py | 27 |
4 files changed, 36 insertions, 16 deletions
diff --git a/lib/stwcs/gui/pars/write_headerlet.cfg b/lib/stwcs/gui/pars/write_headerlet.cfg index 7dfa3aa..dccff0e 100644 --- a/lib/stwcs/gui/pars/write_headerlet.cfg +++ b/lib/stwcs/gui/pars/write_headerlet.cfg @@ -1,13 +1,13 @@ _task_name_ = write_headerlet filename = "" +output = "" +clobber = True hdrname = "" wcskey = "PRIMARY" wcsname = "" author = "" descrip = "" history = "" -output = "" -clobber = True sciext = "SCI" destim = "" sipname = "" diff --git a/lib/stwcs/gui/pars/write_headerlet.cfgspc b/lib/stwcs/gui/pars/write_headerlet.cfgspc index 5aaffe1..323ab4c 100644 --- a/lib/stwcs/gui/pars/write_headerlet.cfgspc +++ b/lib/stwcs/gui/pars/write_headerlet.cfgspc @@ -1,13 +1,13 @@ _task_name_ = string_kw(default="write_headerlet") filename = string_kw(default="", comment="Input file name") +output = string_kw(default="", comment="Filename for headerlet FITS file") +clobber = boolean_kw(default=True, comment= "Overwrite existing headerlet FITS file?") hdrname = string_kw(default="", comment="Unique name(HDRNAME) for headerlet[REQUIRED]") wcskey = option_kw("A","B","C","D","E","F","G","H","I","J","K","L","M","N","P","Q","R","S","T","U","V","W","X","Y","Z","PRIMARY", default="PRIMARY", comment="Create headerlet from WCS with this letter") wcsname = string_kw(default="", comment="Create headerlet from WCS with this name") author = string_kw(default="", comment="Author name for creator of headerlet") descrip = string_kw(default="", comment="Short description of headerlet solution") history = string_kw(default="", comment="Name of ASCII file containing history for headerlet") -output = string_kw(default="", comment="Filename for headerlet FITS file") -clobber = boolean_kw(default=True, comment= "Overwrite existing headerlet FITS file?") sciext = string_kw(default="SCI", comment="EXTNAME of extension with WCS") destim = string_kw(default="", comment="Rootname of image to which this headerlet applies ") sipname = string_kw(default="", comment="Name for source of polynomial distortion keywords") diff --git a/lib/stwcs/gui/write_headerlet.py b/lib/stwcs/gui/write_headerlet.py index 2072d2e..1debcf6 100644 --- a/lib/stwcs/gui/write_headerlet.py +++ b/lib/stwcs/gui/write_headerlet.py @@ -2,6 +2,7 @@ import os import pyfits from stsci.tools import teal +from stsci.tools import parseinput import stwcs from stwcs.wcsutil import headerlet @@ -32,7 +33,8 @@ def getHelpAsString(docstring=False): return helpString def run(configObj=None): - if not os.path.exists(configObj['filename']): + flist,oname = parseinput.parseinput(configObj['filename']) + if len(flist) == 0: print '='*60 print 'ERROR:' print ' No valid "filename" parameter value provided!' @@ -47,7 +49,16 @@ def run(configObj=None): print ' Please restart this task and provide a value for this parameter.' print '='*60 return - + + if configObj['output'] in ['',' ','INDEF']: + print '='*60 + print 'ERROR:' + print ' No valid "output" parameter value provided!' + print ' Please restart this task and provide a value for this parameter.' + print '='*60 + return + + str_kw = ['wcsname','destim','sipname','npolfile','d2imfile', 'descrip','history','author','output'] @@ -71,5 +82,5 @@ def run(configObj=None): # sipname=None, npolfile=None, d2imfile=None, # author=None, descrip=None, history=None, # attach=True, clobber=False) - headerlet.write_headerlet(configObj['filename'], configObj['hdrname'], + headerlet.write_headerlet(flist, configObj['hdrname'], **cdict)
\ No newline at end of file diff --git a/lib/stwcs/wcsutil/headerlet.py b/lib/stwcs/wcsutil/headerlet.py index b7f0e29..0e15102 100644 --- a/lib/stwcs/wcsutil/headerlet.py +++ b/lib/stwcs/wcsutil/headerlet.py @@ -21,6 +21,7 @@ from stwcs.updatewcs import utils from stsci.tools.fileutil import countExtn from stsci.tools import fileutil as fu +from stsci.tools import parseinput #### Logging support functions module_logger = logging.getLogger('headerlet') @@ -577,8 +578,11 @@ def extract_headerlet(filename, output, extnum=None, hdrname=None, """ initLogging('extract_headerlet', verbose=verbose) - if isinstance(filename, pyfits.HDUList) or isinstance(filename,str): + if isinstance(filename, pyfits.HDUList): filename = [filename] + else: + filename,oname = parseinput.parseinput(filename) + for f in filename: fobj,fname,close_fobj = parseFilename(f) frootname = fu.buildNewRootname(fname) @@ -594,6 +598,9 @@ def extract_headerlet(filename, output, extnum=None, hdrname=None, hdrlet = hdrhdu.headerlet + if output is None: + output = frootname + if '.fits' in output: outname = output else: @@ -691,11 +698,11 @@ def write_headerlet(filename, hdrname, output=None, sciext='SCI', """ initLogging('write_headerlet') - if isinstance(filename, str) or isinstance(filename, pyfits.HDUList): - if ',' in filename: # string of comma-separated filenames - filename = filename.split(',') - else: - filename = [filename] + if isinstance(filename, pyfits.HDUList): + filename = [filename] + else: + filename,oname = parseinput.parseinput(filename) + for f in filename: if isinstance(f,str): fname = f @@ -777,9 +784,11 @@ def write_headerlet(filename, hdrname, output=None, sciext='SCI', frootname = fu.buildNewRootname(fname) if output is None: # Generate default filename for headerlet FITS file - outname = frootname - if '.fits' not in output: - outname = frootname+'_'+output+'_hlet.fits' + outname = '%s_hlet.fits'%(frootname) + else: + outname = output + if '.fits' not in outname: + outname = '%s_%s_hlet.fits'%(frootname,outname) # If user specifies an output filename for headerlet, write it out write_hdrlet = True |