def _lanczos_interpolate(L, ixi, iyi, dx, dy, laccs, limages, table=True): ''' L: int, Lanczos order ixi: int, 1-d numpy array, len n, x coord in input images iyi: ----""---- y dx: float, 1-d numpy array, len n, fractional x coord dy: ----""---- y laccs: list of [float, 1-d numpy array, len n]: outputs limages list of [float, 2-d numpy array, shape h,w]: inputs ''' from miscutils import lanczos_filter lfunc = lanczos_filter if L == 3: try: from util import lanczos3_filter, lanczos3_filter_table # 0: no rangecheck if table: #lfunc = lambda nil,x,y: lanczos3_filter_table(x,y, 0) lfunc = lambda nil,x,y: lanczos3_filter_table(x,y, 1) else: lfunc = lambda nil,x,y: lanczos3_filter(x,y) except: pass h,w = limages[0].shape n = len(ixi) # sum of lanczos terms fsum = np.zeros(n) off = np.arange(-L, L+1) #fx = np.zeros(n) #fy = np.zeros(n) fx = np.zeros(n, np.float32) fy = np.zeros(n, np.float32) for oy in off: #print 'dy range:', min(-oy + dy), max(-oy + dy) lfunc(L, -oy + dy, fy) for ox in off: lfunc(L, -ox + dx, fx) #print 'dx range:', min(-ox + dx), max(-ox + dx) for lacc,im in zip(laccs, limages): lacc += fx * fy * im[np.clip(iyi + oy, 0, h-1), np.clip(ixi + ox, 0, w-1)] fsum += fx*fy for lacc in laccs: lacc /= fsum
from astrometry.util.util import lanczos3_filter, lanczos3_filter_table # x = np.linspace(-4, 4, 500) # L = np.zeros_like(x) # L2 = np.zeros(len(x), np.float32) # lanczos3_filter(x, L) # lanczos3_filter_table(x.astype(np.float32), L2, 1) # plt.clf() # plt.plot(x, L, 'r-') # plt.plot(x, L2, 'b-') # plt.savefig('l1.png') x = np.linspace(-3.5, 4.5, 8192).astype(np.float32) L1 = np.zeros_like(x) L2 = np.zeros_like(x) lanczos3_filter(x, L1) lanczos3_filter_table(x, L2, 1) print 'L2 - L1 RMS:', np.sqrt(np.mean((L2-L1)**2)) if True: ra,dec = 0.,0., pixscale = 1e-3 W,H = 10,1 cowcs = Tan(ra, dec, (W+1)/2., (H+1)/2., -pixscale, 0., 0., pixscale, W, H) dx,dy = 0.25, 0. wcs = Tan(ra, dec, (W+1)/2. + dx, (H+1)/2. + dy, -pixscale, 0., 0., pixscale, W, H) pix = np.zeros((H,W), np.float32)
from astrometry.util.util import lanczos3_filter, lanczos3_filter_table # x = np.linspace(-4, 4, 500) # L = np.zeros_like(x) # L2 = np.zeros(len(x), np.float32) # lanczos3_filter(x, L) # lanczos3_filter_table(x.astype(np.float32), L2, 1) # plt.clf() # plt.plot(x, L, 'r-') # plt.plot(x, L2, 'b-') # plt.savefig('l1.png') x = np.linspace(-3.5, 4.5, 8192).astype(np.float32) L1 = np.zeros_like(x) L2 = np.zeros_like(x) lanczos3_filter(x, L1) lanczos3_filter_table(x, L2, 1) print 'L2 - L1 RMS:', np.sqrt(np.mean((L2 - L1)**2)) if True: ra, dec = 0., 0., pixscale = 1e-3 W, H = 10, 1 cowcs = Tan(ra, dec, (W + 1) / 2., (H + 1) / 2., -pixscale, 0., 0., pixscale, W, H) dx, dy = 0.25, 0. wcs = Tan(ra, dec, (W + 1) / 2. + dx, (H + 1) / 2. + dy, -pixscale, 0., 0., pixscale, W, H) pix = np.zeros((H, W), np.float32)