diff options
Diffstat (limited to 'stwcs/gui')
30 files changed, 808 insertions, 0 deletions
diff --git a/stwcs/gui/__init__.py b/stwcs/gui/__init__.py new file mode 100644 index 0000000..cd21bf6 --- /dev/null +++ b/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 absolute_import # confidence high +__docformat__ = 'restructuredtext' + +# import modules which define the TEAL interfaces +from . import write_headerlet +from . import extract_headerlet +from . import attach_headerlet +from . import delete_headerlet +from . import headerlet_summary +from . import archive_headerlet +from . import restore_headerlet +from . import apply_headerlet +from . import updatewcs diff --git a/stwcs/gui/apply_headerlet.help b/stwcs/gui/apply_headerlet.help new file mode 100644 index 0000000..f701b52 --- /dev/null +++ b/stwcs/gui/apply_headerlet.help @@ -0,0 +1,38 @@ +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 or wild-card name + File name(s) of science observation whose WCS solution will be updated +hdrlet: string, @-file or wild-card name + Headerlet file(s), must match input filenames 1-to-1 +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. +logging: boolean + enable file logging diff --git a/stwcs/gui/apply_headerlet.py b/stwcs/gui/apply_headerlet.py new file mode 100644 index 0000000..d517e9f --- /dev/null +++ b/stwcs/gui/apply_headerlet.py @@ -0,0 +1,54 @@ +import os +from stsci.tools import teal, parseinput + +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): + + # start by interpreting filename and hdrlet inputs + filename = parseinput.parseinput(configObj['filename'])[0] + hdrlet = parseinput.parseinput(configObj['hdrlet'])[0] + + 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(filename, + hdrlet,attach=configObj['attach'], + archive=configObj['archive'],force=configObj['force'], + logging=configObj['logging']) + 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(filename, + hdrlet, attach=configObj['attach'], + wcsname=wcsname, wcskey=wcskey, + logging=configObj['logging']) diff --git a/stwcs/gui/archive_headerlet.py b/stwcs/gui/archive_headerlet.py new file mode 100644 index 0000000..7ad3d4d --- /dev/null +++ b/stwcs/gui/archive_headerlet.py @@ -0,0 +1,69 @@ +from __future__ import print_function +import os + +from astropy.io import fits +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 "_RULES_" in cdict: 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) diff --git a/stwcs/gui/attach_headerlet.py b/stwcs/gui/attach_headerlet.py new file mode 100644 index 0000000..873c549 --- /dev/null +++ b/stwcs/gui/attach_headerlet.py @@ -0,0 +1,36 @@ +import os + +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'], + configObj['logging']) + diff --git a/stwcs/gui/delete_headerlet.py b/stwcs/gui/delete_headerlet.py new file mode 100644 index 0000000..b3df5a7 --- /dev/null +++ b/stwcs/gui/delete_headerlet.py @@ -0,0 +1,52 @@ +from __future__ import print_function +import os + +from stsci.tools import teal +from stsci.tools import parseinput + +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 + filename = parseinput.parseinput(configObj['filename'])[0] + # Call function with properly interpreted input parameters + # Syntax: delete_headerlet(filename, hdrname=None, hdrext=None, distname=None) + headerlet.delete_headerlet(filename, + hdrname = configObj['hdrname'], + hdrext = configObj['hdrext'], + distname = configObj['distname'], + logging = configObj['logging']) + diff --git a/stwcs/gui/extract_headerlet.py b/stwcs/gui/extract_headerlet.py new file mode 100644 index 0000000..02ecd7a --- /dev/null +++ b/stwcs/gui/extract_headerlet.py @@ -0,0 +1,58 @@ +from __future__ import print_function +import os + +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 "_RULES_" in cdict: 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/stwcs/gui/headerlet_summary.py b/stwcs/gui/headerlet_summary.py new file mode 100644 index 0000000..82a3e0c --- /dev/null +++ b/stwcs/gui/headerlet_summary.py @@ -0,0 +1,47 @@ +import os +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 "_RULES_" in cdict: 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/stwcs/gui/pars/apply_headerlet.cfg b/stwcs/gui/pars/apply_headerlet.cfg new file mode 100644 index 0000000..06d6daf --- /dev/null +++ b/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 = "" +logging = False diff --git a/stwcs/gui/pars/apply_headerlet.cfgspc b/stwcs/gui/pars/apply_headerlet.cfgspc new file mode 100644 index 0000000..648e562 --- /dev/null +++ b/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") +logging = boolean_kw(default=False, comment= "Enable logging to a file") +[ _RULES_ ] +_rule1_ = string_kw(default=True, code='tyfn={"yes":True, "no":False}; OUT = tyfn[VAL]') diff --git a/stwcs/gui/pars/archive_headerlet.cfg b/stwcs/gui/pars/archive_headerlet.cfg new file mode 100644 index 0000000..97cd7ef --- /dev/null +++ b/stwcs/gui/pars/archive_headerlet.cfg @@ -0,0 +1,14 @@ +_task_name_ = archive_headerlet +filename = "" +hdrname = "" +sciext = "SCI" +wcsname = "" +wcskey = "PRIMARY" +destim = "" +sipname = "" +npolfile = "" +d2imfile = "" +author = "" +descrip = "" +history = "" +logging = False
\ No newline at end of file diff --git a/stwcs/gui/pars/archive_headerlet.cfgspc b/stwcs/gui/pars/archive_headerlet.cfgspc new file mode 100644 index 0000000..03e67f0 --- /dev/null +++ b/stwcs/gui/pars/archive_headerlet.cfgspc @@ -0,0 +1,14 @@ +_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") +logging = boolean_kw(default=False, comment= "Enable logging to a file")
\ No newline at end of file diff --git a/stwcs/gui/pars/attach_headerlet.cfg b/stwcs/gui/pars/attach_headerlet.cfg new file mode 100644 index 0000000..d131a70 --- /dev/null +++ b/stwcs/gui/pars/attach_headerlet.cfg @@ -0,0 +1,4 @@ +_task_name_ = attach_headerlet +filename = "" +hdrlet = "" +logging = False diff --git a/stwcs/gui/pars/attach_headerlet.cfgspc b/stwcs/gui/pars/attach_headerlet.cfgspc new file mode 100644 index 0000000..bc91bca --- /dev/null +++ b/stwcs/gui/pars/attach_headerlet.cfgspc @@ -0,0 +1,4 @@ +_task_name_ = string_kw(default="attach_headerlet") +filename = string_kw(default="", comment="FITS image file name") +hdrlet = string_kw(default="", comment="Headerlet FITS filename") +logging = boolean_kw(default=False, comment= "Enable logging to a file")
\ No newline at end of file diff --git a/stwcs/gui/pars/delete_headerlet.cfg b/stwcs/gui/pars/delete_headerlet.cfg new file mode 100644 index 0000000..d156937 --- /dev/null +++ b/stwcs/gui/pars/delete_headerlet.cfg @@ -0,0 +1,6 @@ +_task_name_ = delete_headerlet +filename = "" +hdrname = "" +hdrext = None +distname = "" +logging = False
\ No newline at end of file diff --git a/stwcs/gui/pars/delete_headerlet.cfgspc b/stwcs/gui/pars/delete_headerlet.cfgspc new file mode 100644 index 0000000..43790b1 --- /dev/null +++ b/stwcs/gui/pars/delete_headerlet.cfgspc @@ -0,0 +1,6 @@ +_task_name_ = string_kw(default="delete_headerlet") +filename = string_kw(default="", comment="FITS image file name(s), list or wild-card") +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") +logging = boolean_kw(default=False, comment= "Enable logging to a file") diff --git a/stwcs/gui/pars/extract_headerlet.cfg b/stwcs/gui/pars/extract_headerlet.cfg new file mode 100644 index 0000000..3dd0a7a --- /dev/null +++ b/stwcs/gui/pars/extract_headerlet.cfg @@ -0,0 +1,7 @@ +_task_name_ = extract_headerlet +filename = "" +output = "" +extnum = None +hdrname = "" +clobber = True +logging = False diff --git a/stwcs/gui/pars/extract_headerlet.cfgspc b/stwcs/gui/pars/extract_headerlet.cfgspc new file mode 100644 index 0000000..b50d4bf --- /dev/null +++ b/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?") +logging = boolean_kw(default=False, comment= "Enable logging to a file") diff --git a/stwcs/gui/pars/headerlet_summary.cfg b/stwcs/gui/pars/headerlet_summary.cfg new file mode 100644 index 0000000..7203552 --- /dev/null +++ b/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/stwcs/gui/pars/headerlet_summary.cfgspc b/stwcs/gui/pars/headerlet_summary.cfgspc new file mode 100644 index 0000000..ce65930 --- /dev/null +++ b/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/stwcs/gui/pars/restore_headerlet.cfg b/stwcs/gui/pars/restore_headerlet.cfg new file mode 100644 index 0000000..b0ec427 --- /dev/null +++ b/stwcs/gui/pars/restore_headerlet.cfg @@ -0,0 +1,10 @@ +_task_name_ = restore_headerlet +filename = "" +archive = True +force = False +distname = "" +primary = None +sciext = "SCI" +hdrname = "" +hdrext = None +logging = False
\ No newline at end of file diff --git a/stwcs/gui/pars/restore_headerlet.cfgspc b/stwcs/gui/pars/restore_headerlet.cfgspc new file mode 100644 index 0000000..df47e3f --- /dev/null +++ b/stwcs/gui/pars/restore_headerlet.cfgspc @@ -0,0 +1,12 @@ +_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") +logging = boolean_kw(default=False, comment= "Enable logging to a file") +[ _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/stwcs/gui/pars/updatewcs.cfg b/stwcs/gui/pars/updatewcs.cfg new file mode 100644 index 0000000..35360f2 --- /dev/null +++ b/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/stwcs/gui/pars/updatewcs.cfgspc b/stwcs/gui/pars/updatewcs.cfgspc new file mode 100644 index 0000000..a3a3fb5 --- /dev/null +++ b/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 velocity 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/stwcs/gui/pars/write_headerlet.cfg b/stwcs/gui/pars/write_headerlet.cfg new file mode 100644 index 0000000..9eb4592 --- /dev/null +++ b/stwcs/gui/pars/write_headerlet.cfg @@ -0,0 +1,18 @@ +_task_name_ = write_headerlet +filename = "" +output = "" +clobber = True +hdrname = "" +wcskey = "PRIMARY" +wcsname = "" +author = "" +descrip = "" +catalog = "" +history = "" +sciext = "SCI" +destim = "" +sipname = "" +npolfile = "" +d2imfile = "" +attach = True +logging = False
\ No newline at end of file diff --git a/stwcs/gui/pars/write_headerlet.cfgspc b/stwcs/gui/pars/write_headerlet.cfgspc new file mode 100644 index 0000000..ba28b05 --- /dev/null +++ b/stwcs/gui/pars/write_headerlet.cfgspc @@ -0,0 +1,18 @@ +_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") +catalog = string_kw(default="", comment="Reference frame for headerlet solution") +history = string_kw(default="", comment="Name of ASCII file containing history for headerlet") +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 headerlet FITS extension?") +logging = boolean_kw(default=False, comment= "Enable logging to a file")
\ No newline at end of file diff --git a/stwcs/gui/restore_headerlet.help b/stwcs/gui/restore_headerlet.help new file mode 100644 index 0000000..fe07a15 --- /dev/null +++ b/stwcs/gui/restore_headerlet.help @@ -0,0 +1,43 @@ +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) + +logging: boolean + enable file logging
\ No newline at end of file diff --git a/stwcs/gui/restore_headerlet.py b/stwcs/gui/restore_headerlet.py new file mode 100644 index 0000000..7570d76 --- /dev/null +++ b/stwcs/gui/restore_headerlet.py @@ -0,0 +1,48 @@ +import os + +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'], + logging=configObj['logging']) + 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'], + logging=configObj['logging']) + diff --git a/stwcs/gui/updatewcs.py b/stwcs/gui/updatewcs.py new file mode 100644 index 0000000..3dacb67 --- /dev/null +++ b/stwcs/gui/updatewcs.py @@ -0,0 +1,90 @@ +from __future__ import print_function +import os + +from astropy.io import fits +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 "_RULES_" in cdict: 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 = fits.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 = fits.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/stwcs/gui/write_headerlet.py b/stwcs/gui/write_headerlet.py new file mode 100644 index 0000000..e18bed8 --- /dev/null +++ b/stwcs/gui/write_headerlet.py @@ -0,0 +1,80 @@ +from __future__ import print_function +import os + +from stsci.tools import teal +from stsci.tools import parseinput + +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): + flist,oname = parseinput.parseinput(configObj['filename']) + if len(flist) == 0: + 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 + + if configObj['output'] in ['',' ','INDEF']: + configObj['output'] = None + + str_kw = ['wcsname','destim','sipname','npolfile','d2imfile', + 'descrip','history','author','output','catalog'] + + # create dictionary of remaining parameters, deleting extraneous ones + # such as those above + cdict = configObj.dict() + # remove any rules defined for the TEAL interface + if "_RULES_" in cdict: 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(flist, configObj['hdrname'], + **cdict) |