pyzernike.zernike_order_to_index#
- pyzernike.zernike_order_to_index(n: Integral, m: Integral, indexing: str = 'OSA') int[source]#
- pyzernike.zernike_order_to_index(n: Sequence[Integral], m: Sequence[Integral], indexing: str = 'OSA') List[int]
Convert Zernike orders \((n, m)\) to their corresponding indices in a Zernike polynomial ordering.
Three indexing conventions are available (see the page Definition and conventions for the details, and
pyzernike.zernike_index_to_order()for the table of the first indices):"OSA"(or"ANSI", default): the OSA/ANSI standard [1], starting at 0, with \(j = \frac{n(n + 2) + m}{2}\)."Noll": the indices of Noll [2], starting at 1, with \(j = \frac{n(n + 1)}{2} + |m| + s\), where \(s \in \{0, 1\}\) is chosen so that the even indices correspond to \(m > 0\) (cosine) and the odd indices to \(m < 0\) (sine)."Fringe": the Fringe (University of Arizona) indices, starting at 1, with \(j = \left(1 + \frac{n + |m|}{2}\right)^2 - 2|m| + [m < 0]\).
If \(n < 0\), \(|m| > n\) or \((n - m)\) is odd, an error is raised.
Shape of the inputs and of the output.
nandmcan be two integers, or two sequences of integers (lists, tuples or 1D numpy arrays) with the same length:If
nandmare integers, a single integer index is returned.If
nandmare sequences, a list of integer indices is returned.Mixing an integer and a sequence is not allowed.
See also
pyzernike.zernike_index_to_order()for the inverse conversion and the table of the first indices.pyzernike.zernike_coefficients_convert()to convert vectors of coefficients between the conventions.The page Definition and conventions for the indexing conventions.
- Parameters:
n (Union[Integral, Sequence[Integral]]) – The radial order, or the sequence of radial orders, of the Zernike polynomials.
m (Union[Integral, Sequence[Integral]]) – The azimuthal frequency, or the sequence of azimuthal frequencies, of the Zernike polynomials. Must be of the same kind as
n(integer or sequence) and, for sequences, of the same length.indexing (str, optional) – The indexing convention:
"OSA"(or"ANSI"),"Noll"or"Fringe", case insensitive. Default is"OSA".
- Returns:
If
nandmare integers, the indexjof the Zernike polynomial in the given convention.If
nandmare sequences, the list of the indices, in the same order asnandm.- Return type:
Union[int, List[int]]
- Raises:
TypeError – If
normis not an integer, a sequence of integers or a 1D numpy array of integers, if an integer is mixed with a sequence, or ifindexingis not a string.ValueError – If
nandmdo not have the same length, if a pair(n, m)is not a valid Zernike order (\(n < 0\), \(|m| > n\) or \((n - m)\) odd), or ifindexingis unknown.
References
Examples
Convert a single pair of orders:
from pyzernike import zernike_order_to_index j = zernike_order_to_index(2, 0) print(j) # Output: 4
Convert several pairs of orders:
from pyzernike import zernike_order_to_index n = [2, 3, 4] m = [0, 1, -2] indices = zernike_order_to_index(n, m) print(indices) # Output: [4, 8, 11]
The function is the inverse of
pyzernike.zernike_index_to_order():from pyzernike import zernike_index_to_order, zernike_order_to_index j = [0, 5, 12] print(zernike_order_to_index(*zernike_index_to_order(j))) # Output: [0, 5, 12]
Convert to Noll and Fringe indices:
print(zernike_order_to_index([2, 2, 4], [-2, 2, 0], indexing="Noll")) # Output: [5, 6, 11] print(zernike_order_to_index([2, 2, 4], [-2, 2, 0], indexing="Fringe")) # Output: [6, 5, 9]