SphericalHarmonicsExpander

SphericalHarmonicsExpander#

Expand a set of points using spherical harmonics.

The spherical harmonics expansion is performed using the following equation:

\[f(\theta, \phi) = \sum_{l=0}^{L} \sum_{m=-l}^{l} a_{lm} Y_{lm}(\theta, \phi)\]

where \(a_{lm}\) are the spherical harmonics coefficients and \(Y_{lm}(\theta, \phi)\) are the spherical harmonics functions. The expansion is performed in the spherical coordinate system.

param max_degree:

Maximum degree of spherical harmonics expansion.

type max_degree:

int

param expansion_type:

Type of expansion to perform. Can be either ‘cartesian’ or ‘radial’.

type expansion_type:

str

param normalize_spectrum:

Normalize power spectrum sum to 1.

type normalize_spectrum:

bool

Examples

>>> from napari_stress import SphericalHarmonicsExpander
>>> expander = SphericalHarmonicsExpander(max_degree=5, expansion_type='cartesian')
>>> # Generate points roughly on the surface of a sphere
>>> n = 100
>>> theta = np.linspace(0, np.pi, n)
>>> phi = np.linspace(0, 2 * np.pi, n)
>>> theta, phi = np.meshgrid(theta, phi)
>>> x = np.sin(theta) * np.cos(phi)
>>> y = np.sin(theta) * np.sin(phi)
>>> z = np.cos(theta)
>>> points = np.stack([x.ravel(), y.ravel(), z.ravel()], axis=1)
>>> expander.fit(points)  # Fit spherical harmonics to points
>>> expanded_points = expander.expand(points)  # Expand points using spherical harmonics
napari_stress.approximation.SphericalHarmonicsExpander.coefficients_#

Spherical harmonics coefficients of shape (3, max_degree + 1, max_degree + 1) for ‘cartesian’ expansion type or (1, max_degree + 1, max_degree + 1) for ‘radial’ expansion type.

Type:

np.ndarray

napari_stress.approximation.SphericalHarmonicsExpander.properties#

Dictionary containing properties of the expansion, including residuals and power spectrum. - residuals: np.ndarray

Residual euclidian distance between input points and expanded points.

  • power_spectrum: np.ndarray

    Power spectrum of spherical harmonics coefficients. If ‘normalize_spectrum’ is set to True, the power spectrum is normalized to sum to 1. The spectrum \(P_l\) is calculated as follows:

    \[P_l = \sum_{m=-l}^{l} |a_{lm}|^2\]

    where \(a_{lm}\) are the spherical harmonics coefficients.

Type:

dict

napari_stress.approximation.SphericalHarmonicsExpander.fit(points: 'napari.types.PointsData')#

Fit spherical harmonics to input data. If expansion_type is ‘cartesian’, the input points are converted to ellipsoidal coordinates (latitude/longitude) before fitting and each coordinate (z, y, z) is fitted separately. Hence, the derived coefficients are of shape (3, max_degree + 1, max_degree + 1). If expansion_type is ‘radial’, the input points are converted to radial coordinates ($math:rho, theta, phi$) before fitting. Only the radial coordinate is fitted, hence the derived coefficients are of shape `(1, max_degree + 1, max_degree + 1).

napari_stress.approximation.SphericalHarmonicsExpander.expand(points: 'napari.types.PointsData')#

Expand input points using spherical harmonics.

napari_stress.approximation.SphericalHarmonicsExpander.fit_expand(points: 'napari.types.PointsData')#

Fit spherical harmonics to input data and then expand them.