diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 90d8bb9d..7f3acec2 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -23,4 +23,5 @@ jobs: - name: Test with pytest shell: bash -l {0} run: | + export ZARR_V3_EXPERIMENTAL_API=1 pytest -v --cov diff --git a/kerchunk/grib2.py b/kerchunk/grib2.py index e3a927b3..3b14c29d 100644 --- a/kerchunk/grib2.py +++ b/kerchunk/grib2.py @@ -24,7 +24,7 @@ import xarray import numpy as np -from kerchunk.utils import class_factory, _encode_for_JSON +from kerchunk.utils import class_factory, _encode_for_JSON, zarr_init_group_and_store from kerchunk.codecs import GRIBCodec from kerchunk.combine import MultiZarrToZarr, drop @@ -113,6 +113,7 @@ def scan_grib( inline_threshold=100, skip=0, filter={}, + zarr_version=None, ): """ Generate references for a GRIB2 file @@ -134,6 +135,9 @@ def scan_grib( the exact value or is in the given set, are processed. E.g., the cf-style filter ``{'typeOfLevel': 'heightAboveGround', 'level': 2}`` only keeps messages where heightAboveGround==2. + zarr_version: int + The desired zarr spec version to target (currently 2 or 3). The default + of None will use the default zarr version. Returns ------- @@ -192,7 +196,7 @@ def scan_grib( if good is False: continue - z = zarr.open_group(store) + z, store = zarr_init_group_and_store(store, zarr_version=zarr_version) global_attrs = { f"GRIB_{k}": m[k] for k in cfgrib.dataset.GLOBAL_ATTRIBUTES_KEYS diff --git a/kerchunk/tests/test_grib.py b/kerchunk/tests/test_grib.py index f24f2974..fc490081 100644 --- a/kerchunk/tests/test_grib.py +++ b/kerchunk/tests/test_grib.py @@ -21,14 +21,19 @@ here = os.path.dirname(__file__) -def test_one(): +@pytest.mark.parametrize("zarr_version", [2, 3]) +def test_one(zarr_version): # from https://dd.weather.gc.ca/model_gem_regional/10km/grib2/00/000 fn = os.path.join(here, "CMC_reg_DEPR_ISBL_10_ps10km_2022072000_P000.grib2") - out = scan_grib(fn) + out = scan_grib(fn, zarr_version=zarr_version) ds = xr.open_dataset( "reference://", engine="zarr", - backend_kwargs={"consolidated": False, "storage_options": {"fo": out[0]}}, + backend_kwargs={ + "consolidated": False, + "zarr_version": zarr_version, + "storage_options": {"fo": out[0]}, + }, ) assert ds.attrs["GRIB_centre"] == "cwao"