I\'ve got a 3D dataset that I want to interpolate AND extrapolate linearly. The interpolation can be done easily with scipy.interpolate.LinearNDInterpolator. The module can
use combination of nearest and linear interpolation. LinearNDInterpolator returns np.nan if it fails to interpolate otherwise it returns an array size(1) NearestNDInterpolator returns a float
import scipy.interpolate
import numpy
class LinearNDInterpolatorExt(object):
def __init__(self, points,values):
self.funcinterp=scipy.interpolate.LinearNDInterpolator(points,values)
self.funcnearest=scipy.interpolate.NearestNDInterpolator(points,values)
def __call__(self,*args):
t=self.funcinterp(*args)
if not numpy.isnan(t):
return t.item(0)
else:
return self.funcnearest(*args)