# Computing spherical harmonic coefficients using Scipy

The scipy.special.sph_harm function evaluates a spherical harmonic function at a point. Does Scipy provide any functions to compute the spherical harmonic coefficients for a data set?

• What do you mean by "the spherical harmonic coefficients for a data set"? Jun 16 '17 at 16:58
• I have some data defined on the surface of a sphere, and I'd like to create a spherical harmonic expansion for this data. I can integrate this data against the harmonic basis functions to get the coefficients, but I'm hoping this is built in to SciPy somehow. Jun 16 '17 at 17:03
• Just use Spherepack. There's a python wrapper: pypi.python.org/pypi/pyspharm Jun 16 '17 at 17:12

Given samples of a function $f(\theta,\phi)$, you will need to numerically evaluate the integral
$$\int_0^\pi\int_0^{2\pi}f(\theta,\phi)\left[Y_n^{m}(\theta,\phi)\right]^*\sin\theta d\phi d\theta\, ,$$
to obtain the $n,m$th coefficient of your expansion. Hopefully your samples are at some convenient locations on the unit sphere, either uniformly sampled or at Gauss-Legendre nodes.