Ethunxxx
Ethunxxx

Reputation: 1337

Error when trying to interpolate using SmoothSphereBivariateSpline(): "ValueError: Error code returned by bispev: 10"

I want to interpolate data, which is randomly scattered on the surface of a sphere, onto a regular longitude/latitude grid. I tried to do this with SmoothSphereBivariateSpline() from the scipy.interpolate package (see the code below).

import numpy as np
from scipy.interpolate import SmoothSphereBivariateSpline

#Define the input data and the original sampling points
NSamp = 2000
Theta = np.random.uniform(0,np.pi,NSamp)
Phi   = np.random.uniform(0,2*np.pi, NSamp)
Data  = np.ones(NSamp)

Interpolator = SmoothSphereBivariateSpline(Theta, Phi, Data, s=3.5)

#Prepare the grid to which the input shall be interpolated
NLon = 64
NLat = 32
GridPosLons = np.arange(NLon)/NLon * 2 * np.pi
GridPosLats = np.arange(NLat)/NLat * np.pi
LatsGrid, LonsGrid = np.meshgrid(GridPosLats, GridPosLons)
Lats = LatsGrid.ravel()
Lons = LonsGrid.ravel()

#Interpolate
Interpolator(Lats, Lons)

However, when I execute this code it gives me the following error:

ValueError: Error code returned by bispev: 10

Does anyone know what the problem is and how to fix it? Is this a bug or am I doing something wrong?

Upvotes: 2

Views: 1411

Answers (1)

user6655984
user6655984

Reputation:

In the documentation of __call__ method of SmoothSphereBivariateSpline, note the grid flag (some other interpolators have it too). If True, it's understood that you are entering one-dimensional arrays from which a grid is to be formed. This is the default value. But you already made a meshgrid from your one-dimensional arrays, so this default behavior doesn't work for your input.

Solution: use either

Interpolator(Lats, Lons, grid=False)

or, which is simpler and better:

Interpolator(GridPosLats, GridPosLons)

The latter will return the data in grid form (2D array), which makes more sense than the flattened data you would get with the first version.

Upvotes: 5

Related Questions