pyobs-asi 1.1.0__tar.gz → 2.0.0.dev2__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.dev2/.github/workflows/ruff.yml +23 -0
- {pyobs_asi-1.1.0 → pyobs_asi-2.0.0.dev2}/.pre-commit-config.yaml +3 -3
- {pyobs_asi-1.1.0 → pyobs_asi-2.0.0.dev2}/PKG-INFO +5 -2
- pyobs_asi-2.0.0.dev2/README.md +71 -0
- {pyobs_asi-1.1.0 → pyobs_asi-2.0.0.dev2}/docs/source/index.rst +2 -1
- pyobs_asi-2.0.0.dev2/pyobs_asi/__init__.py +6 -0
- {pyobs_asi-1.1.0 → pyobs_asi-2.0.0.dev2}/pyobs_asi/asicamera.py +105 -155
- pyobs_asi-2.0.0.dev2/pyobs_asi/gui.py +129 -0
- pyobs_asi-2.0.0.dev2/pyproject.toml +47 -0
- pyobs_asi-2.0.0.dev2/uv.lock +2700 -0
- pyobs_asi-1.1.0/README.md +0 -44
- pyobs_asi-1.1.0/pyobs_asi/__init__.py +0 -6
- pyobs_asi-1.1.0/pyproject.toml +0 -29
- pyobs_asi-1.1.0/uv.lock +0 -1606
- {pyobs_asi-1.1.0 → pyobs_asi-2.0.0.dev2}/.github/workflows/pypi.yml +0 -0
- {pyobs_asi-1.1.0 → pyobs_asi-2.0.0.dev2}/.readthedocs.yml +0 -0
- {pyobs_asi-1.1.0 → pyobs_asi-2.0.0.dev2}/CHANGELOG.rst +0 -0
- {pyobs_asi-1.1.0 → pyobs_asi-2.0.0.dev2}/LICENSE +0 -0
- {pyobs_asi-1.1.0 → pyobs_asi-2.0.0.dev2}/docs/Makefile +0 -0
- {pyobs_asi-1.1.0 → pyobs_asi-2.0.0.dev2}/docs/make.bat +0 -0
- {pyobs_asi-1.1.0 → pyobs_asi-2.0.0.dev2}/docs/requirements.txt +0 -0
- {pyobs_asi-1.1.0 → pyobs_asi-2.0.0.dev2}/docs/source/_static/pyobs.gif +0 -0
- {pyobs_asi-1.1.0 → pyobs_asi-2.0.0.dev2}/docs/source/conf.py +0 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
name: ruff
|
|
2
|
+
on: push
|
|
3
|
+
|
|
4
|
+
jobs:
|
|
5
|
+
ruff:
|
|
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 ruff
|
|
23
|
+
run: uv run --no-sync ruff check pyobs_asi/
|
|
@@ -9,7 +9,7 @@ repos:
|
|
|
9
9
|
# pre-commit's default_language_version, see
|
|
10
10
|
# https://pre-commit.com/#top_level-default_language_version
|
|
11
11
|
language_version: python3.11
|
|
12
|
-
- repo: https://github.com/
|
|
13
|
-
rev:
|
|
12
|
+
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
13
|
+
rev: v0.9.0
|
|
14
14
|
hooks:
|
|
15
|
-
|
|
15
|
+
- id: ruff
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pyobs-asi
|
|
3
|
-
Version:
|
|
3
|
+
Version: 2.0.0.dev2
|
|
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<2
|
|
10
|
+
Requires-Dist: pyobs-core<3,>=2.0.0.dev1
|
|
11
11
|
Requires-Dist: zwoasi>=0.2.0
|
|
12
|
+
Provides-Extra: gui
|
|
13
|
+
Requires-Dist: pyobs-core[gui]<3,>=2.0.0.dev1; extra == 'gui'
|
|
14
|
+
Requires-Dist: qasync>=0.28.0; extra == 'gui'
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
*pyobs* for ZWO ASI cameras
|
|
2
|
+
===========================
|
|
3
|
+
|
|
4
|
+
This is a [pyobs](https://www.pyobs.org) module for [ZWO ASI](https://astronomy-imaging-camera.com/) cameras.
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
ASI SDK
|
|
8
|
+
-------
|
|
9
|
+
Download the ASI SDK from https://astronomy-imaging-camera.com/software-drivers and install the libraries from the
|
|
10
|
+
appropriate folder in `lib/` to `/usr/local/lib`. Then copy `asi.rules` to `/etc/udev/rules.d/99-asi.rules`.
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
Install *pyobs-asi*
|
|
14
|
+
--------------------
|
|
15
|
+
Clone the repository:
|
|
16
|
+
|
|
17
|
+
git clone https://github.com/pyobs/pyobs-asi.git
|
|
18
|
+
cd pyobs-asi
|
|
19
|
+
|
|
20
|
+
Install it with [uv](https://docs.astral.sh/uv/):
|
|
21
|
+
|
|
22
|
+
uv sync
|
|
23
|
+
|
|
24
|
+
Alternatively, with plain `venv`/`pip`:
|
|
25
|
+
|
|
26
|
+
python3 -m venv .venv
|
|
27
|
+
source .venv/bin/activate
|
|
28
|
+
pip install .
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
Configuration
|
|
32
|
+
-------------
|
|
33
|
+
The *AsiCamera* class is derived from *BaseCamera* (see *pyobs* documentation) and adds some new parameters:
|
|
34
|
+
|
|
35
|
+
camera:
|
|
36
|
+
Name of camera to acquire driver for.
|
|
37
|
+
sdk:
|
|
38
|
+
Path to .so file from ASI SDK.
|
|
39
|
+
|
|
40
|
+
Therefore, a basic module configuration would look like this:
|
|
41
|
+
|
|
42
|
+
class: pyobs_asi.AsiCamera
|
|
43
|
+
name: ASI camera
|
|
44
|
+
camera: ZWO ASI071MC Pro
|
|
45
|
+
|
|
46
|
+
For cameras with cooling, use *AsiCoolCamera* instead, which adds a `setpoint` parameter for the initial cooling
|
|
47
|
+
setpoint in degrees Celsius:
|
|
48
|
+
|
|
49
|
+
class: pyobs_asi.AsiCoolCamera
|
|
50
|
+
name: ASI camera
|
|
51
|
+
camera: ZWO ASI071MC Pro
|
|
52
|
+
setpoint: -20
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
GUI
|
|
56
|
+
---
|
|
57
|
+
For testing a camera without a full *pyobs* setup, install the optional `gui` extra:
|
|
58
|
+
|
|
59
|
+
uv sync --extra gui
|
|
60
|
+
|
|
61
|
+
and run:
|
|
62
|
+
|
|
63
|
+
uv run asi-gui [path/to/libASICamera2.so]
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
Dependencies
|
|
67
|
+
------------
|
|
68
|
+
* [pyobs-core](https://github.com/pyobs/pyobs-core) for the core functionality.
|
|
69
|
+
* [zwoasi](https://github.com/stevemarple/python-zwoasi/) as a Python wrapper for the ASI SDK.
|
|
70
|
+
* [Astropy](http://www.astropy.org/) for FITS file handling.
|
|
71
|
+
* [NumPy](http://www.numpy.org/) for array handling.
|
|
@@ -53,7 +53,8 @@ This is an example configuration, tested on a ASI 071 MC::
|
|
|
53
53
|
Available classes
|
|
54
54
|
*****************
|
|
55
55
|
|
|
56
|
-
There
|
|
56
|
+
There are two classes for ASI ZWO cameras: :class:`~pyobs_asi.AsiCamera` for cameras without cooling, and
|
|
57
|
+
:class:`~pyobs_asi.AsiCoolCamera` for cameras with cooling support.
|
|
57
58
|
|
|
58
59
|
AsiCamera
|
|
59
60
|
=========
|
|
@@ -1,23 +1,39 @@
|
|
|
1
1
|
import asyncio
|
|
2
2
|
import logging
|
|
3
3
|
import math
|
|
4
|
-
from datetime import
|
|
5
|
-
from typing import
|
|
4
|
+
from datetime import UTC, datetime
|
|
5
|
+
from typing import Any, cast
|
|
6
6
|
|
|
7
7
|
import numpy as np
|
|
8
8
|
import zwoasi as asi # type: ignore
|
|
9
|
-
|
|
10
|
-
from pyobs.interfaces import ICamera, IWindow, IBinning, ICooling, IImageFormat, IAbortable, ITemperatures, IGain
|
|
11
|
-
from pyobs.modules.camera.basecamera import BaseCamera
|
|
12
|
-
from pyobs.utils.enums import ImageFormat, ExposureStatus
|
|
9
|
+
from numpy.typing import NDArray
|
|
13
10
|
from pyobs.images import Image
|
|
14
|
-
from pyobs.
|
|
11
|
+
from pyobs.interfaces import (
|
|
12
|
+
BinningCapabilities,
|
|
13
|
+
BinningState,
|
|
14
|
+
CoolingState,
|
|
15
|
+
GainState,
|
|
16
|
+
IBinning,
|
|
17
|
+
ICooling,
|
|
18
|
+
IGain,
|
|
19
|
+
IImageFormat,
|
|
20
|
+
ImageFormatCapabilities,
|
|
21
|
+
ImageFormatState,
|
|
22
|
+
ITemperatures,
|
|
23
|
+
IWindow,
|
|
24
|
+
SensorReading,
|
|
25
|
+
TemperaturesState,
|
|
26
|
+
WindowCapabilities,
|
|
27
|
+
WindowState,
|
|
28
|
+
)
|
|
29
|
+
from pyobs.modules.camera.basecamera import BaseCamera
|
|
15
30
|
from pyobs.utils import exceptions as exc
|
|
31
|
+
from pyobs.utils.enums import ExposureStatus, ImageFormat
|
|
32
|
+
from pyobs.utils.parallel import event_wait
|
|
16
33
|
|
|
17
34
|
log = logging.getLogger(__name__)
|
|
18
35
|
|
|
19
36
|
|
|
20
|
-
# map of image formats
|
|
21
37
|
FORMATS = {
|
|
22
38
|
ImageFormat.INT8: asi.ASI_IMG_RAW8,
|
|
23
39
|
ImageFormat.INT16: asi.ASI_IMG_RAW16,
|
|
@@ -25,7 +41,7 @@ FORMATS = {
|
|
|
25
41
|
}
|
|
26
42
|
|
|
27
43
|
|
|
28
|
-
class AsiCamera(BaseCamera,
|
|
44
|
+
class AsiCamera(BaseCamera, IWindow, IBinning, IImageFormat, IGain, ITemperatures):
|
|
29
45
|
"""A pyobs module for ASI cameras."""
|
|
30
46
|
|
|
31
47
|
__module__ = "pyobs_asi"
|
|
@@ -39,37 +55,32 @@ class AsiCamera(BaseCamera, ICamera, IWindow, IBinning, IImageFormat, IAbortable
|
|
|
39
55
|
"""
|
|
40
56
|
BaseCamera.__init__(self, **kwargs)
|
|
41
57
|
|
|
42
|
-
# variables
|
|
43
58
|
self._camera_name = camera
|
|
44
59
|
self._sdk_path = sdk
|
|
45
|
-
self._camera:
|
|
46
|
-
self._camera_info:
|
|
60
|
+
self._camera: asi.Camera | None = None
|
|
61
|
+
self._camera_info: dict[str, Any] = {}
|
|
47
62
|
|
|
48
|
-
# window and binning and mode
|
|
49
63
|
self._window = (0, 0, 0, 0)
|
|
50
64
|
self._binning = 1
|
|
51
65
|
self._image_format = ImageFormat.INT16
|
|
52
66
|
|
|
53
67
|
self._gain: float = 1.0
|
|
68
|
+
self._gain_offset: float = 50.0
|
|
69
|
+
|
|
70
|
+
self.add_background_task(self._temperature_thread, True)
|
|
54
71
|
|
|
55
72
|
async def open(self) -> None:
|
|
56
73
|
"""Open module."""
|
|
57
|
-
await BaseCamera.open(self)
|
|
58
|
-
|
|
59
|
-
# init driver
|
|
60
74
|
asi.init(self._sdk_path)
|
|
61
75
|
|
|
62
|
-
# get number of cameras
|
|
63
76
|
num_cameras = asi.get_num_cameras()
|
|
64
77
|
if num_cameras == 0:
|
|
65
78
|
raise ValueError("No cameras found")
|
|
66
79
|
|
|
67
|
-
# get ID of camera
|
|
68
80
|
# index() raises ValueError, if camera could not be found
|
|
69
81
|
cameras_found = asi.list_cameras()
|
|
70
82
|
camera_id = cameras_found.index(self._camera_name)
|
|
71
83
|
|
|
72
|
-
# open driver
|
|
73
84
|
self._camera = asi.Camera(camera_id)
|
|
74
85
|
self._camera_info = self._camera.get_camera_property()
|
|
75
86
|
log.info("Camera info:")
|
|
@@ -82,7 +93,6 @@ class AsiCamera(BaseCamera, ICamera, IWindow, IBinning, IImageFormat, IAbortable
|
|
|
82
93
|
self._camera.set_control_value(asi.ASI_WB_B, 99)
|
|
83
94
|
self._camera.set_control_value(asi.ASI_WB_R, 75)
|
|
84
95
|
self._camera.set_control_value(asi.ASI_GAMMA, 50)
|
|
85
|
-
self._camera.set_control_value(asi.ASI_BRIGHTNESS, 50)
|
|
86
96
|
self._camera.set_control_value(asi.ASI_FLIP, 0)
|
|
87
97
|
self._camera.set_image_type(asi.ASI_IMG_RAW16)
|
|
88
98
|
|
|
@@ -92,31 +102,45 @@ class AsiCamera(BaseCamera, ICamera, IWindow, IBinning, IImageFormat, IAbortable
|
|
|
92
102
|
|
|
93
103
|
# get initial window and binning
|
|
94
104
|
self._binning = self._camera.get_bin()
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
async def get_full_frame(self, **kwargs: Any) -> Tuple[int, int, int, int]:
|
|
98
|
-
"""Returns full size of CCD.
|
|
99
|
-
|
|
100
|
-
Returns:
|
|
101
|
-
Tuple with left, top, width, and height set.
|
|
102
|
-
"""
|
|
103
|
-
return 0, 0, self._camera_info["MaxWidth"], self._camera_info["MaxHeight"]
|
|
104
|
-
|
|
105
|
-
async def get_window(self, **kwargs: Any) -> Tuple[int, int, int, int]:
|
|
106
|
-
"""Returns the camera window.
|
|
105
|
+
left, top, width, height = self._camera.get_roi()
|
|
106
|
+
self._window = (left, top, width, height)
|
|
107
107
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
108
|
+
# publish capabilities before super().open()
|
|
109
|
+
await self.comm.set_capabilities(
|
|
110
|
+
IWindow,
|
|
111
|
+
WindowCapabilities(
|
|
112
|
+
full_frame_x=0,
|
|
113
|
+
full_frame_y=0,
|
|
114
|
+
full_frame_width=self._camera_info["MaxWidth"],
|
|
115
|
+
full_frame_height=self._camera_info["MaxHeight"],
|
|
116
|
+
),
|
|
117
|
+
)
|
|
118
|
+
if "SupportedBins" in self._camera_info:
|
|
119
|
+
await self.comm.set_capabilities(
|
|
120
|
+
IBinning,
|
|
121
|
+
BinningCapabilities(binnings=[BinningState(x=b, y=b) for b in self._camera_info["SupportedBins"]]),
|
|
122
|
+
)
|
|
123
|
+
await self.comm.set_capabilities(IImageFormat, ImageFormatCapabilities(image_formats=list(FORMATS.keys())))
|
|
112
124
|
|
|
113
|
-
|
|
114
|
-
"""Returns the camera binning.
|
|
125
|
+
await BaseCamera.open(self)
|
|
115
126
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
127
|
+
# publish initial states
|
|
128
|
+
await self.comm.set_state(IWindow, WindowState(*self._window))
|
|
129
|
+
await self.comm.set_state(IBinning, BinningState(x=self._binning, y=self._binning))
|
|
130
|
+
await self.comm.set_state(IGain, GainState(gain=self._gain, offset=self._gain_offset))
|
|
131
|
+
await self.comm.set_state(IImageFormat, ImageFormatState(image_format=self._image_format))
|
|
132
|
+
|
|
133
|
+
async def _temperature_thread(self) -> None:
|
|
134
|
+
"""Periodically publishes temperature (and cooling) readings."""
|
|
135
|
+
while True:
|
|
136
|
+
if self._camera is not None:
|
|
137
|
+
await self._publish_temperatures()
|
|
138
|
+
await asyncio.sleep(5)
|
|
139
|
+
|
|
140
|
+
async def _publish_temperatures(self) -> None:
|
|
141
|
+
await self.comm.set_state(
|
|
142
|
+
ITemperatures, TemperaturesState(readings=[SensorReading(name="CCD", value=self._get_temperature())])
|
|
143
|
+
)
|
|
120
144
|
|
|
121
145
|
async def set_window(self, left: int, top: int, width: int, height: int, **kwargs: Any) -> None:
|
|
122
146
|
"""Set the camera window.
|
|
@@ -132,6 +156,7 @@ class AsiCamera(BaseCamera, ICamera, IWindow, IBinning, IImageFormat, IAbortable
|
|
|
132
156
|
"""
|
|
133
157
|
self._window = (left, top, width, height)
|
|
134
158
|
log.info("Setting window to %dx%d at %d,%d...", width, height, left, top)
|
|
159
|
+
await self.comm.set_state(IWindow, WindowState(x=left, y=top, width=width, height=height))
|
|
135
160
|
|
|
136
161
|
async def set_binning(self, x: int, y: int, **kwargs: Any) -> None:
|
|
137
162
|
"""Set the camera binning.
|
|
@@ -145,19 +170,7 @@ class AsiCamera(BaseCamera, ICamera, IWindow, IBinning, IImageFormat, IAbortable
|
|
|
145
170
|
"""
|
|
146
171
|
self._binning = x
|
|
147
172
|
log.info("Setting binning to %dx%d...", x, x)
|
|
148
|
-
|
|
149
|
-
async def list_binnings(self, **kwargs: Any) -> List[Tuple[int, int]]:
|
|
150
|
-
"""List available binnings.
|
|
151
|
-
|
|
152
|
-
Returns:
|
|
153
|
-
List of available binnings as (x, y) tuples.
|
|
154
|
-
"""
|
|
155
|
-
|
|
156
|
-
if "SupportedBins" in self._camera_info:
|
|
157
|
-
# create list of tuples
|
|
158
|
-
return [(b, b) for b in self._camera_info["SupportedBins"]]
|
|
159
|
-
else:
|
|
160
|
-
return []
|
|
173
|
+
await self.comm.set_state(IBinning, BinningState(x=x, y=y))
|
|
161
174
|
|
|
162
175
|
async def _expose(self, exposure_time: float, open_shutter: bool, abort_event: asyncio.Event) -> Image:
|
|
163
176
|
"""Actually do the exposure, should be implemented by derived classes.
|
|
@@ -173,12 +186,9 @@ class AsiCamera(BaseCamera, ICamera, IWindow, IBinning, IImageFormat, IAbortable
|
|
|
173
186
|
Raises:
|
|
174
187
|
GrabImageError: If exposure was not successful.
|
|
175
188
|
"""
|
|
176
|
-
|
|
177
|
-
# no camera?
|
|
178
189
|
if self._camera is None:
|
|
179
190
|
raise ValueError("No camera initialised.")
|
|
180
191
|
|
|
181
|
-
# get image format
|
|
182
192
|
image_format = FORMATS[self._image_format]
|
|
183
193
|
|
|
184
194
|
# set window, divide width/height by binning
|
|
@@ -197,15 +207,18 @@ class AsiCamera(BaseCamera, ICamera, IWindow, IBinning, IImageFormat, IAbortable
|
|
|
197
207
|
)
|
|
198
208
|
self._camera.set_roi(int(self._window[0]), int(self._window[1]), width, height, self._binning, image_format)
|
|
199
209
|
|
|
200
|
-
# set status and exposure time in
|
|
210
|
+
# set status and exposure time in us
|
|
201
211
|
self._camera.set_control_value(asi.ASI_EXPOSURE, int(exposure_time * 1e6))
|
|
202
212
|
|
|
203
|
-
# set gain
|
|
213
|
+
# set gain and offset
|
|
204
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))
|
|
205
216
|
|
|
206
217
|
log.info(
|
|
207
|
-
"Starting exposure with %s shutter for %s seconds and %s gain...",
|
|
208
|
-
if open_shutter else "closed",
|
|
218
|
+
"Starting exposure with %s shutter for %s seconds and %s gain...",
|
|
219
|
+
"open" if open_shutter else "closed",
|
|
220
|
+
exposure_time,
|
|
221
|
+
self._gain,
|
|
209
222
|
)
|
|
210
223
|
|
|
211
224
|
# do exposure
|
|
@@ -214,20 +227,15 @@ class AsiCamera(BaseCamera, ICamera, IWindow, IBinning, IImageFormat, IAbortable
|
|
|
214
227
|
|
|
215
228
|
# wait for image
|
|
216
229
|
while self._camera.get_exposure_status() == asi.ASI_EXP_WORKING:
|
|
217
|
-
# aborted?
|
|
218
230
|
if abort_event.is_set():
|
|
219
231
|
await self._change_exposure_status(ExposureStatus.IDLE)
|
|
220
232
|
raise InterruptedError("Aborted exposure.")
|
|
221
|
-
|
|
222
|
-
# sleep a little
|
|
223
233
|
await event_wait(abort_event, 0.01)
|
|
224
234
|
|
|
225
|
-
# success?
|
|
226
235
|
status = self._camera.get_exposure_status()
|
|
227
236
|
if status != asi.ASI_EXP_SUCCESS:
|
|
228
|
-
raise exc.GrabImageError("Could not capture image:
|
|
237
|
+
raise exc.GrabImageError(f"Could not capture image: {status}")
|
|
229
238
|
|
|
230
|
-
# get data
|
|
231
239
|
log.info("Exposure finished, reading out...")
|
|
232
240
|
await self._change_exposure_status(ExposureStatus.READOUT)
|
|
233
241
|
buffer = self._camera.get_data_after_exposure()
|
|
@@ -236,6 +244,7 @@ class AsiCamera(BaseCamera, ICamera, IWindow, IBinning, IImageFormat, IAbortable
|
|
|
236
244
|
|
|
237
245
|
# decide on image format
|
|
238
246
|
shape = [whbi[1], whbi[0]]
|
|
247
|
+
data: NDArray[Any]
|
|
239
248
|
if image_format == asi.ASI_IMG_RAW8:
|
|
240
249
|
data = np.frombuffer(buffer, dtype=np.uint8)
|
|
241
250
|
elif image_format == asi.ASI_IMG_RAW16:
|
|
@@ -246,7 +255,6 @@ class AsiCamera(BaseCamera, ICamera, IWindow, IBinning, IImageFormat, IAbortable
|
|
|
246
255
|
else:
|
|
247
256
|
raise exc.GrabImageError("Unknown image format.")
|
|
248
257
|
|
|
249
|
-
# reshape
|
|
250
258
|
data = data.reshape(shape)
|
|
251
259
|
|
|
252
260
|
# special treatment for RGB images
|
|
@@ -259,57 +267,37 @@ class AsiCamera(BaseCamera, ICamera, IWindow, IBinning, IImageFormat, IAbortable
|
|
|
259
267
|
# i.e. we go from RGBRGBRGBRGBRGB to RRRRRGGGGGBBBBB
|
|
260
268
|
data = np.moveaxis(data, 2, 0)
|
|
261
269
|
|
|
262
|
-
|
|
263
|
-
date_obs = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%S.%f")
|
|
270
|
+
date_obs = datetime.now(UTC).strftime("%Y-%m-%dT%H:%M:%S.%f")
|
|
264
271
|
|
|
265
|
-
|
|
266
|
-
image = Image(data)
|
|
272
|
+
image = Image(cast(NDArray[Any], data))
|
|
267
273
|
image.header["DATE-OBS"] = (date_obs, "Date and time of start of exposure")
|
|
268
274
|
image.header["EXPTIME"] = (exposure_time, "Exposure time [s]")
|
|
269
275
|
|
|
270
|
-
# instrument and detector
|
|
271
276
|
image.header["INSTRUME"] = (self._camera_name, "Name of instrument")
|
|
272
277
|
|
|
273
|
-
# binning
|
|
274
278
|
image.header["XBINNING"] = image.header["DET-BIN1"] = (self._binning, "Binning factor used on X axis")
|
|
275
279
|
image.header["YBINNING"] = image.header["DET-BIN2"] = (self._binning, "Binning factor used on Y axis")
|
|
276
280
|
|
|
277
|
-
# window
|
|
278
281
|
image.header["XORGSUBF"] = (self._window[0], "Subframe origin on X axis")
|
|
279
282
|
image.header["YORGSUBF"] = (self._window[1], "Subframe origin on Y axis")
|
|
280
283
|
|
|
281
|
-
# statistics
|
|
282
284
|
image.header["DATAMIN"] = (float(np.min(data)), "Minimum data value")
|
|
283
285
|
image.header["DATAMAX"] = (float(np.max(data)), "Maximum data value")
|
|
284
286
|
image.header["DATAMEAN"] = (float(np.mean(data)), "Mean data value")
|
|
285
287
|
|
|
286
|
-
# pixels
|
|
287
288
|
image.header["DET-PIXL"] = (self._camera_info["PixelSize"] / 1000.0, "Size of detector pixels (square) [mm]")
|
|
288
289
|
image.header["DET-GAIN"] = (self._camera_info["ElecPerADU"] * self._gain, "Detector gain [e-/ADU]")
|
|
289
290
|
|
|
290
|
-
# Bayer pattern?
|
|
291
291
|
if image_format in [asi.ASI_IMG_RAW8, asi.ASI_IMG_RAW16]:
|
|
292
292
|
image.header["BAYERPAT"] = image.header["COLORTYP"] = ("GBRG", "Bayer pattern for colors")
|
|
293
293
|
|
|
294
|
-
|
|
295
|
-
temperature = self._get_temperature()
|
|
296
|
-
image.header["DET-TEMP"] = (temperature, "CCD temperature [C]")
|
|
294
|
+
image.header["DET-TEMP"] = (self._get_temperature(), "CCD temperature [C]")
|
|
297
295
|
|
|
298
|
-
# biassec/trimsec
|
|
299
296
|
self.set_biassec_trimsec(image.header, *self._window)
|
|
300
297
|
|
|
301
|
-
# return FITS image
|
|
302
298
|
log.info("Readout finished.")
|
|
303
299
|
return image
|
|
304
300
|
|
|
305
|
-
async def _abort_exposure(self) -> None:
|
|
306
|
-
"""Abort the running exposure. Should be implemented by derived class.
|
|
307
|
-
|
|
308
|
-
Raises:
|
|
309
|
-
ValueError: If an error occured.
|
|
310
|
-
"""
|
|
311
|
-
pass
|
|
312
|
-
|
|
313
301
|
async def set_image_format(self, fmt: ImageFormat, **kwargs: Any) -> None:
|
|
314
302
|
"""Set the camera image format.
|
|
315
303
|
|
|
@@ -322,34 +310,14 @@ class AsiCamera(BaseCamera, ICamera, IWindow, IBinning, IImageFormat, IAbortable
|
|
|
322
310
|
if fmt not in FORMATS:
|
|
323
311
|
raise ValueError("Unsupported image format.")
|
|
324
312
|
self._image_format = fmt
|
|
325
|
-
|
|
326
|
-
async def get_image_format(self, **kwargs: Any) -> ImageFormat:
|
|
327
|
-
"""Returns the camera image format.
|
|
328
|
-
|
|
329
|
-
Returns:
|
|
330
|
-
Current image format.
|
|
331
|
-
"""
|
|
332
|
-
return self._image_format
|
|
333
|
-
|
|
334
|
-
async def list_image_formats(self, **kwargs: Any) -> List[str]:
|
|
335
|
-
"""List available image formats.
|
|
336
|
-
|
|
337
|
-
Returns:
|
|
338
|
-
List of available image formats.
|
|
339
|
-
"""
|
|
340
|
-
return [f.value for f in FORMATS.keys()]
|
|
341
|
-
|
|
342
|
-
async def get_temperatures(self, **kwargs: Any) -> Dict[str, float]:
|
|
343
|
-
temperature = self._get_temperature()
|
|
344
|
-
return {"CCD": temperature}
|
|
313
|
+
await self.comm.set_state(IImageFormat, ImageFormatState(image_format=fmt))
|
|
345
314
|
|
|
346
315
|
def _get_temperature(self) -> float:
|
|
347
|
-
"""
|
|
348
|
-
Gets the temperature from the camera.
|
|
316
|
+
"""Gets the temperature from the camera.
|
|
349
317
|
|
|
350
318
|
Reading is divided by 10, since ASI_TEMPERATURE returns temp * 10
|
|
351
319
|
"""
|
|
352
|
-
return self._camera.get_control_value(asi.ASI_TEMPERATURE)[0] / 10
|
|
320
|
+
return self._camera.get_control_value(asi.ASI_TEMPERATURE)[0] / 10 # type: ignore[union-attr]
|
|
353
321
|
|
|
354
322
|
async def set_gain(self, gain: float, **kwargs: Any) -> None:
|
|
355
323
|
"""Set the camera gain.
|
|
@@ -361,14 +329,19 @@ class AsiCamera(BaseCamera, ICamera, IWindow, IBinning, IImageFormat, IAbortable
|
|
|
361
329
|
ValueError: If gain could not be set.
|
|
362
330
|
"""
|
|
363
331
|
self._gain = gain
|
|
332
|
+
await self.comm.set_state(IGain, GainState(gain=self._gain, offset=self._gain_offset))
|
|
364
333
|
|
|
365
|
-
async def
|
|
366
|
-
"""
|
|
334
|
+
async def set_offset(self, offset: float, **kwargs: Any) -> None:
|
|
335
|
+
"""Set the camera offset.
|
|
367
336
|
|
|
368
|
-
|
|
369
|
-
|
|
337
|
+
Args:
|
|
338
|
+
offset: New camera offset.
|
|
339
|
+
|
|
340
|
+
Raises:
|
|
341
|
+
ValueError: If offset could not be set.
|
|
370
342
|
"""
|
|
371
|
-
|
|
343
|
+
self._gain_offset = offset
|
|
344
|
+
await self.comm.set_state(IGain, GainState(gain=self._gain, offset=self._gain_offset))
|
|
372
345
|
|
|
373
346
|
|
|
374
347
|
class AsiCoolCamera(AsiCamera, ICooling):
|
|
@@ -381,54 +354,29 @@ class AsiCoolCamera(AsiCamera, ICooling):
|
|
|
381
354
|
setpoint: Cooling temperature setpoint.
|
|
382
355
|
"""
|
|
383
356
|
AsiCamera.__init__(self, **kwargs)
|
|
384
|
-
|
|
385
|
-
# variables
|
|
386
357
|
self._temp_setpoint = setpoint
|
|
387
358
|
|
|
388
359
|
async def open(self) -> None:
|
|
389
360
|
"""Open module."""
|
|
390
361
|
await AsiCamera.open(self)
|
|
391
362
|
|
|
392
|
-
# no cooling support?
|
|
393
363
|
if not self._camera_info["IsCoolerCam"]:
|
|
394
364
|
raise ValueError("Camera has no support for cooling.")
|
|
395
365
|
|
|
396
|
-
# activate cooling
|
|
397
366
|
await self.set_cooling(True, self._temp_setpoint)
|
|
398
367
|
|
|
399
|
-
async def
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
Tuple containing:
|
|
404
|
-
Enabled (bool): Whether the cooling is enabled
|
|
405
|
-
SetPoint (float): Setpoint for the cooling in celsius.
|
|
406
|
-
Power (float): Current cooling power in percent or None.
|
|
407
|
-
"""
|
|
368
|
+
async def _publish_temperatures(self) -> None:
|
|
369
|
+
await super()._publish_temperatures()
|
|
370
|
+
enabled, setpoint, power = self._get_cooling_status()
|
|
371
|
+
await self.comm.set_state(ICooling, CoolingState(setpoint=setpoint, power=int(power), enabled=enabled))
|
|
408
372
|
|
|
409
|
-
|
|
373
|
+
def _get_cooling_status(self) -> tuple[bool, float, float]:
|
|
410
374
|
if self._camera is None:
|
|
411
375
|
raise ValueError("No camera initialised.")
|
|
412
|
-
|
|
413
|
-
# return
|
|
414
376
|
enabled = self._camera.get_control_value(asi.ASI_COOLER_ON)[0]
|
|
415
|
-
|
|
377
|
+
setpoint = self._camera.get_control_value(asi.ASI_TARGET_TEMP)[0]
|
|
416
378
|
power = self._camera.get_control_value(asi.ASI_COOLER_POWER_PERC)[0]
|
|
417
|
-
return enabled,
|
|
418
|
-
|
|
419
|
-
async def get_temperatures(self, **kwargs: Any) -> Dict[str, float]:
|
|
420
|
-
"""Returns all temperatures measured by this module.
|
|
421
|
-
|
|
422
|
-
Returns:
|
|
423
|
-
Dict containing temperatures.
|
|
424
|
-
"""
|
|
425
|
-
|
|
426
|
-
# no camera?
|
|
427
|
-
if self._camera is None:
|
|
428
|
-
raise ValueError("No camera initialised.")
|
|
429
|
-
|
|
430
|
-
# return
|
|
431
|
-
return {"CCD": self._camera.get_control_value(asi.ASI_TEMPERATURE)[0] / 10.0}
|
|
379
|
+
return bool(enabled), float(setpoint), float(power)
|
|
432
380
|
|
|
433
381
|
async def set_cooling(self, enabled: bool, setpoint: float, **kwargs: Any) -> None:
|
|
434
382
|
"""Enables/disables cooling and sets setpoint.
|
|
@@ -440,12 +388,9 @@ class AsiCoolCamera(AsiCamera, ICooling):
|
|
|
440
388
|
Raises:
|
|
441
389
|
ValueError: If cooling could not be set.
|
|
442
390
|
"""
|
|
443
|
-
|
|
444
|
-
# no camera?
|
|
445
391
|
if self._camera is None:
|
|
446
392
|
raise ValueError("No camera initialised.")
|
|
447
393
|
|
|
448
|
-
# log
|
|
449
394
|
if enabled:
|
|
450
395
|
log.info("Enabling cooling with a setpoint of %.2f°C...", setpoint)
|
|
451
396
|
self._camera.set_control_value(asi.ASI_TARGET_TEMP, int(setpoint))
|
|
@@ -454,5 +399,10 @@ class AsiCoolCamera(AsiCamera, ICooling):
|
|
|
454
399
|
log.info("Disabling cooling...")
|
|
455
400
|
self._camera.set_control_value(asi.ASI_COOLER_ON, 0)
|
|
456
401
|
|
|
402
|
+
enabled_status, setpoint_status, power = self._get_cooling_status()
|
|
403
|
+
await self.comm.set_state(
|
|
404
|
+
ICooling, CoolingState(setpoint=setpoint_status, power=int(power), enabled=enabled_status)
|
|
405
|
+
)
|
|
406
|
+
|
|
457
407
|
|
|
458
408
|
__all__ = ["AsiCamera", "AsiCoolCamera"]
|