pyobs-asi 2.0.0.dev3__tar.gz → 2.0.0.dev5__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.dev5/.github/dependabot.yml +15 -0
- pyobs_asi-2.0.0.dev5/.github/workflows/pyrefly.yml +23 -0
- pyobs_asi-2.0.0.dev5/.github/workflows/pytest.yml +25 -0
- {pyobs_asi-2.0.0.dev3 → pyobs_asi-2.0.0.dev5}/PKG-INFO +4 -4
- {pyobs_asi-2.0.0.dev3 → pyobs_asi-2.0.0.dev5}/pyobs_asi/asicamera.py +166 -68
- {pyobs_asi-2.0.0.dev3 → pyobs_asi-2.0.0.dev5}/pyproject.toml +10 -4
- pyobs_asi-2.0.0.dev5/tests/test_asicamera.py +145 -0
- pyobs_asi-2.0.0.dev5/tests/test_import.py +27 -0
- pyobs_asi-2.0.0.dev5/uv.lock +3160 -0
- pyobs_asi-2.0.0.dev3/uv.lock +0 -2700
- {pyobs_asi-2.0.0.dev3 → pyobs_asi-2.0.0.dev5}/.github/workflows/pypi.yml +0 -0
- {pyobs_asi-2.0.0.dev3 → pyobs_asi-2.0.0.dev5}/.github/workflows/ruff.yml +0 -0
- {pyobs_asi-2.0.0.dev3 → pyobs_asi-2.0.0.dev5}/.pre-commit-config.yaml +0 -0
- {pyobs_asi-2.0.0.dev3 → pyobs_asi-2.0.0.dev5}/.readthedocs.yml +0 -0
- {pyobs_asi-2.0.0.dev3 → pyobs_asi-2.0.0.dev5}/CHANGELOG.rst +0 -0
- {pyobs_asi-2.0.0.dev3 → pyobs_asi-2.0.0.dev5}/LICENSE +0 -0
- {pyobs_asi-2.0.0.dev3 → pyobs_asi-2.0.0.dev5}/README.md +0 -0
- {pyobs_asi-2.0.0.dev3 → pyobs_asi-2.0.0.dev5}/docs/Makefile +0 -0
- {pyobs_asi-2.0.0.dev3 → pyobs_asi-2.0.0.dev5}/docs/make.bat +0 -0
- {pyobs_asi-2.0.0.dev3 → pyobs_asi-2.0.0.dev5}/docs/requirements.txt +0 -0
- {pyobs_asi-2.0.0.dev3 → pyobs_asi-2.0.0.dev5}/docs/source/_static/pyobs.gif +0 -0
- {pyobs_asi-2.0.0.dev3 → pyobs_asi-2.0.0.dev5}/docs/source/conf.py +0 -0
- {pyobs_asi-2.0.0.dev3 → pyobs_asi-2.0.0.dev5}/docs/source/index.rst +0 -0
- {pyobs_asi-2.0.0.dev3 → pyobs_asi-2.0.0.dev5}/pyobs_asi/__init__.py +0 -0
- {pyobs_asi-2.0.0.dev3 → pyobs_asi-2.0.0.dev5}/pyobs_asi/gui.py +0 -0
|
@@ -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.dev5
|
|
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'
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import asyncio
|
|
2
2
|
import logging
|
|
3
3
|
import math
|
|
4
|
+
import threading
|
|
5
|
+
import time
|
|
6
|
+
from collections.abc import Callable
|
|
4
7
|
from datetime import UTC, datetime
|
|
5
|
-
from typing import Any, cast
|
|
8
|
+
from typing import Any, TypeVar, cast
|
|
6
9
|
|
|
7
10
|
import numpy as np
|
|
8
11
|
import zwoasi as asi # type: ignore
|
|
9
12
|
from numpy.typing import NDArray
|
|
10
13
|
from pyobs.images import Image
|
|
11
14
|
from pyobs.interfaces import (
|
|
15
|
+
Binning,
|
|
12
16
|
BinningCapabilities,
|
|
13
17
|
BinningState,
|
|
14
18
|
CoolingState,
|
|
@@ -29,10 +33,10 @@ from pyobs.interfaces import (
|
|
|
29
33
|
from pyobs.modules.camera.basecamera import BaseCamera
|
|
30
34
|
from pyobs.utils import exceptions as exc
|
|
31
35
|
from pyobs.utils.enums import ExposureStatus, ImageFormat
|
|
32
|
-
from pyobs.utils.parallel import event_wait
|
|
33
36
|
|
|
34
37
|
log = logging.getLogger(__name__)
|
|
35
38
|
|
|
39
|
+
_T = TypeVar("_T")
|
|
36
40
|
|
|
37
41
|
FORMATS = {
|
|
38
42
|
ImageFormat.INT8: asi.ASI_IMG_RAW8,
|
|
@@ -40,6 +44,19 @@ FORMATS = {
|
|
|
40
44
|
ImageFormat.RGB24: asi.ASI_IMG_RGB24,
|
|
41
45
|
}
|
|
42
46
|
|
|
47
|
+
# ZWO ASI SDK calls are blocking and are made directly on the event loop thread (see
|
|
48
|
+
# _run_blocking). If the camera has gone unresponsive, they can hang indefinitely, so they're
|
|
49
|
+
# bounded with a timeout rather than let a single dead camera freeze the whole module.
|
|
50
|
+
_SDK_CALL_TIMEOUT = 5.0
|
|
51
|
+
|
|
52
|
+
# reading out a frame after exposure can take longer than the other SDK calls above, depending on
|
|
53
|
+
# sensor resolution/image format.
|
|
54
|
+
_READOUT_TIMEOUT = 30.0
|
|
55
|
+
|
|
56
|
+
# the exposure-wait loop's own timeout needs to cover the actual exposure time plus some margin
|
|
57
|
+
# for overhead -- exposure_time alone would be too tight.
|
|
58
|
+
_EXPOSURE_WAIT_MARGIN = 30.0
|
|
59
|
+
|
|
43
60
|
|
|
44
61
|
class AsiCamera(BaseCamera, IWindow, IBinning, IImageFormat, IGain, ITemperatures):
|
|
45
62
|
"""A pyobs module for ASI cameras."""
|
|
@@ -69,42 +86,96 @@ class AsiCamera(BaseCamera, IWindow, IBinning, IImageFormat, IGain, ITemperature
|
|
|
69
86
|
|
|
70
87
|
self.add_background_task(self._temperature_thread, True)
|
|
71
88
|
|
|
89
|
+
@staticmethod
|
|
90
|
+
async def _run_blocking(func: Callable[[], None], timeout: float = _SDK_CALL_TIMEOUT) -> bool:
|
|
91
|
+
"""Run a blocking ASI SDK call in a daemon thread, so a hung call can't freeze the module.
|
|
92
|
+
|
|
93
|
+
A plain executor isn't used here, since its worker threads are non-daemon and Python joins
|
|
94
|
+
them on interpreter shutdown -- a hung call would then just move the freeze to process exit.
|
|
95
|
+
|
|
96
|
+
Returns:
|
|
97
|
+
True if func completed within timeout, False if it's still running in the background.
|
|
98
|
+
"""
|
|
99
|
+
loop = asyncio.get_running_loop()
|
|
100
|
+
future: asyncio.Future[None] = loop.create_future()
|
|
101
|
+
|
|
102
|
+
def _wrapper() -> None:
|
|
103
|
+
try:
|
|
104
|
+
func()
|
|
105
|
+
finally:
|
|
106
|
+
loop.call_soon_threadsafe(future.set_result, None)
|
|
107
|
+
|
|
108
|
+
threading.Thread(target=_wrapper, daemon=True).start()
|
|
109
|
+
try:
|
|
110
|
+
await asyncio.wait_for(future, timeout=timeout)
|
|
111
|
+
return True
|
|
112
|
+
except TimeoutError:
|
|
113
|
+
return False
|
|
114
|
+
|
|
115
|
+
async def _run_blocking_or_raise(self, func: Callable[[], _T], timeout: float = _SDK_CALL_TIMEOUT) -> _T:
|
|
116
|
+
"""Run a blocking ASI SDK call in a thread, returning its result or re-raising what it raised.
|
|
117
|
+
|
|
118
|
+
Unlike _run_blocking(), this also carries the callable's return value/exception back to the
|
|
119
|
+
caller -- several ASI calls here drive control flow via their return value or a raised
|
|
120
|
+
ValueError (e.g. camera lookup by name, exposure status), which a bare fire-and-forget
|
|
121
|
+
thread call would otherwise silently lose.
|
|
122
|
+
"""
|
|
123
|
+
outcome: list[Any] = []
|
|
124
|
+
|
|
125
|
+
def _wrapper() -> None:
|
|
126
|
+
try:
|
|
127
|
+
outcome.append(func())
|
|
128
|
+
except BaseException as e:
|
|
129
|
+
outcome.append(e)
|
|
130
|
+
|
|
131
|
+
if not await self._run_blocking(_wrapper, timeout=timeout):
|
|
132
|
+
raise TimeoutError(f"Timed out waiting for ASI SDK call after {timeout}s.")
|
|
133
|
+
value = outcome[0]
|
|
134
|
+
if isinstance(value, BaseException):
|
|
135
|
+
raise value
|
|
136
|
+
return cast(_T, value)
|
|
137
|
+
|
|
72
138
|
async def open(self) -> None:
|
|
73
139
|
"""Open module."""
|
|
74
|
-
asi.init(self._sdk_path)
|
|
75
140
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
141
|
+
def _open() -> tuple[dict[str, Any], int, tuple[int, int, int, int]]:
|
|
142
|
+
asi.init(self._sdk_path)
|
|
143
|
+
|
|
144
|
+
num_cameras = asi.get_num_cameras()
|
|
145
|
+
if num_cameras == 0:
|
|
146
|
+
raise ValueError("No cameras found")
|
|
147
|
+
|
|
148
|
+
# index() raises ValueError, if camera could not be found
|
|
149
|
+
cameras_found = asi.list_cameras()
|
|
150
|
+
camera_id = cameras_found.index(self._camera_name)
|
|
151
|
+
|
|
152
|
+
self._camera = asi.Camera(camera_id)
|
|
153
|
+
camera_info = self._camera.get_camera_property()
|
|
154
|
+
|
|
155
|
+
# Set some sensible defaults. They will need adjusting depending upon
|
|
156
|
+
# the sensitivity, lens and lighting conditions used.
|
|
157
|
+
self._camera.disable_dark_subtract()
|
|
158
|
+
self._camera.set_control_value(asi.ASI_WB_B, 99)
|
|
159
|
+
self._camera.set_control_value(asi.ASI_WB_R, 75)
|
|
160
|
+
self._camera.set_control_value(asi.ASI_GAMMA, 50)
|
|
161
|
+
self._camera.set_control_value(asi.ASI_FLIP, 0)
|
|
162
|
+
self._camera.set_image_type(asi.ASI_IMG_RAW16)
|
|
79
163
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
164
|
+
# enabling image mode
|
|
165
|
+
self._camera.stop_video_capture()
|
|
166
|
+
self._camera.stop_exposure()
|
|
167
|
+
|
|
168
|
+
# get initial window and binning
|
|
169
|
+
binning = self._camera.get_bin()
|
|
170
|
+
left, top, width, height = self._camera.get_roi()
|
|
171
|
+
return camera_info, binning, (left, top, width, height)
|
|
172
|
+
|
|
173
|
+
self._camera_info, self._binning, self._window = await self._run_blocking_or_raise(_open)
|
|
83
174
|
|
|
84
|
-
self._camera = asi.Camera(camera_id)
|
|
85
|
-
self._camera_info = self._camera.get_camera_property()
|
|
86
175
|
log.info("Camera info:")
|
|
87
176
|
for key, val in self._camera_info.items():
|
|
88
177
|
log.info(" - %s: %s", key, val)
|
|
89
178
|
|
|
90
|
-
# Set some sensible defaults. They will need adjusting depending upon
|
|
91
|
-
# the sensitivity, lens and lighting conditions used.
|
|
92
|
-
self._camera.disable_dark_subtract()
|
|
93
|
-
self._camera.set_control_value(asi.ASI_WB_B, 99)
|
|
94
|
-
self._camera.set_control_value(asi.ASI_WB_R, 75)
|
|
95
|
-
self._camera.set_control_value(asi.ASI_GAMMA, 50)
|
|
96
|
-
self._camera.set_control_value(asi.ASI_FLIP, 0)
|
|
97
|
-
self._camera.set_image_type(asi.ASI_IMG_RAW16)
|
|
98
|
-
|
|
99
|
-
# enabling image mode
|
|
100
|
-
self._camera.stop_video_capture()
|
|
101
|
-
self._camera.stop_exposure()
|
|
102
|
-
|
|
103
|
-
# get initial window and binning
|
|
104
|
-
self._binning = self._camera.get_bin()
|
|
105
|
-
left, top, width, height = self._camera.get_roi()
|
|
106
|
-
self._window = (left, top, width, height)
|
|
107
|
-
|
|
108
179
|
# publish capabilities before super().open()
|
|
109
180
|
await self.comm.set_capabilities(
|
|
110
181
|
IWindow,
|
|
@@ -118,7 +189,7 @@ class AsiCamera(BaseCamera, IWindow, IBinning, IImageFormat, IGain, ITemperature
|
|
|
118
189
|
if "SupportedBins" in self._camera_info:
|
|
119
190
|
await self.comm.set_capabilities(
|
|
120
191
|
IBinning,
|
|
121
|
-
BinningCapabilities(binnings=[
|
|
192
|
+
BinningCapabilities(binnings=[Binning(x=b, y=b) for b in self._camera_info["SupportedBins"]]),
|
|
122
193
|
)
|
|
123
194
|
await self.comm.set_capabilities(IImageFormat, ImageFormatCapabilities(image_formats=list(FORMATS.keys())))
|
|
124
195
|
|
|
@@ -139,7 +210,8 @@ class AsiCamera(BaseCamera, IWindow, IBinning, IImageFormat, IGain, ITemperature
|
|
|
139
210
|
|
|
140
211
|
async def _publish_temperatures(self) -> None:
|
|
141
212
|
await self.comm.set_state(
|
|
142
|
-
ITemperatures,
|
|
213
|
+
ITemperatures,
|
|
214
|
+
TemperaturesState(readings=[SensorReading(name="CCD", value=await self._get_temperature())]),
|
|
143
215
|
)
|
|
144
216
|
|
|
145
217
|
async def set_window(self, left: int, top: int, width: int, height: int, **kwargs: Any) -> None:
|
|
@@ -188,6 +260,7 @@ class AsiCamera(BaseCamera, IWindow, IBinning, IImageFormat, IGain, ITemperature
|
|
|
188
260
|
"""
|
|
189
261
|
if self._camera is None:
|
|
190
262
|
raise ValueError("No camera initialised.")
|
|
263
|
+
camera = self._camera
|
|
191
264
|
|
|
192
265
|
image_format = FORMATS[self._image_format]
|
|
193
266
|
|
|
@@ -205,14 +278,6 @@ class AsiCamera(BaseCamera, IWindow, IBinning, IImageFormat, IGain, ITemperature
|
|
|
205
278
|
self._window[0],
|
|
206
279
|
self._window[1],
|
|
207
280
|
)
|
|
208
|
-
self._camera.set_roi(int(self._window[0]), int(self._window[1]), width, height, self._binning, image_format)
|
|
209
|
-
|
|
210
|
-
# set status and exposure time in us
|
|
211
|
-
self._camera.set_control_value(asi.ASI_EXPOSURE, int(exposure_time * 1e6))
|
|
212
|
-
|
|
213
|
-
# set gain and offset
|
|
214
|
-
self._camera.set_control_value(asi.ASI_GAIN, int(self._gain))
|
|
215
|
-
self._camera.set_control_value(asi.ASI_OFFSET, int(self._gain_offset))
|
|
216
281
|
|
|
217
282
|
log.info(
|
|
218
283
|
"Starting exposure with %s shutter for %s seconds and %s gain...",
|
|
@@ -221,26 +286,45 @@ class AsiCamera(BaseCamera, IWindow, IBinning, IImageFormat, IGain, ITemperature
|
|
|
221
286
|
self._gain,
|
|
222
287
|
)
|
|
223
288
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
289
|
+
def _start() -> None:
|
|
290
|
+
camera.set_roi(int(self._window[0]), int(self._window[1]), width, height, self._binning, image_format)
|
|
291
|
+
# set status and exposure time in us
|
|
292
|
+
camera.set_control_value(asi.ASI_EXPOSURE, int(exposure_time * 1e6))
|
|
293
|
+
# set gain and offset
|
|
294
|
+
camera.set_control_value(asi.ASI_GAIN, int(self._gain))
|
|
295
|
+
camera.set_control_value(asi.ASI_OFFSET, int(self._gain_offset))
|
|
296
|
+
camera.start_exposure()
|
|
227
297
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
if abort_event.is_set():
|
|
231
|
-
await self._change_exposure_status(ExposureStatus.IDLE)
|
|
232
|
-
raise InterruptedError("Aborted exposure.")
|
|
233
|
-
await event_wait(abort_event, 0.01)
|
|
298
|
+
await self._run_blocking_or_raise(_start)
|
|
299
|
+
await asyncio.sleep(0.01)
|
|
234
300
|
|
|
235
|
-
|
|
301
|
+
# wait for image -- runs the whole poll loop as a single blocking call (see _run_blocking),
|
|
302
|
+
# rather than polling get_exposure_status() every 10ms directly on the event loop
|
|
303
|
+
def _wait() -> Any:
|
|
304
|
+
while True:
|
|
305
|
+
exposure_status = camera.get_exposure_status()
|
|
306
|
+
if exposure_status != asi.ASI_EXP_WORKING or abort_event.is_set():
|
|
307
|
+
return exposure_status
|
|
308
|
+
time.sleep(0.01)
|
|
309
|
+
|
|
310
|
+
exposure_timeout = exposure_time + _EXPOSURE_WAIT_MARGIN
|
|
311
|
+
status = await self._run_blocking_or_raise(_wait, timeout=exposure_timeout)
|
|
312
|
+
|
|
313
|
+
if abort_event.is_set():
|
|
314
|
+
await self._change_exposure_status(ExposureStatus.IDLE)
|
|
315
|
+
raise InterruptedError("Aborted exposure.")
|
|
236
316
|
if status != asi.ASI_EXP_SUCCESS:
|
|
237
317
|
raise exc.GrabImageError(f"Could not capture image: {status}")
|
|
238
318
|
|
|
239
319
|
log.info("Exposure finished, reading out...")
|
|
240
320
|
await self._change_exposure_status(ExposureStatus.READOUT)
|
|
241
|
-
buffer = self._camera.get_data_after_exposure()
|
|
242
321
|
|
|
243
|
-
|
|
322
|
+
def _readout() -> tuple[Any, Any]:
|
|
323
|
+
buffer = camera.get_data_after_exposure()
|
|
324
|
+
whbi = camera.get_roi_format()
|
|
325
|
+
return buffer, whbi
|
|
326
|
+
|
|
327
|
+
buffer, whbi = await self._run_blocking_or_raise(_readout, timeout=_READOUT_TIMEOUT)
|
|
244
328
|
|
|
245
329
|
# decide on image format
|
|
246
330
|
shape = [whbi[1], whbi[0]]
|
|
@@ -291,7 +375,7 @@ class AsiCamera(BaseCamera, IWindow, IBinning, IImageFormat, IGain, ITemperature
|
|
|
291
375
|
if image_format in [asi.ASI_IMG_RAW8, asi.ASI_IMG_RAW16]:
|
|
292
376
|
image.header["BAYERPAT"] = image.header["COLORTYP"] = ("GBRG", "Bayer pattern for colors")
|
|
293
377
|
|
|
294
|
-
image.header["DET-TEMP"] = (self._get_temperature(), "CCD temperature [C]")
|
|
378
|
+
image.header["DET-TEMP"] = (await self._get_temperature(), "CCD temperature [C]")
|
|
295
379
|
|
|
296
380
|
self.set_biassec_trimsec(image.header, *self._window)
|
|
297
381
|
|
|
@@ -312,12 +396,17 @@ class AsiCamera(BaseCamera, IWindow, IBinning, IImageFormat, IGain, ITemperature
|
|
|
312
396
|
self._image_format = fmt
|
|
313
397
|
await self.comm.set_state(IImageFormat, ImageFormatState(image_format=fmt))
|
|
314
398
|
|
|
315
|
-
def _get_temperature(self) -> float:
|
|
399
|
+
async def _get_temperature(self) -> float:
|
|
316
400
|
"""Gets the temperature from the camera.
|
|
317
401
|
|
|
318
402
|
Reading is divided by 10, since ASI_TEMPERATURE returns temp * 10
|
|
319
403
|
"""
|
|
320
|
-
|
|
404
|
+
camera = self._camera
|
|
405
|
+
|
|
406
|
+
def _get() -> float:
|
|
407
|
+
return camera.get_control_value(asi.ASI_TEMPERATURE)[0] / 10 # type: ignore[union-attr]
|
|
408
|
+
|
|
409
|
+
return await self._run_blocking_or_raise(_get)
|
|
321
410
|
|
|
322
411
|
async def set_gain(self, gain: float, **kwargs: Any) -> None:
|
|
323
412
|
"""Set the camera gain.
|
|
@@ -367,16 +456,21 @@ class AsiCoolCamera(AsiCamera, ICooling):
|
|
|
367
456
|
|
|
368
457
|
async def _publish_temperatures(self) -> None:
|
|
369
458
|
await super()._publish_temperatures()
|
|
370
|
-
enabled, setpoint, power = self._get_cooling_status()
|
|
459
|
+
enabled, setpoint, power = await self._get_cooling_status()
|
|
371
460
|
await self.comm.set_state(ICooling, CoolingState(setpoint=setpoint, power=int(power), enabled=enabled))
|
|
372
461
|
|
|
373
|
-
def _get_cooling_status(self) -> tuple[bool, float, float]:
|
|
462
|
+
async def _get_cooling_status(self) -> tuple[bool, float, float]:
|
|
374
463
|
if self._camera is None:
|
|
375
464
|
raise ValueError("No camera initialised.")
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
465
|
+
camera = self._camera
|
|
466
|
+
|
|
467
|
+
def _get() -> tuple[bool, float, float]:
|
|
468
|
+
enabled = camera.get_control_value(asi.ASI_COOLER_ON)[0]
|
|
469
|
+
setpoint = camera.get_control_value(asi.ASI_TARGET_TEMP)[0]
|
|
470
|
+
power = camera.get_control_value(asi.ASI_COOLER_POWER_PERC)[0]
|
|
471
|
+
return bool(enabled), float(setpoint), float(power)
|
|
472
|
+
|
|
473
|
+
return await self._run_blocking_or_raise(_get)
|
|
380
474
|
|
|
381
475
|
async def set_cooling(self, enabled: bool, setpoint: float, **kwargs: Any) -> None:
|
|
382
476
|
"""Enables/disables cooling and sets setpoint.
|
|
@@ -390,16 +484,20 @@ class AsiCoolCamera(AsiCamera, ICooling):
|
|
|
390
484
|
"""
|
|
391
485
|
if self._camera is None:
|
|
392
486
|
raise ValueError("No camera initialised.")
|
|
487
|
+
camera = self._camera
|
|
393
488
|
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
489
|
+
def _set() -> None:
|
|
490
|
+
if enabled:
|
|
491
|
+
log.info("Enabling cooling with a setpoint of %.2f°C...", setpoint)
|
|
492
|
+
camera.set_control_value(asi.ASI_TARGET_TEMP, int(setpoint))
|
|
493
|
+
camera.set_control_value(asi.ASI_COOLER_ON, 1)
|
|
494
|
+
else:
|
|
495
|
+
log.info("Disabling cooling...")
|
|
496
|
+
camera.set_control_value(asi.ASI_COOLER_ON, 0)
|
|
497
|
+
|
|
498
|
+
await self._run_blocking_or_raise(_set)
|
|
401
499
|
|
|
402
|
-
enabled_status, setpoint_status, power = self._get_cooling_status()
|
|
500
|
+
enabled_status, setpoint_status, power = await self._get_cooling_status()
|
|
403
501
|
await self.comm.set_state(
|
|
404
502
|
ICooling, CoolingState(setpoint=setpoint_status, power=int(power), enabled=enabled_status)
|
|
405
503
|
)
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "pyobs-asi"
|
|
3
|
-
version = "2.0.0.
|
|
3
|
+
version = "2.0.0.dev5"
|
|
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)
|