This repository has been archived by the owner on Feb 11, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from openclimatefix/jacob/zarr_v3
Add Zarr V3 version based on numcodecs zarr v3
- Loading branch information
Showing
7 changed files
with
88 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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 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 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,5 @@ | ||
"""Zarr V3 adaption of Blosc2 codec for numcodecs.""" | ||
|
||
from numcodecs.zarr3 import _make_bytes_bytes_codec | ||
|
||
Blosc2 = _make_bytes_bytes_codec("blosc2", "Blosc2") |
This file contains 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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
numpy==1.26.4 | ||
numpy | ||
numcodecs | ||
blosc2 | ||
pytest | ||
zarr>=3.0.0 |
This file contains 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 |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
author="Jacob Bieker", | ||
author_email="[email protected]", | ||
company="Open Climate Fix Ltd", | ||
install_requires=["numpy", "blosc2", "numcodecs"], | ||
install_requires=["numpy", "blosc2", "numcodecs", "zarr>3"], | ||
long_description=long_description, | ||
long_description_content_type="text/markdown", | ||
packages=find_packages(), | ||
|
This file contains 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 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,69 @@ | ||
"""Test the Zarr version 3 codec with the Blosc2 codec.""" | ||
|
||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
import numpy as np | ||
import pytest | ||
|
||
if TYPE_CHECKING: # pragma: no cover | ||
import zarr | ||
else: | ||
zarr = pytest.importorskip("zarr") | ||
|
||
import numcodecs.zarr3 | ||
import zarr.storage | ||
|
||
from ocf_blosc2.ocf_blosc2_v3 import Blosc2 | ||
|
||
pytestmark = [ | ||
pytest.mark.filterwarnings("ignore:Codec 'numcodecs.*' not configured in config.*:UserWarning"), | ||
pytest.mark.filterwarnings( | ||
"ignore:Numcodecs codecs are not in the Zarr version 3 specification and may not be supported by other zarr implementations." # noqa | ||
), | ||
] | ||
|
||
get_codec_class = zarr.registry.get_codec_class | ||
Array = zarr.Array | ||
BytesCodec = zarr.codecs.BytesCodec | ||
Store = zarr.abc.store.Store | ||
MemoryStore = zarr.storage.MemoryStore | ||
StorePath = zarr.storage.StorePath | ||
|
||
|
||
EXPECTED_WARNING_STR = "Numcodecs codecs are not in the Zarr version 3.*" | ||
|
||
|
||
@pytest.fixture | ||
def store() -> StorePath: | ||
"""Make a new in-memory store.""" | ||
return StorePath(MemoryStore(read_only=False)) | ||
|
||
|
||
ALL_CODECS = [getattr(numcodecs.zarr3, cls_name) for cls_name in numcodecs.zarr3.__all__] | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"codec_class", | ||
[Blosc2], | ||
) | ||
def test_generic_compressor( | ||
store: StorePath, codec_class: type[numcodecs.zarr3._NumcodecsBytesBytesCodec] | ||
): | ||
"""Test that the generic compressor works with the Blosc2 codec.""" | ||
data = np.arange(0, 256, dtype="uint16").reshape((16, 16)) | ||
|
||
with pytest.warns(UserWarning, match=EXPECTED_WARNING_STR): | ||
a = zarr.create_array( | ||
store / "generic", | ||
shape=data.shape, | ||
chunks=(4, 4), | ||
shards=(16, 16), | ||
dtype=data.dtype, | ||
fill_value=0, | ||
compressors=[codec_class()], | ||
) | ||
|
||
a[:, :] = data.copy() | ||
np.testing.assert_array_equal(data, a[:, :]) |