I am a student in internship and I need to use ZPL to automate my system. I have a system with LED, which I am optimizing. After this optimization I have to measure the power received on the detector for different Z positions (34 positions).
I do not know how to make a list of my different Z positions, how to change the value of the Z position for my detector and how to retrieve the value of the power received on my detector.
Thank you in advance,
Best answer by David.NguyenView original
In ZPL, the Z Position of a non-sequential object can be modified with the SETNSCPOSITION keyword. Reading the power requires you to clear the detectors with the numeric function NSDD, run a raytrace with NSTR, and retrieve the power with NSDD again. You can create a loop to iterate through various Z Position with the keywords FOR, NEXT. I have made a dummy example for you (attached to this post).
The system is a divergent Source Ellipse followed by a Detector Rectangle.
The macro is as follow:
It outputs the following graph result:
With my comments and the Help File (F1), I hope you’ll be able to make sense of it. You don’t need to plot the data, but I thought I might as well show you.
Let me know if you have questions about the code and take care,
Thank you very much for your answer. Your explanation is very clear.
I have one more question. You assume that the distance between 2 points is regular, but in my case it is not.
My "Z" list is like : Z_position = [ 50 , 250 , 500 , 1000 , 1500 , 2000 , ... , 10000 , 11000 , 13000 , 15000 , ..., 40000].
I would like to know if it is possible to create such a list.
In case the list is completely irregular, I would create an array beforehand and retrieve the Z positions from that array, in the loop. Something like:
Which should return:
I leave it to you to adapte the previous code with this technique. Let me know if this answers your question.
Thank you so much for your help !
I tried to do something similar. I want to change the x position with ZPL, and I want to save the detector image data for each time x position is changed. How do i modified your code to save the all detector data?
You probably figured it out already, but for everyone’s refernce, to change the X Position, you can keep using SETNSCPOSITION. However, this time, you would use 1 as the third parameter (1: X Position, 2: Y Position, 3: Z Position, 4: X Tilt, 5: Y Tilt, 6 Z Tilt).
As for the detector image data, it really depends what you want to save. Since I’m not sure what you mean by
I will assume that you are referring to all the pixel values of your detector (basically, an image). There are two common ways to go about this.
The easiest way is perhaps to use the SAVEDETECTOR keyword:
SAVEDETECTOR 1, <your_detector_number>, <filename>
The first parameter is the surface number for hybrid systems, for pure non-sequential systems, just use 1. Then, the second parameter is your detector number, and finally, the last parameter is a file name with or without a path (without path means the file is saved where the lens file is). Please note the following from the Help File (F1):
Later, you can use the keyword LOADDETECTOR for display.
Alternatively, you can use the GETTEXTFILE keyword:
GETTEXTFILE <full_path>, DVR
In this case, you need to specify the full path to a text file. This keyword will not use a specific detector, instead it will use the default detector settings (if you want to modify the detector settings, have a look at this thread). The advantage of this technique is that you have the data in a text format that is easily parsed with MATLAB or Python for further analysis.
Hope this helps.
Thanks for the help. I am able to use GETTEXTFILE to save the detectors text file. But I only want to save the pixel values not the whole text file. How do I do that?
It depends what you want to do really.
If you want to stick with OpticStudio only. The NSDD operand can retrieve a single pixel value. Then, you should loop over the number of pixels to retrieve all the pixel values. But, I personnally don’t find this approach elegant.
The other solution I would rather opt for is to parse the saved text-file with Python/MATLAB. In this way, it is rather easy to remove the header of the text file, if that’s your problem, for example.
Can you let us know what you intend to do with those pixel values and I can try to come up with a more specific answer?