存储 scipy griddata 使用的权重以供重用

storing the weights used by scipy griddata for re-use

我正在尝试将数据从非结构化网格 M1 插入到另一个非结构化网格 M2。为此,scipy.interpolate.griddata 似乎不错。

但是,我需要从 M1M2 进行多次插值,仅更改数据而不更改网格。我想,在内部,scipy.interpolate.griddata 在从 M1 插值到 M2 时定义了一些权重系数,这可能是其中之一计算的昂贵部分。

因此,我想避免每次都重新计算这些权重。有没有办法做到这一点?即,从一个非结构化网格多次插值到另一个非结构化网格,两者都保持不变,避免重新计算 scipy.interpolate.griddata(或等效)的内部?

一个解决方案是使用 LinearNDInterpolator Scipy function with a pre-computed Delaunay 三角测量:

from scipy.spatial import Delaunay
from scipy.interpolate import LinearNDInterpolator

tri = Delaunay(mesh1)  # Compute the triangulation

# Perform the interpolation with the given values:
interpolator = LinearNDInterpolator(tri, values_mesh1)
values_mesh2 = interpolator(mesh2)

mesh1 是一个(点数 * dim)数组。

注:CloughTocher2DInterpolator可用于非线性插值。 griddata 使用 LinearNDInterpolatorCloughTocher2DInterpolator