zernike_coefficients_transform#

pyzernike.zernike_coefficients_transform(coefficients: Sequence[float] | ndarray, *, scale: Real = 1.0, x0: Real = 0.0, y0: Real = 0.0, angle: Real = 0.0, normalize: bool = False) → ndarray[source]#

Express a sum of Zernike polynomials in a new pupil, scaled, decentered and rotated with respect to the initial pupil.

The new pupil is the disk of center \((x_0, y_0)\) and radius \(s\), in the normalized coordinates of the initial pupil (whose radius is 1), with its axes rotated by the angle \(\phi\). The point \(p'\) of the new unit disk is the point \(q\) of the initial pupil:

\[\begin{split}q = \begin{pmatrix} x_0 \\ y_0 \end{pmatrix} + s \begin{pmatrix} \cos\phi & -\sin\phi \\ \sin\phi & \cos\phi \end{pmatrix} p'\end{split}\]

and the output coefficients \(c'\) describe the same function in the new pupil:

\[\sum_j c'_j Z_j(p') = \sum_j c_j Z_j(q)\]

This is the classical problem of the comparison of measurements made on pupils of different sizes or positions (e.g. a smaller pupil, \(s < 1\), or a decentered sub-aperture). As a polynomial of degree \(N\) stays a polynomial of degree \(N\), the new coefficients are exact and use the same polynomials (up to the order \(N\)). They are computed with a matrix \(c' = T c\), obtained by projection on the polynomials with an exact quadrature, and cached for the last parameters.

Note

If the new pupil is not inside the initial pupil (\(\sqrt{x_0^2 + y_0^2} + s > 1\)), the function is extrapolated outside the initial pupil with its polynomial expression, which is usually not meaningful for measured data.

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.

  • scale (Real, optional) – The radius \(s\) of the new pupil, in units of the radius of the initial pupil. Must be finite and strictly positive. Default is 1.0.

  • x0 (Real, optional) – The x coordinate \(x_0\) of the center of the new pupil, in units of the radius of the initial pupil. Must be finite. Default is 0.0.

  • y0 (Real, optional) – The y coordinate \(y_0\) of the center of the new pupil, in units of the radius of the initial pupil. Must be finite. Default is 0.0.

  • angle (Real, optional) – The rotation angle \(\phi\) of the axes of the new pupil in radians (counterclockwise). Must be finite. Default is 0.0.

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

Returns:

The coefficients \(c'_j\) in the new pupil, as a 1D array of \(P\) numpy.float64.

Return type:

numpy.ndarray

Raises:
  • TypeError – If coefficients can not be converted to an array of real numbers, if scale, x0, y0 or angle is not a real number, 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}\), if a parameter is not finite, or if scale is not strictly positive.

Examples

A defocus measured on a pupil of radius 1 is seen on the central part of radius 0.5 as a smaller defocus (and a piston): \(Z_2^0(0.5 \rho) = 2 (0.5 \rho)^2 - 1 = 0.25 Z_2^0(\rho) - 0.75\).

import numpy
from pyzernike import zernike_coefficients_transform

coefficients = numpy.array([0.0, 0.0, 0.0, 0.0, 1.0, 0.0])  # Z_2^0 (OSA index 4)
transformed = zernike_coefficients_transform(coefficients, scale=0.5)
# transformed ~ [-0.75, 0, 0, 0, 0.25, 0]

A decentered sub-aperture of radius 0.3 centered at (0.5, 0): the defocus gives a tilt in the sub-aperture.

transformed = zernike_coefficients_transform(coefficients, scale=0.3, x0=0.5)