diff --git a/webknossos/poetry.lock b/webknossos/poetry.lock index 3dc0b25e5..c57c151af 100644 --- a/webknossos/poetry.lock +++ b/webknossos/poetry.lock @@ -178,16 +178,6 @@ doc = ["Sphinx (>=6.1.0)", "packaging", "sphinx-autodoc-typehints (>=1.2.0)", "s test = ["anyio[trio]", "coverage[toml] (>=4.5)", "hypothesis (>=4.0)", "mock (>=4)", "psutil (>=5.9)", "pytest (>=7.0)", "pytest-mock (>=3.6.1)", "trustme", "uvloop (>=0.17)"] trio = ["trio (<0.22)"] -[[package]] -name = "asciitree" -version = "0.3.3" -description = "Draws ASCII trees." -optional = false -python-versions = "*" -files = [ - {file = "asciitree-0.3.3.tar.gz", hash = "sha256:4aa4b9b649f85e3fcb343363d97564aa1fb62e249677f2e18a96765145cc0f6e"}, -] - [[package]] name = "astroid" version = "2.15.5" @@ -807,17 +797,6 @@ files = [ [package.extras] tests = ["asttokens", "littleutils", "pytest", "rich"] -[[package]] -name = "fasteners" -version = "0.19" -description = "A python package that provides useful locks" -optional = false -python-versions = ">=3.6" -files = [ - {file = "fasteners-0.19-py3-none-any.whl", hash = "sha256:758819cb5d94cdedf4e836988b74de396ceacb8e2794d21f82d131fd9ee77237"}, - {file = "fasteners-0.19.tar.gz", hash = "sha256:b4f37c3ac52d8a445af3a66bce57b33b5e90b97c696b7b984f530cf8f0ded09c"}, -] - [[package]] name = "fastremap" version = "1.13.5" @@ -3332,27 +3311,6 @@ files = [ idna = ">=2.0" multidict = ">=4.0" -[[package]] -name = "zarr" -version = "2.16.1" -description = "An implementation of chunked, compressed, N-dimensional arrays for Python" -optional = false -python-versions = ">=3.8" -files = [ - {file = "zarr-2.16.1-py3-none-any.whl", hash = "sha256:de4882433ccb5b42cc1ec9872b95e64ca3a13581424666b28ed265ad76c7056f"}, - {file = "zarr-2.16.1.tar.gz", hash = "sha256:4276cf4b4a653431042cd53ff2282bc4d292a6842411e88529964504fb073286"}, -] - -[package.dependencies] -asciitree = "*" -fasteners = "*" -numcodecs = ">=0.10.0" -numpy = ">=1.20,<1.21.0 || >1.21.0" - -[package.extras] -docs = ["numcodecs[msgpack]", "numpydoc", "pydata-sphinx-theme", "sphinx", "sphinx-copybutton", "sphinx-design", "sphinx-issues", "sphinx-rtd-theme"] -jupyter = ["ipytree (>=0.2.2)", "ipywidgets (>=8.0.0)", "notebook"] - [[package]] name = "zarrita" version = "0.1.0a19" @@ -3457,4 +3415,4 @@ tifffile = ["pims", "tifffile"] [metadata] lock-version = "2.0" python-versions = ">=3.8,<3.12" -content-hash = "07329ab67ad02075ece09a3684ec64abdc370e740d59135e2f77be1e4954ade8" +content-hash = "e55e790064268bdba90de4ca608a1b15edaeed4c26233e9c0b2806815c4d23c5" diff --git a/webknossos/pyproject.toml b/webknossos/pyproject.toml index fbe19d07d..c9de52e4a 100644 --- a/webknossos/pyproject.toml +++ b/webknossos/pyproject.toml @@ -54,7 +54,6 @@ typer = {extras = ["all"], version = "^0.9.0"} typing-extensions = "^4.0" universal-pathlib = "0.1.3" wkw = "1.1.22" -zarr = "^2.16.1" zipp = "^3.5.0" # A list of all of the optional dependencies, some of which are included in the diff --git a/webknossos/webknossos/cli/convert_zarr.py b/webknossos/webknossos/cli/convert_zarr.py index d2f771311..4bb951c94 100644 --- a/webknossos/webknossos/cli/convert_zarr.py +++ b/webknossos/webknossos/cli/convert_zarr.py @@ -9,11 +9,9 @@ from typing import Any, Dict, Optional, Tuple, Union, cast import numpy as np +import tensorstore import typer -import zarr from typing_extensions import Annotated -from upath import UPath -from zarr.storage import FSStore from webknossos import ( BoundingBox, @@ -34,19 +32,16 @@ parse_voxel_size, ) from webknossos.dataset.defaults import DEFAULT_CHUNK_SHAPE, DEFAULT_CHUNKS_PER_SHARD -from webknossos.utils import get_executor_for_args, wait_and_ensure_success +from webknossos.utils import get_executor_for_args, is_fs_path, wait_and_ensure_success logger = logging.getLogger(__name__) -def _fsstore_from_path(path: Path, mode: str = "a") -> FSStore: - storage_options: Dict[str, Any] = {} - if isinstance(path, UPath): - storage_options = getattr(path, "_kwargs", {}).copy() - storage_options.pop("_url", None) - return FSStore(url=str(path), mode=mode, **storage_options) - - return FSStore(url=str(path), mode=mode, **storage_options) +def _make_kvstore(path: Path) -> Union[str, Dict[str, str]]: + if is_fs_path(path): + return {"driver": "file", "path": str(path)} + else: + return str(path) def _zarr_chunk_converter( @@ -58,8 +53,13 @@ def _zarr_chunk_converter( logging.info("Conversion of %s", bounding_box.topleft) slices = bounding_box.to_slices() - zarr_file = zarr.open(store=_fsstore_from_path(source_zarr_path), mode="r") - source_data: Any = zarr_file[slices][None, ...] + zarr_file = tensorstore.open( + { + "driver": "zarr", + "kvstore": _make_kvstore(source_zarr_path), + } + ).result() + source_data: Any = zarr_file[slices].read().result()[None, ...] if flip_axes: source_data = np.flip(source_data, flip_axes) @@ -86,8 +86,13 @@ def convert_zarr( """Performs the conversation of a Zarr dataset to a WEBKNOSSOS dataset.""" ref_time = time.time() - file = zarr.open(store=_fsstore_from_path(source_zarr_path), mode="r") - input_dtype: Any = file.dtype + file = tensorstore.open( + { + "driver": "zarr", + "kvstore": _make_kvstore(source_zarr_path), + } + ).result() + input_dtype: Any = file.dtype.numpy_dtype shape: Any = file.shape if voxel_size is None: