analogy to scipy.interpolate.griddata?

 ̄綄美尐妖づ 提交于 2019-12-03 14:02:10

问题


I want to interpolate a given 3D point cloud:

I had a look at scipy.interpolate.griddata and the result is exactly what I need, but as I understand, I need to input "griddata" which means something like x = [[0,0,0],[1,1,1],[2,2,2]].

But my given 3D point cloud don't has this grid-look - The x,y-values don't behave like a grid - anyway there is only a single z-value for each x,y-value.*

So is there an alternative to scipy.interpolate.griddata for my not-in-a-grid-point-cloud?

*edit: "no grid look" means my input looks like this:

x = [0,4,17]
y = [-7,25,116]
z = [50,112,47]

回答1:


This is a function I use for this kind of stuff:

from numpy import linspace, meshgrid

def grid(x, y, z, resX=100, resY=100):
    "Convert 3 column data to matplotlib grid"
    xi = linspace(min(x), max(x), resX)
    yi = linspace(min(y), max(y), resY)
    Z = griddata(x, y, z, xi, yi)
    X, Y = meshgrid(xi, yi)
    return X, Y, Z

Then use it like this:

  X, Y, Z = grid(x, y, z)



回答2:


Scipy has documentation with a specific example of how to use scipy.interpolate.griddata and they explain exactly what you are asking for. Look here: http://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.griddata.html

In short, you do this the get the "grid data":

grid_x, grid_y = np.mgrid[0:1:100j, 0:1:200j]

This would make a 100x200 grid which ranges from 0 to 1 in both x- and y-direction.

grid_x, grid_y = np.mgrid[-10:10:51j, 0:2:20j]

This would make a 51x20 grid which ranges from -10 to 10 in x-direction and 0 to 2 in y-direction.

Now you have to correct input for scipy.interpolate.griddata.



来源:https://stackoverflow.com/questions/18496783/analogy-to-scipy-interpolate-griddata

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!