diff --git a/finesse/gui/temp_control.py b/finesse/gui/temp_control.py index cf725b66..b6ff4200 100644 --- a/finesse/gui/temp_control.py +++ b/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 @@ -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. @@ -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) @@ -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: @@ -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: diff --git a/finesse/hardware/__init__.py b/finesse/hardware/__init__.py index 8f0b1a36..937dd746 100644 --- a/finesse/hardware/__init__.py +++ b/finesse/hardware/__init__.py @@ -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 @@ -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. diff --git a/finesse/hardware/plugins/temperature/dp9800.py b/finesse/hardware/plugins/temperature/dp9800.py index 0ee0a1fd..a74b4dc1 100644 --- a/finesse/hardware/plugins/temperature/dp9800.py +++ b/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 @@ -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() diff --git a/finesse/hardware/plugins/temperature/dummy_temperature_monitor.py b/finesse/hardware/plugins/temperature/dummy_temperature_monitor.py index d3cb7611..dccfa947 100644 --- a/finesse/hardware/plugins/temperature/dummy_temperature_monitor.py +++ b/finesse/hardware/plugins/temperature/dummy_temperature_monitor.py @@ -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] diff --git a/finesse/hardware/plugins/temperature/senecak107.py b/finesse/hardware/plugins/temperature/senecak107.py index 640f05cb..f4763910 100644 --- a/finesse/hardware/plugins/temperature/senecak107.py +++ b/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 @@ -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 @@ -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. @@ -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 diff --git a/finesse/hardware/plugins/temperature/temperature_monitor_base.py b/finesse/hardware/plugins/temperature/temperature_monitor_base.py index fef31b39..f99b2c1b 100644 --- a/finesse/hardware/plugins/temperature/temperature_monitor_base.py +++ b/finesse/hardware/plugins/temperature/temperature_monitor_base.py @@ -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 @@ -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."""