barsukov 0.0.4__py3-none-any.whl → 1.0.8__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of barsukov might be problematic. Click here for more details.
- 2025-01-24_No Stn_Anon_No Sample_No Description/mw.dill +1 -0
- 2025-01-24_No Stn_Anon_No Sample_No Description/mw.pkl +1 -0
- barsukov/__init__.py +15 -14
- barsukov/data/__init__.py +1 -0
- barsukov/data/fft.py +87 -87
- barsukov/exp/exp_utils.py +136 -119
- barsukov/exp/mwHP.py +191 -357
- barsukov/logger.py +126 -122
- barsukov/obj2file.py +105 -107
- barsukov/script.py +96 -82
- barsukov/testpickle.py +38 -0
- barsukov/time.py +16 -16
- {barsukov-0.0.4.dist-info → barsukov-1.0.8.dist-info}/METADATA +47 -48
- barsukov-1.0.8.dist-info/RECORD +17 -0
- barsukov-1.0.8.dist-info/top_level.txt +2 -0
- barsukov-0.0.4.dist-info/RECORD +0 -14
- barsukov-0.0.4.dist-info/top_level.txt +0 -1
- {barsukov-0.0.4.dist-info → barsukov-1.0.8.dist-info}/WHEEL +0 -0
barsukov/exp/mwHP.py
CHANGED
|
@@ -1,357 +1,191 @@
|
|
|
1
|
-
### BEGIN Dependencies ###
|
|
2
|
-
import numpy as np
|
|
3
|
-
import sys
|
|
4
|
-
from barsukov.exp.exp_utils import *
|
|
5
|
-
### END Dependencies
|
|
6
|
-
|
|
7
|
-
# STATUS: f() finished, nor test it and then add more funcitons
|
|
8
|
-
|
|
9
|
-
class mwHP:
|
|
10
|
-
def __init__(self, gpib=None, visa_rm=None, logger=None, gpib_card=0, log='default', script=None):
|
|
11
|
-
# Pass the Script object, if available.
|
|
12
|
-
# If Script has no visa_rm or if no Script is passed, you'll need to pass the visa_rm=visa.ResourceManager manually.
|
|
13
|
-
# If Script has no logger or if no Script is passed, you can pass the logger manually.
|
|
14
|
-
# If no logger is passed, will simply print to screen.
|
|
15
|
-
# Change log from 'default' to 'screen', 'file', 'both', 'no'.
|
|
16
|
-
# gpib_card is per default 0. You can change, if you have multiple.
|
|
17
|
-
|
|
18
|
-
self.script = script
|
|
19
|
-
self.logger = logger
|
|
20
|
-
self.eq_default_log = log
|
|
21
|
-
self.rm = visa_rm
|
|
22
|
-
self.gpib_card = gpib_card
|
|
23
|
-
self.gpib = gpib
|
|
24
|
-
|
|
25
|
-
self.msg_deco = f'[mwHP {self.gpib_card}::{self.gpib}]'
|
|
26
|
-
#print( 'visa_rm is ', visa_rm )
|
|
27
|
-
#print( 'script is ', script )
|
|
28
|
-
self.eq = initialize_gpib(self) # This will initialize self.eq = visa.open_resource()
|
|
29
|
-
self.log( f'Initialized: {self.identify()}', log='important' ) # This is the 'welcome message' and a check if communication works.
|
|
30
|
-
|
|
31
|
-
self.f_digits = 9 # Digits of precision of mw frequency
|
|
32
|
-
self.f_limits = [0.01, 20.5] # Lower and upper GHz limits
|
|
33
|
-
self.p_digits = 1 #TODO -- Digits of precision of mw power
|
|
34
|
-
self.p_limits = [-15.0, 17.0] #TODO -- Lower and upper __ limits
|
|
35
|
-
self.pulsef_digits = 3 # digits in KHz
|
|
36
|
-
self.pulsew_digits = 3 # digits in ms
|
|
37
|
-
self.pulsef_limits = [0.016, 500]
|
|
38
|
-
self.pulsew_limits = [0.001, 65.53] # digits in ms
|
|
39
|
-
self.pulsedc_limits = [0, 100]
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
def
|
|
49
|
-
return
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
def
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
###
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
self.
|
|
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
|
-
self.
|
|
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
|
-
self.
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
self.
|
|
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
|
-
#self.log(f'Warning: mode for sweep was not specified.', log=log)
|
|
193
|
-
#return np.nan
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
def pulse(self, f=None, duty=None, log=None):
|
|
199
|
-
if log is None: log=self.eq_default_log
|
|
200
|
-
if f is None and duty is None:
|
|
201
|
-
T = float(self.eq.query('puls:per?')) * 10.0**3
|
|
202
|
-
f = 1.0 / T
|
|
203
|
-
w = float(self.eq.query('puls:widt?')) * 10.0**3
|
|
204
|
-
duty = w / T * 100.0
|
|
205
|
-
y = self.eq.query('pulm:stat?')
|
|
206
|
-
y = int(y)
|
|
207
|
-
x = self.eq.query('pulm:sour?')
|
|
208
|
-
x = x[:-1].lower()
|
|
209
|
-
self.log(f'Pulse Frequency {f} KHz, duty-cycle {duty}%. state {y}, source {x}.', log=log)
|
|
210
|
-
return f, duty
|
|
211
|
-
|
|
212
|
-
else:
|
|
213
|
-
if f is None and duty is not None:
|
|
214
|
-
duty_write = max(self.pulsedc_limits[0], min(float(duty), self.pulsedc_limits[1]))
|
|
215
|
-
T = float(self.eq.query('puls:per?')) * 10.0**3
|
|
216
|
-
w = duty_write * T / 100.0
|
|
217
|
-
self.eq.write(f'puls:widt {w} ms')
|
|
218
|
-
|
|
219
|
-
elif f is not None and duty is None:
|
|
220
|
-
f_write = max(self.pulsef_limits[0], min(float(f), self.pulsef_limits[1]))
|
|
221
|
-
duty_write = 50.0
|
|
222
|
-
T = 1.0 / f
|
|
223
|
-
w = duty_write * T / 100.0
|
|
224
|
-
self.eq.write(f'puls:per {T} ms')
|
|
225
|
-
self.eq.write(f'puls:widt {w} ms')
|
|
226
|
-
|
|
227
|
-
elif f is not None and duty is not None:
|
|
228
|
-
f_write = max(self.pulsef_limits[0], min(float(f), self.pulsef_limits[1]))
|
|
229
|
-
duty_write = max(self.pulsedc_limits[0], min(float(duty), self.pulsedc_limits[1]))
|
|
230
|
-
T = 1.0 / f
|
|
231
|
-
w = duty_write * T / 100.0
|
|
232
|
-
self.eq.write(f'puls:per {T} ms')
|
|
233
|
-
self.eq.write(f'puls:widt {w} ms')
|
|
234
|
-
|
|
235
|
-
check = self.pulse()
|
|
236
|
-
return check
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
#def pulse(self, on_off=None, freq=None, duty_cycle=None, int_ext=None, log=None):
|
|
240
|
-
### Always has a return! Which is the state, freq, duty cycle, and source of pulse
|
|
241
|
-
### Frequency in KHz, Duty Cycle in %, source int(ernal) or ext(ernal)
|
|
242
|
-
### pulse() reads and returns state, frequency, duty cycle, and source of pulse
|
|
243
|
-
### pulse(1,1,50,int) writes state ON, frequency 1KHz, duty cycle 50%, and internal mode to Pulse
|
|
244
|
-
### pulse(1,1,50,int) returns the state, frequency, duty cycle, and source that was actually sent to the equipment
|
|
245
|
-
### pulse(1,1,50,int) returns the state, frequency, duty cycle, and source queried after writing
|
|
246
|
-
#if log is None: log=self.eq_default_log
|
|
247
|
-
#if (on_off is None) and (freq is None) and (duty_cycle is None) and (int_ext is None):
|
|
248
|
-
### Accesser Code - returns whats on equipment object
|
|
249
|
-
#try:
|
|
250
|
-
#y = self.eq.query('pulm:stat?')
|
|
251
|
-
#y = int(y)
|
|
252
|
-
#f = float(self.eq.query('puls:freq?')) / 10.0**3
|
|
253
|
-
# returns in Khz
|
|
254
|
-
#dc = float(self.eq.query('puls:widt?')) * f * 10.0**5
|
|
255
|
-
# returns in %
|
|
256
|
-
#x = self.eq.query('pulm:sour?')
|
|
257
|
-
#x = x[:-1].lower()
|
|
258
|
-
# returns in lowercase
|
|
259
|
-
#self.log(f'Pulse state is {y}, frequency {f} KHz, duty-cycle {dc}%, source {x}.', log=log)
|
|
260
|
-
#return [y, f, dc, x]
|
|
261
|
-
#except:
|
|
262
|
-
#self.log(f'Error while reading Pulse state.', log='important')
|
|
263
|
-
#return np.nan
|
|
264
|
-
#else:
|
|
265
|
-
### Mutator Code - Writes to equipment object
|
|
266
|
-
#if (on_off == 1) or (on_off == 'on') or (on_off=='ON') or (on_off=='On'): state = 1
|
|
267
|
-
#else: state = 0
|
|
268
|
-
#error = False
|
|
269
|
-
#if (int_ext == 'int') or (int_ext == 'ext') or (int_ext == 'INT') or (int_ext == 'EXT'):
|
|
270
|
-
### writes mode (int/ext)
|
|
271
|
-
#try:
|
|
272
|
-
#self.eq.write(f'pulm:sour {int_ext}')
|
|
273
|
-
#y = self.eq.query('pulm:sour?')
|
|
274
|
-
#y = y[:-1].lower()
|
|
275
|
-
#if (str(y) == str(int_ext.lower())): self.log(f'Setting Pulse to {int_ext}.', log=log)
|
|
276
|
-
#else: self.log(f'Warning:Setting Pulse to {y[3]}, but was asked {int_ext}.', log='important')
|
|
277
|
-
#except:
|
|
278
|
-
#self.log(f'Error while changing Pulse Source.', log='important')
|
|
279
|
-
#return np.nan
|
|
280
|
-
#elif (int_ext is not None): self.log(f'Error: Invalid Pulse Source.', log='important')
|
|
281
|
-
#if (freq is None) and (duty_cycle is not None):
|
|
282
|
-
### if frequency and duty cycle not in ratio, changes duty cycle to acceptable value
|
|
283
|
-
#try:
|
|
284
|
-
#writeduty_cycle = float(duty_cycle)
|
|
285
|
-
#writeduty_cycle = max(self.pulsedc_limits[0], min(writeduty_cycle, self.pulsedc_limits[1])) # sets writeduty_cycle within pulsedc_limits
|
|
286
|
-
#y = float(self.eq.query(f'puls:freq?')) / 1000.0 #returns in KHz
|
|
287
|
-
#writefreq = y
|
|
288
|
-
#width = writeduty_cycle * 0.01 / writefreq # units of ms
|
|
289
|
-
#width = max(self.pulsew_limits[0], min(width, self.pulsew_limits[1]))
|
|
290
|
-
#wdth = ceil(width * 1000.0) / 1000.0
|
|
291
|
-
#idth = round(width, self.pulsew_digits)
|
|
292
|
-
#lf.eq.write(f'puls:widt {width} ms')
|
|
293
|
-
#except:
|
|
294
|
-
#self.log(f'Error while changing Duty Cycle within limits.', log='important')
|
|
295
|
-
#error = True
|
|
296
|
-
#return np.nan
|
|
297
|
-
#elif (duty_cycle is None) and (freq is not None):
|
|
298
|
-
### if frequency and duty cycle not in ratio, changes frequency to acceptable value
|
|
299
|
-
# try:
|
|
300
|
-
# writeduty_cycle = 50.0
|
|
301
|
-
# writefreq = round(freq, self.pulsef_digits) # rounding the digits
|
|
302
|
-
# writefreq = max(self.pulsef_limits[0], min(writefreq, self.pulsef_limits[1])) # sets writeduty_cycle within pulsedc_limits
|
|
303
|
-
# print(writefreq)
|
|
304
|
-
# width = writeduty_cycle * 0.01 / writefreq # units of ms
|
|
305
|
-
# width = max(self.pulsew_limits[0], min(width, self.pulsew_limits[1]))
|
|
306
|
-
# width = ceil(width * 1000.0) / 1000.0
|
|
307
|
-
#width = round(width, self.pulsew_digits)
|
|
308
|
-
# print(width)
|
|
309
|
-
# self.eq.write(f'puls:freq {writefreq} KHz')
|
|
310
|
-
# self.eq.write(f'puls:widt {width} ms')
|
|
311
|
-
# except:
|
|
312
|
-
# print(width)
|
|
313
|
-
# self.log(f'Error while changing Pulse Frequency within limits.', log='important')
|
|
314
|
-
# error = True
|
|
315
|
-
# return np.nan
|
|
316
|
-
#elif (freq is not None) and (duty_cycle is not None):
|
|
317
|
-
### writing both duty cycle and frequency
|
|
318
|
-
# writeduty_cycle = float(duty_cycle) # rounding the digits
|
|
319
|
-
# writeduty_cycle = max(self.pulsedc_limits[0], min(writeduty_cycle, self.pulsedc_limits[1])) # sets writeduty_cycle within pulsedc_limits
|
|
320
|
-
# writefreq = round(freq, self.pulsef_digits) # rounding the digits
|
|
321
|
-
# writefreq = max(self.pulsef_limits[0], min(writefreq, self.pulsef_limits[1])) # sets writeduty_cycle within pulsedc_limits
|
|
322
|
-
# try:
|
|
323
|
-
# width = writeduty_cycle * 0.01 / writefreq # units of ms
|
|
324
|
-
#width = max(self.pulsew_limits[0], min(width, self.pulsew_limits[1]))
|
|
325
|
-
# width = ceil(width * 1000.0) / 1000.0
|
|
326
|
-
# width = round(width, self.pulsew_digits)
|
|
327
|
-
#self.eq.write(f'puls:freq {writefreq} KHz')
|
|
328
|
-
#self.eq.write(f'puls:widt {width} ms')
|
|
329
|
-
#xcept:
|
|
330
|
-
# self.log(f'Error while writing Duty Cycle.', log='important')
|
|
331
|
-
# self.log(f'Error while writing Pulse Frequency.', log='important')
|
|
332
|
-
# error = True
|
|
333
|
-
# return np.nan
|
|
334
|
-
#y = self.pulse(log='no')
|
|
335
|
-
### returns the actual parameters written to machine to be compared
|
|
336
|
-
#if (freq is not None) and (error == False):
|
|
337
|
-
### Checker Code
|
|
338
|
-
# if abs(y[1] - freq)< 10**(-self.pulsef_digits): self.log(f'Writing Pulse Frequency as {y[1]}.', log=log)
|
|
339
|
-
# else: self.log(f'Warning:Writing Pulse Frequency as {y[1]}, but was asked {freq}.', log='important')
|
|
340
|
-
#if (duty_cycle is not None) and (error == False):
|
|
341
|
-
### Checker Code
|
|
342
|
-
# if abs(y[2] - duty_cycle)<10**(-3): self.log(f'Writing Pulse duty cycle as {y[2]}.', log=log)
|
|
343
|
-
# else: self.log(f'Warning:Writing Pulse duty cycle as {y[2]}, but was asked {duty_cycle}.', log='important')
|
|
344
|
-
#if (on_off is not None):
|
|
345
|
-
# try:
|
|
346
|
-
# self.eq.write(f'pulm:stat {on_off}')
|
|
347
|
-
# x = self.eq
|
|
348
|
-
# y = self.pulse(log='no')
|
|
349
|
-
# if y[0] == state: self.log(f'Pulse state set to {on_off}.')
|
|
350
|
-
# else: self.log(f'Warning: Setting Pulse state to {sstate}, but was asked for {on_off}.')
|
|
351
|
-
#xept:
|
|
352
|
-
# self.log(f'Error while changing Pulse state.', log='important')
|
|
353
|
-
# error = True
|
|
354
|
-
# return np.nan
|
|
355
|
-
#if (error == False): return y
|
|
356
|
-
#else: return np.nan
|
|
357
|
-
|
|
1
|
+
### BEGIN Dependencies ###
|
|
2
|
+
import numpy as np
|
|
3
|
+
import sys
|
|
4
|
+
from barsukov.exp.exp_utils import *
|
|
5
|
+
### END Dependencies
|
|
6
|
+
|
|
7
|
+
# STATUS: f() finished, nor test it and then add more funcitons
|
|
8
|
+
|
|
9
|
+
class mwHP:
|
|
10
|
+
def __init__(self, gpib=None, visa_rm=None, logger=None, gpib_card=0, log='default', script=None):
|
|
11
|
+
# Pass the Script object, if available.
|
|
12
|
+
# If Script has no visa_rm or if no Script is passed, you'll need to pass the visa_rm=visa.ResourceManager manually.
|
|
13
|
+
# If Script has no logger or if no Script is passed, you can pass the logger manually.
|
|
14
|
+
# If no logger is passed, will simply print to screen.
|
|
15
|
+
# Change log from 'default' to 'screen', 'file', 'both', 'no'.
|
|
16
|
+
# gpib_card is per default 0. You can change, if you have multiple.
|
|
17
|
+
|
|
18
|
+
self.script = script
|
|
19
|
+
self.logger = logger
|
|
20
|
+
self.eq_default_log = log
|
|
21
|
+
self.rm = visa_rm
|
|
22
|
+
self.gpib_card = gpib_card
|
|
23
|
+
self.gpib = gpib
|
|
24
|
+
|
|
25
|
+
self.msg_deco = f'[mwHP {self.gpib_card}::{self.gpib}]'
|
|
26
|
+
#print( 'visa_rm is ', visa_rm )
|
|
27
|
+
#print( 'script is ', script )
|
|
28
|
+
self.eq = initialize_gpib(self) # This will initialize self.eq = visa.open_resource()
|
|
29
|
+
self.log( f'Initialized: {self.identify()}', log='important' ) # This is the 'welcome message' and a check if communication works.
|
|
30
|
+
|
|
31
|
+
self.f_digits = 9 # Digits of precision of mw frequency
|
|
32
|
+
self.f_limits = [0.01, 20.5] # Lower and upper GHz limits
|
|
33
|
+
self.p_digits = 1 #TODO -- Digits of precision of mw power
|
|
34
|
+
self.p_limits = [-15.0, 17.0] #TODO -- Lower and upper __ limits
|
|
35
|
+
self.pulsef_digits = 3 # digits in KHz
|
|
36
|
+
self.pulsew_digits = 3 # digits in ms
|
|
37
|
+
self.pulsef_limits = [0.016, 500]
|
|
38
|
+
self.pulsew_limits = [0.001, 65.53] # digits in ms
|
|
39
|
+
self.pulsedc_limits = [0, 100]
|
|
40
|
+
|
|
41
|
+
def disconnect(self):
|
|
42
|
+
eq_disconnect(self)
|
|
43
|
+
|
|
44
|
+
def reconnect(self):
|
|
45
|
+
eq_reconnect(self)
|
|
46
|
+
|
|
47
|
+
### BEGIN The definition of the following functions may be specific to this equipment.
|
|
48
|
+
def query(self, cmd):
|
|
49
|
+
return self.eq.query(cmd)
|
|
50
|
+
|
|
51
|
+
def write(self, cmd):
|
|
52
|
+
return self.eq.write(cmd)
|
|
53
|
+
|
|
54
|
+
def identify(self):
|
|
55
|
+
return str(self.eq.query('*IDN?'))
|
|
56
|
+
### END The definition of the following functions may be specific to this equipment.
|
|
57
|
+
|
|
58
|
+
def log(self, msg, log=None):
|
|
59
|
+
if log is None: log=self.eq_default_log
|
|
60
|
+
log_in_eq(self, msg, log=log)
|
|
61
|
+
### END These functions could be shared across all equipment.
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def f(self, f=None, log=None, check=False):
|
|
65
|
+
### Always has a return! Which is frequency in GHz.
|
|
66
|
+
### f() reads and returns the frequency in GHz.
|
|
67
|
+
### f(10) writes frequency to 10 GHz.
|
|
68
|
+
### f(10) returns the frequency that was actually sent to equipment.
|
|
69
|
+
### f(10, check=True) returns the frequency queried after writing.
|
|
70
|
+
### Do set log='no' to avoid latency for repeated calls.
|
|
71
|
+
if log is None: log=self.eq_default_log
|
|
72
|
+
if f is None:
|
|
73
|
+
try:
|
|
74
|
+
y = self.eq.query('freq?')
|
|
75
|
+
y = float(y)/1e9 # Is the frequency returned in GHz??
|
|
76
|
+
self.log(f'Reading f as {y} GHz.', log=log)
|
|
77
|
+
return y
|
|
78
|
+
except:
|
|
79
|
+
self.log(f'Error while reading Frequency.', log='important')
|
|
80
|
+
return np.nan
|
|
81
|
+
else:
|
|
82
|
+
try:
|
|
83
|
+
x = round(f, self.f_digits) # rounding the digits
|
|
84
|
+
x = max(self.f_limits[0], min(x, self.f_limits[1])) # sets x within f_limits
|
|
85
|
+
self.eq.write(f'freq {x} GHz')
|
|
86
|
+
if check: y = self.f(log='no')
|
|
87
|
+
else: y = x
|
|
88
|
+
print(y, f)
|
|
89
|
+
if abs(y-f)<10.0**(-self.f_digits): self.log(f'Writing f as {x}.', log=log)
|
|
90
|
+
else: self.log(f'Warning: writing Frequency as {x}, but was asked {f}.', log='important')
|
|
91
|
+
return y
|
|
92
|
+
except:
|
|
93
|
+
self.log(f'Error while writing Frequency as {f}.', log='important')
|
|
94
|
+
return np.nan
|
|
95
|
+
|
|
96
|
+
def p(self, p=None, log=None, check=False):
|
|
97
|
+
### Always has a return! Which is the power in dBm.
|
|
98
|
+
### p() reads and returns the power in dBm.
|
|
99
|
+
### p(1) writes power to 1 dBm.
|
|
100
|
+
### p(1) returns the power that was actually sent to equipment.
|
|
101
|
+
### p(1, check=True) returns the power queried after writing
|
|
102
|
+
### Do set log='no' to avoid latency for repeated calls.
|
|
103
|
+
if log is None: log=self.eq_default_log
|
|
104
|
+
if p is None:
|
|
105
|
+
try:
|
|
106
|
+
y = self.eq.query('pow?')
|
|
107
|
+
y = float(y)
|
|
108
|
+
self.log(f'Reading p as {y} dBm.', log=log)
|
|
109
|
+
return y
|
|
110
|
+
except:
|
|
111
|
+
self.log(f'Error while reading Power.', log='important')
|
|
112
|
+
return np.nan
|
|
113
|
+
else:
|
|
114
|
+
try:
|
|
115
|
+
x = round(p, self.p_digits) # rounding the digits
|
|
116
|
+
x = max(self.p_limits[0], min(x, self.p_limits[1])) # sets x within p_limits
|
|
117
|
+
self.eq.write(f'pow {x} dBm')
|
|
118
|
+
if check: y = self.p(log='no')
|
|
119
|
+
else: y = x
|
|
120
|
+
if abs(y-p)<10**(-self.p_digits): self.log(f'Writing p as {x}.', log=log)
|
|
121
|
+
else: self.log(f'Warning: writing Power as {x}, but was asked {p}.', log='important')
|
|
122
|
+
return y
|
|
123
|
+
except:
|
|
124
|
+
self.log(f'Error while writing Power as {p}.', log='important')
|
|
125
|
+
return np.nan
|
|
126
|
+
|
|
127
|
+
def output(self, state=None, log=None, check=False):
|
|
128
|
+
### Always has a return! Which is the state of Output.
|
|
129
|
+
### output() reads and returns the state of Output.
|
|
130
|
+
### output(1) writes state of Output to ON.
|
|
131
|
+
### output(1) returns the state that was actually sent to equipment.
|
|
132
|
+
### output(1, check=True) returns the state queried after writing
|
|
133
|
+
if log is None: log=self.eq_default_log
|
|
134
|
+
if state is None:
|
|
135
|
+
try:
|
|
136
|
+
y = self.eq.query('output?')
|
|
137
|
+
y = int(y)
|
|
138
|
+
self.log(f'Output is {y}.')
|
|
139
|
+
return y
|
|
140
|
+
except:
|
|
141
|
+
self.log(f'Error while reading Output.', log='important')
|
|
142
|
+
return np.nan
|
|
143
|
+
else:
|
|
144
|
+
if (state == 1) or (state == 'on') or (state=='ON') or (state=='On'): sstate = 1
|
|
145
|
+
else: sstate = 0
|
|
146
|
+
try:
|
|
147
|
+
self.eq.write(f'output {sstate}')
|
|
148
|
+
if check: y=self.output(log='no')
|
|
149
|
+
else: y = sstate
|
|
150
|
+
if y == state: self.log(f'Output set to {sstate}.')
|
|
151
|
+
else: self.log(f'Warning: Setting Output to {sstate}, but was asked for {state}.')
|
|
152
|
+
return y
|
|
153
|
+
except:
|
|
154
|
+
self.log(f'Error while changing Output state.', log='important')
|
|
155
|
+
return np.nan
|
|
156
|
+
|
|
157
|
+
def pulse(self, f=None, duty=None, log=None):
|
|
158
|
+
if log is None: log=self.eq_default_log
|
|
159
|
+
if f is None and duty is None:
|
|
160
|
+
T = float(self.eq.query('puls:per?')) * 10.0**3
|
|
161
|
+
f = 1.0 / T
|
|
162
|
+
w = float(self.eq.query('puls:widt?')) * 10.0**3
|
|
163
|
+
duty = w / T * 100.0
|
|
164
|
+
y = self.eq.query('pulm:stat?')
|
|
165
|
+
y = int(y)
|
|
166
|
+
x = self.eq.query('pulm:sour?')
|
|
167
|
+
x = x[:-1].lower()
|
|
168
|
+
self.log(f'Pulse Frequency {f} KHz, duty-cycle {duty}%. state {y}, source {x}.', log=log)
|
|
169
|
+
return f, duty
|
|
170
|
+
else:
|
|
171
|
+
if f is None and duty is not None:
|
|
172
|
+
duty_write = max(self.pulsedc_limits[0], min(float(duty), self.pulsedc_limits[1]))
|
|
173
|
+
T = float(self.eq.query('puls:per?')) * 10.0**3
|
|
174
|
+
w = duty_write * T / 100.0
|
|
175
|
+
self.eq.write(f'puls:widt {w} ms')
|
|
176
|
+
elif f is not None and duty is None:
|
|
177
|
+
f_write = max(self.pulsef_limits[0], min(float(f), self.pulsef_limits[1]))
|
|
178
|
+
duty_write = 50.0
|
|
179
|
+
T = 1.0 / f
|
|
180
|
+
w = duty_write * T / 100.0
|
|
181
|
+
self.eq.write(f'puls:per {T} ms')
|
|
182
|
+
self.eq.write(f'puls:widt {w} ms')
|
|
183
|
+
elif f is not None and duty is not None:
|
|
184
|
+
f_write = max(self.pulsef_limits[0], min(float(f), self.pulsef_limits[1]))
|
|
185
|
+
duty_write = max(self.pulsedc_limits[0], min(float(duty), self.pulsedc_limits[1]))
|
|
186
|
+
T = 1.0 / f
|
|
187
|
+
w = duty_write * T / 100.0
|
|
188
|
+
self.eq.write(f'puls:per {T} ms')
|
|
189
|
+
self.eq.write(f'puls:widt {w} ms')
|
|
190
|
+
check = self.pulse()
|
|
191
|
+
return check
|