From 4cd308dafec0b705473f75fbd7966d29d1e20d4a Mon Sep 17 00:00:00 2001 From: Julia Signell Date: Wed, 20 Aug 2025 09:35:19 -0400 Subject: [PATCH 1/2] Start using zarr-extension --- tests/test_core.py | 18 ++++++++++++++++++ xpystac/core.py | 12 ++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/tests/test_core.py b/tests/test_core.py index 84187b9..a33b007 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -127,6 +127,24 @@ def test_to_xarray_zarr_with_open_kwargs_engine(): to_xarray(zarr_asset) +@requires_planetary_computer +def test_to_xarray_zarr_with_zarr_extension(): + import planetary_computer as pc + + catalog = pystac_client.Client.open( + STAC_URLS["PLANETARY-COMPUTER"], modifier=pc.sign_inplace + ) + collection = catalog.get_collection("daymet-daily-hi") + assert collection is not None + zarr_asset = collection.assets["zarr-abfs"] + + # pop off the xarray-assets extension fields + zarr_asset.extra_fields.pop("xarray:open_kwargs") + zarr_asset.extra_fields["zarr:consolidated"] = True + + to_xarray(zarr_asset) + + @pytest.mark.skip(reason="not yet supported with kerchunk >=0.2.8") def test_to_xarray_with_item_collection_with_kerchunk_attrs_in_data_cube( data_cube_kerchunk, diff --git a/xpystac/core.py b/xpystac/core.py index 0f1176a..9d80abd 100644 --- a/xpystac/core.py +++ b/xpystac/core.py @@ -175,9 +175,17 @@ def _( if obj.media_type == pystac.MediaType.COG: _import_optional_dependency("rioxarray") default_kwargs = {**default_kwargs, "engine": "rasterio"} - elif obj.media_type == "application/vnd+zarr": + elif obj.media_type in ["application/vnd+zarr", "application/vnd.zarr"]: _import_optional_dependency("zarr") - default_kwargs = {**default_kwargs, "engine": "zarr"} + zarr_kwargs = {} + if "zarr:consolidated" in obj.extra_fields: + zarr_kwargs["consolidated"] = obj.extra_fields["zarr:consolidated"] + if "zarr:zarr_format" in obj.extra_fields: + zarr_kwargs["zarr_format"] = obj.extra_fields["zarr:zarr_format"] + if zarr_kwargs["zarr_format"] == 3: + raise ValueError("Zarr v3 is not supported by xpystac") + + default_kwargs = {**default_kwargs, **zarr_kwargs, "engine": "zarr"} href = obj.href if patch_url is not None: From 2044b6e81fb82d810f67dbd21d2e87333a6b240a Mon Sep 17 00:00:00 2001 From: Julia Signell Date: Thu, 21 Aug 2025 17:10:38 -0400 Subject: [PATCH 2/2] Remove zarr<3 error --- xpystac/core.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/xpystac/core.py b/xpystac/core.py index 9d80abd..17fd1f2 100644 --- a/xpystac/core.py +++ b/xpystac/core.py @@ -182,8 +182,6 @@ def _( zarr_kwargs["consolidated"] = obj.extra_fields["zarr:consolidated"] if "zarr:zarr_format" in obj.extra_fields: zarr_kwargs["zarr_format"] = obj.extra_fields["zarr:zarr_format"] - if zarr_kwargs["zarr_format"] == 3: - raise ValueError("Zarr v3 is not supported by xpystac") default_kwargs = {**default_kwargs, **zarr_kwargs, "engine": "zarr"}