mjhoptics / ray-optics

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

parse .seq files and write lists #108

Closed Jonas231 closed 1 year ago

Jonas231 commented 1 year ago

Hello, I opened a .seq file and was able to plot it following your example in the docu.

How can I write its radii, thicknesses, materials and semi-diameters to python lists? Is there a method in ray-optics?

Kind regards, Jonas

mjhoptics commented 1 year ago

Hello Jonas, Here's a list comprehension that does something like what you're asking:

from itertools import zip_longest
opm.radius_mode = True

[sm.list_surface_and_gap(ifc, g) for ifc, g in zip_longest(sm.ifcs, sm.gaps)]

with output from the double gauss example:

[[0.0, 993938392063.0, 'air', '', 247816674315.63208],
 [56.20237955932352, 8.75, 'N-SSK2', '', 28.17187921334009],
 [152.2857975564008, 0.5, 'air', '', 27.135934152409657],
 [37.68261994323691, 12.5, 'N-SK2', '', 24.62617295975861],
 [0.0, 3.8, 'F5', '', 22.893920808862706],
 [24.23130498959031, 16.36944492653564, 'air', '', 17.292567570792134],
 [0.0, 13.74795696388906, 'air', '', 15.757601237873693],
 [-28.37730627492329, 3.8, 'F5', '', 15.134796709700428],
 [0.0, 11.0, 'N-SK16', '', 17.250080572337634],
 [-37.9254645198716, 0.5, 'air', '', 18.926115740771415],
 [177.4117591281233, 7.0, 'N-SK16', '', 20.349014535702512],
 [-79.41142879681024, 61.4875364179821, 'air', '', 20.77628240612173],
 [0.0, 0.0, '', '', 24.739123051719602]]

The method list_surface_and_gap in SequentialModel is simple and it would be straightforward to write modified versions as standalone functions if this data isn't exactly what you want. Regards, Mike Hayford