pyzernike.display_interactive#

pyzernike.display_interactive(*, precompute: bool = True, resolution: int = 200, rho_power: float = 1.0) → None[source]#

Explore the Zernike polynomials \(Z_{n}^{m}(\rho, \theta)\) and the radial polynomials \(R_{n}^{m}(\rho)\), and their derivatives, in an interactive matplotlib figure.

The left panel of the figure contains:

  • a selector to switch between the full Zernike polynomials and the radial polynomials,

  • text boxes to set the radial order \(n\), the azimuthal frequency \(m\), the order \(a\) of the derivative with respect to \(\rho\) and the order \(b\) of the derivative with respect to \(\theta\) (hidden for the radial polynomials),

  • text boxes to set the resolution of the grid and the exponent rho_power of the display mapping (see below),

  • a “Generate” button,

  • a message line reporting the invalid inputs.

The plot is computed and updated only when the “Generate” button is clicked, so that the values can be typed without triggering a computation at each change:

  • the radial polynomials are drawn as curves \(\rho \mapsto \frac{d^a R_{n}^{m}}{d\rho^a}(\rho)\) on \([0, 1]\),

  • the Zernike polynomials are drawn as colormaps of \(\frac{\partial^{a+b} Z_{n}^{m}}{\partial \rho^{a} \partial \theta^{b}}\) on the unit disk.

The vertical axis (radial) or the color scale (Zernike) spans \([\min(-1, Z), \max(1, Z)]\). If \(|m| > n\) or \(n - m\) is odd, the displayed polynomial is zero and a warning is shown.

The same figure is opened from the command line with pyzernike (and the figure on an elliptic annulus with pyzernike --xy, see pyzernike.xy_display_interactive()).

See also

Parameters:
  • precompute (bool, optional) – If True, the powers of \(\rho\) and the cosine and sine terms are cached during the computation of each polynomial. Default is True.

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

  • rho_power (float, optional) – The initial 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 precompute is not a boolean, resolution is not an integer or rho_power is not a real number.

  • ValueError – If resolution is lower than 2 or rho_power is not strictly positive.

Examples

Open the interactive figure:

from pyzernike import display_interactive

display_interactive()

Start with a finer grid and enlarge the edge of the disk to explore high orders:

display_interactive(resolution=400, rho_power=0.5)