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 Dec 13, 2024
1 parent 68b26bd commit bc3d71a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 24 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
4 changes: 3 additions & 1 deletion napari_ome_zarr/_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
34 changes: 12 additions & 22 deletions napari_ome_zarr/ome_zarr_reader.py
Original file line number Diff line number Diff line change
@@ -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

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

return results

return f

0 comments on commit bc3d71a

Please sign in to comment.