etho-python 1.2__py3-none-any.whl → 1.2.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.
- etho/services/camera/__init__.py +2 -0
- etho/services/camera/spinnaker_old.py +313 -0
- etho/services/daq/IOTask.py +66 -51
- etho/utils/sound.py +1 -1
- {etho_python-1.2.dist-info → etho_python-1.2.2.dist-info}/METADATA +1 -1
- {etho_python-1.2.dist-info → etho_python-1.2.2.dist-info}/RECORD +9 -8
- {etho_python-1.2.dist-info → etho_python-1.2.2.dist-info}/WHEEL +0 -0
- {etho_python-1.2.dist-info → etho_python-1.2.2.dist-info}/entry_points.txt +0 -0
- {etho_python-1.2.dist-info → etho_python-1.2.2.dist-info}/licenses/LICENSE +0 -0
etho/services/camera/__init__.py
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
from .spinnaker import Spinnaker
|
|
2
|
+
from .spinnaker_old import Spinnaker_OLD
|
|
2
3
|
from .ximea import Ximea
|
|
3
4
|
from .basler import Basler
|
|
4
5
|
from .hamamatsu import Hamamatsu
|
|
5
6
|
from .dummy import Dummy
|
|
6
7
|
|
|
7
8
|
make = {
|
|
9
|
+
"Spinnaker_OLD": Spinnaker_OLD,
|
|
8
10
|
"Spinnaker": Spinnaker,
|
|
9
11
|
"Ximea": Ximea,
|
|
10
12
|
"Basler": Basler,
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
import time
|
|
2
|
+
import numpy as np
|
|
3
|
+
from typing import Tuple, Union
|
|
4
|
+
from .base import BaseCam
|
|
5
|
+
import cv2
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
try:
|
|
9
|
+
import PySpin
|
|
10
|
+
|
|
11
|
+
pyspin_error = None
|
|
12
|
+
except ImportError as pyspin_error:
|
|
13
|
+
pass
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class Spinnaker_OLD(BaseCam):
|
|
17
|
+
"""Supports older FLIR cameras (Flea3, Grasshopper) with only partial support for the Spinnaker SDK."""
|
|
18
|
+
|
|
19
|
+
NAME = "SPO"
|
|
20
|
+
|
|
21
|
+
def __init__(self, serialnumber):
|
|
22
|
+
if pyspin_error is not None:
|
|
23
|
+
raise pyspin_error
|
|
24
|
+
self.serialnumber = serialnumber
|
|
25
|
+
|
|
26
|
+
def init(self):
|
|
27
|
+
self.cam_system = PySpin.System_GetInstance()
|
|
28
|
+
self.cam_list = self.cam_system.GetCameras()
|
|
29
|
+
self.c = self.cam_list.GetBySerial(self.serialnumber)
|
|
30
|
+
self.c.Init()
|
|
31
|
+
self.c.PixelFormat.SetValue(PySpin.PixelFormat_Mono8)
|
|
32
|
+
self._generate_attrs()
|
|
33
|
+
|
|
34
|
+
# enable embedding of frame TIME STAMP
|
|
35
|
+
self.c.ChunkModeActive.SetValue(True)
|
|
36
|
+
self.c.ChunkSelector.SetValue(PySpin.ChunkSelector_Timestamp)
|
|
37
|
+
self.c.ChunkEnable.SetValue(True)
|
|
38
|
+
self.timestamp_offset = 0 # self._estimate_timestamp_offset()
|
|
39
|
+
|
|
40
|
+
# set pixel format
|
|
41
|
+
self.c.PixelFormat.SetValue(PySpin.PixelFormat_Mono8)
|
|
42
|
+
|
|
43
|
+
# set continuous acquisition
|
|
44
|
+
self.c.AcquisitionMode.SetValue(PySpin.AcquisitionMode_Continuous)
|
|
45
|
+
|
|
46
|
+
self.timeout = PySpin.EVENT_TIMEOUT_INFINITE
|
|
47
|
+
self.processor = PySpin.ImageProcessor()
|
|
48
|
+
self.processor.SetColorProcessing(PySpin.SPINNAKER_COLOR_PROCESSING_ALGORITHM_HQ_LINEAR)
|
|
49
|
+
|
|
50
|
+
def get(self, timeout=None):
|
|
51
|
+
|
|
52
|
+
# get image
|
|
53
|
+
im = self.c.GetNextImage(self.timeout)
|
|
54
|
+
system_stimestamp = time.time()
|
|
55
|
+
|
|
56
|
+
if im.IsIncomplete():
|
|
57
|
+
im.Release()
|
|
58
|
+
raise ValueError(f"Image incomplete with image status {im.GetImageStatus()}")
|
|
59
|
+
else:
|
|
60
|
+
im_converted = self.processor.Convert(im, PySpin.PixelFormat_BGR8)
|
|
61
|
+
image_timestamp = im.GetTimeStamp()
|
|
62
|
+
im.Release()
|
|
63
|
+
|
|
64
|
+
BGR = im_converted.GetNDArray()
|
|
65
|
+
image_timestamp = image_timestamp / 1e9 + self.timestamp_offset
|
|
66
|
+
return BGR, image_timestamp, system_stimestamp
|
|
67
|
+
|
|
68
|
+
@property
|
|
69
|
+
def roi(self) -> Tuple[int, int, int, int]:
|
|
70
|
+
return self.c.OffsetX.GetValue(), self.c.OffsetY.GetValue(), self.c.Width.GetValue(), self.c.Height.GetValue()
|
|
71
|
+
|
|
72
|
+
@roi.setter
|
|
73
|
+
def roi(self, x0_y0_x_y: Tuple[int, int, int, int]):
|
|
74
|
+
try:
|
|
75
|
+
x0, y0, x, y = x0_y0_x_y
|
|
76
|
+
except ValueError:
|
|
77
|
+
raise ValueError("Need 4-tuple with x0_y0_x_y")
|
|
78
|
+
else:
|
|
79
|
+
self._min_max_inc(self.c.Width, int(x))
|
|
80
|
+
self._min_max_inc(self.c.Height, int(y))
|
|
81
|
+
self._min_max_inc(self.c.OffsetX, int(x0))
|
|
82
|
+
self._min_max_inc(self.c.OffsetY, int(y0))
|
|
83
|
+
|
|
84
|
+
@property
|
|
85
|
+
def framerate(self):
|
|
86
|
+
return self.c.AcquisitionFrameRate.GetValue()
|
|
87
|
+
|
|
88
|
+
@framerate.setter
|
|
89
|
+
def framerate(self, value: float):
|
|
90
|
+
nodemap = self.c.GetNodeMap()
|
|
91
|
+
self.c.TriggerMode.SetValue(PySpin.TriggerMode_Off)
|
|
92
|
+
node = PySpin.CEnumerationPtr(nodemap.GetNode("AcquisitionFrameRateAuto"))
|
|
93
|
+
val = PySpin.CEnumEntryPtr(node.GetEntryByName("Off")).GetValue() # Once, Continuous
|
|
94
|
+
node.SetIntValue(val)
|
|
95
|
+
self.c.AcquisitionFrameRate.SetValue(float(value))
|
|
96
|
+
|
|
97
|
+
@property
|
|
98
|
+
def gamma(self):
|
|
99
|
+
return self.c.Gamma.GetValue()
|
|
100
|
+
|
|
101
|
+
@gamma.setter
|
|
102
|
+
def gamma(self, value: float):
|
|
103
|
+
# self.c.GammaEnabled.SetValue(bool(True))
|
|
104
|
+
self.c.Gamma.SetValue(value)
|
|
105
|
+
|
|
106
|
+
@property
|
|
107
|
+
def brightness(self) -> float:
|
|
108
|
+
return self.c.BlackLevel.GetValue()
|
|
109
|
+
|
|
110
|
+
@brightness.setter
|
|
111
|
+
def brightness(self, value: float):
|
|
112
|
+
# self.c.BlackLevelSelector.SetValue(PySpin.BlackLevelSelector_All)
|
|
113
|
+
self.c.BlackLevel.SetValue(float(value))
|
|
114
|
+
|
|
115
|
+
@property
|
|
116
|
+
def exposure(self):
|
|
117
|
+
return self.c.ExposureTime.GetValue()
|
|
118
|
+
|
|
119
|
+
@exposure.setter
|
|
120
|
+
def exposure(self, value: Union[float, str]):
|
|
121
|
+
if value == "AUTO":
|
|
122
|
+
self.c.ExposureAuto.SetValue(PySpin.ExposureAuto_Continuous)
|
|
123
|
+
else:
|
|
124
|
+
self.c.ExposureAuto.SetValue(PySpin.ExposureAuto_Off)
|
|
125
|
+
self.c.ExposureMode.SetValue(PySpin.ExposureMode_Timed)
|
|
126
|
+
self.c.ExposureTime.SetValue(float(value))
|
|
127
|
+
|
|
128
|
+
@property
|
|
129
|
+
def gain(self):
|
|
130
|
+
self.c.Gain.GetValue()
|
|
131
|
+
|
|
132
|
+
@gain.setter
|
|
133
|
+
def gain(self, value: Union[float, str]):
|
|
134
|
+
if value == "AUTO":
|
|
135
|
+
self.c.GainAuto.SetValue(PySpin.GainAuto_Continuous)
|
|
136
|
+
else:
|
|
137
|
+
self.c.GainAuto.SetValue(PySpin.GainAuto_Off)
|
|
138
|
+
self.c.Gain.SetValue(float(value))
|
|
139
|
+
|
|
140
|
+
def optimize_auto_exposure(self):
|
|
141
|
+
self.setattr("AutoExposureControlLoopDamping", 0.1)
|
|
142
|
+
self.setattr("AutoExposureLightingMode_Val", 2) # Frontlight
|
|
143
|
+
self.setattr("AutoExposureExposureTimeLowerLimit", 6)
|
|
144
|
+
self.setattr("AutoExposureExposureTimeUpperLimit", 30000)
|
|
145
|
+
self.setattr("AutoExposureEVCompensation", 3)
|
|
146
|
+
|
|
147
|
+
@property
|
|
148
|
+
def external_trigger(self):
|
|
149
|
+
return self.c.TriggerMode.GetValue()
|
|
150
|
+
|
|
151
|
+
@external_trigger.setter
|
|
152
|
+
def external_trigger(self, value: bool = False):
|
|
153
|
+
self.c.TriggerMode.SetValue(PySpin.TriggerMode_Off)
|
|
154
|
+
|
|
155
|
+
if value:
|
|
156
|
+
self.c.TriggerSource.SetValue(PySpin.TriggerSource_Line3)
|
|
157
|
+
self.c.TriggerMode.SetValue(PySpin.TriggerMode_On)
|
|
158
|
+
|
|
159
|
+
def _generate_attrs(self):
|
|
160
|
+
|
|
161
|
+
self._rw_modes = {PySpin.RO: "read only", PySpin.RW: "read/write", PySpin.WO: "write only", PySpin.NA: "not available"}
|
|
162
|
+
|
|
163
|
+
self._attr_types = {
|
|
164
|
+
PySpin.intfIFloat: PySpin.CFloatPtr,
|
|
165
|
+
PySpin.intfIBoolean: PySpin.CBooleanPtr,
|
|
166
|
+
PySpin.intfIInteger: PySpin.CIntegerPtr,
|
|
167
|
+
PySpin.intfIEnumeration: PySpin.CEnumerationPtr,
|
|
168
|
+
PySpin.intfIString: PySpin.CStringPtr,
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
self._attr_type_names = {
|
|
172
|
+
PySpin.intfIFloat: "float",
|
|
173
|
+
PySpin.intfIBoolean: "bool",
|
|
174
|
+
PySpin.intfIInteger: "int",
|
|
175
|
+
PySpin.intfIEnumeration: "enum",
|
|
176
|
+
PySpin.intfIString: "string",
|
|
177
|
+
PySpin.intfICommand: "command",
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
self.camera_attributes = {}
|
|
181
|
+
self.camera_methods = {}
|
|
182
|
+
self.camera_node_types = {}
|
|
183
|
+
|
|
184
|
+
for node in self.c.GetNodeMap().GetNodes():
|
|
185
|
+
pit = node.GetPrincipalInterfaceType()
|
|
186
|
+
name = node.GetName()
|
|
187
|
+
self.camera_node_types[name] = self._attr_type_names.get(pit, pit)
|
|
188
|
+
if pit == PySpin.intfICommand:
|
|
189
|
+
self.camera_methods[name] = PySpin.CCommandPtr(node)
|
|
190
|
+
if pit in self._attr_types:
|
|
191
|
+
self.camera_attributes[name] = self._attr_types[pit](node)
|
|
192
|
+
self.initialized = True
|
|
193
|
+
|
|
194
|
+
def getattr(self, attr):
|
|
195
|
+
if attr in self.camera_attributes:
|
|
196
|
+
prop = self.camera_attributes[attr]
|
|
197
|
+
if not PySpin.IsReadable(prop):
|
|
198
|
+
raise AttributeError("Camera property '%s' is not readable" % attr)
|
|
199
|
+
|
|
200
|
+
if hasattr(prop, "GetValue"):
|
|
201
|
+
return prop.GetValue()
|
|
202
|
+
elif hasattr(prop, "ToString"):
|
|
203
|
+
return prop.ToString()
|
|
204
|
+
else:
|
|
205
|
+
raise AttributeError("Camera property '%s' is not readable" % attr)
|
|
206
|
+
elif attr in self.camera_methods:
|
|
207
|
+
return self.camera_methods[attr].Execute
|
|
208
|
+
else:
|
|
209
|
+
raise AttributeError(attr)
|
|
210
|
+
|
|
211
|
+
def setattr(self, attr, val):
|
|
212
|
+
if attr in self.camera_attributes:
|
|
213
|
+
prop = self.camera_attributes[attr]
|
|
214
|
+
if not PySpin.IsWritable(prop):
|
|
215
|
+
raise AttributeError("Property '%s' is not currently writable!" % attr)
|
|
216
|
+
|
|
217
|
+
if hasattr(prop, "SetValue"):
|
|
218
|
+
prop.SetValue(val)
|
|
219
|
+
else:
|
|
220
|
+
prop.FromString(val)
|
|
221
|
+
|
|
222
|
+
elif attr in self.camera_methods:
|
|
223
|
+
raise AttributeError("Camera method '%s' is a function -- you can't assign it a value!" % attr)
|
|
224
|
+
else:
|
|
225
|
+
if attr not in self.__dict__ and self.lock and self.initialized:
|
|
226
|
+
raise AttributeError("Unknown property '%s'." % attr)
|
|
227
|
+
else:
|
|
228
|
+
raise AttributeError(attr)
|
|
229
|
+
|
|
230
|
+
def _min_max_inc(self, prop, value=None, set_value=True):
|
|
231
|
+
min_val, max_val, inc = prop.GetMin(), prop.GetMax(), prop.GetInc()
|
|
232
|
+
|
|
233
|
+
prop_type = type(prop.GetValue())
|
|
234
|
+
if value is not None:
|
|
235
|
+
value = np.clip(value, min_val, max_val)
|
|
236
|
+
value = np.round(value / inc) * inc
|
|
237
|
+
if set_value:
|
|
238
|
+
value = prop_type(value)
|
|
239
|
+
prop.SetValue(value)
|
|
240
|
+
value = prop.GetValue()
|
|
241
|
+
return value
|
|
242
|
+
|
|
243
|
+
def _estimate_timestamp_offset(self, timestamp_offset_iterations=10):
|
|
244
|
+
"""Gets offset between system time and timestamps."""
|
|
245
|
+
# This method is required because the timestamp stored in the camera is relative to when it was powered on, so an
|
|
246
|
+
# offset needs to be applied to get it into epoch time; from tests I’ve done, this appears to be accurate to ~1e-3
|
|
247
|
+
# seconds.
|
|
248
|
+
timestamp_offsets = []
|
|
249
|
+
for i in range(timestamp_offset_iterations):
|
|
250
|
+
# Latch timestamp. This basically “freezes” the current camera timer into a variable that can be read with
|
|
251
|
+
self.c.TimestampLatch.Execute()
|
|
252
|
+
system_time = time.time()
|
|
253
|
+
# Compute timestamp offset in seconds; note that timestamp latch value is in nanoseconds
|
|
254
|
+
timestamp_offset = system_time - self.c.TimestampLatchValue.GetValue() / 1e9
|
|
255
|
+
timestamp_offsets.append(timestamp_offset)
|
|
256
|
+
# Return the median value
|
|
257
|
+
return np.median(timestamp_offsets)
|
|
258
|
+
|
|
259
|
+
def enable_gpio_strobe(self):
|
|
260
|
+
pass # self._set_gpio_strobe(enable=True)
|
|
261
|
+
|
|
262
|
+
def disable_gpio_strobe(self):
|
|
263
|
+
pass # self._set_gpio_strobe(enable=False)
|
|
264
|
+
|
|
265
|
+
def set_node_and_entry(self, node_name: str, entry_name: str):
|
|
266
|
+
nodemap = self.c.GetNodeMap()
|
|
267
|
+
|
|
268
|
+
node = PySpin.CEnumerationPtr(nodemap.GetNode(node_name))
|
|
269
|
+
if not PySpin.IsAvailable(node) or not PySpin.IsWritable(node):
|
|
270
|
+
raise ValueError(f"Cannot retrieve node {node_name}.")
|
|
271
|
+
|
|
272
|
+
entry = node.GetEntryByName(entry_name)
|
|
273
|
+
if not PySpin.IsAvailable(entry) or not PySpin.IsReadable(entry):
|
|
274
|
+
raise ValueError(f"Cannot retrieve entry {entry_name} from node {node_name}.")
|
|
275
|
+
|
|
276
|
+
node.SetIntValue(entry.GetValue())
|
|
277
|
+
|
|
278
|
+
# def _set_gpio_strobe(self, line: str = "Line2", enable: bool = True):
|
|
279
|
+
# # from PySpin/Examples/Python3/CounterAndTimer.py
|
|
280
|
+
# # from https://github.com/CapAI/misc/blob/a22cd50e90018c03cde3c1339aa622185502bb05/spinnaker/pyspin/Examples/Python3/CounterAndTimer.py#L193
|
|
281
|
+
# if enable:
|
|
282
|
+
# line_mode = "Output"
|
|
283
|
+
# else:
|
|
284
|
+
# line_mode = "Input"
|
|
285
|
+
|
|
286
|
+
# # Select line to control
|
|
287
|
+
# self.set_node_and_entry("LineSelector", line)
|
|
288
|
+
# self.set_node_and_entry("LineMode", line_mode)
|
|
289
|
+
# self.set_node_and_entry("LineSource", "ExposureActive")
|
|
290
|
+
|
|
291
|
+
def reset(self, sleep: float = 10.0):
|
|
292
|
+
device_reset = PySpin.CCommandPtr(self.c.GetNodeMap().GetNode("DeviceReset"))
|
|
293
|
+
device_reset.Execute()
|
|
294
|
+
self.close()
|
|
295
|
+
time.sleep(sleep)
|
|
296
|
+
|
|
297
|
+
def start(self):
|
|
298
|
+
self.c.BeginAcquisition()
|
|
299
|
+
|
|
300
|
+
def stop(self):
|
|
301
|
+
try:
|
|
302
|
+
self.c.EndAcquisition() # not sure this works if BeginAcquistion has not been called
|
|
303
|
+
except:
|
|
304
|
+
pass
|
|
305
|
+
|
|
306
|
+
def close(self):
|
|
307
|
+
self.stop() # should check if cam started
|
|
308
|
+
self.c.DeInit()
|
|
309
|
+
del self.c
|
|
310
|
+
self.cam_list.Clear()
|
|
311
|
+
del self.cam_list
|
|
312
|
+
# self.cam_system.ReleaseInstance()
|
|
313
|
+
# del self.cam_system
|
etho/services/daq/IOTask.py
CHANGED
|
@@ -27,7 +27,7 @@ class IOTask(daq.Task):
|
|
|
27
27
|
dev_name="Dev1",
|
|
28
28
|
cha_name=["ai0"],
|
|
29
29
|
limits=None,
|
|
30
|
-
rate=10000.0,
|
|
30
|
+
rate: float = 10000.0,
|
|
31
31
|
nb_inputsamples_per_cycle=None,
|
|
32
32
|
clock_source=None,
|
|
33
33
|
terminals: Optional[List[str]] = None,
|
|
@@ -63,7 +63,8 @@ class IOTask(daq.Task):
|
|
|
63
63
|
raise TypeError(f"`cha_name` is {type(cha_name)}. Should be `list` or `tuple`")
|
|
64
64
|
|
|
65
65
|
self.samples_read = daq.int32()
|
|
66
|
-
|
|
66
|
+
self.samples_written = daq.int32()
|
|
67
|
+
self.rate = rate
|
|
67
68
|
# channels
|
|
68
69
|
cha_types = {
|
|
69
70
|
"ai": "analog_input",
|
|
@@ -80,7 +81,7 @@ class IOTask(daq.Task):
|
|
|
80
81
|
self.cha_string = ", ".join(self.cha_names)
|
|
81
82
|
self.num_channels = len(self.cha_names)
|
|
82
83
|
if nb_inputsamples_per_cycle is None:
|
|
83
|
-
nb_inputsamples_per_cycle = int(rate)
|
|
84
|
+
nb_inputsamples_per_cycle = int(self.rate)
|
|
84
85
|
|
|
85
86
|
# terminals
|
|
86
87
|
terminal_types = {
|
|
@@ -111,21 +112,30 @@ class IOTask(daq.Task):
|
|
|
111
112
|
self.data_gen = None # called at start of callback
|
|
112
113
|
self.data_rec = None # called at end of callback
|
|
113
114
|
|
|
115
|
+
self.buffer_seconds = 100
|
|
116
|
+
self.refresh_seconds = 0.1
|
|
117
|
+
self.num_samples_per_chan = int(rate * self.buffer_seconds)
|
|
118
|
+
self.num_samples_per_event = int(rate * self.refresh_seconds)
|
|
119
|
+
|
|
114
120
|
if len(set(self.cha_type)) != 1:
|
|
115
121
|
raise ValueError("Mixed channel types (AI, AO, DI, DO).")
|
|
116
122
|
|
|
117
123
|
if self.cha_type[0] == "analog_input":
|
|
118
124
|
# add all channels
|
|
119
125
|
for name, terminal, limit in zip(self.cha_names, self.cha_terminals, self.cha_limits):
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
126
|
+
try:
|
|
127
|
+
self.CreateAIVoltageChan(
|
|
128
|
+
name,
|
|
129
|
+
"",
|
|
130
|
+
terminal,
|
|
131
|
+
limit[0],
|
|
132
|
+
limit[1],
|
|
133
|
+
daq.DAQmx_Val_Volts,
|
|
134
|
+
None,
|
|
135
|
+
)
|
|
136
|
+
except DAQError as e:
|
|
137
|
+
logging.exception(f"Failed creating AO {name}: %s", e)
|
|
138
|
+
raise
|
|
129
139
|
self.num_samples_per_chan = nb_inputsamples_per_cycle
|
|
130
140
|
self.num_samples_per_event = nb_inputsamples_per_cycle # self.num_samples_per_chan*self.num_channels
|
|
131
141
|
self.AutoRegisterEveryNSamplesEvent(daq.DAQmx_Val_Acquired_Into_Buffer, self.num_samples_per_event, 0)
|
|
@@ -140,19 +150,16 @@ class IOTask(daq.Task):
|
|
|
140
150
|
daq.DAQmx_Val_Volts,
|
|
141
151
|
None,
|
|
142
152
|
)
|
|
143
|
-
|
|
144
|
-
self.num_samples_per_event = 1000 # determines shortest interval at which new data can be generated
|
|
153
|
+
|
|
145
154
|
self.AutoRegisterEveryNSamplesEvent(daq.DAQmx_Val_Transferred_From_Buffer, self.num_samples_per_event, 0)
|
|
146
|
-
self.CfgOutputBuffer(self.num_samples_per_chan
|
|
155
|
+
self.CfgOutputBuffer(self.num_samples_per_chan)
|
|
147
156
|
# ensures continuous output and avoids collision of old and new data in buffer
|
|
148
157
|
self.SetWriteRegenMode(daq.DAQmx_Val_DoNotAllowRegen)
|
|
149
158
|
elif self.cha_type[0] == "digital_output":
|
|
150
159
|
for name in self.cha_names:
|
|
151
160
|
self.CreateDOChan(name, "", daq.DAQmx_Val_ChanPerLine)
|
|
152
|
-
self.num_samples_per_chan = 5000
|
|
153
|
-
self.num_samples_per_event = 1000 # determines shortest interval at which new data can be generated
|
|
154
161
|
self.AutoRegisterEveryNSamplesEvent(daq.DAQmx_Val_Transferred_From_Buffer, self.num_samples_per_event, 0)
|
|
155
|
-
self.CfgOutputBuffer(self.num_samples_per_chan
|
|
162
|
+
self.CfgOutputBuffer(self.num_samples_per_chan)
|
|
156
163
|
# ensures continuous output and avoids collision of old and new data in buffer
|
|
157
164
|
self.SetWriteRegenMode(daq.DAQmx_Val_DoNotAllowRegen)
|
|
158
165
|
|
|
@@ -174,7 +181,7 @@ class IOTask(daq.Task):
|
|
|
174
181
|
|
|
175
182
|
self.CfgSampClkTiming(
|
|
176
183
|
clock_source,
|
|
177
|
-
rate,
|
|
184
|
+
self.rate,
|
|
178
185
|
daq.DAQmx_Val_Rising,
|
|
179
186
|
daq.DAQmx_Val_ContSamps,
|
|
180
187
|
self.num_samples_per_chan,
|
|
@@ -210,50 +217,58 @@ class IOTask(daq.Task):
|
|
|
210
217
|
if self.data_gen is not None:
|
|
211
218
|
try:
|
|
212
219
|
self._data = next(self.data_gen) # get data from data generator
|
|
213
|
-
self.log.warning(f"datagen {self.data_gen}")
|
|
214
220
|
except StopIteration as e:
|
|
215
|
-
self.log.warning(f"
|
|
221
|
+
self.log.warning(f"Generator out of data - stopping iteration. This is okay!")
|
|
216
222
|
self._data = None
|
|
217
223
|
|
|
218
224
|
if self.cha_type[0] == "analog_input":
|
|
219
225
|
# should only read self.num_samples_per_event!! otherwise recordings will be zeropadded for each chunk
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
226
|
+
try:
|
|
227
|
+
self.ReadAnalogF64(
|
|
228
|
+
daq.DAQmx_Val_Auto,
|
|
229
|
+
1.0,
|
|
230
|
+
daq.DAQmx_Val_GroupByScanNumber,
|
|
231
|
+
self._data,
|
|
232
|
+
self.num_samples_per_chan * self.num_channels,
|
|
233
|
+
daq.byref(self.samples_read),
|
|
234
|
+
None,
|
|
235
|
+
)
|
|
236
|
+
# only keep samples that were actually read, .value converts c_long to int
|
|
237
|
+
self._data = self._data[: self.samples_read.value, :]
|
|
238
|
+
except daq.DAQError as e:
|
|
239
|
+
logging.exception("Error Reading Analog %d: %s", e.error, e)
|
|
231
240
|
|
|
232
241
|
elif self.cha_type[0] == "analog_output" and self._data is not None:
|
|
233
|
-
|
|
234
|
-
self.
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
+
try:
|
|
243
|
+
self.WriteAnalogF64(
|
|
244
|
+
self._data.shape[0],
|
|
245
|
+
0,
|
|
246
|
+
daq.DAQmx_Val_WaitInfinitely,
|
|
247
|
+
daq.DAQmx_Val_GroupByScanNumber,
|
|
248
|
+
self._data,
|
|
249
|
+
daq.byref(self.samples_written),
|
|
250
|
+
None,
|
|
251
|
+
)
|
|
252
|
+
except daq.DAQError as e:
|
|
253
|
+
logging.exception("Error Writing Analog %d: %s", e.error, e)
|
|
254
|
+
|
|
242
255
|
elif self.cha_type[0] == "digital_output" and self._data is not None:
|
|
243
|
-
|
|
244
|
-
self.
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
256
|
+
try:
|
|
257
|
+
self.WriteDigitalLines(
|
|
258
|
+
self._data.shape[0],
|
|
259
|
+
0,
|
|
260
|
+
daq.DAQmx_Val_WaitInfinitely,
|
|
261
|
+
daq.DAQmx_Val_GroupByScanNumber,
|
|
262
|
+
self._data,
|
|
263
|
+
daq.byref(self.samples_read),
|
|
264
|
+
None,
|
|
265
|
+
)
|
|
266
|
+
except daq.DAQError as e:
|
|
267
|
+
logging.exception("Error Writing Digital %d: %s", e.error, e)
|
|
252
268
|
|
|
253
269
|
if self.data_rec is not None:
|
|
254
270
|
for data_rec in self.data_rec:
|
|
255
271
|
if self._data is not None:
|
|
256
|
-
self.log.warning(f"{data_rec} {systemtime}")
|
|
257
272
|
data_rec.send((self._data, systemtime))
|
|
258
273
|
self._newdata_event.set()
|
|
259
274
|
|
etho/utils/sound.py
CHANGED
|
@@ -16,7 +16,7 @@ def parse_cell(cell, dtype: Callable = None) -> List:
|
|
|
16
16
|
if isinstance(cell, str):
|
|
17
17
|
cell = cell.strip()
|
|
18
18
|
token = cell.lstrip("[").rstrip("]").split(",")
|
|
19
|
-
token = [tok.strip() for tok in token]
|
|
19
|
+
token = [tok.strip().strip("'\"") for tok in token]
|
|
20
20
|
if dtype:
|
|
21
21
|
token = [dtype(tok) for tok in token]
|
|
22
22
|
else:
|
|
@@ -21,14 +21,15 @@ etho/services/callbacks/__init__.py,sha256=XGD_-ZGuYvPOKXn_u3MOYVMC-aa6AFN0HqlB3
|
|
|
21
21
|
etho/services/callbacks/_base.py,sha256=Kd1BdkTgMtg4FzKH7XwzJjmFaJw6BkgKupSiHr8ChPs,2673
|
|
22
22
|
etho/services/callbacks/_image.py,sha256=jVSDrzaL7lPZfk_msSA2JicfbwkeqB2GGAlL2rLgZKY,27440
|
|
23
23
|
etho/services/callbacks/_trace.py,sha256=kg3a5ggd7SH_CFKL3ZjeO7J7s2Z5H8KMSY5UXFqJqHM,13847
|
|
24
|
-
etho/services/camera/__init__.py,sha256=
|
|
24
|
+
etho/services/camera/__init__.py,sha256=sHJfESDswESrODpJaTDaQTE8HyMd1h_vl6CrMkEzNlc,365
|
|
25
25
|
etho/services/camera/base.py,sha256=RqaeZGl-PCLaha6fq6OyOni1vPja5oP2xoOa25TOv-A,3646
|
|
26
26
|
etho/services/camera/basler.py,sha256=Snz060KZWejB6A3DI3fPof8b2G6noJ85U-V9mIUgafc,7003
|
|
27
27
|
etho/services/camera/dummy.py,sha256=rwYfQvm_3sxR8gtqw2-J9isULxurV8lCDJgSYehBq8k,3582
|
|
28
28
|
etho/services/camera/hamamatsu.py,sha256=M6zVEgpUlGCcszVNSBrnjyRdexzA0ZivI4G_GpqMAP4,3690
|
|
29
29
|
etho/services/camera/spinnaker.py,sha256=4QewxZlNm0CSRyfXK-9300QthD4egCX1ulyEg_qPsi0,11961
|
|
30
|
+
etho/services/camera/spinnaker_old.py,sha256=vJLxfyRFhSwZorJmpPOmidNoi-R_XVmAQ-04_cgLKrs,11594
|
|
30
31
|
etho/services/camera/ximea.py,sha256=qNPMC49j_WH3xkRfv0sZF20HVu4W4FTA6-lsFqy8OOc,5306
|
|
31
|
-
etho/services/daq/IOTask.py,sha256=
|
|
32
|
+
etho/services/daq/IOTask.py,sha256=brMxfx8NRXxbdZ6lcK7rGm-1-mcRsFSIP9I4fJd_IUg,13210
|
|
32
33
|
etho/services/daq/ai.py,sha256=JNDbhtZbmuO-LbKtybmWIPGpMYuFw41xGJg63ZPTgCw,6561
|
|
33
34
|
etho/services/dlp/dlp_make_warpfiles.py,sha256=YL9rBmryb_mwDpwc6QlXTf7jqANyFg8XVcAVt0dM2S8,5995
|
|
34
35
|
etho/services/dlp/dlp_runners.py,sha256=Bk34jyyGOCsYpJpPEkG7szirtPfagPHiqNTtiJU3xKc,8730
|
|
@@ -40,11 +41,11 @@ etho/utils/calibration.py,sha256=-FMABMS-ReJ4XXR0wUAiAqGizXX5Vlj2NYH4ofiBnpA,314
|
|
|
40
41
|
etho/utils/config.py,sha256=Tp8nxFfrRC6ujU3L6dDRXmh-JQF630jCEoxg63PIzF0,1314
|
|
41
42
|
etho/utils/runner.py,sha256=XiUWQp0ua1DYwHUdgBr5Z_lz5ZVxBVCidPBgjckEaH8,4171
|
|
42
43
|
etho/utils/shuffled_cycle.py,sha256=WvBbNQP-iK7fVoCgHGTDjmT0wJhZm8Rb7IDXIbBcE5Q,1481
|
|
43
|
-
etho/utils/sound.py,sha256=
|
|
44
|
+
etho/utils/sound.py,sha256=UUN8AReClsNX6aBtluwWWjNuztk-Xh8m9PsiNmA1cAQ,11704
|
|
44
45
|
etho/utils/tui.py,sha256=zPaV5ItzOa3QuC3DGMNcTWM4N3El87hnAnTy51lacHs,3777
|
|
45
46
|
etho/utils/zeroclient.py,sha256=3wHR9rtHlESLu9UR1hZRsVisGNpLJKYv2m0sIJUbT08,3498
|
|
46
|
-
etho_python-1.2.dist-info/entry_points.txt,sha256=Y9LGGC-42Xm1bv62a_IiLYVq8T2HoPO5fLypuFfqamo,38
|
|
47
|
-
etho_python-1.2.dist-info/licenses/LICENSE,sha256=DpD3ghQH7qR9cJdLW41cPartvauhOgGI0CeEXtoWNyI,1068
|
|
48
|
-
etho_python-1.2.dist-info/WHEEL,sha256=G2gURzTEtmeR8nrdXUJfNiB3VYVxigPQ-bEQujpNiNs,82
|
|
49
|
-
etho_python-1.2.dist-info/METADATA,sha256=
|
|
50
|
-
etho_python-1.2.dist-info/RECORD,,
|
|
47
|
+
etho_python-1.2.2.dist-info/entry_points.txt,sha256=Y9LGGC-42Xm1bv62a_IiLYVq8T2HoPO5fLypuFfqamo,38
|
|
48
|
+
etho_python-1.2.2.dist-info/licenses/LICENSE,sha256=DpD3ghQH7qR9cJdLW41cPartvauhOgGI0CeEXtoWNyI,1068
|
|
49
|
+
etho_python-1.2.2.dist-info/WHEEL,sha256=G2gURzTEtmeR8nrdXUJfNiB3VYVxigPQ-bEQujpNiNs,82
|
|
50
|
+
etho_python-1.2.2.dist-info/METADATA,sha256=Cj-Ovg89CSkuGQTKFzHXwvkV5qtTJD5Uo3VGf39ecBI,5928
|
|
51
|
+
etho_python-1.2.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|