chaosmagpy.coordinate_utils.sh_analysis¶
- chaosmagpy.coordinate_utils.sh_analysis(func, nmax)[source]¶
Perform a spherical harmonic expansion of a function defined on a spherical surface.
- Parameters
- func: callable
Function takes two inputs: colatitude in degrees and longitude in degrees. The function must accept 2-D arrays and preserve shapes.
- nmax: int
Maximum spherical harmponic degree of the expansion.
- Returns
- coeffs: ndarray, shape (nmax*(nmax+2),)
Spherical harmonic expansion.
Examples
>>> import chaosmagpy as cp >>> import numpy as np >>> def func(theta, phi): >>> n, m = 1, 1 >>> Pnm = cp.coordinate_utils.legendre_poly(n, theta) >>> return np.cos(m*np.radians(phi))*Pnm[n, m]
>>> cp.coordinate_utils.sh_analysis(func, nmax=1) array([0.0000000e+00, 1.0000000e+00, 1.2246468e-16])