-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomponent.py
More file actions
185 lines (151 loc) · 6.86 KB
/
component.py
File metadata and controls
185 lines (151 loc) · 6.86 KB
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
import numpy as np
import pylab as plt
import pyzdde.zdde as pyz
class Component(object):
def __init__(self, zmx_file, zcontroller, lumultiplier=1e-3, wumultiplier=1e6):
'''
Initialise a component.
[lumultiplier] is used to move from Zemax lens units to another
physical dimension. By default, Zemax does its calculations in
mm, so a [lumultiplier] of 1e-3 moves from mm to m.
[wumultiplier] is used to move from SI units to Zemax wavelength
units. By default, Zemax does its calculations in
micron, so a [wumultiplier] of 1e6 moves from m to micron.
'''
self.file_pathname = zmx_file
self.zcontroller = zcontroller
self.lumultiplier = lumultiplier
self.wumultiplier = wumultiplier
def _doAnalysisWFE(self, fields, field_type, wavelength, sampling,
verbose=True, debug=False):
if not self.zcontroller.isFileAlreadyLoaded(self.file_pathname):
self.zcontroller.loadZemaxFile(self.file_pathname)
self.zcontroller.setWavelengthNumberOf(1)
self.zcontroller.setWavelengthValue(float(wavelength)*self.wumultiplier, 1)
data, headers = self.zcontroller.getAnalysisWFEForFields(fields, field_type,
sampling=sampling)
return data, headers
def _doRayTrace(self, fields, field_type, wavelength, verbose=True,
debug=False):
if not self.zcontroller.isFileAlreadyLoaded(self.file_pathname):
self.zcontroller.loadZemaxFile(self.file_pathname)
self.zcontroller.setWavelengthNumberOf(1)
self.zcontroller.setWavelengthValue(float(wavelength)*self.wumultiplier, 1)
rays = self.zcontroller.doRayTraceForFields(fields, field_type=field_type,
px=0, py=0)
tmp = []
for ray in rays:
tmp.append({
'x': ray.x * self.lumultiplier,
'y': ray.y * self.lumultiplier,
'z': ray.z * self.lumultiplier,
'dcos_l': ray.dcos_l,
'dcos_m': ray.dcos_m,
'dcos_n': ray.dcos_n
})
rays = tmp
if debug:
for idx, ray in enumerate(rays):
if idx == 0:
print
print "field\tx\ty\tz"
print idx, '\t', round(ray['x'], 2), '\t', round(ray['y'], 2), \
'\t', round(ray['z'], 2)
if idx == len(rays):
print
plt.plot()
for field, ray in zip(fields, rays):
plt.plot(rays['x'], ray['y'], 'o', label=str('[' + str(field[0]) +
', ' + str(field[1]) +
']'))
plt.legend(loc='upper right', numpoints=1)
plt.show()
return rays
def getEFFL(self, wavelength, verbose=False):
if verbose:
print "Getting EFFL for component... "
if not self.zcontroller.isFileAlreadyLoaded(self.file_pathname):
self.zcontroller.loadZemaxFile(self.file_pathname)
self.zcontroller.setWavelengthNumberOf(1)
self.zcontroller.setWavelengthValue(float(wavelength)*self.wumultiplier, 1)
return self.zcontroller.getLensData().EFL*self.lumultiplier
def getENPD(self, wavelength, verbose=False):
if verbose:
print "Getting ENPD for component... "
if not self.zcontroller.isFileAlreadyLoaded(self.file_pathname):
self.zcontroller.loadZemaxFile(self.file_pathname)
self.zcontroller.setWavelengthNumberOf(1)
self.zcontroller.setWavelengthValue(float(wavelength)*self.wumultiplier, 1)
return self.zcontroller.getPupilData().ENPD*self.lumultiplier
def getEXPD(self, wavelength, verbose=False):
if verbose:
print "Getting EXPD for component... "
if not self.zcontroller.isFileAlreadyLoaded(self.file_pathname):
self.zcontroller.loadZemaxFile(self.file_pathname)
self.zcontroller.setWavelengthNumberOf(1)
self.zcontroller.setWavelengthValue(float(wavelength)*self.wumultiplier, 1)
return self.zcontroller.getPupilData().EXPD*self.lumultiplier
def getWFNO(self, wavelength, verbose=False):
if verbose:
print "Getting WFNO for component... "
if not self.zcontroller.isFileAlreadyLoaded(self.file_pathname):
self.zcontroller.loadZemaxFile(self.file_pathname)
self.zcontroller.setWavelengthNumberOf(1)
self.zcontroller.setWavelengthValue(float(wavelength)*self.wumultiplier, 1)
return self.zcontroller.getLensData().realWorkFNum
class Camera(Component):
def __init__(self, camera_zmx_file, zcontroller, lumultiplier=1e-3,
wumultiplier=1e6):
super(Camera, self).__init__(camera_zmx_file, zcontroller, lumultiplier,
wumultiplier)
pass
def getImXY(self, fields, wavelength, verbose=True, debug=False):
'''
Trace the chief ray from each collimated field point through the camera
and work out the corresponding (x, y) positions at the image plane.
'''
if verbose:
print "Tracing object angles through camera..."
rays = self._doRayTrace(fields, 0, wavelength, verbose=verbose,
debug=debug)
ImXYs = []
for ray in rays:
ImXYs.append((ray['x'], ray['y']))
return ImXYs
def getWFE(self, fields, wavelength, sampling, verbose=True, debug=False):
'''
Get the pupil WFE after passing through the camera.
'''
return self._doAnalysisWFE(fields, 0, wavelength, sampling=sampling,
verbose=verbose, debug=debug)
class Collimator(Component):
def __init__(self, collimator_zmx_file, zcontroller, lumultiplier=1e-3,
wumultiplier=1e6):
super(Collimator, self).__init__(collimator_zmx_file, zcontroller,
lumultiplier, wumultiplier)
pass
def getOA(self, fields, wavelength, verbose=True, debug=False):
'''
Trace the chief ray for each field point in the slit through the
collimator and, using directional cosines and the relations
(p53 Zemax manual)
tan(alpha) = direction_cosine(x)/direction_cosine(z) .. (1)
tan(beta) = direction_cosine(y)/direction_cosine(z) .. (2)
calculate the output field angles x and y (alpha and beta respectively).
'''
if verbose:
print "Tracing object heights through collimator... "
rays = self._doRayTrace(fields, 1, wavelength, verbose=verbose,
debug=debug)
OAs = []
for ray in rays:
#print ray['dcos_l'], ray['dcos_m'], ray['dcos_n']
OAs.append((np.degrees(np.arctan(ray['dcos_l']/ray['dcos_n'])),
np.degrees(np.arctan(ray['dcos_m']/ray['dcos_n']))))
return OAs
def getWFE(self, fields, wavelength, sampling, verbose=True, debug=False):
'''
Get the pupil WFE after passing through the collimator.
'''
return self._doAnalysisWFE(fields, 1, wavelength, sampling=sampling,
verbose=verbose, debug=debug)