简体   繁体   English

python-二维插值,一次一维

[英]python - 2d interpolation, one dimension at a time

I am trying to implement some interpolation techniques - specifically using the scipy pchip routine. 我正在尝试实现一些插值技术-特别是使用scipy pchip例程。

What I am trying to determine is whether I can perform interpolation of regularly space 2d data by interpolating each coordinate separately. 我要确定的是,是否可以通过分别插值每个坐标来执行规则空间2d数据的插值。

For example, if I have: 例如,如果我有:

(1 x m) vector of X coordinates
(1 x n) vector of Y coordinates

(m x n) matrix of Z coordinates //Z value corresponding to (x,y) pair

Is it possible to perform pchip interpolation over each dimension in succession, therefore creating an interpolated surface? 是否可以在每个维度上连续执行pchip插值,从而创建插值曲面?

Pchip expects data in the form of pchip(X,Z) - where both X and Z are 1D arrays. Pchip期望数据以pchip(X,Z)的形式-X和Z均为一维数组。 What then is the best way to interpolate each dimension? 那么插值每个维度的最佳方法是什么? Should I do, for example, pchip(X,Z) for each column of my Z matrix? 我应该为Z矩阵的每一列做pchip(X,Z)吗? Then pchip(Y,Z*) over each row of the matrix resulting from the first interpolation? 然后在由第一次插值产生的矩阵的每一行上有pchip(Y,Z *)吗?

Thank you for the help. 感谢您的帮助。 I have seen pv post about performing tensor rpoduct interpolation with pchip, but it results in a pesky divide by zero error I can't get rid of, even with his updates on github. 我看过有关用pchip执行张量rpoduct插值的pv帖子,但是即使他在github上进行了更新,它也导致了我无法摆脱的讨厌的零除错误。

EDIT: 编辑:

I found this ticket posted regarding the warning I have using pchip: http://projects.scipy.org/scipy/ticket/1838 我发现这张票已贴上我使用pchip发出的警告: http ://projects.scipy.org/scipy/ticket/1838

Could anyone please tell me what it means when it says "The infs/nans so generated are filtered out by applying a boolean condition mask, but the mask could be applied before division to avoid the warnings altogether. " 任何人都可以告诉我这是什么意思,当它说“这样生成的infs / nans通过应用布尔条件掩码被过滤掉了,但是可以在分割之前应用该掩码以避免完全避免警告。”

How do I got about applying this to avoid the warning? 我如何应用此方法来避免警告?

Take a look at the top picture in Bilinear interpolation . 看一看双线性插值的顶部图片。
Find the rows y1, y2 nearest y, 找到y1,y2最接近y的行,
pchip x in those to get R1 R2 (blue), pchip x来获得R1 R2(蓝色),
then linearly interpolate those to get P (green). 然后线性插值得到P(绿色)。
(You could also do that in the other order, and average the values x-then-y, y-then-x.) (您也可以按照其他顺序进行操作,然后对值x-then-y,y-then-x求平均值。)

However if pchip is nearly linear between knots (is it for your data ?), 但是,如果pchip在两个节点之间几乎是线性的(是否是为了您的数据?),
then it would be simpler to do bilinear directly, either with scipy BivariateSpline 那么直接使用scipy BivariateSpline进行双线性会更简单
or with scipy.ndimage.interpolation.map_coordinates ( ... order=1 ) and (ahem) the wrapper Intergrid . 或使用scipy.ndimage.interpolation.map_coordinates (... order = 1)和(包装)包装器Intergrid

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

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