Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
7d2fdc1
Bump the patch-and-minor group with 3 updates
dependabot[bot] Oct 6, 2026
f80b489
Merge pull request #65 from pyobs/dependabot/uv/develop/patch-and-min…
github-actions[bot] Oct 6, 2026
116f1a4
Bump multidict from 6.7.1 to 6.9.1
dependabot[bot] Oct 6, 2026
ebff560
Merge pull request #66 from pyobs/dependabot/uv/multidict-6.9.1
github-actions[bot] Oct 6, 2026
e0fe8f5
Bump the patch-and-minor group with 3 updates
dependabot[bot] Oct 14, 2026
757bc23
Merge pull request #67 from pyobs/dependabot/uv/develop/patch-and-min…
github-actions[bot] Oct 14, 2026
a4b7b0c
docs: mark frames() migration plan implemented, note deviations
thusser Oct 17, 2026
5c6f93f
Bump the patch-and-minor group with 4 updates
dependabot[bot] Oct 20, 2026
a220d0d
Merge pull request #68 from pyobs/dependabot/uv/develop/patch-and-min…
github-actions[bot] Oct 20, 2026
3fc03d4
Bump virtualenv from 21.7.13 to 21.14.9
dependabot[bot] Oct 23, 2026
b9b03ed
Bump pillow from 12.3.0 to 13.0.0
dependabot[bot] Oct 23, 2026
e58c49d
Merge pull request #70 from pyobs/dependabot/uv/virtualenv-21.14.9
github-actions[bot] Oct 23, 2026
0f78691
Bump virtualenv from 21.14.9 to 21.14.13
dependabot[bot] Oct 23, 2026
afa21d3
Bump filelock from 3.32.2 to 4.2.1
dependabot[bot] Oct 23, 2026
7a71c38
Merge pull request #72 from pyobs/dependabot/uv/virtualenv-21.14.13
github-actions[bot] Oct 23, 2026
556103c
Bump the patch-and-minor group with 2 updates
dependabot[bot] Oct 27, 2026
beba9cb
Merge pull request #74 from pyobs/dependabot/uv/develop/patch-and-min…
github-actions[bot] Oct 27, 2026
f3cfeef
Bump certifi from 2026.7.22 to 2026.10.18
dependabot[bot] Oct 27, 2026
4e82871
Merge pull request #75 from pyobs/dependabot/uv/certifi-2026.10.18
github-actions[bot] Oct 27, 2026
29cccad
Bump pyasn1 from 0.6.4 to 0.6.5
dependabot[bot] Oct 30, 2026
b6ee9af
Merge pull request #76 from pyobs/dependabot/uv/pyasn1-0.6.5
github-actions[bot] Oct 30, 2026
f5d3bb1
Bump the patch-and-minor group with 4 updates
dependabot[bot] Nov 3, 2026
ea9f3af
Merge pull request #77 from pyobs/dependabot/uv/develop/patch-and-min…
github-actions[bot] Nov 3, 2026
2383d11
Bump the patch-and-minor group with 3 updates
dependabot[bot] Nov 10, 2026
5193cc4
Bump pytest-asyncio from 1.4.1 to 1.4.1.post1
dependabot[bot] Nov 10, 2026
877690b
Merge pull request #79 from pyobs/dependabot/uv/develop/pytest-asynci…
github-actions[bot] Nov 10, 2026
72441bd
Merge pull request #78 from pyobs/dependabot/uv/develop/patch-and-min…
github-actions[bot] Nov 10, 2026
b3ab071
Bump aiohttp from 3.14.3 to 3.14.4
dependabot[bot] Nov 10, 2026
7b51819
Merge pull request #69 from pyobs/dependabot/uv/aiohttp-3.14.4
github-actions[bot] Nov 10, 2026
44a0ba7
Merge pull request #71 from pyobs/dependabot/uv/pillow-13.0.0
thusser Nov 10, 2026
b4a26c6
Merge pull request #73 from pyobs/dependabot/uv/filelock-4.2.1
thusser Nov 10, 2026
0c097b2
ci: run checks on pull requests
thusser Nov 10, 2026
09d48b8
Merge pull request #80 from pyobs/ci/run-on-pull-requests
thusser Nov 10, 2026
7306521
Bump the patch-and-minor group with 3 updates
dependabot[bot] Nov 17, 2026
70532f2
Merge pull request #81 from pyobs/dependabot/uv/develop/patch-and-min…
github-actions[bot] Nov 17, 2026
d233c22
Use the shared frame header in the camera and GUI
thusser Nov 17, 2026
d483e84
Require pyobs-core 2.28.0 for make_frame_header
thusser Nov 17, 2026
80f3b54
Skip the GUI header tests when Qt cannot be loaded
thusser Nov 17, 2026
3797352
v2.2.0
thusser Nov 17, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/pyrefly.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: pyrefly
on: push
on:
push:
branches: [develop, main]
pull_request:

jobs:
pyrefly:
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: PyTest
on: push
on:
push:
branches: [develop, main]
pull_request:

jobs:
test:
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: ruff
on: push
on:
push:
branches: [develop, main]
pull_request:

jobs:
ruff:
Expand Down
13 changes: 11 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

Entries for releases before this file existed were generated from commit subjects.

## [Unreleased]

- The GUI writes a FITS header into the frames it saves (it was empty): exposure time, instrument, gain and data
statistics, no `DATE-OBS` because it only knows when a frame arrived. `AravisCamera` and the GUI build the header cards
with `make_frame_header` from pyobs-core. Needs pyobs-core 2.28.0 (the pin in `pyproject.toml` is still 2.13.1).

## [2.1.2] - 2026-09-29

- Change settings during acquisition without restarting it
- Change settings during acquisition without restarting it (a restart is only the fallback if the camera
rejects the change), since restarting made the IAG VT fibercamera deliver no frames for up to a minute

## [2.1.1] - 2026-09-29

- Stop frames() from hanging forever when the reader thread fails

## [2.1.0] - 2026-09-29

- Migrate AravisCamera to BaseVideo.frames()
- Migrate AravisCamera to BaseVideo.frames(). Breaking for subclasses: `_capture()` and `_wait_for_frame()`
are gone, and a subclass overriding `_capture()` no longer gets its loop run (an error is logged in
`__init__`). Override `frames()` and wrap `super().frames()` instead. Needs pyobs-core>=2.13.
- specs: plan for migrating AravisCamera to BaseVideo.frames()
- Stop _wait_for_frame from leaking a polling thread on every timeout (#56)

Expand Down
8 changes: 4 additions & 4 deletions pyobs_aravis/araviscamera.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from pyobs.interfaces import ExposureTimeState, IExposureTime
from pyobs.modules.camera import BaseVideo, Frame
from pyobs.utils.enums import ImageType
from pyobs.utils.frameheader import FrameSettings, make_frame_header

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -93,11 +94,10 @@ async def _finish_image(self, image: Image, broadcast: bool, image_type: ImageTy
"""Add device identity/settings headers, then finish up as usual (BaseVideo has no
per-frame header hook of its own, so this is the earliest point after add_fits_headers()
and before the image is serialized to bytes)."""
image.header["INSTRUME"] = (self._camera_device_name, "Name of instrument")
gain = next((value for key, value in self._settings.items() if key.lower() == "gain"), None)
image.header.update(make_frame_header(FrameSettings(instrument=self._camera_device_name, gain=gain)))
for key, value in self._settings.items():
if key.lower() == "gain":
image.header["GAIN"] = (value, "Gain used for exposure")
elif key.lower() == "triggermode":
if key.lower() == "triggermode":
image.header["TRIGMODE"] = (value, "Trigger mode used for exposure")
return await super()._finish_image(image, broadcast, image_type)

Expand Down
49 changes: 45 additions & 4 deletions pyobs_aravis/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import qasync # type: ignore
from astropy.io import fits
from numpy.typing import NDArray
from pyobs.utils.frameheader import FrameSettings, make_frame_header
from pyobs.utils.gui.camera import DataDisplayWidget, ExposeWidget, ExposureTimeWidget, ListPickerDialog
from PySide6 import QtWidgets # type: ignore[import-untyped]

Expand Down Expand Up @@ -38,11 +39,42 @@ def _wrapper() -> None:
return await future


def make_header(camera: aravis.Camera, device: str, data: NDArray[Any]) -> fits.Header:
"""Builds the FITS header for a frame, reading exposure time and gain from the camera (blocking).

There is no DATE-OBS: the GUI only knows when a frame arrived, not when its exposure started.

Args:
camera: Camera to read the settings from.
device: Device id, used as instrument name.
data: The frame.

Returns:
The header.
"""
gain: float | None
try:
value = camera.get_feature("Gain")
gain = None if value is None else float(value)
except Exception:
# the camera may not have a feature of that name
gain = None
return make_frame_header(
FrameSettings(
exposure_time=camera.get_exposure_time() / 1e6,
instrument=device,
gain=gain,
data=data,
)
)


class MainWindow(QtWidgets.QMainWindow):
def __init__(self, device: str) -> None:
super().__init__()
self.setWindowTitle(f"Aravis Camera — {device}")

self.device = device
self.camera: aravis.Camera | None = None
self._last_frame: NDArray[Any] | None = None
self._preview_task: asyncio.Task[None] | None = None
Expand Down Expand Up @@ -77,6 +109,13 @@ async def _init_camera(self, device: str) -> None:
self.exposure_time.spin_exposure_time.setValue(exposure_time / 1e6)
self._preview_task = asyncio.ensure_future(self._live_preview())

async def _show_frame(self, frame: NDArray[Any]) -> None:
camera = self.camera
if camera is None:
return
header = await _run_blocking(lambda: make_header(camera, self.device, frame))
self.display.set_data(fits.PrimaryHDU(frame, header=header))

@qasync.asyncSlot(float) # type: ignore
async def _exposure_time_changed(self, value: float) -> None:
if self.camera is not None:
Expand All @@ -87,8 +126,9 @@ async def _live_preview(self) -> None:
if self.camera is None:
await asyncio.sleep(0.05)
continue
self._last_frame = await _run_blocking(self.camera.pop_frame)
self.display.set_data(fits.PrimaryHDU(self._last_frame))
frame = await _run_blocking(self.camera.pop_frame)
self._last_frame = frame
await self._show_frame(frame)
await asyncio.sleep(0.05)

@qasync.asyncSlot(int) # type: ignore
Expand All @@ -98,8 +138,9 @@ async def _expose_clicked(self, count: int) -> None:
self.expose.start_exposure(self.exposure_time.value)
for _ in range(count):
self._last_frame = await _run_blocking(self.camera.pop_frame)
if self._last_frame is not None:
self.display.set_data(fits.PrimaryHDU(self._last_frame))
last_frame = self._last_frame
if last_frame is not None:
await self._show_frame(last_frame)
self.expose.set_exposures_left()

def closeEvent(self, event: Any) -> None:
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[project]
name = "pyobs-aravis"
version = "2.1.4"
version = "2.2.0"
description = "pyobs module for Aravis cameras"
authors = [{ name = "Tim-Oliver Husser", email = "thusser@uni-goettingen.de" }]
requires-python = ">=3.11"
license = "MIT"
readme = "README.md"
dependencies = [
"numpy>=2.2.5,<3",
"pyobs-core>=2.13.1,<3",
"pyobs-core>=2.28.0,<3",
]

[project.urls]
Expand All @@ -19,7 +19,7 @@ Issues = "https://github.com/pyobs/pyobs-aravis/issues"

[project.optional-dependencies]
gui = [
"pyobs-core[gui]>=2.13.1,<3",
"pyobs-core[gui]>=2.28.0,<3",
"qasync>=0.28.0",
]

Expand Down
10 changes: 5 additions & 5 deletions specs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ Layout mirrors `pyobs-core`'s `specs/`. Docs that span `pyobs-core` and this rep
## Plans

- [plans/2026-09-29-frames-migration.md](plans/2026-09-29-frames-migration.md):
**proposed, not started**. Move `AravisCamera` from the deprecated `_set_image()` shim to
`BaseVideo.frames()`: one reader thread per activation, acquisition restart plus
settings-generation bump on every image-affecting setting, estimated start times until a
hardware check shows device timestamps are usable. Breaking for subclasses that override
`_capture()`.
**implemented** (released in v2.1.0, refined in v2.1.2). Moved `AravisCamera` from the deprecated
`_set_image()` shim to `BaseVideo.frames()`: one reader thread per activation, settings-generation
bump on every image-affecting setting, estimated start times. Settings are applied while streaming
(restart only as fallback). Breaking for subclasses that override `_capture()`. Phase 0 hardware
checks and device timestamps still open.

## Specs in `pyobs-core` about `pyobs-aravis`

Expand Down
30 changes: 23 additions & 7 deletions specs/plans/2026-09-29-frames-migration.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# AravisCamera: migrate to `BaseVideo.frames()`

Status: Phase 1 implemented (2026-09-29), not released. Phase 0 (hardware) and 2 open.
Status: implemented, released in v2.1.0 (2026-09-29), refined in v2.1.2 (see Deviations). Phase 0
(hardware checks) and Phase 2 (device timestamps) still open.

Needs pyobs-core `>=2.13.0` (`frames()`, `Frame`, `_new_generation()`, PR #926). No pyobs-core
Needs pyobs-core `>=2.13.0` (pinned `>=2.13.1` as of v2.1.4) (`frames()`, `Frame`, `_new_generation()`, PR #926). No pyobs-core
changes.

Related: pyobs-core `specs/design/basevideo-frame-source.md` (the `frames()` contract, step 2 of
Expand All @@ -29,11 +30,26 @@ its migration order), issue #56.

## Prerequisites

- #56 fix in `_wait_for_frame()`/`_run_blocking()` plus tests (done, uncommitted as of
2026-09-29). Worth releasing on its own before this plan.
- #56 fix in `_wait_for_frame()`/`_run_blocking()` plus tests (done, closed). Shipped together with
this migration in v2.1.0 instead of on its own.

## Deviations from this plan (as implemented)

- **Decision 3 was reversed in v2.1.2.** `_apply_settings()` applies the change while acquisition
keeps running and only flushes the queued buffers. It stops/restarts acquisition only if the
camera rejects the change. Reason: restarting made the IAG VT fibercamera deliver no frames for
up to a minute after every exposure time change (e.g. on each acquisition step). The restart
timing check in Phase 0 is therefore moot for that camera.
- **Decision 4 changed accordingly.** The generation is bumped after the setting and the flush,
not inside a restart. The one frame exposing during the change may carry the new generation
although it was exposed (partly) with the old settings, so the old-to-new exposure race from
"Problem" point 2 is narrowed, not closed. Going from a long to a short exposure is the
visible case.

## Design decisions

(As originally planned. Decisions 3 and 4 are superseded, see Deviations.)

1. **One long-lived reader thread per activation, not one per frame.** `frames()` starts a daemon
thread that polls `try_pop_frame()` under `_device_lock` and hands frames to the event loop
via `loop.call_soon_threadsafe()` into a small `asyncio.Queue`. The `finally` of `frames()`
Expand All @@ -59,7 +75,7 @@ its migration order), issue #56.
camera's own clock (ns since power-on or since the last timestamp reset) unless the camera
runs PTP, and the point in the exposure where it's latched is model-dependent (**unverified**).
So `Frame.start=None`, and `exposure_time` is the value **read back** from the camera after
setting it (cameras quantize), not the requested one. Device timestamps are Phase 3, only if
setting it (cameras quantize), not the requested one. Device timestamps are Phase 2, only if
Phase 0 shows they're usable.
6. **Every image-affecting setting bumps the generation.** In `AravisCamera` that's
`set_exposure_time()` and a (re)connect with `settings` applied (bump in `_activate_camera()`).
Expand All @@ -78,7 +94,7 @@ its migration order), issue #56.
cameras. If it's seconds rather than ~100ms, revisit decision 3.
- [ ] Check whether the cameras expose PTP (`arv-tool-0.8 -a <ip> features | grep -i -E
"ptp|1588"`), and compare `buf.get_timestamp()` / `buf.get_system_timestamp()` against host
time over a few minutes (offset, drift). Result decides whether Phase 3 happens.
time over a few minutes (offset, drift). Result decides whether Phase 2 happens.
- [ ] Confirm whether the `ExposureTime` read-back differs from the requested value
(quantization), to know whether decision 5's read-back matters in practice.

Expand Down Expand Up @@ -106,7 +122,7 @@ its migration order), issue #56.
order; `aclose()` stops the reader thread (`threading.active_count()` back to baseline);
`set_exposure_time()` bumps the generation and no frame popped after the bump carries the
old one; read-back value lands in `Frame.exposure_time`; bounded queue drops oldest.
- [ ] Release, coordinated with downstream subclasses (decision 7).
- [x] Release (v2.1.0). Coordination with downstream subclasses (decision 7) is not tracked here.

## Phase 2 (optional, depends on Phase 0): device timestamps

Expand Down
47 changes: 47 additions & 0 deletions tests/test_frameheader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""Tests for the FITS header cards of the module and the GUI."""

from __future__ import annotations

from unittest.mock import AsyncMock, MagicMock

import numpy as np
import pytest
from pyobs.images import Image
from pyobs.modules.camera import BaseVideo
from pyobs.utils.enums import ImageType

from pyobs_aravis import AravisCamera


@pytest.mark.asyncio
async def test_module_header_has_instrument_gain_and_trigger_mode(monkeypatch: pytest.MonkeyPatch) -> None:
# AravisCamera.__init__ imports gi/Aravis, unavailable here
camera = AravisCamera.__new__(AravisCamera)
camera._camera_device_name = "cam0"
camera._settings = {"Gain": 12.0, "TriggerMode": "On"}
monkeypatch.setattr(BaseVideo, "_finish_image", AsyncMock(side_effect=lambda image, *a: (image, "x")))

image, _ = await camera._finish_image(Image(np.zeros((2, 2), dtype=np.uint8)), False, ImageType.OBJECT)

h = image.header
assert h["INSTRUME"] == "cam0" and h["GAIN"] == 12.0 and h["TRIGMODE"] == "On"
assert "XBINNING" not in h


def test_gui_header_has_exposure_time_and_gain() -> None:
gui = pytest.importorskip("pyobs_aravis.gui", exc_type=ImportError)
camera = MagicMock()
camera.get_exposure_time.return_value = 20000.0
camera.get_feature.return_value = 4.0
h = gui.make_header(camera, "cam0", np.array([[1, 2], [3, 6]], dtype=np.uint8))
assert h["EXPTIME"] == 0.02 and h["GAIN"] == 4.0 and h["INSTRUME"] == "cam0"
assert "DATE-OBS" not in h and h["DATAMAX"] == 6.0


def test_gui_header_without_gain_feature() -> None:
gui = pytest.importorskip("pyobs_aravis.gui", exc_type=ImportError)
camera = MagicMock()
camera.get_exposure_time.return_value = 20000.0
camera.get_feature.side_effect = KeyError("Gain")
h = gui.make_header(camera, "cam0", np.zeros((2, 2), dtype=np.uint8))
assert "GAIN" not in h
Loading
Loading