From 8b0cd915004ee720dc25f815602cde2c75629d36 Mon Sep 17 00:00:00 2001 From: Marcel Ochsendorf Date: Tue, 8 Oct 2024 09:33:28 +0200 Subject: [PATCH] added more additional data functions --- .../MRP/MRPReading.py | 49 +++++++++++++++++++ src/MagneticReadoutProcessing/pyproject.toml | 2 +- src/MagneticReadoutProcessing/setup.cfg | 2 +- src/MagneticReadoutProcessing/setup.py | 2 +- 4 files changed, 52 insertions(+), 3 deletions(-) diff --git a/src/MagneticReadoutProcessing/MRP/MRPReading.py b/src/MagneticReadoutProcessing/MRP/MRPReading.py index 6a69eccc..9dad2baa 100644 --- a/src/MagneticReadoutProcessing/MRP/MRPReading.py +++ b/src/MagneticReadoutProcessing/MRP/MRPReading.py @@ -104,6 +104,55 @@ def load_from_file(self, _filepath_name: str): except Exception as e: sys.stderr.write(str(e)) + + def has_additional_data(self, _keys: list[str]) -> bool: + """ + Checks if all the provided keys exist in the `additional_data` dictionary. + + Args: + _keys (list[str]): A list of keys to be checked in the `additional_data` dictionary. + + Returns: + bool: + - True if all keys in the list exist in `additional_data`. + - False if any key in the list is missing from `additional_data`. + + This function iterates over a list of keys and checks if each one exists in the + `additional_data` dictionary by calling the `has_additional_data` method for each key. + If any key is missing, the function returns `False`; otherwise, it returns `True` when all keys are present. + """ + # Iterate over each key in the provided list of keys + for k in _keys: + # If any key is not found in additional_data, return False + if not self.has_additional_data(k): + return False + # If all keys are found, return True + return True + + + def has_additional_data(self, _k: str) -> bool: + """ + Checks if the provided key exists and is valid in the `additional_data` dictionary. + + Args: + _k (str): The key to be checked in the `additional_data` dictionary. + + Returns: + bool: + - True if the key exists and is non-empty. + - False if the key is None, empty, or not found in `additional_data`. + + The function first ensures that the input key `_k` is not None and has a length greater than zero. + If the key passes this condition, it checks if the key exists in the `additional_data` dictionary. + """ + if _k is not None and len(_k) > 0: + # If the key exists in the additional_data dictionary, return its value + if _k in self.additional_data: + return True + return False + + + def get_additional_data(self, _k: str) -> any: """ Retrieve additional data associated with the given key from the instance's diff --git a/src/MagneticReadoutProcessing/pyproject.toml b/src/MagneticReadoutProcessing/pyproject.toml index 67ee65fc..3e94c609 100644 --- a/src/MagneticReadoutProcessing/pyproject.toml +++ b/src/MagneticReadoutProcessing/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta" [project] name = "MagneticReadoutProcessing" -version = "2.0.0" +version = "2.0.1" 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 aa917d80..c8910c23 100644 --- a/src/MagneticReadoutProcessing/setup.cfg +++ b/src/MagneticReadoutProcessing/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = MagneticReadoutProcessing -version = 2.0.0 +version = 2.0.1 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 e41918b6..17dbcea7 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='2.0.0', + version='2.0.1', 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',