Error when trying to interpolate using SmoothSphereBivariateSpline(): "ValueError: Error code returned by bispev: 10"
Error when trying to interpolate using SmoothSphereBivariateSpline(): "ValueError: Error code returned by bispev: 10"
我想将随机散布在球体表面的数据插值到规则的 longitude/latitude 网格中。我试图用 scipy.interpolate
包中的 SmoothSphereBivariateSpline()
来做到这一点(见下面的代码)。
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)
但是,当我执行这段代码时,出现以下错误:
ValueError: Error code returned by bispev: 10
有谁知道问题出在哪里以及如何解决?这是一个错误还是我做错了什么?
在 SmoothSphereBivariateSpline 的 __call__
method 文档中,请注意 grid
标志(其他一些插值器也有)。如果为 True,则可以理解您正在输入 one-dimensional 个数组,从中形成网格。这是默认值。但是您已经从 one-dimensional 数组中创建了一个 meshgrid
,因此此默认行为不适用于您的输入。
解决方案:使用
Interpolator(Lats, Lons, grid=False)
或者,哪个更简单更好:
Interpolator(GridPosLats, GridPosLons)
后者将 return 网格形式(二维数组)中的数据,这比您在第一个版本中获得的扁平化数据更有意义。
我想将随机散布在球体表面的数据插值到规则的 longitude/latitude 网格中。我试图用 scipy.interpolate
包中的 SmoothSphereBivariateSpline()
来做到这一点(见下面的代码)。
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)
但是,当我执行这段代码时,出现以下错误:
ValueError: Error code returned by bispev: 10
有谁知道问题出在哪里以及如何解决?这是一个错误还是我做错了什么?
在 SmoothSphereBivariateSpline 的 __call__
method 文档中,请注意 grid
标志(其他一些插值器也有)。如果为 True,则可以理解您正在输入 one-dimensional 个数组,从中形成网格。这是默认值。但是您已经从 one-dimensional 数组中创建了一个 meshgrid
,因此此默认行为不适用于您的输入。
解决方案:使用
Interpolator(Lats, Lons, grid=False)
或者,哪个更简单更好:
Interpolator(GridPosLats, GridPosLons)
后者将 return 网格形式(二维数组)中的数据,这比您在第一个版本中获得的扁平化数据更有意义。