Skip to content

Commit

Permalink
Merge pull request #91 from LaboratoireMecaniqueLille/hotfix/2.0.3
Browse files Browse the repository at this point in the history
Release of version 2.0.3
  • Loading branch information
WeisLeDocto authored Jan 17, 2024
2 parents 44e78bd + b276d78 commit b9ffd74
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 73 deletions.
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from time import gmtime, strftime
from re import match

__version__ = '2.0.2'
__version__ = '2.0.3'

# -- Project information -----------------------------------------------------

Expand Down
14 changes: 6 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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.3"
description = "Command and Real-time Acquisition in Parallelized Python"
license = {file = "LICENSE"}
keywords = ["control", "command", "acquisition", "multiprocessing"]
Expand Down Expand Up @@ -65,18 +66,15 @@ main = [
]

[tool.setuptools]
include-package-data = true
package-dir = {"" = "src"}
include-package-data = false

[tool.setuptools.dynamic]
version = {attr = "crappy.__version__"}
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

Expand Down
56 changes: 1 addition & 55 deletions src/crappy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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')}
2 changes: 1 addition & 1 deletion src/crappy/__version__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# coding: utf-8

__version__ = '2.0.2'
__version__ = '2.0.3'
53 changes: 53 additions & 0 deletions src/crappy/_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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`."""
Expand Down
10 changes: 5 additions & 5 deletions src/crappy/blocks/camera_processes/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand All @@ -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'):
Expand Down
6 changes: 3 additions & 3 deletions src/crappy/inout/daqmx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()
Expand All @@ -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:
Expand Down

0 comments on commit b9ffd74

Please sign in to comment.