简体   繁体   English

Python - 在数据行之间插值

[英]Python - Interpolating between lines of data

I have data on a 2d grid characterized by points (x,Y,Z). 我有一个以点(x,Y,Z)为特征的二维网格数据。 The X and Y values indicate each point's position and Z is "height" or "intensity" at each point. X和Y值表示每个点的位置,Z是每个点的“高度”或“强度”。

My issue is that my data coordinates along the X axis are extremely closely spaced (~1000 points), while my Y coordinates are spread out (~50 points). 我的问题是我沿X轴的数据坐标是非常紧密的间距(~1000点),而我的Y坐标是展开的(~50点)。 This means that when plotted on a scatter plot, I essentially have lines of data with an equal amount of blank space between neighboring lines. 这意味着当在散点图上绘制时,我基本上具有在相邻行之间具有相等数量的空白空间的数据行。

Example of how my data is spaced on a scatter plot: 我的数据在散点图上如何间隔的示例:

ooooooooooooooooooooooooooooooo


ooooooooooooooooooooooooooooooo


ooooooooooooooooooooooooooooooo

I want to interpolate these points to get a continuous surface. 我想插入这些点以获得连续的表面。 I want to be able to evaluate the "height" at any position on this surface. 我希望能够评估此表面上任何位置的“高度”。 I have tried what seems like every scipy interpolation method and am not sure of what the most "intelligent" method is. 我已经尝试了似乎每个scipy插值方法,并且不确定最“智能”的方法是什么。 Should I interpolate each vertical slice of data, then stitch them together? 我应该插入每个垂直数据片段,然后将它们拼接在一起吗?

I want as smooth a surface as possible, but need a shape preserving method. 我想要尽可能光滑的表面,但需要一种形状保持方法。 I do not want any of the interpolated surface to overshoot my input data. 我不希望任何插值曲面超出我的输入数据。

Any help you can provide would be very helpful. 您可以提供的任何帮助都非常有用。

EDIT: 编辑:

As I think about the problem more, it seems that interpolating the vertical slices and then stitching them together wouldn't work. 当我更多地考虑这个问题时,似乎插入垂直切片然后将它们拼接在一起是行不通的。 That would cause the value along a vertical slice to only be effected by that slice, Wouldn't that result in an inaccurate surface? 这会导致沿垂直切片的值仅受该切片的影响,这不会导致表面不准确吗?

I recommend this tutorial . 我推荐这个教程 The guts of it are (lifted from link): 它的内脏是(从链接中取出):

>>> grid_x, grid_y = np.mgrid[0:1:100j, 0:1:200j]
>>> from scipy.interpolate import griddata
>>> grid_z0 = griddata(points, values, (grid_x, grid_y), method='nearest')
>>> grid_z1 = griddata(points, values, (grid_x, grid_y), method='linear')
>>> grid_z2 = griddata(points, values, (grid_x, grid_y), method='cubic')

Which will get you three different levels of interpolation of your data (doc) . 这将为您提供三种不同级别的数据插值(doc)

如果您正在寻找表面,我的假设是您可以使用垂直切片,然后绘制填充的数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM