Skip to content

Instantly share code, notes, and snippets.

@nden
Last active August 29, 2015 14:00
Show Gist options
  • Save nden/11215743 to your computer and use it in GitHub Desktop.
Save nden/11215743 to your computer and use it in GitHub Desktop.
SIP transformations
'''
Definitions:
SIP forward transformation:
'''
foc_X = (px_x - crpix1) + Forward_SIP_X((px_x - crpix1), (px_y - crpix2))
foc_Y = (px_y - crpix2) + Forward_SIP_Y((px_x - crpix1), (px_y - crpix2))
# SIP inverse transformation:
px_x = foc_X + Inverse_SIP_X(foc_X, foc_Y)
px_y = foc_Y + Inverse_SIP_Y(foc_X, foc_Y)
#Using these definitions
pix = np.array([200., 200.])
hdr=fits.Header.fromfile(test_file, padding=False)
wobj = wcs.WCS(hdr)
sip= models.SIP([crpix1, crpix2], a_order, a_pars, b_order, b_pars, ap_order=ap_order, ap_coeff=ap_pars, bp_order=bp_order, bp_coeff=bp_pars)
inverse_sip = sip.inverse()
# result with modeling.SIP (PR#2177) result (Note that modeling.SIP returns only the deltas
relpix = pix - wobj.wcs.crpix
foc = sip(*relpix) + relppix
new_pix = inverse_sip(*foc) + foc + wobj.wcs.crpix
print new_pix
array([ 200.00049456, 200.00039271])
print foc
[ 72.00594086 71.9758633 ]
#results with astropy.wcs
print wobj.sip_foc2pix(wobj.sip_pix2foc([[200,200]],1),1)
array([[ 200.00049456, 200.00039271]])
print wobj.sip_pix2foc([[200,200]],1)
[[ 200.00594086 199.9758633 ]]
'''
They both roundtrip correctly.
However the focal plane coordinates are different.
Because of the intricate nature of how computations are passed between pywcs and wcs I think
my initial analysis is not quite correct.
The forward transformation in wcs is missing an additional term -wobj.wcs.crpix
'''
foc_X = px_x + Forward_SIP_X((px_x - crpix1), (px_y - crpix2))
foc_Y = px_y + Forward_SIP_Y((px_x - crpix1), (px_y - crpix2))
'''
The inverse transformation currently is
'''
px_x = foc_X + Inverse_SIP_X((foc_X-crpix1), (foc_Y-crpix2))
px_y = foc_Y + Inverse_SIP_Y((foc_X-crpix1), (foc_Y-crpix2))
'''
Subtracting crpix from foc_X/Y compensates for the fact that crpix was not subtracted in the
forward transformation and allows them to roundtrip. But produces the wrong focal plane coordinates.
I'm not sure what the right way to do this is.
In fact I'm fine with just documenting this somewhere so that when
questions about modeling come up I don't have to look at this again.
But if you think this is correct (I'm not sure I got all details in wcs) and it
may be fixed, that would be good too. I don't think now that PR#2237 is the right fix for this.
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment