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 '17 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 Bystricky Jun 16 '17 at 17:03
  • $\begingroup$ Just use Spherepack. There's a python wrapper: pypi.python.org/pypi/pyspharm $\endgroup$ – Spencer Bryngelson 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.

| cite | improve this answer | |
  • $\begingroup$ You probably want to Lebedev grid points instead of Gauss-Legendre nodes. $\endgroup$ – nicoguaro Jun 16 '17 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$ – Spencer Bryngelson Jun 16 '17 at 19:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.