From 41c61925994a5ab33a8eb4627651e34ccb6a78ff Mon Sep 17 00:00:00 2001 From: CWestICL Date: Wed, 15 Nov 2023 10:35:03 +0000 Subject: [PATCH 01/10] Added TemperatureSequence alias --- finesse/hardware/plugins/temperature/dp9800.py | 4 ++-- finesse/hardware/plugins/temperature/senecak107.py | 6 +++--- .../plugins/temperature/temperature_monitor_base.py | 6 +++++- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/finesse/hardware/plugins/temperature/dp9800.py b/finesse/hardware/plugins/temperature/dp9800.py index cf36c677..83584a95 100644 --- a/finesse/hardware/plugins/temperature/dp9800.py +++ b/finesse/hardware/plugins/temperature/dp9800.py @@ -6,7 +6,7 @@ from finesse.hardware.serial_device import SerialDevice -from .temperature_monitor_base import TemperatureMonitorBase +from .temperature_monitor_base import TemperatureMonitorBase, TemperatureSequence def check_data(data: bytes) -> None: @@ -193,7 +193,7 @@ def request_read(self) -> None: except Exception as e: raise DP9800Error(e) - def get_temperatures(self) -> list[Decimal]: + def get_temperatures(self) -> TemperatureSequence: """Get the current temperatures.""" self.request_read() data = self.read_temperature_data() diff --git a/finesse/hardware/plugins/temperature/senecak107.py b/finesse/hardware/plugins/temperature/senecak107.py index b570e10c..0e54d541 100644 --- a/finesse/hardware/plugins/temperature/senecak107.py +++ b/finesse/hardware/plugins/temperature/senecak107.py @@ -13,7 +13,7 @@ ) from finesse.hardware.serial_device import SerialDevice -from .temperature_monitor_base import TemperatureMonitorBase +from .temperature_monitor_base import TemperatureMonitorBase, TemperatureSequence class SenecaK107Error(Exception): @@ -123,7 +123,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. @@ -144,7 +144,7 @@ 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) -> TemperatureSequence: """Get the current temperatures.""" self.request_read() data = self.read() diff --git a/finesse/hardware/plugins/temperature/temperature_monitor_base.py b/finesse/hardware/plugins/temperature/temperature_monitor_base.py index fef31b39..9b076b01 100644 --- a/finesse/hardware/plugins/temperature/temperature_monitor_base.py +++ b/finesse/hardware/plugins/temperature/temperature_monitor_base.py @@ -2,9 +2,13 @@ from abc import abstractmethod from decimal import Decimal +import numpy + from finesse.config import TEMPERATURE_MONITOR_TOPIC from finesse.hardware.device import Device +TemperatureSequence = list[Decimal | numpy.float64] + class TemperatureMonitorBase( Device, @@ -15,5 +19,5 @@ class TemperatureMonitorBase( """The base class for temperature monitor devices or mock devices.""" @abstractmethod - def get_temperatures(self) -> list[Decimal]: + def get_temperatures(self) -> TemperatureSequence: """Get the current temperatures.""" From 35a9f22b77efe2a64874c28c9a70e368f28fb084 Mon Sep 17 00:00:00 2001 From: CWestICL Date: Wed, 15 Nov 2023 10:56:53 +0000 Subject: [PATCH 02/10] Updated hardware __init__ --- finesse/hardware/__init__.py | 3 ++- .../hardware/plugins/temperature/temperature_monitor_base.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/finesse/hardware/__init__.py b/finesse/hardware/__init__.py index e7749e27..67f83714 100644 --- a/finesse/hardware/__init__.py +++ b/finesse/hardware/__init__.py @@ -16,6 +16,7 @@ from . import data_file_writer # noqa: F401 from .device import get_device_types from .plugins.temperature import get_temperature_monitor_instance +from .plugins.temperature.temperature_monitor_base import TemperatureSequence _opus: OPUSInterface @@ -25,7 +26,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() -> TemperatureSequence | 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/temperature_monitor_base.py b/finesse/hardware/plugins/temperature/temperature_monitor_base.py index 9b076b01..b72fb742 100644 --- a/finesse/hardware/plugins/temperature/temperature_monitor_base.py +++ b/finesse/hardware/plugins/temperature/temperature_monitor_base.py @@ -1,5 +1,6 @@ """Provides a base class for temperature monitor devices or mock devices.""" from abc import abstractmethod +from collections.abc import Sequence from decimal import Decimal import numpy @@ -7,7 +8,7 @@ from finesse.config import TEMPERATURE_MONITOR_TOPIC from finesse.hardware.device import Device -TemperatureSequence = list[Decimal | numpy.float64] +TemperatureSequence = Sequence[Decimal | numpy.float64] class TemperatureMonitorBase( From 437b371cd6341f6acef0ee52ca7ee990f07025ac Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 15 Nov 2023 11:24:09 +0000 Subject: [PATCH 03/10] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- finesse/hardware/__init__.py | 4 ++-- finesse/hardware/plugins/temperature/dp9800.py | 2 +- finesse/hardware/plugins/temperature/senecak107.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/finesse/hardware/__init__.py b/finesse/hardware/__init__.py index ddc7d4cc..19c3a570 100644 --- a/finesse/hardware/__init__.py +++ b/finesse/hardware/__init__.py @@ -16,11 +16,11 @@ from datetime import datetime from finesse.config import NUM_TEMPERATURE_MONITOR_CHANNELS, TEMPERATURE_MONITOR_TOPIC - from finesse.hardware import data_file_writer # noqa: F401 from finesse.hardware.device import get_device_types from finesse.hardware.plugins.temperature import get_temperature_monitor_instance -from .plugins.temperature.temperature_monitor_base import TemperatureSequence + +from finesse.hardware.plugins.temperature.temperature_monitor_base import TemperatureSequence _opus: OPUSInterface diff --git a/finesse/hardware/plugins/temperature/dp9800.py b/finesse/hardware/plugins/temperature/dp9800.py index 57068d1f..ca2460cc 100644 --- a/finesse/hardware/plugins/temperature/dp9800.py +++ b/finesse/hardware/plugins/temperature/dp9800.py @@ -9,7 +9,7 @@ ) from finesse.hardware.serial_device import SerialDevice -from .temperature_monitor_base import TemperatureMonitorBase, TemperatureSequence +from finesse.hardware.plugins.temperature.temperature_monitor_base import TemperatureMonitorBase, TemperatureSequence def check_data(data: bytes) -> None: diff --git a/finesse/hardware/plugins/temperature/senecak107.py b/finesse/hardware/plugins/temperature/senecak107.py index aeb6410e..2e37161c 100644 --- a/finesse/hardware/plugins/temperature/senecak107.py +++ b/finesse/hardware/plugins/temperature/senecak107.py @@ -16,7 +16,7 @@ ) from finesse.hardware.serial_device import SerialDevice -from .temperature_monitor_base import TemperatureMonitorBase, TemperatureSequence +from finesse.hardware.plugins.temperature.temperature_monitor_base import TemperatureMonitorBase, TemperatureSequence class SenecaK107Error(Exception): From 16371f112a1c4fd067757a90edfc277d7d3c605c Mon Sep 17 00:00:00 2001 From: CWestICL Date: Wed, 15 Nov 2023 11:35:08 +0000 Subject: [PATCH 04/10] Updated seneca parse_data() --- finesse/hardware/plugins/temperature/senecak107.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/finesse/hardware/plugins/temperature/senecak107.py b/finesse/hardware/plugins/temperature/senecak107.py index 0e54d541..f7af7d83 100644 --- a/finesse/hardware/plugins/temperature/senecak107.py +++ b/finesse/hardware/plugins/temperature/senecak107.py @@ -1,5 +1,4 @@ """This module provides an interface to Seneca temperature readers.""" -from decimal import Decimal from typing import Any import numpy @@ -104,7 +103,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 From 115963139abf6819660eed6e6d9db454db1a6684 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 15 Nov 2023 11:35:40 +0000 Subject: [PATCH 05/10] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- finesse/hardware/__init__.py | 5 +++-- finesse/hardware/plugins/temperature/dp9800.py | 3 +-- finesse/hardware/plugins/temperature/senecak107.py | 3 +-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/finesse/hardware/__init__.py b/finesse/hardware/__init__.py index 19c3a570..898bf4a2 100644 --- a/finesse/hardware/__init__.py +++ b/finesse/hardware/__init__.py @@ -19,8 +19,9 @@ from finesse.hardware import data_file_writer # noqa: F401 from finesse.hardware.device import get_device_types from finesse.hardware.plugins.temperature import get_temperature_monitor_instance - -from finesse.hardware.plugins.temperature.temperature_monitor_base import TemperatureSequence +from finesse.hardware.plugins.temperature.temperature_monitor_base import ( + TemperatureSequence, +) _opus: OPUSInterface diff --git a/finesse/hardware/plugins/temperature/dp9800.py b/finesse/hardware/plugins/temperature/dp9800.py index ca2460cc..43abd0fb 100644 --- a/finesse/hardware/plugins/temperature/dp9800.py +++ b/finesse/hardware/plugins/temperature/dp9800.py @@ -6,11 +6,10 @@ from finesse.hardware.plugins.temperature.temperature_monitor_base import ( TemperatureMonitorBase, + TemperatureSequence, ) from finesse.hardware.serial_device import SerialDevice -from finesse.hardware.plugins.temperature.temperature_monitor_base import TemperatureMonitorBase, TemperatureSequence - def check_data(data: bytes) -> None: """Perform message integrity checks. diff --git a/finesse/hardware/plugins/temperature/senecak107.py b/finesse/hardware/plugins/temperature/senecak107.py index 6f7b70a6..18bfd1d8 100644 --- a/finesse/hardware/plugins/temperature/senecak107.py +++ b/finesse/hardware/plugins/temperature/senecak107.py @@ -12,11 +12,10 @@ ) from finesse.hardware.plugins.temperature.temperature_monitor_base import ( TemperatureMonitorBase, + TemperatureSequence, ) from finesse.hardware.serial_device import SerialDevice -from finesse.hardware.plugins.temperature.temperature_monitor_base import TemperatureMonitorBase, TemperatureSequence - class SenecaK107Error(Exception): """Indicates that an error occurred while communicating with the device.""" From fd957b89ba152cfd3dbad88647e205aa92df4b9e Mon Sep 17 00:00:00 2001 From: CWestICL Date: Thu, 16 Nov 2023 14:59:08 +0000 Subject: [PATCH 06/10] Alias replaced with Sequence --- finesse/hardware/__init__.py | 6 ++---- finesse/hardware/plugins/temperature/dp9800.py | 4 ++-- finesse/hardware/plugins/temperature/senecak107.py | 4 ++-- .../plugins/temperature/temperature_monitor_base.py | 7 +------ 4 files changed, 7 insertions(+), 14 deletions(-) diff --git a/finesse/hardware/__init__.py b/finesse/hardware/__init__.py index 898bf4a2..937dd746 100644 --- a/finesse/hardware/__init__.py +++ b/finesse/hardware/__init__.py @@ -13,15 +13,13 @@ OPUSInterface, ) +from collections.abc import Sequence from datetime import datetime from finesse.config import NUM_TEMPERATURE_MONITOR_CHANNELS, TEMPERATURE_MONITOR_TOPIC from finesse.hardware import data_file_writer # noqa: F401 from finesse.hardware.device import get_device_types from finesse.hardware.plugins.temperature import get_temperature_monitor_instance -from finesse.hardware.plugins.temperature.temperature_monitor_base import ( - TemperatureSequence, -) _opus: OPUSInterface @@ -31,7 +29,7 @@ def _broadcast_device_types() -> None: pub.sendMessage("device.list", device_types=get_device_types()) -def _try_get_temperatures() -> TemperatureSequence | 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 43abd0fb..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 @@ -6,7 +7,6 @@ from finesse.hardware.plugins.temperature.temperature_monitor_base import ( TemperatureMonitorBase, - TemperatureSequence, ) from finesse.hardware.serial_device import SerialDevice @@ -195,7 +195,7 @@ def request_read(self) -> None: except Exception as e: raise DP9800Error(e) - def get_temperatures(self) -> TemperatureSequence: + def get_temperatures(self) -> Sequence: """Get the current temperatures.""" self.request_read() data = self.read_temperature_data() diff --git a/finesse/hardware/plugins/temperature/senecak107.py b/finesse/hardware/plugins/temperature/senecak107.py index 18bfd1d8..79d37dcb 100644 --- a/finesse/hardware/plugins/temperature/senecak107.py +++ b/finesse/hardware/plugins/temperature/senecak107.py @@ -1,4 +1,5 @@ """This module provides an interface to Seneca temperature readers.""" +from collections.abc import Sequence from typing import Any import numpy @@ -12,7 +13,6 @@ ) from finesse.hardware.plugins.temperature.temperature_monitor_base import ( TemperatureMonitorBase, - TemperatureSequence, ) from finesse.hardware.serial_device import SerialDevice @@ -145,7 +145,7 @@ def calc_temp(self, vals: numpy.ndarray) -> numpy.ndarray: vals += self.MIN_TEMP return vals - def get_temperatures(self) -> TemperatureSequence: + def get_temperatures(self) -> Sequence: # type: ignore """Get the current temperatures.""" self.request_read() data = self.read() diff --git a/finesse/hardware/plugins/temperature/temperature_monitor_base.py b/finesse/hardware/plugins/temperature/temperature_monitor_base.py index b72fb742..f99b2c1b 100644 --- a/finesse/hardware/plugins/temperature/temperature_monitor_base.py +++ b/finesse/hardware/plugins/temperature/temperature_monitor_base.py @@ -1,15 +1,10 @@ """Provides a base class for temperature monitor devices or mock devices.""" from abc import abstractmethod from collections.abc import Sequence -from decimal import Decimal - -import numpy from finesse.config import TEMPERATURE_MONITOR_TOPIC from finesse.hardware.device import Device -TemperatureSequence = Sequence[Decimal | numpy.float64] - class TemperatureMonitorBase( Device, @@ -20,5 +15,5 @@ class TemperatureMonitorBase( """The base class for temperature monitor devices or mock devices.""" @abstractmethod - def get_temperatures(self) -> TemperatureSequence: + def get_temperatures(self) -> Sequence: """Get the current temperatures.""" From e2b9c837502cd1e29ddc1a980bbeaba33f9add3f Mon Sep 17 00:00:00 2001 From: CWestICL Date: Thu, 16 Nov 2023 15:00:44 +0000 Subject: [PATCH 07/10] Updated dummy temp monitor --- .../hardware/plugins/temperature/dummy_temperature_monitor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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] From 6d8029b53820a9217041de0fa59e829b3d3a11aa Mon Sep 17 00:00:00 2001 From: CWestICL Date: Thu, 16 Nov 2023 15:07:36 +0000 Subject: [PATCH 08/10] Updated frontend --- finesse/gui/temp_control.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/finesse/gui/temp_control.py b/finesse/gui/temp_control.py index cf725b66..792358f4 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 @@ -178,7 +179,7 @@ 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: @@ -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: From 7899756943298168c3f2e4b5c2182ffaf19f9706 Mon Sep 17 00:00:00 2001 From: CWestICL Date: Thu, 16 Nov 2023 15:21:58 +0000 Subject: [PATCH 09/10] Moved ignore statement --- finesse/hardware/plugins/temperature/senecak107.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/finesse/hardware/plugins/temperature/senecak107.py b/finesse/hardware/plugins/temperature/senecak107.py index 79d37dcb..f4763910 100644 --- a/finesse/hardware/plugins/temperature/senecak107.py +++ b/finesse/hardware/plugins/temperature/senecak107.py @@ -145,8 +145,8 @@ def calc_temp(self, vals: numpy.ndarray) -> numpy.ndarray: vals += self.MIN_TEMP return vals - def get_temperatures(self) -> Sequence: # type: ignore + 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 From eab229f98a84e0823e04c8a6865a84026da56314 Mon Sep 17 00:00:00 2001 From: CWestICL Date: Thu, 16 Nov 2023 15:56:21 +0000 Subject: [PATCH 10/10] Updated _update_figure() --- finesse/gui/temp_control.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/finesse/gui/temp_control.py b/finesse/gui/temp_control.py index 792358f4..b6ff4200 100644 --- a/finesse/gui/temp_control.py +++ b/finesse/gui/temp_control.py @@ -129,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. @@ -186,8 +186,8 @@ def _plot_bb_temps(self, time: datetime, temperatures: Sequence) -> None: 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)