pyzernike.radial_symbolic#

pyzernike.radial_symbolic(n: Integral | Sequence[Integral] | ndarray, m: Integral | Sequence[Integral] | ndarray, rho_derivative: Integral | Sequence[Integral] | ndarray | None = 0) → Expr | List[Expr][source]#

Compute the symbolic expressions of the radial Zernike polynomials \(R_{n}^{m}(\rho)\) and of their derivatives.

The radial Zernike polynomials [1] are defined for \(0 \leq m \leq n\) and \(n - m\) even by:

\[R_{n}^{m}(\rho) = \sum_{k=0}^{\frac{n-m}{2}} \frac{(-1)^k (n-k)!}{k! \left(\frac{n+m}{2} - k\right)! \left(\frac{n-m}{2} - k\right)!} \rho^{n-2k}\]

The expressions are exact polynomials with integer coefficients in the symbol r, which stands for \(\rho\). For \(n \leq 19\) without derivative, they are read from a precomputed table (factorized form \(r^{m} P(r^2)\) for \(n \geq 10\)). Otherwise they are built in expanded form from the exact integer coefficients of the explicit sum (see the page Computation of the polynomials).

  • If \(m < 0\), \(m > n\) or \(n - m\) is odd, the expression is 0.

  • If the derivative order \(a\) is greater than \(n\), the expression is 0.

Shape of the inputs and of the output. n, m and rho_derivative can each be a single integer or a sequence of integers (list, tuple or 1D numpy array):

  • If all of them are integers, a single expression is returned.

  • If at least one of them is a sequence, the integers are repeated to the length \(N\) of the sequences (which must all have the same length), and a list of \(N\) expressions is returned.

See also

Parameters:
  • n (Union[Integral, Sequence[Integral], numpy.ndarray]) – The radial order(s) \(n\).

  • m (Union[Integral, Sequence[Integral], numpy.ndarray]) – The azimuthal frequency(ies) \(m\).

  • rho_derivative (Optional[Union[Integral, Sequence[Integral], numpy.ndarray]], optional) – The order(s) \(a \geq 0\) of the derivative with respect to \(\rho\). Default is 0 (no derivative). None is accepted and means 0.

Returns:

  • If n, m and rho_derivative are integers: a single expression in the symbol r.

  • Otherwise: a list of \(N\) expressions, where output[i] corresponds to (n[i], m[i], rho_derivative[i]).

Return type:

Union[sympy.Expr, List[sympy.Expr]]

Raises:
  • TypeError – If n, m or rho_derivative is not an integer or a sequence of integers.

  • ValueError – If the sequences do not have the same length, or if a derivative order is negative.

References

Examples

Get the expression of \(R_{4}^{0}(\rho)\) and of its first derivative:

from pyzernike import radial_symbolic

print(radial_symbolic(n=4, m=0))
print(radial_symbolic(n=4, m=0, rho_derivative=1))
6*r**4 - 6*r**2 + 1
24*r**3 - 12*r

Evaluate the expressions of order 4 with numpy:

import numpy
import sympy

expressions = radial_symbolic(n=4, m=[0, 2, 4])
rho = numpy.linspace(0, 1, 100)
values = [sympy.lambdify('r', expression, 'numpy')(rho) for expression in expressions]

Note

For an expression equal to a constant (e.g. 0), sympy.lambdify returns a scalar and not an array. Use numpy.broadcast_to(value, rho.shape) if an array is needed.