mjhoptics / ray-optics

geometric ray tracing for optical systems
BSD 3-Clause "New" or "Revised" License
263 stars 54 forks source link

Zemax import failed #107

Closed dinosauria123 closed 1 year ago

dinosauria123 commented 1 year ago

Hi,

I try to open zmx file extracted from zar file (unzar via zmxtools https://zmxtools.readthedocs.io/en/latest/), it was failed to open via rayoptics GUI .

Traceback (most recent call last): File "/home/dino/.local/lib/python3.10/site-packages/rayoptics/qtgui/rayopticsapp.py", line 240, in do_file_action self.file_action(q.text()) File "/home/dino/.local/lib/python3.10/site-packages/rayoptics/qtgui/rayopticsapp.py", line 268, in file_action self.open_file(filename) File "/home/dino/.local/lib/python3.10/site-packages/rayoptics/qtgui/rayopticsapp.py", line 310, in open_file opt_model = cmds.open_model(file_name, kwargs) File "/home/dino/.local/lib/python3.10/site-packages/rayoptics/gui/appcmds.py", line 91, in open_model opm, import_info = zmxread.read_lens_file(file_url_pth, kwargs) File "/home/dino/.local/lib/python3.10/site-packages/rayoptics/zemax/zmxread.py", line 65, in read_lens_file opt_model, info = read_lens(filename, inpt, **kwargs) File "/home/dino/.local/lib/python3.10/site-packages/rayoptics/zemax/zmxread.py", line 104, in read_lens process_line(opt_model, line, i+1) File "/home/dino/.local/lib/python3.10/site-packages/rayoptics/zemax/zmxread.py", line 182, in process_line elif handle_aperture_data(opt_model, cur, cmd, inputs): File "/home/dino/.local/lib/python3.10/site-packages/rayoptics/zemax/zmxread.py", line 379, in handle_aperture_data ca_list = ifc.clear_apertures AttributeError: 'ThinLens' object has no attribute 'clear_apertures'. Did you mean: 'max_aperture'? qt.qpa.xcb: QXcbConnection: XCB error: 3 (BadWindow), sequence: 1714, resource id: 22272805, major code: 40 (TranslateCoords), minor code: 0

The zar file got from Open HSI models (https://github.com/openhsi/openhsi-models). It seems to have a problem on zmxread.py,

File "/home/dino/.local/lib/python3.10/site-packages/rayoptics/zemax/zmxread.py", line 379, in handle_aperture_data ca_list = ifc.clear_apertures AttributeError: 'ThinLens' object has no attribute 'clear_apertures'. Did you mean: 'max_aperture'?

I modified

ca_list = []

It looks partially working (I could see the lens view), something for help.

ss

open-hsi-opt1.zmx.txt

mjhoptics commented 1 year ago

This model definitely has a Zemax surface type that ray-optics doesn't recognize: Paraxial. I suspect the ray-optics Thinlens type would be a good first approximation. I'll try to get a patch in a day or so. Thanks for the detailed report. Mike Hayford

mjhoptics commented 1 year ago

Update on investigation: There are 3 surface types that are at issue: Thinlens, Diffraction grating and Blackbox. There were several problems with handling Thinlenses in ZMX files; I think I have that almost working. There is a linear diffraction grating in the model also; I am implementing the ray trace code for that now.

The real problem for this model is the Blackbox lens surfaces, of which there are 2 (on surfaces 20 and 23). These point to encrypted files that can only be read and processed by Zemax. This is Zemax's way of enabling people to pass around models while protecting their IP.

Hope this helps.

dinosauria123 commented 1 year ago

Thank you for your reply and hard work.

"Blackbox" is explained original OPEN-HSI model web site, hope this helps.

ZEMAX Opitcal Design Notes

The optical design make use of Zemax Black Box lens and perscriptions provided by Edmund Optics. These reamin the propety of the respective manufactures.

A Black Box was not avalive for the field lens, so a Paraxial Perfect lens is used with the same f/# and focal length.

mjhoptics commented 1 year ago

I've updated several changes to the master branch that address this issue. A major one is the addition of a linear diffraction grating that may be used as a phase_element. Zemax import support was added as well. There were other misc. issues with paraxial lens import that were fixed. The remaining issue with the .zmx file are the black box lens use, which cannot be supported by packages other than Zemax by design. Please let me know if you have any questions. Mike

dinosauria123 commented 1 year ago

Thank you for your work ! It is much better than before. I don't have zemax so I could not say "Blackbox"....