diff --git a/CHANGELOG.md b/CHANGELOG.md index 71c7c09..d3cb1b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ Entries for releases before this file existed were generated from commit subject ## [Unreleased] +- The GUI writes the same FITS header as the module (it only had `EXPTIME` and the binning): date, instrument, binning, + window origin, temperatures, cooler power and data statistics. `FliCamera` and the GUI build the header cards with + `make_frame_header` from pyobs-core. 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. After a restart of the module the cooler is assumed to be on until something was written, so that switching it off warms up from the diff --git a/pyobs_fli/flicamera.py b/pyobs_fli/flicamera.py index 60c7093..349fc16 100644 --- a/pyobs_fli/flicamera.py +++ b/pyobs_fli/flicamera.py @@ -15,6 +15,7 @@ from pyobs.modules.camera.basecamera import BaseCamera from pyobs.utils import exceptions as exc from pyobs.utils.enums import ExposureStatus +from pyobs.utils.frameheader import FrameSettings, make_frame_header from .flibase import FliBaseMixin from .flidriver import DeviceType @@ -187,21 +188,23 @@ def _get_headers() -> tuple[float, float, float, tuple[int, int, int, int]]: ccd_temp, base_temp, cooler_power, visible_frame = await self._run_blocking_or_raise(_get_headers) image = Image(img) # type: ignore[arg-type] - 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"] = (ccd_temp, "CCD temperature [C]") - image.header["DET-TBAS"] = (base_temp, "Base plate temperature [C]") - image.header["DET-COOL"] = (cooler_power, "Cooler power [percent]") - image.header["DET-TSET"] = (self._commanded_setpoint(), "Cooler setpoint [C]") - image.header["INSTRUME"] = (self._driver.name, "Name of instrument") + image.header.update( + make_frame_header( + FrameSettings( + date_obs=date_obs, + exposure_time=exposure_time, + instrument=self._driver.name, + binning=self._binning, + window=self._window, + temperature=ccd_temp, + base_temperature=base_temp, + cooler_power=cooler_power, + setpoint=self._commanded_setpoint(), + data=img, + ) + ) + ) image.header["DET-ID"] = (self._serial, "Camera serial number") - 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") - image.header["XORGSUBF"] = (self._window[0], "Subframe origin on X axis") - image.header["YORGSUBF"] = (self._window[1], "Subframe origin on Y axis") - 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") self.set_biassec_trimsec(image.header, *visible_frame) diff --git a/pyobs_fli/gui.py b/pyobs_fli/gui.py index e2a0a85..0ac92a9 100644 --- a/pyobs_fli/gui.py +++ b/pyobs_fli/gui.py @@ -8,11 +8,15 @@ import sys import threading import time +from datetime import UTC, datetime +from typing import Any import numpy as np import qasync # type: ignore[import-untyped] from astropy.io import fits +from numpy.typing import NDArray from pyobs.utils.enums import ImageFormat +from pyobs.utils.frameheader import FrameSettings, make_frame_header from pyobs.utils.gui.camera import ( BinningWidget, DataDisplayWidget, @@ -27,6 +31,43 @@ from .flidriver import FliDriver, FliTemperature # type: ignore[import-untyped] +def make_header( + driver: FliDriver, + 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 cooler power 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 in binned pixels, as the window widget gives them. + binning: Binning in x and y. + data: The frame. + + Returns: + The header. + """ + return make_frame_header( + FrameSettings( + date_obs=date_obs, + exposure_time=exposure_time, + instrument=driver.name, + binning=binning, + # the window start is in unbinned pixels, like in the module + window=(window[0] * binning[0], window[1] * binning[1], window[2] * binning[0], window[3] * binning[1]), + temperature=driver.get_temp(FliTemperature.CCD), + base_temperature=driver.get_temp(FliTemperature.BASE), + cooler_power=driver.get_cooler_power(), + data=data, + ) + ) + + class MainWindow(QtWidgets.QMainWindow): def __init__(self, driver: FliDriver, binning, full_frame) -> None: super().__init__() @@ -143,6 +184,7 @@ def _readout() -> np.ndarray: self._expose_widget.start_exposure(exposure_time) await self._run_blocking(_prepare) + date_obs = datetime.now(UTC) await self._run_blocking(self._driver.start_exposure) if await self._wait_exposure(): @@ -151,10 +193,12 @@ def _readout() -> np.ndarray: data = await self._run_blocking(_readout) - image = fits.PrimaryHDU(data) - image.header["EXPTIME"] = (exposure_time, "Exposure time [s]") - image.header["XBINNING"] = (xbin, "Binning factor used on X axis") - image.header["YBINNING"] = (ybin, "Binning factor used on Y axis") + header = await self._run_blocking( + lambda: make_header( + self._driver, date_obs, exposure_time, (left, top, width, height), (xbin, ybin), data + ) + ) + image = fits.PrimaryHDU(data, header=header) self._data_display.set_data(image) self._expose_widget.set_exposures_left(count - i - 1) diff --git a/pyproject.toml b/pyproject.toml index 1eba737..dca032e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "pyobs-fli" -version = "2.1.1" +version = "2.2.0" description = "pyobs module for FLI cameras" authors = [{ name = "Tim-Oliver Husser", email = "thusser@uni-goettingen.de" }] requires-python = ">=3.11" @@ -9,7 +9,7 @@ readme = "README.md" dependencies = [ "astropy>=7.0.1,<9", "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-fli/issues" [project.optional-dependencies] gui = [ - "pyobs-core[gui]>=2.24.0,<3", + "pyobs-core[gui]>=2.28.0,<3", "qasync>=0.27", ] diff --git a/tests/test_guiheader.py b/tests/test_guiheader.py new file mode 100644 index 0000000..3daa085 --- /dev/null +++ b/tests/test_guiheader.py @@ -0,0 +1,36 @@ +"""Tests for the FITS header the GUI writes.""" + +from __future__ import annotations + +from datetime import UTC, datetime + +import numpy as np +import pytest + +try: + from pyobs_fli.gui import FliTemperature, 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: + name = "FLI ProLine" + + def get_temp(self, which: FliTemperature) -> float: + return {FliTemperature.CCD: -9.5, FliTemperature.BASE: 21.0}[which] + + def get_cooler_power(self) -> float: + return 50.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"] == "FLI ProLine" + assert h["DET-TEMP"] == -9.5 and h["DET-TBAS"] == 21.0 and h["DET-COOL"] == 50.0 and "DET-TSET" not in h + assert h["DET-BIN1"] == 2 and h["XORGSUBF"] == 20 and h["YORGSUBF"] == 40 + assert (h["DATAMIN"], h["DATAMAX"], h["DATAMEAN"]) == (1.0, 6.0, 3.0) diff --git a/uv.lock b/uv.lock index 9d7b133..fdded59 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] @@ -1981,7 +1981,7 @@ gui = [ [[package]] name = "pyobs-fli" -version = "2.1.1" +version = "2.2.0" source = { editable = "." } dependencies = [ { name = "astropy" }, @@ -2010,8 +2010,8 @@ dev = [ requires-dist = [ { name = "astropy", specifier = ">=7.0.1,<9" }, { 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"]