From bec0adef879e6af2eaf022fbc1fca5e73afd59e1 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 6 Jun 2024 12:51:54 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- ome_zarr/format.py | 4 ++-- ome_zarr/io.py | 12 ++++++------ ome_zarr/reader.py | 12 +++++++++--- ome_zarr/writer.py | 8 +++++++- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/ome_zarr/format.py b/ome_zarr/format.py index 2f0acc67..26274900 100644 --- a/ome_zarr/format.py +++ b/ome_zarr/format.py @@ -376,7 +376,7 @@ 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: @@ -384,7 +384,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 diff --git a/ome_zarr/io.py b/ome_zarr/io.py index 0c7e56a7..09972ea6 100644 --- a/ome_zarr/io.py +++ b/ome_zarr/io.py @@ -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 @@ -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") @@ -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 {} diff --git a/ome_zarr/reader.py b/ome_zarr/reader.py index 4ace8237..7b7109b2 100644 --- a/ome_zarr/reader.py +++ b/ome_zarr/reader.py @@ -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 @@ -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) @@ -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 diff --git a/ome_zarr/writer.py b/ome_zarr/writer.py index b39e3e03..4405d887 100644 --- a/ome_zarr/writer.py +++ b/ome_zarr/writer.py @@ -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