diff options
Diffstat (limited to 'interp.py')
-rw-r--r-- | interp.py | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -21,6 +21,25 @@ def interp1d(src_start, src_step, src_val, dst_coords, stencil): return ret +def interp1d_irregular(src_coord, src_val, dst_coord, stencil): + idx_src = np.empty(dst_coord.shape, dtype = np.int) + for i, dc in enumerate(dst_coord): + idx_src[i] = np.where(src_coord - dc < 0, src_coord, -np.inf).argmax() - stencil / 2 + 1 + + fact = np.zeros((stencil, ) + idx_src.shape, dtype = src_val.dtype) + 1.0 + for i in range(stencil): + for j in range(stencil): + if i == j: + continue + + fact[i] *= (dst_coord - src_coord[idx_src + j]) / (src_coord[idx_src + i] - src_coord[idx_src + j]) + + ret = np.zeros_like(dst_coord, dtype = src_val.dtype) + for i in range(stencil): + ret += fact[i] * src_val[idx_src + i] + + return ret + def interp2d(src_start, src_step, src_val, dst_coords, stencil): ret = np.zeros_like(dst_coords[0], dtype = src_val.dtype) |