Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TemperatureSequence alias for temperature monitors #416

Merged
merged 13 commits into from Nov 16, 2023
13 changes: 7 additions & 6 deletions finesse/gui/temp_control.py
@@ -1,4 +1,5 @@
"""Panel and widgets related to temperature monitoring."""
from collections.abc import Sequence
from datetime import datetime
from decimal import Decimal
from functools import partial
Expand Down Expand Up @@ -128,7 +129,7 @@ def _toggle_axis_visibility(self, name: str) -> None:
self._canvas.draw()

def _update_figure(
self, new_time: float, new_hot_data: Decimal, new_cold_data: Decimal
self, new_time: float, new_hot_data: float, new_cold_data: float
) -> None:
"""Updates the matplotlib figure to be contained within the panel.

Expand Down Expand Up @@ -178,15 +179,15 @@ def _make_axes_sensible(self) -> None:
self._ax["hot"].autoscale()
self._ax["cold"].autoscale()

def _plot_bb_temps(self, time: datetime, temperatures: list[Decimal]) -> None:
def _plot_bb_temps(self, time: datetime, temperatures: Sequence) -> None:
"""Extract blackbody temperatures from DP9800 data and plot them.

Args:
time: the time that the temperatures were read
temperatures: the list of temperatures measured by the DP9800
"""
hot_bb_temp = temperatures[TEMPERATURE_MONITOR_HOT_BB_IDX]
cold_bb_temp = temperatures[TEMPERATURE_MONITOR_COLD_BB_IDX]
hot_bb_temp = float(temperatures[TEMPERATURE_MONITOR_HOT_BB_IDX])
cold_bb_temp = float(temperatures[TEMPERATURE_MONITOR_COLD_BB_IDX])

self._update_figure(time.timestamp(), hot_bb_temp, cold_bb_temp)

Expand Down Expand Up @@ -263,7 +264,7 @@ def _poll_dp9800(self) -> None:
self._poll_light.flash()
pub.sendMessage(f"device.{TEMPERATURE_MONITOR_TOPIC}.data.request")

def _update_pt100s(self, temperatures: list[Decimal], time: datetime) -> None:
def _update_pt100s(self, temperatures: Sequence, time: datetime) -> None:
"""Display the latest Pt 100 temperatures.

Args:
Expand Down Expand Up @@ -431,7 +432,7 @@ def _update_controls(self, properties: dict):
elif self._alarm_light._is_on:
self._alarm_light._turn_off()

def _update_pt100(self, temperatures: list[Decimal], time: datetime):
def _update_pt100(self, temperatures: Sequence, time: datetime):
"""Show the latest blackbody temperature.

Args:
Expand Down
3 changes: 2 additions & 1 deletion finesse/hardware/__init__.py
Expand Up @@ -13,6 +13,7 @@
OPUSInterface,
)

from collections.abc import Sequence
from datetime import datetime

from finesse.config import NUM_TEMPERATURE_MONITOR_CHANNELS, TEMPERATURE_MONITOR_TOPIC
Expand All @@ -28,7 +29,7 @@ def _broadcast_device_types() -> None:
pub.sendMessage("device.list", device_types=get_device_types())


def _try_get_temperatures() -> list[Decimal] | None:
def _try_get_temperatures() -> Sequence | None:
"""Try to read the current temperatures from the temperature monitor.

If the device is not connected or the operation fails, None is returned.
Expand Down
3 changes: 2 additions & 1 deletion finesse/hardware/plugins/temperature/dp9800.py
@@ -1,4 +1,5 @@
"""This module provides an interface to DP9800 temperature readers."""
from collections.abc import Sequence
from decimal import Decimal
from typing import Any

Expand Down Expand Up @@ -194,7 +195,7 @@ def request_read(self) -> None:
except Exception as e:
raise DP9800Error(e)

def get_temperatures(self) -> list[Decimal]:
def get_temperatures(self) -> Sequence:
"""Get the current temperatures."""
self.request_read()
data = self.read_temperature_data()
Expand Down
Expand Up @@ -44,6 +44,6 @@ def __init__(
def close(self) -> None:
"""Close the connection to the device."""

def get_temperatures(self) -> list[Decimal]:
def get_temperatures(self) -> Sequence:
"""Get current temperatures."""
return [producer() for producer in self._temperature_producers]
10 changes: 5 additions & 5 deletions finesse/hardware/plugins/temperature/senecak107.py
@@ -1,5 +1,5 @@
"""This module provides an interface to Seneca temperature readers."""
from decimal import Decimal
from collections.abc import Sequence
from typing import Any

import numpy
Expand Down Expand Up @@ -105,7 +105,7 @@ def request_read(self) -> None:
except Exception as e:
raise SenecaK107Error(e)

def parse_data(self, data: bytes) -> list[Decimal]:
def parse_data(self, data: bytes) -> numpy.ndarray:
"""Parse temperature data read from the SenecaK107.

The sequence of bytes is put through the conversion function and translated
Expand All @@ -124,7 +124,7 @@ def parse_data(self, data: bytes) -> list[Decimal]:
ints = numpy.frombuffer(data, dt, 8, 3)

vals = self.calc_temp(ints)
return [Decimal(val) for val in vals]
return vals

def calc_temp(self, vals: numpy.ndarray) -> numpy.ndarray:
"""Convert data read from the SenecaK107 device into temperatures.
Expand All @@ -145,8 +145,8 @@ def calc_temp(self, vals: numpy.ndarray) -> numpy.ndarray:
vals += self.MIN_TEMP
return vals

def get_temperatures(self) -> list[Decimal]:
def get_temperatures(self) -> Sequence:
"""Get the current temperatures."""
self.request_read()
data = self.read()
return self.parse_data(data)
return self.parse_data(data) # type: ignore
@@ -1,6 +1,6 @@
"""Provides a base class for temperature monitor devices or mock devices."""
from abc import abstractmethod
from decimal import Decimal
from collections.abc import Sequence

from finesse.config import TEMPERATURE_MONITOR_TOPIC
from finesse.hardware.device import Device
Expand All @@ -15,5 +15,5 @@ class TemperatureMonitorBase(
"""The base class for temperature monitor devices or mock devices."""

@abstractmethod
def get_temperatures(self) -> list[Decimal]:
def get_temperatures(self) -> Sequence:
"""Get the current temperatures."""