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 (#22)

* add "!" notation to remove optional groups with missing required children

* Implement suggestions

---------

Co-authored-by: domna <[email protected]>
  • Loading branch information
rettigl and domna authored Jul 10, 2024
1 parent 1b567ff commit fe6a13d
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions pynxtools_mpes/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -33,6 +34,9 @@
parse_flatten_json,
)

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)

DEFAULT_UNITS = {
"X": "step",
"Y": "step",
Expand Down Expand Up @@ -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 :]
Expand Down Expand Up @@ -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


Expand Down

0 comments on commit fe6a13d

Please sign in to comment.