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_indexingto its index inoutput_indexing(seepyzernike.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_indexingandoutput_indexingare the same, the output has the length of the input.If
output_indexingis 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 topyzernike.zernike_evaluate().If
output_indexingis 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
pyzernike.zernike_index_to_order()andpyzernike.zernike_order_to_index()for the indexing conventions.pyzernike.zernike_normalization()for the normalization factors of Noll.The page Definition and conventions for the indexing conventions and the normalization.
The page Coefficients of a sum of polynomials for the operations on the coefficients.
- Parameters:
coefficients (Union[Sequence[float], numpy.ndarray]) – The coefficients in the
input_indexingordering, 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
coefficientscan not be converted to an array of real numbers, ifinput_indexingoroutput_indexingis not a string, or ifinput_normalizedoroutput_normalizedis not a boolean.ValueError – If
coefficientsis not a non-empty 1D array of finite values, or ifinput_indexingoroutput_indexingis 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)