Generating a list of output data types for each analysis in the ZOS-API

This article is part of the Getting Started with ZOS-API free tutorial.

This article explains how to use Python and MATLAB to generate a list of available data types (IAR types) for each analysis in the ZOS-API.
 

Authored By Michael Cheng

Downloads

Article Attachments

Introduction

When using the ZOS-API to access OpticStudio, it’s common to run analyses like Spot Diagram, the Modulation Transfer Function (MTF), or the Point Spread Function (PSF). Different analyses provide different types of data. The ZOS-API supports the following data types:

 

Analyses Results data types (IAR)

 

Typically, an analysis returns only one or two kinds of data types. For example, results from a Fast Fourier Transform (FFT) MTF analysis are returned in a DataSeries. A request for DataGrid from analysis FFT MTF results in empty or null data. Not all analyses windows have populated results. Although each analysis has an associated data type, test the corresponding data type to ensure it includes data. For analyses that do not have data, use the brute force GetTextFile to save the data to disk and then manually parse the data.
 
A table makes it easy to see the data types that are available for an analysis. The following two examples show how to generate a table using Python and MATLAB. The source code for both tables is provided in the "Sample File" section of this article.

 

Python Example

The following section is when using Python.NET. A script is available in the attachments for Python using COM.

After the boilerplate code is generated from OpticStudio, start from the line “# Insert Code here” The following code snippet is the first block of code. By default, this code tests sequential analyses. To generate a table for non-sequential analyses, uncomment the second line of code.

# Insert Code here

TheSystem = zosapi.TheSystem

# Uncomment following line for non-sequential analyses

# TheSystem.MakeNonSequential()

TheAnalyses = TheSystem.Analyses

analIDM = ZOSAPI.Analysis.AnalysisIDM;

 

The next line prints the data type names.

print('Name\tSetting\tDatGrid\tDatGridRgb\tDatSrs\tDatSrsRgb\t' + 'DatScat\tDatScatRgb\tRayData\tCriRayDat\tPathAnal\tSpotDat')

 

The list analIDM includes all the analyses. The following line will count the number of analyses:

number_of_enum = Enum.GetNames(analIDM).Length-1

 

In the next code snippet, a for-loop is used to open all the available analyses using “TheAnalyses.New_Analysis(k).”

If the analysis is a None type, an error message is printed. To get information about these analyses, the codes should change the system to corresponding mode (sequential or non-sequential) as described above.
 
If the analysis is a valid type (not a None type), the following code snippet tests and reports the availability of each data type.

for idx in range(number_of_enum):   

a = TheAnalyses.New_Analysis(Enum.Parse(analIDM, Enum.GetName(analIDM,idx)));    

if a is None :        

print('This analysis cannot be opened in ',               

'Sequential Mode' if TheSystem.Mode == 0 else 'Non-Sequential Mode',               

': enumID ',k)        

continue

    ar = a.GetResults()

    print(a.GetAnalysisName, '\t',

           a.HasAnalysisSpecificSettings, '\t',

           ar.DataGrids is not None and ar.NumberOfDataGrids > 0, '\t',

           ar.DataGridsRgb is not None and ar.NumberOfDataGridsRgb > 0, '\t',

           ar.DataSeries is not None and ar.NumberOfDataSeries > 0, '\t',

           ar.DataSeriesRgb is not None and ar.NumberOfDataSeriesRgb > 0, '\t',

           ar.DataScatterPoints is not None and ar.NumberOfDataScatterPoints > 0, '\t',

           ar.DataScatterPointsRgb is not None and ar.NumberOfDataScatterPoints > 0, '\t',

           ar.RayData is not None, '\t',

           ar.CriticalRayData is not None, '\t',

           ar.PathAnalysisData is not None, '\t',

           ar.SpotData is not None)    

a.Close()

 

The result looks like this:

 

Availability of each data type

 

Different values are separated by tabs, so you can easily copy and paste the data into a Microsoft Excel spreadsheet.

 

Excel spreadsheet

MATLAB Example


First, generate the boilerplate code in OpticStudio, and then add the custom code after the line “% Add your custom code here...”. The following code snippet is the first block of code. By default, this code tests sequential analyses. To generate a table for non-sequential analyses, uncomment “TheSystem.MakeNonSequential()” line.

% Add your custom code here...

% Uncomment following line for non-sequential analyses

% TheSystem.MakeNonSequential()

TheAnalyses = TheSystem.Analyses;

 

In next block of code, the code snippet saves the analysis enumerations ZOSAPI.Analysis.AnalysisIDM in the variable analIDM, and then gets the value by using “System.Enum.GetValues(analIDM.GetType).”

analIDM = ZOSAPI.Analysis.AnalysisIDM; analValue = System.Enum.GetValues(analIDM.GetType);

 

The next line prints the data type names. The LogicStr is defined for printing the Boolean values in an output that’s easier to read. In MATLAB, if you print a Boolean value, by default, the output will be “0” for Boolean-false and “1” for Boolean-true. By predefining a LogicStr, we can print “true” for Boolean-true and “false” for Boolean-false.

print('Name\tSetting\tDatGrid\tDatGridRgb\tDatSrs\tDatSrsRgb\t' + 'DatScat\tDatScatRgb\tRayData\tCriRayDat\tPathAnal\tSpotDat')

 

The list analIDM includes all the analyses. In the next block, a for-loop opens all the available analyses using “TheAnalyses.New_Analysis(analValue(idx))”.  If the returned analysis object is not empty, the code snippet tests and reports the availability of each data type. If the returned analysis object is empty, the code prints an error message. To get information about these analyses, the code snippet changes the system to the corresponding mode (sequential or non-sequential).

for idx = 1:analValue.Length    

a = TheAnalyses.New_Analysis(analValue(idx));    

if not(isempty(a))

        ar = a.GetResults();

        fprintf('%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n',...

            char(a.GetAnalysisName),...

            LogicalStr{(a.HasAnalysisSpecificSettings > 0) + 1},...

            LogicalStr{(ar.NumberOfDataGrids > 0) + 1},...

            LogicalStr{(ar.NumberOfDataGridsRgb > 0) + 1},...

            LogicalStr{(ar.NumberOfDataSeries > 0) + 1},...

            LogicalStr{(ar.NumberOfDataSeriesRgb > 0) + 1},...

            LogicalStr{(ar.NumberOfDataScatterPoints > 0) + 1},...

            LogicalStr{(ar.NumberOfDataScatterPointsRgb > 0) + 1},...

            LogicalStr{(ar.NumberOfRayData > 0) + 1},...

            LogicalStr{(~isempty(ar.CriticalRayData)) + 1},...

            LogicalStr{(~isempty(ar.PathAnalysisData)) + 1},...

            LogicalStr{(~isempty(ar.SpotData)) + 1});

        a.Close()

    else

        fprintf('This analysis cannot be opened in %s. Mode. enumID: %s\n', char(TheSystem.Mode), char(analValue(idx)));

    end

end

 

The result appears like this:

 

Matlab data availability

The different values are separated by tabs, so that you can copy and paste them into an Excel spreadsheet. Here is an example:

 

Matlab to Excel Spreadsheet

For more information about accessing data for analyses that do not have values in the data type, refer to the GetTextFile() method in the ZOS-API Syntax Help.

KA-01650

Was this article helpful?
3 out of 9 found this helpful

Comments

0 comments

Article is closed for comments.