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
5 changes: 4 additions & 1 deletion finesse/hardware/__init__.py
Expand Up @@ -19,6 +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,
)

_opus: OPUSInterface

Expand All @@ -28,7 +31,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.
Expand Down
3 changes: 2 additions & 1 deletion finesse/hardware/plugins/temperature/dp9800.py
Expand Up @@ -6,6 +6,7 @@

from finesse.hardware.plugins.temperature.temperature_monitor_base import (
TemperatureMonitorBase,
TemperatureSequence,
)
from finesse.hardware.serial_device import SerialDevice

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) -> TemperatureSequence:
"""Get the current temperatures."""
self.request_read()
data = self.read_temperature_data()
Expand Down
8 changes: 4 additions & 4 deletions 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
Expand All @@ -13,6 +12,7 @@
)
from finesse.hardware.plugins.temperature.temperature_monitor_base import (
TemperatureMonitorBase,
TemperatureSequence,
)
from finesse.hardware.serial_device import SerialDevice

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,7 +145,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()
Expand Down
@@ -1,10 +1,15 @@
"""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,
Expand All @@ -15,5 +20,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."""