Skip to content

Commit ee8756e

Browse files
authored
Merge pull request #130 from legend-exp/chunks
Allow passing lists to set HDF5 chunking
2 parents 487d3a2 + b04168b commit ee8756e

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/lgdo/lh5/_serializers/write/array.py

+5
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ def _h5_write_array(
6464
if "hdf5_settings" in obj.attrs:
6565
h5py_kwargs |= obj.attrs["hdf5_settings"]
6666

67+
# HACK: a tuple is strictly requested for the "chunks" setting, but
68+
# we'd like to pass a list too in some situations
69+
if "chunks" in h5py_kwargs and isinstance(h5py_kwargs["chunks"], list):
70+
h5py_kwargs["chunks"] = tuple(h5py_kwargs["chunks"])
71+
6772
# create HDF5 dataset
6873
ds = group.create_dataset(name, data=nda, **h5py_kwargs)
6974

tests/lh5/test_lh5_write.py

+13
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,19 @@ def test_write_with_hdf5_compression(lgnd_file, tmptestdir):
4444
assert h5f["/geds/raw/waveform/values"].compression is None
4545
assert h5f["/geds/raw/waveform/values"].shuffle is False
4646

47+
store.write(
48+
wft.values,
49+
"/geds/raw/waveform/values",
50+
f"{tmptestdir}/tmp-pygama-hdf5-compressed-wfs.lh5",
51+
wo_mode="overwrite_file",
52+
chunks=[1, 10],
53+
compression=None,
54+
shuffle=False,
55+
)
56+
with h5py.File(f"{tmptestdir}/tmp-pygama-hdf5-compressed-wfs.lh5") as h5f:
57+
assert h5f["/geds/raw/waveform/values"].compression is None
58+
assert h5f["/geds/raw/waveform/values"].shuffle is False
59+
4760

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

0 commit comments

Comments
 (0)