Skip to content

Commit

Permalink
adds data index only if not already present
Browse files Browse the repository at this point in the history
  • Loading branch information
Arora0 committed Nov 23, 2023
1 parent b3ec011 commit 838941c
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions pynxtools/dataconverter/readers/mpes/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,25 @@ def _getattr(obj, attr):
return reduce(_getattr, [obj] + attr.split("."))


def fill_data_indices_in_config(config_file_dict, x_array_loaded):
"""Add data indices key value pairs to the config_file
dictionary from the xarray dimensions if not already
present.
"""
for key in list(config_file_dict):
if "*" in key:
value = config_file_dict[key]
for dim in x_array_loaded.dims:
new_key = key.replace("*", dim)
new_value = value.replace("*", dim)

if new_key not in config_file_dict.keys() \
and new_value not in config_file_dict.values():
config_file_dict[new_key] = new_value

config_file_dict.pop(key)


class MPESReader(BaseReader):
"""MPES-specific reader class"""

Expand All @@ -251,7 +270,7 @@ class MPESReader(BaseReader):
# Whitelist for the NXDLs that the reader supports and can process
supported_nxdls = ["NXmpes"]

def read(
def read( # pylint: disable=too-many-branches
self,
template: dict = None,
file_paths: Tuple[str] = None,
Expand All @@ -269,12 +288,7 @@ def read(
eln_data_dict,
) = handle_h5_and_json_file(file_paths, objects)

for key in list(config_file_dict):
if "*" in key:
value = config_file_dict[key]
for dim in x_array_loaded.dims:
config_file_dict[key.replace("*", dim)] = value.replace("*", dim)
config_file_dict.pop(key)
fill_data_indices_in_config(config_file_dict, x_array_loaded)

for key, value in config_file_dict.items():

Expand Down

0 comments on commit 838941c

Please sign in to comment.