pyobs-asi 2.0.0.dev4__tar.gz → 2.0.0.dev6__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.
- pyobs_asi-2.0.0.dev6/.github/dependabot.yml +15 -0
- pyobs_asi-2.0.0.dev6/.github/workflows/dependabot-automerge.yml +24 -0
- pyobs_asi-2.0.0.dev6/.github/workflows/pyrefly.yml +23 -0
- pyobs_asi-2.0.0.dev6/.github/workflows/pytest.yml +25 -0
- {pyobs_asi-2.0.0.dev4 → pyobs_asi-2.0.0.dev6}/PKG-INFO +4 -4
- {pyobs_asi-2.0.0.dev4 → pyobs_asi-2.0.0.dev6}/pyobs_asi/asicamera.py +39 -13
- {pyobs_asi-2.0.0.dev4 → pyobs_asi-2.0.0.dev6}/pyobs_asi/gui.py +39 -16
- {pyobs_asi-2.0.0.dev4 → pyobs_asi-2.0.0.dev6}/pyproject.toml +10 -4
- pyobs_asi-2.0.0.dev6/tests/test_asicamera.py +145 -0
- pyobs_asi-2.0.0.dev6/tests/test_import.py +27 -0
- pyobs_asi-2.0.0.dev6/uv.lock +3160 -0
- pyobs_asi-2.0.0.dev4/uv.lock +0 -2700
- {pyobs_asi-2.0.0.dev4 → pyobs_asi-2.0.0.dev6}/.github/workflows/pypi.yml +0 -0
- {pyobs_asi-2.0.0.dev4 → pyobs_asi-2.0.0.dev6}/.github/workflows/ruff.yml +0 -0
- {pyobs_asi-2.0.0.dev4 → pyobs_asi-2.0.0.dev6}/.pre-commit-config.yaml +0 -0
- {pyobs_asi-2.0.0.dev4 → pyobs_asi-2.0.0.dev6}/.readthedocs.yml +0 -0
- {pyobs_asi-2.0.0.dev4 → pyobs_asi-2.0.0.dev6}/CHANGELOG.rst +0 -0
- {pyobs_asi-2.0.0.dev4 → pyobs_asi-2.0.0.dev6}/LICENSE +0 -0
- {pyobs_asi-2.0.0.dev4 → pyobs_asi-2.0.0.dev6}/README.md +0 -0
- {pyobs_asi-2.0.0.dev4 → pyobs_asi-2.0.0.dev6}/docs/Makefile +0 -0
- {pyobs_asi-2.0.0.dev4 → pyobs_asi-2.0.0.dev6}/docs/make.bat +0 -0
- {pyobs_asi-2.0.0.dev4 → pyobs_asi-2.0.0.dev6}/docs/requirements.txt +0 -0
- {pyobs_asi-2.0.0.dev4 → pyobs_asi-2.0.0.dev6}/docs/source/_static/pyobs.gif +0 -0
- {pyobs_asi-2.0.0.dev4 → pyobs_asi-2.0.0.dev6}/docs/source/conf.py +0 -0
- {pyobs_asi-2.0.0.dev4 → pyobs_asi-2.0.0.dev6}/docs/source/index.rst +0 -0
- {pyobs_asi-2.0.0.dev4 → pyobs_asi-2.0.0.dev6}/pyobs_asi/__init__.py +0 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
name: Dependabot auto-merge
|
|
2
|
+
|
|
3
|
+
on: pull_request
|
|
4
|
+
|
|
5
|
+
permissions:
|
|
6
|
+
contents: write
|
|
7
|
+
pull-requests: write
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
dependabot:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
if: ${{ github.event.pull_request.user.login == 'dependabot[bot]' }}
|
|
13
|
+
steps:
|
|
14
|
+
- name: Fetch Dependabot metadata
|
|
15
|
+
id: metadata
|
|
16
|
+
uses: dependabot/fetch-metadata@v2
|
|
17
|
+
with:
|
|
18
|
+
compat-lookup: true
|
|
19
|
+
- name: Enable auto-merge for patch and minor updates
|
|
20
|
+
if: ${{ steps.metadata.outputs.update-type == 'version-update:semver-patch' || steps.metadata.outputs.update-type == 'version-update:semver-minor' }}
|
|
21
|
+
run: gh pr merge --auto --merge "$PR_URL"
|
|
22
|
+
env:
|
|
23
|
+
PR_URL: ${{ github.event.pull_request.html_url }}
|
|
24
|
+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
name: pyrefly
|
|
2
|
+
on: push
|
|
3
|
+
|
|
4
|
+
jobs:
|
|
5
|
+
pyrefly:
|
|
6
|
+
runs-on: ubuntu-latest
|
|
7
|
+
timeout-minutes: 10
|
|
8
|
+
|
|
9
|
+
steps:
|
|
10
|
+
- name: Check out repository code
|
|
11
|
+
uses: actions/checkout@v4
|
|
12
|
+
|
|
13
|
+
- name: Set up Python
|
|
14
|
+
uses: astral-sh/setup-uv@v5
|
|
15
|
+
with:
|
|
16
|
+
enable-cache: true
|
|
17
|
+
python-version: "3.13"
|
|
18
|
+
|
|
19
|
+
- name: Install packages
|
|
20
|
+
run: uv sync --all-extras --dev
|
|
21
|
+
|
|
22
|
+
- name: Run pyrefly
|
|
23
|
+
run: uv run pyrefly check
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
name: PyTest
|
|
2
|
+
on: push
|
|
3
|
+
|
|
4
|
+
jobs:
|
|
5
|
+
test:
|
|
6
|
+
runs-on: ubuntu-latest
|
|
7
|
+
timeout-minutes: 10
|
|
8
|
+
|
|
9
|
+
steps:
|
|
10
|
+
- name: Check out repository code
|
|
11
|
+
uses: actions/checkout@v4
|
|
12
|
+
|
|
13
|
+
- name: Set up Python
|
|
14
|
+
uses: astral-sh/setup-uv@v5
|
|
15
|
+
with:
|
|
16
|
+
enable-cache: true
|
|
17
|
+
python-version: "3.13"
|
|
18
|
+
|
|
19
|
+
- name: Install packages
|
|
20
|
+
run: uv sync --all-extras --dev
|
|
21
|
+
|
|
22
|
+
- name: Run tests
|
|
23
|
+
run: uv run pytest tests
|
|
24
|
+
env:
|
|
25
|
+
CI: true
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
2
|
Name: pyobs-asi
|
|
3
|
-
Version: 2.0.0.
|
|
3
|
+
Version: 2.0.0.dev6
|
|
4
4
|
Summary: pyobs model for ASI cameras
|
|
5
5
|
Author-email: Tim-Oliver Husser <thusser@uni-goettingen.de>
|
|
6
6
|
License-Expression: MIT
|
|
7
7
|
License-File: LICENSE
|
|
8
8
|
Requires-Python: >=3.11
|
|
9
9
|
Requires-Dist: numpy<3,>=2.2.5
|
|
10
|
-
Requires-Dist: pyobs-core<3,>=2.0.0.
|
|
10
|
+
Requires-Dist: pyobs-core<3,>=2.0.0.dev48
|
|
11
11
|
Requires-Dist: zwoasi>=0.2.0
|
|
12
12
|
Provides-Extra: gui
|
|
13
|
-
Requires-Dist: pyobs-core[gui]<3,>=2.0.0.
|
|
13
|
+
Requires-Dist: pyobs-core[gui]<3,>=2.0.0.dev48; extra == 'gui'
|
|
14
14
|
Requires-Dist: qasync>=0.28.0; extra == 'gui'
|
|
@@ -12,6 +12,7 @@ import zwoasi as asi # type: ignore
|
|
|
12
12
|
from numpy.typing import NDArray
|
|
13
13
|
from pyobs.images import Image
|
|
14
14
|
from pyobs.interfaces import (
|
|
15
|
+
Binning,
|
|
15
16
|
BinningCapabilities,
|
|
16
17
|
BinningState,
|
|
17
18
|
CoolingState,
|
|
@@ -83,15 +84,26 @@ class AsiCamera(BaseCamera, IWindow, IBinning, IImageFormat, IGain, ITemperature
|
|
|
83
84
|
self._gain: float = 1.0
|
|
84
85
|
self._gain_offset: float = 50.0
|
|
85
86
|
|
|
87
|
+
# The ASI SDK is not thread-safe: the 5s temperature poll and in-progress exposure
|
|
88
|
+
# threads would otherwise hit the same camera handle concurrently.
|
|
89
|
+
self._sdk_lock = threading.Lock()
|
|
90
|
+
|
|
86
91
|
self.add_background_task(self._temperature_thread, True)
|
|
87
92
|
|
|
88
93
|
@staticmethod
|
|
89
|
-
async def _run_blocking(
|
|
94
|
+
async def _run_blocking(
|
|
95
|
+
func: Callable[[], None], timeout: float = _SDK_CALL_TIMEOUT, lock: threading.Lock | None = None
|
|
96
|
+
) -> bool:
|
|
90
97
|
"""Run a blocking ASI SDK call in a daemon thread, so a hung call can't freeze the module.
|
|
91
98
|
|
|
92
99
|
A plain executor isn't used here, since its worker threads are non-daemon and Python joins
|
|
93
100
|
them on interpreter shutdown -- a hung call would then just move the freeze to process exit.
|
|
94
101
|
|
|
102
|
+
Args:
|
|
103
|
+
func: The blocking call to run.
|
|
104
|
+
timeout: How long to wait for func to complete.
|
|
105
|
+
lock: Optional lock to hold while func runs, guarding SDK access against other threads.
|
|
106
|
+
|
|
95
107
|
Returns:
|
|
96
108
|
True if func completed within timeout, False if it's still running in the background.
|
|
97
109
|
"""
|
|
@@ -100,7 +112,11 @@ class AsiCamera(BaseCamera, IWindow, IBinning, IImageFormat, IGain, ITemperature
|
|
|
100
112
|
|
|
101
113
|
def _wrapper() -> None:
|
|
102
114
|
try:
|
|
103
|
-
|
|
115
|
+
if lock is not None:
|
|
116
|
+
with lock:
|
|
117
|
+
func()
|
|
118
|
+
else:
|
|
119
|
+
func()
|
|
104
120
|
finally:
|
|
105
121
|
loop.call_soon_threadsafe(future.set_result, None)
|
|
106
122
|
|
|
@@ -111,13 +127,20 @@ class AsiCamera(BaseCamera, IWindow, IBinning, IImageFormat, IGain, ITemperature
|
|
|
111
127
|
except TimeoutError:
|
|
112
128
|
return False
|
|
113
129
|
|
|
114
|
-
async def _run_blocking_or_raise(
|
|
130
|
+
async def _run_blocking_or_raise(
|
|
131
|
+
self, func: Callable[[], _T], timeout: float = _SDK_CALL_TIMEOUT, lock: threading.Lock | None = None
|
|
132
|
+
) -> _T:
|
|
115
133
|
"""Run a blocking ASI SDK call in a thread, returning its result or re-raising what it raised.
|
|
116
134
|
|
|
117
135
|
Unlike _run_blocking(), this also carries the callable's return value/exception back to the
|
|
118
136
|
caller -- several ASI calls here drive control flow via their return value or a raised
|
|
119
137
|
ValueError (e.g. camera lookup by name, exposure status), which a bare fire-and-forget
|
|
120
138
|
thread call would otherwise silently lose.
|
|
139
|
+
|
|
140
|
+
Args:
|
|
141
|
+
func: The blocking call to run.
|
|
142
|
+
timeout: How long to wait for func to complete.
|
|
143
|
+
lock: Optional lock to hold while func runs, guarding SDK access against other threads.
|
|
121
144
|
"""
|
|
122
145
|
outcome: list[Any] = []
|
|
123
146
|
|
|
@@ -127,7 +150,7 @@ class AsiCamera(BaseCamera, IWindow, IBinning, IImageFormat, IGain, ITemperature
|
|
|
127
150
|
except BaseException as e:
|
|
128
151
|
outcome.append(e)
|
|
129
152
|
|
|
130
|
-
if not await self._run_blocking(_wrapper, timeout=timeout):
|
|
153
|
+
if not await self._run_blocking(_wrapper, timeout=timeout, lock=lock):
|
|
131
154
|
raise TimeoutError(f"Timed out waiting for ASI SDK call after {timeout}s.")
|
|
132
155
|
value = outcome[0]
|
|
133
156
|
if isinstance(value, BaseException):
|
|
@@ -169,7 +192,7 @@ class AsiCamera(BaseCamera, IWindow, IBinning, IImageFormat, IGain, ITemperature
|
|
|
169
192
|
left, top, width, height = self._camera.get_roi()
|
|
170
193
|
return camera_info, binning, (left, top, width, height)
|
|
171
194
|
|
|
172
|
-
self._camera_info, self._binning, self._window = await self._run_blocking_or_raise(_open)
|
|
195
|
+
self._camera_info, self._binning, self._window = await self._run_blocking_or_raise(_open, lock=self._sdk_lock)
|
|
173
196
|
|
|
174
197
|
log.info("Camera info:")
|
|
175
198
|
for key, val in self._camera_info.items():
|
|
@@ -188,7 +211,7 @@ class AsiCamera(BaseCamera, IWindow, IBinning, IImageFormat, IGain, ITemperature
|
|
|
188
211
|
if "SupportedBins" in self._camera_info:
|
|
189
212
|
await self.comm.set_capabilities(
|
|
190
213
|
IBinning,
|
|
191
|
-
BinningCapabilities(binnings=[
|
|
214
|
+
BinningCapabilities(binnings=[Binning(x=b, y=b) for b in self._camera_info["SupportedBins"]]),
|
|
192
215
|
)
|
|
193
216
|
await self.comm.set_capabilities(IImageFormat, ImageFormatCapabilities(image_formats=list(FORMATS.keys())))
|
|
194
217
|
|
|
@@ -294,14 +317,16 @@ class AsiCamera(BaseCamera, IWindow, IBinning, IImageFormat, IGain, ITemperature
|
|
|
294
317
|
camera.set_control_value(asi.ASI_OFFSET, int(self._gain_offset))
|
|
295
318
|
camera.start_exposure()
|
|
296
319
|
|
|
297
|
-
await self._run_blocking_or_raise(_start)
|
|
320
|
+
await self._run_blocking_or_raise(_start, lock=self._sdk_lock)
|
|
298
321
|
await asyncio.sleep(0.01)
|
|
299
322
|
|
|
300
323
|
# wait for image -- runs the whole poll loop as a single blocking call (see _run_blocking),
|
|
301
|
-
# rather than polling get_exposure_status() every 10ms directly on the event loop
|
|
324
|
+
# rather than polling get_exposure_status() every 10ms directly on the event loop. The SDK
|
|
325
|
+
# lock is taken per get_exposure_status() call here, so the temperature poll can interleave.
|
|
302
326
|
def _wait() -> Any:
|
|
303
327
|
while True:
|
|
304
|
-
|
|
328
|
+
with self._sdk_lock:
|
|
329
|
+
exposure_status = camera.get_exposure_status()
|
|
305
330
|
if exposure_status != asi.ASI_EXP_WORKING or abort_event.is_set():
|
|
306
331
|
return exposure_status
|
|
307
332
|
time.sleep(0.01)
|
|
@@ -310,6 +335,7 @@ class AsiCamera(BaseCamera, IWindow, IBinning, IImageFormat, IGain, ITemperature
|
|
|
310
335
|
status = await self._run_blocking_or_raise(_wait, timeout=exposure_timeout)
|
|
311
336
|
|
|
312
337
|
if abort_event.is_set():
|
|
338
|
+
await self._run_blocking_or_raise(camera.stop_exposure, lock=self._sdk_lock)
|
|
313
339
|
await self._change_exposure_status(ExposureStatus.IDLE)
|
|
314
340
|
raise InterruptedError("Aborted exposure.")
|
|
315
341
|
if status != asi.ASI_EXP_SUCCESS:
|
|
@@ -323,7 +349,7 @@ class AsiCamera(BaseCamera, IWindow, IBinning, IImageFormat, IGain, ITemperature
|
|
|
323
349
|
whbi = camera.get_roi_format()
|
|
324
350
|
return buffer, whbi
|
|
325
351
|
|
|
326
|
-
buffer, whbi = await self._run_blocking_or_raise(_readout, timeout=_READOUT_TIMEOUT)
|
|
352
|
+
buffer, whbi = await self._run_blocking_or_raise(_readout, timeout=_READOUT_TIMEOUT, lock=self._sdk_lock)
|
|
327
353
|
|
|
328
354
|
# decide on image format
|
|
329
355
|
shape = [whbi[1], whbi[0]]
|
|
@@ -405,7 +431,7 @@ class AsiCamera(BaseCamera, IWindow, IBinning, IImageFormat, IGain, ITemperature
|
|
|
405
431
|
def _get() -> float:
|
|
406
432
|
return camera.get_control_value(asi.ASI_TEMPERATURE)[0] / 10 # type: ignore[union-attr]
|
|
407
433
|
|
|
408
|
-
return await self._run_blocking_or_raise(_get)
|
|
434
|
+
return await self._run_blocking_or_raise(_get, lock=self._sdk_lock)
|
|
409
435
|
|
|
410
436
|
async def set_gain(self, gain: float, **kwargs: Any) -> None:
|
|
411
437
|
"""Set the camera gain.
|
|
@@ -469,7 +495,7 @@ class AsiCoolCamera(AsiCamera, ICooling):
|
|
|
469
495
|
power = camera.get_control_value(asi.ASI_COOLER_POWER_PERC)[0]
|
|
470
496
|
return bool(enabled), float(setpoint), float(power)
|
|
471
497
|
|
|
472
|
-
return await self._run_blocking_or_raise(_get)
|
|
498
|
+
return await self._run_blocking_or_raise(_get, lock=self._sdk_lock)
|
|
473
499
|
|
|
474
500
|
async def set_cooling(self, enabled: bool, setpoint: float, **kwargs: Any) -> None:
|
|
475
501
|
"""Enables/disables cooling and sets setpoint.
|
|
@@ -494,7 +520,7 @@ class AsiCoolCamera(AsiCamera, ICooling):
|
|
|
494
520
|
log.info("Disabling cooling...")
|
|
495
521
|
camera.set_control_value(asi.ASI_COOLER_ON, 0)
|
|
496
522
|
|
|
497
|
-
await self._run_blocking_or_raise(_set)
|
|
523
|
+
await self._run_blocking_or_raise(_set, lock=self._sdk_lock)
|
|
498
524
|
|
|
499
525
|
enabled_status, setpoint_status, power = await self._get_cooling_status()
|
|
500
526
|
await self.comm.set_state(
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import asyncio
|
|
2
2
|
import sys
|
|
3
|
+
from typing import Any
|
|
3
4
|
|
|
4
5
|
import numpy as np
|
|
5
6
|
import qasync # type: ignore
|
|
@@ -25,12 +26,10 @@ FORMATS = {
|
|
|
25
26
|
|
|
26
27
|
|
|
27
28
|
class MainWindow(QtWidgets.QMainWindow):
|
|
28
|
-
def __init__(self,
|
|
29
|
+
def __init__(self, camera: asi.Camera, camera_info: dict[str, Any]) -> None:
|
|
29
30
|
super().__init__()
|
|
30
31
|
|
|
31
|
-
self.camera =
|
|
32
|
-
self.camera.disable_dark_subtract()
|
|
33
|
-
camera_info = self.camera.get_camera_property()
|
|
32
|
+
self.camera = camera
|
|
34
33
|
|
|
35
34
|
self.central_widget = QtWidgets.QWidget()
|
|
36
35
|
self.setCentralWidget(self.central_widget)
|
|
@@ -66,23 +65,31 @@ class MainWindow(QtWidgets.QMainWindow):
|
|
|
66
65
|
left, top, width, height = self.window_widget.values
|
|
67
66
|
binning = self.window_widget.binning[0]
|
|
68
67
|
image_type = FORMATS[self.format_widget.value]
|
|
68
|
+
loop = asyncio.get_running_loop()
|
|
69
69
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
# WindowingWidget already returns binned coordinates (its maxima are the binned
|
|
71
|
+
# dimensions), and set_roi works in binned units too, so no further division is needed.
|
|
73
72
|
self.expose.start_exposure(self.exposure_time.value)
|
|
74
|
-
self.camera.start_exposure()
|
|
75
73
|
|
|
76
|
-
|
|
74
|
+
def _start() -> None:
|
|
75
|
+
self.camera.set_roi(left, top, width, height, bins=binning, image_type=image_type)
|
|
76
|
+
self.camera.set_control_value(asi.ASI_EXPOSURE, int(self.exposure_time.value * 1e6))
|
|
77
|
+
self.camera.start_exposure()
|
|
78
|
+
|
|
79
|
+
await loop.run_in_executor(None, _start)
|
|
80
|
+
|
|
81
|
+
def _get_status() -> int:
|
|
82
|
+
return self.camera.get_exposure_status()
|
|
83
|
+
|
|
84
|
+
while await loop.run_in_executor(None, _get_status) == asi.ASI_EXP_WORKING:
|
|
77
85
|
if self.abort_exposure.is_set():
|
|
78
|
-
self.camera.stop_exposure
|
|
86
|
+
await loop.run_in_executor(None, self.camera.stop_exposure)
|
|
79
87
|
break
|
|
80
88
|
await event_wait(self.abort_exposure, 0.1)
|
|
81
89
|
|
|
82
90
|
if not self.abort_exposure.is_set():
|
|
83
|
-
loop = asyncio.get_running_loop()
|
|
84
91
|
buffer = await loop.run_in_executor(None, self.camera.get_data_after_exposure)
|
|
85
|
-
whbi = self.camera.get_roi_format
|
|
92
|
+
whbi = await loop.run_in_executor(None, self.camera.get_roi_format)
|
|
86
93
|
shape = [whbi[1], whbi[0]]
|
|
87
94
|
dtype = np.uint8 if image_type == asi.ASI_IMG_RAW8 else np.uint16
|
|
88
95
|
data = np.frombuffer(buffer, dtype=dtype).reshape(shape)
|
|
@@ -97,24 +104,40 @@ class MainWindow(QtWidgets.QMainWindow):
|
|
|
97
104
|
async def _abort_clicked(self) -> None:
|
|
98
105
|
self.abort_exposure.set()
|
|
99
106
|
|
|
107
|
+
def closeEvent(self, event) -> None: # type: ignore[override]
|
|
108
|
+
self.camera.close()
|
|
109
|
+
super().closeEvent(event)
|
|
110
|
+
|
|
100
111
|
|
|
101
112
|
async def async_main(app: QtWidgets.QApplication) -> None:
|
|
102
113
|
sdk_path = sys.argv[1] if len(sys.argv) > 1 else "/usr/local/lib/libASICamera2.so"
|
|
103
|
-
|
|
114
|
+
loop = asyncio.get_running_loop()
|
|
115
|
+
|
|
116
|
+
def _init() -> int:
|
|
117
|
+
asi.init(sdk_path)
|
|
118
|
+
return asi.get_num_cameras()
|
|
104
119
|
|
|
105
|
-
if
|
|
120
|
+
if await loop.run_in_executor(None, _init) == 0:
|
|
106
121
|
print("No devices found. Exiting...")
|
|
107
122
|
return
|
|
108
|
-
cameras_found = asi.list_cameras
|
|
123
|
+
cameras_found = await loop.run_in_executor(None, asi.list_cameras)
|
|
109
124
|
device_picker = ListPickerDialog(cameras_found)
|
|
110
125
|
if device_picker.exec() != QtWidgets.QDialog.DialogCode.Accepted:
|
|
111
126
|
print("No device selected. Exiting...")
|
|
112
127
|
return
|
|
113
128
|
camera_id = device_picker.comboBox().currentIndex()
|
|
114
129
|
|
|
130
|
+
def _open_camera() -> asi.Camera:
|
|
131
|
+
camera = asi.Camera(camera_id)
|
|
132
|
+
camera.disable_dark_subtract()
|
|
133
|
+
return camera
|
|
134
|
+
|
|
135
|
+
camera = await loop.run_in_executor(None, _open_camera)
|
|
136
|
+
camera_info = await loop.run_in_executor(None, camera.get_camera_property)
|
|
137
|
+
|
|
115
138
|
app_close_event = asyncio.Event()
|
|
116
139
|
app.aboutToQuit.connect(app_close_event.set)
|
|
117
|
-
main_window = MainWindow(
|
|
140
|
+
main_window = MainWindow(camera, camera_info)
|
|
118
141
|
main_window.show()
|
|
119
142
|
await app_close_event.wait()
|
|
120
143
|
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "pyobs-asi"
|
|
3
|
-
version = "2.0.0.
|
|
3
|
+
version = "2.0.0.dev6"
|
|
4
4
|
description = "pyobs model for ASI cameras"
|
|
5
5
|
authors = [{ name = "Tim-Oliver Husser", email = "thusser@uni-goettingen.de" }]
|
|
6
6
|
requires-python = ">=3.11"
|
|
7
7
|
license = "MIT"
|
|
8
8
|
dependencies = [
|
|
9
9
|
"numpy>=2.2.5,<3",
|
|
10
|
-
"pyobs-core>=2.0.0.
|
|
10
|
+
"pyobs-core>=2.0.0.dev48,<3",
|
|
11
11
|
"zwoasi>=0.2.0",
|
|
12
12
|
]
|
|
13
13
|
|
|
14
14
|
[project.optional-dependencies]
|
|
15
15
|
gui = [
|
|
16
|
-
"pyobs-core[gui]>=2.0.0.
|
|
16
|
+
"pyobs-core[gui]>=2.0.0.dev48,<3",
|
|
17
17
|
"qasync>=0.28.0",
|
|
18
18
|
]
|
|
19
19
|
|
|
@@ -22,10 +22,12 @@ asi-gui = 'pyobs_asi.gui:main'
|
|
|
22
22
|
|
|
23
23
|
[dependency-groups]
|
|
24
24
|
dev = [
|
|
25
|
-
"black>=25.1.0,<
|
|
25
|
+
"black>=25.1.0,<27",
|
|
26
26
|
"ruff>=0.9.0",
|
|
27
27
|
"pyrefly>=1.1.1",
|
|
28
28
|
"pre-commit>=4.2.0,<5",
|
|
29
|
+
"pytest>=8.0.0",
|
|
30
|
+
"pytest-asyncio>=0.24.0",
|
|
29
31
|
]
|
|
30
32
|
|
|
31
33
|
[build-system]
|
|
@@ -45,3 +47,7 @@ select = ["E", "F", "W", "I", "UP", "G"]
|
|
|
45
47
|
|
|
46
48
|
[tool.pyrefly]
|
|
47
49
|
python-version = "3.11"
|
|
50
|
+
project-excludes = ["pyobs_asi/gui.py"]
|
|
51
|
+
|
|
52
|
+
[tool.pytest.ini_options]
|
|
53
|
+
asyncio_mode = "strict"
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"""Unit tests for the non-hardware logic in AsiCamera: constructor defaults, the
|
|
2
|
+
state-setting methods (window/binning/gain/offset/image format), and the
|
|
3
|
+
_run_blocking/_run_blocking_or_raise thread wrappers.
|
|
4
|
+
|
|
5
|
+
Hardware I/O (opening a camera, exposing, reading out) is out of scope here.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import asyncio
|
|
9
|
+
import threading
|
|
10
|
+
from unittest.mock import AsyncMock
|
|
11
|
+
|
|
12
|
+
import pytest
|
|
13
|
+
from pyobs.interfaces import IBinning, IGain, IWindow
|
|
14
|
+
from pyobs.utils.enums import ImageFormat
|
|
15
|
+
|
|
16
|
+
from pyobs_asi import AsiCamera, AsiCoolCamera
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def test_constructor_defaults() -> None:
|
|
20
|
+
camera = AsiCamera(camera="test")
|
|
21
|
+
assert camera._camera_name == "test"
|
|
22
|
+
assert camera._sdk_path == "/usr/local/lib/libASICamera2.so"
|
|
23
|
+
assert camera._camera is None
|
|
24
|
+
assert camera._window == (0, 0, 0, 0)
|
|
25
|
+
assert camera._binning == 1
|
|
26
|
+
assert camera._image_format == ImageFormat.INT16
|
|
27
|
+
assert camera._gain == 1.0
|
|
28
|
+
assert camera._gain_offset == 50.0
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def test_cool_camera_default_setpoint() -> None:
|
|
32
|
+
camera = AsiCoolCamera(camera="test")
|
|
33
|
+
assert camera._temp_setpoint == -20
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@pytest.mark.asyncio
|
|
37
|
+
async def test_set_window() -> None:
|
|
38
|
+
camera = AsiCamera(camera="test")
|
|
39
|
+
camera.comm.set_state = AsyncMock() # type: ignore[method-assign]
|
|
40
|
+
|
|
41
|
+
await camera.set_window(10, 20, 100, 200)
|
|
42
|
+
|
|
43
|
+
assert camera._window == (10, 20, 100, 200)
|
|
44
|
+
assert camera.comm.set_state.await_args is not None
|
|
45
|
+
interface, state = camera.comm.set_state.await_args.args
|
|
46
|
+
assert interface is IWindow
|
|
47
|
+
assert (state.x, state.y, state.width, state.height) == (10, 20, 100, 200)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
@pytest.mark.asyncio
|
|
51
|
+
async def test_set_binning() -> None:
|
|
52
|
+
camera = AsiCamera(camera="test")
|
|
53
|
+
camera.comm.set_state = AsyncMock() # type: ignore[method-assign]
|
|
54
|
+
|
|
55
|
+
await camera.set_binning(2, 3)
|
|
56
|
+
|
|
57
|
+
# only x is tracked as the scalar binning factor; both axes still go out in the state
|
|
58
|
+
assert camera._binning == 2
|
|
59
|
+
assert camera.comm.set_state.await_args is not None
|
|
60
|
+
interface, state = camera.comm.set_state.await_args.args
|
|
61
|
+
assert interface is IBinning
|
|
62
|
+
assert (state.x, state.y) == (2, 3)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
@pytest.mark.asyncio
|
|
66
|
+
async def test_set_gain() -> None:
|
|
67
|
+
camera = AsiCamera(camera="test")
|
|
68
|
+
camera.comm.set_state = AsyncMock() # type: ignore[method-assign]
|
|
69
|
+
|
|
70
|
+
await camera.set_gain(5.0)
|
|
71
|
+
|
|
72
|
+
# offset is untouched, but the published state still carries the last-known offset
|
|
73
|
+
assert camera._gain == 5.0
|
|
74
|
+
assert camera.comm.set_state.await_args is not None
|
|
75
|
+
interface, state = camera.comm.set_state.await_args.args
|
|
76
|
+
assert interface is IGain
|
|
77
|
+
assert (state.gain, state.offset) == (5.0, camera._gain_offset)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
@pytest.mark.asyncio
|
|
81
|
+
async def test_set_offset() -> None:
|
|
82
|
+
camera = AsiCamera(camera="test")
|
|
83
|
+
camera.comm.set_state = AsyncMock() # type: ignore[method-assign]
|
|
84
|
+
|
|
85
|
+
await camera.set_offset(25.0)
|
|
86
|
+
|
|
87
|
+
assert camera._gain_offset == 25.0
|
|
88
|
+
assert camera.comm.set_state.await_args is not None
|
|
89
|
+
interface, state = camera.comm.set_state.await_args.args
|
|
90
|
+
assert interface is IGain
|
|
91
|
+
assert (state.gain, state.offset) == (camera._gain, 25.0)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
@pytest.mark.asyncio
|
|
95
|
+
async def test_set_image_format() -> None:
|
|
96
|
+
camera = AsiCamera(camera="test")
|
|
97
|
+
await camera.set_image_format(ImageFormat.RGB24)
|
|
98
|
+
assert camera._image_format == ImageFormat.RGB24
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
@pytest.mark.asyncio
|
|
102
|
+
async def test_set_image_format_invalid() -> None:
|
|
103
|
+
camera = AsiCamera(camera="test")
|
|
104
|
+
with pytest.raises(ValueError):
|
|
105
|
+
await camera.set_image_format("bogus") # type: ignore[arg-type]
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
@pytest.mark.asyncio
|
|
109
|
+
async def test_run_blocking_runs_func_and_returns_true() -> None:
|
|
110
|
+
ran: list[bool] = []
|
|
111
|
+
|
|
112
|
+
def fast() -> None:
|
|
113
|
+
ran.append(True)
|
|
114
|
+
|
|
115
|
+
assert await AsiCamera._run_blocking(fast) is True
|
|
116
|
+
assert ran == [True]
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
@pytest.mark.asyncio
|
|
120
|
+
async def test_run_blocking_times_out() -> None:
|
|
121
|
+
done = threading.Event()
|
|
122
|
+
|
|
123
|
+
def slow() -> None:
|
|
124
|
+
done.wait()
|
|
125
|
+
|
|
126
|
+
assert await AsiCamera._run_blocking(slow, timeout=0.01) is False
|
|
127
|
+
done.set()
|
|
128
|
+
await asyncio.sleep(0.05)
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
@pytest.mark.asyncio
|
|
132
|
+
async def test_run_blocking_or_raise_returns_value() -> None:
|
|
133
|
+
camera = AsiCamera(camera="test")
|
|
134
|
+
assert await camera._run_blocking_or_raise(lambda: 42) == 42
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
@pytest.mark.asyncio
|
|
138
|
+
async def test_run_blocking_or_raise_reraises() -> None:
|
|
139
|
+
camera = AsiCamera(camera="test")
|
|
140
|
+
|
|
141
|
+
def boom() -> int:
|
|
142
|
+
raise ValueError("boom")
|
|
143
|
+
|
|
144
|
+
with pytest.raises(ValueError):
|
|
145
|
+
await camera._run_blocking_or_raise(boom)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"""Smoke tests: import the drivers and instantiate them without hardware, asserting
|
|
2
|
+
the interfaces they claim.
|
|
3
|
+
|
|
4
|
+
zwoasi imports cleanly with no SDK present (it logs "ASI SDK library not found" and
|
|
5
|
+
degrades), so no camera is needed at import/instantiate time.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from pyobs.interfaces import IBinning, ICooling, IGain, IImageFormat, ITemperatures, IWindow
|
|
9
|
+
from pyobs.modules import Module
|
|
10
|
+
|
|
11
|
+
from pyobs_asi import AsiCamera, AsiCoolCamera
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def test_instantiate_asicamera() -> None:
|
|
15
|
+
camera = AsiCamera(camera="ZWO ASI1600MM Pro")
|
|
16
|
+
assert isinstance(camera, Module)
|
|
17
|
+
assert isinstance(camera, IWindow)
|
|
18
|
+
assert isinstance(camera, IBinning)
|
|
19
|
+
assert isinstance(camera, IImageFormat)
|
|
20
|
+
assert isinstance(camera, IGain)
|
|
21
|
+
assert isinstance(camera, ITemperatures)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def test_instantiate_asicoolcamera() -> None:
|
|
25
|
+
camera = AsiCoolCamera(camera="ZWO ASI1600MM Pro")
|
|
26
|
+
assert isinstance(camera, ICooling)
|
|
27
|
+
assert isinstance(camera, ITemperatures)
|