summaryrefslogtreecommitdiff
path: root/stwcs/wcsutil/convertwcs.py
diff options
context:
space:
mode:
Diffstat (limited to 'stwcs/wcsutil/convertwcs.py')
-rw-r--r--stwcs/wcsutil/convertwcs.py53
1 files changed, 27 insertions, 26 deletions
diff --git a/stwcs/wcsutil/convertwcs.py b/stwcs/wcsutil/convertwcs.py
index a384eb1..e47a829 100644
--- a/stwcs/wcsutil/convertwcs.py
+++ b/stwcs/wcsutil/convertwcs.py
@@ -1,4 +1,5 @@
-from __future__ import print_function
+from __future__ import absolute_import, division, print_function
+from astropy.io import fits
try:
import stwcs
from stwcs import wcsutil
@@ -7,12 +8,12 @@ except:
from stsci.tools import fileutil
-OPUS_WCSKEYS = ['OCRVAL1','OCRVAL2','OCRPIX1','OCRPIX2',
- 'OCD1_1','OCD1_2','OCD2_1','OCD2_2',
- 'OCTYPE1','OCTYPE2']
+OPUS_WCSKEYS = ['OCRVAL1', 'OCRVAL2', 'OCRPIX1', 'OCRPIX2',
+ 'OCD1_1', 'OCD1_2', 'OCD2_1', 'OCD2_2',
+ 'OCTYPE1', 'OCTYPE2']
-def archive_prefix_OPUS_WCS(fobj,extname='SCI'):
+def archive_prefix_OPUS_WCS(fobj, extname='SCI'):
""" Identifies WCS keywords which were generated by OPUS and archived
using a prefix of 'O' for all 'SCI' extensions in the file
@@ -28,43 +29,42 @@ def archive_prefix_OPUS_WCS(fobj,extname='SCI'):
print('=====================')
raise ImportError
-
closefits = False
- if isinstance(fobj,str):
+ if isinstance(fobj, str):
# A filename was provided as input
- fobj = fits.open(fobj,mode='update')
- closefits=True
+ fobj = fits.open(fobj, mode='update')
+ closefits = True
# Define the header
- ext = ('sci',1)
+ ext = ('sci', 1)
hdr = fobj[ext].header
numextn = fileutil.countExtn(fobj)
extlist = []
- for e in range(1,numextn+1):
- extlist.append(('sci',e))
+ for e in range(1, numextn + 1):
+ extlist.append(('sci', e))
# Insure that the 'O' alternate WCS is present
if 'O' not in wcsutil.wcskeys(hdr):
# if not, archive the Primary WCS as the default OPUS WCS
- wcsutil.archiveWCS(fobj,extlist, wcskey='O', wcsname='OPUS')
+ wcsutil.archiveWCS(fobj, extlist, wcskey='O', wcsname='OPUS')
# find out how many SCI extensions are in the image
- numextn = fileutil.countExtn(fobj,extname=extname)
+ numextn = fileutil.countExtn(fobj, extname=extname)
if numextn == 0:
extname = 'PRIMARY'
# create HSTWCS object from PRIMARY WCS
- wcsobj = wcsutil.HSTWCS(fobj,ext=ext,wcskey='O')
+ wcsobj = wcsutil.HSTWCS(fobj, ext=ext, wcskey='O')
# get list of WCS keywords
wcskeys = list(wcsobj.wcs2header().keys())
# For each SCI extension...
- for e in range(1,numextn+1):
+ for e in range(1, numextn + 1):
# Now, look for any WCS keywords with a prefix of 'O'
for key in wcskeys:
- okey = 'O'+key[:7]
- hdr = fobj[(extname,e)].header
+ okey = 'O' + key[: 7]
+ hdr = fobj[(extname, e)].header
if okey in hdr:
# Update alternate WCS keyword with prefix-O OPUS keyword value
hdr[key] = hdr[okey]
@@ -72,7 +72,8 @@ def archive_prefix_OPUS_WCS(fobj,extname='SCI'):
if closefits:
fobj.close()
-def create_prefix_OPUS_WCS(fobj,extname='SCI'):
+
+def create_prefix_OPUS_WCS(fobj, extname='SCI'):
""" Creates alternate WCS with a prefix of 'O' for OPUS generated WCS values
to work with old MultiDrizzle.
@@ -91,10 +92,10 @@ def create_prefix_OPUS_WCS(fobj,extname='SCI'):
owcskeys = OPUS_WCSKEYS
closefits = False
- if isinstance(fobj,str):
+ if isinstance(fobj, str):
# A filename was provided as input
fobj = fits.open(fobj, mode='update')
- closefits=True
+ closefits = True
else:
# check to make sure this FITS obj has been opened in update mode
if fobj.fileinfo(0)['filemode'] != 'update':
@@ -102,16 +103,16 @@ def create_prefix_OPUS_WCS(fobj,extname='SCI'):
raise IOError
# check for existance of O-prefix WCS
- if owcskeys[0] not in fobj['sci',1].header:
+ if owcskeys[0] not in fobj['sci', 1].header:
# find out how many SCI extensions are in the image
- numextn = fileutil.countExtn(fobj,extname=extname)
+ numextn = fileutil.countExtn(fobj, extname=extname)
if numextn == 0:
extname = ''
- for extn in range(1,numextn+1):
- hdr = fobj[(extname,extn)].header
+ for extn in range(1, numextn + 1):
+ hdr = fobj[(extname, extn)].header
for okey in owcskeys:
- hdr[okey] = hdr[okey[1:]+'O']
+ hdr[okey] = hdr[okey[1: ] + 'O']
# Close FITS image if we had to open it...
if closefits: