Skip to main content

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,

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:

 

 

Methods for extracting detector data through the API

 

 

How do I output the image of an analysis in ZOS-API?

 

 

How can I pull Peak Irradiance or Total Hits from the Detector Viewer analysis in the API?

 

 

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:

 

 

200928-102657-image.png

 

 

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


Reply