From 0b38491c798f18298d7d176f65fd3ed86153393d Mon Sep 17 00:00:00 2001 From: lorenzo Date: Tue, 5 Nov 2024 13:02:44 +0100 Subject: [PATCH] feat: minor changes to support fsspec store Support reading remote zarrs via authenticated HTTP calls #9 --- src/ngio/core/image_like_handler.py | 4 ++-- src/ngio/io/_zarr_group_utils.py | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/ngio/core/image_like_handler.py b/src/ngio/core/image_like_handler.py index 0586b47..f0b42dd 100644 --- a/src/ngio/core/image_like_handler.py +++ b/src/ngio/core/image_like_handler.py @@ -99,11 +99,11 @@ def _init_dataset(self, dataset: Dataset) -> None: This method is for internal use only. """ self._dataset = dataset + self._array = self._group.get(self._dataset.path, None) - if self._dataset.path not in self._group.array_keys(): + if self._array is None: raise ValueError(f"Dataset {self._dataset.path} not found in the group.") - self._array = self._group[self.dataset.path] self._diminesions = Dimensions( on_disk_shape=self._array.shape, axes_names=self._dataset.axes_names, diff --git a/src/ngio/io/_zarr_group_utils.py b/src/ngio/io/_zarr_group_utils.py index dd2de9b..59efef7 100644 --- a/src/ngio/io/_zarr_group_utils.py +++ b/src/ngio/io/_zarr_group_utils.py @@ -1,5 +1,6 @@ from pathlib import Path +import fsspec import zarr from ngio.io._zarr import ( @@ -22,8 +23,14 @@ def _check_store(store: StoreLike) -> StoreLike: if isinstance(store, str) or isinstance(store, Path): return store + if isinstance(store, fsspec.mapping.FSMap) or isinstance( + store, zarr.storage.FSStore + ): + return store + raise NotImplementedError( - "RemoteStore is not yet supported. Please use LocalStore." + f"Store type {type(store)} is not supported. supported types are: " + "str, Path, fsspec.mapping.FSMap, zarr.storage.FSStore" )