Skip to content

Commit b822b02

Browse files
committed
add back options and test s3
1 parent d00c92c commit b822b02

2 files changed

Lines changed: 15 additions & 9 deletions

File tree

rio_tiler/experimental/zarr.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838

3939
@cache
40-
def open_dataset(src_path: str) -> xarray.Dataset:
40+
def open_dataset(src_path: str, **kwargs: Any) -> xarray.Dataset:
4141
"""Open Xarray dataset
4242
4343
Args:
@@ -51,7 +51,7 @@ def open_dataset(src_path: str) -> xarray.Dataset:
5151
if not parsed.scheme:
5252
src_path = str(Path(src_path).resolve())
5353
src_path = "file://" + src_path
54-
store = obstore.store.from_url(src_path)
54+
store = obstore.store.from_url(src_path, **kwargs)
5555
zarr_store = ObjectStore(store=store, read_only=True)
5656
ds = xarray.open_dataset(
5757
zarr_store,
@@ -77,7 +77,10 @@ class ZarrReader(BaseReader):
7777
Examples:
7878
>>> with ZarrReader(
7979
"s3://mur-sst/zarr-v1",
80-
opener_options={"engine": "zarr"}
80+
opener_options={
81+
"skip_signature": True,
82+
"region": "us-west-2",
83+
}
8184
) as src:
8285
print(src)
8386
print(src.variables)
@@ -91,7 +94,7 @@ class ZarrReader(BaseReader):
9194
tms: TileMatrixSet = attr.ib(default=WEB_MERCATOR_TMS)
9295

9396
opener: Callable[..., xarray.Dataset] = attr.ib(default=open_dataset)
94-
97+
opener_options: Dict = attr.ib(factory=dict)
9598
_ctx_stack: contextlib.ExitStack = attr.ib(init=False, factory=contextlib.ExitStack)
9699

97100
def __attrs_post_init__(self):
@@ -100,7 +103,9 @@ def __attrs_post_init__(self):
100103
assert rioxarray is not None, "rioxarray must be installed to use XarrayReader"
101104

102105
if not self.dataset:
103-
self.dataset = self._ctx_stack.enter_context(self.opener(self.input))
106+
self.dataset = self._ctx_stack.enter_context(
107+
self.opener(self.input, **self.opener_options)
108+
)
104109

105110
# NOTE: rioxarray returns **ordered** bounds in form of (minx, miny, maxx, maxx)
106111
self.bounds = tuple(self.dataset.rio.bounds())

tests/test_io_zarr.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@
1111

1212

1313
@pytest.mark.parametrize(
14-
"filename",
14+
"filename,options",
1515
[
16-
ZARR_3D,
16+
(ZARR_3D, {}),
17+
("s3://mur-sst/zarr-v1", {"skip_signature": True, "region": "us-west-2"}),
1718
],
1819
)
19-
def test_dataset_reader(filename):
20+
def test_dataset_reader(filename, options):
2021
"""test reader."""
21-
with ZarrReader(filename) as ds:
22+
with ZarrReader(filename, opener_options=options) as ds:
2223
assert ds.variables
2324
assert ds.crs
2425
assert ds.transform

0 commit comments

Comments
 (0)