Skip to content

Commit

Permalink
add "!" notation to remove optional groups with missing required chil…
Browse files Browse the repository at this point in the history
…dren
  • Loading branch information
rettigl committed Jul 9, 2024
1 parent 1b567ff commit 094ed64
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions pynxtools_mpes/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 :]
Expand Down Expand Up @@ -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


Expand Down

0 comments on commit 094ed64

Please sign in to comment.