def py_sampleImage(reference_image, dxy, udat, vdat, dRA=0., dDec=0., PA=0.):
"""
Python implementation of sampleImage.
"""
nxy = reference_image.shape[0]
dRA *= 2.*np.pi
dDec *= 2.*np.pi
du = 1. / (nxy*dxy)
# Real to Complex transform
fft_r2c_shifted = np.fft.fftshift(
np.fft.rfft2(
np.fft.fftshift(reference_image)), axes=0)
# apply rotation
cos_PA = np.cos(PA)
sin_PA = np.sin(PA)
urot = udat * cos_PA - vdat * sin_PA
vrot = udat * sin_PA + vdat * cos_PA
dRArot = dRA * cos_PA - dDec * sin_PA
dDecrot = dRA * sin_PA + dDec * cos_PA
# interpolation indices
uroti = np.abs(urot)/du
vroti = nxy/2. + vrot/du
uneg = urot < 0.
vroti[uneg] = nxy/2 - vrot[uneg]/du
# coordinates of FT
u_axis = np.linspace(0., nxy // 2, nxy // 2 + 1)
v_axis = np.linspace(0., nxy - 1, nxy)
# We use RectBivariateSpline to do only linear interpolation, which is faster
# than interp2d for our case of a regular grid.
# RectBivariateSpline does not work for complex input, so we need to run it twice.
f_re = RectBivariateSpline(v_axis, u_axis, fft_r2c_shifted.real, kx=1, ky=1, s=0)
ReInt = f_re.ev(vroti, uroti)
f_im = RectBivariateSpline(v_axis, u_axis, fft_r2c_shifted.imag, kx=1, ky=1, s=0)
ImInt = f_im.ev(vroti, uroti)
# correct for Real to Complex frequency mapping
uneg = urot < 0.
ImInt[uneg] *= -1.
# apply the phase change
theta = urot*dRArot + vrot*dDecrot
vis = (ReInt + 1j*ImInt) * (np.cos(theta) + 1j*np.sin(theta))
return vis
评论列表
文章目录