python scipy 3D插值/查找表

python scipy 3D插值/查找表,python,3d,scipy,interpolation,lookup-tables,Python,3d,Scipy,Interpolation,Lookup Tables,我有从Comsol生成的数据,我想在我正在构建的Python/Scipy程序中用作查找表。comsol的输出看起来像B(ri,thick,L),将包含大约20000个条目。下面显示了减少的3x3版本的输出示例 虽然我已经找到了许多使用regulargridinterpolator(下面的第一个链接)的3D插值的好解决方案,但我仍然在寻找使用查找表样式的解决方案。下面的第二个链接似乎很接近,但我不确定该方法如何在所有三个维度上插值 我很难相信查找表需要如此精细的实现,所以任何建议都非常感谢 我

我有从Comsol生成的数据,我想在我正在构建的Python/Scipy程序中用作查找表。comsol的输出看起来像B(ri,thick,L),将包含大约20000个条目。下面显示了减少的3x3版本的输出示例

虽然我已经找到了许多使用regulargridinterpolator(下面的第一个链接)的3D插值的好解决方案,但我仍然在寻找使用查找表样式的解决方案。下面的第二个链接似乎很接近,但我不确定该方法如何在所有三个维度上插值

我很难相信查找表需要如此精细的实现,所以任何建议都非常感谢


我能够解决这个问题,并想将我的解决方案传递给下一个人。我发现,仅对通过cKDtree找到的两个最近点求平均值,误差就高达10%

相反,我使用cKDtree在分散的查找表/数据文件中找到适当的条目,并将其分配给3D numpy数组的正确条目(如果愿意,可以将此numpy数组保存到文件)。然后我在这个数组上使用矩形网格插值器。误差约为0.5%,比cKDtree好一个数量级

import numpy as np
from scipy.spatial import cKDTree
from scipy.interpolate import RegularGridInterpolator

l_data = np.linspace(.125,0.5,16)# np.linspace(0.01,0.1,10) #Range for "short L"
ri_data = np.linspace(0.005,0.075,29)
thick_data = np.linspace(0.0025,0.1225,25)
#xyz data with known bounds above
F = np.zeros((np.size(l_data),np.size(ri_data),np.size(thick_data)))


LUT = np.genfromtxt('a_data_file.csv', delimiter = ',')
F_val = LUT[:, 3]
tree_small_l = cKDTree(LUT[:, :3]) #xyz coords

for ri_iter in np.arange(np.size(ri_data)):
    for thick_iter in np.arange(np.size(thick_data)):
        for l_iter in np.arange(np.size(l_data)):    
            dist,ind = tree_small_l.query(((l_data[l_iter],ri_data[ri_iter],thick_data[thick_iter])))
            F[l_iter,ri_iter,thick_iter] = F_val[ind].T 

interp_F_func = RegularGridInterpolator((l_data, ri_data, thick_data), F)