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?
-
1$\begingroup$ What do you mean by "the spherical harmonic coefficients for a data set"? $\endgroup$– nicoguaro ♦Jun 16, 2017 at 16:58
-
$\begingroup$ 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. $\endgroup$– Lukas BystrickyJun 16, 2017 at 17:03
-
$\begingroup$ Just use Spherepack. There's a python wrapper: pypi.python.org/pypi/pyspharm $\endgroup$– user20857Jun 16, 2017 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.
-
1$\begingroup$ You probably want to Lebedev grid points instead of Gauss-Legendre nodes. $\endgroup$– nicoguaro ♦Jun 16, 2017 at 17:13
-
$\begingroup$ Numerical evaluation this integral is poorly conditioned and painful. Which is why people usually just use a software package designed for this specific purpose. $\endgroup$– user20857Jun 16, 2017 at 19:31