pyzernike.radial_polynomial#
- pyzernike.radial_polynomial(rho: ndarray, n: array | Sequence[Integral], m: array | Sequence[Integral], rho_derivative: array | Sequence[Integral] | None = None, default: Real = nan, precompute: bool = True) List[ndarray][source]#
Computes the radial Zernike polynomial \(R_{n}^{m}(\rho)\) for \(\rho \leq 1\).
The radial Zernike polynomial is defined as follows:
\[R_{n}^{m}(\rho) = \sum_{k=0}^{(n-m)/2} \frac{(-1)^k (n-k)!}{k! ((n+m)/2 - k)! ((n-m)/2 - k)!} \rho^{n-2k}\]If \(n < 0\), \(m < 0\), \(n < m\), or \((n - m)\) is odd, the output is a zeros array with the same shape as \(\rho\). If \(\rho\) is not in \(0 \leq \rho \leq 1\) or \(\rho\) is numpy.nan, the output is set to the default value (numpy.nan by default).
See also
pyzernike.zernike_polynomial()for computing the full Zernike polynomial \(Z_{n}^{m}(\rho, \theta)\).pyzernike.core.core_polynomial()to inspect the core implementation of the computation.The page Mathematical description in the documentation for the detailed mathematical description of the Zernike polynomials.
This function allows to compute several radial Zernike polynomials at once for different sets of (order, azimuthal frequency, derivative order) given as sequences, which can be more efficient than calling the radial polynomial function multiple times.
The parameters
n,mandrho_derivativemust be sequences of integers with the same length.
The \(\rho\) values are the same for all the polynomials. The output is a list of numpy arrays, each containing the values of the radial Zernike polynomial for the corresponding order and azimuthal frequency. The list has the same length as the input sequences and the arrays have the same shape as
rho.Note
If the input
rhois not a floating point numpy array, it is converted to one withnumpy.float64dtype by default. If the inputrhois a floating point numpy array (ex:numpy.float32), the computation will be done innumpy.float32.- Parameters:
rho (numpy.ndarray (N-D array)) – The radial coordinate values with shape (…,) and floating point values.
n (Sequence[Integral] or numpy.array) – A sequence (List, Tuple) or 1D numpy array of the radial order(s) of the Zernike polynomial(s) to compute. Must be non-negative integers.
m (Sequence[Integral] or numpy.array) – A sequence (List, Tuple) or 1D numpy array of the azimuthal frequency(ies) of the Zernike polynomial(s) to compute. Must be non-negative integers.
rho_derivative (Optional[Union[Sequence[Integral], numpy.array]], optional) – A sequence (List, Tuple) or 1D numpy array of the order(s) of the radial derivative(s) to compute. Must be non-negative integers. If None, is it assumed that rho_derivative is 0 for all polynomials.
default (Real, optional) – The default value for invalid rho values. The default is numpy.nan. If the radial coordinate values are not in the valid domain (0 <= rho <= 1) or if they are numpy.nan, the output is set to this value.
precompute (bool, optional) – If True, precomputes the useful terms for better performance when computing multiple polynomials with the same rho values. If False, computes the useful terms on the fly for each polynomial to avoid memory overhead. The default is True.
- Returns:
A list of numpy arrays containing the radial Zernike polynomial values for each order and azimuthal frequency. Each array has the same shape as
rhoand the list has the same length as the input sequences. The dtype of the arrays is the same as the dtype ofrhois given, otherwisenumpy.float64.- Return type:
List[numpy.ndarray]
- Raises:
TypeError – If the rho values can not be converted to a 1D numpy array of floating points values. If n, m or rho_derivative (if not None) are not sequences of integers.
ValueError – If the lengths of n, m and rho_derivative (if not None) are not the same.
Examples
Compute the radial Zernike polynomial \(R_{2}^{0}(\rho)\) for \(\rho \leq 1\):
import numpy from pyzernike import radial_polynomial rho = numpy.linspace(0, 1, 100) result = radial_polynomial(rho, n=[2], m=[0]) polynomial = result[0] # result is a list, we take the first element
Compute the radial Zernike polynomial \(R_{2}^{0}(\rho)\) and its first derivative for \(\rho \leq 1\):
import numpy from pyzernike import radial_polynomial rho = numpy.linspace(0, 1, 100) result = radial_polynomial(rho, n=[2,2], m=[0,0], rho_derivative=[0, 1]) polynomial = result[0] # result is a list, we take the first element derivative = result[1] # result is a list, we take the second element