Skip to content

Commit

Permalink
sqme: chunk_store fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirill888 committed Jun 26, 2024
1 parent a2ec97f commit 6d75bfc
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions odc/loader/_zarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,12 @@ def _from_zarr_spec(
drop_variables: Sequence[str] = (),
) -> xr.Dataset:
fsspec_opts = fsspec_opts or {}
if target is not None and chunk_store is None:
if target is not None:
if chunk_store is None:
fs, target = url_to_fs(target, **fsspec_opts)
chunk_store = fs.get_mapper(target)
elif isinstance(chunk_store, fsspec.AbstractFileSystem):
chunk_store = chunk_store.get_mapper(target)

# TODO: deal with coordinates being loaded at open time.
#
Expand Down Expand Up @@ -200,9 +202,14 @@ def __init__(
self,
src: RasterSource,
chunks: Any | None = None,
chunk_store: fsspec.AbstractFileSystem | Mapping[str, Any] | None = None,
chunk_store: (
fsspec.AbstractFileSystem | fsspec.FSMap | Mapping[str, Any] | None
) = None,
drop_variables: Sequence[str] = (),
) -> None:
if isinstance(chunk_store, fsspec.AbstractFileSystem):
chunk_store = chunk_store.get_mapper(src.uri)

driver_data: xr.DataArray | xr.Dataset | SomeDoc = src.driver_data
self._spec: ZarrSpecDict | None = None
self._ds: xr.Dataset | None = None
Expand Down Expand Up @@ -231,6 +238,9 @@ def __init__(
assert subdataset is not None
assert subdataset in ds.data_vars

if chunk_store is None:
chunk_store = fsspec.get_mapper(src.uri)

# recreate xr.DataArray with all the dims/coords/attrs
# but this time loadable from chunk_store
xx = ds.data_vars[subdataset]
Expand Down

0 comments on commit 6d75bfc

Please sign in to comment.