Skip to main content

I´ve a simple simulation with a diode source followed by a gaussian diffuser and then a polar or rectangle detectors. I would like to see how the gaussian diffuser parameters (e.g. sigma parameter) affect the angular parameters of the output field.

I´m having difficulties extracting the data both from the polar and rectangle detectors when using the ZOS-API. 

For the rectangle detector i´ve used the following sample code adapted from the Zemax repository:

DetObj = 12obj = TheSystem.NCE.GetObjectAt(DetObj);numXPixels = obj.ObjectData.NumberXPixels;numYPixels = obj.ObjectData.NumberYPixels;pltWidth   = 2 * obj.ObjectData.XHalfWidth;pltHeight  = 2 * obj.ObjectData.YHalfWidth;pix = 0# Get detector datadetectorData = ta0 for x in range(numYPixels)] for x in range(numXPixels)]for x in range(0,numYPixels,1):    for y in range(0,numXPixels,1):        ret, pixel_val = TheNCE.GetDetectorData(DetObj, pix, 1, 0)        pix += 1        if ret == 1:            detectorDatary]tx] = pixel_val        else:            detectorDatarx]ty] = -1

However Python returns “AttributeError: 'IObject' object has no attribute 'NumberXPixels"”. I have checked that

obj.ObjectData is a IO Object, ZemaxUI.ZOSAPI.Editors.ZOSAPI_DetectorRectangleObject, so I am picking the correct object, but I cannot find any of the following parameters (NumberXPixels, NumberYPixels, ,XHalfWidth, YHalfWidth). I´m faced with a similar problem when retrieving data from the PolarDetector.

 

Hi @Jonasz,

 

Your code runs with Pythonnet 2.5.2 but not 3.0.1 on my machine. I believe it is related to this:

However, I don’t understand how to cast a Detector Object like demonstrated in the above topic. Perhaps @MichaelH can help? In the meantime, if you use Pythonnet 2.5.2 it should work.

@jwbeenakker, @Luc.van Vught  do you have something to work around that as well in ZOSPy, I didn’t find it?

Take care,

 

David


Hi all, the following code works on my machine with Pythonnet 3.0.1:

numXPixels = obj.get_ObjectData().__implementation__.NumberXPixels

Instead of accessing the attribute “ObjectData” directly, the getter method is called. Similar to the “GetSettings()” issue with analyses, the ObjectData is then casted to the correct class using “__implementation__” (as described by MichaelH in the topic mentioned by David).


As indicated by David Nguyen, downgrading the pythonnet version to 2.5.2 made the sample code functional!

I haven´t tried the suggestion by Benjamin N.

 

Thank you for your time!

 


@David.NguyenThis is not yet available in ZOSPy, but it would indeed be a nice feature. We can add it ourselves, but if there is anyone from the community willing to contribute it, this would be a nice opportunity to get involved with the development of ZOSPy! It can be added as a new function in zospy.functions.nce .

If you are willing to contribute this function, please drop a message here and we’re looking forward to your contribution.


Hi @chaasjes,

 

I’ll try to implement the solution by @Benjamin.N in ZOSPy. I think it should rather be in

zospy.functions.nce

as it is a Detector Object property. Wouldn’t you agree?

Take care,

 

David


You're right, I didn't pay much attention when writing that post. I updated it to mention the correct module.


Reply