From 315a58250eb446b528160389d401009e97332f4a Mon Sep 17 00:00:00 2001 From: Tim-Oliver Husser Date: Tue, 17 Nov 2026 10:05:59 +0100 Subject: [PATCH 1/4] Require pyobs-core 2.28.0 for the estimated cooling close timeout Co-Authored-By: Claude Sonnet 5.5 --- CHANGELOG.md | 1 + pyproject.toml | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 71c3146..8c7d69a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ Entries for releases before this file existed were generated from commit subject ## [Unreleased] +- Closing the camera warms up first (pyobs-core `CoolingRampMixin`). The time limit `cooling_close_timeout` is now estimated from the current setpoint and `cooling_rate_warm` instead of a fixed 300 s, so a deeply cooled camera is warmed up completely before it is closed. Needs pyobs-core 2.28.0. - Switching cooling off sets the camera to the off temperature (20 degC by default) or, if the sensor is warmer than that, to just above the sensor, so that the cooler does not keep cooling below ambient. A setpoint below the off temperature counts as cooler on, also after a restart of the module, so that switching it off warms up first. diff --git a/pyproject.toml b/pyproject.toml index a8b52a0..8c1dce5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,7 +9,7 @@ readme = "README.md" dependencies = [ "astropy>=7.0.1,<8", "numpy>=2.2.5,<3", - "pyobs-core>=2.27.0,<3", + "pyobs-core>=2.28.0,<3", ] [project.urls] @@ -20,7 +20,7 @@ Issues = "https://github.com/pyobs/pyobs-flipro/issues" [project.optional-dependencies] gui = [ - "pyobs-core[gui]>=2.24.0,<3", + "pyobs-core[gui]>=2.28.0,<3", "qasync>=0.27", ] From 79fd2c36d0ffa021f7fe35e8e277fd8c19c4461f Mon Sep 17 00:00:00 2001 From: Tim-Oliver Husser Date: Tue, 17 Nov 2026 10:38:42 +0100 Subject: [PATCH 2/4] Use the shared frame header in the camera and GUI The GUI saved frames with an empty header. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 3 +++ pyobs_flipro/fliprocamera.py | 40 +++++++++++++---------------- pyobs_flipro/gui.py | 49 +++++++++++++++++++++++++++++++++++- tests/test_guiheader.py | 43 +++++++++++++++++++++++++++++++ 4 files changed, 111 insertions(+), 24 deletions(-) create mode 100644 tests/test_guiheader.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c7d69a..bc5b26e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,9 @@ Entries for releases before this file existed were generated from commit subject ## [Unreleased] +- The GUI writes a FITS header into the frames it saves (it was empty). `FliProCamera` and the GUI build the header + cards with `make_frame_header` from pyobs-core, so key names and comments are the same everywhere. Needs pyobs-core + 2.28.0. - Closing the camera warms up first (pyobs-core `CoolingRampMixin`). The time limit `cooling_close_timeout` is now estimated from the current setpoint and `cooling_rate_warm` instead of a fixed 300 s, so a deeply cooled camera is warmed up completely before it is closed. Needs pyobs-core 2.28.0. - Switching cooling off sets the camera to the off temperature (20 degC by default) or, if the sensor is warmer than that, to just above the sensor, so that the cooler does not keep cooling below ambient. A setpoint below the off diff --git a/pyobs_flipro/fliprocamera.py b/pyobs_flipro/fliprocamera.py index 4e14d1d..f05b863 100644 --- a/pyobs_flipro/fliprocamera.py +++ b/pyobs_flipro/fliprocamera.py @@ -9,7 +9,6 @@ from datetime import UTC, datetime from typing import TYPE_CHECKING, Any, TypeVar, cast -import numpy as np from pyobs.images import Image from pyobs.interfaces import IAbortable, IBinning, ICamera, ICooling, ITemperatures, IWindow from pyobs.interfaces.IBinning import Binning, BinningCapabilities, BinningState @@ -18,6 +17,7 @@ from pyobs.mixins import CoolingRampMixin from pyobs.modules.camera.basecamera import BaseCamera from pyobs.utils.enums import ExposureStatus +from pyobs.utils.frameheader import FrameSettings, make_frame_header if TYPE_CHECKING: from .fliprodriver import DeviceCaps, DeviceInfo, FliProDriver @@ -334,29 +334,23 @@ def _readout() -> tuple[Any, float, float, float, float]: # create FITS image and set header image = Image(img) - image.header["DATE-OBS"] = (date_obs, "Date and time of start of exposure") - image.header["EXPTIME"] = (exposure_time, "Exposure time [s]") - image.header["DET-TEMP"] = (temp, "CCD temperature [C]") - image.header["DET-TBAS"] = (temp_base, "Base plate temperature [C]") - image.header["DET-COOL"] = (cooler_duty, "Cooler power [percent]") - image.header["DET-TSET"] = (temp_set, "Cooler setpoint [C]") - - # instrument and detector dev = driver.device - image.header["INSTRUME"] = (f"{dev.friendly_name} {dev.serial_number}", "Name of instrument") - - # binning - image.header["XBINNING"] = image.header["DET-BIN1"] = (self._binning[0], "Binning factor used on X axis") - image.header["YBINNING"] = image.header["DET-BIN2"] = (self._binning[1], "Binning factor used on Y axis") - - # window - image.header["XORGSUBF"] = (self._window[0], "Subframe origin on X axis") - image.header["YORGSUBF"] = (self._window[1], "Subframe origin on Y axis") - - # statistics - image.header["DATAMIN"] = (float(np.min(img)), "Minimum data value") - image.header["DATAMAX"] = (float(np.max(img)), "Maximum data value") - image.header["DATAMEAN"] = (float(np.mean(img)), "Mean data value") + image.header.update( + make_frame_header( + FrameSettings( + date_obs=date_obs, + exposure_time=exposure_time, + instrument=f"{dev.friendly_name} {dev.serial_number}", + binning=self._binning, + window=self._window, + temperature=temp, + base_temperature=temp_base, + cooler_power=cooler_duty, + setpoint=temp_set, + data=img, + ) + ) + ) # biassec/trimsec self.set_biassec_trimsec(image.header, *self._full_frame) diff --git a/pyobs_flipro/gui.py b/pyobs_flipro/gui.py index b8bfd8e..33602f3 100644 --- a/pyobs_flipro/gui.py +++ b/pyobs_flipro/gui.py @@ -1,9 +1,13 @@ import asyncio import sys import time +from datetime import UTC, datetime +from typing import Any import qasync # type: ignore[import-untyped] 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 BinningWidget, DataDisplayWidget, ExposeWidget, ExposureTimeWidget, ListPickerDialog from pyobs.utils.gui.camera.windowingwidget import WindowingWidget from PySide6 import QtCore, QtWidgets # type: ignore[import-untyped] @@ -11,6 +15,45 @@ from .fliprodriver import FliProDriver # type: ignore[import-untyped] +def make_header( + driver: FliProDriver, + date_obs: datetime, + exposure_time: float, + window: tuple[int, int, int, int], + binning: tuple[int, int], + data: NDArray[Any], +) -> fits.Header: + """Builds the FITS header for a frame, reading temperatures and cooling from the camera (blocking). + + Args: + driver: Camera to read the settings from. + date_obs: UTC time the exposure was started. + exposure_time: Exposure time in seconds. + window: Left, top, width and height of the window, as passed to the camera. + binning: Binning in x and y. + data: The frame. + + Returns: + The header. + """ + dev = driver.device + _, temp_base, _ = driver.get_temperatures() + return make_frame_header( + FrameSettings( + date_obs=date_obs, + exposure_time=exposure_time, + instrument=f"{dev.friendly_name} {dev.serial_number}", + binning=binning, + window=window, + temperature=driver.get_sensor_temperature(), + base_temperature=temp_base, + cooler_power=driver.get_cooler_duty_cycle(), + setpoint=driver.get_temperature_set_point(), + data=data, + ) + ) + + class MainWindow(QtWidgets.QMainWindow): def __init__(self, device_info) -> None: super().__init__() @@ -98,13 +141,17 @@ async def _expose_clicked(self, count: int) -> None: break self._expose_widget.start_exposure(self._exposure_time.value) + date_obs = datetime.now(UTC) self._driver.start_exposure() await loop.run_in_executor(None, self._wait_for_frame) data = self._driver.read_exposure(frame_size) self._driver.stop_exposure() + header = make_header( + self._driver, date_obs, self._exposure_time.value, (x, y, width, height), (xbin, ybin), data + ) self._expose_widget.set_exposures_left(count - i - 1) - self._data_display.set_data(fits.PrimaryHDU(data)) + self._data_display.set_data(fits.PrimaryHDU(data, header=header)) self._refresh_temp() self._abort_event.clear() diff --git a/tests/test_guiheader.py b/tests/test_guiheader.py new file mode 100644 index 0000000..ec9f3e1 --- /dev/null +++ b/tests/test_guiheader.py @@ -0,0 +1,43 @@ +"""Tests for the FITS header the GUI writes.""" + +from __future__ import annotations + +from datetime import UTC, datetime +from types import SimpleNamespace + +import numpy as np +import pytest + +try: + from pyobs_flipro.gui import make_header +except ImportError as e: # no Qt extras, or the camera library is not installed + pytest.skip(f"GUI cannot be imported: {e}", allow_module_level=True) + + +class FakeDriver: + device = SimpleNamespace(friendly_name="ProLine", serial_number="PL123") + + def get_temperatures(self) -> tuple[float, float, float]: + return -9.5, 21.0, -9.4 + + def get_sensor_temperature(self) -> float: + return -9.5 + + def get_cooler_duty_cycle(self) -> float: + return 50.0 + + def get_temperature_set_point(self) -> float: + return -10.0 + + +DATE = datetime(2026, 11, 17, 10, 0, 0, tzinfo=UTC) +DATA = np.array([[1, 2], [3, 6]], dtype=np.uint16) + + +def test_header_has_the_module_keys() -> None: + h = make_header(FakeDriver(), DATE, 5.0, (10, 20, 100, 100), (2, 2), DATA) # type: ignore[arg-type] + assert h["EXPTIME"] == 5.0 and h["DATE-OBS"] == "2026-11-17T10:00:00.000000" + assert h["INSTRUME"] == "ProLine PL123" + assert h["DET-TEMP"] == -9.5 and h["DET-TBAS"] == 21.0 and h["DET-COOL"] == 50.0 and h["DET-TSET"] == -10.0 + assert h["DET-BIN1"] == 2 and h["XORGSUBF"] == 10 and h["YORGSUBF"] == 20 + assert (h["DATAMIN"], h["DATAMAX"], h["DATAMEAN"]) == (1.0, 6.0, 3.0) From ad155ada92ccefb0b7c9c08fcdd599d47945523a Mon Sep 17 00:00:00 2001 From: Tim-Oliver Husser Date: Tue, 17 Nov 2026 11:06:07 +0100 Subject: [PATCH 3/4] Lock pyobs-core 2.28.0 Co-Authored-By: Claude Opus 5.5 --- uv.lock | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/uv.lock b/uv.lock index 5c6422c..4473e0b 100644 --- a/uv.lock +++ b/uv.lock @@ -1947,7 +1947,7 @@ wheels = [ [[package]] name = "pyobs-core" -version = "2.27.0" +version = "2.28.0" source = { registry = "https://pypi.org/simple" } dependencies = [ { name = "aiohttp" }, @@ -1967,9 +1967,9 @@ dependencies = [ { name = "slixmpp" }, { name = "typing-extensions" }, ] -sdist = { url = "https://files.pythonhosted.org/packages/a3/c6/10f5e83e180d1dc0627493fff430ff5ee406527f55d67a4a3911d6a48fad/pyobs_core-2.27.0.tar.gz", hash = "sha256:3f652837e6e2ce9ff53ed63bf3242f7f7a0e07d2ec8e21bd3c33c93138bea88b", size = 469346, upload-time = "2026-11-16T09:48:23.457Z" } +sdist = { url = "https://files.pythonhosted.org/packages/e5/f1/55308532957cdcb0edd7a0f5e183fcd2730f9bb409e5b9d016b55408f086/pyobs_core-2.28.0.tar.gz", hash = "sha256:8fba546096aff8f6a9dd71b6dafb57968615bdefea067003270d6283956a085f", size = 471156, upload-time = "2026-11-17T10:02:58.25Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/a0/cd/7274a7cce5ff4a4ac2b16c438454e15ea0fef91787294ccb2908b53fcf1f/pyobs_core-2.27.0-py3-none-any.whl", hash = "sha256:a2b16e3a57d1636912b4756c01a99a4e1402d11f6b632213cb53965247e8377a", size = 712357, upload-time = "2026-11-16T09:48:21.873Z" }, + { url = "https://files.pythonhosted.org/packages/1e/9c/7625e223f38047fbf565247abafc725971c1635c0ecc6a3dac08b08e3bc9/pyobs_core-2.28.0-py3-none-any.whl", hash = "sha256:3b83b416b47f7844b78b335947c92939acade66ed0771595a758aa9d03d2bc97", size = 714500, upload-time = "2026-11-17T10:02:56.508Z" }, ] [package.optional-dependencies] @@ -2010,8 +2010,8 @@ dev = [ requires-dist = [ { name = "astropy", specifier = ">=7.0.1,<8" }, { name = "numpy", specifier = ">=2.2.5,<3" }, - { name = "pyobs-core", specifier = ">=2.27.0,<3" }, - { name = "pyobs-core", extras = ["gui"], marker = "extra == 'gui'", specifier = ">=2.24.0,<3" }, + { name = "pyobs-core", specifier = ">=2.28.0,<3" }, + { name = "pyobs-core", extras = ["gui"], marker = "extra == 'gui'", specifier = ">=2.28.0,<3" }, { name = "qasync", marker = "extra == 'gui'", specifier = ">=0.27" }, ] provides-extras = ["gui"] From 902c867e5ade97a7b8874d0509f5669170d04469 Mon Sep 17 00:00:00 2001 From: Tim-Oliver Husser Date: Tue, 17 Nov 2026 11:11:02 +0100 Subject: [PATCH 4/4] v2.2.0 --- pyproject.toml | 2 +- uv.lock | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 8c1dce5..f9f73e9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "pyobs-flipro" -version = "2.1.1" +version = "2.2.0" description = "pyobs module for FLIPRO cameras" authors = [{ name = "Tim-Oliver Husser", email = "thusser@uni-goettingen.de" }] requires-python = ">=3.11" diff --git a/uv.lock b/uv.lock index 4473e0b..f7e36e4 100644 --- a/uv.lock +++ b/uv.lock @@ -1981,7 +1981,7 @@ gui = [ [[package]] name = "pyobs-flipro" -version = "2.1.1" +version = "2.2.0" source = { editable = "." } dependencies = [ { name = "astropy" },