Skip to content

Commit

Permalink
Added tests for compression filters, also failing ones.
Browse files Browse the repository at this point in the history
  • Loading branch information
florianziemen committed Aug 29, 2023
1 parent d3f8419 commit d5c42e9
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 0 deletions.
19 changes: 19 additions & 0 deletions kerchunk/tests/gen_hdf5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import numpy
import h5py
import hdf5plugin

compressors = dict (
zstd = hdf5plugin.Zstd(),
bitshuffle = hdf5plugin.Bitshuffle(nelems=0, cname='lz4'),
lz4 = hdf5plugin.LZ4(nbytes=0),
blosc_lz4_bitshuffle = hdf5plugin.Blosc(cname='blosclz', clevel=9, shuffle=hdf5plugin.Blosc.BITSHUFFLE)
)

for c in compressors :
f = h5py.File(f'hdf5_compression_{c}.h5', 'w')
f.create_dataset(
'data',
data=numpy.arange(100),
**compressors[c]
)
f.close()
Binary file added kerchunk/tests/hdf5_compression_bitshuffle.h5
Binary file not shown.
Binary file not shown.
Binary file added kerchunk/tests/hdf5_compression_lz4.h5
Binary file not shown.
Binary file added kerchunk/tests/hdf5_compression_zstd.h5
Binary file not shown.
11 changes: 11 additions & 0 deletions kerchunk/tests/test_hdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,17 @@ def test_compact():
assert np.allclose(g.ancillary_data.atlas_sdp_gps_epoch[:], 1.19880002e09)


def test_compress():
import glob
files = glob.glob (osp.join(here, "hdf5_compression_*.h5"))
for f in files:
h = kerchunk.hdf.SingleHdf5ToZarr(f)
out = h.translate()
m = fsspec.get_mapper("reference://", fo=out)
g = zarr.open(m)
assert np.mean(g.data) == 49.5


def test_embed():
fn = osp.join(here, "NEONDSTowerTemperatureData.hdf5")
h = kerchunk.hdf.SingleHdf5ToZarr(fn, vlen_encode="embed")
Expand Down

0 comments on commit d5c42e9

Please sign in to comment.