summaryrefslogtreecommitdiff
path: root/lib/stwcs/updatewcs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/stwcs/updatewcs')
-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
5 files changed, 53 insertions, 56 deletions
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
-------