Skip to content

Instantly share code, notes, and snippets.

@daguiam
Created May 4, 2020 18:44
Show Gist options
  • Save daguiam/b849096c1e1ca2275830caa63f528d36 to your computer and use it in GitHub Desktop.
Save daguiam/b849096c1e1ca2275830caa63f528d36 to your computer and use it in GitHub Desktop.
from scipy import interpolate
import numpy as np
# x_resolution = 0.38
# y_resolution = 0.38
# z = matrix_data
# xsize,ysize = z.shape
# x = np.arange(0,xsize+extra,1)*x_resolution
# y = np.arange(0,ysize+extra,1)*y_resolution
def interpolate_2d_data(x,y, z,x_resolution, y_resolution, new_N=None):
extra = 0
x_min, x_max = np.min(x),np.max(x)
y_min, y_max = np.min(y),np.max(y)
xx, yy = np.meshgrid(x, y)
f = interpolate.interp2d(x, y, z, kind='cubic')
# Interpolate the matrix data
xnew = np.linspace(x_min, x_max, new_N)
ynew = np.linspace(y_min, y_max, new_N)
znew = f(xnew, ynew)
return (xnew,ynew,znew)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment