我需要在4个维度(纬度、经度、海拔和时间)内线性插值温度数据。
点的数量相当高(360x720x50x8),我需要一种快速的方法来计算数据范围内空间和时间中任意点的温度。
我尝试过使用scipy.interpolate.LinearNDInterpolator,但是在矩形网格上使用Qhull进行三角剖分效率很低,而且需要几个小时才能完成。
通过读取这个SciPy ticket,解决方案似乎是使用标准的interp1d实现一个新的nd插值器来计算更多的数据点,然后对新的数据集使用“最近邻”方法。
然而,这又需要很长时间(几分钟)。
有没有一种快速的方法可以在4维的矩形网格上插值数据,而不需要花费几分钟来完成?
我想使用interp1d4次而不使用计算更高密度的点,但让用户使用坐标调用,但我无法理解如何做到这一点。
否则,写我自己的4D插值具体我的需要是一个选择在这里?
下面是我用来测试这个的代码:
使用scipy.interpolate.LinearNDInterpolator:import numpy as np
from scipy.interpolate import LinearNDInterpolator
lats = np.arange(-90,90.5,0.5)
lons = np.arange(-180,180,0.5)
alts = np.arange(1,1000,21.717)
time = np.arange(8)
data = np.random.rand(len(lats)*len(lons)*len(alts)*len(time)).reshape((len(lats),len(lons),len(alts),len(time)))
coords = np.zeros((len(lats),len(lons),len(alts),len(time),4))
coords[...,0] = lats.reshape((len(lats),1,1,1))
coords[...,1] = lons.reshape((1,len(lons),1,1))
coords[...,2] = alts.reshape((1,1,len(alts),1))
coords[...,3] = time.reshape((1,1,1,len(time)))
coords = coords.reshape((data.size,4))
interpolatedData = LinearNDInterpolator(coords,data)
使用scipy.interpolate.interp1d:import numpy as np
from scipy.interpolate import LinearNDInterpolator
lats = np.arange(-90,90.5,0.5)
lons = np.arange(-180,180,0.5)
alts = np.arange(1,1000,21.717)
time = np.arange(8)
data = np.random.rand(len(lats)*len(lons)*len(alts)*len(time)).reshape((len(lats),len(lons),len(alts),len(time)))
interpolatedData = np.array([None, None, None, None])
interpolatedData[0] = interp1d(lats,data,axis=0)
interpolatedData[1] = interp1d(lons,data,axis=1)
interpolatedData[2] = interp1d(alts,data,axis=2)
interpolatedData[3] = interp1d(time,data,axis=3)
非常感谢你的帮助!