Skip to content

Instantly share code, notes, and snippets.

@micviklui
Created January 22, 2015 18:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save micviklui/73f381851b911eb567ba to your computer and use it in GitHub Desktop.
Save micviklui/73f381851b911eb567ba to your computer and use it in GitHub Desktop.
interpolate 2D-grid with splines
xy_in2 = np.array([
np.linspace(-1.5, 1.5, 11),
np.linspace(1, 1, 11)
]).T
print xy_in2.shape
def _grid_interpolate_additional(xy, xydev, xy_in):
"""Interpolate values for xy and xydev on points of xy_in.
Values of xy_in that are outside of xy result in 0.
"""
gx = grid.grid_size(xy[:, 0])
gy = grid.grid_size(xy[:, 1])
# Reshape input arrays for scipy.interpolate.RectBivariateSpline
# shape = (n, n, 2)
xy_re = xy.reshape((gx[3], gy[3], xy.shape[1]))
xydev_re = xydev.reshape((gx[3], gy[3], xydev.shape[1]))
xdev_bspl = scipy.interpolate.RectBivariateSpline(
xy_re[0, :, 0], xy_re[:, 0, 1],
xydev_re[:, :, 0],
kx=2, ky=2
)
ydev_bspl = scipy.interpolate.RectBivariateSpline(
xy_re[0, :, 0], xy_re[:, 0, 1],
xydev_re[:, :, 1],
kx=2, ky=2
)
# gx_in = grid.grid_size(xy_in[:, 0])
# gy_in = grid.grid_size(xy_in[:, 1])
# xy_in_re = xy_in.reshape((gx_in[3], gy_in[3], xy_in.shape[1]))
#
# xdev_in = xdev_bspl(xy_in_re[0, :, 0], xy_in_re[:, 0, 1])
# ydev_in = ydev_bspl(xy_in_re[0, :, 0], xy_in_re[:, 0, 1])
#
# # Reshape output arrays for mirrormap
# # shape = (n*n, 2)
# xydev_in = np.array([xdev_in.flatten(), ydev_in.flatten()]).T
xydev_in = np.zeros(xy_in.shape)
for i, p in enumerate(xy_in):
xydev_in[i] = np.concatenate([
xdev_bspl(p[0], p[1]),
ydev_bspl(p[0], p[1])
]).flatten()
return xydev_in
@micviklui
Copy link
Author

in line 27: xydev_re[:, :, 1].T,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment