2

I have 974 data points located on the surface of the unit sphere. The points are not ordered in any particular way. I wish to read in these data points, along with their corresponding polar coordinates (phi, theta). I then wish to interpolate onto a regular latitude-longitude grid using scipy.interpolate.SmoothSphereBivariateSpline. So far I have the following code:

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) 

In the above code, the arrays phi, theta and data1 are the unorganized data points, with each of these three arrays having a shape (974,). When i run this code I get the error message: Traceback (most recent call last):

  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

Now I don't understand this error code - it seems to be something to do with the underlying Fortran routine. Is there anything obvious I'm doing wrong here?

O Smith
  • 375
  • 1
  • 3
  • 11
  • Have a look at http://stackoverflow.com/questions/29262962/unable-to-use-scipy-interpolate-rectbivariatespline-with-matplotlib-pyplot-pl - although the description seems different, the symptoms, comments and solutions seem relevant. Hope it helps! – J Richard Snape Sep 29 '15 at 00:30
  • I think `SmoothSphereBivariateSpline` expects `theta, phi` instead of `phi, theta`. You may essentially be getting an "non-physical latitude" error, but I'm not 100% sure. – Joe Kington Sep 29 '15 at 15:05

0 Answers0