Skip to content

Commit 3e8d4c6

Browse files
fix xarray_open_dataset for cloud hosted files (#1164)
* fix xarray_open_dataset for cloud hosted files * fix tests dependencies * use aws creds
1 parent cc29d69 commit 3e8d4c6

File tree

5 files changed

+32
-7
lines changed

5 files changed

+32
-7
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ jobs:
3535
with:
3636
python-version: ${{ matrix.python-version }}
3737

38+
- name: Configure AWS credentials
39+
uses: aws-actions/configure-aws-credentials@v4
40+
with:
41+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
42+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
43+
aws-region: us-east-1
44+
3845
- name: Install dependencies
3946
run: |
4047
python -m pip install --upgrade pip

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77

88
* remove unused templates
99

10+
### titiler.xarray
11+
12+
* fix `xarray_open_dataset` for cloud hosted files
13+
1014
## 0.22.1 (2025-05-13)
1115

1216
### titiler.xarray

src/titiler/xarray/pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ test = [
6767
"zarr",
6868
"h5netcdf",
6969
"fsspec",
70+
"s3fs",
71+
"aiohttp",
72+
"requests",
7073
]
7174

7275
[project.urls]

src/titiler/xarray/tests/test_io_tools.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import pytest
88
import xarray
99

10-
from titiler.xarray.io import Reader, get_variable
10+
from titiler.xarray.io import Reader, get_variable, xarray_open_dataset
1111

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

@@ -200,3 +200,17 @@ def test_zarr_group(group):
200200
assert src.info()
201201
assert src.tile(0, 0, 0)
202202
assert src.point(0, 0).data[0] == group * 2 + 1
203+
204+
205+
@pytest.mark.parametrize(
206+
"src_path",
207+
[
208+
"s3://mur-sst/zarr-v1",
209+
"https://nasa-power.s3.amazonaws.com/syn1deg/temporal/power_syn1deg_monthly_temporal_lst.zarr",
210+
os.path.join(prefix, "dataset_3d.zarr"),
211+
],
212+
)
213+
def test_io_xarray_open_dataset(src_path):
214+
"""test xarray_open_dataset with cloud hosted files."""
215+
with xarray_open_dataset(src_path) as ds:
216+
assert list(ds.data_vars)

src/titiler/xarray/titiler/xarray/io.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,9 @@ def xarray_open_dataset( # noqa: C901
8080
# Fallback to Zarr
8181
else:
8282
if module_available("zarr", minversion="3.0"):
83-
if protocol == "file":
84-
store = zarr.storage.LocalStore(parsed.path, read_only=True)
85-
else:
86-
fs = fsspec.filesystem(protocol, storage_options={"asynchronous": True})
87-
store = zarr.storage.FsspecStore(fs, path=src_path, read_only=True)
88-
83+
store = zarr.storage.FsspecStore.from_url(
84+
src_path, storage_options={"asynchronous": True}
85+
)
8986
else:
9087
store = fsspec.filesystem(protocol).get_mapper(src_path)
9188

0 commit comments

Comments
 (0)