Skip to content

Commit

Permalink
Add NXClass attribute to the nx reflections group
Browse files Browse the repository at this point in the history
  • Loading branch information
jbeilstenedmands committed Oct 30, 2024
1 parent 85210c1 commit 099e895
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/dials/util/table_as_hdf5_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def encode(
n = len(group)
this_group = group.create_group(f"group_{n}")
this_nx_group = nx_reflections.create_group(f"group_{n}")
this_nx_group.attrs["NX_class"] = "NXreflections"

# Experiment identifiers and ids are required as part of our spec for this format.
identifier_map = dict(table.experiment_identifiers())
Expand Down Expand Up @@ -157,13 +158,17 @@ def encode_columns(
group.create_dataset(
key, data=this_data, shape=this_data.shape, dtype=this_data.dtype
)
# Create references to the data in the NXReflections group
ref_dtype = h5py.special_dtype(ref=h5py.RegionReference)
if key in dials_to_nx_names:
nx_group[dials_to_nx_names[key]] = group[key] # a reference
elif key in dials_to_nx_names_split:
for i, name in enumerate(dials_to_nx_names_split[key]):
nx_group.create_dataset(name, (1,), dtype=ref_dtype)
nx_group[name][0] = group[key].regionref[:, i] # a region reference
# note, use region references to get the slice back as follows:
# e.g. h_ref = nx_group["h"][0] # contains a reference to the data array and region
# h = file_handle[h_ref][h_ref] # first index gets the array, second index the slice

@staticmethod
def encode_shoebox(group: h5py.Group, data: flex.shoebox, key: str):
Expand Down

0 comments on commit 099e895

Please sign in to comment.