0

I have data produced from Comsol which I would like to use as a look up table in a Python / Scipy program I am building. The output from comsol looks like B(ri,thick,L) and will contain approximately 20,000 entries. An example of the output is shown below for a reduced 3x3x3 version.

While I have found many good solutions for 3D interpolation using e.g. regulargridinterpolator (first link below), I am still looking for a solution using the lookup table style. The second link below seems close, however I am unsure how the method interpolates over all three dimensions.

I am having a hard time believing that a lookup table requires such an elaborate implementation, so any suggestions are most appreciated!

COMSOL data example

interpolate 3D volume with numpy and or scipy

Interpolating data from a look up table

Teyber
  • 1
  • 3

1 Answers1

0

I was able to figure this out and wanted to pass on my solution to the next person. I found that merely averaging the two closest points found via a cKDtree yielded errors as large as 10%.

Instead, I used the cKDtree to find the appropriate entry in the scattered look up table / data file and assign it to the correct entry of a 3D numpy array (You can save this numpy array to file if you like). Then I use rectangulargridinterpolator on this array. Errors were on the order of 0.5 percent which was an order of magnitude better than the 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)
Teyber
  • 1
  • 3