summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--updatewcs/det2im.py20
-rw-r--r--updatewcs/dgeo.py31
2 files changed, 33 insertions, 18 deletions
diff --git a/updatewcs/det2im.py b/updatewcs/det2im.py
index 90fe339..c8e9ab8 100644
--- a/updatewcs/det2im.py
+++ b/updatewcs/det2im.py
@@ -42,8 +42,8 @@ class DET2IMCorr(object):
getAxisCorr = classmethod(getAxisCorr)
def applyDet2ImCorr(cls,fobj, axiscorr):
- d2imfile = fileutil.osfn(fobj[0].header['D2IMFILE'])
- hdu = cls.createDgeoHDU(d2imfile, axiscorr)
+
+ hdu = cls.createDgeoHDU(fobj, axiscorr)
d2imarr_ind = cls.getD2imIndex(fobj)
if d2imarr_ind:
fobj[d2imarr_ind] = hdu
@@ -63,30 +63,32 @@ class DET2IMCorr(object):
return index
getD2imIndex = classmethod(getD2imIndex)
- def createDgeoHDU(cls, d2imfile, axiscorr):
-
+ def createDgeoHDU(cls, fobj, axiscorr):
+ d2imfile = fileutil.osfn(fobj[0].header['D2IMFILE'])
d2im_data = pyfits.getdata(d2imfile, ext=1)
- d2im_hdr = cls.createDet2ImHdr(d2im_data.shape, axiscorr)
+ sci_hdr = fobj['sci',1].header
+ d2im_hdr = cls.createDet2ImHdr(sci_hdr, d2im_data.shape, axiscorr)
hdu = pyfits.ImageHDU(header=d2im_hdr, data=d2im_data)
return hdu
createDgeoHDU = classmethod(createDgeoHDU)
- def createDet2ImHdr(cls, data_shape, axiscorr):
+ def createDet2ImHdr(cls, sci_hdr, data_shape, axiscorr):
"""
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
- crval2 = 0.0
+ crval1 = 0.0 + ltv1
+ crval2 = 0.0 + ltv2
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 e50725d..d1db3fd 100644
--- a/updatewcs/dgeo.py
+++ b/updatewcs/dgeo.py
@@ -184,23 +184,36 @@ class DGEOCorr(object):
def createDgeoHdr(cls, sciheader, dgeofile, wdvarr_ver, dgeoname, extver):
"""
Creates a header for the WCSDVARR extension based on the DGEO reference file
- and sci extension header.
+ and sci extension header. The goal is to always work in image coordinates
+ (also for subarrays and binned images. The WCS for the WCSDVARR extension
+ i ssuch that a full size dgeo table is created and then shifted or scaled
+ if the science image is a subarray or binned image.
"""
dgeo_header = pyfits.getheader(dgeofile, ext=(dgeoname,extver))
- sci_naxis1 = sciheader['NAXIS1']
- sci_naxis2 = sciheader['NAXIS2']
- sci_crpix1 = sciheader['CRPIX1']
- sci_crpix2 = sciheader['CRPIX2']
+
+ #LTV1/2 are needed to map correctly dgeo files into subarray coordinates
+ ltv1 = sciheader.get('LTV1', 0.0)
+ ltv2 = sciheader.get('LTV2', 0.0)
+
+ # This is the size of the full dgeo chip
+ # recorded in the small dgeo table and needed in order to map to full dgeo
+ # chip coordinates.
+ chip_size1 = dgeo_header['ONAXIS1']
+ chip_size2 = dgeo_header['ONAXIS2']
naxis1 = dgeo_header['naxis1']
naxis2 = dgeo_header['naxis2']
extver = dgeo_header['extver']
crpix1 = naxis1/2.
crpix2 = naxis2/2.
- cdelt1 = float(sci_naxis1)/naxis1
- cdelt2 = float(sci_naxis2)/naxis2
- crval1 = sci_crpix1
- crval2 = sci_crpix2
+ cdelt1 = float(chip_size1)/naxis1
+ cdelt2 = float(chip_size2)/naxis2
+
+ # 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
+
keys = ['XTENSION','BITPIX','NAXIS','NAXIS1','NAXIS2',
'EXTNAME','EXTVER','PCOUNT','GCOUNT','CRPIX1',
'CDELT1','CRVAL1','CRPIX2','CDELT2','CRVAL2']