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 indicesrange(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()orpyzernike.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.
ordercan be a single non-negative integer, or a sequence (list, tuple or 1D numpy array) of non-negative integers:If
orderis an integer, a single integer is returned.If
orderis a sequence, a list of integers is returned.
See also
pyzernike.zernike_order_to_index()for converting Zernike orders to indices.pyzernike.zernike_index_to_order()for converting indices to Zernike orders.pyzernike.zernike_polynomial_up_to_order()for computing all the polynomials up to an order.The page Definition and conventions for the indexing conventions.
- 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
orderis an integer, the number of Zernike polynomials up to this order.If
orderis a sequence, the list of the numbers of Zernike polynomials, in the same order asorder.- Return type:
Union[int, List[int]]
- Raises:
TypeError – If
orderis 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]