forked from kparasch/ebs2pySC
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterface.py
More file actions
244 lines (202 loc) · 9.11 KB
/
interface.py
File metadata and controls
244 lines (202 loc) · 9.11 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
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
232
233
234
235
236
237
238
239
240
241
242
243
244
from tango import AttributeProxy, DeviceProxy
import os
import time
from pathlib import Path
data_folder = Path('./data')
os.environ['TANGO_HOST'] = 'acs.esrf.fr:10000,acs.esrf.fr:11000'
# os.environ['TANGO_HOST'] = 'ebs-simu-1:10000'
present_host = os.environ['TANGO_HOST']
print(present_host)
master_source = AttributeProxy('sy/ms/1/Frequency')
HRefOrb = AttributeProxy('sr/beam-orbitcor/svd-h/BumpOrbit')
VRefOrb = AttributeProxy('sr/beam-orbitcor/svd-v/BumpOrbit')
HBPM = AttributeProxy('srdiag/bpm/all/All_SA_HPosition')
VBPM = AttributeProxy('srdiag/bpm/all/All_SA_VPosition')
hst = DeviceProxy('srmag/hst/all') # 384 hor steerers (include DQ hor steerer)
vst = DeviceProxy('srmag/vst/all') # 288 ver steerers
sqp = DeviceProxy('srmag/sqp/all') # 288 skew quads
sext = DeviceProxy('srmag/m-s/all') # 192 Sextupoles
quad = DeviceProxy('srmag/m-q/all') # 610 quadrupoles (includes DQ quad)
oct = DeviceProxy('srmag/m-o/all') # 64 octupoles
# get names in arrays
hst_names = hst.CorrectorNames
vst_names = vst.CorrectorNames
sqp_names = sqp.CorrectorNames
sext_names = sext.MagnetNames
quad_names = quad.MagnetNames
oct_names = oct.MagnetNames
class Interface:
wait_after_set = 1 # seconds
quad_wait_time = 5 # seconds
rf_wait_time = 5 # seconds
orbit_wait_time = 1 # seconds
def get_rf_main_frequency(self):
""" get master source frequency in Hz"""
return master_source.read().value
def set_rf_main_frequency(self, frequency):
""" set absolute value of master source frequency in Hz"""
master_source.write(frequency)
time.sleep(self.rf_wait_time)
return
def get_ref_orbit(self):
'''
returns the reference orbit of the machine in two lists/arrays:
e.g. x, y = ebs.get_ref_orbit()
we should make sure here that we can call this function twice and not get the same reading (i.e. wait that the orbit has refreshed).
'''
orb_ref_h = HRefOrb.read().value
orb_ref_v = VRefOrb.read().value
return orb_ref_h, orb_ref_v
def get_orbit(self):
'''
returns the orbit of the machine in two lists/arrays:
e.g. x, y = ebs.get_orbit()
we should make sure here that we can call this function twice and not get the same reading (i.e. wait that the orbit has refreshed).
'''
time.sleep(self.orbit_wait_time) # 1 second polling time
orb_h = HBPM.read().value
orb_v = VBPM.read().value
return orb_h, orb_v
def get(self, name: str) -> float:
'''
gets a magnet strength in the machine (physics units), integrated or not.
e.g. k0 = ebs.get('SD1A-C01-H')
'''
# name is a tango device in this format 'srmag/m-q/all/CorrectionStrengths' where is pySC exepcting to find the magnet names?
mag = AttributeProxy(name+'/Strength')
mag_SetPoint = mag.read().w_value
return mag_SetPoint
def set(self, name: str, value: float):
'''
sets a magnet strength in the machine (physics units), integrated or not.
e.g. ebs.set('SD1A-C01-H', 100e-6)
waiting time to make sure power supply is settled and eddy currents are decayed to be handled also here.
'''
AttributeProxy(name+'/Strength').write(value)
if "m-q" in name:
time.sleep(max(self.quad_wait_time, self.wait_after_set))
else:
time.sleep(self.wait_after_set)
return
def get_many(self, names: list) -> dict[str, float]:
'''
gets many magnet strengths in the machine (physics units), integrated or not.
e.g. data_k0 = ebs.get_many(['SD1A-C01-H', 'SD1A-C01-V'])
resulting in data_k0 as {'SD1A-C01-H': 100e-6, 'SD1A-C01-V': 200e-6} for example
'''
data_k0={}
# init set points
hst_SetPoint = []
vst_SetPoint = []
sqp_SetPoint = []
sext_SetPoint = []
quad_SetPoint = []
oct_SetPoint = []
for name in names:
if "hst" in name:
# get set points only if a name is requested
if len(hst_SetPoint) == 0:
hst_SetPoint = hst.read_attribute("Strengths").w_value # single call to read array
# find name index
data_k0[name] = hst_SetPoint[hst_names.index(name)]
if "vst" in name:
# get set points only if a name is requested
if len(vst_SetPoint) == 0:
vst_SetPoint = vst.read_attribute("Strengths").w_value # single call to read array
# find name index
data_k0[name] = vst_SetPoint[vst_names.index(name)]
if "sqp" in name:
# get set points only if a name is requested
if len(sqp_SetPoint) == 0:
sqp_SetPoint = sqp.read_attribute("CorrectionStrengths").w_value # single call to read array
# find name index
data_k0[name] = sqp_SetPoint[sqp_names.index(name)]
if "m-s" in name:
# get set points only if a name is requested
if len(sext_SetPoint) == 0:
sext_SetPoint = sext.read_attribute("CorrectionStrengths").w_value # single call to read array
# find name index
data_k0[name] = sext_SetPoint[sext_names.index(name)]
if "m-q" in name:
# get set points only if a name is requested
if len(quad_SetPoint) == 0:
quad_SetPoint = quad.read_attribute("CorrectionStrengths").w_value # single call to read array
# find name index
data_k0[name] = quad_SetPoint[quad_names.index(name)]
if "m-o" in name:
# get set points only if a name is requested
if len(oct_SetPoint) == 0:
oct_SetPoint = oct.read_attribute("CorrectionStrengths").w_value # single call to read array
# find name index
data_k0[name] = oct_SetPoint[oct_names.index(name)]
return data_k0
def set_many(self, data: dict[str, float]):
'''
perhaps there is a specific host you use to set all corrector settings?
sets many magnet strengths in the machine (physics units), integrated or not.
e.g. ebs.set_many({'SD1A-C01-H': 100e-6, 'SD1A-C01-V': 200e-6})
waiting time to make sure power supply is settled and eddy currents are decayed to be handled also here.
'''
wait_time = self.wait_after_set
# init set points
hst_SetPoint = []
vst_SetPoint = []
sqp_SetPoint = []
sext_SetPoint = []
quad_SetPoint = []
oct_SetPoint = []
# apply setting to array:
hst_apply = False
vst_apply = False
sqp_apply = False
sext_apply =False
quad_apply = False
oct_apply = False
# loop values to change
for key, value in data.items():
if "hst" in key:
if len(hst_SetPoint) == 0:
hst_SetPoint = hst.read_attribute("Strengths").w_value # single call to read array
hst_apply = True
hst_SetPoint[hst_names.index(key)] = value
if "vst" in key:
if len(vst_SetPoint) == 0:
vst_SetPoint = vst.read_attribute("Strengths").w_value # single call to read array
vst_apply = True
vst_SetPoint[vst_names.index(key)] = value
if "sqp" in key:
if len(sqp_SetPoint) == 0:
sqp_SetPoint = sqp.read_attribute("CorrectionStrengths").w_value # single call to read array
sqp_apply = True
sqp_SetPoint[sqp_names.index(key)] = value
if "m-s" in key:
if len(sext_SetPoint) == 0:
sext_SetPoint = sext.read_attribute("CorrectionStrengths").w_value # single call to read array
sext_apply = True
sext_SetPoint[sext_names.index(key)] = value
if "m-q" in key:
if len(quad_SetPoint) == 0:
quad_SetPoint = quad.read_attribute("CorrectionStrengths").w_value # single call to read array
quad_apply = True
quad_SetPoint[quad_names.index(key)] = value
if "m-o" in key:
if len(oct_SetPoint) == 0:
oct_SetPoint = oct.read_attribute("CorrectionStrengths").w_value # single call to read array
oct_apply = True
oct_SetPoint[oct_names.index(key)] = value
# apply values
if hst_apply:
hst.Strengths = hst_SetPoint
if vst_apply:
vst.Strengths = vst_SetPoint
if sqp_apply:
sqp.CorrectionStrengths = sqp_SetPoint
if quad_apply:
wait_time = max(wait_time, self.quad_wait_time)
quad.CorrectionStrengths = quad_SetPoint
if sext_apply:
sext.CorrectionStrengths = sext_SetPoint
if oct_apply:
oct.CorrectionStrengths = oct_SetPoint
time.sleep(wait_time)
return