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 6, 2024
1 parent 767b642 commit bec0ade
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
4 changes: 2 additions & 2 deletions ome_zarr/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,15 +376,15 @@ def init_store(self, path: str, mode: str = "r") -> FSStore:
mode=mode,
**kwargs,
) # TODO: open issue for using Path
print("Created v0.5 store %s(%s, %s, %s)" % (cls, path, mode, kwargs))
print("Created v0.5 store {}({}, {}, {})".format(cls, path, mode, kwargs))
return store

def matches(self, metadata: dict) -> bool:
"""Version 0.5+ defined by version_key (URL)"""
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
12 changes: 6 additions & 6 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 @@ -109,19 +109,19 @@ def __init_metadata(self) -> None:
try:
# NB: zarr_format not supported in Group.open() or Array.open() yet
# We want to use zarr_format=None to handle v2 or v3
zarr_group = Group.open(self.__store) #, zarr_format=None)
zarr_group = Group.open(self.__store) # , zarr_format=None)
self.zgroup = zarr_group.metadata.to_dict()
self.__metadata = self.zgroup
except FileNotFoundError:
# group doesn't exist yet, try array
try:
zarr_array = Array.open(self.__store) #, zarr_format=None)
zarr_array = Array.open(self.__store) # , zarr_format=None)
self.zarray = zarr_array.metadata.to_dict()
self.__metadata = self.zarray
except (ValueError, KeyError, FileNotFoundError):
# exceptions raised may change here?
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 @@ -212,9 +212,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
12 changes: 9 additions & 3 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 @@ -279,7 +283,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
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 bec0ade

Please sign in to comment.