From 07accf352030142c95e502e4130d7eb21d66adc5 Mon Sep 17 00:00:00 2001 From: Antoine Weisrock Date: Wed, 17 Jan 2024 15:27:10 +0100 Subject: [PATCH 1/7] refactor: change default backend order in ImageSaver The cv2 backend was found to be quite much slower than pil and sitk --- src/crappy/blocks/camera_processes/record.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/crappy/blocks/camera_processes/record.py b/src/crappy/blocks/camera_processes/record.py index a54f40c6..03a2ebc1 100644 --- a/src/crappy/blocks/camera_processes/record.py +++ b/src/crappy/blocks/camera_processes/record.py @@ -62,10 +62,10 @@ def __init__(self, save_backend: The backend to use for saving the images. Should be one of: :: - 'sitk', 'cv2', 'pil', 'npy' + 'sitk', 'pil', 'cv2', 'npy' - They correspond to the modules :mod:`SimpleITK`, :mod:`cv2` (OpenCV), - :mod:`PIL` (Pillow Fork), and :mod:`numpy`. Depending on the machine, + They correspond to the modules :mod:`SimpleITK`, :mod:`PIL` (Pillow + Fork), :mod:`cv2` (OpenCV), and :mod:`numpy`. Depending on the machine, some may be faster or slower. The ``img_extension`` is ignored for the backend ``'npy'``, that saves the images as raw numpy arrays. """ @@ -77,10 +77,10 @@ def __init__(self, if save_backend is None: if not isinstance(Sitk, OptionalModule): self._save_backend = 'sitk' - elif not isinstance(PIL, OptionalModule): - self._save_backend = 'cv2' elif not isinstance(PIL, OptionalModule): self._save_backend = 'pil' + elif not isinstance(cv2, OptionalModule): + self._save_backend = 'cv2' else: self._save_backend = 'npy' elif save_backend in ('sitk', 'pil', 'cv2', 'npy'): From 41c911c80841ffef71864217cc8b4b8ffa2285eb Mon Sep 17 00:00:00 2001 From: Antoine Weisrock Date: Wed, 17 Jan 2024 15:28:05 +0100 Subject: [PATCH 2/7] fix: wrong default value for parameter make_zero Causing errors when parameter unspecified and left to default. --- src/crappy/inout/daqmx.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/crappy/inout/daqmx.py b/src/crappy/inout/daqmx.py index 55e2a3fe..8bf0962e 100644 --- a/src/crappy/inout/daqmx.py +++ b/src/crappy/inout/daqmx.py @@ -47,7 +47,7 @@ def __init__(self, gain: Optional[Iterable[float]] = None, offset: Optional[Iterable[float]] = None, ranges: Optional[Iterable[float]] = None, - make_zero: Optional[Iterable[bool]] = True, + make_zero: Optional[Iterable[bool]] = None, sample_rate: float = 10000, out_channels: Optional[Iterable[str]] = None, out_gain: Optional[Iterable[float]] = None, From b696b1ae34ffddc57bced7b9246a7fc997c4ce81 Mon Sep 17 00:00:00 2001 From: Antoine Weisrock Date: Wed, 17 Jan 2024 15:28:38 +0100 Subject: [PATCH 3/7] fix: wrong data type used in get_data method Causing errors in the Blocks receiving the data --- src/crappy/inout/daqmx.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/crappy/inout/daqmx.py b/src/crappy/inout/daqmx.py index 8bf0962e..99e94b5f 100644 --- a/src/crappy/inout/daqmx.py +++ b/src/crappy/inout/daqmx.py @@ -237,7 +237,7 @@ def get_data(self) -> List[float]: PyDAQmx.DAQmx_Val_FiniteSamps, 2) PyDAQmx.DAQmxStartTask(self._handle) - data = np.empty((len(self._channels), 1), dtype=np.float64) + data = np.empty(len(self._channels), dtype=np.float64) # Reading the acquired values and stopping the task t0 = time() @@ -247,7 +247,7 @@ def get_data(self) -> List[float]: PyDAQmx.byref(self._n_reads), None) PyDAQmx.DAQmxStopTask(self._handle) - return [t0] + [data[i, :] * chan.gain + chan.offset + return [t0] + [data[i] * chan.gain + chan.offset for i, chan in enumerate(self._channels)] def set_cmd(self, *cmd: float) -> None: From 12ee73a081ce643cef0560b6159b18c3b2e18fd6 Mon Sep 17 00:00:00 2001 From: Antoine Weisrock Date: Wed, 17 Jan 2024 15:31:15 +0100 Subject: [PATCH 4/7] refactor: move docs and resources objects to _global.py file They required imports that were directly exposed to the user (e.g. import crappy.uint8) --- src/crappy/__init__.py | 56 +----------------------------------------- src/crappy/_global.py | 53 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 55 deletions(-) diff --git a/src/crappy/__init__.py b/src/crappy/__init__.py index 3b61e968..4ad155be 100644 --- a/src/crappy/__init__.py +++ b/src/crappy/__init__.py @@ -5,10 +5,6 @@ It imports all the modules and other resources, and defines aliases. """ -from pkg_resources import resource_string, resource_filename -from numpy import frombuffer, uint8 -from webbrowser import open - # Importing the modules of crappy from . import actuator from . import blocks @@ -21,7 +17,7 @@ # Importing other features from .__version__ import __version__ -from ._global import OptionalModule +from ._global import OptionalModule, docs # Useful aliases link = links.link @@ -39,53 +35,3 @@ start = Block.start_all renice = Block.renice_all reset = Block.reset - - -# Quick access to documentation -def docs(): - """Opens the online documentation of Crappy. - - It opens the latest version, and of course requires an internet access. - - .. versionadded:: 1.5.5 - .. versionchanged:: 2.0.0 renamed from doc to docs - """ - - open('https://crappy.readthedocs.io/en/latest/') - - -# Data aliases -class resources: - """This class defines aliases for quick access to the resources in the - `tool/data/` folder. - - These aliases are then used in the examples provided on the GitHub - repository, but could also be used in custom user scripts. - - .. versionadded:: 1.5.3 - """ - - try: - # Defining aliases to the images themselves - from cv2 import imdecode - speckle = imdecode(frombuffer(resource_string('crappy', - 'tool/data/speckle.png'), - uint8), flags=0) - - ve_markers = imdecode(frombuffer( - resource_string('crappy', 'tool/data/ve_markers.tif'), uint8), flags=0) - - pad = imdecode(frombuffer(resource_string('crappy', 'tool/data/pad.png'), - uint8), flags=0) - - # In case the module opencv-python is missing - except (ModuleNotFoundError, ImportError): - speckle = OptionalModule('opencv-python') - ve_markers = OptionalModule('opencv-python') - pad = OptionalModule('opencv-python') - - # Also getting the paths to the images - paths = {'pad': resource_filename('crappy', 'tool/data/pad.png'), - 'speckle': resource_filename('crappy', 'tool/data/speckle.png'), - 've_markers': resource_filename('crappy', - 'tool/data/ve_markers.tif')} diff --git a/src/crappy/_global.py b/src/crappy/_global.py index efdad44b..0fa9ad40 100644 --- a/src/crappy/_global.py +++ b/src/crappy/_global.py @@ -2,6 +2,22 @@ from typing import Optional, NoReturn, Any from importlib import import_module +import webbrowser +from pkg_resources import resource_string, resource_filename +from numpy import frombuffer, uint8 + + +# Quick access to documentation +def docs(): + """Opens the online documentation of Crappy. + + It opens the latest version, and of course requires an internet access. + + .. versionadded:: 1.5.5 + .. versionchanged:: 2.0.0 renamed from doc to docs + """ + + webbrowser.open('https://crappy.readthedocs.io/en/latest/') class OptionalModule: @@ -76,6 +92,43 @@ def __call__(self, *_, **__) -> NoReturn: raise RuntimeError(f"Missing module: {self._name}\n{self._msg}") +# Data aliases +class resources: + """This class defines aliases for quick access to the resources in the + `tool/data/` folder. + + These aliases are then used in the examples provided on the GitHub + repository, but could also be used in custom user scripts. + + .. versionadded:: 1.5.3 + """ + + try: + # Defining aliases to the images themselves + from cv2 import imdecode + speckle = imdecode(frombuffer(resource_string('crappy', + 'tool/data/speckle.png'), + uint8), flags=0) + + ve_markers = imdecode(frombuffer( + resource_string('crappy', 'tool/data/ve_markers.tif'), uint8), flags=0) + + pad = imdecode(frombuffer(resource_string('crappy', 'tool/data/pad.png'), + uint8), flags=0) + + # In case the module opencv-python is missing + except (ModuleNotFoundError, ImportError): + speckle = OptionalModule('opencv-python') + ve_markers = OptionalModule('opencv-python') + pad = OptionalModule('opencv-python') + + # Also getting the paths to the images + paths = {'pad': resource_filename('crappy', 'tool/data/pad.png'), + 'speckle': resource_filename('crappy', 'tool/data/speckle.png'), + 've_markers': resource_filename('crappy', + 'tool/data/ve_markers.tif')} + + class LinkDataError(ValueError): """Exception raised when trying to send a wrong data type through a :class:`~crappy.links.Link`.""" From d42328c7f3a607393539cdc1445e4872074a6a46 Mon Sep 17 00:00:00 2001 From: Antoine Weisrock Date: Wed, 17 Jan 2024 15:32:47 +0100 Subject: [PATCH 5/7] fix: numpy was by mistake a dependency for building Crappy This was caused by the dynamic lookup of the project version. It is now statically specified in pyproject.toml --- pyproject.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 5981d8be..88f6c4e5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,10 +1,11 @@ [build-system] -requires = ["setuptools >= 61.0", "numpy >= 1.21"] +requires = ["setuptools >= 61.0"] build-backend = "setuptools.build_meta" [project] name = "crappy" -dynamic = ["version", "readme"] +dynamic = ["readme"] +version = "2.0.2" description = "Command and Real-time Acquisition in Parallelized Python" license = {file = "LICENSE"} keywords = ["control", "command", "acquisition", "multiprocessing"] @@ -68,7 +69,6 @@ main = [ include-package-data = true [tool.setuptools.dynamic] -version = {attr = "crappy.__version__"} readme = {file = "README.md", content-type = "text/markdown"} [tool.setuptools.package-dir] From d5dc29ceaf98e41dff9a33df15d99df2dbc10031 Mon Sep 17 00:00:00 2001 From: Antoine Weisrock Date: Wed, 17 Jan 2024 15:33:12 +0100 Subject: [PATCH 6/7] fix: wrong syntax in pyproject.toml causing warnings at build time --- pyproject.toml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 88f6c4e5..99e74d99 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -66,17 +66,15 @@ main = [ ] [tool.setuptools] -include-package-data = true +package-dir = {"" = "src"} +include-package-data = false [tool.setuptools.dynamic] readme = {file = "README.md", content-type = "text/markdown"} -[tool.setuptools.package-dir] -crappy = "src/crappy" - [tool.setuptools.packages.find] where = ["src"] -include = ["*"] +include = ["crappy*"] exclude = [] namespaces = false From b276d7833a94733526ee1431e29805cb9bdf7190 Mon Sep 17 00:00:00 2001 From: Antoine Weisrock Date: Wed, 17 Jan 2024 15:36:12 +0100 Subject: [PATCH 7/7] build: update project version from 2.0.2 to 2.0.3 --- docs/source/conf.py | 2 +- pyproject.toml | 2 +- src/crappy/__version__.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index a82f7de3..6aebf3b2 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -16,7 +16,7 @@ from time import gmtime, strftime from re import match -__version__ = '2.0.2' +__version__ = '2.0.3' # -- Project information ----------------------------------------------------- diff --git a/pyproject.toml b/pyproject.toml index 99e74d99..93f67b36 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta" [project] name = "crappy" dynamic = ["readme"] -version = "2.0.2" +version = "2.0.3" description = "Command and Real-time Acquisition in Parallelized Python" license = {file = "LICENSE"} keywords = ["control", "command", "acquisition", "multiprocessing"] diff --git a/src/crappy/__version__.py b/src/crappy/__version__.py index 10656329..572682a9 100644 --- a/src/crappy/__version__.py +++ b/src/crappy/__version__.py @@ -1,3 +1,3 @@ # coding: utf-8 -__version__ = '2.0.2' +__version__ = '2.0.3'