From bf292d5d721b53bd7237021af6db3f85523a4cb4 Mon Sep 17 00:00:00 2001 From: Julia Signell Date: Wed, 6 Sep 2023 09:57:32 -0400 Subject: [PATCH] Always pass chunks (#30) It seems uncontroversially nice to default to dask. --- tests/test_core.py | 7 ++++++- xpystac/core.py | 11 +++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/tests/test_core.py b/tests/test_core.py index 5127752..803ca2d 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -26,11 +26,16 @@ def test_to_xarray_with_bad_type(): def test_to_xarray_reference_file(simple_reference_file): ds = to_xarray(simple_reference_file) assert ds + for da in ds.data_vars.values(): + if da.ndim >= 2: + assert hasattr(da.data, "dask") def test_to_xarray_zarr(simple_zarr): ds = to_xarray(simple_zarr) - assert ds + for da in ds.data_vars.values(): + if da.ndim >= 2: + assert hasattr(da.data, "dask"), da.name def test_to_xarray_zarr_with_open_kwargs_engine(complex_zarr): diff --git a/xpystac/core.py b/xpystac/core.py index d562527..ad334bf 100644 --- a/xpystac/core.py +++ b/xpystac/core.py @@ -32,7 +32,7 @@ def _( @to_xarray.register def _(obj: pystac.Asset, **kwargs) -> xarray.Dataset: - default_kwargs: Mapping + default_kwargs: Mapping = {"chunks": {}} open_kwargs = obj.extra_fields.get("xarray:open_kwargs", {}) storage_options = obj.extra_fields.get("xarray:storage_options", None) @@ -52,11 +52,12 @@ def _(obj: pystac.Asset, **kwargs) -> xarray.Dataset: refs = planetary_computer.sign(r.json()) except ImportError: refs = r.json() + mapper = fsspec.get_mapper("reference://", fo=refs) default_kwargs = { + **default_kwargs, "engine": "zarr", "consolidated": False, - "chunks": {}, } return xarray.open_dataset( mapper, **{**default_kwargs, **open_kwargs, **kwargs} @@ -64,12 +65,10 @@ def _(obj: pystac.Asset, **kwargs) -> xarray.Dataset: if obj.media_type == pystac.MediaType.COG: _import_optional_dependency("rioxarray") - default_kwargs = {"engine": "rasterio"} + default_kwargs = {**default_kwargs, "engine": "rasterio"} elif obj.media_type == "application/vnd+zarr": _import_optional_dependency("zarr") - default_kwargs = {"engine": "zarr"} - else: - default_kwargs = {} + default_kwargs = {**default_kwargs, "engine": "zarr"} ds = xarray.open_dataset(obj.href, **{**default_kwargs, **open_kwargs, **kwargs}) return ds