From 920d9cf21580d1c399cf7c519e1de055cb2011b2 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 6 Jan 2025 15:07:49 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .isort.cfg | 2 +- napari_ome_zarr/_reader.py | 1 + napari_ome_zarr/ome_zarr_reader.py | 46 ++++++++++++------------------ 3 files changed, 21 insertions(+), 28 deletions(-) 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 811c115..1b30f0a 100644 --- a/napari_ome_zarr/_reader.py +++ b/napari_ome_zarr/_reader.py @@ -8,6 +8,7 @@ from .ome_zarr_reader import read_ome_zarr + def napari_get_reader(path): """Returns a reader for supported paths that include IDR ID. diff --git a/napari_ome_zarr/ome_zarr_reader.py b/napari_ome_zarr/ome_zarr_reader.py index 463cf8a..5086a3f 100644 --- a/napari_ome_zarr/ome_zarr_reader.py +++ b/napari_ome_zarr/ome_zarr_reader.py @@ -1,31 +1,26 @@ - - # zarr v3 -import zarr -from zarr import Group -from zarr.core.sync import SyncMixin -from zarr.core.buffer import default_buffer_prototype +from typing import Any, Dict, List, Tuple, Union +from xml.etree import ElementTree as ET import dask.array as da -from typing import List +import zarr from vispy.color import Colormap -from xml.etree import ElementTree as ET - -from typing import Any, Dict, List, Tuple, Union +from zarr import Group +from zarr.core.buffer import default_buffer_prototype +from zarr.core.sync import SyncMixin 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 @@ -39,8 +34,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(): @@ -56,7 +50,6 @@ def get_attrs(group: Group): class Multiscales(Spec): - @staticmethod def matches(group: Group) -> bool: return "multiscales" in Spec.get_attrs(group) @@ -127,8 +120,8 @@ def metadata(self): return rsp -class Bioformats2raw(Spec): +class Bioformats2raw(Spec): @staticmethod def matches(group: Group) -> bool: attrs = Spec.get_attrs(group) @@ -137,7 +130,11 @@ def matches(group: Group) -> bool: def children(self): # lookup children from series of OME/METADATA.xml - xml_data = SyncMixin()._sync(self.group.store.get("OME/METADATA.ome.xml", prototype=default_buffer_prototype())) + xml_data = SyncMixin()._sync( + self.group.store.get( + "OME/METADATA.ome.xml", prototype=default_buffer_prototype() + ) + ) # print("xml_data", xml_data.to_bytes()) root = ET.fromstring(xml_data.to_bytes()) rv = [] @@ -156,19 +153,16 @@ def children(self): # override to NOT yield self since node has no data def iter_nodes(self): for child in self.children(): - for ch in child.iter_nodes(): - yield ch - + yield from child.iter_nodes() -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 @@ -182,12 +176,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()) @@ -214,5 +206,5 @@ def f(*args: Any, **kwargs: Any) -> List[LayerData]: results.append(rv) return results - + return f