From 094ed640c6892c76328f79bca2deaf5b5818cfbf Mon Sep 17 00:00:00 2001 From: rettigl Date: Tue, 9 Jul 2024 22:11:22 +0200 Subject: [PATCH] add "!" notation to remove optional groups with missing required children --- pynxtools_mpes/reader.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/pynxtools_mpes/reader.py b/pynxtools_mpes/reader.py index 67979a8..2e88bc9 100644 --- a/pynxtools_mpes/reader.py +++ b/pynxtools_mpes/reader.py @@ -330,7 +330,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 "!" in value and value.index("!") == 0: + 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 +390,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 key not in template: + group_to_delete = "/".join(key.split("/")[:-1]) + print( + f"[info]: Required element {key} not provided. " + f"Removing the parent group {group_to_delete}.", + ) + for temp_key in template.keys(): + if temp_key.find(group_to_delete) == 0: + del template[temp_key] + return template