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 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
temperature counts as cooler on, also after a restart of the module, so that switching it off warms up first.
Expand Down
40 changes: 17 additions & 23 deletions pyobs_flipro/fliprocamera.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
49 changes: 48 additions & 1 deletion pyobs_flipro/gui.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,59 @@
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]

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__()
Expand Down Expand Up @@ -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()
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-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"
Expand All @@ -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]
Expand All @@ -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",
]

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