小编Nic*_*oni的帖子

矩形网格上的Python 4D线性插值

我需要在4个维度(纬度,经度,高度和时间)中线性插值温度数据.
点数相当高(360x720x50x8),我需要一种快速的方法来计算数据范围内空间和时间任意点的温度.

我尝试过使用scipy.interpolate.LinearNDInterpolator但是使用Qhull进行三角测量在矩形网格上效率低下并且需要数小时才能完成.

通过阅读此SciPy票证,解决方案似乎是使用标准实现新的nd插值器interp1d来计算更多数据点,然后使用"最近邻居"方法和新数据集.

然而,这需要很长时间(分钟).

有没有一种快速的方法可以在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)
Run Code Online (Sandbox Code Playgroud)

使用scipy.interpolate.interp1d:

import numpy as np
from scipy.interpolate import LinearNDInterpolator

lats = np.arange(-90,90.5,0.5) …
Run Code Online (Sandbox Code Playgroud)

python interpolation numpy scipy

16
推荐指数
2
解决办法
1万
查看次数

标签 统计

interpolation ×1

numpy ×1

python ×1

scipy ×1