Skip to content

fix xarray_open_dataset for cloud hosted files #1164

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

Merged
merged 3 commits into from
Jun 2, 2025
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: 7 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1

- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

* remove unused templates

### titiler.xarray

* fix `xarray_open_dataset` for cloud hosted files

## 0.22.1 (2025-05-13)

### titiler.xarray
Expand Down
3 changes: 3 additions & 0 deletions src/titiler/xarray/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ test = [
"zarr",
"h5netcdf",
"fsspec",
"s3fs",
"aiohttp",
"requests",
]

[project.urls]
Expand Down
16 changes: 15 additions & 1 deletion src/titiler/xarray/tests/test_io_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import pytest
import xarray

from titiler.xarray.io import Reader, get_variable
from titiler.xarray.io import Reader, get_variable, xarray_open_dataset

prefix = os.path.join(os.path.dirname(__file__), "fixtures")

Expand Down Expand Up @@ -200,3 +200,17 @@ def test_zarr_group(group):
assert src.info()
assert src.tile(0, 0, 0)
assert src.point(0, 0).data[0] == group * 2 + 1


@pytest.mark.parametrize(
"src_path",
[
"s3://mur-sst/zarr-v1",
"https://nasa-power.s3.amazonaws.com/syn1deg/temporal/power_syn1deg_monthly_temporal_lst.zarr",
os.path.join(prefix, "dataset_3d.zarr"),
],
)
def test_io_xarray_open_dataset(src_path):
"""test xarray_open_dataset with cloud hosted files."""
with xarray_open_dataset(src_path) as ds:
assert list(ds.data_vars)
9 changes: 3 additions & 6 deletions src/titiler/xarray/titiler/xarray/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,9 @@ def xarray_open_dataset( # noqa: C901
# Fallback to Zarr
else:
if module_available("zarr", minversion="3.0"):
if protocol == "file":
store = zarr.storage.LocalStore(parsed.path, read_only=True)
else:
fs = fsspec.filesystem(protocol, storage_options={"asynchronous": True})
store = zarr.storage.FsspecStore(fs, path=src_path, read_only=True)

store = zarr.storage.FsspecStore.from_url(
src_path, storage_options={"asynchronous": True}
)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maxrjones Not sure why but the other error I was seeing while debugging was due to an old aiobotocore version

else:
store = fsspec.filesystem(protocol).get_mapper(src_path)

Expand Down
Loading