zernike_generator#

class arte.utils.zernike_generator.ZernikeGenerator(pupil)#

Bases: object

Generator of Zernike polynomials and their derivatives

The generator returns masked arrays representing Zernike polynomials sampled over the array grid. The pixels whose distance from the unit disk center is greater than the mask radius are masked.

The discretization of the continous unit disk space into the array grid is done in the pixels’ center (e.g. if the disk diameter is 2 pixels and the center is in x=1 then the first pixel contains polynomial values evaluated in x=-0.5 and the second pixel contains values evaluated in x=0.5)

The user can specify the diameter of the pupil pupil or specify a CircularMask

In the case a scalar real value is passed as pupil argument, The shape of the returned array cannot be specified: it is a square array of size ceil(pupil_diameter). The center of the unit disk cannot be specified and it is the central pixel of the array (if the array size is odd) or the corner of the 4 central pixels (if the array size is even).

In the case a CircularMask is passed as pupil argument, the mask is used as unit disk over which the polynomial are computed. Non-integer center coordinates and radius are properly managed.

Parameters:

pupil (real or CircularMask) – If a scalar value, the argument is used as pupil diameter in pixels. If a CircularMask, the argument is used as mask representing the unit disk.

Notes

Polynomials normalization and ordering follows the conventions described in Noll’s paper [1]

[1]

Noll, R. J., “Zernike polynomials and atmospheric turbulence.”, Journal of the Optical Society of America (1917-1983), vol. 66, pp. 207–211, 1976.

[2]

Born, M. and Wolf, E., “Principles of Optics”, 7th edition, Cambridge University Press, 1999.

[3]

Magnus W., Oberhettinger F., and Soni R.P., “Formulas and Theorems for the Special Functions of Mathematical Physics”, Springer-Verlag, New York, 1966.

Examples

Create a Zernike polynomial sampled with unit circle defined over 64 pixels representing tilt

>>> zg = ZernikeGenerator(64)
>>> tip = zg.getZernike(2)
>>> tilt = zg.getZernike(3)
>>> tilt = zg[3] # equivalent to getZernike(3)

Methods

cartesian_coordinates()

Return X, Y maps of cartesian coordinates

center()

Y, X coordinates of the unit disk center

first_mode()

Index of first mode, excluding piston

index_to_name_dict()

Zernike index to zernike name mapping

name_to_index_dict([piston_index])

Zernike name to zernike index mapping

radial_order(j)

Return radial order of j-th polynomial

radius()

Radius of the unit disk

degree

getDerivativeX

getDerivativeXDict

getDerivativeY

getDerivativeYDict

getModesDict

getZernike

getZernikeDict

cartesian_coordinates()#

Return X, Y maps of cartesian coordinates

The Zernike polynomials and derivatives are evaluated over a grid of points, whose coordinates are accessible through cartesian_coordinates

Returns:

X,Y – coordinates of points of the unit disk where the polynomials are evaluated

Return type:

array

Examples

Create Zernike polynomials on a unit disk defined over 4 pixels. The returned arrays have (4,4) shape (corresponding to the coords [-0.75, -0.25, 0.25, 0.75])

>>> zg = ZernikeGenerator(4)
>>> x, y = zg.cartesian_coordinates()
>>> x[0]
array([-0.75, -0.25,  0.25,  0.75])

As above with 3 pixels

>>> zg = ZernikeGenerator(3)
>>> x, y = zg.cartesian_coordinates()
>>> x[0]
array([-0.666, 0,  0.666])

In case of non-integer diameter, the array size is rounded up to the next integer

>>> zg = ZernikeGenerator(2.5)
>>> x, y = zg.cartesian_coordinates()
>>> x[0]
array([-0.8, 0,  0.8])
center()#

Y, X coordinates of the unit disk center

Returns:

center – Y, X coordinate of the unit disk center in the array reference system

Return type:

array of shape (2,)

classmethod degree(index)#
first_mode()#

Index of first mode, excluding piston

getDerivativeX(index)#
getDerivativeXDict(indexVector)#
getDerivativeY(index)#
getDerivativeYDict(indexVector)#
getModesDict(indexVector)#
getZernike(index)#
getZernikeDict(indexVector)#
classmethod index_to_name_dict()#

Zernike index to zernike name mapping

Returns:

names – dictionary of Zernike mode names: int -> str

Return type:

dict

classmethod name_to_index_dict(piston_index=None)#

Zernike name to zernike index mapping

Optionally shifts the naming vector so that piston corresponds to a specified index. For example if tip and tilt are the first modes, then piston_index should be set to -1

Returns:

names – dictionary of Zernike indexes: str -> int

Return type:

dict

classmethod radial_order(j)#

Return radial order of j-th polynomial

Parameters:

j (int or sequence of int) – polynomial index

Returns:

n – radial order of the specified indexes

Return type:

int or sequence of int

radius()#

Radius of the unit disk

Returns:

radius – unit disk radius in pixel

Return type:

real