pyzernike.zernike_index_to_order#
- pyzernike.zernike_index_to_order(j: Integral, indexing: str = 'OSA') Tuple[int, int][source]#
- pyzernike.zernike_index_to_order(j: Sequence[Integral], indexing: str = 'OSA') Tuple[List[int], List[int]]
Convert indices of a Zernike polynomial ordering to their corresponding Zernike orders \((n, m)\).
Three indexing conventions are available (see the page Definition and conventions for the formulas and the details):
"OSA"(or"ANSI", default): the OSA/ANSI standard [1], starting at 0, sorted by increasing \(n\), then by increasing \(m\), with \(j = \frac{n(n + 2) + m}{2}\)."Noll": the indices of Noll [2], starting at 1, sorted by increasing \(n\), then by increasing \(|m|\), with the even indices for \(m > 0\) (cosine) and the odd indices for \(m < 0\) (sine)."Fringe": the Fringe (University of Arizona) indices, starting at 1, sorted by increasing \(\frac{n + |m|}{2}\), then by decreasing \(|m|\), with \(j = \left(1 + \frac{n + |m|}{2}\right)^2 - 2|m| + [m < 0]\). This ordering is not sorted by radial order.
The first Zernike polynomials in each convention are:
n
m
OSA
Noll
Fringe
0
0
0
1
1
1
-1
1
3
3
1
1
2
2
2
2
-2
3
5
6
2
0
4
4
4
2
2
5
6
5
3
-3
6
9
11
3
-1
7
7
8
3
1
8
8
7
3
3
9
10
10
4
0
12
11
9
The functions computing all the polynomials up to an order (e.g.
pyzernike.zernike_polynomial_up_to_order()) and the functions working on vectors of coefficients always use the OSA/ANSI ordering. The vectors of coefficients are converted between the conventions withpyzernike.zernike_coefficients_convert().The conversions use exact integer arithmetic (
math.isqrt), so that the result is exact for any index.Shape of the input and of the output.
jcan be a single integer or a sequence of integers (list, tuple or 1D numpy array):If
jis a single integer, a tuple(n, m)of integers is returned.If
jis a sequence, a tuple(n, m)of lists of integers is returned.
See also
pyzernike.zernike_order_to_index()for the inverse conversion.pyzernike.zernike_polynomials_count()for the number of polynomials up to an order.pyzernike.zernike_coefficients_convert()to convert vectors of coefficients between the conventions.The page Definition and conventions for the indexing conventions.
- Parameters:
j (Union[Integral, Sequence[Integral], numpy.ndarray]) – The index, or the sequence (list, tuple or 1D numpy array) of indices, of the Zernike polynomials. Must be greater than or equal to 0 (OSA/ANSI) or 1 (Noll and Fringe).
indexing (str, optional) – The indexing convention:
"OSA"(or"ANSI"),"Noll"or"Fringe", case insensitive. Default is"OSA".
- Returns:
If
jis an integer, the tuple(n, m)with the radial ordernand the azimuthal frequencymof the Zernike polynomial.If
jis a sequence, the tuple(n, m)wherenis the list of the radial orders andmthe list of the azimuthal frequencies, in the same order asj.- Return type:
Union[Tuple[int, int], Tuple[List[int], List[int]]]
- Raises:
TypeError – If
jis not an integer, a sequence of integers or a 1D numpy array of integers, or ifindexingis not a string.ValueError – If an index in
jis lower than the first index of the convention, or ifindexingis unknown.
References
Examples
Convert a single index:
from pyzernike import zernike_index_to_order n, m = zernike_index_to_order(4) print(n, m) # Output: 2 0
Convert several indices:
j = [2, 3, 4] n, m = zernike_index_to_order(j) print(n) # Output: [1, 2, 2] print(m) # Output: [1, -2, 0]
Convert Noll indices:
n, m = zernike_index_to_order([1, 2, 3, 4, 11], indexing="Noll") print(n) # Output: [0, 1, 1, 2, 4] print(m) # Output: [0, 1, -1, 0, 0]