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 Jun 12, 2024
1 parent d5b37ac commit 7bb49b8
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 21 deletions.
15 changes: 7 additions & 8 deletions ome_zarr/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
from abc import ABC, abstractmethod
from typing import Any, Dict, Iterator, List, Optional

from zarr.v2.storage import FSStore

from zarr.store import LocalStore, RemoteStore
from zarr.store import StoreLike, StorePath
from zarr.abc.store import Store
from zarr.store import LocalStore, RemoteStore, StoreLike, StorePath
from zarr.v2.storage import FSStore

LOGGER = logging.getLogger("ome_zarr.format")

Expand Down Expand Up @@ -200,7 +198,6 @@ def version(self) -> str:

# mkdir = True


# if "r" in mode or path.startswith(("http", "s3")):
# # Could be simplified on the fsspec side
# mkdir = False
Expand All @@ -214,7 +211,7 @@ def version(self) -> str:
# ) # TODO: open issue for using Path
# LOGGER.debug("Created nested FSStore(%s, %s, %s)", path, mode, kwargs)
# return store

def init_store(self, path: str, mode: str = "r") -> Store:
"""
Returns a Zarr v3 PathStore
Expand All @@ -231,7 +228,9 @@ def init_store(self, path: str, mode: str = "r") -> Store:
mode=mode,
**kwargs,
) # TODO: open issue for using Path
print("Created %s store %s(%s, %s, %s)" % (self.version, cls, path, mode, kwargs))
print(
"Created {} store {}({}, {}, {})".format(self.version, cls, path, mode, kwargs)
)
return store


Expand Down Expand Up @@ -389,7 +388,7 @@ def matches(self, metadata: dict) -> bool:
version = self._get_metadata_version(metadata)
LOGGER.debug("%s matches %s?", self.version, version)
return version == self.version_key

def _get_metadata_version(self, metadata: dict) -> Optional[str]:
"""
For version 0.5+ we use the NGFF_URL_0_5 key
Expand Down
15 changes: 7 additions & 8 deletions ome_zarr/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from urllib.parse import urljoin

import dask.array as da
from zarr import Group, Array, open
from zarr import Array, Group, open

# from zarr.v2.storage import FSStore
from zarr.abc.store import Store
Expand Down Expand Up @@ -75,9 +75,7 @@ def __init__(
detected = detect_format(self.__metadata, loader)
print("ZarrLocation.__init__ %s detected: %s", self.__path, detected)
if detected != self.__fmt:
print(
"version mismatch: detected: %s, requested: %s", detected, self.__fmt
)
print("version mismatch: detected: %s, requested: %s", detected, self.__fmt)
self.__fmt = detected
self.__store = detected.init_store(self.__path, self.__mode)
self.__init_metadata()
Expand Down Expand Up @@ -112,7 +110,7 @@ def __init_metadata(self) -> None:
print("ZarrLocation __init_metadata: TRY to open group...")
# zarr_group = Group.open(self.__store) #, zarr_format=None)

# NB: If the store is writable, open() will fail IF location doesn't exist because
# NB: If the store is writable, open() will fail IF location doesn't exist because
# zarr v3 will try to create an Array (instead of looking instead for a Group)
# and fails because 'shape' is not provided - see TypeError below.
# NB: we need zarr_format here to open V2 groups
Expand All @@ -134,7 +132,7 @@ def __init_metadata(self) -> None:
except TypeError:
# open() tried to open_array() but we didn't supply 'shape' argument
self.__exists = False

# self.zarray: JSONDict = await self.get_json(".zarray")
# self.zgroup: JSONDict = await self.get_json(".zgroup")
# v3_json = await self.get_json("zarr.json")
Expand Down Expand Up @@ -189,6 +187,7 @@ def load(self, subpath: str = "") -> da.core.Array:
"""Use dask.array.from_zarr to load the subpath."""
# return da.from_zarr(self.__store, subpath)
from zarr import load

# returns zarr Array (no chunks) instead of Dask
return load(store=self.__store, path=subpath)

Expand Down Expand Up @@ -229,9 +228,9 @@ async def get_json(self, subpath: str) -> JSONDict:
All other exceptions log at the ERROR level.
"""
try:
print('get_json', subpath)
print("get_json", subpath)
data = await self.__store.get(subpath)
print('data', data)
print("data", data)

if not data:
return {}
Expand Down
16 changes: 12 additions & 4 deletions ome_zarr/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import numpy as np

from .axes import Axes
from .format import format_from_version, NGFF_URL_0_5
from .format import NGFF_URL_0_5, format_from_version
from .io import ZarrLocation
from .types import JSONDict

Expand Down Expand Up @@ -179,7 +179,11 @@ def lookup(self, key: str, default: Any) -> Any:

# Handle zarr V3 where everything is under "attributes"
if NGFF_URL_0_5 in self.zarr.root_attrs.get("attributes", {}):
return self.zarr.root_attrs.get("attributes", {}).get(NGFF_URL_0_5, {}).get(key, default)
return (
self.zarr.root_attrs.get("attributes", {})
.get(NGFF_URL_0_5, {})
.get(key, default)
)

return self.zarr.root_attrs.get(key, default)

Expand Down Expand Up @@ -281,7 +285,9 @@ def matches(zarr: ZarrLocation) -> bool:
if zarr.zgroup:
if "multiscales" in zarr.root_attrs:
return True
if "multiscales" in (zarr.root_attrs.get("attributes", {}).get(NGFF_URL_0_5, {})):
if "multiscales" in (
zarr.root_attrs.get("attributes", {}).get(NGFF_URL_0_5, {})
):
return True
return False

Expand Down Expand Up @@ -331,7 +337,9 @@ def __init__(self, node: Node) -> None:
# e.g. 6001240.zarr/labels/0/labels doesn't exist
# BUT calling this with zarr v3 fails since
child_zarr = self.zarr.create("labels")
print("Multiscales child_zarr 'labels' exists??", child_zarr, child_zarr.exists())
print(
"Multiscales child_zarr 'labels' exists??", child_zarr, child_zarr.exists()
)
if child_zarr.exists():
node.add(child_zarr, visibility=False)
print("Multiscales __init__ END")
Expand Down
8 changes: 7 additions & 1 deletion ome_zarr/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,13 @@ def write_multiscale(

else:
# We create the array and write data to it immediately...
a = group.create_array(str(path), chunks=chunks_opt, shape=data.shape, dtype=data.dtype, **options)
a = group.create_array(
str(path),
chunks=chunks_opt,
shape=data.shape,
dtype=data.dtype,
**options,
)
# These 2 lines are equivalent to e.g. a[:,:] = data (for any number of dimensions)
s = [np.s_[:]] * len(data.shape)
a[tuple(s)] = data
Expand Down

0 comments on commit 7bb49b8

Please sign in to comment.