Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Evaluate SmoothBivariateSpline over a grid

I have three columns of unstructured data and would like to do a bivariate spline fit over them. I am not yet too good with classes in Python so I don't understand exactly how to do this. To show my problem I have made a simple code:

#! /usr/bin/env python3

import numpy as np
from scipy import interpolate

#an array of 3 columns:
a=np.zeros((200, 3))
a[:,0]=np.random.uniform(0,1,200)
a[:,1]=np.random.uniform(3,5,200)
a[:,2]=np.random.uniform(10,12,200)

#find the boundries
min_x, max_x = np.amin(a[:,0]), np.amax(a[:,0])
min_y, max_y = np.amin(a[:,1]), np.amax(a[:,1])

#Set the resolution:
x_res=1000
y_res=int( ( (max_y-min_y) / (max_x-min_x) )*x_res )

#Make a grid
grid_x, grid_y = np.mgrid[min_x:max_x:x_res*1j, min_y:max_y:y_res*1j]

sbsp=interpolate.SmoothBivariateSpline(a[:,0], a[:,1], a[:,2])

b=sbsp.ev(4,5)
#c=sbsp.ev(grid_x, grid_y)
print(b)

This gives the interpolated value for one point, but if you comment out the second last line, it doesn't work. I would be very grateful if someone could guide me on how I can get the spline interpolation on the grid. Thanks in advance.

like image 311
makhlaghi Avatar asked May 01 '13 13:05

makhlaghi


1 Answers

The methodev(x,y) requires x and y to be a 1D array. In your code, grid_x and grid_y are 2D.

You could try the following:

c=sbsp.ev(grid_x[0,0], grid_y[0,0])
like image 97
Marco Avatar answered Oct 13 '22 01:10

Marco