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 with pyzernike.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. j can be a single integer or a sequence of integers (list, tuple or 1D numpy array):

  • If j is a single integer, a tuple (n, m) of integers is returned.

  • If j is a sequence, a tuple (n, m) of lists of integers is returned.

See also

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 j is an integer, the tuple (n, m) with the radial order n and the azimuthal frequency m of the Zernike polynomial.

If j is a sequence, the tuple (n, m) where n is the list of the radial orders and m the list of the azimuthal frequencies, in the same order as j.

Return type:

Union[Tuple[int, int], Tuple[List[int], List[int]]]

Raises:
  • TypeError – If j is not an integer, a sequence of integers or a 1D numpy array of integers, or if indexing is not a string.

  • ValueError – If an index in j is lower than the first index of the convention, or if indexing is 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]