zernike_coefficients_convert#

pyzernike.zernike_coefficients_convert(coefficients: Sequence[float] | ndarray, *, input_indexing: str = 'OSA', output_indexing: str = 'OSA', input_normalized: bool = False, output_normalized: bool = False) → ndarray[source]#

Convert a vector of coefficients of Zernike polynomials between indexing conventions (OSA/ANSI, Noll, Fringe) and between the normalized and the not normalized polynomials.

The function \(f = \sum_j c_j Z_j\) is unchanged by the conversion:

  • Indexing. The coefficient of each polynomial \(Z_{n}^{m}\) is moved from its index in input_indexing to its index in output_indexing (see pyzernike.zernike_index_to_order()). The vectors start at the first index of each convention (0 for OSA/ANSI, 1 for Noll and Fringe).

  • Normalization. With the factors of Noll \(N_{n}^{m} = \sqrt{(2 - \delta_{m0})(n + 1)}\), \(c_j Z_j = c'_j (N_j Z_j)\), so \(c'_j = c_j / N_j\) from the not normalized to the normalized polynomials, and \(c_j = c'_j N_j\) in the other direction.

Length of the output. The coefficients of the polynomials that are not in the input are set to zero.

  • If input_indexing and output_indexing are the same, the output has the length of the input.

  • If output_indexing is OSA/ANSI or Noll, the output contains all the polynomials up to the maximum radial order \(N\) of the input polynomials, so its length is \(\frac{(N+1)(N+2)}{2}\). In the OSA/ANSI ordering, the output can be given directly to pyzernike.zernike_evaluate().

  • If output_indexing is Fringe, the output ends at the largest Fringe index of the input polynomials (the Fringe ordering is not sorted by radial order: for example, \(Z_4^0\) has the index 9 and \(Z_3^3\) the index 10).

See also

Parameters:
  • coefficients (Union[Sequence[float], numpy.ndarray]) – The coefficients in the input_indexing ordering, as a non-empty 1D array of finite real numbers.

  • input_indexing (str, optional) – The indexing of the input coefficients: "OSA" (or "ANSI"), "Noll" or "Fringe" (case-insensitive). Default is "OSA".

  • output_indexing (str, optional) – The indexing of the output coefficients: "OSA" (or "ANSI"), "Noll" or "Fringe" (case-insensitive). Default is "OSA".

  • input_normalized (bool, optional) – If True, the input coefficients are those of the normalized polynomials. Default is False.

  • output_normalized (bool, optional) – If True, the output coefficients are those of the normalized polynomials. Default is False.

Returns:

The converted coefficients as a 1D array of numpy.float64.

Return type:

numpy.ndarray

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

  • ValueError – If coefficients is not a non-empty 1D array of finite values, or if input_indexing or output_indexing is not a known convention.

Examples

Convert the coefficients of the first 11 Noll polynomials (up to the spherical aberration \(Z_4^0\)) to the OSA/ANSI ordering, to evaluate them:

import numpy
from pyzernike import zernike_coefficients_convert, zernike_evaluate

noll = numpy.array([0.0, 0.1, -0.2, 0.5, 0.0, 0.3, 0.0, 0.0, 0.0, 0.0, 0.05])  # Noll indices 1 to 11
osa = zernike_coefficients_convert(noll, input_indexing="Noll", output_indexing="OSA")  # 15 coefficients

Convert normalized coefficients (e.g. given by a measurement instrument) to the not normalized polynomials:

raw = zernike_coefficients_convert(osa, input_normalized=True, output_normalized=False)