Skip to content

Commit

Permalink
Zarr V3: update with latest Zarr V3 specification
Browse files Browse the repository at this point in the history
- Rename 'endian' codec to 'bytes'
- Always generate a "codecs" array with the "bytes" codec in it.
  On reading, be tolerant with its absence but raise a warning
  as it being deprecated
- On reading, raise a warning on implicit groups, as being
  deprecated
- Support the 'zstd' codec, which isn't yet standardized, but is
  the default one used by Python zarr v3.0.2

Not handled: 'crc32c' and 'sharding' codecs
  • Loading branch information
rouault committed Feb 4, 2025
1 parent e502e9a commit 8871463
Show file tree
Hide file tree
Showing 16 changed files with 405 additions and 200 deletions.
3 changes: 2 additions & 1 deletion autotest/gdrivers/data/zarr/v3/test.zr3/ar/zarr.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
"separator":"\/"
}
},
"fill_value": 255
"fill_value": 255,
"codecs": [{"name":"bytes"}]
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
"chunk_key_encoding":{
"name":"v2"
},
"fill_value":255
"fill_value":255,
"codecs": [{"name":"bytes"}]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"zarr_format":3,
"node_type":"group"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"zarr_format":3,
"node_type":"array",
"shape":[
2
],
"data_type":"uint8",
"chunk_grid":{
"name":"regular",
"configuration":{
"chunk_shape":[
2
]
}
},
"chunk_key_encoding":{
"name":"default",
"configuration":{
"separator":"\/"
}
},
"fill_value": 255
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"zarr_format":3,
"node_type":"array",
"shape":[
5,
4
],
"data_type":"uint8",
"chunk_grid":{
"name":"regular",
"configuration":{
"chunk_shape":[
5,
4
]
}
},
"chunk_key_encoding":{
"name":"v2"
},
"fill_value":255
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"zarr_format":3,
"node_type":"group",
"attributes":{
"foo":"bar"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"zarr_format":3,
"node_type":"group",
"attributes":{
"root_foo":"bar"
}
}
55 changes: 41 additions & 14 deletions autotest/gdrivers/zarr_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -982,11 +982,13 @@ def test_zarr_read_ARRAY_DIMENSIONS(use_zmetadata, filename):
assert len(rg.GetDimensions()) == 2


@pytest.mark.parametrize(
"ds_name", ["data/zarr/v3/test_deprecated_no_codecs.zr3", "data/zarr/v3/test.zr3"]
)
@pytest.mark.parametrize("use_get_names", [True, False])
def test_zarr_read_v3(use_get_names):
def test_zarr_read_v3(ds_name, use_get_names):

filename = "data/zarr/v3/test.zr3"
ds = gdal.OpenEx(filename, gdal.OF_MULTIDIM_RASTER)
ds = gdal.OpenEx(ds_name, gdal.OF_MULTIDIM_RASTER)
assert ds is not None
rg = ds.GetRootGroup()
assert rg.GetName() == "/"
Expand Down Expand Up @@ -1930,21 +1932,28 @@ def create():
@pytest.mark.parametrize(
"compressor,options,expected_json",
[
["NONE", [], None],
["NONE", [], [{"name": "bytes", "configuration": {"endian": "little"}}]],
[
"gzip",
[],
[{"name": "gzip", "configuration": {"level": 6}}],
[
{"name": "bytes", "configuration": {"endian": "little"}},
{"name": "gzip", "configuration": {"level": 6}},
],
],
[
"gzip",
["GZIP_LEVEL=1"],
[{"name": "gzip", "configuration": {"level": 1}}],
[
{"name": "bytes", "configuration": {"endian": "little"}},
{"name": "gzip", "configuration": {"level": 1}},
],
],
[
"blosc",
[],
[
{"name": "bytes", "configuration": {"endian": "little"}},
{
"name": "blosc",
"configuration": {
Expand All @@ -1954,7 +1963,7 @@ def create():
"typesize": 1,
"blocksize": 0,
},
}
},
],
],
[
Expand All @@ -1966,6 +1975,7 @@ def create():
"BLOSC_BLOCKSIZE=2",
],
[
{"name": "bytes", "configuration": {"endian": "little"}},
{
"name": "blosc",
"configuration": {
Expand All @@ -1974,7 +1984,23 @@ def create():
"shuffle": "noshuffle",
"blocksize": 2,
},
}
},
],
],
[
"zstd",
["ZSTD_LEVEL=20"],
[
{"name": "bytes", "configuration": {"endian": "little"}},
{"name": "zstd", "configuration": {"level": 20, "checksum": False}},
],
],
[
"zstd",
["ZSTD_CHECKSUM=YES"],
[
{"name": "bytes", "configuration": {"endian": "little"}},
{"name": "zstd", "configuration": {"level": 13, "checksum": True}},
],
],
],
Expand Down Expand Up @@ -2032,28 +2058,28 @@ def read():
[
[
["@ENDIAN=little"],
[{"configuration": {"endian": "little"}, "name": "endian"}],
[{"configuration": {"endian": "little"}, "name": "bytes"}],
],
[["@ENDIAN=big"], [{"configuration": {"endian": "big"}, "name": "endian"}]],
[["@ENDIAN=big"], [{"configuration": {"endian": "big"}, "name": "bytes"}]],
[
["@ENDIAN=little", "CHUNK_MEMORY_LAYOUT=F"],
[
{"name": "transpose", "configuration": {"order": "F"}},
{"configuration": {"endian": "little"}, "name": "endian"},
{"configuration": {"endian": "little"}, "name": "bytes"},
],
],
[
["@ENDIAN=big", "CHUNK_MEMORY_LAYOUT=F"],
[
{"name": "transpose", "configuration": {"order": "F"}},
{"configuration": {"endian": "big"}, "name": "endian"},
{"configuration": {"endian": "big"}, "name": "bytes"},
],
],
[
["@ENDIAN=big", "CHUNK_MEMORY_LAYOUT=F", "COMPRESS=GZIP"],
[
{"name": "transpose", "configuration": {"order": "F"}},
{"name": "endian", "configuration": {"endian": "big"}},
{"name": "bytes", "configuration": {"endian": "big"}},
{"name": "gzip", "configuration": {"level": 6}},
],
],
Expand Down Expand Up @@ -3180,6 +3206,7 @@ def create():
assert "codecs" in j
assert j["codecs"] == [
{"name": "transpose", "configuration": {"order": "F"}},
{"name": "bytes", "configuration": {"endian": "little"}},
{"name": "gzip", "configuration": {"level": 6}},
]

Expand Down Expand Up @@ -5512,7 +5539,7 @@ def test_zarr_driver_copy_files(format):
assert gdal.Open(filename)

assert gdal.VSIStatL(newfilename)
print(gdal.ReadDirRecursive(newfilename))
# print(gdal.ReadDirRecursive(newfilename))
assert gdal.Open(newfilename)

finally:
Expand Down
3 changes: 3 additions & 0 deletions doc/source/drivers/raster/zarr.rst
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,9 @@ with ``ARRAY:`` using :program:`gdalmdimtranslate`):

Compression method.

For FORMAT=ZARR_V3, only ``NONE``, ``BLOSC``, ``GZIP`` and ``ZSTD`` are
supported.

- .. co:: FILTER
:choices: NONE, DELTA
:default: NONE
Expand Down
Loading

0 comments on commit 8871463

Please sign in to comment.