etho-python 1.2.3__tar.gz → 1.2.5__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.3 → etho_python-1.2.5}/PKG-INFO +6 -3
  2. {etho_python-1.2.3 → etho_python-1.2.5}/docs/callbacks.md +1 -0
  3. {etho_python-1.2.3 → etho_python-1.2.5}/docs/configuration/protocol.md +1 -0
  4. {etho_python-1.2.3 → etho_python-1.2.5}/pyproject.toml +3 -3
  5. {etho_python-1.2.3 → etho_python-1.2.5}/src/etho/services/callbacks/_image.py +123 -77
  6. {etho_python-1.2.3 → etho_python-1.2.5}/src/etho/services/callbacks/_trace.py +15 -6
  7. etho_python-1.2.5/tests/test_pyav_callback.py +15 -0
  8. etho_python-1.2.5/tests/test_zarr_callbacks.py +18 -0
  9. {etho_python-1.2.3 → etho_python-1.2.5}/.github/workflows/draft-pdf.yml +0 -0
  10. {etho_python-1.2.3 → etho_python-1.2.5}/.github/workflows/python-package.yml +0 -0
  11. {etho_python-1.2.3 → etho_python-1.2.5}/.github/workflows/static.yml +0 -0
  12. {etho_python-1.2.3 → etho_python-1.2.5}/.gitignore +0 -0
  13. {etho_python-1.2.3 → etho_python-1.2.5}/CITATION.cff +0 -0
  14. {etho_python-1.2.3 → etho_python-1.2.5}/CONTRIBUTING.md +0 -0
  15. {etho_python-1.2.3 → etho_python-1.2.5}/LICENSE +0 -0
  16. {etho_python-1.2.3 → etho_python-1.2.5}/README.md +0 -0
  17. {etho_python-1.2.3 → etho_python-1.2.5}/docs/Makefile +0 -0
  18. {etho_python-1.2.3 → etho_python-1.2.5}/docs/README.md +0 -0
  19. {etho_python-1.2.3 → etho_python-1.2.5}/docs/_static/etho_dark.svg +0 -0
  20. {etho_python-1.2.3 → etho_python-1.2.5}/docs/_static/etho_light.svg +0 -0
  21. {etho_python-1.2.3 → etho_python-1.2.5}/docs/_templates/api_head.rst +0 -0
  22. {etho_python-1.2.3 → etho_python-1.2.5}/docs/_templates/autosummary/module.rst +0 -0
  23. {etho_python-1.2.3 → etho_python-1.2.5}/docs/api/etho.app.rst +0 -0
  24. {etho_python-1.2.3 → etho_python-1.2.5}/docs/api/etho.cli.rst +0 -0
  25. {etho_python-1.2.3 → etho_python-1.2.5}/docs/api/etho.client.rst +0 -0
  26. {etho_python-1.2.3 → etho_python-1.2.5}/docs/api/etho.services.BLTZeroService.rst +0 -0
  27. {etho_python-1.2.3 → etho_python-1.2.5}/docs/api/etho.services.DAQZeroService.rst +0 -0
  28. {etho_python-1.2.3 → etho_python-1.2.5}/docs/api/etho.services.GCMZeroService.rst +0 -0
  29. {etho_python-1.2.3 → etho_python-1.2.5}/docs/api/etho.services.GOVZeroService.rst +0 -0
  30. {etho_python-1.2.3 → etho_python-1.2.5}/docs/api/etho.services.NICounterZeroService.rst +0 -0
  31. {etho_python-1.2.3 → etho_python-1.2.5}/docs/api/etho.services.TemplateZeroService.rst +0 -0
  32. {etho_python-1.2.3 → etho_python-1.2.5}/docs/api/etho.services.ZeroService.rst +0 -0
  33. {etho_python-1.2.3 → etho_python-1.2.5}/docs/api/etho.services.camera.base.rst +0 -0
  34. {etho_python-1.2.3 → etho_python-1.2.5}/docs/api/etho.services.camera.basler.rst +0 -0
  35. {etho_python-1.2.3 → etho_python-1.2.5}/docs/api/etho.services.camera.dummy.rst +0 -0
  36. {etho_python-1.2.3 → etho_python-1.2.5}/docs/api/etho.services.camera.hamamatsu.rst +0 -0
  37. {etho_python-1.2.3 → etho_python-1.2.5}/docs/api/etho.services.camera.spinnaker.rst +0 -0
  38. {etho_python-1.2.3 → etho_python-1.2.5}/docs/api/etho.services.camera.spinnaker_old.rst +0 -0
  39. {etho_python-1.2.3 → etho_python-1.2.5}/docs/api/etho.services.camera.ximea.rst +0 -0
  40. {etho_python-1.2.3 → etho_python-1.2.5}/docs/api/etho.services.dlp.dlp_make_warpfiles.rst +0 -0
  41. {etho_python-1.2.3 → etho_python-1.2.5}/docs/api/etho.services.utils.concurrent_task.rst +0 -0
  42. {etho_python-1.2.3 → etho_python-1.2.5}/docs/api/etho.services.utils.log_exceptions.rst +0 -0
  43. {etho_python-1.2.3 → etho_python-1.2.5}/docs/api/etho.utils.calibration.rst +0 -0
  44. {etho_python-1.2.3 → etho_python-1.2.5}/docs/api/etho.utils.config.rst +0 -0
  45. {etho_python-1.2.3 → etho_python-1.2.5}/docs/api/etho.utils.runner.rst +0 -0
  46. {etho_python-1.2.3 → etho_python-1.2.5}/docs/api/etho.utils.sound.rst +0 -0
  47. {etho_python-1.2.3 → etho_python-1.2.5}/docs/api/etho.utils.tui.rst +0 -0
  48. {etho_python-1.2.3 → etho_python-1.2.5}/docs/api/etho.utils.zeroclient.rst +0 -0
  49. {etho_python-1.2.3 → etho_python-1.2.5}/docs/api_etho.rst +0 -0
  50. {etho_python-1.2.3 → etho_python-1.2.5}/docs/cli.md +0 -0
  51. {etho_python-1.2.3 → etho_python-1.2.5}/docs/conf.py +0 -0
  52. {etho_python-1.2.3 → etho_python-1.2.5}/docs/configuration/calibration_led.md +0 -0
  53. {etho_python-1.2.3 → etho_python-1.2.5}/docs/configuration/calibration_speaker.md +0 -0
  54. {etho_python-1.2.3 → etho_python-1.2.5}/docs/configuration/configuration.rst +0 -0
  55. {etho_python-1.2.3 → etho_python-1.2.5}/docs/configuration/global.md +0 -0
  56. {etho_python-1.2.3 → etho_python-1.2.5}/docs/configuration/playlist.md +0 -0
  57. {etho_python-1.2.3 → etho_python-1.2.5}/docs/extensions.md +0 -0
  58. {etho_python-1.2.3 → etho_python-1.2.5}/docs/hardware/camera.md +0 -0
  59. {etho_python-1.2.3 → etho_python-1.2.5}/docs/hardware/govee.md +0 -0
  60. {etho_python-1.2.3 → etho_python-1.2.5}/docs/hardware/hardware.rst +0 -0
  61. {etho_python-1.2.3 → etho_python-1.2.5}/docs/hardware/nidaq.md +0 -0
  62. {etho_python-1.2.3 → etho_python-1.2.5}/docs/hardware/projector.md +0 -0
  63. {etho_python-1.2.3 → etho_python-1.2.5}/docs/hardware/scanimage.md +0 -0
  64. {etho_python-1.2.3 → etho_python-1.2.5}/docs/index.rst +0 -0
  65. {etho_python-1.2.3 → etho_python-1.2.5}/docs/install.rst +0 -0
  66. {etho_python-1.2.3 → etho_python-1.2.5}/docs/logging.md +0 -0
  67. {etho_python-1.2.3 → etho_python-1.2.5}/docs/make.bat +0 -0
  68. {etho_python-1.2.3 → etho_python-1.2.5}/docs/make_api_doctree.py +0 -0
  69. {etho_python-1.2.3 → etho_python-1.2.5}/docs/tutorial.md +0 -0
  70. {etho_python-1.2.3 → etho_python-1.2.5}/paper/bib.bib +0 -0
  71. {etho_python-1.2.3 → etho_python-1.2.5}/paper/fig_flow.pdf +0 -0
  72. {etho_python-1.2.3 → etho_python-1.2.5}/paper/paper.md +0 -0
  73. {etho_python-1.2.3 → etho_python-1.2.5}/src/etho/__init__.py +0 -0
  74. {etho_python-1.2.3 → etho_python-1.2.5}/src/etho/app.py +0 -0
  75. {etho_python-1.2.3 → etho_python-1.2.5}/src/etho/assets/etho_icon1_pipeline_dark.svg +0 -0
  76. {etho_python-1.2.3 → etho_python-1.2.5}/src/etho/assets/etho_icon1_pipeline_light.svg +0 -0
  77. {etho_python-1.2.3 → etho_python-1.2.5}/src/etho/cli.py +0 -0
  78. {etho_python-1.2.3 → etho_python-1.2.5}/src/etho/client.py +0 -0
  79. {etho_python-1.2.3 → etho_python-1.2.5}/src/etho/res_app.py +0 -0
  80. {etho_python-1.2.3 → etho_python-1.2.5}/src/etho/resumable.py +0 -0
  81. {etho_python-1.2.3 → etho_python-1.2.5}/src/etho/services/BLTZeroService.py +0 -0
  82. {etho_python-1.2.3 → etho_python-1.2.5}/src/etho/services/DAQZeroService.py +0 -0
  83. {etho_python-1.2.3 → etho_python-1.2.5}/src/etho/services/DLPZeroService.py +0 -0
  84. {etho_python-1.2.3 → etho_python-1.2.5}/src/etho/services/GCMZeroService.py +0 -0
  85. {etho_python-1.2.3 → etho_python-1.2.5}/src/etho/services/GOVZeroService.py +0 -0
  86. {etho_python-1.2.3 → etho_python-1.2.5}/src/etho/services/NICounterZeroService.py +0 -0
  87. {etho_python-1.2.3 → etho_python-1.2.5}/src/etho/services/ScanImageTriggerZeroService.py +0 -0
  88. {etho_python-1.2.3 → etho_python-1.2.5}/src/etho/services/TemplateZeroService.py +0 -0
  89. {etho_python-1.2.3 → etho_python-1.2.5}/src/etho/services/ZeroService.py +0 -0
  90. {etho_python-1.2.3 → etho_python-1.2.5}/src/etho/services/__init__.py +0 -0
  91. {etho_python-1.2.3 → etho_python-1.2.5}/src/etho/services/callbacks/__init__.py +0 -0
  92. {etho_python-1.2.3 → etho_python-1.2.5}/src/etho/services/callbacks/_base.py +0 -0
  93. {etho_python-1.2.3 → etho_python-1.2.5}/src/etho/services/camera/__init__.py +0 -0
  94. {etho_python-1.2.3 → etho_python-1.2.5}/src/etho/services/camera/base.py +0 -0
  95. {etho_python-1.2.3 → etho_python-1.2.5}/src/etho/services/camera/basler.py +0 -0
  96. {etho_python-1.2.3 → etho_python-1.2.5}/src/etho/services/camera/dummy.py +0 -0
  97. {etho_python-1.2.3 → etho_python-1.2.5}/src/etho/services/camera/hamamatsu.py +0 -0
  98. {etho_python-1.2.3 → etho_python-1.2.5}/src/etho/services/camera/spinnaker.py +0 -0
  99. {etho_python-1.2.3 → etho_python-1.2.5}/src/etho/services/camera/spinnaker_old.py +0 -0
  100. {etho_python-1.2.3 → etho_python-1.2.5}/src/etho/services/camera/ximea.py +0 -0
  101. {etho_python-1.2.3 → etho_python-1.2.5}/src/etho/services/daq/IOTask.py +0 -0
  102. {etho_python-1.2.3 → etho_python-1.2.5}/src/etho/services/dlp/dlp_make_warpfiles.py +0 -0
  103. {etho_python-1.2.3 → etho_python-1.2.5}/src/etho/services/dlp/dlp_runners.py +0 -0
  104. {etho_python-1.2.3 → etho_python-1.2.5}/src/etho/services/resumable.py +0 -0
  105. {etho_python-1.2.3 → etho_python-1.2.5}/src/etho/services/utils/__init__.py +0 -0
  106. {etho_python-1.2.3 → etho_python-1.2.5}/src/etho/services/utils/concurrent_task.py +0 -0
  107. {etho_python-1.2.3 → etho_python-1.2.5}/src/etho/services/utils/log_exceptions.py +0 -0
  108. {etho_python-1.2.3 → etho_python-1.2.5}/src/etho/utils/__init__.py +0 -0
  109. {etho_python-1.2.3 → etho_python-1.2.5}/src/etho/utils/calibration.py +0 -0
  110. {etho_python-1.2.3 → etho_python-1.2.5}/src/etho/utils/config.py +0 -0
  111. {etho_python-1.2.3 → etho_python-1.2.5}/src/etho/utils/runner.py +0 -0
  112. {etho_python-1.2.3 → etho_python-1.2.5}/src/etho/utils/sound.py +0 -0
  113. {etho_python-1.2.3 → etho_python-1.2.5}/src/etho/utils/tui.py +0 -0
  114. {etho_python-1.2.3 → etho_python-1.2.5}/src/etho/utils/zeroclient.py +0 -0
  115. {etho_python-1.2.3 → etho_python-1.2.5}/tests/test_cli_gui_smoke.py +0 -0
  116. {etho_python-1.2.3 → etho_python-1.2.5}/tests/test_config.py +0 -0
  117. {etho_python-1.2.3 → etho_python-1.2.5}/tests/test_config.yaml +0 -0
  118. {etho_python-1.2.3 → etho_python-1.2.5}/tests/test_daq_playlist.py +0 -0
  119. {etho_python-1.2.3 → etho_python-1.2.5}/tests/test_gov_service.py +0 -0
  120. {etho_python-1.2.3 → etho_python-1.2.5}/tests/test_import.py +0 -0
  121. {etho_python-1.2.3 → etho_python-1.2.5}/tests/test_resumable.py +0 -0
  122. {etho_python-1.2.3 → etho_python-1.2.5}/tests/test_service_client_wiring.py +0 -0
  123. {etho_python-1.2.3 → etho_python-1.2.5}/tests/test_services.py +0 -0
  124. {etho_python-1.2.3 → etho_python-1.2.5}/tests/test_sound.py +0 -0
  125. {etho_python-1.2.3 → etho_python-1.2.5}/tests/test_sound_playlist_mono.txt +0 -0
  126. {etho_python-1.2.3 → etho_python-1.2.5}/tests/test_sound_playlist_stereo.txt +0 -0
@@ -1,16 +1,18 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: etho-python
3
- Version: 1.2.3
3
+ Version: 1.2.5
4
4
  Summary: etho
5
5
  Author-email: Jan Clemens <clemensjan@googlemail.com>
6
6
  Requires-Python: >=3.10
7
7
  Description-Content-Type: text/markdown
8
8
  Classifier: License :: OSI Approved :: MIT License
9
9
  License-File: LICENSE
10
- Requires-Dist: numpy
10
+ Requires-Dist: numpy<2; python_version < "3.11"
11
+ Requires-Dist: numpy; python_version >= "3.11"
11
12
  Requires-Dist: scipy
12
13
  Requires-Dist: h5py
13
14
  Requires-Dist: opencv-python-headless
15
+ Requires-Dist: av>=16,<18
14
16
  Requires-Dist: bleak
15
17
  Requires-Dist: pandas
16
18
  Requires-Dist: pyzmq
@@ -29,7 +31,8 @@ Requires-Dist: pydaqmx
29
31
  Requires-Dist: pyqtgraph
30
32
  Requires-Dist: qtpy
31
33
  Requires-Dist: PySide6-Essentials
32
- Requires-Dist: zarr
34
+ Requires-Dist: zarr>=2,<3; python_version < "3.11"
35
+ Requires-Dist: zarr>=3,<4; python_version >= "3.11"
33
36
  Requires-Dist: zerorpc-numpy
34
37
  Requires-Dist: pytest ; extra == "dev"
35
38
  Requires-Dist: flit>=3.2,<4 ; extra == "dev"
@@ -33,6 +33,7 @@ the callback accepts options.
33
33
  | `disp` | Display frames with OpenCV. |
34
34
  | `disp_fast` | Display frames with pyqtgraph. |
35
35
  | `save_avi` | Save frames with OpenCV `VideoWriter`. |
36
+ | `save_pyav` | Save H.264 MP4 video with PyAV. |
36
37
  | `save_ffmpegcv` | Save frames with an ffmpegcv backend. |
37
38
  | `save_vidgear` | Save frames through VidGear. |
38
39
  | `save_avi_fast` | Save video with NVIDIA Video Processing Framework. |
@@ -107,6 +107,7 @@ Common camera callbacks:
107
107
  - `disp_top`: Display a center/top view helper.
108
108
  - `save_timestamps`: Save system and camera timestamps.
109
109
  - `save_avi`: Save video with OpenCV `VideoWriter`.
110
+ - `save_pyav`: Save H.264 MP4 video with PyAV.
110
111
  - `save_ffmpegcv`: Save video with an ffmpegcv backend.
111
112
  - `save_vidgear`: Save video through VidGear.
112
113
  - `save_vidgear_round`: Save long videos, chunked into a sequences of individual files using the VidGear output.
@@ -11,13 +11,13 @@ classifiers = ["License :: OSI Approved :: MIT License"]
11
11
  dynamic = ["description"]
12
12
  requires-python = ">=3.10"
13
13
  dependencies = [
14
- 'numpy', 'scipy', 'h5py', 'opencv-python-headless', 'bleak',
14
+ 'numpy<2; python_version < "3.11"', 'numpy; python_version >= "3.11"', 'scipy', 'h5py', 'opencv-python-headless', 'av>=16,<18', 'bleak',
15
15
  'pandas', 'pyzmq', 'gevent', 'future', 'pillow', 'msgpack-python',
16
16
  'pyyaml', 'ipython', 'defopt', 'msgpack-numpy', 'rich', 'psutil', 'tables',
17
- 'pydaqmx', 'pyqtgraph', 'qtpy', 'PySide6-Essentials', 'zarr', 'zerorpc-numpy'
17
+ 'pydaqmx', 'pyqtgraph', 'qtpy', 'PySide6-Essentials', 'zarr>=2,<3; python_version < "3.11"', 'zarr>=3,<4; python_version >= "3.11"', 'zerorpc-numpy'
18
18
  ]
19
19
  readme= "README.md"
20
- version="1.2.3"
20
+ version="1.2.5"
21
21
 
22
22
  [project.scripts]
23
23
  etho = "etho.cli:main"
@@ -1,5 +1,7 @@
1
1
  """Callbacks for processing images."""
2
- import logging
2
+
3
+ import logging
4
+ from fractions import Fraction
3
5
  from xml.dom import NotFoundErr
4
6
  import numpy as np
5
7
  from . import register_callback
@@ -12,18 +14,28 @@ import tables
12
14
 
13
15
  try:
14
16
  import cv2
17
+
15
18
  cv2_import_error = None
16
- except ImportError as cv2_import_error:
17
- pass
19
+ except ImportError as cv2_import_error:
20
+ pass
21
+
22
+ try:
23
+ import av
24
+
25
+ av_import_error = None
26
+ except ImportError as av_import_error:
27
+ pass
28
+
29
+ try:
30
+ import ffmpegcv
18
31
 
19
- try:
20
- import ffmpegcv
21
32
  ffmpegcv_import_error = None
22
33
  except ImportError as ffmpegcv_import_error:
23
34
  pass
24
35
 
25
36
  try:
26
37
  from vidgear.gears import WriteGear
38
+
27
39
  vidgear_import_error = None
28
40
  except ImportError as vidgear_import_error:
29
41
  pass
@@ -32,6 +44,7 @@ try:
32
44
  from qtpy import QtWidgets
33
45
  import pyqtgraph as pg
34
46
  from pyqtgraph.widgets.RawImageWidget import RawImageWidget
47
+
35
48
  pyqtgraph_import_error = None
36
49
  except Exception as pyqtgraph_import_error: # catch generic Exception to cover missing Qt error from pyqtgraph
37
50
  pass
@@ -45,7 +58,6 @@ except Exception as zarr_import_error: # catch generic Exception to cover missi
45
58
  pass
46
59
 
47
60
 
48
-
49
61
  logger = logging.getLogger(__name__)
50
62
 
51
63
 
@@ -73,7 +85,6 @@ class ImageCallback(BaseCallback):
73
85
  @for_all_methods(log_exceptions(logger))
74
86
  @register_callback
75
87
  class ImageDisplayCV2(ImageCallback):
76
-
77
88
  FRIENDLY_NAME = "disp"
78
89
  TIMESTAMPS_ONLY = False
79
90
 
@@ -81,7 +92,7 @@ class ImageDisplayCV2(ImageCallback):
81
92
  super().__init__(data_source=data_source, poll_timeout=poll_timeout, **kwargs)
82
93
 
83
94
  if cv2_import_error is not None:
84
- logger.exception('Could not import cv2. Aborting!', exc_info=cv2_import_error)
95
+ logger.exception("Could not import cv2. Aborting!", exc_info=cv2_import_error)
85
96
  raise cv2_import_error
86
97
 
87
98
  logger.info("setting up disp")
@@ -110,7 +121,6 @@ class ImageDisplayCV2(ImageCallback):
110
121
  @for_all_methods(log_exceptions(logger))
111
122
  @register_callback
112
123
  class ImageDisplayPQG(ImageCallback):
113
-
114
124
  FRIENDLY_NAME = "disp_fast"
115
125
  TIMESTAMPS_ONLY = False
116
126
 
@@ -118,7 +128,7 @@ class ImageDisplayPQG(ImageCallback):
118
128
  super().__init__(data_source=data_source, poll_timeout=poll_timeout, **kwargs)
119
129
 
120
130
  if pyqtgraph_import_error is not None:
121
- logger.exception('Could not import pyqtgraph. Aborting!', exc_info=pyqtgraph_import_error)
131
+ logger.exception("Could not import pyqtgraph. Aborting!", exc_info=pyqtgraph_import_error)
122
132
  raise pyqtgraph_import_error
123
133
 
124
134
  logger.info("setting up ImageDisplayPQG")
@@ -155,7 +165,7 @@ class ImageDisplayPQG(ImageCallback):
155
165
 
156
166
  @for_all_methods(log_exceptions(logger))
157
167
  @register_callback
158
- class ImageWriterCV2(ImageCallback):
168
+ class ImageWriterCV2(ImageCallback):
159
169
  """Save images to video using opencv's VideoWriter.
160
170
 
161
171
  Fast but little control over video compression quality.
@@ -180,7 +190,7 @@ class ImageWriterCV2(ImageCallback):
180
190
  super().__init__(data_source=data_source, poll_timeout=poll_timeout, **kwargs)
181
191
 
182
192
  if cv2_import_error is not None:
183
- logger.exception('Could not import cv2. Aborting!', exc_info=cv2_import_error)
193
+ logger.exception("Could not import cv2. Aborting!", exc_info=cv2_import_error)
184
194
  raise cv2_import_error
185
195
 
186
196
  self.vw = cv2.VideoWriter()
@@ -200,16 +210,60 @@ class ImageWriterCV2(ImageCallback):
200
210
 
201
211
  self.vw.write(image)
202
212
 
203
- def _cleanup(self):
204
- self.vw.release()
205
- del self.vw
206
- super()._cleanup()
207
-
208
-
209
-
210
- @for_all_methods(log_exceptions(logger))
211
- @register_callback
212
- class ImageWriterFCV(ImageCallback):
213
+ def _cleanup(self):
214
+ self.vw.release()
215
+ del self.vw
216
+ super()._cleanup()
217
+
218
+
219
+ @for_all_methods(log_exceptions(logger))
220
+ @register_callback
221
+ class ImageWriterPyAV(ImageCallback):
222
+ """Save H.264 video using PyAV."""
223
+
224
+ SUFFIX: str = ".mp4"
225
+ FRIENDLY_NAME = "save_pyav"
226
+ TIMESTAMPS_ONLY = False
227
+
228
+ def __init__(self, data_source, *, poll_timeout=0.01, **kwargs):
229
+ super().__init__(data_source=data_source, poll_timeout=poll_timeout, **kwargs)
230
+
231
+ if av_import_error is not None:
232
+ logger.exception("Could not import PyAV. Aborting!", exc_info=av_import_error)
233
+ raise av_import_error
234
+
235
+ self.container = None
236
+
237
+ def _loop(self, data):
238
+ if hasattr(self.data_source, "WHOAMI") and self.data_source.WHOAMI == "array":
239
+ image = data
240
+ else:
241
+ image, timestamp = data
242
+
243
+ if self.container is None:
244
+ self.container = av.open(self.file_name + self.SUFFIX, "w")
245
+ self.stream = self.container.add_stream("libx264", rate=Fraction(str(self.frame_rate)))
246
+ self.stream.width = image.shape[1]
247
+ self.stream.height = image.shape[0]
248
+ self.stream.pix_fmt = "yuv420p"
249
+
250
+ frame_format = "gray" if image.ndim == 2 else "bgr24"
251
+ frame = av.VideoFrame.from_ndarray(image, format=frame_format)
252
+ for packet in self.stream.encode(frame):
253
+ self.container.mux(packet)
254
+
255
+ def _cleanup(self):
256
+ if self.container is not None:
257
+ for packet in self.stream.encode():
258
+ self.container.mux(packet)
259
+ self.container.close()
260
+ self.container = None
261
+ super()._cleanup()
262
+
263
+
264
+ @for_all_methods(log_exceptions(logger))
265
+ @register_callback
266
+ class ImageWriterFCV(ImageCallback):
213
267
  """Save images to video using ffmpegcv.
214
268
 
215
269
  Supports hardware accelerated encoding
@@ -232,7 +286,7 @@ class ImageWriterFCV(ImageCallback):
232
286
  super().__init__(data_source=data_source, poll_timeout=poll_timeout, **kwargs)
233
287
 
234
288
  if ffmpegcv_import_error is not None:
235
- logger.exception('Could not import ffmpegcv. Aborting!', exc_info=ffmpegcv_import_error)
289
+ logger.exception("Could not import ffmpegcv. Aborting!", exc_info=ffmpegcv_import_error)
236
290
  raise ffmpegcv_import_error
237
291
 
238
292
  # self.vw = ffmpegcv.VideoWriter()
@@ -292,7 +346,7 @@ class ImageWriterCVR(ImageCallback):
292
346
  super().__init__(data_source=data_source, poll_timeout=poll_timeout, **kwargs)
293
347
 
294
348
  if vidgear_import_error is not None:
295
- logger.exception('No!', exc_info=vidgear_import_error)
349
+ logger.exception("No!", exc_info=vidgear_import_error)
296
350
  self._cleanup()
297
351
  raise vidgear_import_error
298
352
 
@@ -308,7 +362,6 @@ class ImageWriterCVR(ImageCallback):
308
362
  except:
309
363
  self.vw = WriteGear(output=self.file_name + f"_{self.video_count:06d}" + self.SUFFIX, **self.output_params)
310
364
 
311
-
312
365
  def _loop(self, data):
313
366
  if hasattr(self.data_source, "WHOAMI") and self.data_source.WHOAMI == "array":
314
367
  image = data
@@ -369,7 +422,7 @@ class ImageWriterVidGear(ImageCallback):
369
422
  super().__init__(data_source=data_source, poll_timeout=poll_timeout, **kwargs)
370
423
 
371
424
  if vidgear_import_error is not None:
372
- logger.exception('Failed to import VidGear. Closing!', exc_info=vidgear_import_error)
425
+ logger.exception("Failed to import VidGear. Closing!", exc_info=vidgear_import_error)
373
426
  self._cleanup()
374
427
  # raise vidgear_import_error
375
428
 
@@ -398,7 +451,6 @@ class ImageWriterVidGear(ImageCallback):
398
451
  super()._cleanup()
399
452
 
400
453
 
401
-
402
454
  @for_all_methods(log_exceptions(logger))
403
455
  @register_callback
404
456
  class ImageWriterVPF(ImageCallback):
@@ -418,10 +470,11 @@ class ImageWriterVPF(ImageCallback):
418
470
 
419
471
  try:
420
472
  import sys
473
+
421
474
  sys.path.append(VPF_bin_path)
422
475
  import PyNvCodec as nvc
423
476
  except Exception as e:
424
- logging.exception('Could not import PyNvCodec. Quitting.', exc_info=e)
477
+ logging.exception("Could not import PyNvCodec. Quitting.", exc_info=e)
425
478
  self._cleanup()
426
479
 
427
480
  gpuID = 0
@@ -444,9 +497,7 @@ class ImageWriterVPF(ImageCallback):
444
497
  gpuID,
445
498
  )
446
499
  self.nvUpl = nvc.PyFrameUploader(self.nvEnc.Width(), self.nvEnc.Height(), nvc.PixelFormat.YUV420, gpuID)
447
- self.nvCvt = nvc.PySurfaceConverter(
448
- self.nvEnc.Width(), self.nvEnc.Height(), nvc.PixelFormat.YUV420, nvc.PixelFormat.NV12, gpuID
449
- )
500
+ self.nvCvt = nvc.PySurfaceConverter(self.nvEnc.Width(), self.nvEnc.Height(), nvc.PixelFormat.YUV420, nvc.PixelFormat.NV12, gpuID)
450
501
 
451
502
  def _loop(self, data):
452
503
  image, timestamp = data
@@ -478,7 +529,6 @@ class ImageWriterVPF(ImageCallback):
478
529
  @for_all_methods(log_exceptions(logging.getLogger(__name__)))
479
530
  @register_callback
480
531
  class ImageWriterH5(BaseCallback):
481
-
482
532
  FRIENDLY_NAME = "saveimg_h5"
483
533
  SUFFIX = "_images.h5"
484
534
 
@@ -524,7 +574,7 @@ class ImageWriterH5(BaseCallback):
524
574
 
525
575
  def _loop(self, data):
526
576
  data_to_save, timestamp = data # unpack
527
- data_to_save = data_to_save[np.newaxis,...]
577
+ data_to_save = data_to_save[np.newaxis, ...]
528
578
  timestamp = np.array([timestamp])[:, np.newaxis]
529
579
  if self.vanilla:
530
580
  self._init_data(data_to_save, timestamp)
@@ -542,7 +592,6 @@ class ImageWriterH5(BaseCallback):
542
592
  @for_all_methods(log_exceptions(logging.getLogger(__name__)))
543
593
  @register_callback
544
594
  class ImageWriterZarr(BaseCallback):
545
-
546
595
  FRIENDLY_NAME = "saveimg_zarr"
547
596
  SUFFIX = "_images.zarr"
548
597
 
@@ -550,13 +599,20 @@ class ImageWriterZarr(BaseCallback):
550
599
  super().__init__(data_source=data_source, poll_timeout=poll_timeout, **kwargs)
551
600
 
552
601
  if zarr_import_error is not None:
553
- logger.exception("Could not import zarr. Aborting!", exc_info=tables_import_error)
602
+ logger.exception("Could not import zarr. Aborting!", exc_info=zarr_import_error)
554
603
  raise zarr_import_error
555
604
 
556
605
  self.file_name = file_name
557
- self.f = zarr.DirectoryStore(self.file_name + self.SUFFIX) # ONLY FOR ZARR2 - otherwise zarr.storage.LocalStore
606
+ # Backward compatibility for Zarr 2; remove when Python 3.10 support ends.
607
+ if hasattr(zarr, "DirectoryStore"):
608
+ self.f = zarr.DirectoryStore(self.file_name + self.SUFFIX)
609
+ self.arrays = zarr.group(self.f, overwrite=True)
610
+ self._create_array = self.arrays.create_dataset
611
+ else:
612
+ self.f = zarr.storage.LocalStore(self.file_name + self.SUFFIX)
613
+ self.arrays = zarr.group(self.f, overwrite=True, zarr_format=2)
614
+ self._create_array = self.arrays.create_array
558
615
  self.vanilla: bool = True
559
- self.arrays = zarr.group(self.f, overwrite=True)
560
616
  self.attrs = attrs
561
617
 
562
618
  @classmethod
@@ -566,22 +622,21 @@ class ImageWriterZarr(BaseCallback):
566
622
  def _init_data(self, data, timestamp):
567
623
  compressor = Blosc(cname="zstd", clevel=3, shuffle=Blosc.BITSHUFFLE)
568
624
 
569
- self.arrays.create_dataset("images", shape=(0, *data.shape[1:]), chunks=(30, *data.shape[1:]), dtype=data.dtype, compressor=compressor)
625
+ self._create_array("images", shape=(0, *data.shape[1:]), chunks=(30, *data.shape[1:]), dtype=data.dtype, compressor=compressor)
570
626
 
571
627
  if self.attrs is not None:
572
628
  for key, val in self.attrs.items():
573
629
  self.arrays["images"].attrs[key] = val
574
630
 
575
- self.arrays.create_dataset("timestamp", shape=(0, *timestamp.shape[1:]), chunks=(100, *timestamp.shape[1:]), dtype=timestamp.dtype, compressor=None)
631
+ self._create_array("timestamp", shape=(0, *timestamp.shape[1:]), chunks=(100, *timestamp.shape[1:]), dtype=timestamp.dtype, compressor=None)
576
632
 
577
633
  def _append_data(self, data, timestamp):
578
634
  self.arrays["images"].append(data, axis=0)
579
635
  self.arrays["timestamp"].append(timestamp, axis=0)
580
636
 
581
-
582
637
  def _loop(self, data):
583
638
  data_to_save, timestamp = data # unpack
584
- data_to_save = data_to_save[np.newaxis,...]
639
+ data_to_save = data_to_save[np.newaxis, ...]
585
640
  timestamp = np.array([timestamp])[:, np.newaxis]
586
641
  if self.vanilla:
587
642
  self._init_data(data_to_save, timestamp)
@@ -619,9 +674,7 @@ class TimestampWriterHDF(ImageCallback):
619
674
 
620
675
  self.increment = increment
621
676
  self.f = h5py.File(self.file_name + self.SUFFIX, "w")
622
- self.ts = self.f.create_dataset(
623
- name="timeStamps", shape=[self.increment, data_dim], maxshape=[None, data_dim], dtype=np.float64, compression="gzip"
624
- )
677
+ self.ts = self.f.create_dataset(name="timeStamps", shape=[self.increment, data_dim], maxshape=[None, data_dim], dtype=np.float64, compression="gzip")
625
678
  self.frame_count = 0
626
679
 
627
680
  def _loop(self, data):
@@ -644,7 +697,6 @@ class TimestampWriterHDF(ImageCallback):
644
697
  @for_all_methods(log_exceptions(logger))
645
698
  @register_callback
646
699
  class ImageDisplayCenterBackCV2(ImageCallback):
647
-
648
700
  FRIENDLY_NAME = "disp_back"
649
701
  TIMESTAMPS_ONLY = False
650
702
 
@@ -683,12 +735,8 @@ class ImageDisplayCenterBackCV2(ImageCallback):
683
735
  color=self.color,
684
736
  thickness=self.thickness,
685
737
  ) # ball region
686
- image = cv2.line(
687
- image, (60, self.center_y), (self.frame_height - 60, self.center_y), self.color, self.thickness
688
- ) # y-axis cross
689
- image = cv2.line(
690
- image, (self.center_x, 60), (self.center_x, self.frame_width - 60), self.color, self.thickness
691
- ) # x-axis cross
738
+ image = cv2.line(image, (60, self.center_y), (self.frame_height - 60, self.center_y), self.color, self.thickness) # y-axis cross
739
+ image = cv2.line(image, (self.center_x, 60), (self.center_x, self.frame_width - 60), self.color, self.thickness) # x-axis cross
692
740
  # image = cv2.rectangle(image, (self.center_x-40,self.center_y-35), (self.center_x+20,self.center_y+35), color=self.color, thickness=self.thickness) # fly
693
741
  cv2.imshow("display", image)
694
742
  cv2.waitKey(1)
@@ -702,7 +750,6 @@ class ImageDisplayCenterBackCV2(ImageCallback):
702
750
  @for_all_methods(log_exceptions(logger))
703
751
  @register_callback
704
752
  class ImageDisplayCenterTopCV2(ImageCallback):
705
-
706
753
  FRIENDLY_NAME = "disp_top"
707
754
  TIMESTAMPS_ONLY = False
708
755
 
@@ -730,17 +777,26 @@ class ImageDisplayCenterTopCV2(ImageCallback):
730
777
  self.needle_color = [250, 0, 0]
731
778
  self.circ_thickness = 2
732
779
 
733
- self.flyhead_topleft, self.flyhead_bottomright = (self.circ_center_x - 45, self.circ_center_y - 50), (
734
- self.circ_center_x + 5,
735
- self.circ_center_y + 50,
780
+ self.flyhead_topleft, self.flyhead_bottomright = (
781
+ (self.circ_center_x - 45, self.circ_center_y - 50),
782
+ (
783
+ self.circ_center_x + 5,
784
+ self.circ_center_y + 50,
785
+ ),
736
786
  )
737
- self.flybody_topleft, self.flybody_bottomright = (self.circ_center_x, self.circ_center_y - 45), (
738
- self.circ_center_x + 200,
739
- self.circ_center_y + 45,
787
+ self.flybody_topleft, self.flybody_bottomright = (
788
+ (self.circ_center_x, self.circ_center_y - 45),
789
+ (
790
+ self.circ_center_x + 200,
791
+ self.circ_center_y + 45,
792
+ ),
740
793
  )
741
- self.needle_topleft, self.needle_bottomright = (self.circ_center_x + 195, self.circ_center_y - 40), (
742
- self.frame_width,
743
- self.circ_center_y + 40,
794
+ self.needle_topleft, self.needle_bottomright = (
795
+ (self.circ_center_x + 195, self.circ_center_y - 40),
796
+ (
797
+ self.frame_width,
798
+ self.circ_center_y + 40,
799
+ ),
744
800
  )
745
801
 
746
802
  @classmethod
@@ -754,21 +810,11 @@ class ImageDisplayCenterTopCV2(ImageCallback):
754
810
  image, timestamp = data
755
811
 
756
812
  image = cv2.circle(image, (self.circ_center_x, self.circ_center_y), self.circ_r, self.circ_color, self.circ_thickness)
757
- image = cv2.line(
758
- image, (self.circ_center_x, 0), (self.circ_center_x, self.frame_width), self.circ_color, self.circ_thickness
759
- )
760
- image = cv2.line(
761
- image, (0, self.circ_center_y), (self.frame_height, self.circ_center_y), self.circ_color, self.circ_thickness
762
- )
763
- image = cv2.rectangle(
764
- image, self.flyhead_topleft, self.flyhead_bottomright, color=self.circ_color, thickness=self.circ_thickness
765
- )
766
- image = cv2.rectangle(
767
- image, self.flybody_topleft, self.flybody_bottomright, color=self.circ_color, thickness=self.circ_thickness
768
- )
769
- image = cv2.rectangle(
770
- image, self.needle_topleft, self.needle_bottomright, color=self.needle_color, thickness=self.circ_thickness
771
- )
813
+ image = cv2.line(image, (self.circ_center_x, 0), (self.circ_center_x, self.frame_width), self.circ_color, self.circ_thickness)
814
+ image = cv2.line(image, (0, self.circ_center_y), (self.frame_height, self.circ_center_y), self.circ_color, self.circ_thickness)
815
+ image = cv2.rectangle(image, self.flyhead_topleft, self.flyhead_bottomright, color=self.circ_color, thickness=self.circ_thickness)
816
+ image = cv2.rectangle(image, self.flybody_topleft, self.flybody_bottomright, color=self.circ_color, thickness=self.circ_thickness)
817
+ image = cv2.rectangle(image, self.needle_topleft, self.needle_bottomright, color=self.needle_color, thickness=self.circ_thickness)
772
818
  cv2.imshow("display", image)
773
819
  cv2.waitKey(1)
774
820
 
@@ -783,7 +829,7 @@ if __name__ == "__main__":
783
829
  import ctypes
784
830
 
785
831
  ct = ImageDisplayPQG.make_concurrent(
786
- task_kwargs={"frame_width": 1000, "frame_height": 1000, "rate": .1},
832
+ task_kwargs={"frame_width": 1000, "frame_height": 1000, "rate": 0.1},
787
833
  comms="array",
788
834
  comms_kwargs={"shape": (1000, 1000, 3), "ctype": ctypes.c_uint8},
789
835
  )
@@ -216,12 +216,21 @@ class SaveZarr(BaseCallback):
216
216
  super().__init__(data_source=data_source, poll_timeout=poll_timeout, **kwargs)
217
217
 
218
218
  if zarr_import_error is not None:
219
- logger.exception("Could not import zarr. Aborting!", exc_info=tables_import_error)
219
+ logger.exception("Could not import zarr. Aborting!", exc_info=zarr_import_error)
220
220
  raise zarr_import_error
221
221
  self.file_name = file_name
222
- self.f = zarr.DirectoryStore(self.file_name + self.SUFFIX)
222
+ # Backward compatibility for Zarr 2; remove when Python 3.10 support ends.
223
+ if hasattr(zarr, "DirectoryStore"):
224
+ self.f = zarr.DirectoryStore(self.file_name + self.SUFFIX)
225
+ self.arrays = zarr.group(self.f, overwrite=True)
226
+ self._create_array = self.arrays.create_dataset
227
+ self._auto_chunks = True
228
+ else:
229
+ self.f = zarr.storage.LocalStore(self.file_name + self.SUFFIX)
230
+ self.arrays = zarr.group(self.f, overwrite=True, zarr_format=2)
231
+ self._create_array = self.arrays.create_array
232
+ self._auto_chunks = "auto"
223
233
  self.vanilla: bool = True
224
- self.arrays = zarr.group(self.f, overwrite=True)
225
234
 
226
235
  self.attrs = attrs
227
236
 
@@ -232,16 +241,16 @@ class SaveZarr(BaseCallback):
232
241
  def _init_data(self, data, systemtime):
233
242
  compressor = Blosc(cname="zstd", clevel=3, shuffle=Blosc.BITSHUFFLE)
234
243
 
235
- self.arrays.create_dataset("samples", shape=(0, *data.shape[1:]), chunks=data.shape, dtype=data.dtype, compressor=compressor)
244
+ self._create_array("samples", shape=(0, *data.shape[1:]), chunks=data.shape, dtype=data.dtype, compressor=compressor)
236
245
 
237
246
  if self.attrs is not None:
238
247
  for key, val in self.attrs.items():
239
248
  self.arrays["samples"].attrs[key] = val
240
249
 
241
- self.arrays.create_dataset("systemtime", shape=(0, 1), chunks=True, dtype=systemtime.dtype, compressor=compressor)
250
+ self._create_array("systemtime", shape=(0, 1), chunks=self._auto_chunks, dtype=systemtime.dtype, compressor=compressor)
242
251
 
243
252
  sn = np.array(data.shape[:1])[:, np.newaxis]
244
- self.arrays.create_dataset("samplenumber", shape=(0, 1), chunks=True, dtype=sn.dtype, compressor=compressor)
253
+ self._create_array("samplenumber", shape=(0, 1), chunks=self._auto_chunks, dtype=sn.dtype, compressor=compressor)
245
254
  # print([(k, v.shape) for k, v in self.arrays.items()])
246
255
 
247
256
  def _append_data(self, data, systemtime):
@@ -0,0 +1,15 @@
1
+ import av
2
+ import numpy as np
3
+
4
+ from etho.services.callbacks._image import ImageWriterPyAV
5
+
6
+
7
+ def test_pyav_callback_writes_h264_mp4(tmp_path):
8
+ writer = ImageWriterPyAV(None, file_name=str(tmp_path / "video"), frame_rate=30)
9
+ writer._loop((np.zeros((4, 6, 3), dtype=np.uint8), 1.0))
10
+ writer._cleanup()
11
+
12
+ with av.open(str(tmp_path / "video.mp4")) as video:
13
+ stream = video.streams.video[0]
14
+ assert stream.codec_context.name == "h264"
15
+ assert (stream.width, stream.height) == (6, 4)
@@ -0,0 +1,18 @@
1
+ import numpy as np
2
+ import zarr
3
+
4
+ from etho.services.callbacks._image import ImageWriterZarr
5
+ from etho.services.callbacks._trace import SaveZarr
6
+
7
+
8
+ def test_zarr_callbacks_write_v2_stores(tmp_path):
9
+ trace = SaveZarr(None, file_name=str(tmp_path / "trace"))
10
+ trace._loop((np.ones((2, 1)), 1.0))
11
+ trace._cleanup()
12
+
13
+ images = ImageWriterZarr(None, file_name=str(tmp_path / "images"))
14
+ images._loop((np.ones((2, 3)), 1.0))
15
+ images._cleanup()
16
+
17
+ assert zarr.open_group(str(tmp_path / "trace_daq.zarr"), mode="r")["samples"].shape == (2, 1)
18
+ assert zarr.open_group(str(tmp_path / "images_images.zarr"), mode="r")["images"].shape == (1, 2, 3)
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