-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHV_mon.py
More file actions
124 lines (105 loc) · 3.41 KB
/
HV_mon.py
File metadata and controls
124 lines (105 loc) · 3.41 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
#!/usr/bin/env python3
from iceboot.iceboot_session import getParser, startIcebootSession
import os, sys
import numpy as np
import scope
import time
from addparser_iceboot import AddParser
import matplotlib.pyplot as plt
from sensorcheck import getHVV, getHVI, getTemp
from loadFPGA import loadFPGA
from utils import pathSetting
import tables
from tqdm import tqdm
def main(parser):
(options, args) = parser.parse_args()
nevents = int(options.nevents)
path = pathSetting(options,'HVMON',True)
loadFPGA(parser)
session = startIcebootSession(parser)
time.sleep(1)
channel = int(options.channel)
session.enableHV(channel)
hvv = []
hvi = []
setv = []
temp = []
HVstart = 700
HVend = 1500
waittime = 200
HVstartDelay = int(HVstart/50)
stages = np.linspace(HVstart,HVend,20)
pbar = tqdm(total = len(stages))
i = 0
while i < len(stages):
stage = stages[i]
try:
session.setDEggHV(channel,int(stage))
except:
i = 0
hvv = []
hvi = []
setv = []
temp = []
pbar.reset()
session.close()
time.sleep(1)
session = startIcebootSession(parser)
time.sleep(1)
session.enableHV(channel)
continue
for iteration in tqdm(np.arange(HVstartDelay*10+waittime if stage==HVstart else waittime),leave=False):
hvv.append(getHVV(session,channel))
hvi.append(getHVI(session,channel))
setv.append(stage)
temp.append(getTemp(session))
time.sleep(0.1)
i += 1
pbar.update(1)
pbar.close()
store_hdf(f'{path}/data.hdf',hvv,hvi,temp)
session.setDEggHV(channel,0)
session.close()
fig = plt.figure(figsize=(9.6,6.4))
ax1 = fig.add_subplot(111)
ax2 = ax1.twinx()
for i in range(len(stages)):
ax1.axvline(HVstartDelay*10+10+waittime*i,ls=':',color='magenta',alpha=0.7)
ax1.plot(np.arange(len(hvv)), hvv, label='Voltage',color='tab:blue')
ax2.plot(np.arange(len(hvv)), hvi, label='Current',color='tab:orange')
ax1.set_xlabel('Readout number')
ax1.set_ylabel('Observed Voltage [V]')
ax2.set_ylabel('Observed Current [$\mu$A]')
h1, l1 = ax1.get_legend_handles_labels()
h2, l2 = ax2.get_legend_handles_labels()
ax1.legend(h1+h2,l1+l2)
plt.tight_layout()
plt.savefig(f'{path}/hv_relation_time.pdf')
if options.b:
plt.show()
else:
plt.draw()
def store_hdf(filename, data_hvv, data_hvi, data_temp):
if not os.path.isfile(filename):
class Event(tables.IsDescription):
hvv = tables.Float32Col(shape=np.asarray(data_hvv).shape)
hvi = tables.Float32Col(shape=np.asarray(data_hvi).shape)
temp = tables.Float32Col(shape=np.asarray(data_temp).shape)
with tables.open_file(filename,'w') as f:
table = f.create_table('/','data',Event)
with tables.open_file(filename, 'a') as f:
table = f.get_node('/data')
event = table.row
event['hvv'] = data_hvv
event['hvi'] = data_hvi
event['temp'] = data_temp
event.append()
table.flush()
if __name__ == "__main__":
parser = getParser()
scope.AddParser(parser)
(options, args) = parser.parse_args()
if not options.b:
import matplotlib as mpl
mpl.use('PDF')
main(parser)