-
Notifications
You must be signed in to change notification settings - Fork 13
zarr python sharding #139
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
Merged
Merged
zarr python sharding #139
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| import json | ||
| from packaging import version | ||
| import tempfile | ||
|
|
||
| import pytest | ||
|
|
||
| import zarr.storage | ||
| import zarr | ||
|
|
||
| from ngff_zarr import Methods, to_multiscales, to_ngff_zarr | ||
|
|
||
| from ._data import verify_against_baseline | ||
|
|
||
| zarr_version = version.parse(zarr.__version__) | ||
|
|
||
| # Skip tests if zarr version is less than 3.0.0b1 | ||
| pytestmark = pytest.mark.skipif( | ||
| zarr_version < version.parse("3.0.0b1"), reason="zarr version < 3.0.0b1" | ||
| ) | ||
|
|
||
|
|
||
| def test_zarr_python_sharding(input_images): | ||
| dataset_name = "cthead1" | ||
| image = input_images[dataset_name] | ||
| baseline_name = "2_4/RFC3_GAUSSIAN.zarr" | ||
| chunks = (64, 64) | ||
| multiscales = to_multiscales( | ||
| image, [2, 4], chunks=chunks, method=Methods.ITKWASM_GAUSSIAN | ||
| ) | ||
| store = zarr.storage.MemoryStore() | ||
|
|
||
| chunks_per_shard = 2 | ||
| version = "0.4" | ||
| with pytest.raises(ValueError): | ||
| to_ngff_zarr( | ||
| store, multiscales, version=version, chunks_per_shard=chunks_per_shard | ||
| ) | ||
|
|
||
| version = "0.5" | ||
| with tempfile.TemporaryDirectory() as tmpdir: | ||
| to_ngff_zarr( | ||
| tmpdir, multiscales, version=version, chunks_per_shard=chunks_per_shard | ||
| ) | ||
| with open(tmpdir + "/zarr.json") as f: | ||
| zarr_json = json.load(f) | ||
| assert zarr_json["zarr_format"] == 3 | ||
| metadata = zarr_json["consolidated_metadata"]["metadata"] | ||
| scale0 = metadata["scale0/image"] | ||
| assert scale0["shape"][0] == 256 | ||
| assert scale0["shape"][1] == 256 | ||
| assert scale0["chunk_grid"]["configuration"]["chunk_shape"][0] == 128 | ||
| assert scale0["chunk_grid"]["configuration"]["chunk_shape"][1] == 128 | ||
| assert scale0["codecs"][0]["name"] == "sharding_indexed" | ||
| assert scale0["codecs"][0]["configuration"]["chunk_shape"][0] == 64 | ||
| assert scale0["codecs"][0]["configuration"]["chunk_shape"][1] == 64 | ||
|
|
||
| verify_against_baseline( | ||
| dataset_name, baseline_name, multiscales, version=version | ||
| ) | ||
|
|
||
| chunks_per_shard = (2, 1) | ||
| with tempfile.TemporaryDirectory() as tmpdir: | ||
| to_ngff_zarr( | ||
| tmpdir, multiscales, version=version, chunks_per_shard=chunks_per_shard | ||
| ) | ||
| with open(tmpdir + "/zarr.json") as f: | ||
| zarr_json = json.load(f) | ||
| assert zarr_json["zarr_format"] == 3 | ||
| metadata = zarr_json["consolidated_metadata"]["metadata"] | ||
| scale0 = metadata["scale0/image"] | ||
| assert scale0["shape"][0] == 256 | ||
| assert scale0["shape"][1] == 256 | ||
| assert scale0["chunk_grid"]["configuration"]["chunk_shape"][0] == 128 | ||
| assert scale0["chunk_grid"]["configuration"]["chunk_shape"][1] == 64 | ||
| assert scale0["codecs"][0]["name"] == "sharding_indexed" | ||
| assert scale0["codecs"][0]["configuration"]["chunk_shape"][0] == 64 | ||
| assert scale0["codecs"][0]["configuration"]["chunk_shape"][1] == 64 | ||
|
|
||
| verify_against_baseline( | ||
| dataset_name, baseline_name, multiscales, version=version | ||
| ) | ||
|
|
||
| chunks_per_shard = {"y": 2, "x": 1} | ||
| with tempfile.TemporaryDirectory() as tmpdir: | ||
| to_ngff_zarr( | ||
| tmpdir, multiscales, version=version, chunks_per_shard=chunks_per_shard | ||
| ) | ||
| with open(tmpdir + "/zarr.json") as f: | ||
| zarr_json = json.load(f) | ||
| assert zarr_json["zarr_format"] == 3 | ||
| metadata = zarr_json["consolidated_metadata"]["metadata"] | ||
| scale0 = metadata["scale0/image"] | ||
| assert scale0["shape"][0] == 256 | ||
| assert scale0["shape"][1] == 256 | ||
| assert scale0["chunk_grid"]["configuration"]["chunk_shape"][0] == 128 | ||
| assert scale0["chunk_grid"]["configuration"]["chunk_shape"][1] == 64 | ||
| assert scale0["codecs"][0]["name"] == "sharding_indexed" | ||
| assert scale0["codecs"][0]["configuration"]["chunk_shape"][0] == 64 | ||
| assert scale0["codecs"][0]["configuration"]["chunk_shape"][1] == 64 | ||
|
|
||
| verify_against_baseline( | ||
| dataset_name, baseline_name, multiscales, version=version | ||
| ) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.