def _interpolate(x1, y1, z1, x2, y2):
"""Helper to interpolate in 1d or 2d
We interpolate to get the same shape than with other methods.
"""
if x1.size > 1 and y1.size > 1:
func = interp2d(x1, y1, z1.T, kind='linear', bounds_error=False)
z2 = func(x2, y2)
elif x1.size == 1 and y1.size > 1:
func = interp1d(y1, z1.ravel(), kind='linear', bounds_error=False)
z2 = func(y2)
elif y1.size == 1 and x1.size > 1:
func = interp1d(x1, z1.ravel(), kind='linear', bounds_error=False)
z2 = func(x2)
else:
raise ValueError("Can't interpolate a scalar.")
# interp2d is not intuitive and return this shape:
z2.shape = (y2.size, x2.size)
return z2
评论列表
文章目录