Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/hdfmap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
]

__version__ = "1.1.1"
__date__ = "2025/11/17"
__date__ = "2025/11/18"
__author__ = "Dan Porter"


Expand Down
4 changes: 2 additions & 2 deletions src/hdfmap/eval_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions tests/test_edge_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'