1

given is data like the following:

A, B, C, Value
1, 2, 3, 123
5, 1, 4, 223
3, 4, 5, 444

And so on. I always have 3 index values, where I want to index my data with and the corresponding value that "sits at this point" in the 3D space.

What I want now, after passing my value set through some kind of Python, NumPy, SciPy magic is a function that takes the three parameters and interpolates in such a way that I can get any value I want within the cube, where the points are in, and even around it, of course with reduced precision when moving too far away from the points.

There are several interpolation methods in SciPy but the examples always generate some points using random values or some linear spacings. No examples with fixed data. Especially for the coordinates.

Which interpolation method(s) can be used for this and most important: How do I have to call them to get my fixed data in there?

Manu
  • 11
  • 2
  • Could you be more clear on this? There are some interpolation algorithms in Scipy, some of them need data on a grid, is this what you mean with fixed data? Others take scattered points. – Joe Mar 11 '20 at 13:32
  • I just have the points. No grids. I have a big pile of A, B, C, V data sets. A, B and C were set on some test setup and value V was measured. Several data sets were created this way. All values (A, B, C and V) are floats. Based on this data base I want to query for a unknown A, B, C pair and get a interpolated V for this which may be inside or outside of the defined value regions. – Manu Mar 11 '20 at 13:36
  • https://docs.scipy.org/doc/scipy/reference/interpolate.html#multivariate-interpolation – Joe Mar 11 '20 at 13:39
  • You could start with LinearNDInterpolator, there are many examples available https://stackoverflow.com/questions/36210769/plotting-interpolated-values-using-linearndinterpolator-python – Joe Mar 11 '20 at 13:40
  • Or that one https://matplotlib.org/3.1.0/gallery/images_contours_and_fields/triinterp_demo.html – Joe Mar 11 '20 at 13:43
  • I guess that "griddata" doesn't take my 3D point? I'm running a multithreaded web application so I'm sure I will run into this when using LinearNDInterpolator: https://github.com/scipy/scipy/issues/8856 – Manu Mar 11 '20 at 13:44
  • So do not use global variables and make your thread send the results somewhere...return them in a Queue or Pipe or whatever. – Joe Mar 11 '20 at 13:47
  • Or don't run the interpolation in the web app. Create a service for it that will handle the interpolation. Everything is possible. – Joe Mar 11 '20 at 13:49
  • OK, so I guess the problem does not exist if my variables are local to a function and the function runs "single threaded" anyway. I'll see if this works out for me. I hoped that I can keep the function (cached) for future calls but I'll measure how long it actually takes to set up the function. If this is fast enough, then there is no need for having this cached. – Manu Mar 11 '20 at 14:00
  • LinearNDInterpolator returns 0.0 every time a request is done outside of the region defined by the points which is not acceptable for me. I want the interpolation to work even outside of the defined points. Maybe by linear approximation between the closest points. "interp2d" does that for two index values and one data value, so I would need a "interp3d" which does not exist – Manu Mar 11 '20 at 14:15
  • You could use something like https://stackoverflow.com/a/48757471/7919597 or create a local grid and use function that supports extrapolation – Joe Mar 11 '20 at 14:28
  • I also like Rbf, it extrapolates fine https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.Rbf.html#scipy.interpolate.Rbf – Joe Mar 11 '20 at 14:29
  • Still, you have to validate somehow that the results out of the region are somehow reasonable. They will at least be some numbers that look cool in every colored plot. – Joe Mar 11 '20 at 14:33
  • "Rbf" may be exactly what I need. I'll test that. – Manu Mar 11 '20 at 14:58

0 Answers0