summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/stwcs/distortion/coeff_converter.py12
-rw-r--r--lib/stwcs/distortion/utils.py3
-rw-r--r--lib/stwcs/gui/apply_headerlet.py3
-rw-r--r--lib/stwcs/gui/archive_headerlet.py3
-rw-r--r--lib/stwcs/gui/attach_headerlet.py2
-rw-r--r--lib/stwcs/gui/delete_headerlet.py2
-rw-r--r--lib/stwcs/gui/extract_headerlet.py2
-rw-r--r--lib/stwcs/gui/headerlet_summary.py3
-rw-r--r--lib/stwcs/gui/restore_headerlet.py2
-rw-r--r--lib/stwcs/gui/updatewcs.py7
-rw-r--r--lib/stwcs/gui/write_headerlet.py2
-rw-r--r--lib/stwcs/updatewcs/__init__.py21
-rw-r--r--lib/stwcs/updatewcs/apply_corrections.py20
-rw-r--r--lib/stwcs/updatewcs/det2im.py18
-rw-r--r--lib/stwcs/updatewcs/npol.py20
-rw-r--r--lib/stwcs/updatewcs/utils.py30
-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
25 files changed, 307 insertions, 330 deletions
diff --git a/lib/stwcs/distortion/coeff_converter.py b/lib/stwcs/distortion/coeff_converter.py
index 6d9a754..aace72f 100644
--- a/lib/stwcs/distortion/coeff_converter.py
+++ b/lib/stwcs/distortion/coeff_converter.py
@@ -1,18 +1,18 @@
from __future__ import division # confidence high
import numpy as np
-from astropy.io import fits as pyfits
-#import pywcs
+from astropy.io import fits
from astropy import wcs as pywcs
def sip2idc(wcs):
"""
Converts SIP style coefficients to IDCTAB coefficients.
- :Parameters:
- `wcs`: pyfits.Header or pywcs.WCS object
+ Parameters
+ ----------
+ wcs : `astropy.io.fits.Header` or `astropy.wcs.WCS` object
"""
- if isinstance(wcs,pyfits.Header):
+ if isinstance(wcs, fits.Header):
ocx10 = wcs.get('OCX10', None)
ocx11 = wcs.get('OCX11', None)
ocy10 = wcs.get('OCY10', None)
@@ -22,7 +22,7 @@ def sip2idc(wcs):
if None in [ocx10, ocx11, ocy10, ocy11, sipa, sipb]:
print 'Cannot convert SIP to IDC coefficients.\n'
return None, None
- elif isinstance(wcs,pywcs.WCS):
+ elif isinstance(wcs, pywcs.WCS):
try:
ocx10 = wcs.ocx10
ocx11 = wcs.ocx11
diff --git a/lib/stwcs/distortion/utils.py b/lib/stwcs/distortion/utils.py
index 69b24a5..5e0bf79 100644
--- a/lib/stwcs/distortion/utils.py
+++ b/lib/stwcs/distortion/utils.py
@@ -1,7 +1,6 @@
from __future__ import division # confidence high
import os
import numpy as np
-#import pywcs
from astropy import wcs as pywcs
from stwcs import wcsutil
from numpy import sqrt, arctan2
@@ -24,7 +23,7 @@ def output_wcs(list_of_wcsobj, ref_wcs=None, owcs=None, undistort=True):
undistort: boolean (default-True)
a flag whether to create an undistorted output WCS
"""
- fra_dec = np.vstack([w.calcFootprint() for w in list_of_wcsobj])
+ fra_dec = np.vstack([w.calc_footprint() for w in list_of_wcsobj])
wcsname = list_of_wcsobj[0].wcs.name
# This new algorithm may not be strictly necessary, but it may be more
diff --git a/lib/stwcs/gui/apply_headerlet.py b/lib/stwcs/gui/apply_headerlet.py
index 8d8daf9..9f51029 100644
--- a/lib/stwcs/gui/apply_headerlet.py
+++ b/lib/stwcs/gui/apply_headerlet.py
@@ -1,8 +1,5 @@
import os
import string
-
-#import pyfits
-from astropy.io import fits as pyfits
from stsci.tools import teal, parseinput
import stwcs
diff --git a/lib/stwcs/gui/archive_headerlet.py b/lib/stwcs/gui/archive_headerlet.py
index 65e133a..70dbc89 100644
--- a/lib/stwcs/gui/archive_headerlet.py
+++ b/lib/stwcs/gui/archive_headerlet.py
@@ -1,8 +1,7 @@
import os
import string
-#import pyfits
-from astropy.io import fits as pyfits
+from astropy.io import fits
from stsci.tools import teal
import stwcs
diff --git a/lib/stwcs/gui/attach_headerlet.py b/lib/stwcs/gui/attach_headerlet.py
index 5a3bdc8..873c549 100644
--- a/lib/stwcs/gui/attach_headerlet.py
+++ b/lib/stwcs/gui/attach_headerlet.py
@@ -1,7 +1,5 @@
import os
-#import pyfits
-from astropy.io import fits as pyfits
from stsci.tools import teal
import stwcs
diff --git a/lib/stwcs/gui/delete_headerlet.py b/lib/stwcs/gui/delete_headerlet.py
index f25c545..96d3ed1 100644
--- a/lib/stwcs/gui/delete_headerlet.py
+++ b/lib/stwcs/gui/delete_headerlet.py
@@ -1,7 +1,5 @@
import os
-#import pyfits
-from astropy.io import fits as pyfits
from stsci.tools import teal
from stsci.tools import parseinput
diff --git a/lib/stwcs/gui/extract_headerlet.py b/lib/stwcs/gui/extract_headerlet.py
index 16a0aee..972f5c7 100644
--- a/lib/stwcs/gui/extract_headerlet.py
+++ b/lib/stwcs/gui/extract_headerlet.py
@@ -1,7 +1,5 @@
import os
-#import pyfits
-from astropy.io import fits as pyfits
from stsci.tools import teal
import stwcs
diff --git a/lib/stwcs/gui/headerlet_summary.py b/lib/stwcs/gui/headerlet_summary.py
index 7772a95..82a3e0c 100644
--- a/lib/stwcs/gui/headerlet_summary.py
+++ b/lib/stwcs/gui/headerlet_summary.py
@@ -1,7 +1,4 @@
import os
-
-#import pyfits
-from astropy.io import fits as pyfits
from stsci.tools import teal
import stwcs
diff --git a/lib/stwcs/gui/restore_headerlet.py b/lib/stwcs/gui/restore_headerlet.py
index 46575db..2f46bb7 100644
--- a/lib/stwcs/gui/restore_headerlet.py
+++ b/lib/stwcs/gui/restore_headerlet.py
@@ -1,8 +1,6 @@
import os
import string
-#import pyfits
-from astropy.io import fits as pyfits
from stsci.tools import teal
import stwcs
diff --git a/lib/stwcs/gui/updatewcs.py b/lib/stwcs/gui/updatewcs.py
index 1e5b9d9..f8f10d7 100644
--- a/lib/stwcs/gui/updatewcs.py
+++ b/lib/stwcs/gui/updatewcs.py
@@ -1,7 +1,6 @@
import os
-#import pyfits
-from astropy.io import fits as pyfits
+from astropy.io import fits
from stsci.tools import parseinput
from stsci.tools import fileutil
from stsci.tools import teal
@@ -67,7 +66,7 @@ def run(configObj=None):
#
for file in input:
# Check to insure that there is a valid reference file to be used
- idctab = pyfits.getval(file,'idctab')
+ 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
@@ -78,7 +77,7 @@ def run(configObj=None):
#
for file in input:
# get instrument name from input file
- instr = pyfits.getval(file,'INSTRUME')
+ 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
diff --git a/lib/stwcs/gui/write_headerlet.py b/lib/stwcs/gui/write_headerlet.py
index 9ba0639..353e32b 100644
--- a/lib/stwcs/gui/write_headerlet.py
+++ b/lib/stwcs/gui/write_headerlet.py
@@ -1,7 +1,5 @@
import os
-#import pyfits
-from astropy.io import fits as pyfits
from stsci.tools import teal
from stsci.tools import parseinput
diff --git a/lib/stwcs/updatewcs/__init__.py b/lib/stwcs/updatewcs/__init__.py
index d8acb17..aca33f7 100644
--- a/lib/stwcs/updatewcs/__init__.py
+++ b/lib/stwcs/updatewcs/__init__.py
@@ -1,12 +1,11 @@
from __future__ import division # confidence high
import os
-from astropy.io import fits as pyfits
+from astropy.io import fits
import numpy as np
from stwcs import wcsutil
from stwcs.wcsutil import HSTWCS
import stwcs
-#import pywcs
from astropy import wcs as pywcs
import astropy
@@ -24,8 +23,6 @@ atexit.register(logging.shutdown)
#Note: The order of corrections is important
-__docformat__ = 'restructuredtext'
-
def updatewcs(input, vacorr=True, tddcorr=True, npolcorr=True, d2imcorr=True,
checkfiles=True, verbose=False):
"""
@@ -46,8 +43,8 @@ def updatewcs(input, vacorr=True, tddcorr=True, npolcorr=True, d2imcorr=True,
Dependencies
------------
`stsci.tools`
- `pyfits`
- `pywcs`
+ `astropy.io.fits`
+ `astropy.wcs`
Parameters
----------
@@ -114,7 +111,7 @@ def makecorr(fname, allowed_corr):
list of corrections to be applied
"""
logger.info("Allowed corrections: {0}".format(allowed_corr))
- f = pyfits.open(fname, mode='update')
+ f = fits.open(fname, mode='update')
#Determine the reference chip and create the reference HSTWCS object
nrefchip, nrefext = getNrefchip(f)
wcsutil.restoreWCS(f, nrefext, wcskey='O')
@@ -181,7 +178,7 @@ def makecorr(fname, allowed_corr):
f[0].header.set('UPWCSVER', value=stwcs.__version__,
comment="Version of STWCS used to updated the WCS",
after='ASN_MTYP')
- f[0].header.set('PYWCSVER', value=pywcs.__version__,
+ f[0].header.set('PYWCSVER', value=astropy.__version__,
comment="Version of PYWCS used to updated the WCS",
after='ASN_MTYP')
else:
@@ -192,7 +189,7 @@ def makecorr(fname, allowed_corr):
f[0].header.set('UPWCSVER', stwcs.__version__,
"Version of STWCS used to updated the WCS",
after=i)
- f[0].header.set('PYWCSVER', pywcs.__version__,
+ f[0].header.set('PYWCSVER', astropy.__version__,
"Version of PYWCS used to updated the WCS",
after=i)
# add additional keywords to be used by headerlets
@@ -231,7 +228,7 @@ def getNrefchip(fobj):
Parameters
----------
- fobj: pyfits HDUList object
+ fobj: `astropy.io.fits.HDUList` object
"""
nrefext = 1
nrefchip = 1
@@ -337,7 +334,7 @@ def checkFiles(input):
def newIDCTAB(fname):
#When this is called we know there's a kw IDCTAB in the header
- hdul = pyfits.open(fname)
+ hdul = fits.open(fname)
idctab = fileutil.osfn(hdul[0].header['IDCTAB'])
try:
#check for the presence of IDCTAB in the first extension
@@ -352,7 +349,7 @@ def newIDCTAB(fname):
def cleanWCS(fname):
# A new IDCTAB means all previously computed WCS's are invalid
# We are deleting all of them except the original OPUS WCS.nvalidates all WCS's.
- f = pyfits.open(fname, mode='update')
+ f = fits.open(fname, mode='update')
keys = wcsutil.wcskeys(f[1].header)
# Remove the primary WCS from the list
try:
diff --git a/lib/stwcs/updatewcs/apply_corrections.py b/lib/stwcs/updatewcs/apply_corrections.py
index fa56db6..b7e41b2 100644
--- a/lib/stwcs/updatewcs/apply_corrections.py
+++ b/lib/stwcs/updatewcs/apply_corrections.py
@@ -1,7 +1,7 @@
from __future__ import division # confidence high
import os
-from astropy.io import fits as pyfits
+from astropy.io import fits
import time
from stsci.tools import fileutil
import os.path
@@ -38,7 +38,7 @@ def setCorrections(fname, vacorr=True, tddcorr=True, npolcorr=True, d2imcorr=Tru
based on user input paramters and allowed corrections
for the instrument.
"""
- instrument = pyfits.getval(fname, 'INSTRUME')
+ instrument = fits.getval(fname, 'INSTRUME')
# make a copy of this list !
acorr = allowed_corrections[instrument][:]
@@ -66,7 +66,7 @@ def setCorrections(fname, vacorr=True, tddcorr=True, npolcorr=True, d2imcorr=Tru
def foundIDCTAB(fname):
try:
- idctab = fileutil.osfn(pyfits.getval(fname, 'IDCTAB'))
+ idctab = fileutil.osfn(fits.getval(fname, 'IDCTAB'))
except KeyError:
return False
if idctab == 'N/A' or idctab == "":
@@ -85,7 +85,7 @@ def applyTDDCorr(fname, utddcorr):
- the idc table specified in the primary header is available.
"""
- phdr = pyfits.getheader(fname)
+ phdr = fits.getheader(fname)
instrument = phdr['INSTRUME']
try:
detector = phdr['DETECTOR']
@@ -127,7 +127,7 @@ def applyNpolCorr(fname, unpolcorr):
applyNPOLCorr = True
try:
# get NPOLFILE kw from primary header
- fnpol0 = pyfits.getval(fname, 'NPOLFILE')
+ fnpol0 = fits.getval(fname, 'NPOLFILE')
if fnpol0 == 'N/A':
return False
fnpol0 = fileutil.osfn(fnpol0)
@@ -140,7 +140,7 @@ def applyNpolCorr(fname, unpolcorr):
return applyNPOLCorr
try:
# get NPOLEXT kw from first extension header
- fnpol1 = pyfits.getval(fname, 'NPOLEXT', ext=1)
+ fnpol1 = fits.getval(fname, 'NPOLEXT', ext=1)
fnpol1 = fileutil.osfn(fnpol1)
if fnpol1 and fileutil.findFile(fnpol1):
if fnpol0 != fnpol1:
@@ -172,8 +172,8 @@ def isOldStyleDGEO(fname, dgname):
# checks if the file defined in a NPOLFILE kw is a full size
# (old style) image
- sci_hdr = pyfits.getheader(fname, ext=1)
- dgeo_hdr = pyfits.getheader(dgname, ext=1)
+ sci_hdr = fits.getheader(fname, ext=1)
+ dgeo_hdr = fits.getheader(dgname, ext=1)
sci_naxis1 = sci_hdr['NAXIS1']
sci_naxis2 = sci_hdr['NAXIS2']
dg_naxis1 = dgeo_hdr['NAXIS1']
@@ -190,7 +190,7 @@ def applyD2ImCorr(fname, d2imcorr):
applyD2IMCorr = True
try:
# get D2IMFILE kw from primary header
- fd2im0 = pyfits.getval(fname, 'D2IMFILE')
+ fd2im0 = fits.getval(fname, 'D2IMFILE')
if fd2im0 == 'N/A':
return False
fd2im0 = fileutil.osfn(fd2im0)
@@ -203,7 +203,7 @@ def applyD2ImCorr(fname, d2imcorr):
return applyD2IMCorr
try:
# get D2IMEXT kw from first extension header
- fd2imext = pyfits.getval(fname, 'D2IMEXT', ext=1)
+ fd2imext = fits.getval(fname, 'D2IMEXT', ext=1)
fd2imext = fileutil.osfn(fd2imext)
if fd2imext and fileutil.findFile(fd2imext):
if fd2im0 != fd2imext:
diff --git a/lib/stwcs/updatewcs/det2im.py b/lib/stwcs/updatewcs/det2im.py
index a783c88..902deaa 100644
--- a/lib/stwcs/updatewcs/det2im.py
+++ b/lib/stwcs/updatewcs/det2im.py
@@ -1,6 +1,6 @@
from __future__ import division # confidence high
-from astropy.io import fits as pyfits
+from astropy.io import fits
from stsci.tools import fileutil
import utils
import numpy as np
@@ -33,15 +33,15 @@ class DET2IMCorr(object):
"""
Parameters
----------
- fobj: pyfits object
+ fobj: `astropy.io.fits.HDUList` object
Science file, for which a distortion correction in a NPOLFILE is available
"""
logger.info("\n\tStarting DET2IM: %s" %time.asctime())
try:
- assert isinstance(fobj, pyfits.HDUList)
+ assert isinstance(fobj, fits.HDUList)
except AssertionError:
- logger.exception('\n\tInput must be a pyfits.HDUList object')
+ logger.exception('\n\tInput must be a fits.HDUList object')
raise
cls.applyDet2ImCorr(fobj)
@@ -54,7 +54,7 @@ class DET2IMCorr(object):
def applyDet2ImCorr(cls, fobj):
"""
- For each science extension in a pyfits file object:
+ For each science extension in a fits file object:
- create a WCSDVARR extension
- update science header
- add/update D2IMEXT keyword
@@ -159,7 +159,7 @@ class DET2IMCorr(object):
Make sure 'CCDCHIP' in the npolfile matches "CCDCHIP' in the science file.
"""
xdata, ydata = (None, None)
- d2im = pyfits.open(d2imfile)
+ d2im = fits.open(d2imfile)
for ext in d2im:
d2imextname = ext.header.get('EXTNAME',"")
d2imccdchip = ext.header.get('CCDCHIP',1)
@@ -183,7 +183,7 @@ class DET2IMCorr(object):
hdr = cls.createD2ImHdr(sciheader, d2imfile=d2imfile,
wdvarr_ver=wdvarr_ver, d2im_extname=d2im_extname,
ccdchip=ccdchip)
- hdu=pyfits.ImageHDU(header=hdr, data=data)
+ hdu = fits.ImageHDU(header=hdr, data=data)
return hdu
createD2ImHDU = classmethod(createD2ImHDU)
@@ -196,7 +196,7 @@ class DET2IMCorr(object):
is such that a full size d2im table is created and then shifted or scaled
if the science image is a subarray or binned image.
"""
- d2im = pyfits.open(d2imfile)
+ d2im = fits.open(d2imfile)
d2im_phdr = d2im[0].header
for ext in d2im:
try:
@@ -272,7 +272,7 @@ class DET2IMCorr(object):
for card in d2im_phdr.cards[start_indx:end_indx]:
cdl.append(card)
- hdr = pyfits.Header(cards=cdl)
+ hdr = fits.Header(cards=cdl)
return hdr
diff --git a/lib/stwcs/updatewcs/npol.py b/lib/stwcs/updatewcs/npol.py
index 0427b61..cee7b9b 100644
--- a/lib/stwcs/updatewcs/npol.py
+++ b/lib/stwcs/updatewcs/npol.py
@@ -1,6 +1,6 @@
from __future__ import division # confidence high
-from astropy.io import fits as pyfits
+from astropy.io import fits
from stsci.tools import fileutil
import utils
import numpy as np
@@ -37,15 +37,15 @@ class NPOLCorr(object):
"""
Parameters
----------
- fobj: pyfits object
- Science file, for which a distortion correction in a NPOLFILE is available
+ fobj : `astropy.io.fits.HDUList` object
+ Science file, for which a distortion correction in a NPOLFILE is available
"""
logger.info("\n\tStarting NPOL: %s" %time.asctime())
try:
- assert isinstance(fobj, pyfits.HDUList)
+ assert isinstance(fobj, fits.HDUList)
except AssertionError:
- logger.exception('\n\tInput must be a pyfits.HDUList object')
+ logger.exception('\n\tInput must be a fits.HDUList object')
raise
cls.applyNPOLCorr(fobj)
@@ -58,7 +58,7 @@ class NPOLCorr(object):
def applyNPOLCorr(cls, fobj):
"""
- For each science extension in a pyfits file object:
+ For each science extension in a fits file object:
- create a WCSDVARR extension
- update science header
- add/update NPOLEXT keyword
@@ -168,7 +168,7 @@ class NPOLCorr(object):
Get the data arrays from the reference NPOL files
Make sure 'CCDCHIP' in the npolfile matches "CCDCHIP' in the science file.
"""
- npl = pyfits.open(nplfile)
+ npl = fits.open(nplfile)
for ext in npl:
nplextname = ext.header.get('EXTNAME',"")
nplccdchip = ext.header.get('CCDCHIP',1)
@@ -224,7 +224,7 @@ class NPOLCorr(object):
Creates an HDU to be added to the file object.
"""
hdr = cls.createNpolHdr(sciheader, npolfile=npolfile, wdvarr_ver=wdvarr_ver, npl_extname=npl_extname, ccdchip=ccdchip)
- hdu=pyfits.ImageHDU(header=hdr, data=data)
+ hdu = fits.ImageHDU(header=hdr, data=data)
return hdu
createNpolHDU = classmethod(createNpolHDU)
@@ -237,7 +237,7 @@ class NPOLCorr(object):
i ssuch that a full size npol table is created and then shifted or scaled
if the science image is a subarray or binned image.
"""
- npl = pyfits.open(npolfile)
+ npl = fits.open(npolfile)
npol_phdr = npl[0].header
for ext in npl:
try:
@@ -315,7 +315,7 @@ class NPOLCorr(object):
for card in npol_phdr.cards[start_indx:end_indx]:
cdl.append(card)
- hdr = pyfits.Header(cards=cdl)
+ hdr = fits.Header(cards=cdl)
return hdr
diff --git a/lib/stwcs/updatewcs/utils.py b/lib/stwcs/updatewcs/utils.py
index 550ce56..7bdd6fe 100644
--- a/lib/stwcs/updatewcs/utils.py
+++ b/lib/stwcs/updatewcs/utils.py
@@ -35,8 +35,8 @@ def updateNEXTENDKw(fobj):
Parameters
-----------
- fobj : pyfits.HDUList
- PyFITS object for file opened in update mode
+ fobj : `astropy.io.fits.HDUList`
+ The FITS object for file opened in `update` mode
"""
if 'nextend' in fobj[0].header:
@@ -124,11 +124,11 @@ def build_sipname(fobj, fname=None, sipname=None):
Parameters
----------
- fobj: HDUList
- pyfits file object
- fname: string
- science file name (to be used if ROOTNAMe is not present
- sipname: string
+ fobj : `astropy.io.fits.HDUList`
+ file object
+ fname : string
+ science file name (to be used if ROOTNAME is not present
+ sipname : string
user supplied SIPNAME keyword
Returns
@@ -169,10 +169,10 @@ def build_npolname(fobj, npolfile=None):
Parameters
----------
- fobj: HDUList
- pyfits file object
- npolfile: string
- user supplied NPOLFILE keyword
+ fobj : `astropy.io.fits.HDUList`
+ file object
+ npolfile : string
+ user supplied NPOLFILE keyword
Returns
-------
@@ -202,10 +202,10 @@ def build_d2imname(fobj, d2imfile=None):
Parameters
----------
- fobj: HDUList
- pyfits file object
- d2imfile: string
- user supplied NPOLFILE keyword
+ fobj : `astropy.io.fits.HDUList`
+ file object
+ d2imfile : string
+ user supplied NPOLFILE keyword
Returns
-------
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: