-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Zarr v3 #404
Open
will-moore
wants to merge
38
commits into
ome:master
Choose a base branch
from
will-moore:zarr_v3
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Zarr v3 #404
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
b0d6b3d
Basic read example working (no labels)
will-moore da8c32f
cli_tests passing
will-moore 19b89a8
Passing all 6 test_io.py
will-moore a954161
Passing tests/test_io.py and test_node.py
will-moore 80f6e01
Include dtype in group.create_array()
will-moore e568911
Uncomment labels spec. Fixes test_ome_zarr.py download
will-moore b49ecc8
Fix test_scaler
will-moore 18abe02
Add dimension_separator to existing v2 data .zarray to fix test_upgra…
will-moore 86142c3
Fixed test_write_image_dask
will-moore 31584bf
Pin zarr==v3.0.0-beta.1
will-moore daa3546
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] fa29ccc
Remove python 3.9 and 3.10 from build.yml
will-moore 8fc02b4
Remove unused imports
will-moore 29890b8
remove fsspec from .isort.cfg
will-moore 35bc979
mypy fix
will-moore 75ba690
Use Blosc compression by default
will-moore 52aceb0
Black formatting fixes
will-moore 55d4ba9
Use group.array_values() for iterating arrays
will-moore 0ea21bc
Use zarr_format=2 for zarr.open() in test_writer.py
will-moore 7fc113b
Fix return type RemoteStore | LocalStore
will-moore 94f7ace
Support reading of Zarr v3 data
will-moore d140c6d
Hard-code zarr_version=2 in parse_url()
will-moore f7b5f98
Use read_only instead of mode when creating Stores
will-moore c527c77
Pin zarr-python to specific commit on main branch
will-moore d8d5378
Fix test_write_image_compressed
will-moore 2138160
Support READING of zarr v3 data
will-moore af2648d
Merge remote-tracking branch 'origin/master' into zarr_v3. Use zarr v…
will-moore 1ea9e1a
Check that PR is green IF we skip test_writer with 3D-scale-True-from…
will-moore 7754774
Bump dependencies including zarr==v3.0.0-beta.3 in docs/requirements.txt
will-moore 499531f
Specify python 3.12 in .readthedocs.yml
will-moore c0fe50d
Merge remote-tracking branch 'origin/master' into zarr_v3
will-moore e021c13
Merge remote-tracking branch 'origin/master' into zarr_v3
joshmoore 0a8d0b4
test fixes
will-moore c953723
Merge remote-tracking branch 'gh/zarr_v3' into zarr_v3
will-moore 4f2a4b1
Merge remote-tracking branch 'origin/master' into zarr_v3
will-moore 50e43c1
Rename zarr.storage.RemoteStore to FsspecStore
will-moore 6c4ba92
_blosc_compressor() helper and other zarr-python fixes
will-moore 872ce11
Use zarr_format=2 for download dask.to_zarr()
will-moore File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
sphinx==7.1.2 | ||
sphinx==8.1.3 | ||
sphinx-rtd-theme==3.0.2 | ||
fsspec | ||
zarr | ||
zarr>=v3.0.0 | ||
dask | ||
numpy | ||
scipy | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,14 +3,14 @@ | |
Primary entry point is the :func:`~ome_zarr.io.parse_url` method. | ||
""" | ||
|
||
import json | ||
import logging | ||
from pathlib import Path | ||
from typing import Optional, Union | ||
from urllib.parse import urljoin | ||
|
||
import dask.array as da | ||
from zarr.storage import FSStore | ||
import zarr | ||
from zarr.storage import FsspecStore, LocalStore, StoreLike | ||
|
||
from .format import CurrentFormat, Format, detect_format | ||
from .types import JSONDict | ||
|
@@ -20,7 +20,7 @@ | |
|
||
class ZarrLocation: | ||
""" | ||
IO primitive for reading and writing Zarr data. Uses FSStore for all | ||
IO primitive for reading and writing Zarr data. Uses a store for all | ||
data access. | ||
|
||
No assumptions about the existence of the given path string are made. | ||
|
@@ -29,7 +29,7 @@ class ZarrLocation: | |
|
||
def __init__( | ||
self, | ||
path: Union[Path, str, FSStore], | ||
path: StoreLike, | ||
mode: str = "r", | ||
fmt: Format = CurrentFormat(), | ||
) -> None: | ||
|
@@ -40,18 +40,21 @@ def __init__( | |
self.__path = str(path.resolve()) | ||
elif isinstance(path, str): | ||
self.__path = path | ||
elif isinstance(path, FSStore): | ||
elif isinstance(path, FsspecStore): | ||
self.__path = path.path | ||
elif isinstance(path, LocalStore): | ||
self.__path = str(path.root) | ||
else: | ||
raise TypeError(f"not expecting: {type(path)}") | ||
|
||
loader = fmt | ||
if loader is None: | ||
loader = CurrentFormat() | ||
self.__store: FSStore = ( | ||
path if isinstance(path, FSStore) else loader.init_store(self.__path, mode) | ||
self.__store: FsspecStore = ( | ||
path | ||
if isinstance(path, FsspecStore) | ||
else loader.init_store(self.__path, mode) | ||
) | ||
|
||
self.__init_metadata() | ||
detected = detect_format(self.__metadata, loader) | ||
LOGGER.debug("ZarrLocation.__init__ %s detected: %s", path, detected) | ||
|
@@ -67,16 +70,41 @@ def __init_metadata(self) -> None: | |
""" | ||
Load the Zarr metadata files for the given location. | ||
""" | ||
self.zarray: JSONDict = self.get_json(".zarray") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can |
||
self.zgroup: JSONDict = self.get_json(".zgroup") | ||
self.zgroup: JSONDict = {} | ||
self.zarray: JSONDict = {} | ||
self.__metadata: JSONDict = {} | ||
self.__exists: bool = True | ||
if self.zgroup: | ||
self.__metadata = self.get_json(".zattrs") | ||
elif self.zarray: | ||
self.__metadata = self.get_json(".zattrs") | ||
else: | ||
self.__exists = False | ||
# If we want to *create* a new zarr v2 group, we need to specify | ||
# zarr_format. This is not needed for reading. | ||
zarr_format = None | ||
if self.__mode == "w": | ||
# For now, let's support writing of zarr v2 | ||
# TODO: handle writing of zarr v2 OR zarr v3 | ||
zarr_format = 2 | ||
try: | ||
group = zarr.open_group( | ||
store=self.__store, path="/", mode=self.__mode, zarr_format=zarr_format | ||
) | ||
self.zgroup = group.attrs.asdict() | ||
# For zarr v3, everything is under the "ome" namespace | ||
if "ome" in self.zgroup: | ||
self.zgroup = self.zgroup["ome"] | ||
self.__metadata = self.zgroup | ||
except (ValueError, FileNotFoundError): | ||
try: | ||
array = zarr.open_array( | ||
store=self.__store, | ||
path="/", | ||
mode=self.__mode, | ||
zarr_format=zarr_format, | ||
) | ||
self.zarray = array.attrs.asdict() | ||
self.__metadata = self.zarray | ||
except (ValueError, FileNotFoundError): | ||
# We actually get a ValueError when the file is not found | ||
# /zarr-python/src/zarr/abc/store.py", line 189, in _check_writable | ||
# raise ValueError("store mode does not support writing") | ||
self.__exists = False | ||
|
||
def __repr__(self) -> str: | ||
"""Print the path as well as whether this is a group or an array.""" | ||
|
@@ -104,7 +132,7 @@ def path(self) -> str: | |
return self.__path | ||
|
||
@property | ||
def store(self) -> FSStore: | ||
def store(self) -> FsspecStore: | ||
"""Return the initialized store for this location""" | ||
assert self.__store is not None | ||
return self.__store | ||
|
@@ -154,11 +182,9 @@ def get_json(self, subpath: str) -> JSONDict: | |
All other exceptions log at the ERROR level. | ||
""" | ||
try: | ||
data = self.__store.get(subpath) | ||
if not data: | ||
return {} | ||
return json.loads(data) | ||
except KeyError: | ||
array_or_group = zarr.open_group(store=self.__store, path="/") | ||
return array_or_group.attrs.asdict() | ||
except (KeyError, FileNotFoundError): | ||
LOGGER.debug("JSON not found: %s", subpath) | ||
return {} | ||
except Exception: | ||
|
@@ -193,10 +219,11 @@ def _isfile(self) -> bool: | |
Return whether the current underlying implementation | ||
points to a local file or not. | ||
""" | ||
return self.__store.fs.protocol == "file" or self.__store.fs.protocol == ( | ||
"file", | ||
"local", | ||
) | ||
# return self.__store.fs.protocol == "file" or self.__store.fs.protocol == ( | ||
# "file", | ||
# "local", | ||
# ) | ||
return isinstance(self.__store, LocalStore) | ||
|
||
def _ishttp(self) -> bool: | ||
""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would also checking for LocalStore here work?