Skip to content

Commit

Permalink
Fix naming when adding multiple groups incrementally.
Browse files Browse the repository at this point in the history
  • Loading branch information
jbeilstenedmands committed Oct 29, 2024
1 parent 33b0db3 commit 2ca09ef
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
7 changes: 4 additions & 3 deletions src/dials/util/table_as_hdf5_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,12 @@ def encode(
else:
group = top_group.create_group(second_level_name, track_order=True)

for i, table in enumerate(reflections):
for table in reflections:
# Allow storing either a single experiment or multi-experiment table.
# Therefore use a generic 'group' name to avoid any reliance on this name
name = f"group_{i}"
this_group = group.create_group(name)
# name as group_0, group_1 etc.
n = len(group)
this_group = group.create_group(f"group_{n}")

# Experiment identifiers and ids are required as part of our spec for this format.
identifier_map = dict(table.experiment_identifiers())
Expand Down
8 changes: 4 additions & 4 deletions tests/util/test_table_as_hdf5_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def simple_test_equal(t1, t2):

data = h5py.File(tmp_path / "scaled2.refl", "r")
# try reading the two experiments to check it was written as h5
dset0 = data["dials"]["processing"]["0"]
dset1 = data["dials"]["processing"]["1"]
dset0 = data["dials"]["processing"]["group_0"]
dset1 = data["dials"]["processing"]["group_1"]
assert dset0["intensity.sum.value"].shape == (4417,)
assert dset1["intensity.sum.value"].shape == (5555,)

Expand All @@ -46,8 +46,8 @@ def simple_test_equal(t1, t2):

data = h5py.File(tmp_path / "scaled3.refl", "r")
# try reading the two experiments to check it was written as h5
dset0 = data["dials"]["processing"]["0"]
dset1 = data["dials"]["processing"]["1"]
dset0 = data["dials"]["processing"]["group_0"]
dset1 = data["dials"]["processing"]["group_1"]
assert dset0["intensity.sum.value"].shape == (4417,)
assert dset1["intensity.sum.value"].shape == (5555,)

Expand Down

0 comments on commit 2ca09ef

Please sign in to comment.