zernike_polynomials_count#

pyzernike.zernike_polynomials_count(order: Integral) → int[source]#
pyzernike.zernike_polynomials_count(order: Sequence[Integral]) → List[int]

Compute the number of Zernike polynomials \(Z_{n}^{m}\) with a radial order \(0 \leq n \leq N\), i.e. the number of polynomials computed up to the order \(N\).

For each radial order \(n\) there are \(n + 1\) polynomials (\(m = -n, -n + 2, \dots, n\)), so that:

\[P(N) = \sum_{n=0}^{N} (n + 1) = \frac{(N + 1)(N + 2)}{2}\]

In the OSA/ANSI ordering, the last polynomial of order \(N\) is \(Z_{N}^{N}\), with index \(j(N, N) = N(N + 3)/2\). Since the indices start at 0, the number of polynomials is \(P(N) = j(N, N) + 1\), and the polynomials up to the order \(N\) are exactly the indices range(P(N)). The same holds for the Noll indices range(1, P(N) + 1), but not for the Fringe ordering, which is not sorted by radial order.

\(P(N)\) is also the length of a complete vector of coefficients up to the order \(N\), as expected by the functions working on coefficients (e.g. pyzernike.zernike_evaluate() or pyzernike.zernike_rms()).

The first values are:

N

j(N, N)

P(N)

0

0

1

1

2

3

2

5

6

3

9

10

4

14

15

…

…

…

Shape of the input and of the output. order can be a single non-negative integer, or a sequence (list, tuple or 1D numpy array) of non-negative integers:

  • If order is an integer, a single integer is returned.

  • If order is a sequence, a list of integers is returned.

See also

Parameters:

order (Union[Integral, Sequence[Integral], numpy.ndarray]) – The maximum radial order \(N\), or a sequence (list, tuple or 1D numpy array) of maximum radial orders.

Returns:

If order is an integer, the number of Zernike polynomials up to this order.

If order is a sequence, the list of the numbers of Zernike polynomials, in the same order as order.

Return type:

Union[int, List[int]]

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

  • ValueError – If any order is negative.

Examples

Number of polynomials up to the order 4:

from pyzernike import zernike_polynomials_count

P = zernike_polynomials_count(4)
print(P)  # Output: 15

List all the orders (n, m) up to the order 2:

from pyzernike import zernike_polynomials_count, zernike_index_to_order

n, m = zernike_index_to_order(range(zernike_polynomials_count(2)))
print(n)  # Output: [0, 1, 1, 2, 2, 2]
print(m)  # Output: [0, -1, 1, -2, 0, 2]