diff --git a/src/ngio/core/image_like_handler.py b/src/ngio/core/image_like_handler.py index 104e454..c1ad1a9 100644 --- a/src/ngio/core/image_like_handler.py +++ b/src/ngio/core/image_like_handler.py @@ -9,12 +9,12 @@ import numpy as np import zarr from dask.delayed import Delayed -from dask.distributed import Lock from scipy.ndimage import zoom from ngio._common_types import ArrayLike from ngio.core.dimensions import Dimensions from ngio.core.roi import WorldCooROI +from ngio.core.utils import Lock from ngio.io import StoreOrGroup, open_group_wrapper from ngio.ngff_meta import ( Dataset, @@ -229,6 +229,10 @@ def on_disk_shape(self) -> tuple[int, ...]: # Methods to get the image data in the canonical order def init_lock(self, lock_id: str | None = None) -> None: """Set the lock for the Dask array.""" + if Lock is None: + raise ImportError( + "Lock is not available. Please install dask[distributed]." + ) # Unique zarr array identifier array_path = ( Path(self._group.store.path) / self._group.path / self._dataset.path diff --git a/src/ngio/core/utils.py b/src/ngio/core/utils.py index 6ba7832..6bad216 100644 --- a/src/ngio/core/utils.py +++ b/src/ngio/core/utils.py @@ -14,6 +14,11 @@ TimeUnits, ) +try: + from dask.distributed import Lock +except ImportError: + Lock = None + def _build_empty_pyramid( group,