# [SciPy-User] 3D scatter data interpolate Classic List Threaded 6 messages Open this post in threaded view
|

## [SciPy-User] 3D scatter data interpolate

 Hi all,I would like to interpolate 3D scatter data.I have some 3D points, each point has an associated value, I would like to interpolate these point to calculate the value of a random point.This example may help to understand:from math import cos, sinfrom scipy.interpolate import Rbffrom numpy import linspace, pifrom mpl_toolkits.mplot3d import Axes3Dimport matplotlib.pyplot as plt#%% DataR = 10.0x = list()y = list()z = list()c = list()for i in linspace(0.0,10.0,11):    for t in linspace(0.0,2*pi,90):        x.append(R*cos(t))        y.append(R*sin(t))        z.append(i)        c.append(i)#%% Plotfig = plt.figure()ax = fig.add_subplot(111, projection='3d')sc = ax.scatter(x, y, z, c=z)ax.set_xlabel('X')ax.set_ylabel('Y')ax.set_zlabel('Z')plt.colorbar(sc)#%%rbfi = Rbf(x, y, z, c)xi = [0,0]yi = [0,0]zi = [0,1]print rbfi(xi, yi, zi)As you can see here we have some points over a cylinder, each point has associate a value (color), which in this case is the z-coordinate.scipy.interpolate.Rbf should answer my problem, to better understsand how it works I gave it some points [[0,0,0],[0,0,1]], but the result of rbfi(xi, yi, zi) is [-1.04833984 -0.10205078].I expected that a point along the axis, aligned with some point should return the z-coordinate of this point [0, 1] but got some negative number.Any ideas?Do you have any alternative that I can use to have a linear interpolation or by the nearest?Thanks _______________________________________________ SciPy-User mailing list [hidden email] https://mail.scipy.org/mailman/listinfo/scipy-user
Open this post in threaded view
|

## Re: 3D scatter data interpolate

 Hi Vasco,Sorry for not replying sooner. I thought I had a self-contained example of using the scipy.ndimage.map_coordinates() function to do this. I can't find it though. It may help to look at how I used map_coordinates() to interpolate a vector field to map the vector onto a sphere:https://gist.github.com/gazzar/369ed55f15045bb99caeThat code is pretty old now and I don't have any small test data sets for it, so just take a look and see if it helps,GaryOn 16 February 2016 at 06:48, Vasco Gervasi wrote:Hi all,I would like to interpolate 3D scatter data.I have some 3D points, each point has an associated value, I would like to interpolate these point to calculate the value of a random point.This example may help to understand:from math import cos, sinfrom scipy.interpolate import Rbffrom numpy import linspace, pifrom mpl_toolkits.mplot3d import Axes3Dimport matplotlib.pyplot as plt#%% DataR = 10.0x = list()y = list()z = list()c = list()for i in linspace(0.0,10.0,11):    for t in linspace(0.0,2*pi,90):        x.append(R*cos(t))        y.append(R*sin(t))        z.append(i)        c.append(i)#%% Plotfig = plt.figure()ax = fig.add_subplot(111, projection='3d')sc = ax.scatter(x, y, z, c=z)ax.set_xlabel('X')ax.set_ylabel('Y')ax.set_zlabel('Z')plt.colorbar(sc)#%%rbfi = Rbf(x, y, z, c)xi = [0,0]yi = [0,0]zi = [0,1]print rbfi(xi, yi, zi)As you can see here we have some points over a cylinder, each point has associate a value (color), which in this case is the z-coordinate.scipy.interpolate.Rbf should answer my problem, to better understsand how it works I gave it some points [[0,0,0],[0,0,1]], but the result of rbfi(xi, yi, zi) is [-1.04833984 -0.10205078].I expected that a point along the axis, aligned with some point should return the z-coordinate of this point [0, 1] but got some negative number.Any ideas?Do you have any alternative that I can use to have a linear interpolation or by the nearest?Thanks _______________________________________________ SciPy-User mailing list [hidden email] https://mail.scipy.org/mailman/listinfo/scipy-user _______________________________________________ SciPy-User mailing list [hidden email] https://mail.scipy.org/mailman/listinfo/scipy-user
Open this post in threaded view
|

## Re: 3D scatter data interpolate

 Sorry but I am not able to understand how map_coordinates works.Let's say that I am in 2D and I have the points [x=0, y=0] and [x=1, y=1], and each point has associated a value [x=0, y=0, v=0] and [x=1, y=1, v=2].My input for map_coordinates should be:in_data = np.array([[0.,0.,0.],                    [1.,1.,2.]])I would like to interpolate in the middle point [x=0.5, y=0.5] so the  coordinates should be;lookpoints = np.array([[0.5, 0.5]]).T So:s = map_coordinates(in_data, lookpoints, order=1)But i get s=0.5 not 1.What am I doing wrong?Thanks  _______________________________________________ SciPy-User mailing list [hidden email] https://mail.scipy.org/mailman/listinfo/scipy-user
Open this post in threaded view
|

## Re: 3D scatter data interpolate

 Hi Vasco,The input to map_coordinates should be a regularly-sampled array, like an image. In your case, you've provided an input image of shape (2, 3). In the format you're thinking, (x, y, val) tuples, the input you have provided would be expressed as:[[0, 0, 0], [0, 1, 0], [0, 2, 0], [1, 0, 1], [1, 1, 1], [1, 2, 2]]As you can see, using linear interpolation at (0.5, 0.5) in that image interpolates between the values 0, 0, 1, 1, thus resulting in 0.5.Juan.On Mon, Feb 22, 2016 at 1:48 AM, Vasco Gervasi wrote:Sorry but I am not able to understand how map_coordinates works.Let's say that I am in 2D and I have the points [x=0, y=0] and [x=1, y=1], and each point has associated a value [x=0, y=0, v=0] and [x=1, y=1, v=2].My input for map_coordinates should be:in_data = np.array([[0.,0.,0.],                    [1.,1.,2.]])I would like to interpolate in the middle point [x=0.5, y=0.5] so the  coordinates should be;lookpoints = np.array([[0.5, 0.5]]).T So:s = map_coordinates(in_data, lookpoints, order=1)But i get s=0.5 not 1.What am I doing wrong?Thanks  _______________________________________________ SciPy-User mailing list [hidden email] https://mail.scipy.org/mailman/listinfo/scipy-user _______________________________________________ SciPy-User mailing list [hidden email] https://mail.scipy.org/mailman/listinfo/scipy-user