pyzernike.radial_symbolic#

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

Compute the symbolic expression of 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 the zero polynomial.

See also

The function allows to display several radial Zernike polynomials for different sets of (order, azimuthal frequency, derivative order) given as sequences.

  • The parameters n, m and rho_derivative must be sequences of integers with the same length.

The output is a list of sympy expressions, each containing the symbolic expression of the radial Zernike polynomial for the corresponding order and azimuthal frequency. The list has the same length as the input sequences.

Note

The symbol r is used to represent the radial coordinate \(\rho\) in the symbolic expression.

Parameters:
  • 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.

Returns:

A list of symbolic expressions containing the radial Zernike polynomial values for each order and azimuthal frequency Each expression is a sympy expression that can be evaluated for specific values of \(\rho\).

Return type:

List[sympy.Expr]

Raises:
  • TypeError – 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 expression of the radial Zernike polynomial \(R_{2}^{0}(\rho)\):

from pyzernike import radial_symbolic
result = radial_symbolic(n=[2], m=[0])
expression = result[0]  # result is a list, we take the first element
print(expression)
2*r**2 - 1

Then evaluate the expression for a specific value of \(\rho\):

import numpy
import sympy
rho = numpy.linspace(0, 1, 100)
# `r` represents the radial coordinate in the symbolic expression

func = sympy.lambdify('r', expression, 'numpy')
evaluated_result = func(rho)