etho-python 1.2__tar.gz → 1.2.2__tar.gz

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 (126) hide show
  1. {etho_python-1.2 → etho_python-1.2.2}/PKG-INFO +1 -1
  2. etho_python-1.2.2/docs/hardware/govee.md +29 -0
  3. {etho_python-1.2 → etho_python-1.2.2}/docs/hardware/hardware.rst +2 -0
  4. {etho_python-1.2 → etho_python-1.2.2}/pyproject.toml +1 -1
  5. {etho_python-1.2 → etho_python-1.2.2}/src/etho/services/camera/__init__.py +2 -0
  6. etho_python-1.2.2/src/etho/services/camera/spinnaker_old.py +313 -0
  7. {etho_python-1.2 → etho_python-1.2.2}/src/etho/services/daq/IOTask.py +66 -51
  8. {etho_python-1.2 → etho_python-1.2.2}/src/etho/utils/sound.py +1 -1
  9. {etho_python-1.2 → etho_python-1.2.2}/tests/test_sound.py +9 -0
  10. {etho_python-1.2 → etho_python-1.2.2}/.github/workflows/draft-pdf.yml +0 -0
  11. {etho_python-1.2 → etho_python-1.2.2}/.github/workflows/python-package.yml +0 -0
  12. {etho_python-1.2 → etho_python-1.2.2}/.github/workflows/static.yml +0 -0
  13. {etho_python-1.2 → etho_python-1.2.2}/.gitignore +0 -0
  14. {etho_python-1.2 → etho_python-1.2.2}/CITATION.cff +0 -0
  15. {etho_python-1.2 → etho_python-1.2.2}/CONTRIBUTING.md +0 -0
  16. {etho_python-1.2 → etho_python-1.2.2}/LICENSE +0 -0
  17. {etho_python-1.2 → etho_python-1.2.2}/README.md +0 -0
  18. {etho_python-1.2 → etho_python-1.2.2}/docs/Makefile +0 -0
  19. {etho_python-1.2 → etho_python-1.2.2}/docs/README.md +0 -0
  20. {etho_python-1.2 → etho_python-1.2.2}/docs/_static/etho_dark.svg +0 -0
  21. {etho_python-1.2 → etho_python-1.2.2}/docs/_static/etho_light.svg +0 -0
  22. {etho_python-1.2 → etho_python-1.2.2}/docs/_templates/api_head.rst +0 -0
  23. {etho_python-1.2 → etho_python-1.2.2}/docs/_templates/autosummary/module.rst +0 -0
  24. {etho_python-1.2 → etho_python-1.2.2}/docs/api/etho.app.rst +0 -0
  25. {etho_python-1.2 → etho_python-1.2.2}/docs/api/etho.cli.rst +0 -0
  26. {etho_python-1.2 → etho_python-1.2.2}/docs/api/etho.client.rst +0 -0
  27. {etho_python-1.2 → etho_python-1.2.2}/docs/api/etho.services.BLTZeroService.rst +0 -0
  28. {etho_python-1.2 → etho_python-1.2.2}/docs/api/etho.services.DAQZeroService.rst +0 -0
  29. {etho_python-1.2 → etho_python-1.2.2}/docs/api/etho.services.GCMZeroService.rst +0 -0
  30. {etho_python-1.2 → etho_python-1.2.2}/docs/api/etho.services.GOVZeroService.rst +0 -0
  31. {etho_python-1.2 → etho_python-1.2.2}/docs/api/etho.services.NICounterZeroService.rst +0 -0
  32. {etho_python-1.2 → etho_python-1.2.2}/docs/api/etho.services.TemplateZeroService.rst +0 -0
  33. {etho_python-1.2 → etho_python-1.2.2}/docs/api/etho.services.ZeroService.rst +0 -0
  34. {etho_python-1.2 → etho_python-1.2.2}/docs/api/etho.services.camera.base.rst +0 -0
  35. {etho_python-1.2 → etho_python-1.2.2}/docs/api/etho.services.camera.basler.rst +0 -0
  36. {etho_python-1.2 → etho_python-1.2.2}/docs/api/etho.services.camera.dummy.rst +0 -0
  37. {etho_python-1.2 → etho_python-1.2.2}/docs/api/etho.services.camera.hamamatsu.rst +0 -0
  38. {etho_python-1.2 → etho_python-1.2.2}/docs/api/etho.services.camera.spinnaker.rst +0 -0
  39. {etho_python-1.2 → etho_python-1.2.2}/docs/api/etho.services.camera.ximea.rst +0 -0
  40. {etho_python-1.2 → etho_python-1.2.2}/docs/api/etho.services.dlp.dlp_make_warpfiles.rst +0 -0
  41. {etho_python-1.2 → etho_python-1.2.2}/docs/api/etho.services.utils.concurrent_task.rst +0 -0
  42. {etho_python-1.2 → etho_python-1.2.2}/docs/api/etho.services.utils.log_exceptions.rst +0 -0
  43. {etho_python-1.2 → etho_python-1.2.2}/docs/api/etho.utils.calibration.rst +0 -0
  44. {etho_python-1.2 → etho_python-1.2.2}/docs/api/etho.utils.config.rst +0 -0
  45. {etho_python-1.2 → etho_python-1.2.2}/docs/api/etho.utils.runner.rst +0 -0
  46. {etho_python-1.2 → etho_python-1.2.2}/docs/api/etho.utils.shuffled_cycle.rst +0 -0
  47. {etho_python-1.2 → etho_python-1.2.2}/docs/api/etho.utils.sound.rst +0 -0
  48. {etho_python-1.2 → etho_python-1.2.2}/docs/api/etho.utils.tui.rst +0 -0
  49. {etho_python-1.2 → etho_python-1.2.2}/docs/api/etho.utils.zeroclient.rst +0 -0
  50. {etho_python-1.2 → etho_python-1.2.2}/docs/api_etho.rst +0 -0
  51. {etho_python-1.2 → etho_python-1.2.2}/docs/callbacks.md +0 -0
  52. {etho_python-1.2 → etho_python-1.2.2}/docs/cli.md +0 -0
  53. {etho_python-1.2 → etho_python-1.2.2}/docs/conf.py +0 -0
  54. {etho_python-1.2 → etho_python-1.2.2}/docs/configuration/calibration_led.md +0 -0
  55. {etho_python-1.2 → etho_python-1.2.2}/docs/configuration/calibration_speaker.md +0 -0
  56. {etho_python-1.2 → etho_python-1.2.2}/docs/configuration/configuration.rst +0 -0
  57. {etho_python-1.2 → etho_python-1.2.2}/docs/configuration/global.md +0 -0
  58. {etho_python-1.2 → etho_python-1.2.2}/docs/configuration/playlist.md +0 -0
  59. {etho_python-1.2 → etho_python-1.2.2}/docs/configuration/protocol.md +0 -0
  60. {etho_python-1.2 → etho_python-1.2.2}/docs/extensions.md +0 -0
  61. {etho_python-1.2 → etho_python-1.2.2}/docs/hardware/camera.md +0 -0
  62. {etho_python-1.2 → etho_python-1.2.2}/docs/hardware/nidaq.md +0 -0
  63. {etho_python-1.2 → etho_python-1.2.2}/docs/hardware/projector.md +0 -0
  64. {etho_python-1.2 → etho_python-1.2.2}/docs/hardware/scanimage.md +0 -0
  65. {etho_python-1.2 → etho_python-1.2.2}/docs/index.rst +0 -0
  66. {etho_python-1.2 → etho_python-1.2.2}/docs/install.rst +0 -0
  67. {etho_python-1.2 → etho_python-1.2.2}/docs/logging.md +0 -0
  68. {etho_python-1.2 → etho_python-1.2.2}/docs/make.bat +0 -0
  69. {etho_python-1.2 → etho_python-1.2.2}/docs/make_api_doctree.py +0 -0
  70. {etho_python-1.2 → etho_python-1.2.2}/docs/tutorial.md +0 -0
  71. {etho_python-1.2 → etho_python-1.2.2}/paper/bib.bib +0 -0
  72. {etho_python-1.2 → etho_python-1.2.2}/paper/fig_flow.pdf +0 -0
  73. {etho_python-1.2 → etho_python-1.2.2}/paper/paper.md +0 -0
  74. {etho_python-1.2 → etho_python-1.2.2}/src/etho/__init__.py +0 -0
  75. {etho_python-1.2 → etho_python-1.2.2}/src/etho/app.py +0 -0
  76. {etho_python-1.2 → etho_python-1.2.2}/src/etho/assets/etho_icon1_pipeline_dark.svg +0 -0
  77. {etho_python-1.2 → etho_python-1.2.2}/src/etho/assets/etho_icon1_pipeline_light.svg +0 -0
  78. {etho_python-1.2 → etho_python-1.2.2}/src/etho/cli.py +0 -0
  79. {etho_python-1.2 → etho_python-1.2.2}/src/etho/client.py +0 -0
  80. {etho_python-1.2 → etho_python-1.2.2}/src/etho/res_app.py +0 -0
  81. {etho_python-1.2 → etho_python-1.2.2}/src/etho/resumable.py +0 -0
  82. {etho_python-1.2 → etho_python-1.2.2}/src/etho/services/BLTZeroService.py +0 -0
  83. {etho_python-1.2 → etho_python-1.2.2}/src/etho/services/DAQZeroService.py +0 -0
  84. {etho_python-1.2 → etho_python-1.2.2}/src/etho/services/DLPZeroService.py +0 -0
  85. {etho_python-1.2 → etho_python-1.2.2}/src/etho/services/GCMZeroService.py +0 -0
  86. {etho_python-1.2 → etho_python-1.2.2}/src/etho/services/GOVZeroService.py +0 -0
  87. {etho_python-1.2 → etho_python-1.2.2}/src/etho/services/NICounterZeroService.py +0 -0
  88. {etho_python-1.2 → etho_python-1.2.2}/src/etho/services/ScanImageTriggerZeroService.py +0 -0
  89. {etho_python-1.2 → etho_python-1.2.2}/src/etho/services/TemplateZeroService.py +0 -0
  90. {etho_python-1.2 → etho_python-1.2.2}/src/etho/services/ZeroService.py +0 -0
  91. {etho_python-1.2 → etho_python-1.2.2}/src/etho/services/__init__.py +0 -0
  92. {etho_python-1.2 → etho_python-1.2.2}/src/etho/services/callbacks/__init__.py +0 -0
  93. {etho_python-1.2 → etho_python-1.2.2}/src/etho/services/callbacks/_base.py +0 -0
  94. {etho_python-1.2 → etho_python-1.2.2}/src/etho/services/callbacks/_image.py +0 -0
  95. {etho_python-1.2 → etho_python-1.2.2}/src/etho/services/callbacks/_trace.py +0 -0
  96. {etho_python-1.2 → etho_python-1.2.2}/src/etho/services/camera/base.py +0 -0
  97. {etho_python-1.2 → etho_python-1.2.2}/src/etho/services/camera/basler.py +0 -0
  98. {etho_python-1.2 → etho_python-1.2.2}/src/etho/services/camera/dummy.py +0 -0
  99. {etho_python-1.2 → etho_python-1.2.2}/src/etho/services/camera/hamamatsu.py +0 -0
  100. {etho_python-1.2 → etho_python-1.2.2}/src/etho/services/camera/spinnaker.py +0 -0
  101. {etho_python-1.2 → etho_python-1.2.2}/src/etho/services/camera/ximea.py +0 -0
  102. {etho_python-1.2 → etho_python-1.2.2}/src/etho/services/daq/ai.py +0 -0
  103. {etho_python-1.2 → etho_python-1.2.2}/src/etho/services/dlp/dlp_make_warpfiles.py +0 -0
  104. {etho_python-1.2 → etho_python-1.2.2}/src/etho/services/dlp/dlp_runners.py +0 -0
  105. {etho_python-1.2 → etho_python-1.2.2}/src/etho/services/resumable.py +0 -0
  106. {etho_python-1.2 → etho_python-1.2.2}/src/etho/services/utils/__init__.py +0 -0
  107. {etho_python-1.2 → etho_python-1.2.2}/src/etho/services/utils/concurrent_task.py +0 -0
  108. {etho_python-1.2 → etho_python-1.2.2}/src/etho/services/utils/log_exceptions.py +0 -0
  109. {etho_python-1.2 → etho_python-1.2.2}/src/etho/utils/__init__.py +0 -0
  110. {etho_python-1.2 → etho_python-1.2.2}/src/etho/utils/calibration.py +0 -0
  111. {etho_python-1.2 → etho_python-1.2.2}/src/etho/utils/config.py +0 -0
  112. {etho_python-1.2 → etho_python-1.2.2}/src/etho/utils/runner.py +0 -0
  113. {etho_python-1.2 → etho_python-1.2.2}/src/etho/utils/shuffled_cycle.py +0 -0
  114. {etho_python-1.2 → etho_python-1.2.2}/src/etho/utils/tui.py +0 -0
  115. {etho_python-1.2 → etho_python-1.2.2}/src/etho/utils/zeroclient.py +0 -0
  116. {etho_python-1.2 → etho_python-1.2.2}/tests/test_cli_gui_smoke.py +0 -0
  117. {etho_python-1.2 → etho_python-1.2.2}/tests/test_config.py +0 -0
  118. {etho_python-1.2 → etho_python-1.2.2}/tests/test_config.yaml +0 -0
  119. {etho_python-1.2 → etho_python-1.2.2}/tests/test_gov_service.py +0 -0
  120. {etho_python-1.2 → etho_python-1.2.2}/tests/test_import.py +0 -0
  121. {etho_python-1.2 → etho_python-1.2.2}/tests/test_resumable.py +0 -0
  122. {etho_python-1.2 → etho_python-1.2.2}/tests/test_service_client_wiring.py +0 -0
  123. {etho_python-1.2 → etho_python-1.2.2}/tests/test_services.py +0 -0
  124. {etho_python-1.2 → etho_python-1.2.2}/tests/test_shuffled_cycle.py +0 -0
  125. {etho_python-1.2 → etho_python-1.2.2}/tests/test_sound_playlist_mono.txt +0 -0
  126. {etho_python-1.2 → etho_python-1.2.2}/tests/test_sound_playlist_stereo.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: etho-python
3
- Version: 1.2
3
+ Version: 1.2.2
4
4
  Summary: etho
5
5
  Author-email: Jan Clemens <clemensjan@googlemail.com>
6
6
  Requires-Python: >=3.10
@@ -0,0 +1,29 @@
1
+ # Govee Temperature/Humidity Sensors
2
+
3
+ The `GOV` service supports Govee H5075 sensors over Bluetooth Low Energy (BLE).
4
+
5
+ ## Discover the Sensor Address
6
+
7
+ On the acquisition computer, activate the `etho` conda environment and scan for
8
+ nearby sensors:
9
+
10
+ ```powershell
11
+ conda activate etho
12
+ etho govee
13
+ ```
14
+
15
+ After scanning for 10 seconds, the command lists each sensor's address, name,
16
+ temperature, and humidity. Match the temperature and humidity pair in a row to
17
+ the values shown on the physical sensor's display. If multiple sensors show
18
+ similar values, temporarily move or warm one sensor, run `etho govee` again,
19
+ and match the changed readings.
20
+
21
+ Copy the address from the matching row into the sensor's protocol block:
22
+
23
+ ```yaml
24
+ GOV:
25
+ address: AA:BB:CC:DD:EE:FF
26
+ interval: 60
27
+ ```
28
+
29
+ The `interval` is the logging interval in seconds.
@@ -12,6 +12,7 @@ operated from protocols:
12
12
  - :doc:`National Instruments DAQmx compatible devices <nidaq>`
13
13
  - :doc:`DLP projectors <projector>`
14
14
  - :doc:`ScanImage microscopes <scanimage>`
15
+ - :doc:`Govee H5075 temperature/humidity sensors <govee>`
15
16
 
16
17
  You can add support for new hardware by implementing the appropriate service interface. See :ref:`extensions`.
17
18
 
@@ -24,3 +25,4 @@ You can add support for new hardware by implementing the appropriate service int
24
25
  nidaq
25
26
  projector
26
27
  scanimage
28
+ govee
@@ -17,7 +17,7 @@ dependencies = [
17
17
  'pydaqmx', 'pyqtgraph', 'qtpy', 'PySide6-Essentials', 'zarr', 'zerorpc-numpy'
18
18
  ]
19
19
  readme= "README.md"
20
- version="1.2"
20
+ version="1.2.2"
21
21
 
22
22
  [project.scripts]
23
23
  etho = "etho.cli:main"
@@ -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
@@ -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
- self.CreateAIVoltageChan(
121
- name,
122
- "",
123
- terminal,
124
- limit[0],
125
- limit[1],
126
- daq.DAQmx_Val_Volts,
127
- None,
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
- self.num_samples_per_chan = 5000
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 * self.num_channels * 2)
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 * self.num_channels * 2)
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"datagen {self.data_gen} StopIteration {e}")
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
- self.ReadAnalogF64(
221
- daq.DAQmx_Val_Auto,
222
- 1.0,
223
- daq.DAQmx_Val_GroupByScanNumber,
224
- self._data,
225
- self.num_samples_per_chan * self.num_channels,
226
- daq.byref(self.samples_read),
227
- None,
228
- )
229
- # only keep samples that were actually read, .value converts c_long to int
230
- self._data = self._data[: self.samples_read.value, :]
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
- self.WriteAnalogF64(
234
- self._data.shape[0],
235
- 0,
236
- daq.DAQmx_Val_WaitInfinitely,
237
- daq.DAQmx_Val_GroupByScanNumber,
238
- self._data,
239
- daq.byref(self.samples_read),
240
- None,
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
- self.WriteDigitalLines(
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_read),
250
- None,
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
 
@@ -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:
@@ -41,3 +41,12 @@ def test_parse_table_ignores_unused_playlist_columns():
41
41
  assert list(parsed.columns) == ["stimFileName", "silencePre", "silencePost", "intensity", "freq"]
42
42
  assert parsed.loc[0, "stimFileName"] == ["SIN_100_0_3000"]
43
43
  assert parsed.loc[0, "intensity"] == [1.0]
44
+
45
+
46
+ def test_parse_table_accepts_quoted_bracketed_stimulus_name():
47
+ playlist = pd.DataFrame(
48
+ [["['SIN_100_0_3000']", 1000, 1000, 1.0, 100]],
49
+ columns=["stimFileName", "silencePre", "silencePost", "intensity", "freq"],
50
+ )
51
+
52
+ assert parse_table(playlist).loc[0, "stimFileName"] == ["SIN_100_0_3000"]
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes