mosca 2.0.2__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.
- mosca/__init__.py +11 -0
- mosca/common/__init__.py +9 -0
- mosca/common/enums.py +79 -0
- mosca/common/logger.py +139 -0
- mosca/common/threads.py +199 -0
- mosca/common/utils.py +70 -0
- mosca/control/__init__.py +4 -0
- mosca/control/buffer.py +526 -0
- mosca/control/controller.py +278 -0
- mosca/control/datahandler.py +261 -0
- mosca/control/detectors.py +116 -0
- mosca/control/mosca.py +693 -0
- mosca/control/spectra.py +36 -0
- mosca/control/stats.py +43 -0
- mosca/control/tasks/__init__.py +3 -0
- mosca/control/tasks/background.py +118 -0
- mosca/control/tasks/rois.py +466 -0
- mosca/control/tasks/saving.py +391 -0
- mosca/control/tasks/spectrasums.py +185 -0
- mosca/control/tasks/task.py +201 -0
- mosca/control/tasks/taskmanager.py +133 -0
- mosca/devices/__init__.py +28 -0
- mosca/devices/hamamatsu/__init__.py +0 -0
- mosca/devices/hamamatsu/hamamatsu.py +88 -0
- mosca/devices/hamamatsu/hamamatsuhw.py +1298 -0
- mosca/devices/oceanoptics/__init__.py +0 -0
- mosca/devices/oceanoptics/oceanoptics.py +59 -0
- mosca/devices/oceanoptics/oceanopticshw.py +379 -0
- mosca/devices/simulation/__init__.py +0 -0
- mosca/devices/simulation/dante/__init__.py +1 -0
- mosca/devices/simulation/dante/simdante.py +33 -0
- mosca/devices/simulation/dante/simdantehw.py +506 -0
- mosca/devices/simulation/dummy/__init__.py +1 -0
- mosca/devices/simulation/dummy/dummy.py +299 -0
- mosca/devices/simulation/generator.py +607 -0
- mosca/devices/simulation/xia/__init__.py +1 -0
- mosca/devices/simulation/xia/iniparser.py +99 -0
- mosca/devices/simulation/xia/simfalconx.py +26 -0
- mosca/devices/simulation/xia/simfalconxhw.py +599 -0
- mosca/devices/xglab/__init__.py +0 -0
- mosca/devices/xglab/dante.py +126 -0
- mosca/devices/xglab/dantehw.py +1178 -0
- mosca/devices/xia/__init__.py +0 -0
- mosca/devices/xia/falconx.py +232 -0
- mosca/devices/xia/handel/__init__.py +14 -0
- mosca/devices/xia/handel/_cffi.py +62 -0
- mosca/devices/xia/handel/error.py +272 -0
- mosca/devices/xia/handel/handel_inc/handel_constants.h +127 -0
- mosca/devices/xia/handel/handel_inc/handel_errors.h +254 -0
- mosca/devices/xia/handel/handel_inc/handel_generic.h +66 -0
- mosca/devices/xia/handel/interface.py +1025 -0
- mosca/devices/xia/handel/mapping.py +107 -0
- mosca/devices/xia/handel/parser.py +62 -0
- mosca/devices/xia/handel/stats.py +85 -0
- mosca/devices/xia/mercury.py +160 -0
- mosca/devices/xia/utils.py +47 -0
- mosca/devices/xia/xia.py +575 -0
- mosca/devices/xia/xiads.py +161 -0
- mosca/mosca.py +0 -0
- mosca/tango/__init__.py +2 -0
- mosca/tango/controller.py +80 -0
- mosca/tango/main.py +163 -0
- mosca/tango/mosca.py +513 -0
- mosca/tango/moscav1.py +408 -0
- mosca/tango/shared.py +23 -0
- mosca/tango/tasks/__init__.py +0 -0
- mosca/tango/tasks/background.py +55 -0
- mosca/tango/utils.py +109 -0
- mosca-2.0.2.dist-info/METADATA +32 -0
- mosca-2.0.2.dist-info/RECORD +73 -0
- mosca-2.0.2.dist-info/WHEEL +4 -0
- mosca-2.0.2.dist-info/entry_points.txt +2 -0
- mosca-2.0.2.dist-info/licenses/LICENSE +166 -0
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
import io
|
|
2
|
+
import copy
|
|
3
|
+
import enum
|
|
4
|
+
import logging
|
|
5
|
+
import dataclasses
|
|
6
|
+
|
|
7
|
+
logger = logging.getLogger(__name__)
|
|
8
|
+
|
|
9
|
+
import numpy as np
|
|
10
|
+
from ruamel.yaml import YAML
|
|
11
|
+
|
|
12
|
+
from tango.server import device_property, attribute, command
|
|
13
|
+
from ....control import Controller, PollResult, TriggerMode, GateMode, Status
|
|
14
|
+
from ....control.buffer import CircularBuffer
|
|
15
|
+
from ....tango import ControllerDS, TangoDevInfo
|
|
16
|
+
from ..generator import DataGenerator
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class Dummy(ControllerDS):
|
|
20
|
+
""" DS for the simulated hardware. """
|
|
21
|
+
|
|
22
|
+
def _create_control(self, *args, **kwargs):
|
|
23
|
+
return DummyHW()
|
|
24
|
+
|
|
25
|
+
@command(dtype_out=str)
|
|
26
|
+
def dummy_mosca_kwargs(self):
|
|
27
|
+
""" Returns the """
|
|
28
|
+
stream = io.StringIO()
|
|
29
|
+
YAML().dump(self.control.dummy_get_mosca_kwargs(),
|
|
30
|
+
stream=stream)
|
|
31
|
+
return stream.getvalue()
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@dataclasses.dataclass
|
|
35
|
+
class DummyConfig:
|
|
36
|
+
detectors: tuple = tuple()
|
|
37
|
+
enabled: tuple = tuple()
|
|
38
|
+
spectrum_size: int = 0
|
|
39
|
+
allow_hw_disable: bool = True
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
# WARNING!!!
|
|
43
|
+
# Do no modify these config, they are used for unit testing!
|
|
44
|
+
dummy_configs = {
|
|
45
|
+
0: DummyConfig(detectors=(0, 1, 2, 3, 4, 5, 6, 7),
|
|
46
|
+
enabled=(0, 2, 3, 4, 6),
|
|
47
|
+
spectrum_size=666),
|
|
48
|
+
1: DummyConfig(detectors=(0, 1, 2, 3),
|
|
49
|
+
enabled=(0, 1, 2, 3),
|
|
50
|
+
spectrum_size=1024),
|
|
51
|
+
2: DummyConfig(detectors=(0, 1, 2, 3),
|
|
52
|
+
enabled=(0, 1, 2, 3),
|
|
53
|
+
spectrum_size=1024,
|
|
54
|
+
allow_hw_disable=False)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
class DummyGenerator(DataGenerator):
|
|
59
|
+
def __init__(self, *args, **kwargs):
|
|
60
|
+
self._dummy_spectra = None
|
|
61
|
+
self._dummy_stats = None
|
|
62
|
+
self._dummy_det_mapping = tuple()
|
|
63
|
+
super().__init__(*args, **kwargs)
|
|
64
|
+
|
|
65
|
+
@property
|
|
66
|
+
def dummy_det_mapping(self):
|
|
67
|
+
return copy.copy(self._dummy_det_mapping)
|
|
68
|
+
|
|
69
|
+
@dummy_det_mapping.setter
|
|
70
|
+
def dummy_det_mapping(self, dummy_det_mapping):
|
|
71
|
+
self._dummy_det_mapping = copy.copy(dummy_det_mapping)
|
|
72
|
+
|
|
73
|
+
def _init_data(self):
|
|
74
|
+
if self.data_file:
|
|
75
|
+
return super()._init_data()
|
|
76
|
+
data = {}
|
|
77
|
+
stats = {}
|
|
78
|
+
n_values = self.acq_nb_points * self.spectrum_size
|
|
79
|
+
for i_det in range(self.n_detectors):
|
|
80
|
+
det_num = self._dummy_det_mapping[i_det]
|
|
81
|
+
det_data = np.arange(det_num * 100, n_values + det_num * 100, dtype=np.uint32)
|
|
82
|
+
det_data.shape = self.acq_nb_points, self.spectrum_size
|
|
83
|
+
data[f"det{i_det}"] = det_data
|
|
84
|
+
stats[f"det{i_det}"] = np.full((self.acq_nb_points, 4),
|
|
85
|
+
200 * det_num + 0.666,
|
|
86
|
+
dtype=float)
|
|
87
|
+
return data, stats
|
|
88
|
+
|
|
89
|
+
def start_detector(self, detector):
|
|
90
|
+
n_points = min(self.acq_nb_points, 500)
|
|
91
|
+
self._dummy_spectra = {idet: CircularBuffer(1,
|
|
92
|
+
n_points,
|
|
93
|
+
self.spectrum_size,
|
|
94
|
+
dtype=np.uint32)
|
|
95
|
+
for idet in range(self.n_detectors)}
|
|
96
|
+
self._dummy_stats = {idet: CircularBuffer(1,
|
|
97
|
+
n_points,
|
|
98
|
+
4,
|
|
99
|
+
dtype=float)
|
|
100
|
+
for idet in range(self.n_detectors)}
|
|
101
|
+
return super().start_detector(detector)
|
|
102
|
+
|
|
103
|
+
def n_dummy_points(self):
|
|
104
|
+
return min(value.n_points
|
|
105
|
+
for value in self._dummy_spectra.values())
|
|
106
|
+
|
|
107
|
+
def update(self, detector, data, stats, f_pix, l_pix):
|
|
108
|
+
self._dummy_spectra[detector].add_data(data)
|
|
109
|
+
self._dummy_stats[detector].add_data(stats)
|
|
110
|
+
|
|
111
|
+
def get_dummy_data(self, p0, p1=None):
|
|
112
|
+
if p1 is None:
|
|
113
|
+
p1 = self.n_dummy_points()
|
|
114
|
+
|
|
115
|
+
det_spectra = self._dummy_spectra
|
|
116
|
+
det_stats = self._dummy_stats
|
|
117
|
+
spec_dtype = det_spectra[0].dtype
|
|
118
|
+
stats_type = det_stats[0].dtype
|
|
119
|
+
spectra = np.zeros((self.n_detectors, p1 - p0, self.spectrum_size),
|
|
120
|
+
dtype=spec_dtype)
|
|
121
|
+
stats = np.zeros((self.n_detectors, p1 - p0, 4),
|
|
122
|
+
dtype=stats_type)
|
|
123
|
+
|
|
124
|
+
for i in range(self.n_detectors):
|
|
125
|
+
spectra[i, ...] = self._dummy_spectra[i][p0:p1]
|
|
126
|
+
stats[i, ...] = self._dummy_stats[i][p0:p1]
|
|
127
|
+
|
|
128
|
+
return spectra, stats
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
class DummyHW(Controller):
|
|
132
|
+
""" Simulated hardware with some extra stuff for unit testing. """
|
|
133
|
+
|
|
134
|
+
def __init__(self, *args, **kwargs):
|
|
135
|
+
super().__init__(*args, **kwargs)
|
|
136
|
+
self._dummy_mosca_kwargs = {}
|
|
137
|
+
self._dummy_config: DummyConfig = dataclasses.replace(dummy_configs.get(0))
|
|
138
|
+
self._dummy_generator = DummyGenerator()
|
|
139
|
+
self._poller = None
|
|
140
|
+
|
|
141
|
+
def mca_status(self):
|
|
142
|
+
if not self._dummy_config:
|
|
143
|
+
return Status.UNINITIALIZED
|
|
144
|
+
if self._dummy_generator and self._dummy_generator.is_running():
|
|
145
|
+
return Status.RUNNING
|
|
146
|
+
return Status.READY
|
|
147
|
+
|
|
148
|
+
def set_dummy_config(self, config_num):
|
|
149
|
+
self._dummy_config = dataclasses.replace(dummy_configs.get(config_num))
|
|
150
|
+
|
|
151
|
+
def spectrum_size(self):
|
|
152
|
+
return self._dummy_config.spectrum_size
|
|
153
|
+
|
|
154
|
+
def enabled_detectors(self):
|
|
155
|
+
if self._dummy_config.allow_hw_disable:
|
|
156
|
+
return self._dummy_config.enabled
|
|
157
|
+
else:
|
|
158
|
+
return super().enabled_detectors()
|
|
159
|
+
|
|
160
|
+
def enable_detector(self, detector, enable=True):
|
|
161
|
+
if self._dummy_config.allow_hw_disable:
|
|
162
|
+
enabled = set(self._dummy_config.enabled)
|
|
163
|
+
if enable:
|
|
164
|
+
enabled.add(detector)
|
|
165
|
+
else:
|
|
166
|
+
enabled.discard(detector)
|
|
167
|
+
self._dummy_config.enabled = \
|
|
168
|
+
tuple([det for det in self._dummy_config.detectors
|
|
169
|
+
if det in enabled])
|
|
170
|
+
else:
|
|
171
|
+
super().enable_detector(detector, enable=enable)
|
|
172
|
+
|
|
173
|
+
def available_detectors(self):
|
|
174
|
+
return self._dummy_config.detectors
|
|
175
|
+
|
|
176
|
+
def generator(self):
|
|
177
|
+
return self._dummy_generator
|
|
178
|
+
|
|
179
|
+
def apply_mosca(self, *args, **kwargs):
|
|
180
|
+
filtered = {key: (value.name if isinstance(value, enum.Enum) else value)
|
|
181
|
+
for key, value in kwargs.items()}
|
|
182
|
+
self._dummy_mosca_kwargs = copy.deepcopy(filtered)
|
|
183
|
+
|
|
184
|
+
generator = self.generator()
|
|
185
|
+
generator.start_delay = 0.015
|
|
186
|
+
self.generator().apply_mosca(*args, **kwargs)
|
|
187
|
+
|
|
188
|
+
def dummy_get_mosca_kwargs(self):
|
|
189
|
+
return self._dummy_mosca_kwargs
|
|
190
|
+
|
|
191
|
+
def get_supported_spectrum_sizes(self):
|
|
192
|
+
return (666, 1024, 3082)
|
|
193
|
+
|
|
194
|
+
def get_stats_names(self):
|
|
195
|
+
return "stat_a", "stat_b", "stat_c", "stat_d"
|
|
196
|
+
|
|
197
|
+
def get_supported_trigger_modes(self):
|
|
198
|
+
return [TriggerMode.FREERUN,
|
|
199
|
+
TriggerMode.EXT_TRIG,
|
|
200
|
+
TriggerMode.INT_TRIG_READOUT,
|
|
201
|
+
TriggerMode.GATE]
|
|
202
|
+
|
|
203
|
+
def get_supported_gate_modes(self):
|
|
204
|
+
return [GateMode.IGNORE,
|
|
205
|
+
GateMode.HIGH]
|
|
206
|
+
|
|
207
|
+
def prepare_acq(self, resume=False):
|
|
208
|
+
generator = self.generator()
|
|
209
|
+
detectors = self.enabled_detectors()
|
|
210
|
+
generator.dummy_det_mapping = detectors
|
|
211
|
+
n_points = self._dummy_mosca_kwargs["acq_nb_points"]
|
|
212
|
+
block_size=self._dummy_mosca_kwargs["block_size"]
|
|
213
|
+
self.generator().prepare(detectors, self.spectrum_size())
|
|
214
|
+
|
|
215
|
+
def start_acq(self, resume=None):
|
|
216
|
+
|
|
217
|
+
# # generator = DummyGenerator(n_points,
|
|
218
|
+
# # len(detectors),
|
|
219
|
+
# # self.spectrum_size(),
|
|
220
|
+
# # gate=False,
|
|
221
|
+
# # block_size=block_size,
|
|
222
|
+
# # mapping_mode=True,
|
|
223
|
+
# # internal_trig_time=self._dummy_mosca_kwargs["acq_realtime"],
|
|
224
|
+
# # dummy_det_mapping=detectors)
|
|
225
|
+
generator = self.generator()
|
|
226
|
+
detectors = self.enabled_detectors()
|
|
227
|
+
for idet, _ in enumerate(detectors):
|
|
228
|
+
generator.start_detector(idet)
|
|
229
|
+
n_points = self._dummy_mosca_kwargs["acq_nb_points"]
|
|
230
|
+
block_size=self._dummy_mosca_kwargs["block_size"]
|
|
231
|
+
|
|
232
|
+
self._poller = Poller(n_points,
|
|
233
|
+
detectors,
|
|
234
|
+
generator,
|
|
235
|
+
block_size=block_size)
|
|
236
|
+
|
|
237
|
+
# map_refresh_t=0.05,
|
|
238
|
+
# data_file=None,
|
|
239
|
+
# gate=True,
|
|
240
|
+
|
|
241
|
+
# point_offset=0,
|
|
242
|
+
# start_delay=0.05,
|
|
243
|
+
|
|
244
|
+
def stop_acq(self):
|
|
245
|
+
""" Stops the acquisitions. """
|
|
246
|
+
self.generator().stop()
|
|
247
|
+
|
|
248
|
+
def poll_acq(self) -> PollResult:
|
|
249
|
+
""" After an acquisition is started, this method can be called to poll the
|
|
250
|
+
controller and retrieve data. See the documentation for the `PollResult`
|
|
251
|
+
class.
|
|
252
|
+
|
|
253
|
+
Returns:
|
|
254
|
+
an instance of PollResult.
|
|
255
|
+
"""
|
|
256
|
+
return self._poller.poll()
|
|
257
|
+
|
|
258
|
+
# def is_running(self) -> bool:
|
|
259
|
+
# return self._state == Status.RUNNING
|
|
260
|
+
# # raise NotImplementedError
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
class Poller:
|
|
264
|
+
def __init__(self, n_points, detectors,
|
|
265
|
+
generator: DummyGenerator, block_size=None):
|
|
266
|
+
self.n_points = n_points
|
|
267
|
+
self.detectors = detectors
|
|
268
|
+
self.generator = generator
|
|
269
|
+
self.last_read = 0
|
|
270
|
+
self.block_size = block_size
|
|
271
|
+
|
|
272
|
+
def poll(self):
|
|
273
|
+
finished = False
|
|
274
|
+
generator = self.generator
|
|
275
|
+
block_size = self.block_size
|
|
276
|
+
p0 = self.last_read
|
|
277
|
+
|
|
278
|
+
n_triggered = generator.n_dummy_points()
|
|
279
|
+
n_avail = n_triggered - self.last_read
|
|
280
|
+
|
|
281
|
+
if block_size is not None and block_size > 0 and n_avail >= block_size:
|
|
282
|
+
n_avail = max(block_size, n_avail)
|
|
283
|
+
|
|
284
|
+
if n_avail:
|
|
285
|
+
spectra, stats = generator.get_dummy_data(p0, p0 + n_avail)
|
|
286
|
+
self.last_read += n_avail
|
|
287
|
+
finished = self.generator.finished and self.last_read == self.n_points
|
|
288
|
+
else:
|
|
289
|
+
spectra = None
|
|
290
|
+
stats = None
|
|
291
|
+
|
|
292
|
+
return PollResult(finished,
|
|
293
|
+
n_avail,
|
|
294
|
+
spectra,
|
|
295
|
+
stats,
|
|
296
|
+
n_triggered)
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
DUMMY_DEVINFO = TangoDevInfo(klass=Dummy, properties={})
|