jmquintana79
4/19/2016 - 4:47 AM

Interpolation 2d: get z value in geographic point between four grid points with z value known

Interpolation 2d: get z value in geographic point between four grid points with z value known

"""
manual: http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.interpolate.interp2d.html
"""

from scipy import interpolate

# get grid base
x = np.arange(-5.01, 5.01, 0.25)
y = np.arange(-5.01, 5.01, 0.25)
xx, yy = np.meshgrid(x, y) # build grid if it is necessary
z = np.sin(xx**2+yy**2)    # calculate grid z value if it is necessary
# build model interpolation
f = interpolate.interp2d(x, y, z, kind='cubic') # ‘linear’, ‘cubic’, ‘quintic’

# new points
xnew = np.arange(-5.01, 5.01, 1e-2)
ynew = np.arange(-5.01, 5.01, 1e-2)
znew = f(xnew, ynew)