python 网格数据插值_矩形网格上的Python 4D线性插值

我需要在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)

非常感谢你的帮助!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值