zernike_coefficients_rotate#

pyzernike.zernike_coefficients_rotate(coefficients: Sequence[float] | ndarray, angle: Real) → ndarray[source]#

Express a sum of Zernike polynomials in a pupil frame rotated by an angle \(\phi\).

The output coefficients \(c'\) describe the same function in the rotated frame:

\[\sum_j c'_j Z_j(\rho, \theta) = \sum_j c_j Z_j(\rho, \theta + \phi)\]

i.e. the point of polar angle \(\theta\) in the new frame is the point of polar angle \(\theta + \phi\) in the initial frame. For each pair of polynomials \(Z_n^{m}\) and \(Z_n^{-m}\) (\(m > 0\)), with the coefficients \(a\) of \(R_n^m(\rho) \cos(m\theta)\) and \(b\) of \(R_n^m(\rho) \sin(m\theta)\):

\[a' = a \cos(m\phi) + b \sin(m\phi) \quad \text{and} \quad b' = b \cos(m\phi) - a \sin(m\phi)\]

The rotationally symmetric polynomials (\(m = 0\)) are unchanged. The relation is exact, and holds for the normalized and the not normalized polynomials (the factors of Noll are the same for \(m\) and \(-m\)). This is the particular case of pyzernike.zernike_coefficients_transform() with angle=phi.

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.

  • angle (Real) – The rotation angle \(\phi\) of the new frame in radians (counterclockwise). Must be finite.

Returns:

The coefficients \(c'_j\) in the rotated frame, 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, or if angle is not a real number.

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

Examples

An astigmatism \(Z_2^2\) rotated by 45 degrees becomes the astigmatism \(Z_2^{-2}\):

import numpy
from pyzernike import zernike_coefficients_rotate

coefficients = numpy.array([0.0, 0.0, 0.0, 0.0, 0.0, 1.0])  # Z_2^2 (OSA index 5)
rotated = zernike_coefficients_rotate(coefficients, angle=numpy.pi / 4)
# rotated ~ [0, 0, 0, -1, 0, 0]: cos(2 (theta + pi/4)) = -sin(2 theta)