Skip to content

Commit

Permalink
Merge pull request #130 from legend-exp/chunks
Browse files Browse the repository at this point in the history
Allow passing lists to set HDF5 chunking
  • Loading branch information
gipert authored Jan 21, 2025
2 parents 487d3a2 + b04168b commit ee8756e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/lgdo/lh5/_serializers/write/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ def _h5_write_array(
if "hdf5_settings" in obj.attrs:
h5py_kwargs |= obj.attrs["hdf5_settings"]

# HACK: a tuple is strictly requested for the "chunks" setting, but
# we'd like to pass a list too in some situations
if "chunks" in h5py_kwargs and isinstance(h5py_kwargs["chunks"], list):
h5py_kwargs["chunks"] = tuple(h5py_kwargs["chunks"])

# create HDF5 dataset
ds = group.create_dataset(name, data=nda, **h5py_kwargs)

Expand Down
13 changes: 13 additions & 0 deletions tests/lh5/test_lh5_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ def test_write_with_hdf5_compression(lgnd_file, tmptestdir):
assert h5f["/geds/raw/waveform/values"].compression is None
assert h5f["/geds/raw/waveform/values"].shuffle is False

store.write(
wft.values,
"/geds/raw/waveform/values",
f"{tmptestdir}/tmp-pygama-hdf5-compressed-wfs.lh5",
wo_mode="overwrite_file",
chunks=[1, 10],
compression=None,
shuffle=False,
)
with h5py.File(f"{tmptestdir}/tmp-pygama-hdf5-compressed-wfs.lh5") as h5f:
assert h5f["/geds/raw/waveform/values"].compression is None
assert h5f["/geds/raw/waveform/values"].shuffle is False


def test_write_empty_vov(tmptestdir):
vov = types.VectorOfVectors(flattened_data=[], cumulative_length=[])
Expand Down

0 comments on commit ee8756e

Please sign in to comment.