【问题标题】:python scipy 3D interpolation / look up tablepython scipy 3D插值/查找表
【发布时间】:2017-12-13 10:53:03
【问题描述】:

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

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

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

COMSOL data example

interpolate 3D volume with numpy and or scipy

Interpolating data from a look up table

【问题讨论】:

    标签: python 3d scipy interpolation lookup-tables


    【解决方案1】:

    我能够弄清楚这一点,并想将我的解决方案传递给下一个人。我发现仅仅对通过 cKDtree 找到的两个最近点进行平均会产生高达 10% 的错误。

    相反,我使用 cKDtree 在分散的查找表/数据文件中找到适当的条目,并将其分配给 3D numpy 数组的正确条目(如果您愿意,可以将此 numpy 数组保存到文件中)。然后我在这个数组上使用 rectanglegridinterpolator。误差在 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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-04
      • 2023-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-09
      • 1970-01-01
      • 2014-04-30
      相关资源
      最近更新 更多