U.Dhome
U.Dhome

Reputation: 1

2D Interpolation over list of points Python

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 !

Upvotes: 0

Views: 1691

Answers (1)

Owen Hempel
Owen Hempel

Reputation: 434

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

Upvotes: 1

Related Questions