Skip to content

Commit 9fcdc3d

Browse files
authored
v0.14.1
version 0.14.1
2 parents 4ea234d + 235d765 commit 9fcdc3d

File tree

6 files changed

+86
-22
lines changed

6 files changed

+86
-22
lines changed

.github/workflows/pypi.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Publish package to PyPI
2+
on:
3+
push:
4+
tags:
5+
- 'v*'
6+
jobs:
7+
build-n-publish:
8+
name: Build and publish package to PyPI
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v2
12+
- name: Set up Python
13+
uses: actions/setup-python@v1
14+
with:
15+
python-version: "3.7"
16+
- name: Install poetry
17+
run: |
18+
curl -fsS -o get-poetry.py https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py
19+
python get-poetry.py -y
20+
- name: Publish
21+
env:
22+
PYPI_TOKEN: ${{ secrets.pypi_password }}
23+
run: |
24+
$HOME/.poetry/bin/poetry config pypi-token.pypi $PYPI_TOKEN
25+
$HOME/.poetry/bin/poetry publish --build

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ Dependencies
2424
* **pyobs** for the core funcionality. It is not included in the *requirements.txt*, so needs to be installed
2525
separately.
2626
* [Aravis](https://github.com/AravisProject/aravis) for accessing the camera.
27+
* [python-aravis](https://github.com/SintefManufacturing/python-aravis) as an easy-to-use interface.
2728

pyobs_aravis/araviscamera.py

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
import threading
23
import time
34
from typing import Any, Dict, Optional, List
45

@@ -27,6 +28,7 @@ def __init__(self, device: str, settings: Optional[Dict[str, Any]] = None, **kwa
2728
self._device_name = device
2829
self._camera: Optional[aravis.Camera] = None
2930
self._settings: Dict[str, Any] = {} if settings is None else settings
31+
self._camera_lock = threading.Lock()
3032

3133
# thread
3234
if device is not None:
@@ -36,11 +38,25 @@ def __init__(self, device: str, settings: Optional[Dict[str, Any]] = None, **kwa
3638

3739
def open(self) -> None:
3840
"""Open module."""
41+
BaseVideo.open(self)
42+
3943
# list devices
4044
ids = aravis.get_device_ids()
4145
if self._device_name not in ids:
4246
raise ValueError('Could not find given device name in list of available cameras.')
4347

48+
# open camera
49+
self.activate_camera()
50+
51+
def close(self) -> None:
52+
"""Close the module."""
53+
BaseVideo.close(self)
54+
with self._camera_lock:
55+
self._close_camera()
56+
57+
def _open_camera(self) -> None:
58+
"""Open camera."""
59+
4460
# open camera
4561
log.info('Connecting to camera %s...', self._device_name)
4662
self._camera = aravis.Camera(self._device_name)
@@ -51,32 +67,47 @@ def open(self) -> None:
5167
log.info(f'Setting value {key}={value}...')
5268
self._camera.set_feature(key, value)
5369

54-
# open base
55-
BaseVideo.open(self)
56-
57-
def close(self) -> None:
58-
"""Close the module."""
59-
BaseVideo.close(self)
70+
# start acquisition
71+
self._camera.start_acquisition_continuous(nb_buffers=5)
6072

73+
def _close_camera(self) -> None:
74+
"""Close camera."""
6175
# stop camera
6276
if self._camera is not None:
77+
log.info('Closing camera...')
6378
self._camera.stop_acquisition()
6479
self._camera.shutdown()
80+
self._camera = None
81+
82+
def _activate_camera(self) -> None:
83+
"""Can be overridden by derived class to implement inactivity sleep"""
84+
with self._camera_lock:
85+
self._open_camera()
86+
87+
def _deactivate_camera(self) -> None:
88+
"""Can be overridden by derived class to implement inactivity sleep"""
89+
with self._camera_lock:
90+
self._close_camera()
6591

6692
def _capture(self) -> None:
67-
# start acquisition
68-
self._camera.start_acquisition_continuous(nb_buffers=5)
93+
"""Take new images in loop."""
6994

7095
# loop until closing
7196
last = time.time()
7297
while not self.closing.is_set():
73-
# read frame
74-
frame = self._camera.pop_frame()
98+
# no camera or not active?
99+
if self._camera is None or not self.camera_active:
100+
# wait a little
101+
self.closing.wait(0.1)
102+
continue
75103

76104
# if time since last image is too short, wait a little
77105
if time.time() - last < self._interval:
78106
self.closing.wait(0.01)
79107
continue
108+
109+
# read frame
110+
frame = self._camera.pop_frame()
80111
last = time.time()
81112

82113
# process it
@@ -91,6 +122,7 @@ def set_exposure_time(self, exposure_time: float, **kwargs: Any) -> None:
91122
Raises:
92123
ValueError: If exposure time could not be set.
93124
"""
125+
self.activate_camera()
94126
self._camera.set_exposure_time(exposure_time * 1e6)
95127

96128
def get_exposure_time(self, **kwargs: Any) -> float:
@@ -99,6 +131,7 @@ def get_exposure_time(self, **kwargs: Any) -> float:
99131
Returns:
100132
Exposure time in seconds.
101133
"""
134+
self.activate_camera()
102135
return self._camera.get_exposure_time() / 1e6
103136

104137

pyproject.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[tool.poetry]
2+
name = "pyobs-aravis"
3+
version = "0.14.1"
4+
description = "pyobs module for Aravis cameras"
5+
authors = ["Tim-Oliver Husser <[email protected]>"]
6+
license = "MIT"
7+
8+
[tool.poetry.dependencies]
9+
python = ">=3.7,<3.11"
10+
numpy = "^1.21"
11+
PyGObject = "^3.42"
12+
13+
[tool.poetry.dev-dependencies]
14+
15+
[build-system]
16+
requires = ["poetry-core>=1.0.0"]
17+
build-backend = "poetry.core.masonry.api"

requirements.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

setup.py

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)