This article introduces an automated interoperability workflow using Ansys Zemax OpticStudio (AZOS) and Ansys Speos, connected by optical design exchange (ODX) data exchange, to analyze and reduce stray light in optical systems. To demonstrate this, we apply the workflow to a cellphone camera system. The process automatically identifies and applies anti-reflective (AR) coatings to critical optical surfaces in Ansys Zemax OpticStudio. Then Speos GPU simulation is utilized to pinpoint and coat problematic optomechanical parts to improve the signal-to-noise ratio (SNR). This scalable, iterative solution reduces manual work by efficiently generating optimized optical designs, enhancing performance through the minimization of unwanted light.
Overview
Understand the simulation workflow and key results
Stray light, including optical ghosts and reflections from optical and optomechanical surfaces, can severely degrade the performance of imaging systems. Addressing these unwanted light paths through surface coatings is essential but can be time-consuming and costly when done manually.
While sequential design is primarily used for investigating imaging quality and performance targets, it can also be leveraged for preliminary stray light mitigation during the early development stages. Specifically, a ghost analysis of double-bounce reflections can be conducted to proactively minimize stray light, a method detailed in the article: Stray Light Analysis with Ghost Focus Generator
This workflow, orchestrated by Python, automates stray light analysis (SLA) and reduction in optical systems.
The block diagram of the Cross-Functional Stray Light Automated Workflow is shown below:
Step 1: Workflow Initialization
A Python script ( Mainworkflow.py ) contains the full implementation of the automated workflow, coordinating the consecutive calls to AZOS and Speos. The user is required to define the target Signal-to-Noise Ratio (SNR) and error budget within this script.
The workflow begins by establishing a standalone connection to AZOS using its application programming interface (ZOS-API). Next, all existing optical coatings (if any) are removed from the model. This ensures that the optimization process evaluates surface contributions to ghost reflections without the impact of prior surface treatments, allowing coatings to be applied only where necessary during the iterative process.
Then, the initial non-sequential ray trace is performed with ray splitting disabled. This isolates only the intended optical paths, i.e., rays that propagate from the defined source fields to the detector without any reflections. The resulting ray data is saved as ZRD file, which is processed using the Path Analysis Tool to sort signal paths and compute the received signal power at the detector. Next, the coating cycles begin.
Each coating cycle consists of two primary parts; the first part is performed in AZOS (Step 2) to identify the optical reflections and the second in Speos (Step 3), to identify reflection on mechanical components. These steps are executed by calling two specialized Python scripts from within the main workflow script: CoatingCycle_Zemax.py for OpticStudio tasks and CoatingCycle_Speos.py for Speos simulations.
Step 2: Ansys OpticStudio - Optical Surface Optimization (Ghost optimization)
Each iteration in AZOS, implemented in CoatingCycle_Zemax.py subroutine, aims at further reducing ghost reflections through performing the following steps:
- Non-sequential ray tracing: A non-sequential ray trace is executed, this time with ray splitting enabled. This allows for the simulation of optical ghost reflections (multiple reflections on optical lenses) that introduced stray light into the system. The ray trace data is again saved in a ZRD file.
- Path analysis: The ray data is analyzed using the Path Analysis Tool. In this step, the tool identifies non-intended paths resulting from ghost reflections.
- Identifying worst offenders: The paths are sorted based on their received noise power, and the face associated with the most significant ghost path, referred to as the worst offender, is identified.
- Applying AR coating: The worst offender's face is then coated with an AR coating.
- Calcualte optical SNR: At this point, the workflow computes the optical SNR based on the previously calculated signal and noise powers.
- Export to ODX: The updated optical system is then exported via ODX, preparing it for the next step in Ansys Speos.
Step 3: Ansys Speos - Optomechanical Stray Light Analysis
The “CoatingCycle_Speos.py” script manages the import and update of the .odx file into Speos and then orchestrates the subsequent workflow. All required sensors and simulations will be automatically created from the .odx sensor data. In total, the following four steps are performed:
- Initial system SNR calculation: A system SNR simulation (including noise from optomechanics) is run to establish a baseline by filtering signal and noise energy.
- Optomechanical face identification: Speos GPU computation is used to identify the specific optomechanical faces contributing predominantly to noise energy.
- Coating application: The identified problematic optomechanical faces, such as the lens barrel or housing, are coated. Users can define upfront specific faces for coating optimization and select coatings from a customizable absorbing coating library.
- Post-Coating system SNR calculation: After problematic optomechanical parts (e.g., lens barrel, housing) are pinpointed and coated, a final System SNR simulation is performed. This post-coating SNR value is then compared with the initial target SNR to assess the effectiveness of the optimization in reducing stray light and improving the overall SNR.
Step 4: Report Generation
Steps 2 and 3 are repeated in successive coating cycles until the target SNR is achieved, after which a comprehensive "Stray Light Analysis Report" in .csv format is generated. This report includes details of the optimization iterations, such as the achieved SNR, lists of the most critical lens or optomechanical faces, and details of the applied coatings.
The preceding description provided a high-level overview of our automated stray light analysis workflow, highlighting its key steps and benefits.
Data: The dataset including the OpticStudio, Speos files and the python scripts can be found in the attachment of this article.
Note on project storage:
For optimal performance and to prevent potential file access issues - such as those related to path length limitations or conflicts with special characters often encountered in cloud-synced directories (e.g., OneDrive)—we strongly recommend storing the project on a local drive rather than a shared network or cloud folder.
Prerequisites :
• Python 3.10 or higher: Make sure you have Python installed on your system. Further required Python modules are listed in the requirements.txt file.
• Ansys Speos 2025 R1 or higher
• Ansys Zemax OpticStudio 2025 R1 or higher
Run and results
Instructions for running the model and discussion of key results
Step 1: Workflow Initialization
In this step, you will first familiarize yourself with the project's folder and file organization. Afterward, we will guide you through configuring the scripts for your specific installation environment.
To help you navigate the project files, here is a detailed breakdown of the folder and file organization:
Note: The files located in the 'Backup Zemax Reset' and 'Backup Speos Reset' folders are provided for recovery purposes and can be used to replace the files in their respective 'active working directories' ('Zemax' and 'Speos' folders).
This section guides you through configuring the Python scripts for your local Ansys Zemax OpticStudio installation.
Before you run the workflow we recommend:
- Access the Project Directory: Open the top-level “SLA Automation” project folder using your preferred file explorer or Python IDE.
- Update the path variable to the correct installation directory of your Ansys Zemax OpticStudio version within "Mainworkflow.py". “AZOS_path=r'C:\Program Files\Ansys Zemax OpticStudio 2025 R1.01”
- Set the System SNR_target and ErrorBudget in the “Main_Workflow.py” script.
- Run the script and monitor the IDE output.
Step 2: Ansys OpticStudio - Optical Surface Optimization (Ghost optimization)
This output log presents the results of an automated ray path analysis, performed within Ansys Zemax OpticStudio via its ZOS-API. It displays key optical simulation data, including input and output flux, the number of simulated rays, the number of all ray branches , and the number of intended paths. The number of simulated rays refers to the total rays initially launched into the system, whereas the number of ray branches includes every subsequent path a ray can take after interacting with lens surfaces, i.e., when a single ray splits into both a refracted and a reflected component at an interface. As a result of the analysis, the details of the first path analysis for identifying the intended paths are displayed. This includes listing the corresponding flux values and the complete ray path sequence that rays follow through the system. For each coating iteration, the output shows the object and its exact face that receives the AR coating; e.g., "Coating Object 14, Face 1 with AR". After the coating is applied, the optics SNR is printed to indicate performance gains. Once the cycle is complete, the system confirms that the updated optical design has been successfully exported to an .odx file, with the save location clearly specified.
Step 3: Ansys Speos - Optomechanical Stray Light Analysis
In step 3 of the process, the updated lens data is imported into Speos, to perform a complete Stray Light Analysis including the optomechanics.
The process successfully exported the .odx file "WorkingCopy_Cycle_01.odx" and log its progress in "Speos_log.txt" located in the “Camera System” folder.
The SLA process involves several key steps:
- Project and Lens Data Import: First we import or update the ODX lens data
- Initial SNR Calculation: Then, we compute an initial Signal-to-Noise Ratio (SNR) using the CPU.
- Worst Offender Identification: Next, a worst offender simulation (SLA_Comp) is performed, leveraging face filtering and GPU processing. This initial iteration consistently identifies the “BAFFLE 3_SLA_ABS” as the primary source of stray light.
- Coating Application: To mitigate this, an "85 Absorbing Coating" (an ideal coating with 85% absorption) is applied to the identified worst offender, specifically "BAFFLE 3_SLA_ABS"
- Post-Coating Assessment: Finally, we compute a new SNR to assess the effectiveness of the coating, save the results, and generate a comprehensive final report (if the target SNR is met).
Step 4: Report Generation
You will receive a notification upon the target Signal-to-Noise Ratio (SNR) being met. Subsequently, a comprehensive Stray Light report will be automatically generated and placed within the project folder.
Straylight Analysis Report:
This following report details the iterative process of optimizing an optical system's performance by minimizing stray light.
The last row, Iteration 3 (4 th iteration loop), represents the culmination of the optimization effort, showcasing the most refined state achieved by the automated optimization.
At this stage:
- The System Noise [W] has been significantly reduced to its lowest point (0.101 W), while the System Signal [W] has reached its highest point (2.556 W).
- Following four rounds of identifying and coating troublesome components, the system's performance has reached its peak. This is clearly indicated by the highest "System SNR after coating" of 25.694, resulting that the system now operates with minimal stray light interference and delivers a signal over 25 times stronger than the residual noise.
-
In this final iteration, "BAFFLE_4_SLA_ABS" was identified as the last "Worst Offender" in the sequence, with "Object17/face 1" on a lens face specifically targeted for additional AR coating. While these final adjustments were made, the overall success stems from the collective application of absorbing coatings across various components (including the SENSOR_HOUSING, BAFFLEs, and the BARREL) throughout all preceding iterations, demonstrably yielding a highly optimized result. Notably, Baffle 3 had previously been identified as the most significant optomechanical noise contributor and was coated with a 90% absorbing coating.
Note: In the current version, only the “System SNR after coating” value is compared to the target. However, the System SNR already reached 25 before the current coating application, indicating that the optomechanical coating assignments from previous iterations were sufficient to meet an SNR of 25.
Important Model Settings
Description of important objects and settings used in this model
OpticStudio: In the “Zemax_Library/Zemax_ParametersAndSettings.py” file, which contains the non-sequential ray tracing parameters for the coating cycle, you can adjust the number of rays and max segments per rays.
Speos: (CoatingCycle_Speos.py) While the default settings provide a good balance between performance and accuracy, you may need to adjust the number of launched rays based on your system's complexity and precision requirements. For instance, to improve the visual quality of the SNR and optomechanical noise results for presentations, increase the “SNR_Rays” and “Comparison_Rays” parameters.
Updating the Model With Your Parameters
Instructions for updating the model based on your device parameters
This workflow-automation is designed to work with various optical lens systems. Using the scripts there are some important things to note. Below you will find these requirements and information about the simulation settings.
OpticStudio:
- A comprehensive stray light and ghost reflection analysis requires converting the design into non-sequential mode to enable full ray interaction tracking. This conversion is a prerequisite that must be completed before initiating the workflow.
- To adapt this automated workflow for a new system, perform the following modifications after converting the design to non-sequential mode:
- The conversion tool generates multiple detectors (one per field). Remove these and replace them with a single, larger detector that matches the sensor specifications used in Speos.
-
Update the detector number in the parameter list to match the new detector object number, as detailed below.
Speos:
- Group optomechanical objects that you want to consider for coating into a component named "Optomechanics". These are selected by the script and are coated and analyzed through each iteration.
- Group all other optomechanical objects that will NOT be coated in the "Optomechanics Noncoating" component. This includes any objects with are unable to be coated or already have a specified and required material or coating. They are geometries you would still like to consider in simulation but will not have any analysis or coatings applied to them.
- Named selections to be analyzed for face filtering are created by the user and labeled with _SLA_ABS at the end of them, Ex) Barrel_SLA_ABS. The named selections (NS) are applied for face filtering on many sensors and the results are analyzed from all of them individually.
- Create "SLA ABS Coatings" folder in materials and populate with idealized coatings in increasing levels of absorption. This is the folder and ranking system the script uses to assign an increasing level of coating to the worst optomechanical system at the time of use. Users can customize this coating list.
- The system SNR is calculated from the output of "Signal" and "Noise" simulations. If you modify the number of field sources, you will also need to adjust the "active sequences" in the Signal and Noise.xml templates located within the Speos input file folder.
- For debugging purposes, you can specify in "Main_Workflow.py" to run Speos in Headless mode = "False".
Taking the model further
Information and tips for users that want to further customize the model
Advanced automated optimization workflows using optiSLang
Using optiSLang with Zemax and Speos is especially powerful for optimizing complex optical systems with a larger number of design parameters. The platform's strength lies in enabling automated workflows for detailed analyses of parameter sensitivity, performance, and robustness across numerous variables simultaneously. Direct integration with Speos simplifies the process of defining and running simulations for these extensive parameter sets. OptiSLang employs advanced techniques, like metamodel-based optimization, to efficiently solve complex design challenges, making it ideal for navigating large design spaces where many variables interact.
This video demonstrates how to create such a workflow, connecting Ansys optiSLang with Zemax OpticStudio and Speos for the automatic data transfer needed in multi-parameter optimization.
Additional resources
Additional documentation, examples and training material
Relevant Speos Ansys Training and Learning Hub courses
- Speos Crash Course
- Speos Rendering Crash Course
- Ansys Speos Getting Started
- Ansys Speos Camera Sensor Visualization
- Stray Light Analysis Theory
- Stray Light Analysis – Smartphone Camera
- Optomechanical tolerancing using Speos – Ansys Optics
- Stray Light Analysis in Ansys Speos Software
An introduction to ZOS-API can be found in:
More information about stray light analysis and smart phone lens design in Ansys Zemax OpticStudio can be found in: