summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/stwcs/gui/apply_headerlet.help12
-rw-r--r--lib/stwcs/gui/apply_headerlet.py19
-rw-r--r--lib/stwcs/gui/delete_headerlet.py11
-rw-r--r--lib/stwcs/gui/pars/delete_headerlet.cfgspc2
-rw-r--r--lib/stwcs/wcsutil/headerlet.py117
-rw-r--r--setup.cfg2
6 files changed, 116 insertions, 47 deletions
diff --git a/lib/stwcs/gui/apply_headerlet.help b/lib/stwcs/gui/apply_headerlet.help
index 15c81a0..f701b52 100644
--- a/lib/stwcs/gui/apply_headerlet.help
+++ b/lib/stwcs/gui/apply_headerlet.help
@@ -1,5 +1,5 @@
This task applies a headerlet to a science observation to update either the
-PRIMARY WCS or to add it as an alternate WCS.
+PRIMARY WCS or to add it as an alternate WCS.
filename = ""
hdrlet = ""
@@ -13,10 +13,10 @@ verbose = False
Parameters
----------
-filename: string
- File name of science observation whose WCS solution will be updated
-hdrlet: string
- Headerlet file
+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
@@ -29,7 +29,7 @@ force: boolean
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
+ 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
diff --git a/lib/stwcs/gui/apply_headerlet.py b/lib/stwcs/gui/apply_headerlet.py
index 1b97e38..d87f586 100644
--- a/lib/stwcs/gui/apply_headerlet.py
+++ b/lib/stwcs/gui/apply_headerlet.py
@@ -1,8 +1,8 @@
import os
-import string
+import string
import pyfits
-from stsci.tools import teal
+from stsci.tools import teal, parseinput
import stwcs
from stwcs.wcsutil import headerlet
@@ -31,12 +31,16 @@ def getHelpAsString(docstring=False):
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(configObj['filename'],
- configObj['hdrlet'],attach=configObj['attach'],
+ headerlet.apply_headerlet_as_primary(filename,
+ hdrlet,attach=configObj['attach'],
archive=configObj['archive'],force=configObj['force'],
logging=configObj['logging'])
else:
@@ -45,10 +49,9 @@ def run(configObj=None):
wcskey = configObj['wcskey']
if wcskey == '': wcskey = None
# Call function with properly interpreted input parameters
- # apply_headerlet_as_alternate(filename, hdrlet, attach=True,
+ # 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'],
+ headerlet.apply_headerlet_as_alternate(filename,
+ hdrlet, attach=configObj['attach'],
wcsname=wcsname, wcskey=wcskey,
logging=configObj['logging'])
-
diff --git a/lib/stwcs/gui/delete_headerlet.py b/lib/stwcs/gui/delete_headerlet.py
index 24a2ba2..9eed22b 100644
--- a/lib/stwcs/gui/delete_headerlet.py
+++ b/lib/stwcs/gui/delete_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
@@ -31,7 +32,7 @@ def getHelpAsString(docstring=False):
return helpString
def run(configObj=None):
-
+
if configObj['hdrname'] == '' and configObj['hdrext'] is None and \
configObj['distname'] == '':
print '='*60
@@ -40,12 +41,12 @@ def run(configObj=None):
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(configObj['filename'],
- hdrname = configObj['hdrname'],
- hdrext = configObj['hdrext'],
+ headerlet.delete_headerlet(filename,
+ hdrname = configObj['hdrname'],
+ hdrext = configObj['hdrext'],
distname = configObj['distname'],
logging = configObj['logging'])
diff --git a/lib/stwcs/gui/pars/delete_headerlet.cfgspc b/lib/stwcs/gui/pars/delete_headerlet.cfgspc
index 7b7cc0b..43790b1 100644
--- a/lib/stwcs/gui/pars/delete_headerlet.cfgspc
+++ b/lib/stwcs/gui/pars/delete_headerlet.cfgspc
@@ -1,5 +1,5 @@
_task_name_ = string_kw(default="delete_headerlet")
-filename = string_kw(default="", comment="FITS image file name")
+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")
diff --git a/lib/stwcs/wcsutil/headerlet.py b/lib/stwcs/wcsutil/headerlet.py
index 5eff40c..935b280 100644
--- a/lib/stwcs/wcsutil/headerlet.py
+++ b/lib/stwcs/wcsutil/headerlet.py
@@ -1109,10 +1109,10 @@ def apply_headerlet_as_primary(filename, hdrlet, attach=True, archive=True,
Parameters
----------
- filename: string
- File name of science observation whose WCS solution will be updated
- hdrlet: string
- Headerlet file
+ filename: string or list of strings
+ File name(s) of science observation whose WCS solution will be updated
+ hdrlet: string or list of strings
+ Headerlet file(s), must match 1-to-1 with input filename(s)
attach: boolean
True (default): append headerlet to FITS file as a new extension.
archive: boolean
@@ -1126,9 +1126,18 @@ def apply_headerlet_as_primary(filename, hdrlet, attach=True, archive=True,
logmode: 'w' or 'a'
log file open mode
"""
-
- hlet = Headerlet.fromfile(hdrlet, logging=logging, logmode=logmode)
- hlet.apply_as_primary(filename, attach=attach, archive=archive,
+ if not isinstance(filename, list):
+ filename = [filename]
+ if not isinstance(hdrlet, list):
+ hdrlet = [hdrlet]
+ if len(hdrlet) != len(filename):
+ logger.critical("Filenames must have matching headerlets. "
+ "{0:d} filenames and {1:d} headerlets specified".format(len(filename),len(hdrlet)))
+
+ for fname,h in zip(filename,hdrlet):
+ print "Applying {0} as Primary WCS to {1}".format(h,fname)
+ hlet = Headerlet.fromfile(h, logging=logging, logmode=logmode)
+ hlet.apply_as_primary(fname, attach=attach, archive=archive,
force=force)
@@ -1140,10 +1149,10 @@ def apply_headerlet_as_alternate(filename, hdrlet, attach=True, wcskey=None,
Parameters
----------
- filename: string
- File name of science observation whose WCS solution will be updated
- hdrlet: string
- Headerlet file
+ filename: string or list of strings
+ File name(s) of science observation whose WCS solution will be updated
+ hdrlet: string or list of strings
+ Headerlet file(s), must match 1-to-1 with input filename(s)
attach: boolean
flag indicating if the headerlet should be attached as a
HeaderletHDU to fobj. If True checks that HDRNAME is unique
@@ -1159,9 +1168,18 @@ def apply_headerlet_as_alternate(filename, hdrlet, attach=True, wcskey=None,
enable file logging
logmode: 'a' or 'w'
"""
-
- hlet = Headerlet.fromfile(hdrlet, logging=logging, logmode=logmode)
- hlet.apply_as_alternate(filename, attach=attach,
+ if not isinstance(filename, list):
+ filename = [filename]
+ if not isinstance(hdrlet, list):
+ hdrlet = [hdrlet]
+ if len(hdrlet) != len(filename):
+ logger.critical("Filenames must have matching headerlets. "
+ "{0:d} filenames and {1:d} headerlets specified".format(len(filename),len(hdrlet)))
+
+ for fname,h in zip(filename,hdrlet):
+ print 'Applying {0} as an alternate WCS to {1}'.format(h,fname)
+ hlet = Headerlet.fromfile(h, logging=logging, logmode=logmode)
+ hlet.apply_as_alternate(fname, attach=attach,
wcsname=wcsname, wcskey=wcskey)
@@ -1172,24 +1190,72 @@ def attach_headerlet(filename, hdrlet, logging=False, logmode='a'):
Parameters
----------
- filename: string, HDUList
- science file to which the headerlet should be applied
- hdrlet: string or Headerlet object
- string representing a headerlet file
+ filename: HDUList or list of HDULists
+ science file(s) to which the headerlet should be applied
+ hdrlet: string, Headerlet object or list of strings or Headerlet objects
+ string representing a headerlet file(s), must match 1-to-1 input filename(s)
logging: boolean
enable file logging
logmode: 'a' or 'w'
"""
+ if not isinstance(filename, list):
+ filename = [filename]
+ if not isinstance(hdrlet, list):
+ hdrlet = [hdrlet]
+ if len(hdrlet) != len(filename):
+ logger.critical("Filenames must have matching headerlets. "
+ "{0:d} filenames and {1:d} headerlets specified".format(len(filename),len(hdrlet)))
- hlet = Headerlet.fromfile(hdrlet, logging=logging, logmode=logmode)
- hlet.attach_to_file(filename,archive=True)
+ for fname,h in zip(filename,hdrlet):
+ print 'Attaching {0} as Headerlet extension to {1}'.format(h,fname)
+ hlet = Headerlet.fromfile(h, logging=logging, logmode=logmode)
+ hlet.attach_to_file(fname,archive=True)
@with_logging
def delete_headerlet(filename, hdrname=None, hdrext=None, distname=None,
logging=False, logmode='w'):
"""
- Deletes HeaderletHDU(s) from a science file
+ Deletes HeaderletHDU(s) with same HDRNAME from science files
+
+ Notes
+ -----
+ One of hdrname, hdrext or distname should be given.
+ If hdrname is given - delete a HeaderletHDU with a name HDRNAME from fobj.
+ If hdrext is given - delete HeaderletHDU in extension.
+ If distname is given - deletes all HeaderletHDUs with a specific distortion model from fobj.
+ Updates wcscorr
+
+ Parameters
+ ----------
+ filename: string or HDUList
+ Filename can be specified as a single filename or HDUList, a comma-separated
+ list of filenames, a wild-card filename (e.g., 'j6q*flt.fits') or
+ '@-file'.
+ Each input filename (str) will be expanded as necessary to interpret
+ any environmental variables included in the filename.
+ hdrname: string or None
+ HeaderletHDU primary header keyword HDRNAME
+ hdrext: int, tuple or None
+ HeaderletHDU FITS extension number
+ tuple has the form ('HDRLET', 1)
+ distname: string or None
+ distortion model as specified in the DISTNAME keyword
+ logging: boolean
+ enable file logging
+ logmode: 'a' or 'w'
+ """
+ fnames = parseinput.parseinput(filename)[0]
+
+ for f in fnames:
+ print "Deleting Headerlet from ",f
+ _delete_single_headerlet(f, hdrname=hdrname, hdrext=hdrext,
+ distname=distname, logging=logging, logmode='a')
+
+def _delete_single_headerlet(filename, hdrname=None, hdrext=None, distname=None,
+ logging=False, logmode='w'):
+ """
+ Deletes HeaderletHDU(s) from a SINGLE science file
Notes
-----
@@ -1216,7 +1282,6 @@ def delete_headerlet(filename, hdrname=None, hdrext=None, distname=None,
enable file logging
logmode: 'a' or 'w'
"""
-
hdrlet_ind = find_headerlet_HDUs(filename, hdrname=hdrname, hdrext=hdrext,
distname=distname, logging=logging, logmode='a')
if len(hdrlet_ind) == 0:
@@ -1712,11 +1777,9 @@ class Headerlet(pyfits.HDUList):
self.logging = logging
init_logging('class Headerlet', level=logging, mode=logmode)
- #fobj, fname, close_file = parse_filename(fobj)
super(Headerlet, self).__init__(hdus, file=file)
- if hdus == []:
- return
+ def init_attrs(self):
self.fname = self.filename()
self.hdrname = self[0].header["HDRNAME"]
self.wcsname = self[0].header["WCSNAME"]
@@ -1728,6 +1791,7 @@ class Headerlet(pyfits.HDUList):
self.npolfile = self[0].header["NPOLFILE"]
self.d2imfile = self[0].header["D2IMFILE"]
self.distname = self[0].header["DISTNAME"]
+
try:
self.vafactor = self[("SIPWCS", 1)].header.get("VAFACTOR", 1) #None instead of 1?
except (IndexError, KeyError):
@@ -1751,6 +1815,8 @@ class Headerlet(pyfits.HDUList):
save_backup=False, logging=False, logmode='w', **kwargs):
hlet = super(cls, cls).fromfile(fileobj, mode, memmap, save_backup,
**kwargs)
+ if len(hlet) > 0:
+ hlet.init_attrs()
hlet.logging = logging
init_logging('class Headerlet', level=logging, mode=logmode)
return hlet
@@ -2256,7 +2322,6 @@ class Headerlet(pyfits.HDUList):
DESTIM in the primary header of the headerlet must match ROOTNAME
of the science file (or the name of the destination file)
"""
-
try:
if not isinstance(dest, pyfits.HDUList):
droot = pyfits.getval(dest, 'ROOTNAME')
diff --git a/setup.cfg b/setup.cfg
index 9c83e53..66d6088 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,7 +1,7 @@
[metadata]
name = stwcs
# version is the *next* version to be release, with .dev at the end if it is not final
-version = 1.1.1.dev
+version = 1.1.2.dev
author = Nadia Dencheva, Warren Hack
author-email = help@stsci.edu
summary = Recomputes the WCS of an HST observation and puts all distortion