-
Notifications
You must be signed in to change notification settings - Fork 2
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
Fix opening STAC Assets with xarray:open_kwargs engine field #18
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -55,14 +55,14 @@ def _(obj: pystac.Asset, **kwargs) -> xarray.Dataset: | |||||
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"} | ||||||
elif obj.media_type == "application/vnd+zarr": | ||||||
_import_optional_dependency("zarr") | ||||||
default_kwargs = {"engine": "zarr"} | ||||||
else: | ||||||
default_kwargs = {} | ||||||
default_kwargs = {} | ||||||
if open_kwargs.get("engine") is None: | ||||||
if obj.media_type == pystac.MediaType.COG: | ||||||
_import_optional_dependency("rioxarray") | ||||||
default_kwargs["engine"] = "rasterio" | ||||||
elif obj.media_type == "application/vnd+zarr": | ||||||
_import_optional_dependency("zarr") | ||||||
default_kwargs["engine"] = "zarr" | ||||||
|
||||||
ds = xarray.open_dataset(obj.href, **default_kwargs, **open_kwargs, **kwargs) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of making the changes above, we can just change this one line:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, that's a nice and simple solution! I had to look up dictionary unpacking in https://peps.python.org/pep-0448, and check how the duplicate keys will be handled:
So the user-set |
||||||
return ds |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!