diff --git a/pynxtools_mpes/reader.py b/pynxtools_mpes/reader.py index 67979a8..8a980ad 100644 --- a/pynxtools_mpes/reader.py +++ b/pynxtools_mpes/reader.py @@ -18,6 +18,7 @@ """MPES reader implementation for the DataConverter.""" import errno +import logging import os from functools import reduce from typing import Any, Tuple, Union @@ -33,6 +34,9 @@ parse_flatten_json, ) +logger = logging.getLogger(__name__) +logger.setLevel(logging.INFO) + DEFAULT_UNITS = { "X": "step", "Y": "step", @@ -330,7 +334,13 @@ def read( # pylint: disable=too-many-branches fill_data_indices_in_config(config_file_dict, x_array_loaded) + optional_groups_to_remove = [] + for key, value in config_file_dict.items(): + if isinstance(value, str) and value.startswith("!"): + optional_groups_to_remove.append(key) + value = value[1:] + if isinstance(value, str) and ":" in value: precursor = value.split(":")[0] value = value[value.index(":") + 1 :] @@ -384,6 +394,18 @@ def read( # pylint: disable=too-many-branches for key, value in eln_data_dict.items(): template[key] = value + # remove groups that have required children missing + for key in optional_groups_to_remove: + if template.get(key) is None: + group_to_delete = key.rsplit("/", 1)[0] + logger.info( + f"[info]: Required element {key} not provided. " + f"Removing the parent group {group_to_delete}.", + ) + for temp_key in template.keys(): + if temp_key.startswith(group_to_delete): + del template[temp_key] + return template