API Documentation
This section provides detailed API documentation for the individual modules within the stop-utils package.
Command-Line Interface (cli)
Command-line interface for WFE analysis.
- stop_utils.cli.print_coeffs(coefficients, zernikes)[source]
Logs polynomial coefficients line by line.
- stop_utils.cli.save_coefficients(output_dir, orthonormal_coefficients, zernike_coefficients, params)[source]
Save polynomial coefficients and ellipse parameters to JSON file.
- stop_utils.cli.run_analysis(input_file, output_dir, n_polynomials, plot_format, save_coeffs, no_plots, file_format=None)[source]
Run WFE analysis with given parameters.
- stop_utils.cli.callback(version=<typer.models.OptionInfo object>)[source]
Wavefront Error Analysis Tools - Analyze and visualize wavefront error data.
This tool provides functionality for analyzing wavefront error data using (orthonormal) polynomial decomposition on elliptical apertures and generating visualization outputs.
- stop_utils.cli.analyze(input_file=<typer.models.OptionInfo object>, output_dir=<typer.models.OptionInfo object>, n_polynomials=<typer.models.OptionInfo object>, plot_format=<typer.models.OptionInfo object>, save_coeffs=<typer.models.OptionInfo object>, no_plots=<typer.models.OptionInfo object>, file_format=<typer.models.OptionInfo object>)[source]
Analyze WFE data and generate results.
WFE Analysis (wfe_analysis)
Core functionality for Wavefront Error analysis.
- stop_utils.wfe_analysis.load_wfe_data(file_path, file_format=None)[source]
Load WFE data from file and convert to nanometers. Handles different formats based on the provided format string or defaults to generic.
- stop_utils.wfe_analysis.mask_to_elliptical_aperture(label_img)[source]
Convert an elliptical mask to a photutils EllipticalAperture.
- Parameters:
label_img (
ndarray[Any,dtype[int64]]) – Labeled image array where each region has a unique integer value- Returns:
(EllipticalAperture object, EllipticalParams object)
- Return type:
- Raises:
ValueError – If no regions found in mask
- stop_utils.wfe_analysis.calculate_polynomials(pupil_mask, x, y, n_polynomials=15)[source]
Calculate orthonormal polynomials for given coordinates.
- Parameters:
- Returns:
(Orthonormal polynomials array, Covariance matrix)
- Return type:
- stop_utils.wfe_analysis.fit_polynomials(errormap, pupil_mask, x, y, n_polynomials=15)[source]
Fit orthonormal polynomials to WFE data.
- Parameters:
- Returns:
raw: Errormap to be fitted
coefficients: Fitted orthonormal polynomial coefficients
zernikes: Zernike coefficients (after removing first 3 terms from the orthonormal fit)
PTTF component map
Complete model map
Residual error map
- Return type:
WFEResult object containing
- stop_utils.wfe_analysis.analyze_wfe_data(wfe_file, n_polynomials=15, file_format=None)[source]
Analyze WFE data file.
- Parameters:
- Returns:
(WFEResult object, EllipticalParams object)
- Return type:
- Raises:
FileNotFoundError – If wfe_file does not exist
ValueError – If data cannot be processed
Visualization (visualization)
Visualization utilities for WFE analysis.
- stop_utils.visualization.setup_wfe_plot(data, title, zoom=4, cmap='jet')[source]
Set up a basic WFE plot with common formatting.
- stop_utils.visualization.plot_wfe_data(data, aperture=None, title='Wavefront Error Map', output_path=None, zoom=4, cmap='gray_r')[source]
Plot WFE data with optional aperture overlay.
- Parameters:
- Return type:
File Format Converters (converters)
- stop_utils.converters.load_zemax_wfe(file_path)[source]
Loads Wavefront Error (WFE) data from a Zemax text file.
Parses the header to find wavelength and grid size, then reads the data grid and converts it from waves to nanometers.
- Parameters:
file_path (
Union[str,Path]) – path to the Zemax WFE map file (.txt). Can be a string or Path object.- Return type:
- Returns:
A 2D numpy array containing the WFE map in nanometers.
- Raises:
FileNotFoundError – If the file does not exist.
ValueError – If the file format is incorrect or metadata is missing.
Types (types)
Type definitions for stop-utils package.
- class stop_utils.types.EllipticalParams(x0, y0, a, b, theta)[source]
Bases:
objectParameters defining an elliptical aperture.
- class stop_utils.types.WFEResult(raw, coefficients, zernikes, pttf, model, residual)[source]
Bases:
objectResults from WFE analysis.
- Parameters:
Zemax Integration (zemax)
Note
The Zemax integration modules require a Windows system with Zemax OpticStudio installed. These modules use the Zemax ZOS-API which is only available on Windows platforms.
- Prerequisites:
Windows operating system
Zemax OpticStudio (Premium, Professional, or Standard Edition)
Valid Zemax license for API use
Python.NET (pythonnet) package installed
The Zemax submodule provides integration with Zemax OpticStudio through its ZOS-API.
Core ZOS-API Interface (zemax.zemax_wfe)
- class stop_utils.zemax.zmx_boilerplate.PythonStandaloneApplication(path=None)[source]
Bases:
object- reshape(data, x, y, transpose=False)[source]
Converts a System.Double[,] to a 2D list for plotting or post processing
- Parameters:
data (System.Double[,] data directly from ZOS-API)
x (x width of new 2D list [use var.GetLength(0) for dimension])
y (y width of new 2D list [use var.GetLength(1) for dimension])
transpose (transposes data; needed for some multi-dimensional line series data)
- Returns:
res – a numpy array using numpy.asarray(res)
- Return type:
2D list; can be directly used with Matplotlib or converted to
Wavefront Extractor (zemax.wavefront_extractor)
Batch Processor (zemax.zmx_batch_processor)
- stop_utils.zemax.zmx_batch_processor.batch_process_zmx(base_folder, output_dir='WavefrontOutputs', surface_name='EXPP', wavelength_um=None)[source]
Process all ZMX files in the specified directory.
Warning
Attempting to use these modules on non-Windows platforms will result in import errors for Windows-specific dependencies like ‘winreg’ and the Zemax API components.