forked from mess42/pyrate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo_effl.py
144 lines (97 loc) · 4.47 KB
/
demo_effl.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/env/python
"""
Pyrate - Optical raytracing based on Python
Copyright (C) 2014 Moritz Esslinger moritz.esslinger@web.de
and Johannes Hartung j.hartung@gmx.net
and Uwe Lippmann uwe.lippmann@web.de
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
"""
import numpy as np
import matplotlib.pyplot as plt
import time
from core import pupil
from core import field
from core import raster
from core import material
from core import aim
from core import surfShape
from core.optical_system import OpticalSystem, Surface
from core.ray import RayPath, RayBundle
from core import plots
from core.aperture import CircularAperture, BaseAperture
from core.coordinates import LocalCoordinates
import math
# formula for effective focal length
def effl(r, alpha, phi):
sp = math.sin(phi)
cp = math.cos(phi)
return r*math.sqrt((1. - alpha**2*sp**2)**3/(- 1 + alpha**2*sp**2 + alpha*cp*math.sqrt(1. - alpha**2*sp**2))**2)
def effl_pt(r, alpha, phi):
sp = math.sin(phi)
cp = math.cos(phi)
def Power(x,y):
return x**y
def Sqrt(x):
return math.sqrt(x)
return np.array([
-((Power(1 - Power(alpha,2) + Power(alpha,2)*Power(cp,2),2)*r)/(-1 + Power(alpha,2)*Power(sp,2) +
alpha*cp*Sqrt(1 - Power(alpha,2)*Power(sp,2)))),
-((alpha*Power(1 - Power(alpha,2) + Power(alpha,2)*Power(cp,2),1.5)*r*sp)/(-1 + Power(alpha,2)*Power(sp,2) +
alpha*cp*Sqrt(1 - Power(alpha,2)*Power(sp,2))))
]
)
# definition of optical system
s = OpticalSystem()
lc1 = s.addLocalCoordinateSystem(LocalCoordinates(name="surf1", decz=0.0)) # objectDist
lc2 = s.addLocalCoordinateSystem(LocalCoordinates(name="surf2", decz=10.0))
s.insertSurface(1, Surface(lc1, surfShape.Conic(curv=1./3.),
material=material.ConstantIndexGlass(1.7), aperture=CircularAperture(3.0)))
s.insertSurface(2, Surface(lc2))
# pilot bundle
fig = plt.figure(1)
ax = fig.add_subplot(111)
ax.axis('equal')
ax.set_axis_bgcolor('black')
phirange = np.linspace(0.0, 1.0, 5)
phirange_anal = list(np.linspace(0.0, 1.5, 100))
effls = np.zeros((np.shape(phirange_anal)[0], 2), dtype=float)
for (ind, phiangle) in enumerate(phirange):
pts = np.array([[0, 0], [0.0, 0.1], [0, 0]])
dirs = np.array([[0,0], np.sin([phiangle, phiangle]), np.cos([phiangle, phiangle])])
pilotbundle = RayBundle(pts, dirs, s.surfaces[0].material, np.array([0, 1, 2]), wave=0.55, pol=[])
pilotpath = RayPath(pilotbundle, s)
plots.drawLayout2d(ax, s, [pilotpath])
for (ind, blub) in enumerate(phirange_anal):
effls[ind] = effl_pt(3.0, 1/1.7, blub)
ax.plot(effls[:, 0], effls[:, 1], color='r')
print(effl_pt(3.0, 1/1.7, 1.0))
# definition of rays
#nray = 1E5 # number of rays
#aimy = aim.aimFiniteByMakingASurfaceTheStop(s, pupilType=pupil.ObjectSpaceNA, #.StopDiameter,
# pupilSizeParameter=0.2,#3.0,
# fieldType= field.ObjectHeight,
# rasterType= raster.RectGrid,
# nray=nray, wavelength=0.55, stopPosition=1)
#initialBundle = aimy.getInitialRayBundle(s, fieldXY=np.array([0, 0]), wavelength=.55)
#nray = len(initialBundle.o[0, :])
#t0 = time.clock()
#r = RayPath(initialBundle, s)
#print "benchmark : ", time.clock() - t0, "s for tracing ", nray, " rays through ", len(s.surfaces) - 1, " surfaces."
#print " That is ", int(round(nray * (len(s.surfaces) - 1) / (time.clock() - t0))), "ray-surface-operations per second"
# plot
#aimy.setPupilRaster(rasterType= raster.RectGrid, nray=20)
#initialBundle2 = aimy.getInitialRayBundle(s, fieldXY=np.array([0, 0]), wavelength=.55)
#r2 = RayPath(initialBundle2, s)
#initialBundle3 = aimy.getInitialRayBundle(s, fieldXY=np.array([0, 0.1]), wavelength=.55)
#r3 = RayPath(initialBundle3, s)
plt.show()