From 90725f84a14695225a4b0aadfea028cba52de729 Mon Sep 17 00:00:00 2001 From: Jeremy Magland Date: Tue, 3 Dec 2024 13:43:56 -0500 Subject: [PATCH] support zlib compression --- lindi/LindiH5pyFile/writers/LindiH5pyGroupWriter.py | 8 ++++++++ lindi/conversion/h5_filters_to_codecs.py | 2 ++ 2 files changed, 10 insertions(+) diff --git a/lindi/LindiH5pyFile/writers/LindiH5pyGroupWriter.py b/lindi/LindiH5pyFile/writers/LindiH5pyGroupWriter.py index 068614f..12325f8 100644 --- a/lindi/LindiH5pyFile/writers/LindiH5pyGroupWriter.py +++ b/lindi/LindiH5pyFile/writers/LindiH5pyGroupWriter.py @@ -82,6 +82,14 @@ def create_dataset( else: raise Exception(f'Unexpected type for compression_opts: {type(compression_opts)}') _zarr_compressor = numcodecs.GZip(level=level) + elif compression == 'zlib': + if compression_opts is None: + level = 4 + elif isinstance(compression_opts, int): + level = compression_opts + else: + raise Exception(f'Unexpected type for compression_opts: {type(compression_opts)}') + _zarr_compressor = numcodecs.Zlib(level=level) else: raise Exception(f'Compression {compression} is not supported') elif compression is None: diff --git a/lindi/conversion/h5_filters_to_codecs.py b/lindi/conversion/h5_filters_to_codecs.py index 7fa9cdb..069e4b2 100644 --- a/lindi/conversion/h5_filters_to_codecs.py +++ b/lindi/conversion/h5_filters_to_codecs.py @@ -57,6 +57,8 @@ def h5_filters_to_codecs(h5obj: h5py.Dataset) -> Union[List[Codec], None]: filters.append(numcodecs.Zstd(level=properties[0])) elif str(filter_id) == "gzip": filters.append(numcodecs.Zlib(level=properties)) + elif str(filter_id) == "zlib": + filters.append(numcodecs.Zlib(level=properties)) elif str(filter_id) == "32004": raise RuntimeError( f"{h5obj.name} uses lz4 compression - not supported"