optiland.zernike.fit
Zernike Fit Module
This module contains the ZernikeFit class, which can be used to fit Zernike polynomial to a set of points. This is commonly used for wavefront calculations, but the class can be used for any fitting operation requiring Zernike polynomials.
Kramer Harrison, 2025
Classes
|
Fit Zernike polynomials to wavefront or arbitrary data points. |
- class ZernikeFit(x: ScalarOrArray, y: ScalarOrArray, z: ScalarOrArray, zernike_type: Literal['fringe', 'standard', 'noll'] = 'fringe', num_terms: int = 36)[source]
Fit Zernike polynomials to wavefront or arbitrary data points.
This class constructs a linear design matrix of Zernike basis functions and solves for the coefficients via least squares.
- Parameters:
x (array-like) – X-coordinates of data points.
y (array-like) – Y-coordinates of data points.
z (array-like) – Values at (x, y) to fit.
zernike_type (str) – Type of Zernike basis: ‘fringe’, ‘standard’, or ‘noll’.
num_terms (int) – Number of Zernike terms to include in the fit.
- x
Flattened x-coordinates.
- Type:
array-like
- y
Flattened y-coordinates.
- Type:
array-like
- z
Flattened target values.
- Type:
array-like
- radius
Radial coordinate of each point.
- Type:
array-like
- phi
Azimuthal coordinate of each point.
- Type:
array-like
- num_pts
Number of data points.
- Type:
int
- zernike
Zernike basis instance with fitted coefficients.
- Type:
- property coeffs: BEArray
The fitted Zernike coefficients.
- Type:
Tensor
- view(fig_to_plot_on: Figure | None = None, projection: str = '2d', num_points: int = 128, figsize: tuple[float, float] = (7, 5.5), z_label: str = 'OPD (waves)') tuple[Figure, Axes][source]
Visualize the fitted Zernike surface.
- Parameters:
fig_to_plot_on (plt.Figure, optional) – Figure to plot on. If None, a new figure is created.
projection (str) – ‘2d’ for image plot, ‘3d’ for surface plot.
num_points (int) – Grid resolution for display.
figsize (tuple) – Figure size in inches.
to (defaults)
z_label (str) – Label for the z-axis or colorbar.
'OPD (defaults to)
- Returns:
A tuple containing the figure and axes objects.
- Return type:
tuple
- Raises:
ValueError – If projection is not ‘2d’ or ‘3d’.
- view_residual(fig_to_plot_on: Figure | None = None, figsize: tuple[float, float] = (7, 5.5), z_label: str = 'Residual (waves)')[source]
Scatter plot of residuals between fitted surface and original data.
- Parameters:
fig_to_plot_on (plt.Figure, optional) – Figure to plot on. If None, a new figure is created.
figsize (tuple) – Figure size in inches. Defaults to (7, 5.5).
z_label (str) – Label for the colorbar. Defaults to ‘Residual (waves)’.
- Returns:
A tuple containing the figure and axes objects.
- Return type:
tuple