Nick X Tsui
Nick X Tsui

Reputation: 2912

2D interpolation results in OverflowError: Too many data points to interpolate

I am mapping a signal sampled on a spherical coordinates grid to a cylindrical coordinates grid. Obviously both are NOT uniform grid. Both grids have size 256 X 864 (row X col).

So I tried something like this:

f = interp2d(x, y, z, kind='cubic')
zz= f(xx, yy)

Here,

x, y = meshgrid(spherical_x, spherical_y)
xx, yy = meshgrid(cylindrical_x, cylindrical_y)

with spherical_x, spherical_y, cylindrical_x, and cylindrical_y all being non-uniform on 1D direction.

When I run interp2D, a error message came on, which says:

  File "C:\Users\MyComputer\AppData\Local\Continuum\anaconda3\lib\site-packages\scipy\interpolate\_fitpack_impl.py", line 48, in _intc_overflow
    raise OverflowError(msg)

OverflowError: Too many data points to interpolate

So, I am wondering what I am going to do with this non-unform 2D interpolation with Python/NumPy/SciPy? I know there is a rectbivariatespline, but it seems your original data have to be on a uniform grid. Thanks.

Upvotes: 5

Views: 7335

Answers (1)

user6655984
user6655984

Reputation:

You are calling the object created with interp2d incorrectly. Its call method has arguments

x : 1D array, x-coordinates of the mesh on which to interpolate.
y : 1D array, y-coordinates of the mesh on which to interpolate.

So, you should be passing in 1D arrays like cylindrical_x, cylindrical_y instead of meshgrid created from them.

Even at creation, meshgrid is not needed for interp2d: see the example in documentation, which uses 1D arrays for x and y.

there is a rectbivariatespline, but it seems your original data have to be on a uniform grid.

It has to be on a grid, not a uniform grid. For example, the 6 points with x-coordinates 1, 3, 10 and y-coordinates -3, 2 qualify as a grid. A grid is anything that can be specified by separate 1D arrays like I did above, instead of an array of tuples.


For interpolation on a sphere there is RectSphereBivariateSpline. But I do not understand how you expect the conversion from spherical to cylindrical to happen by means of 2D interpolation, so cannot advise on an appropriate method for that.

Upvotes: 1

Related Questions