Skip to main content
Question

ZOS-API, Python Image simulation. No output

  • September 20, 2023
  • 2 replies
  • 123 views

KBL
  • Single Emitter

Hey, I’m very naïve to Zemax and ZOS-API. 

I just tried to find the setting and run the code, but I couldn’t see the results from the image simulation.

I used the standalone application and here is my code.

 

    # load local variables
    ZOSAPI = zos.ZOSAPI
    TheApplication = zos.TheApplication
    TheSystem = zos.TheSystem
    
    # Insert Code Here
    file = "C:/2021/Zemax_Image_Simulation/test.zmx"
    cfg = "C:/2021/Zemax_Image_Simulation/test.CFG"
    TheSystem.LoadFile(file, False)
    TheImageSimulation = TheSystem.Analyses.New_ImageSimulation()
    analysisSettings = TheImageSimulation.GetSettings()
    
    analysisSettings.ModifySettings(cfg, 'ISM_INPUTFILE', "Text_100p_3x3_2_g1196x1279_dist.png")
    analysisSettings.ModifySettings(cfg, 'ISM_FIELDHEIGHT', '15')
    analysisSettings.ModifySettings(cfg, 'ISM_FLIPIMAGE', '3')
    analysisSettings.ModifySettings(cfg, 'ISM_OUTPUTFILE', 'Test1.png')
    
    analysisSettings.LoadFrom(cfg)

    a = TheImageSimulation.ApplyAndWaitForCompletion()
    b = TheImageSimulation.GetResults()

 

 

after running the code, the “a” said “ successfully unlocked Spatial components”

I don’t think it went successful because it was completed too soon ~ 10 sec (it takes 1 or 2 minutes in zemax)

Could you guide me on how to debug this situation?

Thanks.

2 replies

nicolexi
  • Single Emitter
  • 1 reply
  • March 13, 2025

Hi I think the Zemax can not retrieve the data if the UI didn’t have currently.

For example, the case you mentioned, I have the same question. If you look through the GetResults results. they are all zero. The way to solve it is to change the OutputFile path as yourdesiredfilepath.bmp, and run the analysis. you can do that using modifysettings


Hi ​@KBL,

 

I think the best way to debug is to connect in extension modus to OpticStudio. If you create analysis when connected, it should show in OpticStudio, and you can see what happens. Maybe there is an invalid setting or something else wrong, which will show in the UI. 

 

Some points of error that I can think of from the top of my hat:

  1. Is the InputFile in the correct folder? (It should be if you can normally use it). A quick wat to inspect if the API sees it with analysisSettings.GetInputFileNames() (or list(nalysisSettings.GetInputFileNames()))
  2. Is the output file correctly occurring in the images folder? According to the documentation, just a filename and extension should save it in the OpticStudio Images folder, but in my experience, the API sometimes wants full length paths instead (I have not worked with this analysis, so I'm unsure.
  3. What version of Pythonnet are you using. As indicated in this post, there can be some issues that you need to account for in your code to make sure you have the correct settings object. Another way is to use the ZOSPy python package, which takes care of the pythonnet problems (note that I am one of the authors of that package, so I 'm a bit biased).
    p.s. We do not have the Image Simulation implemented in ZOSPy yet, but you can easily use the new_analysis() function to get a well working analysis class
    p.p.s. A new major release with some breaking changes is very near, so if you want to start using ZOSPy it might reward to wait a few days!

 

Unfortunately, obtaining the results through the ZOS-API is not directly possible, as also said by ​@nicolexi (at least for my OpticStudio version, which is not the latest). I checked the data in the results within the ZOS-API and it gives:

NumberOfDataGrids: 0
NumberOfDataGridsRgb: 0
NumberOfDataScatterPoints: 0
NumberOfDataScatterPointsRgb: 0
NumberOfDataSeries: 0
NumberOfDataSeriesRgb: 0
NumberOfMessages: 0
NumberOfRayData: 0

Thus, to get your Simulated Image to Python (based on your tags I assume you use Python), you have to specify a filepath in analysisSettings.OutputFile, which you can then also use to read the same file in in Python. 

 

Also note that you don't have to work with a configuration file for this analysis anymore if you are using the ZOS-API. While the results are not exposed in the API, all settings are. So rather than

analysisSettings.ModifySettings(cfg, 'ISM_INPUTFILE', "Text_100p_3x3_2_g1196x1279_dist.png")
analysisSettings.ModifySettings(cfg, 'ISM_FIELDHEIGHT', '15')
analysisSettings.ModifySettings(cfg, 'ISM_FLIPIMAGE', '3')
analysisSettings.ModifySettings(cfg, 'ISM_OUTPUTFILE', 'Test1.png')

You could do

analysisSettings.InputFile = "Text_100p_3x3_2_g1196x1279_dist.png"
analysisSettings.FieldHeight = 15

etc.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings