Solved

Use ZPL to read out the detector pixles

  • 8 July 2021
  • 4 replies
  • 549 views

I'm having trouble to read detector pixels using a ZPL.


The syntax should be NSCDetectorData,surface,object,pixel,data


However, I get error message and do not know how to solve.


Can somebody provide me with a example of a piece of ZPL code to get the job done.


Ideally reading the detector into a 2D array


But I'm already happy with a single statement reading out say the 6th pixel iof the 5th row


Hope somebody can help me


Pascal 

icon

Best answer by David.Nguyen 12 July 2021, 12:08

View original

4 replies

Userlevel 7
Badge +2

Hi Pascal,


This was more complicated than I thought, but this should help you.


The macro I used is the following:



# Clear all detectors
clear = NSDD(0, 0, 0, 0)
# Number of the non-sequential surface (1 = purely non-sequential system)
surface = 1
# Sources to trace (0 = all)
source = 0
# Raytrace parameters
split_rays = 0
scatter_rays = 0
use_polar = 0
ignore_errors = 1
# Random seed (0 = random number)
random_seed = 0
# Run a raytrace (without saving to a file)
NSTR surface, source, split_rays, scatter_rays, use_polar, ignore_errors, random_seed
# Specify detector to read from
detector = 10
# Data to read (1 = flux/area)
data = 1
# Read all pixels individually
pixel_value1 = NSDD(surface, detector, 1, data)
pixel_value2 = NSDD(surface, detector, 2, data)
pixel_value3 = NSDD(surface, detector, 3, data)
pixel_value4 = NSDD(surface, detector, 4, data)
pixel_value5 = NSDD(surface, detector, 5, data)
pixel_value6 = NSDD(surface, detector, 6, data)
pixel_value7 = NSDD(surface, detector, 7, data)
pixel_value8 = NSDD(surface, detector, 8, data)
pixel_value9 = NSDD(surface, detector, 9, data)
# Print pixels value
FORMAT 1.15
PRINT 'Pixel 1 = ', pixel_value1
PRINT 'Pixel 2 = ', pixel_value2
PRINT 'Pixel 3 = ', pixel_value3
PRINT 'Pixel 4 = ', pixel_value4
PRINT 'Pixel 5 = ', pixel_value5
PRINT 'Pixel 6 = ', pixel_value6
PRINT 'Pixel 7 = ', pixel_value7
PRINT 'Pixel 8 = ', pixel_value8
PRINT 'Pixel 9 = ', pixel_value9

Hopefully, it is self explanatory except for the pixel numbering part. The pixel numbering is what got me confused at first, but here is what I obtained (you can also download my file, which has the macro in it, and check for yourself):



As you can see, pixel 1 is the bottom left corner, and pixel 2 is the next one to the right, etc.


Let me know if that makes sense. I let you do the math for the 6th pixel of the 5th row, which is different depending on the origin. Note that the indexing starts at 1. You probably need something like 5 times the row length + 6 or similar.


At this point, I would strongly suggest to look into the ZOS-API, particularly if you are doing any sort of post-processing with Python or MATLAB, or even C++/C#.


I hope this helps.


Take care,


David

Hi David,


Great! This helps and is super! I understand it and tested it. A good step forwards for me.


You mention Python, MATLAB or C++/C#. I'm unfortunately not familiar with these languages and the learning curve is too long for me. 


I am though familiar with VB excel and I think I have understood that it sould be possible to read, write and give a command to trace to Optics Studio but I have no clue how to do that. I have not seen any examples. If these exist I would be interested!


At the moment I will work with the more primitive ZPL. Also there I need some learning to do.


Thank you again for your great help!


Pascal

Userlevel 7
Badge +2

Hi Pascal,


I'm glad I could help. Feel free to mark my reply as the answer to your question (there should be a button on the top-right) as it can also help others.


I completely understand the issue with the learning curve. It does require some effort to get started. To be fair, you can do most of the things with ZPL, it's just sometimes less convenient.


I have heard of people using the ZOS-API with VB, but never seen it myself. I have found this other post though, maybe that can help.


Let us know in the forum if you have other quesitons about ZPL, and the community will try to help :)


Take care,


David

Thank you David

Reply