zernike_rms#

pyzernike.zernike_rms(coefficients: Sequence[float] | ndarray, *, normalize: bool = False) → float[source]#

Compute the root mean square (RMS) of a sum of Zernike polynomials on the unit disk from its coefficients.

The RMS is computed around the mean value of the function \(f = \sum_j c_j Z_j\) (the piston is removed):

\[\sigma^2 = \frac{1}{\pi} \int_{0}^{2\pi} \int_{0}^{1} \left( f - \bar{f} \right)^2 \rho \, d\rho \, d\theta\]

The polynomials are orthogonal on the unit disk with \(\frac{1}{\pi} \int Z_j^2 = \frac{1}{N_j^2}\), where \(N_j\) are the normalization factors of Noll, and only the piston has a non-zero mean, so:

\[\sigma = \sqrt{\sum_{j > 0} \frac{c_j^2}{N_j^2}} \quad \text{or} \quad \sigma = \sqrt{\sum_{j > 0} c_j^2} \text{ for the normalized polynomials}\]

The value is exact (no sampling). It is also the RMS on an ellipse for the polynomials of pyzernike.xy_zernike_polynomial() with \(h = 0\) (the mapping onto the disk is affine).

See also

Parameters:
  • coefficients (Union[Sequence[float], numpy.ndarray]) – The coefficients \(c_j\) in the OSA/ANSI ordering, as a 1D array of \(P = \frac{(N+1)(N+2)}{2}\) finite real numbers.

  • normalize (bool, optional) – If True, the coefficients are those of the polynomials normalized by the factors of Noll (see pyzernike.zernike_normalization()). Default is False.

Returns:

The RMS \(\sigma\), in the unit of the coefficients.

Return type:

float

Raises:
  • TypeError – If coefficients can not be converted to an array of real numbers, or if normalize is not a boolean.

  • ValueError – If coefficients is not a 1D array of finite values whose length is \(\frac{(N+1)(N+2)}{2}\).

Examples

The RMS of the defocus \(Z_2^0 = 2\rho^2 - 1\) is \(1 / \sqrt{3}\):

import numpy
from pyzernike import zernike_rms

zernike_rms([0.0, 0.0, 0.0, 0.0, 1.0, 0.0])  # 0.5773...
zernike_rms([0.0, 0.0, 0.0, 0.0, 1.0, 0.0], normalize=True)  # 1.0 (normalized defocus)