sphharm
SphericalHarmonics
Bases: SphericalHarmonicsBase
Spherical harmonics.
SphericalHarmonicsBase
Base class for spherical harmonics [1] [2] [3] [4] [5] [6] [7] [8].
References
.. [1] Ken-Ichi, K. (1984). Distribution of directional data and fabric tensors. International journal of engineering science, 22(2), 149-164. .. [2] Green, R. (2003, March). Spherical harmonic lighting: The gritty details. In Archives of the game developers conference (Vol. 56, p. 4). .. [3] https://en.wikipedia.org/wiki/Spherical_harmonics .. [4] https://en.wikipedia.org/wiki/Table_of_spherical_harmonics .. [5] https://en.wikipedia.org/wiki/Legendre_polynomials .. [6] https://en.wikipedia.org/wiki/Associated_Legendre_polynomials .. [7] https://docs.scipy.org/doc/scipy/reference/generated/scipy.special.sph_harm.html .. [8] https://zhuanlan.zhihu.com/p/466774017
basis
classmethod
Spherical harmonics basis in complex form. The spherical harmonics function in complex form is defined as
where :math:P_n^m
are the associated Legendre functions.
basis_real
classmethod
Spherical harmonics basis in real form. The spherical harmonics function in real form is defined as
which gives in simplified form
evalf
classmethod
Evaluate a function with given arguments, vectorize it if necessary.
PARAMETER | DESCRIPTION |
---|---|
func
|
Function that takes theta and phi as arguments and returns the function value.
TYPE:
|
args
|
Positional arguments passed to func.
DEFAULT:
|
vectorize_kwargs
|
Keyword arguments passed to
TYPE:
|
kwargs
|
Keyword arguments passed to func.
DEFAULT:
|
expand
classmethod
expand(
func: (
Callable[[float, float], float] | Callable[[ndarray, ndarray], ndarray]
),
deg: int,
*,
n_sample: int = N_SAMPLE_DEFAULT,
n_theta: int = N_THETA_DEFAULT,
n_phi: int = N_PHI_DEFAULT
) -> Tuple[ndarray, ndarray, ndarray, ndarray, Dict[int, ndarray]]
Expand a function in the spherical harmonics basis.
PARAMETER | DESCRIPTION |
---|---|
deg
|
Degree of the spherical harmonics basis.
TYPE:
|
func
|
Function that takes theta and phi as arguments and returns the function value.
TYPE:
|
n_sample
|
Number of samples, by default 1000.
TYPE:
|
n_theta
|
Number of points to use for the theta (azimuthal, 0-2*pi) coordinate, by default 101
TYPE:
|
n_phi
|
Number of points to use for the phi (polar, 0-pi) coordinate, by default 101
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tuple[ndarray, ndarray, ndarray, ndarray, Dict[int, ndarray]]
|
A tuple of coefs, theta, phi, fevals, and fprojs_degrees, where fprojs_degrees is a dictionary of the projected function for each degree. |
plot_basis
classmethod
plot_basis(
n: int,
m: int,
*,
n_theta: int = N_THETA_DEFAULT,
n_phi: int = N_PHI_DEFAULT,
positive_color: str = "green",
negative_color: str = "red",
ax: Union["Axes3D", None] = None,
subplot_kwargs: dict | None = None,
**kwargs
) -> Tuple["Figure", "Axes3D"]
Plot the spherical harmonics function.
PARAMETER | DESCRIPTION |
---|---|
n
|
Degree of the harmonic (int); must have n >= 0. This is often denoted by l (lower case L) in descriptions of spherical harmonics.
TYPE:
|
m
|
Order of the harmonic (int); must have abs(m) <= n.
TYPE:
|
n_theta
|
Number of points to use for the theta (azimuthal, 0-2*pi) coordinate, by default 101
TYPE:
|
n_phi
|
Number of points to use for the phi (polar, 0-pi) coordinate, by default 101
TYPE:
|
positive_color
|
Color to use for positive values, by default "green"
TYPE:
|
negative_color
|
Color to use for negative values, by default "red"
TYPE:
|
ax
|
Axes to plot on, by default None.
TYPE:
|
subplot_kwargs
|
Keyword arguments passed to
TYPE:
|
kwargs
|
Keyword arguments passed to
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
Tuple[Figure, Axes3D]
|
Figure and axes objects containing the plot. |
plot_gallery
classmethod
plot_gallery(
deg: int,
*,
subplot_kwargs: dict | None = None,
clear_empty_axis: bool = True,
clear_axis: bool = False,
**kwargs
) -> Tuple["Figure", List[List["Axes3D"]]]
Plot a gallery of spherical harmonics functions.
PARAMETER | DESCRIPTION |
---|---|
deg
|
Degree of the spherical harmonics basis.
TYPE:
|
subplot_kwargs
|
Keyword arguments passed to
TYPE:
|
clear_empty_axis
|
Whether to clear the axis if there is no plot, by default True
TYPE:
|
clear_axis
|
Whether to clear the axis of all plots, by default False
TYPE:
|
kwargs
|
Keyword arguments passed to
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
Tuple[Figure, List[List[Axes3D]]]
|
Figure and list of lists of axes objects containing the plots. |
plot_projection
classmethod
plot_projection(
func: (
Callable[[float, float], float] | Callable[[ndarray, ndarray], ndarray]
),
deg: int,
*,
n_sample: int = N_SAMPLE_DEFAULT,
n_theta: int = N_THETA_DEFAULT,
n_phi: int = N_PHI_DEFAULT,
positive_color: str = "green",
negative_color: str = "red",
ax: Union["Axes3D", None] = None,
subplot_kwargs: dict | None = None,
**kwargs
) -> Tuple["Figure", "Axes3D"]
Plot the projected function onto the spherical harmonics basis.
PARAMETER | DESCRIPTION |
---|---|
func
|
Function that takes theta and phi as arguments and returns the function value.
TYPE:
|
deg
|
Degree of the spherical harmonics basis.
TYPE:
|
n_sample
|
Number of samples, by default 1000.
TYPE:
|
n_theta
|
Number of points to use for the theta (azimuthal, 0-2*pi) coordinate, by default 101
TYPE:
|
n_phi
|
Number of points to use for the phi (polar, 0-pi) coordinate, by default 101
TYPE:
|
positive_color
|
Color to use for positive values, by default "green"
TYPE:
|
negative_color
|
Color to use for negative values, by default "red"
TYPE:
|
ax
|
Axes to plot on, by default None.
TYPE:
|
subplot_kwargs
|
Keyword arguments passed to
TYPE:
|
kwargs
|
Keyword arguments passed to
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
Tuple[Figure, List[Axes3D]]
|
Figure and list of two axes objects containing the plots. |
plot_projections_gallery
classmethod
plot_projections_gallery(
func: (
Callable[[float, float], float] | Callable[[ndarray, ndarray], ndarray]
),
deg: int,
*,
n_sample: int = N_SAMPLE_DEFAULT,
n_theta: int = N_THETA_DEFAULT,
n_phi: int = N_PHI_DEFAULT,
positive_color: str = "green",
negative_color: str = "red",
subplot_kwargs: dict | None = None,
real_kwargs: dict | None = None,
proj_kwargs: dict | None = None,
clear_empty_axis: bool = True,
clear_axis: bool = False,
**kwargs
) -> Tuple["Figure", List[List["Axes3D"]]]
project
classmethod
project(
func: (
Callable[[float, float], float] | Callable[[ndarray, ndarray], ndarray]
),
deg: int,
n_sample: int = N_SAMPLE_DEFAULT,
) -> ndarray
Project a spherical function onto the spherical harmonics basis.
The coefficients of the spherical harmonics basis are given by
PARAMETER | DESCRIPTION |
---|---|
deg
|
Degree of the spherical harmonics basis.
TYPE:
|
func
|
Function that takes theta and phi as arguments and returns the function value.
TYPE:
|
n_sample
|
Number of samples, by default 1000.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ndarray
|
An array of shape
|