I'm trying to interpolate a set of non-uniform data on a sphere using scipy.interpolate.SmoothSphereBivariateSpline. In the example in the documentation, the example data is set up differently from my data, and below is a test data set that has the shape I need (theta, phi, and z are each 1D arrays). I've played around with changing z a bit, and in every case, the interpolation doesn't do a satisfactory job. Any idea what I'm doing wrong, or a better way to do what I need?
import numpy as np
from scipy.interpolate import SmoothSphereBivariateSpline
import matplotlib.pyplot as plt
theta = np.array([0, 0.5, 1., 1.5, 2., 2.5, 3.])
phi = np.array([1., 2., 3., 3.5, 4., 5., 6.])
z = np.array([1, 1, 0, 0, 0, 1, 1])
lut = SmoothSphereBivariateSpline(theta,phi,z, s=len(theta))
theta_new = np.linspace(0,np.pi,50)
phi_new = np.linspace(0,2.*np.pi,50)
znew = lut(theta_new,phi_new)
theta_new_mesh, phi_new_mesh = np.meshgrid(theta_new, phi_new)
fig=plt.figure()
ax = fig.add_subplot(111,projection='mollweide')
im = ax.pcolormesh(phi_new_mesh-np.pi,theta_new_mesh-np.pi/2.,znew,vmin=0, vmax=1)
ax.scatter(phi-np.pi,theta-np.pi/2.,c=z, ec='k',vmin=0,vmax=1)