summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/utils.py12
-rw-r--r--updatewcs/det2im.py20
-rw-r--r--updatewcs/dgeo.py24
3 files changed, 29 insertions, 27 deletions
diff --git a/lib/utils.py b/lib/utils.py
index efe8594..2731f87 100644
--- a/lib/utils.py
+++ b/lib/utils.py
@@ -86,4 +86,14 @@ def diff_angles(a,b):
if diff < -180.0:
diff += 360.0
- return diff \ No newline at end of file
+ return diff
+
+def getBinning(fobj, extver=1):
+ # Return the binning factor
+ binned = 1
+ if fobj[0].header['INSTRUME'] == 'WFPC2':
+ mode = fobj[0].header.get('MODE', "")
+ if mode == 'AREA': binned = 2
+ else:
+ binned = fobj['SCI', extver].header.get('BINAXIS',1)
+ return binned
diff --git a/updatewcs/det2im.py b/updatewcs/det2im.py
index c8e9ab8..e04b518 100644
--- a/updatewcs/det2im.py
+++ b/updatewcs/det2im.py
@@ -1,5 +1,6 @@
import pyfits
from pytools import fileutil
+from stwcs import utils
class DET2IMCorr(object):
def updateWCS(cls, fobj):
@@ -42,8 +43,8 @@ class DET2IMCorr(object):
getAxisCorr = classmethod(getAxisCorr)
def applyDet2ImCorr(cls,fobj, axiscorr):
-
- hdu = cls.createDgeoHDU(fobj, axiscorr)
+ binned = utils.getBinning(fobj)
+ hdu = cls.createDgeoHDU(fobj, axiscorr, binned)
d2imarr_ind = cls.getD2imIndex(fobj)
if d2imarr_ind:
fobj[d2imarr_ind] = hdu
@@ -63,32 +64,33 @@ class DET2IMCorr(object):
return index
getD2imIndex = classmethod(getD2imIndex)
- def createDgeoHDU(cls, fobj, axiscorr):
+ def createDgeoHDU(cls, fobj, axiscorr, binned=1):
d2imfile = fileutil.osfn(fobj[0].header['D2IMFILE'])
d2im_data = pyfits.getdata(d2imfile, ext=1)
sci_hdr = fobj['sci',1].header
- d2im_hdr = cls.createDet2ImHdr(sci_hdr, d2im_data.shape, axiscorr)
+ d2im_hdr = cls.createDet2ImHdr(sci_hdr, d2im_data.shape, axiscorr, binned)
hdu = pyfits.ImageHDU(header=d2im_hdr, data=d2im_data)
return hdu
createDgeoHDU = classmethod(createDgeoHDU)
- def createDet2ImHdr(cls, sci_hdr, data_shape, axiscorr):
+ def createDet2ImHdr(cls, sci_hdr, data_shape, axiscorr, binned=1):
"""
Creates a header for the D2IMARR extension based on the
reference file recorded in D2IMFILE keyword in the primary header.
"""
+
ltv1 = sci_hdr.get('LTV1', 0.0)
ltv2 = sci_hdr.get('LTV2', 0.0)
naxis1 = data_shape[0]
naxis2 = 0
crpix1 = 0.0
crpix2 = 0.0
- cdelt1 = 1.0
- cdelt2 = 1.0
- crval1 = 0.0 + ltv1
- crval2 = 0.0 + ltv2
+ cdelt1 = 1.0 / binned
+ cdelt2 = 1.0 / binned
+ crval1 = (0.0 + ltv1) / binned
+ crval2 = (0.0 + ltv2) / binned
keys = ['XTENSION','BITPIX','NAXIS','NAXIS1','NAXIS2',
'EXTNAME','EXTVER','PCOUNT','GCOUNT','CRPIX1',
'CDELT1','CRVAL1','CRPIX2','CDELT2','CRVAL2', 'AXISCORR']
diff --git a/updatewcs/dgeo.py b/updatewcs/dgeo.py
index 6c2bc15..c50bbde 100644
--- a/updatewcs/dgeo.py
+++ b/updatewcs/dgeo.py
@@ -1,5 +1,6 @@
import pyfits
from pytools import fileutil
+from stwcs import utils
import numpy as np
class DGEOCorr(object):
@@ -61,7 +62,7 @@ class DGEOCorr(object):
if extname == 'sci':
extversion = ext.header['EXTVER']
ccdchip = cls.get_ccdchip(fobj, extversion)
- binned = cls.getBinning(fobj, extversion)
+ binned = utils.getBinning(fobj, extversion)
header = ext.header
# get the data arrays from the reference file and transform them for use with SIP
dx,dy = cls.getData(dgfile, ccdchip)
@@ -233,13 +234,13 @@ class DGEOCorr(object):
extver = dgeo_header['extver']
crpix1 = naxis1/2.
crpix2 = naxis2/2.
- cdelt1 = float(chip_size1)*binned/naxis1
- cdelt2 = float(chip_size2)*binned/naxis2
+ cdelt1 = float(chip_size1) / (naxis1 * binned)
+ cdelt2 = float(chip_size2) / (naxis2 * binned)
# CRVAL1/2 of the small dgeo table is the shifted center of the full
# dgeo chip.
- crval1 = chip_size1/2. +ltv1
- crval2 = chip_size2/2. + ltv2
+ crval1 = (chip_size1/2. + ltv1) / binned
+ crval2 = (chip_size2/2. + ltv2) / binned
keys = ['XTENSION','BITPIX','NAXIS','NAXIS1','NAXIS2',
'EXTNAME','EXTVER','PCOUNT','GCOUNT','CCDCHIP', 'CRPIX1',
@@ -309,15 +310,4 @@ class DGEOCorr(object):
get_ccdchip = classmethod(get_ccdchip)
-
- def getBinning(cls, fobj, extver):
- # Return the binning factor
- binned = 1
- if fobj[0].header['INSTRUME'] == 'WFPC2':
- mode = fobj[0].header.get('MODE', "")
- if mode == 'AREA': binned = 2
- else:
- binned = fobj['SCI', extver].header.get('BINAXIS',1)
- return binned
-
- getBinning = classmethod(getBinning) \ No newline at end of file
+ \ No newline at end of file