Solved

Compile global optimization output files


Userlevel 3
Badge

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

11 replies

Userlevel 7
Badge +3

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

Userlevel 6
Badge +4

Add my vote please. 

Userlevel 6
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 3
Badge

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 3
Badge

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!

Userlevel 5
Badge +2

Hello @John.Hygelund ,

Regarding the settings in the config file, I think there might be a confusion with the Project Directory option here. Are you using the Project Directory? If so, i.e. the checkbox is ticked under the System Explorer > Files tab, then the L3D.cfg file will be saved to the local Configs folder inside your local working directory. However, on the other side, the ZPL macro code OPENANALYSISWINDOW "L3d", "L3D.CFG" will look for the config file in your general \Documents\Zemax\Configs folder. Perhaps you have another config file saved there as well, but with different settings. In order to make sure the correct L3D.cfg config file is used, you may include the full path of the file you would like to use in the macro.

For further references about the Project Directory, please take a look at this article:
Using Project Directories to organize OpticStudio files – Knowledgebase (zemax.com)

Best,
Csilla

Userlevel 3
Badge

Hello @Csilla Timar-Fulep ,

Thank you for the continued help. I was able to correct my issue. I needed to add ‘\configs’ to line 63

cfg$ = $DATAPATH() + "\Configs\L3D.CFG"

Userlevel 3
Badge

Pretty cool to output plots and pictures like this!

Thanks again @MichaelH  and @Csilla Timar-Fulep 

 

Userlevel 7
Badge +3

I know I’m about a year late to this discussion, but the Report Graphics feature was added so you could combine 4 or 6 graphics in a single report. Your macro that steps through all the files in a folder could call this single Report to output a lot of data in one go. It’s how we made the graphics for the Zebase manual.

You could also create a merit function that gets spot size, MTF, wavefront error etc. Your macro would load the file, then load the .MF file and write out the data.

  • Mark

Reply