Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jan 6, 2025
1 parent e4cda75 commit 920d9cf
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .isort.cfg
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions napari_ome_zarr/_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
46 changes: 19 additions & 27 deletions napari_ome_zarr/ome_zarr_reader.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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():
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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 = []
Expand All @@ -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
Expand All @@ -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())
Expand All @@ -214,5 +206,5 @@ def f(*args: Any, **kwargs: Any) -> List[LayerData]:
results.append(rv)

return results

return f

0 comments on commit 920d9cf

Please sign in to comment.