Question

Get data for volume detector in zos API?

  • 14 February 2024
  • 2 replies
  • 66 views

Hello! I am trying to extract the data for a non-sequential volume detector for intensity at each X and Y coordinate along a Z slice for each Z slice. The intention is to eventually make an interactive python plot with a cross section, but I am struggling on actually extracting the detector data using the python API? Anyone have any tips? Thanks :)


2 replies

Userlevel 7
Badge +2

@ArmandP

 

From the ZOSAPI Syntax Help, it doesn’t seem like DataGrid handles 3D data. However, you can still open a Detector Viewer, and have the data for a given Z-Plane. Therefore, one solution is to re-run the Detector Viewer analysis in a loop and iterate over the Zplane setting. At this point however, it might be better to just save the whole analysis as a text file with GetTextFile and then parse the resulting text file. This is what I’ve done in the example below, and I used Napari to view the results in 3D.

Save the Detector Viewer as a text file with the ZOSAPI

This is the ZOSAPI code to save the Detector Viewer data as a text file, assuming a raytrace was run and the Detector Viewer is properly configured already:

# For simplicity, I'm assuming a raytrace was run and the detector viewer has the correct settings already

# Open and run a Detector Viewer analysis
detector_volume = TheSystem.Analyses.New_Analysis(ZOSAPI.Analysis.AnalysisIDM.DetectorViewer)
detector_volume.ApplyAndWaitForCompletion()

# Retrieve the Detector Viewer results
detector_results = detector_volume.GetResults()

# Create a temporary text file
temp_file = r'D:\temporary_file.txt'

# Save the results as a text file
print(detector_results.GetTextFile(temp_file))

# Close the Detector Viewer
detector_volume.Close()

Parse the text file with Python and render in Napari

I’ve put my code to parse the text file data on GitHub at this address:

https://github.com/Omnistic/zosapi_detector_volume_data_parser

Note that this is valid for Unicode encoding of the TXT files in OpticStudio (more about that in the comments of my code). I’m going to attach my OpticStudio test file, but not my text file (it is 0.5GB). You should be able to regenerate the text file with the code above. For reference this is what it looks like:

​And this is the 3D rendering in Napari:

I hope this helps.

Take care,

 

David

Userlevel 5
Badge +3

Hi @ArmandP 

I wonder whether the content in this KBA might be useful? 

STOP Analysis of high-power laser systems - part 4 – Knowledgebase (zemax.com)

Reply