etho-python 0.22.0__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.
Files changed (47) hide show
  1. etho/__init__.py +9 -0
  2. etho/app.py +569 -0
  3. etho/assets/etho_icon1_pipeline_dark.svg +23 -0
  4. etho/assets/etho_icon1_pipeline_light.svg +30 -0
  5. etho/cli.py +215 -0
  6. etho/client.py +384 -0
  7. etho/services/ANAZeroService.py +123 -0
  8. etho/services/BLTZeroService.py +108 -0
  9. etho/services/DAQZeroService.py +326 -0
  10. etho/services/DLPZeroService.py +240 -0
  11. etho/services/GCMZeroService.py +271 -0
  12. etho/services/GOVZeroService.py +231 -0
  13. etho/services/NICounterZeroService.py +92 -0
  14. etho/services/NITriggerZeroService.py +120 -0
  15. etho/services/TemplateZeroService.py +98 -0
  16. etho/services/ZeroService.py +272 -0
  17. etho/services/__init__.py +0 -0
  18. etho/services/callbacks/__init__.py +19 -0
  19. etho/services/callbacks/_base.py +92 -0
  20. etho/services/callbacks/_image.py +798 -0
  21. etho/services/callbacks/_trace.py +456 -0
  22. etho/services/camera/__init__.py +13 -0
  23. etho/services/camera/base.py +164 -0
  24. etho/services/camera/basler.py +201 -0
  25. etho/services/camera/dummy.py +139 -0
  26. etho/services/camera/hamamatsu.py +133 -0
  27. etho/services/camera/spinnaker.py +317 -0
  28. etho/services/camera/ximea.py +167 -0
  29. etho/services/daq/IOTask.py +311 -0
  30. etho/services/daq/ai.py +174 -0
  31. etho/services/dlp/dlp_make_warpfiles.py +131 -0
  32. etho/services/dlp/dlp_runners.py +238 -0
  33. etho/services/utils/__init__.py +0 -0
  34. etho/services/utils/concurrent_task.py +236 -0
  35. etho/services/utils/log_exceptions.py +39 -0
  36. etho/utils/__init__.py +0 -0
  37. etho/utils/calibration.py +88 -0
  38. etho/utils/config.py +41 -0
  39. etho/utils/runner.py +121 -0
  40. etho/utils/shuffled_cycle.py +45 -0
  41. etho/utils/sound.py +336 -0
  42. etho/utils/tui.py +105 -0
  43. etho/utils/zeroclient.py +95 -0
  44. etho_python-0.22.0.dist-info/METADATA +49 -0
  45. etho_python-0.22.0.dist-info/RECORD +47 -0
  46. etho_python-0.22.0.dist-info/WHEEL +4 -0
  47. etho_python-0.22.0.dist-info/entry_points.txt +3 -0
@@ -0,0 +1,201 @@
1
+ import time
2
+ import logging
3
+ import numpy as np
4
+ from typing import Tuple, Optional
5
+ from .base import BaseCam, gray2rgb
6
+
7
+ try:
8
+ import pypylon.pylon as py
9
+
10
+ pylon_error = None
11
+ except ImportError as pylon_error:
12
+ pass
13
+
14
+
15
+ class Basler(BaseCam):
16
+ NAME = "BAS"
17
+
18
+ def __init__(self, serialnumber):
19
+ if pylon_error is not None:
20
+ raise pylon_error
21
+ self.serialnumber: str = str(serialnumber)
22
+ self.timestamp_offset: float = 0.0
23
+
24
+ def init(self):
25
+ # self.bus =
26
+ devices = py.TlFactory.GetInstance().EnumerateDevices()
27
+ dev_dict = {d.GetSerialNumber(): d for d in devices}
28
+
29
+ self.c = py.InstantCamera(py.TlFactory.GetInstance().CreateDevice(dev_dict[self.serialnumber]))
30
+ self.c.Open()
31
+ self.timestamp_offset = self._estimate_timestamp_offset()
32
+ self.c.ChunkEnable.Value = True
33
+ self.c.PixelFormat.Value = "Mono8"
34
+ self.c.OutputQueueSize.Value = 10
35
+
36
+ self.converter = py.ImageFormatConverter()
37
+ self.converter.OutputBitAlignment = py.OutputBitAlignment_MsbAligned
38
+ self.converter.OutputPixelFormat = py.PixelType_BGR8packed
39
+
40
+ def get(self, timeout: Optional[float] = None) -> Tuple[np.ndarray, float, float]:
41
+ """
42
+
43
+ pull image from cam, convert to np.ndarray, get time stamp
44
+
45
+ Args:
46
+ timeout (Optional[float], optional): [description]. Defaults to None.
47
+
48
+ Returns:
49
+ Tuple[np.ndarray, float, float]:
50
+ image as np.array (x,y,c)
51
+ image_timestamp (in seconds UTC)
52
+ system_timestamp (in seconds UTC)
53
+
54
+ Raises:
55
+ ValueError if sth goes wrong
56
+ """
57
+ res = self.c.RetrieveResult(1000) # 1s timeout
58
+ system_ts = time.time()
59
+ if not res.GrabSucceeded():
60
+ code, desc = res.ErrorCode, res.ErrorDescription
61
+ res.Release()
62
+ raise ValueError(f"Error Code {code}, {desc}.")
63
+ else:
64
+ image_ts = res.TimeStamp
65
+ image = self.converter.Convert(res).Array
66
+ res.Release()
67
+ return image, image_ts, system_ts
68
+
69
+ def _estimate_timestamp_offset(self) -> float:
70
+ return 0
71
+
72
+ @property
73
+ def binning(self) -> Tuple[int, int]:
74
+ return self.c.BinningHorizontal.Value, self.c.BinningVertical.Value
75
+
76
+ @binning.setter
77
+ def binning(self, value):
78
+ self.c.BinningHorizontal.Value = value
79
+ self.c.BinningVertical.Value = value
80
+
81
+ @property
82
+ def roi(self) -> Tuple[int, int, int, int]:
83
+ return self.c.OffsetX.Value, self.c.OffsetY.Value, self.c.Width.Value, self.c.Height.Value
84
+
85
+ @roi.setter
86
+ def roi(self, x0_y0_x_y: Tuple[int, int, int, int]):
87
+ try:
88
+ x0, y0, x, y = x0_y0_x_y
89
+ except ValueError:
90
+ raise ValueError(f"Input {x0_y0_x_y} should be a 4-tuple.")
91
+ try:
92
+ self.c.OffsetX.Value = x0
93
+ self.c.OffsetY.Value = y0
94
+ self.c.Width.Value = x
95
+ self.c.Height.Value = y
96
+ except Exception as e:
97
+ logging.exception(f"Failed setting ROI from input {x0_y0_x_y}", exc_info=e)
98
+ x = self._min_max_inc("width", int(x), set_value=False)
99
+ y = self._min_max_inc("height", int(y), set_value=False)
100
+ x0 = self._min_max_inc("offsetX", int(x0), set_value=False)
101
+ y0 = self._min_max_inc("offsetY", int(y0), set_value=False)
102
+ logging.info(f"Trying again with these values {[x0, y0, x, y]}")
103
+ try:
104
+ self.c.OffsetX.Value = x0
105
+ self.c.OffsetY.Value = y0
106
+ self.c.Width.Value = x
107
+ self.c.Height.Value = y
108
+ except Exception as e:
109
+ logging.exception(f"Failed setting ROI from input {x0_y0_x_y}", exc_info=e)
110
+ raise
111
+ pass
112
+
113
+ def _min_max_inc(self, prop: str, value: int = None, set_value=True):
114
+ prop_map = {
115
+ "width": {"max_val": self.c.Width.Max, "min_val": self.c.Width.Max, "inc": self.c.Width.Max},
116
+ "height": {"max_val": self.c.Height.Max, "min_val": self.c.Height.Max, "inc": self.c.Height.Max},
117
+ "offsetX": {"max_val": self.c.OffsetX.Max, "min_val": self.c.OffsetX.Max, "inc": self.c.OffsetX.Max},
118
+ "offsetY": {"max_val": self.c.OffsetY.Max, "min_val": self.c.OffsetY.Max, "inc": self.c.Offsety.Max},
119
+ }
120
+
121
+ if value is not None:
122
+ value = np.clip(value, prop_map[prop]["min_val"], prop_map[prop]["max_val"])
123
+ value = np.round(value / prop_map[prop]["inc"]) * prop_map[prop]["inc"]
124
+ return value
125
+
126
+ @property
127
+ def brightness(self):
128
+ return self.c.BslBrightness.Value
129
+
130
+ @brightness.setter
131
+ def brightness(self, value: float):
132
+ self.c.BslBrightness.Value = value
133
+
134
+ @property
135
+ def exposure(self):
136
+ return self.c.ExposureTime.Value # usec
137
+
138
+ @exposure.setter
139
+ def exposure(self, value: float):
140
+ self.c.ExposureAuto.Value = "Off"
141
+ self.c.ExposureTime.Value = value # usec
142
+
143
+ @property
144
+ def gain(self):
145
+ return self.c.Gain.Value
146
+
147
+ @gain.setter
148
+ def gain(self, value: float):
149
+ self.c.Gain.Value = value
150
+
151
+ @property
152
+ def gamma(self):
153
+ return self.c.Gamma.Value
154
+
155
+ @gamma.setter
156
+ def gamma(self, value: float):
157
+ self.c.Gamma.Value = value
158
+
159
+ @property
160
+ def framerate(self):
161
+ return self.c.AcquisitionFrameRate.Value
162
+
163
+ @framerate.setter
164
+ def framerate(self, value: float):
165
+ self.c.AcquisitionFrameRateEnable.Value = True
166
+ self.c.AcquisitionFrameRate.Value = value
167
+
168
+ def start(self):
169
+ self.c.StartGrabbing(py.GrabStrategy_LatestImages)
170
+ # self.c.StartGrabbing()
171
+
172
+ def stop(self):
173
+ try:
174
+ self.c.StopGrabbing()
175
+ except Exception as e:
176
+ print(e)
177
+
178
+ def close(self):
179
+ self.stop()
180
+ self.c.Close()
181
+ tlf = py.TlFactory.GetInstance()
182
+ tlf.DestroyDevice(self.c.DetachDevice())
183
+
184
+ def reset(self):
185
+ """Reset the camera system to free all resources."""
186
+ # self.bus.FireBusReset(self.guid)
187
+ pass # self.bus.rescanBus() # does not reset but "invalidates all current camera connections"
188
+
189
+ def info_hardware(self):
190
+ cam_info = self.c.DeviceInfo
191
+
192
+ info = {
193
+ "Serial number": cam_info.GetSerialNumber(),
194
+ "Camera model": cam_info.GetModelName(),
195
+ "Camera vendor": cam_info.GetVendorName(),
196
+ # "Sensor": cam_info.sensorInfo.decode("utf-8"),
197
+ # "Resolution": cam_info.sensorResolution.decode("utf-8"),
198
+ # "Firmware version": cam_info.firmwareVersion.decode("utf-8"),
199
+ # "Firmware build time": cam_info.firmwareBuildTime.decode("utf-8"),
200
+ }
201
+ return info
@@ -0,0 +1,139 @@
1
+ import numpy as np
2
+ from typing import Tuple, Optional
3
+ import time
4
+ from .base import BaseCam
5
+ import cv2
6
+
7
+
8
+ class Dummy(BaseCam):
9
+ def __init__(self, serialnumber: int):
10
+ """Dummy cam returning noise frames for testing.
11
+
12
+ Args:
13
+ serialnumber ([type]): [description]
14
+ """
15
+ self.serialnumber: int = serialnumber
16
+
17
+ def init(self, *args, **kwargs):
18
+ self._t0 = time.time()
19
+
20
+ def get(self, timeout: Optional[float] = None) -> Tuple[np.ndarray, float, float]:
21
+ """
22
+
23
+ pull image from cam, convert to np.ndarray, get time stamp
24
+
25
+ Args:
26
+ timeout (Optional[float], optional): [description]. Defaults to None.
27
+
28
+ Returns:
29
+ Tuple[np.ndarray, float, float]:
30
+ image as np.array (x,y,c)
31
+ image_timestamp (in seconds UTC)
32
+ system_timestamp (in seconds UTC)
33
+
34
+ Raises:
35
+ ValueError is sth goes wrong
36
+ """
37
+ time.sleep(1 / (1.11 * self._framerate))
38
+ system_timestamp = time.time()
39
+ image_timestamp = system_timestamp - self._t0
40
+
41
+ image = np.random.randint(0, 64, size=(self._roi[2], self._roi[3], 3), dtype=np.uint8)
42
+ image = cv2.putText(
43
+ image,
44
+ f"{image_timestamp: 1.3f} s",
45
+ org=(20, 100),
46
+ fontFace=cv2.FONT_HERSHEY_SIMPLEX,
47
+ fontScale=1,
48
+ color=(128, 64, 96),
49
+ thickness=2,
50
+ lineType=2,
51
+ )
52
+
53
+ return image, image_timestamp, system_timestamp
54
+
55
+ def _estimate_timestamp_offset(self) -> float:
56
+ """[summary]
57
+
58
+ Returns:
59
+ float: Timestamp offset rel to system time.
60
+ Return 0 if timestamps are already in system time.
61
+ """
62
+ return 0
63
+
64
+ @property
65
+ def roi(self) -> Tuple[int, int, int, int]:
66
+ x0, y0, x, y = self._roi
67
+ return x0, y0, x, y
68
+
69
+ @roi.setter
70
+ def roi(self, x0_y0_x_y: Tuple[int, int, int, int]):
71
+ self._roi = x0_y0_x_y
72
+
73
+ @property
74
+ def framerate(self) -> float:
75
+ return self._framerate
76
+
77
+ @framerate.setter
78
+ def framerate(self, value: float):
79
+ self._framerate = value
80
+
81
+ @property
82
+ def brightness(self) -> float:
83
+ return self._brightness
84
+
85
+ @brightness.setter
86
+ def brightness(self, value: float):
87
+ self._brightness = value
88
+
89
+ @property
90
+ def exposure(self) -> float:
91
+ return self._exposure
92
+
93
+ @exposure.setter
94
+ def exposure(self, value: float):
95
+ self._exposure = float(value)
96
+
97
+ @property
98
+ def gain(self) -> float:
99
+ return self._gain
100
+
101
+ @gain.setter
102
+ def gain(self, value: float):
103
+ self._gain = float(value)
104
+
105
+ @property
106
+ def gamma(self):
107
+ return self._gamma
108
+
109
+ @gamma.setter
110
+ def gamma(self, value: float):
111
+ self._gamma = value
112
+
113
+ def start(self):
114
+ pass
115
+
116
+ def stop(self):
117
+ pass
118
+
119
+ def close(self):
120
+ pass
121
+
122
+ def reset(self):
123
+ """Reset the camera system to free all resources."""
124
+ pass
125
+
126
+ def info_imaging(self):
127
+ x0, y0, x, y = self.roi
128
+ info = {
129
+ "width": x,
130
+ "height": y,
131
+ "offsetX": x0,
132
+ "offsetY": y0,
133
+ "exposure": self.exposure / 1_000,
134
+ "brightness": self.brightness,
135
+ "gamma": self.gamma,
136
+ "gain": self.gain,
137
+ "framerate": self.framerate,
138
+ }
139
+ return info
@@ -0,0 +1,133 @@
1
+ import time
2
+ import numpy as np
3
+ from typing import Tuple
4
+ from .base import BaseCam
5
+
6
+ try:
7
+ from pylablib.devices import DCAM
8
+ hamamatsu_error = None
9
+ except ImportError as e:
10
+ hamamatsu_error = e
11
+
12
+
13
+ class Hamamatsu(BaseCam):
14
+
15
+ NAME = "HAM"
16
+
17
+ def __init__(self, serialnumber):
18
+ if hamamatsu_error is not None:
19
+ raise hamamatsu_error
20
+ self.serialnumber = int(serialnumber)
21
+ self.timestamp_offset = 0
22
+ self.im = None
23
+
24
+ def init(self):
25
+ self.c = DCAM.DCAMCamera(idx=self.serialnumber)
26
+ self.c.set_trigger_mode('int')
27
+ self.c.set_readout_speed('fast')
28
+ self.c.set_defect_correct_mode(enabled=True)
29
+
30
+ def get(self, timeout=None):
31
+ self.c.wait_for_frame() # wait for the next available frame
32
+ image = self.c.read_oldest_image() # get the oldest image which hasn't been read yet
33
+ if image is None:
34
+ return None
35
+ image = image[..., np.newaxis]
36
+ system_timestamp = time.time()
37
+ image_timestamp = system_timestamp
38
+ return image, image_timestamp, system_timestamp
39
+
40
+ @property
41
+ def binning(self) -> Tuple[int, int]:
42
+ # (horizontal, vertical)
43
+ binning = self.c.get_attribute_value("BINNING")
44
+ return (binning, binning)
45
+
46
+ @binning.setter
47
+ def binning(self, binsize):
48
+ if binsize not in [1, 2, 4]:
49
+ raise ValueError(f'Incorrect binsize arg value {binsize}. Must be 1, 2, or 4.')
50
+ self.c.set_attribute_value("BINNING", binsize)
51
+
52
+ @property
53
+ def roi(self):
54
+ roi = self.c.get_roi()
55
+ return roi[0], roi[2], roi[1] - roi[0], roi[3] - roi[2]
56
+
57
+ @roi.setter
58
+ def roi(self, x0_y0_x_y: Tuple[int, int, int, int]):
59
+ try:
60
+ x0, y0, x, y = x0_y0_x_y
61
+ self.c.set_roi(hstart=x0, vstart=y0, hend=x0+x, vend=y0+y)
62
+ except ValueError:
63
+ raise ValueError("Need 4-tuple with x0_y0_x_y")
64
+
65
+ @property
66
+ def exposure(self):
67
+ return float(self.c.get_exposure()) * 1_000.0
68
+
69
+ @exposure.setter
70
+ def exposure(self, value: float):
71
+ """Set exposure/shutter time in ms."""
72
+ self.c.set_exposure(float(value) / 1_000.0)
73
+
74
+ @property
75
+ def framerate(self):
76
+ return 1.0 / self.c.get_frame_period()
77
+
78
+ @framerate.setter
79
+ def framerate(self, value: float):
80
+ self.c.set_exposure(1.0 / float(value))
81
+
82
+ @property
83
+ def gamma(self):
84
+ return 1
85
+
86
+ @gamma.setter
87
+ def gamma(self, value: float):
88
+ pass
89
+
90
+ @property
91
+ def gain(self):
92
+ return 1 # not supported
93
+
94
+ @gain.setter
95
+ def gain(self, value: float):
96
+ pass # not supported
97
+
98
+ @property
99
+ def brightness(self):
100
+ return None
101
+
102
+ @brightness.setter
103
+ def brightness(self, value: float):
104
+ pass
105
+
106
+ def start(self):
107
+ self.c.start_acquisition()
108
+
109
+ def stop(self):
110
+ try:
111
+ self.c.stop_acquisition()
112
+ except:
113
+ pass
114
+
115
+ def close(self):
116
+ self.stop()
117
+ self.c.close()
118
+
119
+ def reset(self, sleep=None):
120
+ DCAM.DCAM.restart_lib()
121
+
122
+ def info_hardware(self):
123
+ cam_info = self.c.get_device_info()
124
+ info = {
125
+ "Serial number": cam_info.serial_number,
126
+ "Camera model": cam_info.model,
127
+ "Camera vendor": cam_info.vendor,
128
+ "Sensor": str(self.c.get_detector_size()),
129
+ "Resolution": str(self.c._get_data_dimensions_rc()),
130
+ "Firmware version": cam_info.camera_version,
131
+ "Firmware build time": '',
132
+ }
133
+ return info