diff --git a/src/hdfmap/__init__.py b/src/hdfmap/__init__.py index 70e63f2..a404d85 100644 --- a/src/hdfmap/__init__.py +++ b/src/hdfmap/__init__.py @@ -67,7 +67,7 @@ ] __version__ = "1.1.1" -__date__ = "2025/11/17" +__date__ = "2025/11/18" __author__ = "Dan Porter" diff --git a/src/hdfmap/eval_functions.py b/src/hdfmap/eval_functions.py index c0c7587..21d9a17 100644 --- a/src/hdfmap/eval_functions.py +++ b/src/hdfmap/eval_functions.py @@ -322,12 +322,12 @@ def prepare_expression(hdf_file: h5py.File, expression: str, hdf_namespace: dict else: expression = expression.replace(match.group(), name) # find alternate names '(opt1|opt2|opt3)' - for alt_names in re_dataset_alternate.findall(expression): # alt_names = 'opt1|opt2|opt3 + for alt_names in re_dataset_alternate.findall(expression): # alt_names = 'opt1|opt2|opt3' names = alt_names.split('|') # first available name in hdf_namespace or last name name = next( (n for n in names if n in attributes), - next((n for n in names if n in hdf_namespace), names[-1]) + next((n for n in names if hdf_namespace.get(n, '') in hdf_file), names[-1]) ) expression = expression.replace(f"({alt_names})", name) # replace parentheses return expression diff --git a/tests/test_edge_cases.py b/tests/test_edge_cases.py index e6a1311..412757f 100644 --- a/tests/test_edge_cases.py +++ b/tests/test_edge_cases.py @@ -93,3 +93,19 @@ def test_msmapper_file(): assert gamma > 1.0, 'unit cell incorrect' +@only_dls_file_system +def test_alternate_name_local_data(): + f1 = '/dls/science/groups/das/ExampleData/hdfmap_tests/i16/1109527.nxs' + f2 = '/dls/science/groups/das/ExampleData/hdfmap_tests/i16/1113658.nxs' + m = hdfmap.create_nexus_map(f1) + + with hdfmap.load_hdf(f1) as nxs: + scan_command1 = m.get_data(nxs, 'scan_command') + print(scan_command1) + cmd1 = m.eval(nxs, '(cmd|scan_command)') + assert scan_command1 != cmd1, 'cmd and scan_command should not be the same' + with hdfmap.load_hdf(f2) as nxs: + scan_command2 = m.get_data(nxs, 'scan_command') + cmd2 = m.eval(nxs, '(cmd|scan_command)') + assert scan_command2 == cmd2, 'cmd and scan_command should be the same' + assert cmd1 != cmd2, 'cmd of both files should not be the same'