Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use zarr default compressor by default #253

Merged
merged 3 commits into from
Feb 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ome_zarr/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def write_multiscale(
url=group.store,
component=str(Path(group.path, str(path))),
storage_options=options,
compressor=options.get("compressor"),
compressor=options.get("compressor", zarr.storage.default_compressor),
dimension_separator=group._store._dimension_separator,
)
else:
Expand Down Expand Up @@ -558,7 +558,7 @@ def _write_dask_image(
component=str(Path(group.path, str(path))),
storage_options=options,
compute=False,
compressor=options.get("compressor"),
compressor=options.get("compressor", zarr.storage.default_compressor),
dimension_separator=group._store._dimension_separator,
)
)
Expand Down
24 changes: 24 additions & 0 deletions tests/test_writer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import filecmp
import pathlib
from tempfile import TemporaryDirectory

import dask.array as da
import numpy as np
Expand All @@ -16,6 +17,7 @@
_retuple,
write_image,
write_labels,
write_multiscale,
write_multiscale_labels,
write_multiscales_metadata,
write_plate_metadata,
Expand Down Expand Up @@ -220,6 +222,28 @@ def test_write_image_compressed(self, array_constructor):
"blocksize": 0,
}

def test_default_compression(self):
"""Test that the default compression is not None.

We make an array of zeros which should compress trivially easily,
write out the chunks, and check that they are smaller than the raw
data.
"""
arr_np = np.zeros((2, 50, 200, 400), dtype=np.uint8)
# avoid empty chunks so they are guaranteed to be written out to disk
arr_np[0, 0, 0, 0] = 1
# 4MB chunks, trivially compressible
arr = da.from_array(arr_np, chunks=(1, 50, 200, 400))
with TemporaryDirectory(suffix=".ome.zarr") as tempdir:
path = tempdir
store = parse_url(path, mode="w").store
root = zarr.group(store=store)
# no compressor options, we are checking default
write_multiscale([arr], group=root, axes="tzyx")
# check chunk: multiscale level 0, 4D chunk at (0, 0, 0, 0)
chunk_size = (pathlib.Path(path) / "0/0/0/0/0").stat().st_size
assert chunk_size < 4e6

def test_validate_coordinate_transforms(self):

fmt = FormatV04()
Expand Down