-
Notifications
You must be signed in to change notification settings - Fork 11
/
BeamInfo.py
231 lines (200 loc) · 6.87 KB
/
BeamInfo.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
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
"""
[Name] BeamInfo
[Description]
BeamInfo hardware object is used to define final beam size and shape.
It can include aperture, slits and/or other beam definer (lenses or other eq.)
[Emited signals]
beamInfoChanged
beamPosChanged
[Included Hardware Objects]
-----------------------------------------------------------------------
| name | signals | functions
-----------------------------------------------------------------------
aperture_hwobj apertureChanged
slits_hwobj
beam_definer_hwobj
-----------------------------------------------------------------------
"""
import logging
from HardwareRepository.BaseHardwareObjects import Equipment
class BeamInfo(Equipment):
"""
Description:
"""
def __init__(self, *args):
"""
Descrip. :
"""
Equipment.__init__(self, *args)
self.aperture_hwobj = None
self.slits_hwobj = None
self.beam_definer_hwobj = None
self.beam_size_slits = None
self.beam_size_aperture = None
self.beam_size_definer = None
self.beam_position = None
self.beam_info_dict = None
self.default_beam_divergence = None
self.chan_beam_size_microns = None
self.chan_beam_shape_ellipse = None
def init(self):
"""
Descript. :
"""
self.beam_size_slits = [9999, 9999]
self.beam_size_aperture = [9999, 9999]
self.beam_size_definer = [9999, 9999]
self.beam_position = [0, 0]
self.beam_info_dict = {}
self.aperture_hwobj = self.getObjectByRole("aperture")
if self.aperture_hwobj is not None:
self.connect(self.aperture_hwobj, "apertureChanged", \
self.aperture_pos_changed)
else:
logging.getLogger("HWR").debug("BeamInfo: Aperture hwobj not defined")
self.slits_hwobj = self.getObjectByRole("slits")
if self.slits_hwobj is not None:
self.connect(self.slits_hwobj, "gapSizeChanged", self.slits_gap_changed)
else:
logging.getLogger("HWR").debug("BeamInfo: Slits hwobj not defined")
self.beam_definer_hwobj = self.getObjectByRole("definer")
if self.beam_definer_hwobj is not None:
self.connect(self.beam_definer_hwobj, "definerPosChanged", \
self.definer_pos_changed)
else:
logging.getLogger("HWR").debug("BeamInfo: Beam definer hwobj not defined")
default_beam_divergence_vertical = None
default_beam_divergence_horizontal = None
try:
default_beam_divergence_vertical = int(self.getProperty("beam_divergence_vertical"))
default_beam_divergence_horizontal = int(self.getProperty("beam_divergence_horizontal"))
except:
pass
self.default_beam_divergence = [default_beam_divergence_horizontal, default_beam_divergence_vertical]
def connectNotify(self, *args):
self.evaluate_beam_info()
self.emit_beam_info_change()
def get_beam_divergence_hor(self):
"""
Descript. :
"""
if self.beam_definer_hwobj is not None:
return self.beam_definer_hwobj.get_divergence_hor()
else:
return self.default_beam_divergence[0]
def get_beam_divergence_ver(self):
"""
Descript. :
"""
if self.beam_definer_hwobj is not None:
return self.beam_definer_hwobj.get_divergence_ver()
else:
return self.default_beam_divergence[1]
def get_beam_position(self):
"""
Descript. :
Arguments :
Return :
"""
return (0, 0)
#raise NotImplementedError
def set_beam_position(self, beam_x, beam_y):
"""
Descript. :
Arguments :
Return :
"""
raise NotImplementedError
def aperture_pos_changed(self, size):
"""
Descript. :
Arguments :
Return :
"""
self.beam_size_aperture = size
self.evaluate_beam_info()
self.emit_beam_info_change()
def slits_gap_changed(self, size):
"""
Descript. :
Arguments :
Return :
"""
self.beam_size_slits = size
self.evaluate_beam_info()
self.emit_beam_info_change()
def definer_pos_changed(self, name, size):
"""
Descript. :
Arguments :
Return :
"""
self.beam_size_definer = size
self.evaluate_beam_info()
self.emit_beam_info_change()
def get_beam_info(self):
"""
Descript. :
Arguments :
Return :
"""
return self.evaluate_beam_info()
def get_beam_size(self):
"""
Descript. : returns beam size in millimeters
Return : list with two integers
"""
self.evaluate_beam_info()
return self.beam_info_dict["size_x"], \
self.beam_info_dict["size_y"]
def get_beam_shape(self):
"""
Descript. :
Arguments :
Return :
"""
self.evaluate_beam_info()
return self.beam_info_dict["shape"]
def get_slits_gap(self):
"""
Descript. :
Arguments :
Return :
"""
self.evaluate_beam_info()
return self.beam_size_slits
def evaluate_beam_info(self):
"""
Descript. : called if aperture, slits or focusing has been changed
Return : dictionary,{size_x:0.1, size_y:0.1, shape:"rectangular"}
"""
size_x = min(self.beam_size_aperture[0],
self.beam_size_slits[0],
self.beam_size_definer[0])
size_y = min(self.beam_size_aperture[1],
self.beam_size_slits[1],
self.beam_size_definer[1])
self.beam_info_dict["size_x"] = size_x
self.beam_info_dict["size_y"] = size_y
# be careful with comparisons!!! both have to be the same type (=tuple)
if tuple(self.beam_size_aperture) < tuple(self.beam_size_slits):
self.beam_info_dict["shape"] = "ellipse"
else:
self.beam_info_dict["shape"] = "rectangular"
return self.beam_info_dict
def emit_beam_info_change(self):
"""
Descript. :
Arguments :
Return :
"""
if self.beam_info_dict["size_x"] != 9999 and \
self.beam_info_dict["size_y"] != 9999:
self.emit("beamSizeChanged", ((self.beam_info_dict["size_x"], \
self.beam_info_dict["size_y"]), ))
self.emit("beamInfoChanged", (self.beam_info_dict, ))
if self.chan_beam_size_microns:
self.chan_beam_size_microns.setValue((self.beam_info_dict["size_x"] * 1000, \
self.beam_info_dict["size_y"] * 1000))
if self.chan_beam_shape_ellipse:
self.chan_beam_shape_ellipse.setValue(self.beam_info_dict["shape"] == "ellipse")