What is the best way to perform a surface integral over two-dimensional point data?

I have a data set of 363 x 190 y-points with the corresponding functional value, which I would like to integrate into several different subregions. I tried to create a SciPy function interp2dfor integration; however, the creation of this function even with linear interpolation took more than 2 hours (and not yet done) .

What is better for this task?

Some snippets below ...

In the function convert_RT_to_XYimb / jmb below , these are the borders of r, theta grids, which I convert to Cartesian borders.

Later, in my code, I convert the grid borders (imb / jmb) to the grid center values ​​(imm, jmm), convert to vectors (iX, iY), convert my function to vector (iZ), and then try to make my interpolation function .


# Convert R, T mesh vectors to X, Y mesh arrays.                                                                       
def convert_RT_to_XY(imb, jmb):                                                                                        
    R, T = np.meshgrid(imb,jmb)                                                                                        
    X = R * np.cos(np.radians(T*360))                                                                                  
    Y = R * np.sin(np.radians(T*360))                                                                                  
    return(X, Y) 

...

imm = imb[:-1]+np.divide(np.diff(imb),2)                                                                       
jmm = jmb[:-1]+np.divide(np.diff(jmb),2) 
iX, iY =  convert_RT_to_XY(imm, jmm)   
iX = np.ndarray.flatten(iX)                                                                                    
iY = np.ndarray.flatten(iY)                                                                                    
iZ = np.ndarray.flatten(plot_function)                                                                         
f = interpolate.interp2d(iX, iY, iZ, kind='linear') 

Ultimately, I want to do:

result = dblquad(f, 10, 30,
    lambda x: 10,
    lambda x: 30))
+4
source share
1 answer

Take a look at SciPy RectBivariateSpline. If you post data on a Cartesian grid anyway, it runs much faster thaninterp2D

+2
source

All Articles