点列表上的 2D 插值 Python [英] 2D Interpolation over list of points Python

查看:52
本文介绍了点列表上的 2D 插值 Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个插值问题.它不应该太复杂,但我找不到任何有效的解决方案.

我正在研究一个 2D 机翼部分,我知道机翼每个坐标点 (x_inf,y_inf) 上的压力(标量),我想将这个压力插值到机翼的另一个离散化((x_profil,y_profil) 坐标).这是我拥有的配置文件的图片((x_inf,y_inf),绿色)和我想要插值的网格((x_profil,y_profil),红色).插值点.数据 x_inf、y_inf、p_inf 是相同大小的 numpy 数组(它们是从特定文件中提取的).x_profil, y_profil 也是相同大小的 numpy 数组(但与 _inf 数据不同).

我首先尝试了 interp2d 函数,但结果是一个数组,其大小是我插值的点的大小的平方.

pressure=interp2d(x_inf,y_inf,p_inf)p_profil=压力(x_profil,y_profil)

我还尝试使用 interp1d 仅在 x 轴上进行插值,但这也不起作用.将插值类型设置为最近"或零"有效,但插值中有漏洞",如下图所示:压力插值,其中绿色点是输入数据,红色点是插值数据.

pressure=interp1d(x_inf,p_inf,kind='zero',bounds_error=False)p_profil=压力(x_profil)

我正在使用 python 2.7.10、scipy 0.16.1 和 numpy 1.9.2 在带有 Enthought Canopy 的 Windows 7 上运行.

有人知道我如何解决我的问题吗?

非常感谢!

解决方案

听起来好像是 interp2d 函数认为您将其传递给常规网格.来自 numpy 文档:

<块引用>

>定义数据点坐标的数组.如果点位于规则网格上,x 可以指定列坐标,y 指定行坐标,例如:

<块引用><块引用>

x, y : array_likex = [0,1,2];y = [0,3];z = [[1,2,3], [4,5,6]]否则,x 和 y 必须指定每个点的完整坐标,例如:

x = [0,1,2,0,1,2];y = [0,0,0,3,3,3];z = [1,2,3,4,5,6]如果 x 和 y 是多维的,则在使用前将它们展平.

z:array_like要在数据点处插值的函数值.如果 z 是多维数组,则在使用前将其展平.如果 x 和 y 指定列和行坐标,则扁平 z 数组的长度为 len(x)*len(y) 或 len(z) == len(x) == len(y) 如果 x 和 y 指定每个点的坐标.

听起来您需要强制 x 和 y 明确表示完整坐标

I have an interpolation problem. It should not be too complicated, but I can't find any valid solution.

I am working on a 2D wing section, I know the pressure (a scalar) on each point of coordinates (x_inf,y_inf) of the wing and I want to interpolate this pressure on an other discretization of the wing ((x_profil,y_profil) coordinates). Here is a picture of the profile I have ((x_inf,y_inf), green) and the grid I want to interpolate on ((x_profil,y_profil), red). Points for interpolation. The data x_inf, y_inf, p_inf are numpy arrays of the same size (they are extracted from a specific file). x_profil, y_profil are also numpy arrays of the same size (but different from _inf data).

I first tried interp2d function, but the result is an array of size the square of the size of the points on which I interpolate.

pressure=interp2d(x_inf,y_inf,p_inf)
p_profil=pressure(x_profil,y_profil)

I also tried to interpolate only over the x axis with interp1d but this doesn't work either. Setting the kind of interpolation to "nearest" or "zero" works, but there are "holes" in the interpolation, as you can see in this figure : presure interpolation, where the green points are the input data and the red the interpolated.

pressure=interp1d(x_inf,p_inf,kind='zero',bounds_error=False)
p_profil=pressure(x_profil)

I am using python 2.7.10, scipy 0.16.1 and numpy 1.9.2 running on windows 7 with Enthought Canopy.

Does anyone have an idea of how I could solve my problem ?

Thank's a lot in advance !

解决方案

It sounds like what's happening is the interp2d function thinks you're pasing it a regular grid. From the numpy Docs:

> Arrays defining the data point coordinates. If the points lie on a regular grid, x can specify the column coordinates and y the row coordinates, for example:

x, y : array_like x = [0,1,2]; y = [0,3]; z = [[1,2,3], [4,5,6]] Otherwise, x and y must specify the full coordinates for each point, for example:

x = [0,1,2,0,1,2]; y = [0,0,0,3,3,3]; z = [1,2,3,4,5,6] If x and y are multi-dimensional, they are flattened before use.

z : array_like The values of the function to interpolate at the data points. If z is a multi-dimensional array, it is flattened before use. The length of a flattened z array is either len(x)*len(y) if x and y specify the column and row coordinates or len(z) == len(x) == len(y) if x and y specify coordinates for each point.

It sounds like you need to force x and y to be explicit to the full coordinates

这篇关于点列表上的 2D 插值 Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆