slmsuite.holography.toolbox.phase.zernike_sum#
- zernike_sum(grid, indices, weights, aperture=None, use_mask=True, derivative=(0, 0), out=None)[source]#
Returns a summation of Zernike polynomials in a computationally-efficient manner. These polynomials are commonly used as an orthonormal basis for optical aberration and are used in a number of places inside
slmsuitefor aberration compensation. This function returns a sum of polynomials:\[\phi(\vec{x}) = \sum_i w_i Z_{I_i}(\vec{x}).\]where \(I_i\) are the ANSI
indicesof the polynomials and \(w_i\) are the floating pointweightsof each polynomial. To improve performance, especially for higher order polynomials, we store a cache of Zernike coefficients to avoid regeneration. See the below example to generate \(Z_1 - Z_2 + Z_4 = Z_1^{-1} - Z_1^1 + Z_2^0\), where the standard radial Zernike indexing \(Z_n^l\) is instead represented as \(Z_j\) by the 1-dimensional ANSI index \(j\).zernike_sum_phase = toolbox.phase.zernike_sum( grid=slm, indices=(1, 2, 4), # Define Z_1, Z_2, Z_4 weights=(1, -1, 1), # Request Z_1 - Z_2 + Z_4 aperture="circular" )
- Parameters:
grid ((array_like, array_like) OR
SLM) – Meshgrids of normalized \(\frac{x}{\lambda}\) coordinates corresponding to SLM pixels, in(x_grid, y_grid)form. These are precalculated and stored in anySLM, so such a class can be passed instead of the grids directly.indices (array_like of int OR None) –
Which Zernike polynomials to sum, defined by ANSI indices. Of shape
(D,).Use
zernike_convert_index()to convert to ANSI from various other common indexing conventions.If
Noneis passed, the assumed Zernike basis depends on the dimensionality of the provided spots:If
D == 2, then the basis is assumed to be[2,1]corresponding to the \(x = Z_2 = Z_1^1\) and \(y = Z_1 = Z_1^{-1}\) tilt terms.If
D == 3, then the basis is assumed to be[2,1,4]corresponding to the previous, with the addition of the \(Z_4 = Z_2^0\) focus term.If
D > 3, then the basis is assumed to be[2,1,4,3,5,6...,D]. The piston term (Zernike index 0) is ignored as this constant phase is not relevant.
weights (array_like of float) – The weight for each given index. Of shape
(D,). If a stack of zernike sums is desired, then use shape(D, N).aperture ({"circular", "elliptical", "cropped"} OR (float, float) OR float OR None) –
Determines how the Zernike polynomials are laterally scaled. Parsed with
zernike_aperture().Important
Read the documentation and tips in
zernike_aperture()to avoid subtle issues with lateral scaling.use_mask (bool OR "return") – If
True, sets the area where standard Zernike polynomials are undefined to zero. IfFalse, the polynomial is not cropped. This should be used carefully, as the wavefront correction outside the unit circle quickly explodes with \(r^O\) for terms of high order \(O\). If"return", returns the 2D maskx_grid**2 + y_grid**2 <= 1.derivative ((int, int)) – If non-negative, returns the Zernike derivative of the given order. For instance,
(1, 0)corresponds to the first derivative in the \(x\) direction. This is fast and accurate because the derivative is computed via power rule before generating Zernike images.out (array_like OR None) – Memory to be used for the phase output. Allocated separately if
None.
- Returns:
The phase for this function. Optionally returns the 2D Zernike mask.
- Return type:
numpy.ndarray