I would like to access, through ZOSAPI, detector data which has been fitered by a filter string. I know how to access detector data through ZOSPI. And it is of course possible to view filtered data in OpticStudio by saving a trace to a ZRD file and specifiying that as the database for a detector viewer. The filter string can be applied as the ZRD is saved, or applied in the settings of the detector viewer.
But I would ike to access the filtered data as it is viewed in the detector viewer, rather than the unfiltered data. Is this possible?
I am actually using ZOSAPI from Mathematica, but an answer related to Python or C++ would be useful.
Kind regards,
David,
Page 1 / 1
I have solved this. I use Mathematica to drive ZOSAPI. The method I used is:
1) Instantiate a ray trace that saves all rays to a ZRD file.
2) Instantiate a detector viewer that specifies the same ZRD file name and also has a filter string.
3) Run a trace.
4) Use GetResults followed by GetDataGrid to obtain the data from the viewer, not the detector.
Here the obscuration is actually generated by a not-hit ( !H ) filter string. The plot was made in Mathematica.
Hi David,
Thanks for your posts here, and for sharing your solution!
Allow me to refer here to a couple of related forum posts from our colleague Allie. She presents multiple methods for pulling detector data from the API, and she also provides Matlab code for her solutions, please find them below:
For more information about how to use ZRD files and apply filter strings specifically, please check out the sample code of Example 10 - NSC ZRD Filter String:
Best,
Csilla
Hi,
I am trying to follow the instructions listed above and apply a filter string to a detector viewer and then try to read out the data from this. Somehow if i convert these pixel values back to the total power i get the total power obtained without a filter string but sadly can’t find my mistake.
The Python code is as follows :
DetectorView = TheSystem.Analyses.New_DetectorViewer() DetectorView_Settings = DetectorView.GetSettings() DetectorView_Settings.Filter = "X_WAVESHIFT(1,2)" # Detector will only display wavelength shifted rays DetectorView_Settings.RayDatabaseFilename = "hi.ZRD" #The rays of the ray trace are saved as hi.ZRD DetectorView_Settings.ShowAs = ZOSAPI.Analysis.DetectorViewerShowAsTypes.FalseColor DetectorView.ApplyAndWaitForCompletion() # Apply Settings to Detector Viewer
a = DetectorView.GetResults() b = a.GetDataGrid(0).Values npData = zos.reshape(b, b.GetLength(0), b.GetLength(1)) #convert this data (All pixels have unit W/cm^2) into Watts TheNCE = TheSystem.NCE dims_bool_return, X_detectorDims, Y_detectorDims = TheNCE.GetDetectorDimensions(DetObj, 0, 0) # get pixel number in x and y direction Psx = TheNCE.GetObjectAt(DetObj).GetObjectCell(ZOSAPI.Editors.NCE.ObjectColumn.Par1).DoubleValue*2/ X_detectorDims #Pixel size = detector size/number of pixels Psy = TheNCE.GetObjectAt(DetObj).GetObjectCell(ZOSAPI.Editors.NCE.ObjectColumn.Par2).DoubleValue*0.2/ Y_detectorDims Power = np.sum(npData) * Psx * Psy print('filtered power = ' + str(Power)) #Gives out the total power of the unfiltered data
Do you have any idea what i am doing wrong?
Kind regards,
Michelle
Hi David,
Thanks for your posts here, and for sharing your solution!
Allow me to refer here to a couple of related forum posts from our colleague Allie. She presents multiple methods for pulling detector data from the API, and she also provides Matlab code for her solutions, please find them below:
For more information about how to use ZRD files and apply filter strings specifically, please check out the sample code of Example 10 - NSC ZRD Filter String:
Best,
Csilla
I don’t understand how the example from the API doc show how to use the Dectector viewer, since the code
And once the ApplyAndWaitForCompletion() is executed, no reference to the viewer is done -in other words, I don’t undestrtand what is the output created by lines e10s03…?