Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always pass chunks #30

Merged
merged 1 commit into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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