Zernike (paos.classes.zernike)
- class Zernike(N, rho, phi, ordering='ansi', normalize=False)[source]
Bases:
objectGenerates Zernike polynomials
- Parameters:
N (integer) – Number of polynomials to generate in a sequence following the defined ‘ordering’
rho (array like) – the radial coordinate normalised to the interval [0, 1]
phi (array like) – Azimuthal coordinate in radians. Has same shape as rho.
ordering (string) –
- The ordering of the Zernike polynomials. Can either be:
ANSI (ordering=’ansi’, this is the default);
Noll (ordering=’noll’). Used in Zemax as “Zernike Standard Coefficients”, R. Noll, “Zernike polynomials and atmospheric turbulence”, J. Opt. Soc. Am., Vol. 66, No. 3, p207 (1976);
Fringe (ordering=’fringe’), AKA the “Fringe” or “University of Arizona” notation;
Standard (ordering=’standard’). Used in CodeV, Born and Wolf, Principles of Optics (Pergamon Press, New York, 1989).
normalize (bool) – Set to True generates ortho-normal polynomials. Set to False generates orthogonal polynomials as described in Laksminarayan & Fleck, Journal of Modern Optics (2011). The radial polynomial is estimated using the Jacobi polynomial expression as in their Equation in Equation 14.
- Returns:
out – An instance of Zernike.
- Return type:
masked array
Example
>>> import numpy as np >>> from matplotlib import pyplot as plt >>> x = np.linspace(-1.0, 1.0, 1024) >>> xx, yy = np.meshgrid(x, x) >>> rho = np.sqrt(xx**2 + yy**2) >>> phi = np.arctan2(yy, xx) >>> zernike = Zernike(36, rho, phi, ordering='noll', normalize=True) >>> zer = zernike() # zer contains a list of polynomials, noll-ordered
>>> # Plot the defocus zernike polynomial >>> plt.imshow(zer[3]) >>> plt.show()
>>> # Plot the defocus zernike polynomial >>> plt.imshow(zernike(3)) >>> plt.show()
Note
In the example, the polar angle is counted counter-clockwise positive from the x axis. To have a polar angle that is clockwise positive from the y axis (as in figure 2 of Laksminarayan & Fleck, Journal of Modern Optics (2011)) use
>>> phi = 0.5*np.pi - np.arctan2(yy, xx)
- static j2mn(N, ordering)[source]
Convert index j into azimuthal number, m, and radial number, n for the first N Zernikes
- Parameters:
N (integer) – Number of polynomials (starting from Piston)
ordering (string) – can take values ‘ansi’, ‘standard’, ‘noll’, ‘fringe’
- Returns:
m, n
- Return type:
array
- static mn2j(m, n, ordering)[source]
Convert radial and azimuthal numbers, respectively n and m, into index j
- cov()[source]
Computes the covariance matrix M defined as
>>> M[i, j] = np.mean(Z[i, ...]*Z[j, ...])
When a pupil is defined as \(\Phi = \sum c[k] Z[k, ...]\), the pupil RMS can be calculated as
>>> RMS = np.sqrt( np.dot(c, np.dot(M, c)) )
This works also on a non-circular pupil, provided that the polynomials are masked over the pupil.
- Returns:
M – the covariance matrix
- Return type:
array
- class PolyOrthoNorm(N, rho, phi, ordering='ansi', normalize=False, mask=False)[source]
Bases:
ZernikeGenerates polynomials that are ortho-normal on the mask provided. This is done by applying the Gram-Smidth orthonormalization process, implemented following Section 3.4 of https://doi.org/10.1117/3.927341. Therefore, the relevant input are the type of Zernike polinomial to be used (ordering and normalization), and the mask defining the pupil.
U[m] = sum_n M[m, n] Z[n]
where Z[m] are Zernike polynomials over a circular domain containing the pupil. If Phi is the field on the pupil, using linear algebra notation:
Phi = b.T U = b.T M Z = c.T Z
And the coefficients of the Zernike expansion are
c.T = M.T c
- Parameters:
N (integer) – Number of polynomials to generate in a sequence following the defined ‘ordering’
rho (array like) – the radial coordinate normalised to the interval [0, 1]. If rho is a numpy masked array, the mask is used in the orthonormalisation process
phi (array like) – Azimuthal coordinate in radians. Has same shape as rho.
ordering (string) –
- The ordering of the Zernike polynomials. Can either be:
ANSI (ordering=’ansi’, this is the default);
Noll (ordering=’noll’). Used in Zemax as “Zernike Standard Coefficients”, R. Noll, “Zernike polynomials and atmospheric turbulence”, J. Opt. Soc. Am., Vol. 66, No. 3, p207 (1976);
Fringe (ordering=’fringe’), AKA the “Fringe” or “University of Arizona” notation;
Standard (ordering=’standard’). Used in CodeV, Born and Wolf, Principles of Optics (Pergamon Press, New York, 1989).
normalize (bool) –
The normalisation of Zernike polinomials. Set to True generates ortho-normal polynomials. Set to False generates orthogonal polynomials as described in Laksminarayan & Fleck, Journal of Modern Optics (2011). The radial polynomial is estimated using the Jacobi polynomial expression as in their Equation in Equation 14.
mask (bool array like) – The mask defining the pupil following masked array convention. Pixel within the pupil are masked False. Defaults to False.
- Returns:
out – An instance of Zernike.
- Return type:
masked array
Example
>>> import numpy as np >>> from matplotlib import pyplot as plt >>> x = np.linspace(-1.0, 1.0, 1024) >>> xx, yy = np.meshgrid(x, x) >>> mask = xx**2 + (yy/0.5)**2 > 1.0 >>> rho = np.ma.MaskedArray(data=np.sqrt(xx**2 + yy**2), mask=mask, fill_value=0.0) >>> phi = np.arctan2(yy, xx) >>> poly = PolyOrthoNorm(36, rho, phi, ordering='noll', normalize=True) >>> U = poly() # zer contains a list of polynomials, noll-ordered
>>> # Plot the Power polynomial >>> plt.imshow(U[4]) >>> plt.show()
Note
In the example, the polar angle is counted counter-clockwise positive from the x axis. To have a polar angle that is clockwise positive from the y axis (as in figure 2 of Laksminarayan & Fleck, Journal of Modern Optics (2011)) use
>>> phi = 0.5*np.pi - np.arctan2(yy, xx)
- toZernike(coeff)[source]
If Phi is the field on the pupil, using linear algebra notation:
Phi = coeff.T U = c.T Z
This function returns the Zerkinke coefficients c
- Parameters:
coeff (vector 1D) – coefficients of the field in the orthonormal base
- Returns:
out – coefficiens of the field in the Zernike expansion
- Return type:
vector 1D