Coverage for src/km3pipe/io/tests/test_online.py: 82%
72 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-23 03:15 +0000
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-23 03:15 +0000
1# Filename: test_online.py
2# pylint: disable=locally-disabled,C0111,R0904,C0301,C0103,W0212
3from km3pipe.testing import TestCase, patch, skip, data_path
4import sys
5import numpy as np
6from km3pipe.io.online import EventPump, TimeslicePump
7from km3pipe.io.hdf5 import HDF5Pump
8from os.path import join, dirname, abspath
10__author__ = "Tamas Gal"
11__copyright__ = "Copyright 2018, Tamas Gal and the KM3NeT collaboration."
12__credits__ = []
13__license__ = "MIT"
14__maintainer__ = "Tamas Gal, Johannes Schumann"
15__email__ = "tgal@km3net.de"
16__status__ = "Development"
18ONLINE_TEST_FILE = data_path("online/events_sample.root")
19ONLINE_TEST_FILE_H5 = data_path("online/events_sample.h5")
22class TestEventPump(TestCase):
23 def setUp(self):
24 self.jpp_pump = EventPump(filename=ONLINE_TEST_FILE)
25 self.h5_pump = HDF5Pump(filename=ONLINE_TEST_FILE_H5)
27 def tearDown(self):
28 self.jpp_pump.finish()
29 self.h5_pump.finish()
31 def test_event_info(self):
32 n = self.jpp_pump.n_events
33 for i in range(n):
34 h5blob = self.h5_pump[i]
35 jppblob = self.jpp_pump[i]
36 for k in h5blob["EventInfo"].dtype.names:
37 if k not in jppblob["EventInfo"].dtype.names:
38 continue
39 ref_value = h5blob["EventInfo"][k][0]
40 test_value = jppblob["EventInfo"][k][0]
41 if isinstance(ref_value, float):
42 if np.isnan(ref_value):
43 assert np.isnan(test_value) == np.isnan(ref_value)
44 else:
45 self.assertAlmostEqual(test_value, ref_value)
46 else:
47 assert ref_value == test_value
49 @skip
50 def test_hit_info(self):
51 n = self.jpp_pump.n_events
52 for i in range(n):
53 h5blob = self.h5_pump[i]
54 jppblob = self.jpp_pump[i]
55 for k in h5blob["Hits"].dtype.names:
56 ref_value = h5blob["Hits"][k][0]
57 test_value = jppblob["Hits"][k][0]
58 if isinstance(ref_value, float):
59 if np.isnan(ref_value):
60 assert np.isnan(test_value)
61 else:
62 self.assertAlmostEqual(test_value, ref_value)
63 else:
64 assert ref_value == test_value
67class TestTimeslicePump(TestCase):
68 def setUp(self):
69 self.jpp_fname = ONLINE_TEST_FILE
70 self.timeslice_pump = TimeslicePump(filename=self.jpp_fname, stream="L1")
72 def test_timeslice_info(self):
73 blob = self.timeslice_pump[0]
74 tsinfo = blob["TimesliceInfo"]
75 assert tsinfo.frame_index == 366
76 assert tsinfo.slice_id == 0
77 assert tsinfo.timestamp == 1575979236
78 assert tsinfo.nanoseconds == 600000000
79 assert tsinfo.n_frames == 69
81 def test_timeslice_hits(self):
82 blob = self.timeslice_pump[0]
83 l1hits = blob["L1Hits"]
84 counts = [
85 1421,
86 1272,
87 1533,
88 1209,
89 1311,
90 1450,
91 1102,
92 1494,
93 1410,
94 1390,
95 1225,
96 1419,
97 1474,
98 1452,
99 1589,
100 1362,
101 1577,
102 1598,
103 1891,
104 1584,
105 1571,
106 1523,
107 1696,
108 1719,
109 1540,
110 1578,
111 1656,
112 1569,
113 1422,
114 1401,
115 1262,
116 ]
117 tot = [
118 216,
119 681,
120 1222,
121 1580,
122 1484,
123 1221,
124 940,
125 887,
126 908,
127 950,
128 844,
129 736,
130 717,
131 661,
132 752,
133 716,
134 791,
135 946,
136 1089,
137 1220,
138 1484,
139 1786,
140 2265,
141 2539,
142 2932,
143 3132,
144 3201,
145 2901,
146 2403,
147 1654,
148 1056,
149 566,
150 297,
151 167,
152 94,
153 74,
154 82,
155 60,
156 50,
157 37,
158 30,
159 24,
160 24,
161 20,
162 19,
163 12,
164 15,
165 15,
166 13,
167 8,
168 5,
169 6,
170 9,
171 9,
172 7,
173 9,
174 11,
175 6,
176 5,
177 10,
178 7,
179 4,
180 7,
181 2,
182 7,
183 1,
184 4,
185 5,
186 5,
187 3,
188 3,
189 3,
190 2,
191 3,
192 2,
193 3,
194 1,
195 4,
196 3,
197 4,
198 1,
199 1,
200 2,
201 2,
202 1,
203 2,
204 3,
205 1,
206 1,
207 1,
208 2,
209 1,
210 1,
211 1,
212 1,
213 1,
214 1,
215 1,
216 1,
217 1,
218 1,
219 1,
220 1,
221 ]
222 dom_id = [
223 774,
224 244,
225 602,
226 935,
227 533,
228 878,
229 862,
230 699,
231 760,
232 1058,
233 625,
234 641,
235 621,
236 679,
237 912,
238 461,
239 925,
240 633,
241 754,
242 701,
243 767,
244 784,
245 812,
246 299,
247 605,
248 1010,
249 226,
250 892,
251 785,
252 864,
253 707,
254 540,
255 749,
256 772,
257 172,
258 748,
259 773,
260 585,
261 278,
262 656,
263 852,
264 685,
265 1041,
266 473,
267 639,
268 695,
269 837,
270 830,
271 656,
272 676,
273 486,
274 647,
275 533,
276 716,
277 649,
278 599,
279 502,
280 271,
281 629,
282 769,
283 613,
284 784,
285 705,
286 600,
287 984,
288 682,
289 243,
290 583,
291 ]
292 self.assertListEqual(
293 counts, np.unique(l1hits.channel_id, return_counts=True)[1].tolist()
294 )
295 self.assertListEqual(tot, np.unique(l1hits.tot, return_counts=True)[1].tolist())
296 self.assertListEqual(
297 dom_id, np.unique(l1hits.dom_id, return_counts=True)[1].tolist()
298 )