Solved

Compile global optimization output files

  • 15 June 2022
  • 7 replies
  • 87 views

Userlevel 2

Does anyone have (preferably Matlab) code that cycles through global optimization output files and compiles custom outputs? For example, I’d like to save out 2d layout images for each file as a quick way to identify interesting design forms rather individually opening each file.

icon

Best answer by MichaelH 17 June 2022, 19:56

View original

7 replies

Userlevel 6
Badge +2

+1 for me.  It would really be nice if such a tool were included within OpticStudio.

Userlevel 5
Badge +3

Add my vote please. 

Userlevel 3
Badge +2

Hi John,

I don’t have Matlab code, but I do have a ZPL script which will cycle through all *.zmx files in a selected directory, save the 3D Layout and extract some basic information about the lenses (saved in an XML format).  The only things to make sure before running the code is:

  • Your files are either sequential or mixed mode (it doesn’t work with non-sequential files...I don’t know if it will skip the files or if it will crash since I haven’t tested with NSQ files)
  • You have your L3D.cfg file saved from your 3D Layout window.  You can make sure you have your ray pattern, fields, wavelengths, etc setup as well so the saved layouts will be what you’re expecting.

The outputs are in an XML format which you can use to input into other programs for more analysis.  The data generated includes basic inputs like min/max fields, min/max/primary wavelengths, EPDI, ENPP, EXPD, EXPP, EFFL, WFNO, TOTR, number of surfaces, 3rd order wavefront coefficients, geometric/rms spot size, geometric/rms wavefront error, and Hy=[0, 0.707, 1] for 30lp/mm & 50lp/mm MTF.

To make the XML file more useful, you can use Excel to import the XML file and make it more into a 2D table format.

 

Ideally, the Design Templates would be updated to allow for a user to generate the images/data from custom locations, but I don’t think this is on the roadmap.

Userlevel 5
Badge +2

Hi All,

For further references for ZPL macro solutions, besides Michael’s one here, please take a look at this knowledgebase article:
How to open consecutively-named lens files using a ZPL macro – Knowledgebase (zemax.com)
This article discusses in detail how to loop through consecutively named files, which can be useful for analyzing the results of Global Optimization, as well as Monte Carlo tolerancing.

Best,
Csilla

Userlevel 2

Hello @MichaelH ,

This is a very helpful and impressive zpl script. Thank you!

From the 3D Layout settings, clicking ‘Save’ generates a <current file>.CFG file. I renamed this to ‘LD3.cfg’. Is this the correct procedure?

The output .jpg images show the frame, but have no rays or lenses.

I tried \Samples\Sequential\Objectives and my global optimization output directory. For my directory, I changed the format filter from .zmx to .ZOS. Both output what looks to be a correct xml file and the blank jpg images.

If I open an example file and ‘load’ in the 3d layout, I see the design as expected.

Any thoughts on trouble shooting this?

Thank you again! 

Userlevel 5
Badge +2

Hi @John.Hygelund,

Regarding your question about the config files, there are two different config files generated when saving the settings for an analysis window. First, there is an analysis specific config file which has a 3-letter-code name specific to the analysis window, that is L3D.CFG for the 3D Viewer specifically. Then second, there is a file specific config file with the name of  <current file>.CFG. The file specific config file will always appear in the same folder as the lens file you're working in, while the analysis specific config file will appear in the general {Zemax}\Configs folder if you are not using the Project Directory option, and it will appear in your local Configs folder inside the project folder if you are using the Project Directory. You should not rename the file specific config file, instead you should search for the analysis specific one.

As for the blank images, I think the problem might be that maybe you are using the Show Options First setting under the Project Preferences > Graphics tab:
 

If the Show Options First checkbox is checked, then the macro will open a new 3D Viewer, however it will not run the analysis unless you click OK, so only a blank image will be generated, like the one below:

I hope this helps to resolve your problem.

Best,
Csilla

Userlevel 2

Hello @Csilla Timar-Fulep ,

Thank you for your help pointing me to the correct location for the LD3.cfg file. You were correct that my ‘Show Options First’ check box was preventing the layout from rendering.

While everything is working, my saved 3d layout previews aren’t following my saved preferences. For example, I have the frame suppressed and lens edges hidden when I save the LD3 file, but these settings aren’t applied to the saved images. While I’ve copied the LED.CFG file into the directory, it seems like it may not be adopting the settings…

Any other thoughts would be appreciated!

Reply