From e7b2d99f7c3f2e2a56c4126b6e24fca0e40a2e07 Mon Sep 17 00:00:00 2001 From: Julius Busecke Date: Wed, 8 Oct 2025 14:52:09 -0400 Subject: [PATCH 1/2] Enable icechunk reading - rough first try --- src/titiler/xarray/titiler/xarray/io.py | 28 +++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/titiler/xarray/titiler/xarray/io.py b/src/titiler/xarray/titiler/xarray/io.py index 44bb11ab3..37d1d14d3 100644 --- a/src/titiler/xarray/titiler/xarray/io.py +++ b/src/titiler/xarray/titiler/xarray/io.py @@ -39,6 +39,12 @@ def xarray_open_dataset( # noqa: C901 except ImportError: # pragma: nocover zarr = None # type: ignore + try: + import icechunk + except ImportError: # pragma: nocover + icechunk = None # type: ignore + + parsed = urlparse(src_path) protocol = parsed.scheme or "file" @@ -77,12 +83,22 @@ def xarray_open_dataset( # noqa: C901 # Fallback to Zarr else: - if module_available("zarr", minversion="3.0"): - store = zarr.storage.FsspecStore.from_url( - src_path, storage_options={"asynchronous": True} - ) - else: - store = fsspec.filesystem(protocol).get_mapper(src_path) + # try icechunk first + try: + assert icechunk is not None, "'icechunk' must be installed to read icechunk dataset" + storage = icechunk.local_filesystem_storage(src_path) + repo = icechunk.Repository.open(storage=storage) + session = repo.readonly_session('main') + store = session.store + xr_open_args['consolidated'] = False + except icechunk.IcechunkError: + # try fsspec and zarr python + if module_available("zarr", minversion="3.0"): + store = zarr.storage.FsspecStore.from_url( + src_path, storage_options={"asynchronous": True} + ) + else: + store = fsspec.filesystem(protocol).get_mapper(src_path) ds = xarray.open_zarr(store, **xr_open_args) return ds From 2f76f8c3720b43759a1da46371dd99a2ac2094fc Mon Sep 17 00:00:00 2001 From: Julius Busecke Date: Wed, 8 Oct 2025 18:14:43 -0400 Subject: [PATCH 2/2] Support s3 storage --- src/titiler/xarray/titiler/xarray/io.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/titiler/xarray/titiler/xarray/io.py b/src/titiler/xarray/titiler/xarray/io.py index 37d1d14d3..0be2c8978 100644 --- a/src/titiler/xarray/titiler/xarray/io.py +++ b/src/titiler/xarray/titiler/xarray/io.py @@ -86,7 +86,16 @@ def xarray_open_dataset( # noqa: C901 # try icechunk first try: assert icechunk is not None, "'icechunk' must be installed to read icechunk dataset" - storage = icechunk.local_filesystem_storage(src_path) + if protocol == "file": + storage = icechunk.local_filesystem_storage(src_path) + elif protocol == "s3": + storage = icechunk.s3_storage( + bucket=parsed.netloc, + prefix=parsed.path.lstrip('/'), # remove leading slash, this is an annoying mismatch between icechunk and urlparse + from_env=True, + ) + else: + raise ValueError(f"Unsupported storage protocol {protocol} for icechunk in titiler.xarray") repo = icechunk.Repository.open(storage=storage) session = repo.readonly_session('main') store = session.store