使用scipy.interpolate.SmoothSphereBivariateSpline将无组织数据拟合到球体

时间:2015-09-28 22:01:11

标签: python numpy scipy interpolation data-fitting

我有974个数据点位于单位球体的表面上。积分不以任何特定方式排序。我希望阅读这些数据点及其相应的极坐标(phi,theta)。然后,我希望使用scipy.interpolate.SmoothSphereBivariateSpline插入到常规纬度 - 经度网格上。到目前为止,我有以下代码:

import numpy as np
from scipy.interpolate import SmoothSphereBivariateSpline

#Read in the unorganized grid points
# and also shift so that phi in [0,pi] and theta in [0,2*pi)
leb = np.genfromtxt('grid.txt')
u, v = np.hsplit(leb, 2)
phi, theta = u[:,0], v[:,0]
theta += np.pi

#Read in the unorganized data values
data1 = np.genfromtxt('0p0_97p03.txt')

#Create the interpolator object
lut = SmoothSphereBivariateSpline(phi, theta, data1, s=350)

#Generate a regular lat-long grid to interpolate onto
N = 100
lat = np.linspace(0.0, np.pi, N)
lon = np.linspace(0.0, 2.0*np.pi, N)
lat, lon = np.meshgrid(lat, lon)

#Now interpolate onto the regular grid
data_inerp = lut(lat, lon) 

在上面的代码中,数组phi,theta和data1是无组织的数据点,这三个数组中的每一个都具有一个形状(974,)。当我运行此代码时,我收到错误消息: 回溯(最近一次调用最后一次):

  File "spherebiv.py", line 25, in <module>
    data_inerp = lut(lat, lon)
  File "/usr/lib/python2.7/dist-packages/scipy/interpolate/fitpack2.py", line 958, in __call__
    raise ValueError("Error code returned by bispev: %s" % ier)
ValueError: Error code returned by bispev: 10

现在我不理解这个错误代码 - 它似乎与底层的Fortran例程有关。有什么明显的我在这里做错了吗?

0 个答案:

没有答案
相关问题