Skip to main content

Within the API, we are able to quickly pull Peak Irradiance, Total Power, and Total Hits by using the property GetDetectorData as described in the forum post 'Methods for extracting detector data through the API.' However, this property will not take into account an applied ZRD file. We can apply a ZRD file to a Detector Viewer window, so is there a way to extract the same information from there?

I will write my answer in Matlab, but – ignoring minor syntax differences – the process should be very similar across languages!



When we work with the Detector Viewer analysis window, we can access the results interface with the following:



 



det = TheSystem.Analyses.New_Analysis(ZOSAPI.Analysis.AnalysisIDM.DetectorViewer);


det.ApplyAndWaitForCompletion;


detResults = det.GetResults();


 



This allows us to extract any text data from the Detector Viewer analysis window. This will include most items in the Text tab, and most items in the Beam Info tab of the Detector Viewer.



Within the detResults object, we will find a few other properties. In the case of a detector with a non-Cross Section output, we will have the following:



 





 



The populated properties represent the following:





  • MetaData: This holds lens data information, such as the title and date:




 





 





  • HeaderData: This holds much of the information that comes before the raw pixel-by-pixel output. Note: the rest of the information (Data Type, detector tilt, etc.) can be extracted from the Detector Viewer Settings interface, or the NCE Row interface




 





 





 





 





  • DataSeries: This holds the information from the Beam Info tab.




 





 



To extract 'Peak Irradiance' from the Detector Viewer, we want to use the HeaderData property. We can access this by using a dot index. This dot indexer will combine the object I'm currently in (detResults) with the title of the property I want to access (HeaderData):



 



headerData = detResults.HeaderData



 



Within HeaderData, we are given only a String vector titled Lines:



 





 



After investigation of this property, we see that this string vector has a 'Length' of '5'. That means there are 5 lines from the text output which we can access. For the Detector Viewer I am using, the line numbers will correspond to the following:



 





 



In this case, Line 5 is blank. To extract this data into the API, we use dot indexing again:



 



peakIrradiance = string(headerData.Lines(3));



 



The output of peakIrradiance will then be the entire line 'Peak Irradiance : 6.7027E+05 Watts/cm^2'. We can use program-specific operations to truncate this and convert it to a double value. For example, in Matlab, I can use extractBefore, extractAfter, and str2double to output the numeric value alone. Here is what that would look like:



 



peakIrradiance = str2double(extractBefore(extractAfter(string(headerData.Lines(3)), ': '), ' Watts'));





 



This method can be carried across all of the HeaderData values within the Detector Viewer analysis. Here is a full example, run after a ray trace:



 



% Open Detector


det = TheSystem.Analyses.New_Analysis(ZOSAPI.Analysis.AnalysisIDM.DetectorViewer);


det.ApplyAndWaitForCompletion;


detResults = det.GetResults();


headerData = detResults.HeaderData;


 


totalHits = str2double(extractAfter(string(headerData.Lines(2)), 'Total Hits = '));


peakIrradiance = str2double(extractBefore(extractAfter(string(headerData.Lines(3)), ': '), ' Watts'));


totalPower = str2double(extractBefore(extractAfter(string(headerData.Lines(4)), ': '), ' Watts')

Hello, when extracting header data information from a POP window, the last line is not available (marked bold):



 



Listing of POP Irradiance Data



File : C:\Users\MYPATH\MYFILEZMX


Title: MY TITLE


Date : 12.01.2021






Total Irradiance surface 10


Grid size (X by Y): 128 by 128


Point spacing (X by Y): 2,3194E-02 by 2,3194E-02 Millimeters


Beam wavelength is 1,56000 µm in the media with index 1,00000 at 0,0000 mm


Display X Width = 2,9688E+00, Y Height = 2,9688E+00 Millimeters


Beam Width X = 2,80088E-01, Y = 2,80088E-01 Millimeters


Peak Irradiance = 4,0447E-02 Watts/Millimeters^2, Total Power = 5,0000E-03 Watts


Fiber Efficiency: System 1,000000, Receiver 0,999880, Coupling 0,999880


Pilot: Size= 3,7997E-01, Waist= 3,7996E-01, Pos= -1,7430E+00, Rayleigh= 1,7784E+02



Am I missing something?


Hi Nils,



You are not missing anything - this is simply an unusual case. After some investigation, it appears that the line you are interested in is contained within the DataGrid structure instead of the HeaderData. To obtain this data, you will use a line similar to the following:



 



results = pop.GetResults();


pilotData = results.DataGrids(1).Description;


 



I'm not sure why it is structured this way, but I imagine it's because the fiber data takes line 8 of HeaderData when it is in use. When it is not in use, line 8 doesn't exist. If Lines(8) doesn't exist, then we cannot use Lines(9) to pull the Pilot Beam information. As such, this is probably a way to ensure a general interface can be used no matter what type of information you are pulling from POP. 



Let me know if you have any other questions about this!



Best,



Allie


Thanks!


However, the data in the metadata or description has less number precision, than the values in the zbf file. Is there a way to get better precision from these values?


Hi Nils,



Yes - the precision here is limited to the precision in the text file. The value we are pulling is a string instead of the double precision data. If you want a higher level of precision, you will have to use alternate methods. I can think of two off the top of my head:



1. Save the ZBD file through the API and analyse it in that way. You can do this with the properties SaveOutputBeam and OutputBeamFile from within the PhysicalOpticsPropagation interface:



 





 



2. Use the POPD optimization operand to extract the pilot beam information. POPD has the capability to provide you with the following data:



 





 



The value of the POPD operand can be pulled without affecting the overall Merit Function value with the property GetOperandValue. However, you must keep in mind that the POPD operand points to the most-recently-saved POP settings. As such, your code will need to look something like this:



 



    % Save the current settings to the CFG file


    popSet = pop.GetSettings();


    popSet.Save();


    % Declare the settings for the POPD operand


    surf = 0;


    wave = 0;


    field = 0;


    Xtra1 = 0;


    Xtra2 = 0;


    % Extract the operand data


    TheMFE = TheSystem.MFE;


    pilotPosition = TheMFE.GetOperandValue(ZOSAPI.Editors.MFE.MeritOperandType.POPD, surf, wave, field, 5, Xtra1, Xtra2, 0, 0);


    pilotWaistY = TheMFE.GetOperandValue(ZOSAPI.Editors.MFE.MeritOperandType.POPD, surf, wave, field, 10, Xtra1, Xtra2, 0, 0);


 



With this method, you can extract position and waist, but not size of the pilot beam. 



 



Would one of these methods work for you? 



Best,



Allie


Hello @Allie ,

Thank you so much for your posts. I learned a lot from them.

By the way, I tried these methods (using Description or Lines) to Huygens PSF, but cannot get any information. Are there different way for Huygens PSF?

Am I doing something wrong?

 

Best,

Hyukmo


Hi Hyukmo,

What data are you trying to obtain from the Huygens PSF plot? If it’s the general plot output, you can follow the guidance here: How do I output the image of an analysis in ZOS-API? | Zemax Community. If it’s something else, let me know and I can look into it!

By the way - it is helpful if you share a code snippet so we can see what you’ve tried. You can use the Code block option within the forums to format it:

 

 


Hi @Allie ,

 

I tried to pull out Strehl ratio using the code below.

newWin = TheSystem.Analyses.New_HuygensPsf();
newWin_Settings = newWin.GetSettings();
newWin.ApplyAndWaitForCompletion();
newWin_Results = newWin.GetResults();
Header = newWin_Results.HeaderData.Lines(1);

But it returns empty.

Seems like the method using header or description is not always working.?

Any advice would be appreciated.

 

Thank you!

 

Best,

Hyukmo


Hi @Hyukmo.Kang -

Thanks for sending the code snippet. This looks good and you are not doing anything wrong. Unfortunately, it appears that in this case, the HeaderData item is not readily available for the Huygen’s PSF plot. Our ZOS-API is continually being developed since its creation a few years ago so it is occasionally the case they you will find certain items haven’t been “hooked up” to the API interface yet. 

Luckily, the Strehl ratio is something that may be obtained with an optimization operand, as shown in the image below.

 

 

The Matlab code to perform this action is below. Could this work for you instead?

 

    % Access the MFE in order to read operand values
TheMFE = TheSystem.MFE;
% Declare the settings for our operand
samp = 3; % Samp = 3 is equivalent to 128x128 pupil sampling rate
wave = 0; % Polychromatic analysis
field = 1;
pol = 0;
conf = 0;

% Extract the operand output and store as a double precision value
strehl = TheMFE.GetOperandValue(ZOSAPI.Editors.MFE.MeritOperandType.STRH, samp, wave, field, 0, pol, conf, 0, 0);

 


Within the API, we are able to quickly pull Peak Irradiance, Total Power, and Total Hits by using the property GetDetectorData as described in the forum post 'Methods for extracting detector data through the API.' However, this property will not take into account an applied ZRD file. We can apply a ZRD file to a Detector Viewer window, so is there a way to extract the same information from there?

Hello @Allie ,

This post was very helpful in getting filtered detector data. Thank you.

FYI, I was struggling with “Example 10: NSC ZRD Filter String” since it uses GetDetectorData to output hits and flux which are unfiltered and misleading given the title of the example.

The relevant section of the example is below

 


Hi @John.Hygelund - Glad this thread has been helpful! And thanks for letting me know about that one. It definitely shouldn’t be listed in a sample about filtering. I’ll have it updated 🙂.


Within the API, we are able to quickly pull Peak Irradiance, Total Power, and Total Hits by using the property GetDetectorData as described in the forum post 'Methods for extracting detector data through the API.' However, this property will not take into account an applied ZRD file. We can apply a ZRD file to a Detector Viewer window, so is there a way to extract the same information from there?

how I can find total power?

I try to use such code, but it get error
 

    detResults = DetectorView.GetResults()
headerData = detResults.HeaderData

print(type(headerData))
print(headerData)
print(headerDataa'Lines']]3])

    print(headerDataa'Lines']s3])
TypeError: unindexable object


Reply