Skip to content

Commit 608edaa

Browse files
committed
fix xarray_open_dataset for cloud hosted files
1 parent cc29d69 commit 608edaa

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

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/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)