pyzernike.cartesian_to_elliptic_annulus#

pyzernike.cartesian_to_elliptic_annulus(x: ndarray, y: ndarray, 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, x_derivative: Integral | Sequence[Integral] | ndarray | None = 0, y_derivative: Integral | Sequence[Integral] | ndarray | None = 0, *, to_list: bool = True) → Tuple[ndarray, ndarray] | Tuple[List[ndarray], List[ndarray]][source]#

Transform Cartesian coordinates \((x, y)\) into the equivalent polar coordinates \((\rho_{eq}, \theta_{eq})\) of an elliptic annulus, and compute their derivatives with respect to \(x\) and \(y\).

../_images/elliptic_annulus_domain.png

The parameters of the elliptic annulus domain.#

The elliptic annulus is defined by its semi-axes \(R_x\) and \(R_y\), its center \((x_0, y_0)\), its rotation angle \(\alpha\) and the ratio \(h = \frac{a}{R_x} = \frac{b}{R_y}\) of the inner to the outer semi-axes. The coordinates are first expressed in the frame of the ellipse:

\[X = \cos(\alpha) (x - x_0) + \sin(\alpha) (y - y_0) \quad \text{and} \quad Y = -\sin(\alpha) (x - x_0) + \cos(\alpha) (y - y_0)\]

then mapped onto the unit annulus [1]:

\[r = \sqrt{\left(\frac{X}{R_x}\right)^2 + \left(\frac{Y}{R_y}\right)^2}, \quad \rho_{eq} = \frac{r - h}{1 - h} \quad \text{and} \quad \theta_{eq} = \operatorname{atan2}\left(\frac{Y}{R_y}, \frac{X}{R_x}\right) \in [-\pi, \pi]\]

The points of the elliptic annulus are those with \(0 \leq \rho_{eq} \leq 1\). The coordinates \((\rho_{eq}, \theta_{eq})\) can be passed directly to pyzernike.zernike_polynomial().

The derivatives of total order 1 and 2 are computed with the analytical expressions obtained by the chain rule (see the section Derivatives of the equivalent polar coordinates of the page Extension to an elliptic annulus). The derivatives of total order 3 and more are not available. The derivatives are not defined at the center of the ellipse (\(r = 0\)).

Note

The derivatives of the Zernike polynomials with respect to \(x\) and \(y\) are not limited: they are computed without the chain rule by pyzernike.xy_zernike_polynomial().

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

  • If both are integers, the output is a tuple (rho_eq, theta_eq) of two arrays with the shape of x.

  • If at least one of them is a sequence, the integer is repeated to the length \(N\) of the sequence (the sequences must have the same length). The output is a tuple of two lists of \(N\) arrays (to_list=True), or of two arrays of shape \((N, \dots)\) (to_list=False).

See also

Parameters:
  • x (numpy.ndarray) – The x Cartesian coordinates with any shape (...).

  • y (numpy.ndarray) – The y Cartesian coordinates with the same shape as x. If x and y are floating point arrays of the same dtype (e.g. numpy.float32), this dtype is kept. Otherwise, both are converted to numpy.float64.

  • 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).

  • 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). For each pair, the total order x_derivative + y_derivative must be lower than or equal to 2.

  • to_list (bool, optional) – Only used when several derivatives are computed. If True, the output is a tuple of two lists of arrays. If False, it is a tuple of two arrays of shape \((N, \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:

The tuple (rho_eq, theta_eq):

  • If x_derivative and y_derivative are integers: two arrays with the shape of x.

  • Otherwise, if to_list is True: two lists of \(N\) arrays with the shape of x.

  • Otherwise: two arrays of shape \((N, \dots)\).

rho_eq[i] (resp. theta_eq[i]) is the derivative of \(\rho_{eq}\) (resp. \(\theta_{eq}\)) of order x_derivative[i] with respect to \(x\) and y_derivative[i] with respect to \(y\).

Return type:

Union[Tuple[numpy.ndarray, numpy.ndarray], Tuple[List[numpy.ndarray], List[numpy.ndarray]]]

Raises:
  • TypeError – If x or y can not be converted to a floating point array, if a parameter of the ellipse is not a real number, if x_derivative or y_derivative is not an integer or a sequence of integers, or if to_list is not a boolean.

  • ValueError – If x and y do not have the same shape, if a parameter of the ellipse is not finite, if Rx or Ry is not strictly positive, if h is not in \([0, 1)\), if the sequences do not have the same length, if a derivative order is negative, or if a total order of derivation x_derivative + y_derivative is greater than 2.

References

Examples

Compute the defocus \(Z_{2}^{0}\) on a circle of radius 2 centered at \((1, 1)\):

import numpy
from pyzernike import cartesian_to_elliptic_annulus, zernike_polynomial

X, Y = numpy.meshgrid(numpy.linspace(-1, 3, 100), numpy.linspace(-1, 3, 100))
rho_eq, theta_eq = cartesian_to_elliptic_annulus(X, Y, Rx=2.0, Ry=2.0, x0=1.0, y0=1.0)
Z20 = zernike_polynomial(rho_eq, theta_eq, n=2, m=0)

The complete process can be done in one step with pyzernike.xy_zernike_polynomial().

Compute the coordinates and their first derivatives with respect to \(x\) and \(y\):

rho_eq, theta_eq = cartesian_to_elliptic_annulus(X, Y, Rx=2.0, Ry=2.0, x0=1.0, y0=1.0, x_derivative=[0, 1, 0], y_derivative=[0, 0, 1])
rho, drho_dx, drho_dy = rho_eq
theta, dtheta_dx, dtheta_dy = theta_eq