Skip to main content

Hi,



I try to retrieve the output POP field distrubution via python. I looked in the help at IAS_PhysicalOpticsPropagation and couldn't find direct way to do it. I know I can manually save ZBF files and then load, but I need a script as I change parameters and want to retrieve the output beam. How would you advise to do so?



 



Thanks,



Leonid

Hello Leonid,

 

I hope it's OK I only have MATLAB example.
 
Assuming you already have "TheSystem", you can open a POP window as shown below.

TheAnalyses = TheSystem.Analyses;
POP = TheAnalyses.New_Analysis(ZOSAPI.Analysis.AnalysisIDM.PhysicalOpticsPropagation);

 
And you can set it up as below. Please especially check I have set up the DataType to EXIrradiance.

POP_set = POP.GetSettings();
POP_set.DataType = ZOSAPI.Analysis.PhysicalOptics.POPDataTypes.EXIrradiance;
POP_set.EndSurface.SetSurfaceNumber(2);

 
Then you can run and get intensity array. Note "Ex2" below is the square of amplitude, not amplitude. You need to take a square root to get it.

POP.ApplyAndWaitForCompletion();
POP_result = POP.GetResults();
Ex2 = double(POP_result.DataGrids(1).Values);

 
To get the phase, you then need to change the DataType to EXPhase and run the analysis again. In below, I save the result in variable "ExP".

POP_set.DataType = ZOSAPI.Analysis.PhysicalOptics.POPDataTypes.EXPhase;
POP.ApplyAndWaitForCompletion();
POP_result = POP.GetResults();
ExP = double(POP_result.DataGrids(1).Values);

 
 
Just FYI, in case you want to find an already opened POP window in your system, you can follow the method below. Note the ZMX file only includes your system settings. If there is any POP or other analysis window, they are saved in ZDA file. So, before you try to find any POP window in the opened file, make sure there is a ZDA file that includes at least one POP window.
 
To get the POP analysis in the code, you need to know the analysis index of the POP window. You can use OpticStudio to open it  and check as below.
?name=image.png
 
 
Then you can get the analysis using the method 

POP = TheAnalyses.Get_AnalysisAtIndex(index);

where the variable index is an integer representing the analysis index.
 
 
In case you don't know which analysis is the POP window and you want to detect it in the code, you will need to loop through all analysis and check their analysis type.
Here is a snippet to do so for your reference.


for i = 1:TheAnalyses.NumberOfAnalyses
if TheAnalyses.Get_AnalysisAtIndex(i).AnalysisType == ZOSAPI.Analysis.AnalysisIDM.PhysicalOpticsPropagation
fprintf("%s\n","This is a POP window");
else
fprintf("%s\n","This is not a POP window");
end
end

 
Please let me know if you have any further questions.
Thank you.
 


Hi Michael,

Just picking up on Leonid’s original question - is it not possible to run POP and specify an OUTPUTBEAMFILE name as one would in OpticStudio?

Also, my understanding is that MODIFYSETTINGS can be used with the set of parameters outlined in the Zemax manual (e.g. p. 768 in the pdf manual). But that set of parameters is not a complete set. Should we be able to set any parameter for, say, POP, directly without needing to use MODIFYSETTINGS?

Lastly, when accessing the data (ExIrradiance) as you describe above. I can get the data, but it does not look the same as when I run the case on POP in OpticStudio. I know I need to provide code and screenshots for what I’m talking about - I may do that in a separate help ticket.

 

Thanks,

Mark Wilder


Reply