diff options
Diffstat (limited to 'lib/stwcs/gui')
30 files changed, 791 insertions, 0 deletions
diff --git a/lib/stwcs/gui/__init__.py b/lib/stwcs/gui/__init__.py new file mode 100644 index 0000000..559d361 --- /dev/null +++ b/lib/stwcs/gui/__init__.py @@ -0,0 +1,19 @@ +""" STWCS.GUI + +This package defines the TEAL interfaces for public, file-based operations +provided by the STWCS package. + +""" +from __future__ import division # confidence high +__docformat__ = 'restructuredtext' + +# import modules which define the TEAL interfaces +import write_headerlet +import extract_headerlet +import attach_headerlet +import delete_headerlet +import headerlet_summary +import archive_headerlet +import restore_headerlet +import apply_headerlet +import updatewcs diff --git a/lib/stwcs/gui/apply_headerlet.help b/lib/stwcs/gui/apply_headerlet.help new file mode 100644 index 0000000..2ddb2e4 --- /dev/null +++ b/lib/stwcs/gui/apply_headerlet.help @@ -0,0 +1,40 @@ +This task applies a headerlet to a science observation to update either the +PRIMARY WCS or to add it as an alternate WCS. + +filename = "" +hdrlet = "" +attach = True +primary = True +archive = True +force = False +wcskey = "" +wcsname = "" +verbose = False + +Parameters +---------- +filename: string + File name of science observation whose WCS solution will be updated +hdrlet: string + Headerlet file +attach: boolean + True (default): append headerlet to FITS file as a new extension. +primary: boolean + Specify whether or not to replace PRIMARY WCS with WCS from headerlet. +archive: boolean + True (default): before updating, create a headerlet with the + WCS old solution. +force: boolean + If True, this will cause the headerlet to replace the current PRIMARY + WCS even if it has a different distortion model. [Default: False] +wcskey: string + Key value (A-Z, except O) for this alternate WCS + If None, the next available key will be used +wcsname: string + Name to be assigned to this alternate WCS + WCSNAME is a required keyword in a Headerlet but this allows the + user to change it as desired. + +verbose: False or a python logging level + (one of 'INFO', 'DEBUG' logging levels) + (an integer representing a logging level) diff --git a/lib/stwcs/gui/apply_headerlet.py b/lib/stwcs/gui/apply_headerlet.py new file mode 100644 index 0000000..0a93104 --- /dev/null +++ b/lib/stwcs/gui/apply_headerlet.py @@ -0,0 +1,54 @@ +import os +import string + +import pyfits +from stsci.tools import teal + +import stwcs +from stwcs.wcsutil import headerlet + +__taskname__ = __name__.split('.')[-1] # needed for help string +__package__ = headerlet.__name__ +__version__ = stwcs.__version__ +# +#### Interfaces used by TEAL +# +def getHelpAsString(docstring=False): + """ + return useful help from a file in the script directory called __taskname__.help + """ + install_dir = os.path.dirname(__file__) + htmlfile = os.path.join(install_dir,'htmlhelp',__taskname__+'.html') + helpfile = os.path.join(install_dir,__taskname__+'.help') + if docstring or (not docstring and not os.path.exists(htmlfile)): + helpString = __taskname__+' Version '+__version__+'\n\n' + if os.path.exists(helpfile): + helpString += teal.getHelpFileAsString(__taskname__,__file__) + else: + helpString = 'file://'+htmlfile + + return helpString + +def run(configObj=None): + + if configObj['primary']: + # Call function with properly interpreted input parameters + # Syntax: apply_headerlet_as_primary(filename, hdrlet, attach=True, + # archive=True, force=False, verbose=False) + headerlet.apply_headerlet_as_primary(configObj['filename'], + configObj['hdrlet'],attach=configObj['attach'], + archive=configObj['archive'],force=configObj['force'], + verbose=configObj['verbose']) + else: + wcsname = configObj['wcsname'] + if wcsname in ['',' ','INDEF']: wcsname = None + wcskey = configObj['wcskey'] + if wcskey == '': wcskey = None + # Call function with properly interpreted input parameters + # apply_headerlet_as_alternate(filename, hdrlet, attach=True, + # wcskey=None, wcsname=None, verbose=False) + headerlet.apply_headerlet_as_alternate(configObj['filename'], + configObj['hdrlet'], attach=configObj['attach'], + wcsname=wcsname, wcskey=wcskey, + verbose=configObj['verbose']) + diff --git a/lib/stwcs/gui/archive_headerlet.py b/lib/stwcs/gui/archive_headerlet.py new file mode 100644 index 0000000..707d521 --- /dev/null +++ b/lib/stwcs/gui/archive_headerlet.py @@ -0,0 +1,69 @@ +import os +import string + +import pyfits +from stsci.tools import teal + +import stwcs +from stwcs.wcsutil import headerlet + +__taskname__ = __name__.split('.')[-1] # needed for help string +__package__ = headerlet.__name__ +__version__ = stwcs.__version__ +# +#### Interfaces used by TEAL +# +def getHelpAsString(docstring=False): + """ + return useful help from a file in the script directory called __taskname__.help + """ + install_dir = os.path.dirname(__file__) + htmlfile = os.path.join(install_dir,'htmlhelp',__taskname__+'.html') + helpfile = os.path.join(install_dir,__taskname__+'.help') + if docstring or (not docstring and not os.path.exists(htmlfile)): + helpString = __taskname__+' Version '+__version__+'\n\n' + if os.path.exists(helpfile): + helpString += teal.getHelpFileAsString(__taskname__,__file__) + else: + helpString += headerlet.archive_as_headerlet.__doc__ + + else: + helpString = 'file://'+htmlfile + + return helpString + +def run(configObj=None): + + if configObj['hdrname'] in ['',' ','INDEF']: + print '='*60 + print 'ERROR:' + print ' No valid "hdrname" 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'] + + # create dictionary of remaining parameters, deleting extraneous ones + # such as those above + cdict = configObj.dict() + # remove any rules defined for the TEAL interface + if cdict.has_key("_RULES_"): del cdict['_RULES_'] + del cdict['_task_name_'] + del cdict['filename'] + del cdict['hdrname'] + + # Convert blank string input as None + for kw in str_kw: + if cdict[kw] == '': cdict[kw] = None + if cdict['wcskey'].lower() == 'primary': cdict['wcskey'] = ' ' + + # Call function with properly interpreted input parameters + # Syntax: archive_as_headerlet(filename, sciext='SCI', wcsname=None, wcskey=None, + # hdrname=None, destim=None, + # sipname=None, npolfile=None, d2imfile=None, + # author=None, descrip=None, history=None, + # hdrlet=None, clobber=False) + headerlet.archive_as_headerlet(configObj['filename'], configObj['hdrname'], + **cdict)
\ No newline at end of file diff --git a/lib/stwcs/gui/attach_headerlet.py b/lib/stwcs/gui/attach_headerlet.py new file mode 100644 index 0000000..c68bbfe --- /dev/null +++ b/lib/stwcs/gui/attach_headerlet.py @@ -0,0 +1,36 @@ +import os + +import pyfits +from stsci.tools import teal + +import stwcs +from stwcs.wcsutil import headerlet + +__taskname__ = __name__.split('.')[-1] # needed for help string +__package__ = headerlet.__name__ +__version__ = stwcs.__version__ +# +#### Interfaces used by TEAL +# +def getHelpAsString(docstring=False): + """ + return useful help from a file in the script directory called __taskname__.help + """ + install_dir = os.path.dirname(__file__) + htmlfile = os.path.join(install_dir,'htmlhelp',__taskname__+'.html') + helpfile = os.path.join(install_dir,__taskname__+'.help') + if docstring or (not docstring and not os.path.exists(htmlfile)): + helpString = __taskname__+' Version '+__version__+'\n\n' + if os.path.exists(helpfile): + helpString += teal.getHelpFileAsString(__taskname__,__file__) + else: + helpString += eval('.'.join([__package__,__taskname__,'__doc__'])) + else: + helpString = 'file://'+htmlfile + + return helpString + +def run(configObj=None): + + headerlet.attach_headerlet(configObj['filename'],configObj['hdrlet']) + diff --git a/lib/stwcs/gui/delete_headerlet.py b/lib/stwcs/gui/delete_headerlet.py new file mode 100644 index 0000000..e33bb91 --- /dev/null +++ b/lib/stwcs/gui/delete_headerlet.py @@ -0,0 +1,50 @@ +import os + +import pyfits +from stsci.tools import teal + +import stwcs +from stwcs.wcsutil import headerlet + +__taskname__ = __name__.split('.')[-1] # needed for help string +__package__ = headerlet.__name__ +__version__ = stwcs.__version__ +# +#### Interfaces used by TEAL +# +def getHelpAsString(docstring=False): + """ + return useful help from a file in the script directory called __taskname__.help + """ + install_dir = os.path.dirname(__file__) + htmlfile = os.path.join(install_dir,'htmlhelp',__taskname__+'.html') + helpfile = os.path.join(install_dir,__taskname__+'.help') + if docstring or (not docstring and not os.path.exists(htmlfile)): + helpString = __taskname__+' Version '+__version__+'\n\n' + if os.path.exists(helpfile): + helpString += teal.getHelpFileAsString(__taskname__,__file__) + else: + helpString += eval('.'.join([__package__,__taskname__,'__doc__'])) + else: + helpString = 'file://'+htmlfile + + return helpString + +def run(configObj=None): + + if configObj['hdrname'] == '' and configObj['hdrext'] is None and \ + configObj['distname'] == '': + print '='*60 + print 'ERROR:' + print ' No valid "hdrname", "hdrext" or "distname" parameter value provided!' + print ' Please restart this task and provide a value for one of these parameters.' + print '='*60 + return + + # Call function with properly interpreted input parameters + # Syntax: delete_headerlet(filename, hdrname=None, hdrext=None, distname=None) + headerlet.delete_headerlet(configObj['filename'], + hdrname = configObj['hdrname'], + hdrext = configObj['hdrext'], + distname = configObj['distname']) + diff --git a/lib/stwcs/gui/extract_headerlet.py b/lib/stwcs/gui/extract_headerlet.py new file mode 100644 index 0000000..8751ff3 --- /dev/null +++ b/lib/stwcs/gui/extract_headerlet.py @@ -0,0 +1,58 @@ +import os + +import pyfits +from stsci.tools import teal + +import stwcs +from stwcs.wcsutil import headerlet + +__taskname__ = __name__.split('.')[-1] # needed for help string +__package__ = headerlet.__name__ +__version__ = stwcs.__version__ +# +#### Interfaces used by TEAL +# +def getHelpAsString(docstring=False): + """ + return useful help from a file in the script directory called __taskname__.help + """ + install_dir = os.path.dirname(__file__) + htmlfile = os.path.join(install_dir,'htmlhelp',__taskname__+'.html') + helpfile = os.path.join(install_dir,__taskname__+'.help') + if docstring or (not docstring and not os.path.exists(htmlfile)): + helpString = __taskname__+' Version '+__version__+'\n\n' + if os.path.exists(helpfile): + helpString += teal.getHelpFileAsString(__taskname__,__file__) + else: + helpString += eval('.'.join([__package__,__taskname__,'__doc__'])) + + else: + helpString = 'file://'+htmlfile + + return helpString + +def run(configObj=None): + + if configObj['output'] in ['',' ',None]: + 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 + + # create dictionary of remaining parameters, deleting extraneous ones + # such as those above + cdict = configObj.dict() + # remove any rules defined for the TEAL interface + if cdict.has_key("_RULES_"): del cdict['_RULES_'] + del cdict['_task_name_'] + del cdict['filename'] + del cdict['output'] + + # Call function with properly interpreted input parameters + # Syntax: extract_headerlet(filename, output, extnum=None, hdrname=None, + # clobber=False, verbose=100) + headerlet.extract_headerlet(configObj['filename'], configObj['output'], + **cdict) + diff --git a/lib/stwcs/gui/headerlet_summary.py b/lib/stwcs/gui/headerlet_summary.py new file mode 100644 index 0000000..28c26c2 --- /dev/null +++ b/lib/stwcs/gui/headerlet_summary.py @@ -0,0 +1,49 @@ +import os + +import pyfits +from stsci.tools import teal + +import stwcs +from stwcs.wcsutil import headerlet + +__taskname__ = __name__.split('.')[-1] # needed for help string +__package__ = headerlet.__name__ +__version__ = stwcs.__version__ +# +#### Interfaces used by TEAL +# +def getHelpAsString(docstring=False): + """ + return useful help from a file in the script directory called __taskname__.help + """ + install_dir = os.path.dirname(__file__) + htmlfile = os.path.join(install_dir,'htmlhelp',__taskname__+'.html') + helpfile = os.path.join(install_dir,__taskname__+'.help') + if docstring or (not docstring and not os.path.exists(htmlfile)): + helpString = __taskname__+' Version '+__version__+'\n\n' + if os.path.exists(helpfile): + helpString += teal.getHelpFileAsString(__taskname__,__file__) + else: + helpString += eval('.'.join([__package__,__taskname__,'__doc__'])) + else: + helpString = 'file://'+htmlfile + + return helpString + +def run(configObj=None): + + # create dictionary of remaining parameters, deleting extraneous ones + # such as those above + cdict = configObj.dict() + # remove any rules defined for the TEAL interface + if cdict.has_key("_RULES_"): del cdict['_RULES_'] + del cdict['_task_name_'] + del cdict['filename'] + if headerlet.is_par_blank(cdict['columns']): + cdict['columns'] = None + # Call function with properly interpreted input parameters + + # Syntax: headerlet_summary(filename,columns=None,pad=2,maxwidth=None, + # output=None,clobber=True,quiet=False) + headerlet.headerlet_summary(configObj['filename'],**cdict) + diff --git a/lib/stwcs/gui/pars/apply_headerlet.cfg b/lib/stwcs/gui/pars/apply_headerlet.cfg new file mode 100644 index 0000000..ae97297 --- /dev/null +++ b/lib/stwcs/gui/pars/apply_headerlet.cfg @@ -0,0 +1,10 @@ +_task_name_ = apply_headerlet +filename = "" +hdrlet = "" +attach = True +primary = True +archive = True +force = False +wcskey = "" +wcsname = "" +verbose = False diff --git a/lib/stwcs/gui/pars/apply_headerlet.cfgspc b/lib/stwcs/gui/pars/apply_headerlet.cfgspc new file mode 100644 index 0000000..240dcec --- /dev/null +++ b/lib/stwcs/gui/pars/apply_headerlet.cfgspc @@ -0,0 +1,12 @@ +_task_name_ = string_kw(default="apply_headerlet") +filename = string_kw(default="", comment="Input file name") +hdrlet = string_kw(default="", comment="Headerlet FITS filename") +attach = boolean_kw(default=True, comment= "Append headerlet to FITS file as new extension?") +primary = boolean_kw(default=True, triggers="_rule1_", comment="Replace PRIMARY WCS with headerlet WCS?") +archive = boolean_kw(default=True, active_if="_rule1_", comment="Save PRIMARY WCS as new headerlet extension?") +force = boolean_kw(default=False, active_if="_rule1_", comment="If distortions do not match, force update anyway?") +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","", default="", inactive_if="_rule1_", comment="Apply headerlet as alternate WCS with this letter") +wcsname = string_kw(default="", inactive_if="_rule1_", comment="Apply headerlet as alternate WCS with this name") +verbose = boolean_kw(default=False, comment= "Print logging messages?") +[ _RULES_ ] +_rule1_ = string_kw(default=True, code='tyfn={"yes":True, "no":False}; OUT = tyfn[VAL]') diff --git a/lib/stwcs/gui/pars/archive_headerlet.cfg b/lib/stwcs/gui/pars/archive_headerlet.cfg new file mode 100644 index 0000000..815ce96 --- /dev/null +++ b/lib/stwcs/gui/pars/archive_headerlet.cfg @@ -0,0 +1,13 @@ +_task_name_ = archive_headerlet +filename = "" +hdrname = "" +sciext = "SCI" +wcsname = "" +wcskey = "PRIMARY" +destim = "" +sipname = "" +npolfile = "" +d2imfile = "" +author = "" +descrip = "" +history = "" diff --git a/lib/stwcs/gui/pars/archive_headerlet.cfgspc b/lib/stwcs/gui/pars/archive_headerlet.cfgspc new file mode 100644 index 0000000..d049769 --- /dev/null +++ b/lib/stwcs/gui/pars/archive_headerlet.cfgspc @@ -0,0 +1,13 @@ +_task_name_ = string_kw(default="archive_headerlet") +filename = string_kw(default="", comment="Input file name") +hdrname = string_kw(default="", comment="Unique name(HDRNAME) for headerlet") +sciext = string_kw(default="SCI", comment="EXTNAME of extension with WCS") +wcsname = string_kw(default="", comment="Name of WCS to be archived") +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="Archive the WCS with this letter") +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") +npolfile = string_kw(default="", comment="Name for source of non-polynomial residuals") +d2imfile = string_kw(default="", comment="Name for source of detector correction table") +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") diff --git a/lib/stwcs/gui/pars/attach_headerlet.cfg b/lib/stwcs/gui/pars/attach_headerlet.cfg new file mode 100644 index 0000000..772a66d --- /dev/null +++ b/lib/stwcs/gui/pars/attach_headerlet.cfg @@ -0,0 +1,3 @@ +_task_name_ = attach_headerlet +filename = "" +hdrlet = "" diff --git a/lib/stwcs/gui/pars/attach_headerlet.cfgspc b/lib/stwcs/gui/pars/attach_headerlet.cfgspc new file mode 100644 index 0000000..03dcf0f --- /dev/null +++ b/lib/stwcs/gui/pars/attach_headerlet.cfgspc @@ -0,0 +1,3 @@ +_task_name_ = string_kw(default="attach_headerlet") +filename = string_kw(default="", comment="FITS image file name") +hdrlet = string_kw(default="", comment="Headerlet FITS filename") diff --git a/lib/stwcs/gui/pars/delete_headerlet.cfg b/lib/stwcs/gui/pars/delete_headerlet.cfg new file mode 100644 index 0000000..f43befa --- /dev/null +++ b/lib/stwcs/gui/pars/delete_headerlet.cfg @@ -0,0 +1,5 @@ +_task_name_ = delete_headerlet +filename = "" +hdrname = "" +hdrext = None +distname = "" diff --git a/lib/stwcs/gui/pars/delete_headerlet.cfgspc b/lib/stwcs/gui/pars/delete_headerlet.cfgspc new file mode 100644 index 0000000..5695130 --- /dev/null +++ b/lib/stwcs/gui/pars/delete_headerlet.cfgspc @@ -0,0 +1,5 @@ +_task_name_ = string_kw(default="delete_headerlet") +filename = string_kw(default="", comment="FITS image file name") +hdrname = string_kw(default="", comment="Delete headerlet with this HDRNAME") +hdrext = integer_or_none_kw(default=None, comment="Delete headerlet from this extension") +distname = string_kw(default="", comment="Delete *ALL* with this DISTNAME") diff --git a/lib/stwcs/gui/pars/extract_headerlet.cfg b/lib/stwcs/gui/pars/extract_headerlet.cfg new file mode 100644 index 0000000..eaf4eff --- /dev/null +++ b/lib/stwcs/gui/pars/extract_headerlet.cfg @@ -0,0 +1,7 @@ +_task_name_ = extract_headerlet +filename = "" +output = "" +extnum = None +hdrname = "" +clobber = True +verbose = False diff --git a/lib/stwcs/gui/pars/extract_headerlet.cfgspc b/lib/stwcs/gui/pars/extract_headerlet.cfgspc new file mode 100644 index 0000000..3b173c2 --- /dev/null +++ b/lib/stwcs/gui/pars/extract_headerlet.cfgspc @@ -0,0 +1,7 @@ +_task_name_ = string_kw(default="extract_headerlet") +filename = string_kw(default="", comment="Input file name") +output = string_kw(default="", comment="Output headerlet FITS filename") +extnum = integer_or_none_kw(default=None, comment="FITS extension number of headerlet") +hdrname = string_kw(default="", comment="Unique name(HDRNAME) for headerlet") +clobber = boolean_kw(default=True, comment= "Overwrite existing headerlet FITS file?") +verbose = boolean_kw(default=False, comment= "Print logging messages?") diff --git a/lib/stwcs/gui/pars/headerlet_summary.cfg b/lib/stwcs/gui/pars/headerlet_summary.cfg new file mode 100644 index 0000000..7203552 --- /dev/null +++ b/lib/stwcs/gui/pars/headerlet_summary.cfg @@ -0,0 +1,8 @@ +_task_name_ = headerlet_summary +filename = "" +columns = None +pad = 2 +maxwidth = None +output = "" +clobber = True +quiet = False diff --git a/lib/stwcs/gui/pars/headerlet_summary.cfgspc b/lib/stwcs/gui/pars/headerlet_summary.cfgspc new file mode 100644 index 0000000..ce65930 --- /dev/null +++ b/lib/stwcs/gui/pars/headerlet_summary.cfgspc @@ -0,0 +1,8 @@ +_task_name_ = string_kw(default="headerlet_summary") +filename = string_kw(default="", comment="FITS image file name") +columns = string_kw(default="", comment="Headerlet keyword(s) to be reported") +pad = integer_kw(default=2, comment="Number of spaces between output columns") +maxwidth = integer_or_none_kw(default=None, comment="Max width for each column") +output = string_kw(default="", comment="Name of output file for summary") +clobber = boolean_kw(default=True, comment="Overwrite previously written summary?") +quiet = boolean_kw(default=False, comment="Suppress output of summary to STDOUT?") diff --git a/lib/stwcs/gui/pars/restore_headerlet.cfg b/lib/stwcs/gui/pars/restore_headerlet.cfg new file mode 100644 index 0000000..a6230a4 --- /dev/null +++ b/lib/stwcs/gui/pars/restore_headerlet.cfg @@ -0,0 +1,9 @@ +_task_name_ = restore_headerlet +filename = "" +archive = True +force = False +distname = "" +primary = None +sciext = "SCI" +hdrname = "" +hdrext = None diff --git a/lib/stwcs/gui/pars/restore_headerlet.cfgspc b/lib/stwcs/gui/pars/restore_headerlet.cfgspc new file mode 100644 index 0000000..3e713ce --- /dev/null +++ b/lib/stwcs/gui/pars/restore_headerlet.cfgspc @@ -0,0 +1,11 @@ +_task_name_ = string_kw(default="restore_headerlet") +filename = string_kw(default="", comment="Input file name") +archive = boolean_kw(default=True, comment= "Create headerlets from WCSs being replaced?") +force = boolean_kw(default=False, comment="If distortions do not match, force update anyway?") +distname = string_kw(default="", triggers="_rule1_", comment="Restore ALL headerlet extensions with this DISTNAME") +primary = integer_or_none_kw(default=None, inactive_if="_rule1_", comment="Headerlet extension to restore as new primary WCS") +sciext = string_kw(default="SCI", inactive_if="_rule1_", comment="EXTNAME of extension with WCS") +hdrname = string_kw(default="", active_if="_rule1_", comment="HDRNAME of headerlet extension to be restored") +hdrext = integer_or_none_kw(default=None, active_if="_rule1_", comment="Extension number for headerlet to be restored") +[ _RULES_ ] +_rule1_ = string_kw(default=True, code='from stwcs import wcsutil;from stwcs.wcsutil import headerlet;OUT = headerlet.is_par_blank(VAL)') diff --git a/lib/stwcs/gui/pars/updatewcs.cfg b/lib/stwcs/gui/pars/updatewcs.cfg new file mode 100644 index 0000000..35360f2 --- /dev/null +++ b/lib/stwcs/gui/pars/updatewcs.cfg @@ -0,0 +1,8 @@ +_task_name_ = updatewcs +input = "*flt.fits" +extname = "SCI" +vacorr = True +tddcorr = True +npolcorr = True +d2imcorr = True +checkfiles = True diff --git a/lib/stwcs/gui/pars/updatewcs.cfgspc b/lib/stwcs/gui/pars/updatewcs.cfgspc new file mode 100644 index 0000000..1ce03bf --- /dev/null +++ b/lib/stwcs/gui/pars/updatewcs.cfgspc @@ -0,0 +1,8 @@ +_task_name_ = string_kw(default="updatewcs") +input = string_kw(default="", comment="Input files (name, suffix, or @list)") +extname = string_kw(default="SCI", comment="EXTNAME of extensions to be archived") +vacorr = boolean_kw(default=True, comment= "Apply vecocity aberration correction?") +tddcorr = boolean_kw(default=True, comment= "Apply time dependent distortion correction?") +npolcorr = boolean_kw(default=True, comment= "Apply lookup table distortion?") +d2imcorr = boolean_kw(default=True, comment= "Apply detector to image correction?") +checkfiles = boolean_kw(default=True, comment= "Check format of input files?") diff --git a/lib/stwcs/gui/pars/write_headerlet.cfg b/lib/stwcs/gui/pars/write_headerlet.cfg new file mode 100644 index 0000000..7dfa3aa --- /dev/null +++ b/lib/stwcs/gui/pars/write_headerlet.cfg @@ -0,0 +1,16 @@ +_task_name_ = write_headerlet +filename = "" +hdrname = "" +wcskey = "PRIMARY" +wcsname = "" +author = "" +descrip = "" +history = "" +output = "" +clobber = True +sciext = "SCI" +destim = "" +sipname = "" +npolfile = "" +d2imfile = "" +attach = True diff --git a/lib/stwcs/gui/pars/write_headerlet.cfgspc b/lib/stwcs/gui/pars/write_headerlet.cfgspc new file mode 100644 index 0000000..41527ab --- /dev/null +++ b/lib/stwcs/gui/pars/write_headerlet.cfgspc @@ -0,0 +1,16 @@ +_task_name_ = string_kw(default="write_headerlet") +filename = string_kw(default="", comment="Input file name") +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") +npolfile = string_kw(default="", comment="Name for source of non-polynomial residuals") +d2imfile = string_kw(default="", comment="Name for source of detector correction table") +attach = boolean_kw(default=True, comment="Create output headerlet FITS file?") diff --git a/lib/stwcs/gui/restore_headerlet.help b/lib/stwcs/gui/restore_headerlet.help new file mode 100644 index 0000000..710d457 --- /dev/null +++ b/lib/stwcs/gui/restore_headerlet.help @@ -0,0 +1,41 @@ +Restore headerlet extension(s) as either a primary WCS or as alternate WCSs + +This task can restore a WCS solution stored in a headerlet extension or +restore all WCS solutions from all headerlet extensions with the same +distortion model. + +Parameters +---------- +filename: string or HDUList + Either a filename or PyFITS HDUList object for the input science file + An input filename (str) will be expanded as necessary to interpret + any environmental variables included in the filename. + +archive: boolean (default True) + flag indicating if HeaderletHDUs should be created from the + primary and alternate WCSs in fname before restoring all matching + headerlet extensions + +force: boolean (default:False) + When the distortion models of the headerlet and the primary do + not match, and archive is False, this flag forces an update of + the primary. + +distname: string + distortion model as represented by a DISTNAME keyword + +primary: int or string or None + HeaderletHDU to be restored as primary + if int - a fits extension + if string - HDRNAME + if None - use first HeaderletHDU + +sciext: string (default: SCI) + EXTNAME value of FITS extensions with WCS keywords + +hdrname: string + HDRNAME keyword of HeaderletHDU + +hdrext: int or tuple + Headerlet extension number of tuple ('HDRLET',2) + diff --git a/lib/stwcs/gui/restore_headerlet.py b/lib/stwcs/gui/restore_headerlet.py new file mode 100644 index 0000000..9de2d3b --- /dev/null +++ b/lib/stwcs/gui/restore_headerlet.py @@ -0,0 +1,49 @@ +import os +import string + +import pyfits +from stsci.tools import teal + +import stwcs +from stwcs.wcsutil import headerlet + +__taskname__ = __name__.split('.')[-1] # needed for help string +__package__ = headerlet.__name__ +__version__ = stwcs.__version__ +# +#### Interfaces used by TEAL +# +def getHelpAsString(docstring=False): + """ + return useful help from a file in the script directory called __taskname__.help + """ + install_dir = os.path.dirname(__file__) + htmlfile = os.path.join(install_dir,'htmlhelp',__taskname__+'.html') + helpfile = os.path.join(install_dir,__taskname__+'.help') + if docstring or (not docstring and not os.path.exists(htmlfile)): + helpString = __taskname__+' Version '+__version__+'\n\n' + if os.path.exists(helpfile): + helpString += teal.getHelpFileAsString(__taskname__,__file__) + else: + helpString = 'file://'+htmlfile + + return helpString + +def run(configObj=None): + + if configObj['distname'] not in ['',' ','INDEF']: + # Call function with properly interpreted input parameters + # Syntax: restore_all_with_distname(filename, distname, primary, + # archive=True, sciext='SCI', verbose=False) + headerlet.restore_all_with_distname(configObj['filename'], + configObj['distname'],configObj['primary'], + archive=configObj['archive'],sciext=configObj['sciext'], + verbose=configObj['verbose']) + else: + # Call function with properly interpreted input parameters + # restore_from_headerlet(filename, hdrname=None, hdrext=None, + # archive=True, force=False) + headerlet.restore_from_headerlet(configObj['filename'], + hdrname=configObj['hdrname'],hdrext=configObj['hdrext'], + archive=configObj['archive'], force=configObj['force']) + diff --git a/lib/stwcs/gui/updatewcs.py b/lib/stwcs/gui/updatewcs.py new file mode 100644 index 0000000..912bf16 --- /dev/null +++ b/lib/stwcs/gui/updatewcs.py @@ -0,0 +1,89 @@ +import os + +import pyfits +from stsci.tools import parseinput +from stsci.tools import fileutil +from stsci.tools import teal +import stwcs +from stwcs import updatewcs +from stwcs.wcsutil import convertwcs + +allowed_corr_dict = {'vacorr':'VACorr','tddcorr':'TDDCorr','npolcorr':'NPOLCorr','d2imcorr':'DET2IMCorr'} + +__taskname__ = __name__.split('.')[-1] # needed for help string +__package__ = updatewcs.__name__ +__version__ = stwcs.__version__ + +# +#### Interfaces used by TEAL +# +def getHelpAsString(docstring=False): + """ + return useful help from a file in the script directory called __taskname__.help + """ + install_dir = os.path.dirname(__file__) + htmlfile = os.path.join(install_dir,'htmlhelp',__taskname__+'.html') + helpfile = os.path.join(install_dir,__taskname__+'.help') + if docstring or (not docstring and not os.path.exists(htmlfile)): + helpString = __taskname__+' Version '+__version__+'\n\n' + if os.path.exists(helpfile): + helpString += teal.getHelpFileAsString(__taskname__,__file__) + else: + helpString += eval('.'.join([__package__,__taskname__,'__doc__'])) + + else: + helpString = 'file://'+htmlfile + + return helpString + +def run(configObj=None): + + # Interpret primary parameters from configObj instance + extname = configObj['extname'] + input = configObj['input'] + + # create dictionary of remaining parameters, deleting extraneous ones + # such as those above + cdict = configObj.dict() + # remove any rules defined for the TEAL interface + if cdict.has_key("_RULES_"): del cdict['_RULES_'] + del cdict['_task_name_'] + del cdict['input'] + del cdict['extname'] + + # parse input + input,altfiles = parseinput.parseinput(configObj['input']) + + # Insure that all input files have a correctly archived + # set of OPUS WCS keywords + # Legacy files from OTFR, like all WFPC2 data from OTFR, will only + # have the OPUS WCS keywords archived using a prefix of 'O' + # These keywords need to be converted to the Paper I alternate WCS + # standard using a wcskey (suffix) of 'O' + # If an alternate WCS with wcskey='O' already exists, this will copy + # the values from the old prefix-'O' WCS keywords to insure the correct + # OPUS keyword values get archived for use with updatewcs. + # + for file in input: + # Check to insure that there is a valid reference file to be used + idctab = pyfits.getval(file,'idctab') + if not os.path.exists(fileutil.osfn(idctab)): + print 'No valid distortion reference file ',idctab,' found in ',file,'!' + raise ValueError + + # Re-define 'cdict' to only have switches for steps supported by that instrument + # the set of supported steps are defined by the dictionary + # updatewcs.apply_corrections.allowed_corrections + # + for file in input: + # get instrument name from input file + instr = pyfits.getval(file,'INSTRUME') + # make copy of input parameters dict for this file + fdict = cdict.copy() + # Remove any parameter that is not part of this instrument's allowed corrections + for step in allowed_corr_dict: + if allowed_corr_dict[step] not in updatewcs.apply_corrections.allowed_corrections[instr]: + fdict[step] + # Call 'updatewcs' on correctly archived file + updatewcs.updatewcs(file,**fdict) + diff --git a/lib/stwcs/gui/write_headerlet.py b/lib/stwcs/gui/write_headerlet.py new file mode 100644 index 0000000..2072d2e --- /dev/null +++ b/lib/stwcs/gui/write_headerlet.py @@ -0,0 +1,75 @@ +import os + +import pyfits +from stsci.tools import teal + +import stwcs +from stwcs.wcsutil import headerlet + +__taskname__ = __name__.split('.')[-1] # needed for help string +__package__ = headerlet.__name__ +__version__ = stwcs.__version__ +# +#### Interfaces used by TEAL +# +def getHelpAsString(docstring=False): + """ + return useful help from a file in the script directory called __taskname__.help + """ + install_dir = os.path.dirname(__file__) + htmlfile = os.path.join(install_dir,'htmlhelp',__taskname__+'.html') + helpfile = os.path.join(install_dir,__taskname__+'.help') + if docstring or (not docstring and not os.path.exists(htmlfile)): + helpString = __taskname__+' Version '+__version__+'\n\n' + if os.path.exists(helpfile): + helpString += teal.getHelpFileAsString(__taskname__,__file__) + else: + helpString += headerlet.write_headerlet.__doc__ + + else: + helpString = 'file://'+htmlfile + + return helpString + +def run(configObj=None): + if not os.path.exists(configObj['filename']): + print '='*60 + print 'ERROR:' + print ' No valid "filename" parameter value provided!' + print ' Please check the working directory and restart this task.' + print '='*60 + return + + if configObj['hdrname'] in ['',' ','INDEF']: + print '='*60 + print 'ERROR:' + print ' No valid "hdrname" 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'] + + # create dictionary of remaining parameters, deleting extraneous ones + # such as those above + cdict = configObj.dict() + # remove any rules defined for the TEAL interface + if cdict.has_key("_RULES_"): del cdict['_RULES_'] + del cdict['_task_name_'] + del cdict['filename'] + del cdict['hdrname'] + + # Convert blank string input as None + for kw in str_kw: + if cdict[kw] == '': cdict[kw] = None + if cdict['wcskey'].lower() == 'primary': cdict['wcskey'] = ' ' + + # Call function with properly interpreted input parameters + # Syntax: write_headerlet(filename, hdrname, output, sciext='SCI', + # wcsname=None, wcskey=None, destim=None, + # sipname=None, npolfile=None, d2imfile=None, + # author=None, descrip=None, history=None, + # attach=True, clobber=False) + headerlet.write_headerlet(configObj['filename'], configObj['hdrname'], + **cdict)
\ No newline at end of file |