# 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"? – nicoguaro 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. – Lukas Bystricky Jun 16 '17 at 17:03
• Just use Spherepack. There's a python wrapper: pypi.python.org/pypi/pyspharm – Spencer Bryngelson Jun 16 '17 at 17:12

## 1 Answer

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.

• You probably want to Lebedev grid points instead of Gauss-Legendre nodes. – nicoguaro Jun 16 '17 at 17:13
• Numerical evaluation this integral is poorly conditioned and painful. Which is why people usually just use a software package designed for this specific purpose. – Spencer Bryngelson Jun 16 '17 at 19:31