Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 17 additions & 14 deletions pyobs_fli/flicamera.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
52 changes: 48 additions & 4 deletions pyobs_fli/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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__()
Expand Down Expand Up @@ -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():
Expand All @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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]
Expand All @@ -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",
]

Expand Down
36 changes: 36 additions & 0 deletions tests/test_guiheader.py
Original file line number Diff line number Diff line change
@@ -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)
12 changes: 6 additions & 6 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading