Skip to content

Commit

Permalink
Always pass chunks (#30)
Browse files Browse the repository at this point in the history
It seems uncontroversially nice to default to dask.
  • Loading branch information
jsignell authored Sep 6, 2023
1 parent beef8c0 commit bf292d5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
7 changes: 6 additions & 1 deletion tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
11 changes: 5 additions & 6 deletions xpystac/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -52,24 +52,23 @@ 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}
)

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

0 comments on commit bf292d5

Please sign in to comment.