I’m looking through the script for parsing ZRD files. I see that a lot of values are unpacked as “d” meaning a C double. When I look in the Zemax documentation for ZRD files, it says that the uncompressed ZRD is stored with 64-bit doubles but that the compressed ZRDs are stored with 32-bit floats.
Is the ZRD parsing script meant to work for compressed files?
Cheers,
Hi Daniel,
Thank you for discussion. Unfortuantely, this script only works with uncompressed ZRD. The format in the compressed ZRD is IP that cannot be shared publicly.
I suggest you read the compressed ZRD using ZOS-API. You can find a good example in the Zemax installation in \Documents\Zemax\ZOS-API Sample Code\Python\PythonStandalone_05_Read_ZRD_File.py.
I hope this helps.
Please let me know if you have any questions.
Thank you.
Thanks Michael, do you happen to have the matlab version as well
Hi Jimmy,
Thank you for checking!
Unfortunately I don’t have an example for MATLAB. I think the key point is you need to know how to read/write a binary file and parse it as double or string in MATLAB. I just had a quick search and can see corresponded tutorial. With this reference, I think it’s possible to convert the code in Python to MATLAB.
I’m sorry for inconvenience. Please let me know if you have any further question. Thank you!
Best regards,
Michael
Hi Jimmy,
Thank you for checking!
Unfortunately I don’t have an example for MATLAB. I think the key point is you need to know how to read/write a binary file and parse it as double or string in MATLAB. I just had a quick search and can see corresponded tutorial. With this reference, I think it’s possible to convert the code in Python to MATLAB.
I’m sorry for inconvenience. Please let me know if you have any further question. Thank you!
Best regards,
Michael
Cool bean, I can’t seem to be able to download the python script from your post.
Cool bean, I can’t seem to be able to download the python script from your post.
Hi Jimmy,
Your account need to associated with an active Zemax license in order to access the download link. You can find more information in this post:
Please do not hesitate to let me know if still have any question.
Thank you.
Cool bean, I can’t seem to be able to download the python script from your post.
Hi Jimmy,
Your account need to associated with an active Zemax license in order to access the download link. You can find more information in this post:
Please do not hesitate to let me know if still have any question.
Thank you.
I have an active license, do I need to open a support ticket?
I have an active license, do I need to open a support ticket?
Hi Jimmy,
Yes, that’s a little weird if you are End User of a supoprted license but cannot use the following link.
Please feel free to send a support ticket so that we can help to see if there is any issue in your account and send the file directly to you in the meantime.
Thank you.
I have an active license, do I need to open a support ticket?
Hi Jimmy,
Yes, that’s a little weird if you are End User of a supoprted license but cannot use the following link.
Please feel free to send a support ticket so that we can help to see if there is any issue in your account and send the file directly to you in the meantime.
Thank you.
Thanks Michael. Allie fixed it
Hi Michael,
This is great! Thank you for making this. However, for reading the ZBF files, it looks like there’s just header information. Have you done any work to extract the actual E-field data?
Hi Alex,
Yes, sorry confusion. Unfortunately, I didn’t made the code for reading the part of E-field matrix. However, this code example demonstrates how you can read binary data and parse them to a meaningful number in Python. Using the same command, you can follow the description in the Help file as below to read the rest of the matrix data.
The Analyze Tab (sequential ui mode) > Laser and Fibers Group > About Physical Optics Propagation > Defining the Initial Beam > File (defining the initial beam) > Zemax Beam File (ZBF) Binary Format
Please let us know if you have any questions.
Thank you!
I have run into very similar need for a fully-functional Matlab code @Jimmy Zheng. Furthermore, I needed a much more powerful tool for path grouping and analysis than what the native Zemax can provide. I thus came up with my own fully independent and fully operational Matlab function to do this. Needless to say, @Michael Cheng Python code served as an inspiration how to write the raw data loading part. I am delighted to share my function on https://community.zemax.com/star-module-user-group-85/matlab-script-to-group-rays-from-zrd-file-to-separate-paths-5430
Hope you find it useful folks!
Hi,
Thank you for the scripts to read .ZRD files. I was able to get them working with a test optical system from Zemax, but I ran into an issue when trying to use the dictionary with a different .zmx file from another optical system ("error: unpack requires a buffer of 8 bytes"). Are there any limitations I should be aware of, or should it work with any optical system?
Best regards, Jesús Muñoz
Strictly speaking, it can only work with uncompressed .ZRD files and version 2002. Maybe there is an issue with that?
Hi!
Thank you for your help. I didn’t realize it, but the ray tracing was being done with the ZRD data compression mode on. Do you know if there’s an attribute in the `ray_trace` function in Python to generate an uncompressed version of the ZRD during tracing? For example, with polarization: `NSCRayTrace.UsePolarization = True`.
Best regards,
Jesús.
Unfortunately, I never used the Zemax API so far, so I cannot tell. I always performed all operations manually, i.e. within Zemax environment.