ionpulse_sequence_generator 2.4.1__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 ionpulse_sequence_generator might be problematic. Click here for more details.
- ionpulse_sequence_generator/__init__.py +91 -0
- ionpulse_sequence_generator/base/__init__.py +0 -0
- ionpulse_sequence_generator/base/configuration.py +23 -0
- ionpulse_sequence_generator/base/header.py +90 -0
- ionpulse_sequence_generator/base/jsonexportable.py +264 -0
- ionpulse_sequence_generator/event/__init__.py +0 -0
- ionpulse_sequence_generator/event/ddspidstatechange.py +65 -0
- ionpulse_sequence_generator/event/dioevent.py +73 -0
- ionpulse_sequence_generator/event/event.py +84 -0
- ionpulse_sequence_generator/event/multitonerfevent.py +139 -0
- ionpulse_sequence_generator/event/qubitevent.py +66 -0
- ionpulse_sequence_generator/event/readout.py +239 -0
- ionpulse_sequence_generator/event/singletonerfevent.py +185 -0
- ionpulse_sequence_generator/event/wait.py +63 -0
- ionpulse_sequence_generator/event/waveform.py +54 -0
- ionpulse_sequence_generator/hardware/__init__.py +0 -0
- ionpulse_sequence_generator/hardware/channel.py +115 -0
- ionpulse_sequence_generator/hardware/device.py +184 -0
- ionpulse_sequence_generator/hardware/hardware.py +780 -0
- ionpulse_sequence_generator/hardware/readout.py +500 -0
- ionpulse_sequence_generator/hardware/system.py +213 -0
- ionpulse_sequence_generator/hardware/units.py +97 -0
- ionpulse_sequence_generator/parameter/__init__.py +0 -0
- ionpulse_sequence_generator/parameter/parameter.py +479 -0
- ionpulse_sequence_generator/parameter/pid_parameter.py +118 -0
- ionpulse_sequence_generator/parameter/spline_parameter.py +370 -0
- ionpulse_sequence_generator/py.typed +0 -0
- ionpulse_sequence_generator/sequence/__init__.py +0 -0
- ionpulse_sequence_generator/sequence/conditional.py +121 -0
- ionpulse_sequence_generator/sequence/loop.py +108 -0
- ionpulse_sequence_generator/sequence/sequence.py +882 -0
- ionpulse_sequence_generator/utils/__init__.py +0 -0
- ionpulse_sequence_generator/utils/logging.py +96 -0
- ionpulse_sequence_generator/utils/utils.py +38 -0
- ionpulse_sequence_generator-2.4.1.dist-info/METADATA +52 -0
- ionpulse_sequence_generator-2.4.1.dist-info/RECORD +37 -0
- ionpulse_sequence_generator-2.4.1.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,500 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
from enum import Enum
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
import numpy as np
|
|
6
|
+
|
|
7
|
+
from ionpulse_sequence_generator.hardware.channel import ChannelMask
|
|
8
|
+
from ionpulse_sequence_generator.hardware.hardware import DIOHardware
|
|
9
|
+
from ionpulse_sequence_generator.utils.utils import error_if_false, is_not_sparse
|
|
10
|
+
|
|
11
|
+
logger = logging.getLogger(__name__)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class ReadoutPostprocessingMethod(Enum):
|
|
15
|
+
"""
|
|
16
|
+
# ReadoutPostprocessingMethod
|
|
17
|
+
used for Discriminators to pass a postprocessing option.
|
|
18
|
+
- NONE: readout channel will not be processed into a result
|
|
19
|
+
- AVERAGE: result will be the avereage of the readout channel
|
|
20
|
+
- SUM: result will be the sum of the readout channel
|
|
21
|
+
- VECTOR: readout channel will be processed into a vector channel
|
|
22
|
+
- CUSTOM: custom implementation by the user in ionpulse_sw
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
NONE = 0
|
|
26
|
+
AVERAGE = 1
|
|
27
|
+
SUM = 2
|
|
28
|
+
VECTOR = 3
|
|
29
|
+
CUSTOM = 4
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class PlotWindowType(Enum):
|
|
33
|
+
NONE = "none"
|
|
34
|
+
HISTOGRAM = "histogram"
|
|
35
|
+
READOUT = "readout"
|
|
36
|
+
VECTOR = "vector"
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class PlotWindow:
|
|
40
|
+
"""PlotWindow to plot"""
|
|
41
|
+
|
|
42
|
+
def __init__(self, name: str, window_type: PlotWindowType, type_based_index: int) -> None:
|
|
43
|
+
self._name = name
|
|
44
|
+
self.type = window_type
|
|
45
|
+
self._type_based_index = type_based_index
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class DataChannel:
|
|
49
|
+
def __init__(self, name: str, index: int) -> None:
|
|
50
|
+
self._name = name
|
|
51
|
+
self._index = index
|
|
52
|
+
|
|
53
|
+
def to_json(self) -> int:
|
|
54
|
+
return self._index
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class PMTChannel(DataChannel):
|
|
58
|
+
"""PMT Channel to retrieve data from"""
|
|
59
|
+
|
|
60
|
+
def __init__(self, name: str, index: int, timestamp: bool) -> None:
|
|
61
|
+
"""
|
|
62
|
+
Args:
|
|
63
|
+
name (_type_): Name of the ShotChannel
|
|
64
|
+
plot (PlotWindow): PlotWindow
|
|
65
|
+
"""
|
|
66
|
+
super().__init__(name, index)
|
|
67
|
+
self._timestamp = timestamp
|
|
68
|
+
|
|
69
|
+
def get_mask(self) -> int:
|
|
70
|
+
return 1 << self._index
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
class CameraChannel(DataChannel):
|
|
74
|
+
"""PMT Channel to retrieve data from"""
|
|
75
|
+
|
|
76
|
+
def __init__(self, name: str, index: int, n_ions_max: int) -> None:
|
|
77
|
+
"""
|
|
78
|
+
Args:
|
|
79
|
+
name (_type_): Name of the ShotChannel
|
|
80
|
+
plot (PlotWindow): PlotWindow
|
|
81
|
+
"""
|
|
82
|
+
super().__init__(name, index)
|
|
83
|
+
self._n_ions_max = n_ions_max
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
class ShotChannel(DataChannel):
|
|
87
|
+
"""ShotChannel to retrieve PMT data"""
|
|
88
|
+
|
|
89
|
+
def __init__(self, name: str, plot: PlotWindow, index: int) -> None:
|
|
90
|
+
"""
|
|
91
|
+
Args:
|
|
92
|
+
name (_type_): Name of the ShotChannel
|
|
93
|
+
plot (PlotWindow): PlotWindow
|
|
94
|
+
"""
|
|
95
|
+
super().__init__(name, index)
|
|
96
|
+
self._plot_window = plot
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
class ReadoutChannel(DataChannel):
|
|
100
|
+
"""ReadoutChannel to retrieve processed data"""
|
|
101
|
+
|
|
102
|
+
def __init__(
|
|
103
|
+
self, name: str, plot: PlotWindow, postprocessing_method: ReadoutPostprocessingMethod, index: int
|
|
104
|
+
) -> None:
|
|
105
|
+
"""
|
|
106
|
+
Args:
|
|
107
|
+
name (_type_): Name of the ReadoutChannel
|
|
108
|
+
plot (PlotWindow): PlotWindow
|
|
109
|
+
postprocessing_method (ReadoutPostprocessingMethod): Postprocessing method
|
|
110
|
+
to be applied at the end of the sequence.
|
|
111
|
+
"""
|
|
112
|
+
super().__init__(name, index)
|
|
113
|
+
self._plot_window = plot
|
|
114
|
+
self._postprocessing_method = postprocessing_method
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
class VectorChannel(DataChannel):
|
|
118
|
+
"""ShotChannel to retrieve vector data"""
|
|
119
|
+
|
|
120
|
+
def __init__(self, name: str, plot: PlotWindow, index: int) -> None:
|
|
121
|
+
"""
|
|
122
|
+
Args:
|
|
123
|
+
name (_type_): Name of the VectorChannel
|
|
124
|
+
plot (PlotWindow): PlotWindow
|
|
125
|
+
"""
|
|
126
|
+
super().__init__(name, index)
|
|
127
|
+
self._plot_window = plot
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
class Readout:
|
|
131
|
+
"""
|
|
132
|
+
# Readout
|
|
133
|
+
collects readout channel definitions, plot channels for ionizer and used readout channels.
|
|
134
|
+
Implements checking methods to ensure that used channels and defined channels overlap.
|
|
135
|
+
"""
|
|
136
|
+
|
|
137
|
+
def __init__(self) -> None:
|
|
138
|
+
### User input elements
|
|
139
|
+
self.shot_channels: dict[str, ShotChannel] = {}
|
|
140
|
+
"""Plot windows to store plot indices"""
|
|
141
|
+
self.readout_channels: dict[str, ReadoutChannel] = {}
|
|
142
|
+
"""Plot windows to store plot indices"""
|
|
143
|
+
self.vector_channels: dict[str, VectorChannel] = {}
|
|
144
|
+
"""Plot windows to store plot indices"""
|
|
145
|
+
self.plot_windows: dict[str, PlotWindow] = {}
|
|
146
|
+
"""Plot windows to store plot indices"""
|
|
147
|
+
self.pmt_channels: dict[str, PMTChannel] = {}
|
|
148
|
+
"""PMTChannels to process from"""
|
|
149
|
+
self.camera_channels: dict[str, CameraChannel] = {}
|
|
150
|
+
"""CameraChannels to process from"""
|
|
151
|
+
|
|
152
|
+
### Processed from user input
|
|
153
|
+
# Comment on names:
|
|
154
|
+
# x_names ... provided by the user, naming a channel
|
|
155
|
+
# x_plot_indices ... provided by the user, setting a plot index
|
|
156
|
+
# _num_used_x ... collected from events when the sequence is exported
|
|
157
|
+
|
|
158
|
+
self._shot_channel_names: list[str] = []
|
|
159
|
+
"""Names of all shot channels, provided by the user"""
|
|
160
|
+
self._readout_channel_names: list[str] = []
|
|
161
|
+
"""Names of all readout channels, provided by the user"""
|
|
162
|
+
self._readout_postprocessing_method: list[ReadoutPostprocessingMethod] = []
|
|
163
|
+
"""Readout postprocessing method per readout channel, provided by the user"""
|
|
164
|
+
self._vector_channel_names: list[str] = []
|
|
165
|
+
"""Names of all vector channels, provided by the user"""
|
|
166
|
+
self._shot_channel_plot_index: list[int] = []
|
|
167
|
+
"""Plot indices of all shot channels, provided by the user"""
|
|
168
|
+
self._readout_channel_plot_index: list[int] = []
|
|
169
|
+
"""Plot indices of all readout channels, provided by the user"""
|
|
170
|
+
self._vector_channel_plot_index: list[int] = []
|
|
171
|
+
"""Plot indices of all vector channels, provided by the user"""
|
|
172
|
+
self._timestamp_channel_mask: int = 0
|
|
173
|
+
"""Channel mask for PMT channels which should be enabled for timestamping."""
|
|
174
|
+
|
|
175
|
+
### Processed from sequence export
|
|
176
|
+
self._num_used_pmt_channels: set[int] = set()
|
|
177
|
+
"""PMT channels used in the sequence, filled by Events"""
|
|
178
|
+
self._num_used_camera_channels: set[int] = set()
|
|
179
|
+
"""Camera channels used in the sequence, filled by Events"""
|
|
180
|
+
self._num_used_shot_channels: set[int] = set()
|
|
181
|
+
"""Shot channels used in the sequence, filled by Events"""
|
|
182
|
+
self._num_used_readout_channels: set[int] = set()
|
|
183
|
+
"""Readout channels used in the sequence, filled by Events"""
|
|
184
|
+
self._num_used_result_channels: set[int] = set()
|
|
185
|
+
"""Result channels used in the sequence, filled by Events"""
|
|
186
|
+
self._num_used_vect_channels: set[int] = set()
|
|
187
|
+
"""Vector channels used in the sequence, filled by Events"""
|
|
188
|
+
self._result_channel_names: list[int] = []
|
|
189
|
+
"""Result channel names, processed from readout channel names"""
|
|
190
|
+
self._result_channel_plot_index: list[int] = []
|
|
191
|
+
"""Result channel plot indices, processed from readout channel plot indices"""
|
|
192
|
+
|
|
193
|
+
self._ch_mask = ChannelMask()
|
|
194
|
+
# create empty plot window
|
|
195
|
+
self.plot_windows["None"] = PlotWindow(name="None", window_type=PlotWindowType.NONE, type_based_index=0)
|
|
196
|
+
|
|
197
|
+
def create_plot_window(self, name: str, plot_window_type: PlotWindowType = PlotWindowType.READOUT) -> PlotWindow:
|
|
198
|
+
if name in self.plot_windows:
|
|
199
|
+
raise RuntimeError(f"Plot window with name {name!r} already exists")
|
|
200
|
+
|
|
201
|
+
window = PlotWindow(
|
|
202
|
+
name=name,
|
|
203
|
+
window_type=plot_window_type,
|
|
204
|
+
type_based_index=len([item for item in self.plot_windows.values() if item.type == plot_window_type]),
|
|
205
|
+
)
|
|
206
|
+
self.plot_windows[name] = window
|
|
207
|
+
return window
|
|
208
|
+
|
|
209
|
+
def create_readout_channel(
|
|
210
|
+
self,
|
|
211
|
+
name: str,
|
|
212
|
+
plot: PlotWindow,
|
|
213
|
+
postprocessing_method: ReadoutPostprocessingMethod,
|
|
214
|
+
) -> ReadoutChannel:
|
|
215
|
+
if plot.type not in (PlotWindowType.READOUT, PlotWindowType.NONE):
|
|
216
|
+
raise Exception(f"Cannot add a readout channel to a plot window of type {plot.type}")
|
|
217
|
+
|
|
218
|
+
channel = ReadoutChannel(name, plot, postprocessing_method, len(self.readout_channels))
|
|
219
|
+
self.readout_channels[name] = channel
|
|
220
|
+
return channel
|
|
221
|
+
|
|
222
|
+
def create_shot_channel(
|
|
223
|
+
self,
|
|
224
|
+
name: str,
|
|
225
|
+
plot: PlotWindow,
|
|
226
|
+
) -> ShotChannel:
|
|
227
|
+
if plot.type not in (PlotWindowType.HISTOGRAM, PlotWindowType.NONE):
|
|
228
|
+
raise Exception(f"Cannot add a shot channel to a plot window of type {plot.type}")
|
|
229
|
+
|
|
230
|
+
# Note: Ionizer currently can't handle plotting of shot channels separately
|
|
231
|
+
channel = ShotChannel(name, plot, len(self.shot_channels))
|
|
232
|
+
self.shot_channels[name] = channel
|
|
233
|
+
return channel
|
|
234
|
+
|
|
235
|
+
def create_vector_channel(self, name: str, plot: PlotWindow) -> VectorChannel:
|
|
236
|
+
if plot.type not in (PlotWindowType.VECTOR, PlotWindowType.NONE):
|
|
237
|
+
raise Exception(f"Cannot add a vector channel to a plot window of type {plot.type}")
|
|
238
|
+
|
|
239
|
+
channel = VectorChannel(name, plot, len(self.vector_channels))
|
|
240
|
+
self.vector_channels[name] = channel
|
|
241
|
+
return channel
|
|
242
|
+
|
|
243
|
+
def create_pmt_channel(self, name: str, index: int, timestamp: bool = False) -> PMTChannel:
|
|
244
|
+
channel = PMTChannel(name, index, timestamp)
|
|
245
|
+
self.pmt_channels[name] = channel
|
|
246
|
+
return channel
|
|
247
|
+
|
|
248
|
+
def create_camera_channel(self, name: str) -> CameraChannel:
|
|
249
|
+
channel = CameraChannel(name, 0, DIOHardware._n_cam_ions_max)
|
|
250
|
+
self.camera_channels[name] = channel
|
|
251
|
+
return channel
|
|
252
|
+
|
|
253
|
+
def channel(self) -> ChannelMask:
|
|
254
|
+
"""
|
|
255
|
+
Returns:
|
|
256
|
+
ChannelMask: The channel assigned for the readout, attached to the MAIN device.
|
|
257
|
+
"""
|
|
258
|
+
return self._ch_mask
|
|
259
|
+
|
|
260
|
+
def process_result_channels(self) -> tuple[set[int], set[int]]:
|
|
261
|
+
# process defined channels into result channels to check against used channels
|
|
262
|
+
# processed result channels to be read by the library
|
|
263
|
+
self._result_channel_names = []
|
|
264
|
+
self._result_channel_plot_index = []
|
|
265
|
+
result_channels_used_in_postprocessing: set[int] = set()
|
|
266
|
+
vect_channels_used_in_postprocessing: set[int] = set()
|
|
267
|
+
for i in range(len(self._readout_postprocessing_method)):
|
|
268
|
+
match self._readout_postprocessing_method[i]:
|
|
269
|
+
case ReadoutPostprocessingMethod.AVERAGE:
|
|
270
|
+
self._result_channel_names.append(self._readout_channel_names[i]) # type: ignore
|
|
271
|
+
self._result_channel_plot_index.append(self._readout_channel_plot_index[i])
|
|
272
|
+
result_channels_used_in_postprocessing.add(i)
|
|
273
|
+
case ReadoutPostprocessingMethod.SUM:
|
|
274
|
+
self._result_channel_names.append(self._readout_channel_names[i]) # type: ignore
|
|
275
|
+
self._result_channel_plot_index.append(self._readout_channel_plot_index[i])
|
|
276
|
+
result_channels_used_in_postprocessing.add(i)
|
|
277
|
+
case ReadoutPostprocessingMethod.VECTOR:
|
|
278
|
+
vect_channels_used_in_postprocessing.add(i)
|
|
279
|
+
case _:
|
|
280
|
+
pass
|
|
281
|
+
return result_channels_used_in_postprocessing, vect_channels_used_in_postprocessing
|
|
282
|
+
|
|
283
|
+
def check_ionizer_plotting(self) -> None:
|
|
284
|
+
# check that all channels passed to ionizer are plotted (for now, until we can disable plotting)
|
|
285
|
+
# error_if_false(
|
|
286
|
+
# np.any(np.array(self._shot_channel_plot_index) == -1),
|
|
287
|
+
# "All shot channels passed to ionizer must have a valid plot window assigned.",
|
|
288
|
+
# )
|
|
289
|
+
# error_if_false(
|
|
290
|
+
# np.any(np.array(self._result_channel_plot_index) == -1),
|
|
291
|
+
# "All result channels passed to ionizer must have a valid plot window assigned.",
|
|
292
|
+
# )
|
|
293
|
+
# error_if_false(
|
|
294
|
+
# np.any(np.array(self._vector_channel_plot_index) == -1),
|
|
295
|
+
# "All vector channels passed to ionizer must have a valid plot window assigned.",
|
|
296
|
+
# )
|
|
297
|
+
pass
|
|
298
|
+
|
|
299
|
+
def check_plot_indices(self) -> None:
|
|
300
|
+
error_if_false(
|
|
301
|
+
len(self._shot_channel_names) == len(self._shot_channel_plot_index),
|
|
302
|
+
"Number of shot channels does not match the number of plot indices defined.",
|
|
303
|
+
)
|
|
304
|
+
error_if_false(
|
|
305
|
+
len(self._readout_channel_names) == len(self._readout_channel_plot_index),
|
|
306
|
+
"Number of readout channels does not match the number of plot indices defined.",
|
|
307
|
+
)
|
|
308
|
+
error_if_false(
|
|
309
|
+
len(self._vector_channel_names) == len(self._vector_channel_plot_index),
|
|
310
|
+
"Number of vector channels does not match the number of plot indices defined.",
|
|
311
|
+
)
|
|
312
|
+
|
|
313
|
+
def check_sparse_channels(self) -> None:
|
|
314
|
+
# error_if_false(
|
|
315
|
+
# is_not_sparse(self._num_used_shot_channels),
|
|
316
|
+
# f"Used shot channels can not be sparse, using {np.sort(np.array(list(self._num_used_shot_channels)))}",
|
|
317
|
+
# )
|
|
318
|
+
error_if_false(
|
|
319
|
+
is_not_sparse(self._num_used_readout_channels),
|
|
320
|
+
f"Used shot channels can not be sparse, using {np.sort(np.array(list(self._num_used_readout_channels)))}",
|
|
321
|
+
)
|
|
322
|
+
# Note: result channels can not be sparse, no need to check
|
|
323
|
+
error_if_false(
|
|
324
|
+
is_not_sparse(self._num_used_vect_channels),
|
|
325
|
+
f"Used shot channels can not be sparse, using {np.sort(np.array(list(self._num_used_vect_channels)))}",
|
|
326
|
+
)
|
|
327
|
+
|
|
328
|
+
def check_channel_ranges(self) -> None:
|
|
329
|
+
# check that all used channels are actually within range
|
|
330
|
+
if len(list(self._num_used_shot_channels)) != 0:
|
|
331
|
+
error_if_false(
|
|
332
|
+
np.max(list(self._num_used_shot_channels)) < len(self._shot_channel_names),
|
|
333
|
+
f"Using shot channel {np.max(list(self._num_used_shot_channels))} \
|
|
334
|
+
outside of maximum defined range of {len(self._shot_channel_names)}",
|
|
335
|
+
)
|
|
336
|
+
if len(list(self._num_used_result_channels)) != 0:
|
|
337
|
+
error_if_false(
|
|
338
|
+
np.max(list(self._num_used_result_channels)) < len(self._result_channel_names),
|
|
339
|
+
f"Using shot channel {np.max(list(self._num_used_result_channels))} \
|
|
340
|
+
outside of maximum defined range of {len(self._result_channel_names)}",
|
|
341
|
+
)
|
|
342
|
+
if len(list(self._num_used_vect_channels)) != 0:
|
|
343
|
+
error_if_false(
|
|
344
|
+
np.max(list(self._num_used_vect_channels)) < len(self._vector_channel_names),
|
|
345
|
+
f"Using shot channel {np.max(list(self._num_used_vect_channels))} \
|
|
346
|
+
outside of maximum defined range of {len(self._vector_channel_names)}",
|
|
347
|
+
)
|
|
348
|
+
|
|
349
|
+
def check_sparse_plotwindows(self) -> None:
|
|
350
|
+
# check if used plot windows are sparse (will lead to ionizer errors if they are)
|
|
351
|
+
# error_if_false(
|
|
352
|
+
# is_not_sparse(set(self._shot_channel_plot_index)),
|
|
353
|
+
# f"Shot channel plot windows can not be sparse. {set(self._shot_channel_plot_index)}",
|
|
354
|
+
# )
|
|
355
|
+
error_if_false(
|
|
356
|
+
is_not_sparse(set(self._readout_channel_plot_index)),
|
|
357
|
+
f"Readout channel plot windows can not be sparse. {set(self._readout_channel_plot_index)}",
|
|
358
|
+
)
|
|
359
|
+
error_if_false(
|
|
360
|
+
is_not_sparse(set(self._vector_channel_plot_index)),
|
|
361
|
+
f"Vector channel plot windows can not be sparse. {set(self._vector_channel_plot_index)}",
|
|
362
|
+
)
|
|
363
|
+
|
|
364
|
+
def log_unused_warnings(self, converted_vect_channels: set[int]) -> None:
|
|
365
|
+
if len(self._num_used_shot_channels) is not len(self._shot_channel_names):
|
|
366
|
+
logger.warning(
|
|
367
|
+
"Used and specified shot channels do not match. Check PopPMTFIFO events and shot_channel_names!"
|
|
368
|
+
)
|
|
369
|
+
if len(self._num_used_readout_channels) is not len(self._readout_channel_names):
|
|
370
|
+
logger.warning(
|
|
371
|
+
"Used and specified readout channels do not match. \
|
|
372
|
+
Check Discriminator events and readout_channel_names!"
|
|
373
|
+
)
|
|
374
|
+
if len(converted_vect_channels) is not len(self._vector_channel_names) - len(self._num_used_vect_channels):
|
|
375
|
+
logger.warning("Used and specified vector channels do not match.")
|
|
376
|
+
|
|
377
|
+
def build_name_index_lists(self) -> None:
|
|
378
|
+
for shot_channel in self.shot_channels.values():
|
|
379
|
+
self._shot_channel_names.append(shot_channel._name)
|
|
380
|
+
self._shot_channel_plot_index.append(shot_channel._plot_window._type_based_index)
|
|
381
|
+
|
|
382
|
+
for vector_channel in self.vector_channels.values():
|
|
383
|
+
self._vector_channel_names.append(vector_channel._name)
|
|
384
|
+
self._vector_channel_plot_index.append(vector_channel._plot_window._type_based_index)
|
|
385
|
+
|
|
386
|
+
for readout_channel in self.readout_channels.values():
|
|
387
|
+
self._readout_channel_names.append(readout_channel._name)
|
|
388
|
+
self._readout_channel_plot_index.append(readout_channel._plot_window._type_based_index)
|
|
389
|
+
self._readout_postprocessing_method.append(readout_channel._postprocessing_method)
|
|
390
|
+
|
|
391
|
+
self._timestamp_channel_mask = 0
|
|
392
|
+
for pmt_channel in self.pmt_channels.values():
|
|
393
|
+
self._timestamp_channel_mask |= pmt_channel.get_mask()
|
|
394
|
+
|
|
395
|
+
def check(self) -> None:
|
|
396
|
+
"""
|
|
397
|
+
Check readout channels against used readout channels.
|
|
398
|
+
Must be called after the main sequence has been exported with this header object.
|
|
399
|
+
"""
|
|
400
|
+
# check postprocessing
|
|
401
|
+
error_if_false(
|
|
402
|
+
len(self._readout_channel_names) == len(self._readout_postprocessing_method),
|
|
403
|
+
"Number of readout channels does not match the number of postprocessing methods.",
|
|
404
|
+
)
|
|
405
|
+
|
|
406
|
+
self.check_plot_indices()
|
|
407
|
+
self.check_sparse_channels()
|
|
408
|
+
self.check_channel_ranges()
|
|
409
|
+
|
|
410
|
+
result_channels_used_in_postprocessing, vect_channels_used_in_postprocessing = self.process_result_channels()
|
|
411
|
+
self.check_ionizer_plotting()
|
|
412
|
+
|
|
413
|
+
# check that assigned vect channels are not used for timestamps
|
|
414
|
+
for ch in self._num_used_vect_channels:
|
|
415
|
+
error_if_false(
|
|
416
|
+
ch <= len(vect_channels_used_in_postprocessing),
|
|
417
|
+
f"Vector channel {ch} is used for timestamps and results!",
|
|
418
|
+
)
|
|
419
|
+
|
|
420
|
+
self.check_sparse_plotwindows()
|
|
421
|
+
|
|
422
|
+
# Comment on names:
|
|
423
|
+
# x_names ... provided by the user, naming a channel
|
|
424
|
+
# x_plot_indices ... provided by the user, setting a plot index
|
|
425
|
+
# _num_used_x ... collected from events when the sequence is exported
|
|
426
|
+
|
|
427
|
+
logger.info(
|
|
428
|
+
"\nReadout using\n"
|
|
429
|
+
"%3d PMT channels\n"
|
|
430
|
+
"%3d Camera channels\n"
|
|
431
|
+
"%3d/%2d Shot Channels\n"
|
|
432
|
+
"%3d/%2d Readout Channels\n"
|
|
433
|
+
"%3d/%2d Result Channels\n"
|
|
434
|
+
"%3d Timestamp Vector Channels\n"
|
|
435
|
+
"%3d/%2d Vector Channels\n",
|
|
436
|
+
len(self._num_used_camera_channels),
|
|
437
|
+
len(self._num_used_pmt_channels),
|
|
438
|
+
len(self._num_used_shot_channels),
|
|
439
|
+
len(self._shot_channel_names),
|
|
440
|
+
len(self._num_used_readout_channels),
|
|
441
|
+
len(self._readout_channel_names),
|
|
442
|
+
len(result_channels_used_in_postprocessing),
|
|
443
|
+
len(self._result_channel_names),
|
|
444
|
+
len(self._num_used_vect_channels),
|
|
445
|
+
len(vect_channels_used_in_postprocessing),
|
|
446
|
+
len(self._vector_channel_names) - len(self._num_used_vect_channels),
|
|
447
|
+
)
|
|
448
|
+
|
|
449
|
+
self.log_unused_warnings(vect_channels_used_in_postprocessing)
|
|
450
|
+
|
|
451
|
+
def to_dict(self) -> dict[str, Any]:
|
|
452
|
+
"""Used to get the channel and plot window information in Icon."""
|
|
453
|
+
|
|
454
|
+
return {
|
|
455
|
+
"readout_channel_names": list(self.readout_channels.keys()),
|
|
456
|
+
"shot_channel_names": list(self.shot_channels.keys()),
|
|
457
|
+
"vector_channel_names": list(self.vector_channels.keys()),
|
|
458
|
+
"readout_channel_windows": [
|
|
459
|
+
{
|
|
460
|
+
"name": window_name,
|
|
461
|
+
"index": window._type_based_index,
|
|
462
|
+
"type": window.type.value,
|
|
463
|
+
"channel_names": [
|
|
464
|
+
channel_name
|
|
465
|
+
for channel_name, channel in self.readout_channels.items()
|
|
466
|
+
if channel._plot_window == window
|
|
467
|
+
],
|
|
468
|
+
}
|
|
469
|
+
for window_name, window in self.plot_windows.items()
|
|
470
|
+
if window.type is PlotWindowType.READOUT
|
|
471
|
+
],
|
|
472
|
+
"shot_channel_windows": [
|
|
473
|
+
{
|
|
474
|
+
"name": window_name,
|
|
475
|
+
"index": window._type_based_index,
|
|
476
|
+
"type": window.type.value,
|
|
477
|
+
"channel_names": [
|
|
478
|
+
channel_name
|
|
479
|
+
for channel_name, channel in self.shot_channels.items()
|
|
480
|
+
if channel._plot_window == window
|
|
481
|
+
],
|
|
482
|
+
}
|
|
483
|
+
for window_name, window in self.plot_windows.items()
|
|
484
|
+
if window.type is PlotWindowType.HISTOGRAM
|
|
485
|
+
],
|
|
486
|
+
"vector_channel_windows": [
|
|
487
|
+
{
|
|
488
|
+
"name": window_name,
|
|
489
|
+
"index": window._type_based_index,
|
|
490
|
+
"type": window.type.value,
|
|
491
|
+
"channel_names": [
|
|
492
|
+
channel_name
|
|
493
|
+
for channel_name, channel in self.vector_channels.items()
|
|
494
|
+
if channel._plot_window == window
|
|
495
|
+
],
|
|
496
|
+
}
|
|
497
|
+
for window_name, window in self.plot_windows.items()
|
|
498
|
+
if window.type is PlotWindowType.VECTOR
|
|
499
|
+
],
|
|
500
|
+
}
|