I'm trying to interpolate temperatures in a massive body made out of a scintillator called PbWO4. There are 10 outer temperature sensors called 'satellites' which help me refer to the inner temperatures at only 4 points. The main problem I'm facing is the fact, that scipy's griddata method and https://pypi.org/project/naturalneighbor/ 's griddata method calculate the temperatures at all vertices in the body which can add up to 2 million (200mm*100mm*100mm). This task has to be done a lot of times and I asked myself, if anyone here had a similar problem with a solution that only interpolate at these 4 points instead of 2 million. You can see my attempt below
class Interpolate:
def __init__(self, xpos, ypos, zpos, data):
self.x = np.asarray(xpos)
self.y = np.asarray(ypos)
self.z = np.asarray(zpos)
self.v = np.asarray(data)
self.points = np.array([self.x, self.y, self.z]).T
self.dx = int(max(self.x) - min(self.x) + 1)
self.dy = int(max(self.y) - min(self.y) + 1)
self.dz = int(max(self.z) - min(self.z) + 1)
self.xg = np.linspace(min(self.x), max(self.x), self.dx)
self.yg = np.linspace(min(self.y), max(self.y), self.dy)
self.zg = np.linspace(min(self.z), max(self.z), self.dz)
self.grid_linear = tuple(np.meshgrid(self.xg, self.yg, self.zg))
self.grid_natnei = [
[min(self.x), max(self.x) + 1, 1],
[min(self.y), max(self.y) + 1, 1],
[min(self.z), max(self.z) + 1, 1],
]
def return_value_at_point(self, point, data):
X, Y, Z = self.grid_linear
for i, j, k, l in zip(X, Y, Z, data):
for ii, jj, kk, ll in zip(i, j, k, l):
for iii, jjj, kkk, lll in zip(ii, jj, kk, ll):
if [iii, jjj, kkk] == point:
return lll
def do_interpolate_linear(self):
return griddata(self.points, self.v, self.grid_linear, method="linear")
def do_interpolate_natural(self):
return naturalneighbor.griddata(self.points, self.v, self.grid_natnei)
the code get executed like this: To study test cases, I used a cube with side lengths 20 mm centered in the origin of
x = [-10, -10, -10, -10, 10, 10, 10, 10]
y = [-10, -10, 10, 10, -10, -10, 10, 10]
z = [-10, 10, -10, 10, -10, 10, -10, 10]
v = [0, 0, 0, 0, 0, 0, 0, 100]
I = Interpolate(y, x, z, v)
interp_n = I.do_interpolate_natural()