xy_zernike_evaluate#
- pyzernike.xy_zernike_evaluate(coefficients: Sequence[float] | ndarray, x: ndarray, y: ndarray, x_derivative: Integral | Sequence[Integral] | ndarray | None = 0, y_derivative: Integral | Sequence[Integral] | ndarray | None = 0, *, Rx: Real | None = 1.0, Ry: Real | None = 1.0, x0: Real | None = 0.0, y0: Real | None = 0.0, alpha: Real | None = 0.0, h: Real | None = 0.0, default: int | float = nan, precompute: bool = True, use_recursive: bool = False, normalize: bool = False, to_list: bool = True) ndarray | List[ndarray][source]#
Evaluate a sum of Zernike polynomials on an elliptic annulus \(f = \sum_j c_j Zxy_j\) and its derivatives with respect to the Cartesian coordinates \(x\) and \(y\).
The parameters of the elliptic annulus domain.#
\[\frac{\partial^{a+b} f}{\partial x^{a} \partial y^{b}}(x, y) = \sum_{j=0}^{P-1} c_j \frac{\partial^{a+b} Zxy_j}{\partial x^{a} \partial y^{b}}(x, y)\]where \(Zxy_j\) is the Zernike polynomial of OSA/ANSI index \(j\) on the elliptic annulus (see
pyzernike.xy_zernike_polynomial()). The derivatives of any order are exact, also at the center of the ellipse. The coefficients must contain all the polynomials up to a maximum radial order \(N\), so their number must be \(P = \frac{(N+1)(N+2)}{2}\) (1, 3, 6, 10, 15, …): pad them with zeros if needed.The polynomials are computed by chunks of points, so that the \(P\) arrays of the polynomials are never stored for all the points at once.
Where the point is outside the elliptic annulus (\(\rho_{eq}\) outside \([0, 1]\)), or the coordinates are not finite, the output is set to
default.Shape of the inputs and of the output.
x_derivativeandy_derivativecan each be a single integer or a sequence of integers (list, tuple or 1D numpy array):If both are integers, the output is an array with the shape of
x.If at least one of them is a sequence, the integer is repeated to the length \(D\) of the sequence (the sequences must have the same length), and the output is a list of \(D\) arrays with the shape of
x(to_list=True), or a single array of shape \((D, \dots)\) (to_list=False).
See also
pyzernike.zernike_evaluate()to evaluate a sum of polynomials in polar coordinates.pyzernike.xy_zernike_fit()to compute the coefficients from sampled values.The page Extension to an elliptic annulus for the extension of the Zernike polynomials to the elliptic annulus.
The page Coefficients of a sum of polynomials for the operations on the coefficients.
- Parameters:
coefficients (Union[Sequence[float], numpy.ndarray]) – The coefficients \(c_j\) in the OSA/ANSI ordering, as a 1D array of \(P = \frac{(N+1)(N+2)}{2}\) finite real numbers.
x (numpy.ndarray) – The x Cartesian coordinates with any shape
(...).y (numpy.ndarray) – The y Cartesian coordinates with the same shape as
x. Ifxandyare floating point arrays of the same dtype (e.g.numpy.float32), this dtype is kept. Otherwise, both are converted tonumpy.float64.x_derivative (Optional[Union[Integral, Sequence[Integral], numpy.ndarray]], optional) – The non-negative order(s) of the derivative with respect to \(x\). Default is 0 (no derivative).
y_derivative (Optional[Union[Integral, Sequence[Integral], numpy.ndarray]], optional) – The non-negative order(s) of the derivative with respect to \(y\). Default is 0 (no derivative).
Rx (Optional[Real], optional) – The semi-axis \(R_x\) of the ellipse along its x axis. Must be finite and strictly positive. Default is 1.0.
Ry (Optional[Real], optional) – The semi-axis \(R_y\) of the ellipse along its y axis. Must be finite and strictly positive. Default is 1.0.
x0 (Optional[Real], optional) – The x coordinate \(x_0\) of the center of the ellipse. Must be finite. Default is 0.0.
y0 (Optional[Real], optional) – The y coordinate \(y_0\) of the center of the ellipse. Must be finite. Default is 0.0.
alpha (Optional[Real], optional) – The rotation angle \(\alpha\) of the ellipse in radians. Must be finite. Default is 0.0.
h (Optional[Real], optional) – The ratio \(h\) of the inner to the outer semi-axes, in \([0, 1)\). Default is 0.0 (full ellipse).
default (Union[int, float], optional) – The value set outside the elliptic annulus or where the coordinates are not finite. Integers and floating point numbers (Python or numpy, including
numpy.nanandnumpy.inf) are accepted and converted to float. Booleans are not accepted. Default isnumpy.nan.precompute (bool, optional) – Only used if
use_recursiveis False. If True, the powers and the cosine and sine terms are cached and shared between the polynomials. Default is True.use_recursive (bool, optional) – If True, the polynomials are computed with the recurrence relation (recommended for high orders, see
pyzernike.xy_zernike_polynomial_up_to_order()). Default is False.normalize (bool, optional) – If True, the coefficients are those of the polynomials normalized by the factors of Noll \(N_{n}^{m} = \sqrt{(2 - \delta_{m0})(n + 1)}\) (see
pyzernike.zernike_normalization()). Default is False.to_list (bool, optional) – Only used when several derivatives are computed. If True, the output is a list of arrays. If False, the output is a single array of shape \((D, \dots)\). Default is True.
orders (None is accepted for all the parameters of the ellipse and for the derivative)
value. (and means the default)
- Returns:
If
x_derivativeandy_derivativeare integers: an array with the shape ofx.Otherwise, if
to_listis True: a list of \(D\) arrays with the shape ofx.Otherwise: an array of shape \((D, \dots)\), where
output[d]is the derivative(x_derivative[d], y_derivative[d]).
The dtype is the common floating point dtype of
xandy(numpy.float64by default).- Return type:
Union[numpy.ndarray, List[numpy.ndarray]]
- Raises:
TypeError – If
coefficients,xorycan not be converted to a floating point array, if a parameter of the ellipse is not a real number, ifx_derivativeory_derivativeis not an integer or a sequence of integers, ifdefaultis not an integer or a floating point number, or ifprecompute,use_recursive,normalizeorto_listis not a boolean.ValueError – If
coefficientsis not a 1D array of finite values whose length is \(\frac{(N+1)(N+2)}{2}\), ifxandydo not have the same shape, if a parameter of the ellipse is not finite, ifRxorRyis not strictly positive, ifhis not in \([0, 1)\), if the sequences do not have the same length, or if a derivative order is negative.
Examples
Evaluate a wavefront and its slopes on an elliptic pupil:
import numpy from pyzernike import xy_zernike_evaluate coefficients = numpy.zeros(15) # all the polynomials up to the order 4 coefficients[[4, 5, 8]] = [0.3, -0.15, 0.1] # Z_2^0, Z_2^2 and Z_3^1 pupil = dict(Rx=1.0, Ry=0.7, alpha=numpy.deg2rad(30.0)) X, Y = numpy.meshgrid(numpy.linspace(-1, 1, 200), numpy.linspace(-1, 1, 200)) W = xy_zernike_evaluate(coefficients, X, Y, **pupil) dW_dx, dW_dy = xy_zernike_evaluate(coefficients, X, Y, x_derivative=[1, 0], y_derivative=[0, 1], **pupil)