Skip to content

Commit 2bb1b7d

Browse files
committed
incremented version and minor updates
1 parent 64e1024 commit 2bb1b7d

3 files changed

Lines changed: 139 additions & 16 deletions

File tree

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
import matplotlib.pyplot as plt
2+
import numpy as np
3+
import raytrace.raytrace as rt
4+
from raytrace.materials import Vacuum, Ebaf11, Nsf11
5+
6+
na = 0.98
7+
f = 1
8+
wlen = 0.561
9+
10+
wlen = 0.635
11+
12+
l1 = rt.Doublet(Ebaf11(),
13+
Nsf11(),
14+
radius_crown=50.8,
15+
radius_flint=-247.7,
16+
radius_interface=-41.7,
17+
thickness_crown=20.,
18+
thickness_flint=3.,
19+
aperture_radius=25.4,
20+
input_collimated=False,
21+
names="AC508-075-A-ML")
22+
23+
l2 = rt.Doublet(Ebaf11(),
24+
Nsf11(),
25+
radius_crown=50.8,
26+
radius_flint=-247.7,
27+
radius_interface=-41.7,
28+
thickness_crown=20.,
29+
thickness_flint=3.,
30+
aperture_radius=25.4,
31+
input_collimated=True,
32+
names="AC508-075-A-ML")
33+
34+
# flat surface at focal plane of lens 1
35+
cp1 = l1.get_cardinal_points(wlen, Vacuum(), Vacuum())
36+
f1_left = cp1[0][-1]
37+
f1_right = cp1[1][-1]
38+
wd_right = f1_right - l1.surfaces[-1].paraxial_center[-1]
39+
40+
system = rt.System([rt.FlatSurface([0, 0, 0], [0, 0, 1], 25.4)],
41+
[]
42+
)
43+
system = system.concatenate(l1, Vacuum(), -f1_left)
44+
45+
# find collimated distance between l1 and l2
46+
d = l2.find_paraxial_collimated_distance(l2, wlen, Vacuum(), Vacuum(), Vacuum())
47+
48+
# add flat surface at Fourier plane
49+
system = system.concatenate(rt.FlatSurface([0, 0, 0],
50+
[0, 0, 1],
51+
25.4),
52+
Vacuum(),
53+
wd_right)
54+
ind_pupil = len(system.surfaces) - 1
55+
56+
# add lens #2
57+
system = system.concatenate(l2, Vacuum(), d - wd_right)
58+
59+
60+
# last surface at focal plane
61+
c2 = l2.get_cardinal_points(wlen, Vacuum(), Vacuum())
62+
wd2 = c2[1][2] - l2.surfaces[-1].paraxial_center[2]
63+
64+
system = system.concatenate(rt.FlatSurface([0, 0, 0],
65+
[0, 0, 1],
66+
25.4),
67+
Vacuum(),
68+
wd2)
69+
70+
# add lenses
71+
system_detect = rt.System([rt.FlatSurface([0, 0, 0],
72+
[0, 0, 1],
73+
f * na),
74+
rt.PerfectLens(f,
75+
[0, 0, f],
76+
[0, 0, 1],
77+
np.arcsin(na)),
78+
rt.FlatSurface([0, 0, 2*f],
79+
[0, 0, 1],
80+
f * na
81+
),
82+
rt.PerfectLens(f,
83+
[0, 0, 3*f],
84+
[0, 0, 1],
85+
np.arcsin(na)),
86+
rt.FlatSurface([0, 0, 4*f],
87+
[0, 0, 1],
88+
f * na
89+
)
90+
],
91+
[Vacuum(), Vacuum(), Vacuum(), Vacuum()]
92+
)
93+
94+
system = system.concatenate(system_detect,
95+
Vacuum(),
96+
0
97+
)
98+
99+
nrays = 101
100+
rays = rt.get_ray_fan([0, 0, 0],
101+
10 * np.pi/180,
102+
nrays,
103+
wlen)
104+
rays_out = system.ray_trace(rays, Vacuum(), Vacuum())
105+
106+
system.plot(rays_out)
107+
plt.show()
108+
109+
figh = plt.figure()
110+
grid = figh.add_gridspec(nrows=1, ncols=1)
111+
112+
ax1 = figh.add_subplot(grid[0])
113+
ax1.set_title('pupil after')
114+
ax1.plot(rays_out[-1, :, 0],
115+
rays_out[-1, :, 6] - rays_out[-1, nrays // 2, 6],
116+
label="pupil after")
117+
ax1.plot(rays_out[-9, :, 0],
118+
rays_out[-9, :, 6] - rays_out[-9, nrays //2 , 6],
119+
'r.',
120+
label='pupil before')
121+
ax1.set_xlabel("Height (mm)")
122+
ax1.set_ylabel("OPL (mm)")
123+
ax1.legend()
124+
plt.show()

src/raytrace/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.0.0"
1+
__version__ = "0.1.0"

src/raytrace/raytrace.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@
1414
from typing import Optional, Union
1515
from collections.abc import Sequence
1616
from numpy.typing import NDArray
17-
import copy
17+
from copy import deepcopy
1818
import numpy as np
1919
from matplotlib.figure import Figure
2020
from matplotlib.axes._axes import Axes
2121
import matplotlib.pyplot as plt
22-
import warnings
2322
from raytrace.materials import Material, Vacuum
2423

2524
try:
@@ -69,17 +68,17 @@ def get_ray_fan(pt: NDArray,
6968
if np.linalg.norm(center_ray) != 1:
7069
raise ValueError("center_ray must be a unit vector")
7170

72-
thetas = np.linspace(-theta_max, theta_max, n_thetas)
73-
phis = np.arange(nphis) * 2*np.pi / nphis
74-
rays = np.zeros((n_thetas * nphis, 8))
71+
thetas = xp.linspace(-theta_max, theta_max, n_thetas)
72+
phis = xp.arange(nphis) * 2*np.pi / nphis
73+
rays = xp.zeros((n_thetas * nphis, 8))
7574

76-
tts, pps = np.meshgrid(thetas, phis)
75+
tts, pps = xp.meshgrid(thetas, phis)
7776
tts = tts.ravel()
7877
pps = pps.ravel()
7978

80-
enx = np.cross(np.array([0, 1, 0]), center_ray)
81-
enx = enx / np.linalg.norm(enx)
82-
eny = np.cross(center_ray, enx)
79+
enx = xp.cross(np.array([0, 1, 0]), center_ray)
80+
enx = enx / xp.linalg.norm(enx)
81+
eny = xp.cross(center_ray, enx)
8382

8483
pt = np.array(pt).squeeze()
8584

@@ -405,7 +404,7 @@ def reverse(self):
405404
flip direction of the optic we are considering (so typically rays now enter from the right)
406405
:return:
407406
"""
408-
surfaces_rev = [copy.deepcopy(self.surfaces[-ii]) for ii in range(1, len(self.surfaces) + 1)]
407+
surfaces_rev = [deepcopy(self.surfaces[-ii]) for ii in range(1, len(self.surfaces) + 1)]
409408

410409
for ii in range(len(self.surfaces)):
411410
surfaces_rev[ii].input_axis *= -1
@@ -436,13 +435,13 @@ def concatenate(self,
436435

437436
# specify distance between surfaces as distances between the paraxial foci
438437
if isinstance(other, System):
439-
new_surfaces = [copy.deepcopy(s) for s in other.surfaces]
438+
new_surfaces = [deepcopy(s) for s in other.surfaces]
440439
new_materials = other.materials
441440
other_stop = other.aperture_stop
442441
new_surfaces_by_name = other.surfaces_by_name
443442
new_names = other.names
444443
elif isinstance(other, Surface):
445-
new_surfaces = [copy.deepcopy(other)]
444+
new_surfaces = [deepcopy(other)]
446445
new_materials = []
447446
other_stop = None
448447
new_surfaces_by_name = np.array([0])
@@ -1284,9 +1283,9 @@ def propagate(self,
12841283
ds_out = mag_na * normals + mag_nc * nc
12851284

12861285
rays_refracted = xp.concatenate((rays_intersection[:, :3],
1287-
ds_out,
1288-
rays_intersection[:, 6:]),
1289-
axis=1)
1286+
ds_out,
1287+
rays_intersection[:, 6:]),
1288+
axis=1)
12901289
rays_refracted[xp.isnan(ds_out[:, 0]), :3] = xp.nan
12911290

12921291
# check array was within aperture

0 commit comments

Comments
 (0)