summaryrefslogtreecommitdiff
path: root/lib/stwcs/wcsutil
diff options
context:
space:
mode:
Diffstat (limited to 'lib/stwcs/wcsutil')
-rw-r--r--lib/stwcs/wcsutil/__init__.py8
-rw-r--r--lib/stwcs/wcsutil/altwcs.py187
-rw-r--r--lib/stwcs/wcsutil/convertwcs.py17
-rw-r--r--lib/stwcs/wcsutil/getinput.py10
-rw-r--r--lib/stwcs/wcsutil/headerlet.py91
-rw-r--r--lib/stwcs/wcsutil/hstwcs.py107
-rw-r--r--lib/stwcs/wcsutil/mosaic.py8
-rw-r--r--lib/stwcs/wcsutil/wcscorr.py52
-rw-r--r--lib/stwcs/wcsutil/wcsdiff.py7
9 files changed, 243 insertions, 244 deletions
diff --git a/lib/stwcs/wcsutil/__init__.py b/lib/stwcs/wcsutil/__init__.py
index 9b7ed8c..b92299e 100644
--- a/lib/stwcs/wcsutil/__init__.py
+++ b/lib/stwcs/wcsutil/__init__.py
@@ -3,16 +3,14 @@ from __future__ import division # confidence high
from altwcs import *
from hstwcs import HSTWCS
-__docformat__ = 'restructuredtext'
-
def help():
print 'How to create an HSTWCS object:\n\n'
print """ \
- 1. Using a pyfits HDUList object and an extension number \n
+ 1. Using a `astropy.io.fits.HDUList` object and an extension number \n
Example:\n
-
- fobj = pyfits.open('some_file.fits')\n
+ from astropy.io improt fits
+ fobj = fits.open('some_file.fits')\n
w = wcsutil.HSTWCS(fobj, 3)\n\n
2. Create an HSTWCS object using a qualified file name. \n
diff --git a/lib/stwcs/wcsutil/altwcs.py b/lib/stwcs/wcsutil/altwcs.py
index a8f1cc1..71588f4 100644
--- a/lib/stwcs/wcsutil/altwcs.py
+++ b/lib/stwcs/wcsutil/altwcs.py
@@ -3,10 +3,8 @@ import os
import string
import numpy as np
-#import pywcs
from astropy import wcs as pywcs
-from astropy.io import fits as pyfits
-#import pyfits
+from astropy.io import fits
from stsci.tools import fileutil as fu
altwcskw = ['WCSAXES', 'CRVAL', 'CRPIX', 'PC', 'CDELT', 'CD', 'CTYPE', 'CUNIT',
@@ -21,19 +19,19 @@ def archiveWCS(fname, ext, wcskey=" ", wcsname=" ", reusekey=False):
Parameters
----------
- fname: string or pyfits.HDUList
- a file name or a file object
- ext: an int, a tuple, string, or list of integers or tuples (e.g.('sci',1))
- fits extensions to work with
- If a string is provided, it should specify the EXTNAME of extensions
- with WCSs to be archived
- wcskey: string "A"-"Z" or " "
- if " ": get next available key if wcsname is also " " or try
- to get a key from WCSNAME value
- wcsname: string
- Name of alternate WCS description
- reusekey: boolean
- if True - overwrites a WCS with the same key
+ fname : string or `astropy.io.fits.HDUList`
+ file name or a file object
+ ext : int, tuple, str, or list of integers or tuples (e.g.('sci',1))
+ fits extensions to work with
+ If a string is provided, it should specify the EXTNAME of extensions
+ with WCSs to be archived
+ wcskey : string "A"-"Z" or " "
+ if " ": get next available key if wcsname is also " " or try
+ to get a key from WCSNAME value
+ wcsname : string
+ Name of alternate WCS description
+ reusekey : boolean
+ if True - overwrites a WCS with the same key
Examples
--------
@@ -55,7 +53,7 @@ def archiveWCS(fname, ext, wcskey=" ", wcsname=" ", reusekey=False):
"""
if isinstance(fname, str):
- f = pyfits.open(fname, mode='update')
+ f = fits.open(fname, mode='update')
else:
f = fname
@@ -151,7 +149,7 @@ def restore_from_to(f, fromext=None, toext=None, wcskey=" ", wcsname=" "):
Parameters
----------
- f: string or pyfits.HDUList object
+ f: string or `astropy.io.fits.HDUList`
a file name or a file object
fromext: string
extname from which to read in the alternate WCS, for example 'SCI'
@@ -171,7 +169,7 @@ def restore_from_to(f, fromext=None, toext=None, wcskey=" ", wcsname=" "):
"""
if isinstance(f, str):
- fobj = pyfits.open(f, mode='update')
+ fobj = fits.open(f, mode='update')
else:
fobj = f
@@ -232,17 +230,17 @@ def restoreWCS(f, ext, wcskey=" ", wcsname=" "):
Parameters
----------
- f: string or pyfits.HDUList object
- a file name or a file object
- ext: an int, a tuple, string, or list of integers or tuples (e.g.('sci',1))
- fits extensions to work with
- If a string is provided, it should specify the EXTNAME of extensions
- with WCSs to be archived
- wcskey: a charater
- "A"-"Z" - Used for one of 26 alternate WCS definitions.
- or " " - find a key from WCSNAMe value
- wcsname: string (optional)
- if given and wcskey is " ", will try to restore by WCSNAME value
+ f : str or `astropy.io.fits.HDUList`
+ file name or a file object
+ ext : int, tuple, str, or list of integers or tuples (e.g.('sci',1))
+ fits extensions to work with
+ If a string is provided, it should specify the EXTNAME of extensions
+ with WCSs to be archived
+ wcskey : str
+ "A"-"Z" - Used for one of 26 alternate WCS definitions.
+ or " " - find a key from WCSNAMe value
+ wcsname : str
+ (optional) if given and wcskey is " ", will try to restore by WCSNAME value
See Also
--------
@@ -251,7 +249,7 @@ def restoreWCS(f, ext, wcskey=" ", wcsname=" "):
"""
if isinstance(f, str):
- fobj = pyfits.open(f, mode='update')
+ fobj = fits.open(f, mode='update')
else:
fobj = f
@@ -301,17 +299,18 @@ def deleteWCS(fname, ext, wcskey=" ", wcsname=" "):
Parameters
----------
- fname: sting or a pyfits.HDUList object
- ext: an int, a tuple, string, or list of integers or tuples (e.g.('sci',1))
- fits extensions to work with
- If a string is provided, it should specify the EXTNAME of extensions
- with WCSs to be archived
- wcskey: one of 'A'-'Z' or " "
- wcsname: string
- Name of alternate WCS description
+ fname : str or a `astropy.io.fits.HDUList`
+ ext : int, tuple, str, or list of integers or tuples (e.g.('sci',1))
+ fits extensions to work with
+ If a string is provided, it should specify the EXTNAME of extensions
+ with WCSs to be archived
+ wcskey : str
+ one of 'A'-'Z' or " "
+ wcsname : str
+ Name of alternate WCS description
"""
if isinstance(fname, str):
- fobj = pyfits.open(fname, mode='update')
+ fobj = fits.open(fname, mode='update')
else:
fobj = fname
@@ -436,19 +435,19 @@ def _restore(fobj, ukey, fromextnum,
#header operations
def _check_headerpars(fobj, ext):
- if not isinstance(fobj, pyfits.Header) and not isinstance(fobj, pyfits.HDUList) \
+ if not isinstance(fobj, fits.Header) and not isinstance(fobj, fits.HDUList) \
and not isinstance(fobj, str):
raise ValueError("Expected a file name, a file object or a header\n")
- if not isinstance(fobj, pyfits.Header):
+ if not isinstance(fobj, fits.Header):
#raise ValueError("Expected a valid ext parameter when input is a file")
if not isinstance(ext, int) and not isinstance(ext, tuple):
raise ValueError("Expected ext to be a number or a tuple, e.g. ('SCI', 1)\n")
def _getheader(fobj, ext):
if isinstance(fobj, str):
- hdr = pyfits.getheader(fobj,ext)
- elif isinstance(fobj, pyfits.Header):
+ hdr = fits.getheader(fobj,ext)
+ elif isinstance(fobj, fits.Header):
hdr = fobj
else:
hdr = fobj[ext].header
@@ -459,21 +458,22 @@ def readAltWCS(fobj, ext, wcskey=' ',verbose=False):
Parameters
----------
- fobj: string, pyfits.HDUList
- fits filename or pyfits file object
+ fobj : str, `astropy.io.fits.HDUList`
+ fits filename or fits file object
containing alternate/primary WCS(s) to be converted
- wcskey: string [" ",A-Z]
+ wcskey : str
+ [" ",A-Z]
alternate/primary WCS key that will be replaced by the new key
- ext: int
- extension number
+ ext : int
+ fits extension number
Returns
-------
- hdr: pyfits.Header
+ hdr: fits.Header
header object with ONLY the keywords for specified alternate WCS
"""
if isinstance(fobj, str):
- fobj = pyfits.open(fobj)
+ fobj = fits.open(fobj)
hdr = _getheader(fobj,ext)
try:
@@ -497,19 +497,21 @@ def convertAltWCS(fobj,ext,oldkey=" ",newkey=' '):
Parameters
----------
- fobj: string, pyfits.HDUList, or pyfits.Header
- fits filename, pyfits file object or pyfits header
+ fobj : str, `astropy.io.fits.HDUList`, or `astropy.io.fits.Header`
+ fits filename, fits file object or fits header
containing alternate/primary WCS(s) to be converted
- ext: int
+ ext : int
extension number
- oldkey: string [" ",A-Z]
+ oldkey : str
+ [" ",A-Z]
alternate/primary WCS key that will be replaced by the new key
- newkey: string [" ",A-Z]
+ newkey : str
+ [" ",A-Z]
new alternate/primary WCS key
Returns
-------
- hdr: pyfits.Header
+ hdr: `astropy.io.fits.Header`
header object with keywords renamed from oldkey to newkey
"""
hdr = readAltWCS(fobj,ext,wcskey=oldkey)
@@ -532,9 +534,9 @@ def wcskeys(fobj, ext=None):
Parameters
----------
- fobj: string, pyfits.HDUList or pyfits.Header
- fits file name, pyfits file object or pyfits header
- ext: int or None
+ fobj : str, `astropy.io.fits.HDUList` or `astropy.io.fits.Header`
+ fits file name, fits file object or fits header
+ ext : int or None
extension number
if None, fobj must be a header
"""
@@ -554,9 +556,9 @@ def wcsnames(fobj, ext=None):
Parameters
----------
- fobj: string, pyfits.HDUList or pyfits.Header
- fits file name, pyfits file object or pyfits header
- ext: int or None
+ fobj : stri, `astropy.io.fits.HDUList` or `astropy.io.fits.Header`
+ fits file name, fits file object or fits header
+ ext : int or None
extension number
if None, fobj must be a header
@@ -579,11 +581,11 @@ def available_wcskeys(fobj, ext=None):
Parameters
----------
- fobj: string, pyfits.HDUList or pyfits.Header
- fits file name, pyfits file object or pyfits header
- ext: int or None
- extension number
- if None, fobj must be a header
+ fobj : str, `astropy.io.fits.HDUList` or `astropy.io.fits.Header`
+ fits file name, fits file object or fits header
+ ext : int or None
+ extension number
+ if None, fobj must be a header
"""
_check_headerpars(fobj, ext)
hdr = _getheader(fobj, ext)
@@ -602,11 +604,11 @@ def next_wcskey(fobj, ext=None):
Parameters
----------
- fobj: string, pyfits.HDUList or pyfits.Header
- fits file name, pyfits file object or pyfits header
- ext: int or None
- extension number
- if None, fobj must be a header
+ fobj : str, `astropy.io.fits.HDUList` or `astropy.io.fits.Header`
+ fits file name, fits file object or fits header
+ ext : int or None
+ extension number
+ if None, fobj must be a header
"""
_check_headerpars(fobj, ext)
hdr = _getheader(fobj, ext)
@@ -624,9 +626,9 @@ def getKeyFromName(header, wcsname):
Parameters
----------
- header: pyfits.Header
- wcsname: str
- Value of WCSNAME
+ header : `astropy.io.fits.Header`
+ wcsname : str
+ value of WCSNAME
"""
wkey = None
names = wcsnames(header)
@@ -648,7 +650,7 @@ def pc2cd(hdr, key=' '):
Parameters
----------
- hdr: pyfits.Header
+ hdr: `astropy.io.fits.Header`
"""
for c in ['1_1', '1_2', '2_1', '2_2']:
@@ -668,19 +670,20 @@ def _parpasscheck(fobj, ext, wcskey, fromext=None, toext=None, reusekey=False):
"""
Check input parameters to altwcs functions
- fobj: string or pyfits.HDUList object
- a file name or a file object
- ext: an int, a tuple, a python list of integers or a python list
- of tuples (e.g.('sci',1))
- fits extensions to work with
- wcskey: a charater
- "A"-"Z" or " "- Used for one of 26 alternate WCS definitions
- wcsname: string (optional)
- if given and wcskey is " ", will try to restore by WCSNAME value
- reusekey: boolean
- A flag which indicates whether to reuse a wcskey in the header
- """
- if not isinstance(fobj,pyfits.HDUList):
+ fobj : str or `astropy.io.fits.HDUList` object
+ a file name or a file object
+ ext : int, a tuple, a python list of integers or a python list
+ of tuples (e.g.('sci',1))
+ fits extensions to work with
+ wcskey : str
+ "A"-"Z" or " "- Used for one of 26 alternate WCS definitions
+ wcsname : str
+ (optional)
+ if given and wcskey is " ", will try to restore by WCSNAME value
+ reusekey : bool
+ A flag which indicates whether to reuse a wcskey in the header
+ """
+ if not isinstance(fobj, fits.HDUList):
print "First parameter must be a fits file object or a file name."
return False
@@ -730,8 +733,8 @@ def mapFitsExt2HDUListInd(fname, extname):
Map FITS extensions with 'EXTNAME' to HDUList indexes.
"""
- if not isinstance(fname, pyfits.HDUList):
- f = pyfits.open(fname)
+ if not isinstance(fname, fits.HDUList):
+ f = fits.open(fname)
close_file = True
else:
f = fname
diff --git a/lib/stwcs/wcsutil/convertwcs.py b/lib/stwcs/wcsutil/convertwcs.py
index 6f9f0bf..7ece2a0 100644
--- a/lib/stwcs/wcsutil/convertwcs.py
+++ b/lib/stwcs/wcsutil/convertwcs.py
@@ -1,5 +1,4 @@
-from astropy.io import fits as pyfits
-
+from astropy.io import fits
try:
import stwcs
from stwcs import wcsutil
@@ -19,8 +18,8 @@ def archive_prefix_OPUS_WCS(fobj,extname='SCI'):
Parameters
----------
- fobj: string or pyfits.HDUList
- Filename or pyfits object of a file
+ fobj : str or `astropy.io.fits.HDUList`
+ Filename or fits object of a file
"""
if stwcs is None:
@@ -33,7 +32,7 @@ def archive_prefix_OPUS_WCS(fobj,extname='SCI'):
closefits = False
if isinstance(fobj,str):
# A filename was provided as input
- fobj = pyfits.open(fobj,mode='update')
+ fobj = fits.open(fobj,mode='update')
closefits=True
# Define the header
@@ -79,13 +78,13 @@ def create_prefix_OPUS_WCS(fobj,extname='SCI'):
Parameters
----------
- fobj: string or pyfits.HDUList
- Filename or pyfits object of a file
+ fobj : str or `astropy.io.fits.HDUList`
+ Filename or fits object of a file
Raises
------
IOError:
- if input PyFITS object was not opened in 'update' mode
+ if input FITS object was not opened in 'update' mode
"""
# List of O-prefix keywords to create
@@ -94,7 +93,7 @@ def create_prefix_OPUS_WCS(fobj,extname='SCI'):
closefits = False
if isinstance(fobj,str):
# A filename was provided as input
- fobj = pyfits.open(fobj,mode='update')
+ fobj = fits.open(fobj, mode='update')
closefits=True
else:
# check to make sure this FITS obj has been opened in update mode
diff --git a/lib/stwcs/wcsutil/getinput.py b/lib/stwcs/wcsutil/getinput.py
index b5a5df7..dbd240f 100644
--- a/lib/stwcs/wcsutil/getinput.py
+++ b/lib/stwcs/wcsutil/getinput.py
@@ -1,4 +1,4 @@
-from astropy.io import fits as pyfits
+from astropy.io import fits
from stsci.tools import irafglob, fileutil, parseinput
def parseSingleInput(f=None, ext=None):
@@ -20,14 +20,14 @@ def parseSingleInput(f=None, ext=None):
extnum = int(ext[1]) #handle ext=('',extnum)
else:
extnum = ext
- phdu = pyfits.open(filename)
+ phdu = fits.open(filename)
hdr0 = phdu[0].header
try:
ehdr = phdu[extnum].header
except (IndexError, KeyError), e:
raise e.__class__('Unable to get extension %s.' % extnum)
- elif isinstance(f, pyfits.HDUList):
+ elif isinstance(f, fits.HDUList):
phdu = f
if ext == None:
extnum = 0
@@ -38,8 +38,8 @@ def parseSingleInput(f=None, ext=None):
filename = hdr0.get('FILENAME', "")
else:
- raise ValueError('Input must be a file name string or a pyfits file '
- 'object')
+ raise ValueError('Input must be a file name string or a'
+ '`astropy.io.fits.HDUList` object')
return filename, hdr0, ehdr, phdu
diff --git a/lib/stwcs/wcsutil/headerlet.py b/lib/stwcs/wcsutil/headerlet.py
index 3ab53f5..a314cc0 100644
--- a/lib/stwcs/wcsutil/headerlet.py
+++ b/lib/stwcs/wcsutil/headerlet.py
@@ -19,7 +19,7 @@ import copy
import time
import numpy as np
-from astropy.io import fits as pyfits
+from astropy.io import fits
#import pywcs
from astropy import wcs as pywcs
from astropy.utils import lazyproperty
@@ -125,27 +125,28 @@ def parse_filename(fname, mode='readonly'):
Parameters
----------
- fname: string, pyfits.HDUList
- Input pointing to a file or PyFITS object. An input filename (str) will
- be expanded as necessary to interpret any environmental variables
+ fname : str, `astropy.io.fits.HDUList`
+ Input pointing to a file or `astropy.io.fits.HDUList` object.
+ An input filename (str) will be expanded as necessary to
+ interpret any environmental variables
included in the filename.
- mode: string
- Specifies what PyFITS mode to use when opening the file, if it needs
+ mode : string
+ Specifies what mode to use when opening the file, if it needs
to open the file at all [Default: 'readonly']
Returns
-------
- fobj: pyfits.HDUList
- PyFITS handle for input file
+ fobj : `astropy.io.fits.HDUList`
+ FITS file handle for input
- fname: string
+ fname : str
Name of input file
- close_fobj: bool
+ close_fobj : bool
Flag specifying whether or not fobj needs to be closed since it was
opened by this function. This allows a program to know whether they
- need to worry about closing the PyFITS object as opposed to letting
+ need to worry about closing the FITS object as opposed to letting
the higher level interface close the object.
"""
@@ -153,7 +154,7 @@ def parse_filename(fname, mode='readonly'):
if not isinstance(fname, list):
if isinstance(fname, basestring):
fname = fu.osfn(fname)
- fobj = pyfits.open(fname, mode=mode)
+ fobj = fits.open(fname, mode=mode)
close_fobj = True
else:
fobj = fname
@@ -170,8 +171,8 @@ def get_headerlet_kw_names(fobj, kw='HDRNAME'):
Parameters
----------
- fobj: string, pyfits.HDUList
- kw: str
+ fobj : str, `astropy.io.fits.HDUList`
+ kw : str
Name of keyword to be read and reported
"""
@@ -179,7 +180,7 @@ def get_headerlet_kw_names(fobj, kw='HDRNAME'):
hdrnames = []
for ext in fobj:
- if isinstance(ext, pyfits.hdu.base.NonstandardExtHDU):
+ if isinstance(ext, fits.hdu.base.NonstandardExtHDU):
hdrnames.append(ext.header[kw])
if open_fobj:
@@ -205,27 +206,27 @@ def find_headerlet_HDUs(fobj, hdrext=None, hdrname=None, distname=None,
Parameters
----------
- fobj: string, pyfits.HDUList
- Name of FITS file or open pyfits object (pyfits.HDUList instance)
- hdrext: int, tuple or None
+ fobj : str, `astropy.io.fits.HDUList`
+ Name of FITS file or open fits object (`astropy.io.fits.HDUList` instance)
+ hdrext : int, tuple or None
index number(EXTVER) or extension tuple of HeaderletHDU to be returned
- hdrname: string
+ hdrname : string
value of HDRNAME for HeaderletHDU to be returned
- distname: string
+ distname : string
value of DISTNAME for HeaderletHDUs to be returned
- strict: bool [Default: True]
+ strict : bool [Default: True]
Specifies whether or not at least one parameter needs to be provided
If False, all extension indices returned if hdrext, hdrname and distname
are all None. If True and hdrext, hdrname, and distname are all None,
raise an Exception requiring one to be specified.
- logging: boolean
+ logging : boolean
enable logging to a file called headerlet.log
- logmode: 'w' or 'a'
+ logmode : 'w' or 'a'
log file open mode
Returns
-------
- hdrlets: list
+ hdrlets : list
A list of all matching HeaderletHDU extension indices (could be just one)
"""
@@ -249,12 +250,12 @@ def find_headerlet_HDUs(fobj, hdrext=None, hdrname=None, distname=None,
hdrlets = []
if hdrext is not None and isinstance(hdrext, int):
if hdrext in range(len(fobj)): # insure specified hdrext is in fobj
- if isinstance(fobj[hdrext], pyfits.hdu.base.NonstandardExtHDU) and \
+ if isinstance(fobj[hdrext], fits.hdu.base.NonstandardExtHDU) and \
fobj[hdrext].header['EXTNAME'] == 'HDRLET':
hdrlets.append(hdrext)
else:
for ext in fobj:
- if isinstance(ext, pyfits.hdu.base.NonstandardExtHDU):
+ if isinstance(ext, fits.hdu.base.NonstandardExtHDU):
if get_all:
hdrlets.append(fobj.index(ext))
else:
@@ -305,9 +306,9 @@ def verify_hdrname_is_unique(fobj, hdrname):
Parameters
----------
- fobj: string, pyfits.HDUList
- Name of FITS file or open pyfits object (pyfits.HDUList instance)
- hdrname: string
+ fobj : str, `astropy.io.fits.HDUList`
+ Name of FITS file or open fits file object
+ hdrname : str
value of HDRNAME for HeaderletHDU to be compared as unique
Returns
@@ -340,8 +341,8 @@ def update_ref_files(source, dest):
Parameters
----------
- source: pyfits.Header
- dest: pyfits.Header
+ source : `astropy.io.fits.Header`
+ dest : `astropy.io.fits.Header`
"""
logger.info("Updating reference files")
phdukw = {'NPOLFILE': True,
@@ -470,7 +471,7 @@ def _create_primary_HDU(fobj, fname, wcsext, destim, hdrname, wcsname,
upwcsver = fobj[0].header.get('UPWCSVER', "")
pywcsver = fobj[0].header.get('PYWCSVER', "")
# build Primary HDU
- phdu = pyfits.PrimaryHDU()
+ phdu = fits.PrimaryHDU()
phdu.header['DESTIM'] = (destim, 'Destination observation root name')
phdu.header['HDRNAME'] = (hdrname, 'Headerlet name')
fmt = "%Y-%m-%dT%H:%M:%S"
@@ -555,7 +556,7 @@ def extract_headerlet(filename, output, extnum=None, hdrname=None,
"""
- if isinstance(filename, pyfits.HDUList):
+ if isinstance(filename, fits.HDUList):
filename = [filename]
else:
filename, oname = parseinput.parseinput(filename)
@@ -689,7 +690,7 @@ def write_headerlet(filename, hdrname, output=None, sciext='SCI',
enable file logging
"""
- if isinstance(filename, pyfits.HDUList):
+ if isinstance(filename, fits.HDUList):
filename = [filename]
else:
filename, oname = parseinput.parseinput(filename)
@@ -1021,7 +1022,7 @@ def create_headerlet(filename, sciext='SCI', hdrname=None, destim=None,
hwcs = HSTWCS(fobj, ext=ext, wcskey=wcskey)
- whdul = hwcs.to_fits(relax=True, wkey=" ")
+ whdul = hwcs.to_fits(relax=True, key=" ")
if hasattr(hwcs, 'orientat'):
orient_comment = "positions angle of image y axis (deg. e of n)"
whdul[0].header['ORIENTAT'] = (wcs.orientat, orient_comment)
@@ -1064,7 +1065,7 @@ def create_headerlet(filename, sciext='SCI', hdrname=None, destim=None,
whdul[0].header['DP1.EXTVER'] = fobj[ext].header['DP1.EXTVER']
if 'DP2.EXTVER' in whdul[0].header:
whdul[0].header['DP2.EXTVER'] = fobj[ext].header['DP2.EXTVER']
- ihdu = pyfits.ImageHDU(header=whdul[0].header, name='SIPWCS')
+ ihdu = fits.ImageHDU(header=whdul[0].header, name='SIPWCS')
if ext[0] != "PRIMARY":
ihdu.update_ext_version(fobj[ext].header['EXTVER'], comment='Extension version')
@@ -1761,7 +1762,7 @@ def archive_as_headerlet(filename, hdrname, sciext='SCI',
fobj.close()
#### Headerlet Class definitions
-class Headerlet(pyfits.HDUList):
+class Headerlet(fits.HDUList):
"""
A Headerlet class
Ref: http://mediawiki.stsci.edu/mediawiki/index.php/Telescopedia:Headerlets
@@ -2133,7 +2134,7 @@ class Headerlet(pyfits.HDUList):
fhdr = fobj[tg_ext].header
hwcs = pywcs.WCS(siphdr, self)
- hwcs_header = hwcs.to_header(wkey=wkey)
+ hwcs_header = hwcs.to_header(key=wkey)
_idc2hdr(siphdr, fhdr, towkey=wkey)
if hwcs.wcs.has_cd():
hwcs_header = altwcs.pc2cd(hwcs_header, key=wkey)
@@ -2144,7 +2145,7 @@ class Headerlet(pyfits.HDUList):
for kw in self.fit_kws:
#fhdr.insert(wind, pyfits.Card(kw + wkey,
# self[0].header[kw]))
- fhdr.append(pyfits.Card(kw + wkey, self[0].header[kw]))
+ fhdr.append(fits.Card(kw + wkey, self[0].header[kw]))
# Update the WCSCORR table with new rows from the headerlet's WCSs
wcscorr.update_wcscorr(fobj, self, 'SIPWCS')
@@ -2301,8 +2302,8 @@ class Headerlet(pyfits.HDUList):
model/reference files.
"""
destim_opened = False
- if not isinstance(dest, pyfits.HDUList):
- destim = pyfits.open(dest)
+ if not isinstance(dest, fits.HDUList):
+ destim = fits.open(dest)
destim_opened = True
else:
destim = dest
@@ -2333,8 +2334,8 @@ class Headerlet(pyfits.HDUList):
of the science file (or the name of the destination file)
"""
try:
- if not isinstance(dest, pyfits.HDUList):
- droot = pyfits.getval(dest, 'ROOTNAME')
+ if not isinstance(dest, fits.HDUList):
+ droot = fits.getval(dest, 'ROOTNAME')
else:
droot = dest[0].header['ROOTNAME']
except KeyError:
@@ -2660,7 +2661,7 @@ def get_extname_extver_list(fobj, sciext):
return extlist
-class HeaderletHDU(pyfits.hdu.nonstandard.FitsHDU):
+class HeaderletHDU(fits.hdu.nonstandard.FitsHDU):
"""
A non-standard extension HDU for encapsulating Headerlets in a file. These
HDUs have an extension type of HDRLET and their EXTNAME is derived from the
@@ -2740,4 +2741,4 @@ class HeaderletHDU(pyfits.hdu.nonstandard.FitsHDU):
return hlet
-pyfits.register_hdu(HeaderletHDU)
+fits.register_hdu(HeaderletHDU)
diff --git a/lib/stwcs/wcsutil/hstwcs.py b/lib/stwcs/wcsutil/hstwcs.py
index b9983e6..4c2c140 100644
--- a/lib/stwcs/wcsutil/hstwcs.py
+++ b/lib/stwcs/wcsutil/hstwcs.py
@@ -1,10 +1,8 @@
from __future__ import division # confidence high
import os
-#from pywcs import WCS
from astropy.wcs import WCS
-from astropy.io import fits as pyfits
-#import pyfits
+from astropy.io import fits
import instruments
from stwcs.distortion import models, coeff_converter
import altwcs
@@ -113,22 +111,22 @@ class HSTWCS(WCS):
Parameters
----------
- fobj: string or PyFITS HDUList object or None
- a file name, e.g j9irw4b1q_flt.fits
- a fully qualified filename[EXTNAME,EXTNUM], e.g. j9irw4b1q_flt.fits[sci,1]
- a pyfits file object, e.g pyfits.open('j9irw4b1q_flt.fits'), in which case the
- user is responsible for closing the file object.
- ext: int, tuple or None
- extension number
- if ext is tuple, it must be ("EXTNAME", EXTNUM), e.g. ("SCI", 2)
- if ext is None, it is assumed the data is in the primary hdu
- minerr: float
- minimum value a distortion correction must have in order to be applied.
- If CPERRja, CQERRja are smaller than minerr, the corersponding
- distortion is not applied.
- wcskey: str
- A one character A-Z or " " used to retrieve and define an
- alternate WCS description.
+ fobj : str or `astropy.io.fits.HDUList` object or None
+ file name, e.g j9irw4b1q_flt.fits
+ fully qualified filename[EXTNAME,EXTNUM], e.g. j9irw4b1q_flt.fits[sci,1]
+ `astropy.io.fits` file object, e.g fits.open('j9irw4b1q_flt.fits'), in which case the
+ user is responsible for closing the file object.
+ ext : int, tuple or None
+ extension number
+ if ext is tuple, it must be ("EXTNAME", EXTNUM), e.g. ("SCI", 2)
+ if ext is None, it is assumed the data is in the primary hdu
+ minerr : float
+ minimum value a distortion correction must have in order to be applied.
+ If CPERRja, CQERRja are smaller than minerr, the corersponding
+ distortion is not applied.
+ wcskey : str
+ A one character A-Z or " " used to retrieve and define an
+ alternate WCS description.
"""
self.inst_kw = ins_spec_kw
@@ -146,9 +144,9 @@ class HSTWCS(WCS):
self.instrument = instrument_name
WCS.__init__(self, ehdr, fobj=phdu, minerr=self.minerr,
key=self.wcskey)
- # If input was a pyfits HDUList object, it's the user's
+ # If input was a `astropy.io.fits.HDUList` object, it's the user's
# responsibility to close it, otherwise, it's closed here.
- if not isinstance(fobj, pyfits.HDUList):
+ if not isinstance(fobj, fits.HDUList):
phdu.close()
self.setInstrSpecKw(hdr0, ehdr)
self.readIDCCoeffs(ehdr)
@@ -197,10 +195,10 @@ class HSTWCS(WCS):
Parameters
----------
- prim_hdr: pyfits.Header
- primary header
- ext_hdr: pyfits.Header
- extension header
+ prim_hdr : `astropy.io.fits.Header`
+ primary header
+ ext_hdr : `astropy.io.fits.Header`
+ extension header
"""
if self.instrument in inst_mappings.keys():
@@ -270,12 +268,12 @@ class HSTWCS(WCS):
Parameters
----------
- header: pyfits.Header
- fits extension header
- update: boolean (False)
- if True - record the following IDCTAB quantities as header keywords:
- CX10, CX11, CY10, CY11, IDCSCALE, IDCTHETA, IDCXREF, IDCYREF,
- IDCV2REF, IDCV3REF
+ header : `astropy.io.fits.Header`
+ fits extension header
+ update : bool (False)
+ if True - record the following IDCTAB quantities as header keywords:
+ CX10, CX11, CY10, CY11, IDCSCALE, IDCTHETA, IDCXREF, IDCYREF,
+ IDCV2REF, IDCV3REF
"""
if self.idctab in [None, '', ' ','N/A']:
#Keyword idctab is not present in header - check for sip coefficients
@@ -321,12 +319,12 @@ class HSTWCS(WCS):
Parameters
----------
- header: pyfits.Header
- fits extension header
- update: boolean (False)
- if True - save teh following as header keywords:
- CX10, CX11, CY10, CY11, IDCSCALE, IDCTHETA, IDCXREF, IDCYREF,
- IDCV2REF, IDCV3REF
+ header : `astropy.io.fits.Header`
+ fits extension header
+ update : booln (False)
+ if True - save teh following as header keywords:
+ CX10, CX11, CY10, CY11, IDCSCALE, IDCTHETA, IDCXREF, IDCYREF,
+ IDCV2REF, IDCV3REF
"""
if self.date_obs == None:
@@ -373,15 +371,15 @@ class HSTWCS(WCS):
def wcs2header(self, sip2hdr=False, idc2hdr=True, wcskey=None, relax=False):
"""
- Create a pyfits.Header object from WCS keywords.
+ Create a `astropy.io.fits.Header` object from WCS keywords.
If the original header had a CD matrix, return a CD matrix,
otherwise return a PC matrix.
Parameters
----------
- sip2hdr: boolean
- If True - include SIP coefficients
+ sip2hdr : bool
+ If True - include SIP coefficients
"""
h = self.to_header(key=wcskey, relax=relax)
@@ -399,7 +397,7 @@ class HSTWCS(WCS):
if idc2hdr:
for card in self._idc2hdr():
- h[card.key+wcskey] = (card.value, card.comment)
+ h[card.keyword + wcskey] = (card.value, card.comment)
try:
del h['RESTFRQ']
del h['RESTWAV']
@@ -407,9 +405,9 @@ class HSTWCS(WCS):
if sip2hdr and self.sip:
for card in self._sip2hdr('a'):
- h[card.key] = (card.value, card.comment)
+ h[card.keyword] = (card.value, card.comment)
for card in self._sip2hdr('b'):
- h[card.key] = (card.value, card.comment)
+ h[card.keyword] = (card.value, card.comment)
try:
ap = self.sip.ap
@@ -422,41 +420,41 @@ class HSTWCS(WCS):
if ap:
for card in self._sip2hdr('ap'):
- h[card.key] = (card.value, card.comment)
+ h[card.keyword] = (card.value, card.comment)
if bp:
for card in self._sip2hdr('bp'):
- h[card.key] = (card.value, card.comment)
+ h[card.keyword] = (card.value, card.comment)
return h
def _sip2hdr(self, k):
"""
Get a set of SIP coefficients in the form of an array
- and turn them into a pyfits.Cardlist.
+ and turn them into a `astropy.io.fits.Cardlist`.
k - one of 'a', 'b', 'ap', 'bp'
"""
- cards = pyfits.CardList()
+ cards = fits.CardList()
korder = self.sip.__getattribute__(k+'_order')
- cards.append(pyfits.Card(key=k.upper()+'_ORDER', value=korder))
+ cards.append(fits.Card(keyword=k.upper()+'_ORDER', value=korder))
coeffs = self.sip.__getattribute__(k)
ind = coeffs.nonzero()
for i in range(len(ind[0])):
- card = pyfits.Card(key=k.upper()+'_'+str(ind[0][i])+'_'+str(ind[1][i]),
- value=coeffs[ind[0][i], ind[1][i]])
+ card = fits.Card(keyword=k.upper()+'_'+str(ind[0][i])+'_'+str(ind[1][i]),
+ value=coeffs[ind[0][i], ind[1][i]])
cards.append(card)
return cards
def _idc2hdr(self):
# save some of the idc coefficients
coeffs = ['ocx10', 'ocx11', 'ocy10', 'ocy11', 'idcscale']
- cards = pyfits.CardList()
+ cards = fits.CardList()
for c in coeffs:
try:
val = self.__getattribute__(c)
except AttributeError:
continue
if val:
- cards.append(pyfits.Card(key=c, value=val))
+ cards.append(fits.Card(keyword=c, value=val))
return cards
def pc2cd(self):
@@ -606,8 +604,9 @@ detect_divergence=True, quiet=False)
Examples
--------
- >>> import stwcs, pyfits
- >>> hdulist = pyfits.open('j94f05bgq_flt.fits')
+ >>> import stwcs
+ >>> from astropy.io import fits
+ >>> hdulist = fits.open('j94f05bgq_flt.fits')
>>> w = stwcs.wcsutil.HSTWCS(hdulist, ext=('sci',1))
>>> hdulist.close()
diff --git a/lib/stwcs/wcsutil/mosaic.py b/lib/stwcs/wcsutil/mosaic.py
index 5f15f2f..ffdc103 100644
--- a/lib/stwcs/wcsutil/mosaic.py
+++ b/lib/stwcs/wcsutil/mosaic.py
@@ -1,7 +1,7 @@
from __future__ import division
import numpy as np
from matplotlib import pyplot as plt
-from astropy.io import fits as pyfits
+from astropy.io import fits
import string
from stsci.tools import parseinput, irafglob
@@ -83,7 +83,7 @@ def vmosaic(fnames, outwcs=None, ref_wcs=None, ext=None, extname=None, undistort
return outwcs
def updatehdr(fname, wcsobj, wkey, wcsname, ext=1, clobber=False):
- hdr = pyfits.getheader(fname, ext=ext)
+ hdr = fits.getheader(fname, ext=ext)
all_keys = list(string.ascii_uppercase)
if wkey.upper() not in all_keys:
raise KeyError, "wkey must be one character: A-Z"
@@ -92,7 +92,7 @@ def updatehdr(fname, wcsobj, wkey, wcsname, ext=1, clobber=False):
raise ValueError, "wkey %s is already in use. Use clobber=True to overwrite it or specify a different key." %wkey
else:
altwcs.deleteWCS(fname, ext=ext, wcskey='V')
- f = pyfits.open(fname, mode='update')
+ f = fits.open(fname, mode='update')
hwcs = wcs2header(wcsobj)
wcsnamekey = 'WCSNAME' + wkey
@@ -152,7 +152,7 @@ def readWCS(input, exts=None, extname=None):
continue
elif extname != None:
for f in filelist:
- fobj = pyfits.open(f)
+ fobj = fits.open(f)
for i in range(len(fobj)):
try:
ename = fobj[i].header['EXTNAME']
diff --git a/lib/stwcs/wcsutil/wcscorr.py b/lib/stwcs/wcsutil/wcscorr.py
index c581e7f..fedc2b2 100644
--- a/lib/stwcs/wcsutil/wcscorr.py
+++ b/lib/stwcs/wcsutil/wcscorr.py
@@ -1,5 +1,5 @@
import os,copy
-from astropy.io import fits as pyfits
+from astropy.io import fits
import numpy as np
from stsci.tools import fileutil
@@ -31,9 +31,9 @@ def init_wcscorr(input, force=False):
"""
# TODO: Create some sort of decorator or (for Python2.5) context for
# opening a FITS file and closing it when done, if necessary
- if not isinstance(input, pyfits.HDUList):
- # input must be a filename, so open as PyFITS object
- fimg = pyfits.open(input, mode='update')
+ if not isinstance(input, fits.HDUList):
+ # input must be a filename, so open as `astropy.io.fits.HDUList` object
+ fimg = fits.open(input, mode='update')
need_to_close = True
else:
fimg = input
@@ -225,8 +225,8 @@ def archive_wcs_file(image, wcs_id=None):
newly updated WCS keyword values.
"""
- if not isinstance(image, pyfits.HDUList):
- fimg = pyfits.open(image, mode='update')
+ if not isinstance(image, fits.HDUList):
+ fimg = fits.open(image, mode='update')
close_image = True
else:
fimg = image
@@ -265,8 +265,8 @@ def update_wcscorr(dest, source=None, extname='SCI', wcs_id=None, active=True):
active WCS information, not just appending the WCS to the file as a
headerlet
"""
- if not isinstance(dest,pyfits.HDUList):
- dest = pyfits.open(dest,mode='update')
+ if not isinstance(dest, fits.HDUList):
+ dest = fits.open(dest,mode='update')
fname = dest.filename()
if source is None:
@@ -409,7 +409,7 @@ def update_wcscorr(dest, source=None, extname='SCI', wcs_id=None, active=True):
if (old_nrows + new_nrows) > old_table.data.shape[0]-1:
pad_rows = 2 * new_nrows
# if not, create a new table with 'pad_rows' new empty rows
- upd_table = pyfits.new_table(old_table.columns,header=old_table.header,
+ upd_table = fits.new_table(old_table.columns,header=old_table.header,
nrows=old_table.data.shape[0]+pad_rows)
else:
upd_table = old_table
@@ -435,8 +435,8 @@ def restore_file_from_wcscorr(image, id='OPUS', wcskey=''):
If wcskey is specified, the WCS with that key will be updated instead.
"""
- if not isinstance(image, pyfits.HDUList):
- fimg = pyfits.open(image, mode='update')
+ if not isinstance(image, fits.HDUList):
+ fimg = fits.open(image, mode='update')
close_image = True
else:
fimg = image
@@ -517,32 +517,32 @@ def create_wcscorr(descrip=False, numrows=1, padding=0):
('NMatch', def_int32_col), ('Catalog', def_str40_col)]
# Define selector columns
- id_col = pyfits.Column(name='WCS_ID', format='40A',
- array=np.array(['OPUS'] * numrows + [''] * padding,
- dtype='S24'))
- extver_col = pyfits.Column(name='EXTVER', format='I',
- array=np.array(range(1, numrows + 1),
- dtype=np.int16))
- wcskey_col = pyfits.Column(name='WCS_key', format='A',
- array=np.array(['O'] * numrows + [''] * padding,
- dtype='S'))
+ id_col = fits.Column(name='WCS_ID', format='40A',
+ array=np.array(['OPUS'] * numrows + [''] * padding,
+ dtype='S24'))
+ extver_col = fits.Column(name='EXTVER', format='I',
+ array=np.array(range(1, numrows + 1),
+ dtype=np.int16))
+ wcskey_col = fits.Column(name='WCS_key', format='A',
+ array=np.array(['O'] * numrows + [''] * padding,
+ dtype='S'))
# create list of remaining columns to be added to table
col_list = [id_col, extver_col, wcskey_col] # start with selector columns
for c in col_names:
cdef = copy.deepcopy(c[1])
- col_list.append(pyfits.Column(name=c[0], format=cdef['format'],
+ col_list.append(fits.Column(name=c[0], format=cdef['format'],
array=cdef['array']))
if descrip:
col_list.append(
- pyfits.Column(name='DESCRIP', format='128A',
- array=np.array(
- ['Original WCS computed by OPUS'] * numrows,
- dtype='S128')))
+ fits.Column(name='DESCRIP', format='128A',
+ array=np.array(
+ ['Original WCS computed by OPUS'] * numrows,
+ dtype='S128')))
# Now create the new table from the column definitions
- newtab = pyfits.new_table(pyfits.ColDefs(col_list), nrows=trows)
+ newtab = fits.new_table(fits.ColDefs(col_list), nrows=trows)
# The fact that setting .name is necessary should be considered a bug in
# pyfits.
# TODO: Make sure this is fixed in pyfits, then remove this
diff --git a/lib/stwcs/wcsutil/wcsdiff.py b/lib/stwcs/wcsutil/wcsdiff.py
index f027df2..cfc2d66 100644
--- a/lib/stwcs/wcsutil/wcsdiff.py
+++ b/lib/stwcs/wcsutil/wcsdiff.py
@@ -1,8 +1,7 @@
from __future__ import print_function
-#import pywcs
from astropy import wcs as pywcs
from collections import OrderedDict
-from astropy.io import fits as pyfits
+from astropy.io import fits
from .headerlet import parse_filename
import numpy as np
@@ -127,10 +126,10 @@ def is_wcs_identical(scifile, file2, sciextlist, fextlist, scikey=" ",
def get_rootname(fname):
"""
- returns the value of ROOTNAME or DESTIM
+ Returns the value of ROOTNAME or DESTIM
"""
- hdr = pyfits.getheader(fname)
+ hdr = fits.getheader(fname)
try:
rootname = hdr['ROOTNAME']
except KeyError: