From 2eed5a9d3a02c19adb65c63cbff189d6b55150e8 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 16 Sep 2024 10:43:19 +0200 Subject: [PATCH] . --- .../MRP/MRPBaseSensor.py | 1 + .../MRP/MRPReadingEntry.py | 37 ++++++++++++++++++- src/MagneticReadoutProcessing/pyproject.toml | 2 +- src/MagneticReadoutProcessing/setup.cfg | 2 +- src/MagneticReadoutProcessing/setup.py | 2 +- 5 files changed, 39 insertions(+), 5 deletions(-) diff --git a/src/MagneticReadoutProcessing/MRP/MRPBaseSensor.py b/src/MagneticReadoutProcessing/MRP/MRPBaseSensor.py index 685563cc..b5f67b34 100644 --- a/src/MagneticReadoutProcessing/MRP/MRPBaseSensor.py +++ b/src/MagneticReadoutProcessing/MRP/MRPBaseSensor.py @@ -138,3 +138,4 @@ def get_vector(self, _sensor_id: int = 0) -> (float, float, float): :rtype: (float, float, float) """ return (self.get_reading('x', _sensor_id), self.get_reading('y', _sensor_id), self.get_reading('z', _sensor_id)) + diff --git a/src/MagneticReadoutProcessing/MRP/MRPReadingEntry.py b/src/MagneticReadoutProcessing/MRP/MRPReadingEntry.py index dfd71c5c..2492ded4 100644 --- a/src/MagneticReadoutProcessing/MRP/MRPReadingEntry.py +++ b/src/MagneticReadoutProcessing/MRP/MRPReadingEntry.py @@ -1,9 +1,19 @@ +from enum import Enum + """ one datapoint for a reading """ class MRPReadingEntryException(Exception): def __init__(self, message="MRPReadingEntryException thrown"): self.message = message super().__init__(self.message) + +class MRPReadingEntryUnit(Enum): + UNIT_UNSPECIFIED = 0 + UNIT_uT = 1 + UNIT_mT = 2 + UNIT_T = 3 + + class MRPReadingEntry: """ Class holds all values for one read entry such as value and position""" _value: float = None # [mT] @@ -14,6 +24,17 @@ class MRPReadingEntry: _is_valid: bool = False _id: int = None _temperature: float = -254.0 + _unit: MRPReadingEntryUnit = MRPReadingEntryUnit.UNIT_UNSPECIFIED + + + @property + def unit(self): + return self._unit + + @unit.setter + def unit(self, value: MRPReadingEntryUnit): + self._unit = value + @property def temperature(self): @@ -83,7 +104,7 @@ def id(self, value: int): self._id = value - def __init__(self, p_id: int = None, p_value: float = None, p_phi: float = None, p_theta: float = None, p_rip: int = None, p_rit: int = None, p_is_valid: bool = False, p_temperature: float = -254.0): + def __init__(self, p_id: int = None, p_value: float = None, p_phi: float = None, p_theta: float = None, p_rip: int = None, p_rit: int = None, p_is_valid: bool = False, p_temperature: float = -254.0, p_unit: MRPReadingEntryUnit = MRPReadingEntryUnit.UNIT_UNSPECIFIED): self._id = p_id self._value = p_value self._phi = p_phi @@ -92,6 +113,7 @@ def __init__(self, p_id: int = None, p_value: float = None, p_phi: float = None, self._reading_index_theta = p_rit self._is_valid = p_is_valid self._temperature = p_temperature + self._unit = p_unit def from_dict(self, _dict: dict, _import_scale_factor: float = 1.0): errors = 0 @@ -148,8 +170,18 @@ def from_dict(self, _dict: dict, _import_scale_factor: float = 1.0): self._temperature = float(v) errors = errors + 1 + if 'unit' in _dict: + v = _dict.get('unit') + if v is None: + v = MRPReadingEntryUnit.UNIT_UNSPECIFIED + #self._unit = MRPReadingEntryUnit(v) + self._unit.value = v + errors = errors + 1 + if errors < len(self.__dict__()): raise MRPReadingEntryException("from_dict import failed") + + def __dict__(self) -> dict: return { 'value': self._value, @@ -159,7 +191,8 @@ def __dict__(self) -> dict: 'reading_index_theta': self._reading_index_theta, 'is_valid': self._is_valid, 'id': self._id, - 'temperature': self._temperature + 'temperature': self._temperature, + 'unit': self.value } def to_dict(self) -> dict: return self.__dict__() \ No newline at end of file diff --git a/src/MagneticReadoutProcessing/pyproject.toml b/src/MagneticReadoutProcessing/pyproject.toml index 6859f1db..32cdf359 100644 --- a/src/MagneticReadoutProcessing/pyproject.toml +++ b/src/MagneticReadoutProcessing/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta" [project] name = "MagneticReadoutProcessing" -version = "1.9.5" +version = "1.9.6" description = "This library was created for the Low-Field MRI project and allows processing of data measured by magnetic field sensors. The focus is on visualization, followed by the provision of simple interfaces to work with this data. In general its possible to use this lib on all kinds of sensor data." license = {file = "LICENSE"} authors = [{name = "Marcel Ochsendorf", email = "info@marcelochsendorf.com"}] diff --git a/src/MagneticReadoutProcessing/setup.cfg b/src/MagneticReadoutProcessing/setup.cfg index d8ae4582..daecadcb 100644 --- a/src/MagneticReadoutProcessing/setup.cfg +++ b/src/MagneticReadoutProcessing/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = MagneticReadoutProcessing -version = 1.9.5 +version = 1.9.6 author = Marcel Ochsendorf author_email = info@marcelochsendorf.com description = This library was created for the Low-Field MRI project and allows processing of data measured by magnetic field sensors. The focus is on visualization, followed by the provision of simple interfaces to work with this data. In general its possible to use this lib on all kinds of sensor data. diff --git a/src/MagneticReadoutProcessing/setup.py b/src/MagneticReadoutProcessing/setup.py index cfbfa287..56b01fa3 100644 --- a/src/MagneticReadoutProcessing/setup.py +++ b/src/MagneticReadoutProcessing/setup.py @@ -10,7 +10,7 @@ install_requires = [str(requirement) for requirement in pkg_resources.parse_requirements(requirements_txt)] setup(name='MagneticReadoutProcessing', - version='1.9.5', + version='1.9.6', license='Apache 2', description='This library was created for the Low-Field MRI project and allows processing of data measured by magnetic field sensors. The focus is on visualization, followed by the provision of simple interfaces to work with this data. In general its possible to use this lib on all kinds of sensor data.', author='Marcel Ochsendorf',