-3

I want to interpolate a set of temperature, defined on each node of a mesh of a CFD simulation, on a different mesh.

Data from the original set are in csv (X1,Y1,Z1,T1) and I want to find new T2 values on a X2,Y2,Z2 mesh.

From the many possibilities that SCIPY provide us, which is the more suitable for that application? Which are the differences between a linear and a nearest-node approach?

Thank you for your time.

EDIT

Here is an example:

import numpy as np
from scipy.interpolate import griddata
from scipy.interpolate import LinearNDInterpolator

data = np.array([
        [ -3.5622760653000E-02,  8.0497122655290E-02,  3.0788827491158E-01],
        [ -3.5854682326000E-02,  8.0591522802259E-02,  3.0784350432341E-01],
        [ -2.8168760240000E-02,  8.0819296043557E-02,  3.0988532075795E-01], 
        [ -2.8413346037000E-02,  8.0890746063578E-02,  3.1002054434659E-01],
        [ -2.8168663383000E-02,  8.0981744777379E-02,  3.1015319609412E-01], 
        [ -3.4150537103000E-02,  8.1385114641365E-02,  3.0865343388355E-01],
        [ -3.4461673349000E-02,  8.1537336777452E-02,  3.0858242919307E-01], 
        [ -3.4285601228000E-02,  8.1655884824782E-02,  3.0877386496235E-01],
        [ -2.1832991391000E-02,  8.0380712111108E-02,  3.0867371621337E-01], 
        [ -2.1933870390000E-02,  8.0335713699008E-02,  3.0867959866155E-01]])

temp = np.array([1.4285955811000E+03,
                 1.4281038818000E+03,
                 1.4543135986000E+03,
                 1.4636379395000E+03,
                 1.4624763184000E+03,                    
                 1.3410919189000E+03,
                 1.3400545654000E+03,
                 1.3505817871000E+03,
                 1.2361110840000E+03,
                 1.2398562012000E+03])

linInter= LinearNDInterpolator(data, temp)
print (linInter(np.array([[-2.8168760240000E-02,  8.0819296043557E-02,  3.0988532075795E-01]])))

this code is working, but I have a dataset of 10million of points to be interpolated on a data set of the same size.

The problem is that this operation is very slow to do for all of my points: is there a way to improve my code?

I used LinearNDinterpolator beacuse it seems to be faster than NearestNDInterpolator (LinearVSNearest).

L. Winchler
  • 101
  • 12
  • Can you please provide us with sample code for what you're trying to do? You've given us a base description, but not enough to really work from. It would also be helpful for us to see that you've given this the old college try. – Jordan Singer Mar 29 '19 at 17:41
  • Sorry, you are right: I will provide an example - together with some tests - as soon as I can. I was hoping in some preliminary advice, but looking at the "-3" I have received I think that it is not possible. Thank you for your time. – L. Winchler Apr 01 '19 at 11:01
  • Is your grid regular? In that case, you could use `RegularGridInterpolator`, which is faster – Tarifazo Apr 01 '19 at 19:18
  • Mstaino, unfortunately my grid is not regular! – L. Winchler Apr 01 '19 at 21:13

1 Answers1

0

One solution would be to use RegularGridInterpolator (if your grid is regular). Another approach I can think of is to reduce your data size by taking intervals:

step = 4   # you can increase this based on your data size (eg 100)
m = ((data.argsort(0) % step)==0).any(1)
linInter= LinearNDInterpolator(data[m], temp[m])
Tarifazo
  • 4,118
  • 1
  • 9
  • 22
  • Thank you for your answer! Unfortunately my grid is strongly irregular. Could you please explain better the approach of taking intervals? What do you mean by "reduce your data size"? thank you – L. Winchler Apr 02 '19 at 07:04
  • Hi, the approach I suggest is simply to reduce the number of points by "downsampling" them. Use `argsort` to get the order of your data, and select intervals of 10-50-100 (your choice) points. Since you have three dimensions, use the % and any() operator to ensure that each dimension is properly spaced. Alternatively, choose random points (the method I suggest is slower but produces a subgrid that is more regularly distributed) – Tarifazo Apr 03 '19 at 23:53