diff --git a/.isort.cfg b/.isort.cfg index b46c472..bc7bfab 100644 --- a/.isort.cfg +++ b/.isort.cfg @@ -1,2 +1,2 @@ [settings] -known_third_party = numpy,ome_zarr,pytest,setuptools,vispy +known_third_party = dask,numpy,ome_zarr,pytest,setuptools,vispy,zarr diff --git a/napari_ome_zarr/_reader.py b/napari_ome_zarr/_reader.py index f39dfa9..fb84299 100644 --- a/napari_ome_zarr/_reader.py +++ b/napari_ome_zarr/_reader.py @@ -10,12 +10,14 @@ from typing import Any, Dict, Iterator, List, Optional import numpy as np -from .ome_zarr_reader import read_ome_zarr + # from ome_zarr.io import parse_url from ome_zarr.reader import Label, Node, Reader from ome_zarr.types import LayerData, PathLike, ReaderFunction from vispy.color import Colormap +from .ome_zarr_reader import read_ome_zarr + LOGGER = logging.getLogger("napari_ome_zarr.reader") METADATA_KEYS = ("name", "visible", "contrast_limits", "colormap", "metadata") diff --git a/napari_ome_zarr/ome_zarr_reader.py b/napari_ome_zarr/ome_zarr_reader.py index 557b30d..9bc46ef 100644 --- a/napari_ome_zarr/ome_zarr_reader.py +++ b/napari_ome_zarr/ome_zarr_reader.py @@ -1,28 +1,24 @@ - - # zarr v3 -import zarr -from zarr import Group -import numpy as np +from typing import Any, Callable, Dict, List, Tuple, Union + import dask.array as da -from typing import List +import numpy as np +import zarr from vispy.color import Colormap - -from typing import Any, Callable, Dict, List, Tuple, Union +from zarr import Group LayerData = Union[Tuple[Any], Tuple[Any, Dict], Tuple[Any, Dict, str]] -class Spec(): - +class Spec: def __init__(self, group: Group): self.group = group @staticmethod def matches(group: Group) -> bool: return False - + def data(self) -> List[da.core.Array] | None: return None @@ -36,8 +32,7 @@ def children(self): def iter_nodes(self): yield self for child in self.children(): - for ch in child.iter_nodes(): - yield ch + yield from child.iter_nodes() def iter_data(self): for node in self.iter_nodes(): @@ -53,7 +48,6 @@ def get_attrs(group: Group): class Multiscales(Spec): - @staticmethod def matches(group: Group) -> bool: return "multiscales" in Spec.get_attrs(group) @@ -97,8 +91,8 @@ def metadata(self): rsp["colormap"] = colormaps return rsp -class Bioformats2raw(Spec): +class Bioformats2raw(Spec): @staticmethod def matches(group: Group) -> bool: attrs = Spec.get_attrs(group) @@ -114,17 +108,15 @@ def children(self): if Multiscales.matches(g): rv.append(Multiscales(g)) return rv - -class Plate(Spec): +class Plate(Spec): @staticmethod def matches(group: Group) -> bool: return "plate" in Spec.get_attrs(group) class Label(Multiscales): - @staticmethod def matches(group: Group) -> bool: # label must also be Multiscales @@ -138,12 +130,10 @@ def metadata(self) -> Dict[str, Any] | None: def read_ome_zarr(url): - def f(*args: Any, **kwargs: Any) -> List[LayerData]: - results: List[LayerData] = list() - # TODO: handle missing file + # TODO: handle missing file root_group = zarr.open(url) print("Root group", root_group.attrs.asdict()) @@ -170,5 +160,5 @@ def f(*args: Any, **kwargs: Any) -> List[LayerData]: results.append(rv) return results - + return f