pyzernike.zernike_display#

pyzernike.zernike_display(n: Integral | Sequence[Integral] | ndarray, m: Integral | Sequence[Integral] | ndarray, rho_derivative: Integral | Sequence[Integral] | ndarray | None = 0, theta_derivative: Integral | Sequence[Integral] | ndarray | None = 0, *, precompute: bool = True, resolution: int = 200, rho_power: float = 1.0) → None[source]#

Display the Zernike polynomials \(Z_{n}^{m}(\rho, \theta)\) and their derivatives in a matplotlib figure.

Each polynomial is drawn as a colormap on the unit disk (polar axes). When several polynomials are given, the “Previous” and “Next” buttons of the figure navigate through them. The color scale spans \([\min(-1, Z), \max(1, Z)]\).

The Zernike polynomials [1] are defined on the unit disk for \(|m| \leq n\) and \(n - m\) even by:

\[\begin{split}Z_{n}^{m}(\rho, \theta) = \begin{cases} R_{n}^{m}(\rho) \cos(m \theta) & \text{if } m \geq 0 \\ R_{n}^{|m|}(\rho) \sin(|m| \theta) & \text{if } m < 0 \end{cases}\end{split}\]

and their derivatives are given in pyzernike.zernike_polynomial(). If \(|m| > n\), \(n - m\) is odd, \(a > n\), or \(m = 0\) and \(b > 0\), the displayed polynomial is zero.

Shape of the inputs. n, m, rho_derivative and theta_derivative can each be a single integer or a sequence of integers (list, tuple or 1D numpy array). The integers are repeated to the length of the sequences, which must all have the same length.

See also

Parameters:
  • n (Union[Integral, Sequence[Integral], numpy.ndarray]) – The radial order(s) \(n\).

  • m (Union[Integral, Sequence[Integral], numpy.ndarray]) – The azimuthal frequency(ies) \(m\).

  • rho_derivative (Optional[Union[Integral, Sequence[Integral], numpy.ndarray]], optional) – The order(s) \(a \geq 0\) of the derivative with respect to \(\rho\). Default is 0 (no derivative). None is accepted and means 0.

  • theta_derivative (Optional[Union[Integral, Sequence[Integral], numpy.ndarray]], optional) – The order(s) \(b \geq 0\) of the derivative with respect to \(\theta\). Default is 0 (no derivative). None is accepted and means 0.

  • precompute (bool, optional) – If True, the powers of \(\rho\) and the cosine and sine terms are cached and shared between the polynomials. Default is True.

  • resolution (int, optional) – The number of points along each axis of the display grid. Default is 200.

  • rho_power (float, optional) – The strictly positive exponent \(p\) of the display mapping: at the displayed radial coordinate \(s \in [0, 1]\), the polynomial is evaluated at \(\rho = s^{p}\). With \(p < 1\) (e.g. 0.5), the edge of the disk, where the high order polynomials oscillate the most, is enlarged; with \(p > 1\), the center is enlarged. Default is 1 (no mapping).

Return type:

None

Raises:
  • TypeError – If n, m, rho_derivative or theta_derivative is not an integer or a sequence of integers, if precompute is not a boolean, or if resolution is not an integer or rho_power is not a real number.

  • ValueError – If the sequences do not have the same length or are empty, if a derivative order is negative, or if resolution is lower than 2 or rho_power is not strictly positive.

References

Examples

Display the defocus \(Z_{2}^{0}(\rho, \theta)\):

from pyzernike import zernike_display

zernike_display(n=2, m=0)

Display the first 15 polynomials in the OSA/ANSI ordering:

from pyzernike import zernike_index_to_order

n, m = zernike_index_to_order(range(15))
zernike_display(n=n, m=m)
../_images/zernike_display.png