Skip to content
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 reader #271

Open
wants to merge 90 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
26a94df
wip toward zarr v2 reader
norlandrhagen Oct 24, 2024
cfb7b8d
removed _ARRAY_DIMENSIONS and trimmed down attrs
norlandrhagen Oct 24, 2024
2f26f03
WIP for zarr reader
norlandrhagen Oct 24, 2024
eab87a6
adding in the key piece, the reader
norlandrhagen Oct 24, 2024
13db375
virtual dataset is returned! Now to deal with fill_value
norlandrhagen Oct 31, 2024
cc30ad7
Merge branch 'main' into zarr_reader
norlandrhagen Nov 12, 2024
a047ff9
Update virtualizarr/readers/zarr.py
norlandrhagen Nov 12, 2024
072bead
Merge branch 'zarr_reader' of https://github.com/zarr-developers/Virt…
norlandrhagen Nov 12, 2024
f7c9a3f
replace fsspec ls with zarr.getsize
norlandrhagen Nov 15, 2024
2024606
lint
norlandrhagen Nov 15, 2024
443435b
wip test_zarr
norlandrhagen Nov 15, 2024
50fd8b5
removed pdb
norlandrhagen Nov 15, 2024
d93c932
zarr import in type checking
norlandrhagen Nov 19, 2024
39be1c5
moved get_chunk_paths & get_chunk_size async funcs outside of constru…
norlandrhagen Nov 19, 2024
e718240
added a few notes from PR review.
norlandrhagen Nov 19, 2024
bbcd473
removed array encoding
norlandrhagen Nov 19, 2024
ed9f2b4
v2 passing, v3 skipped for now
norlandrhagen Nov 19, 2024
db89da7
added missed staged files
norlandrhagen Nov 19, 2024
e3d4318
fixed merge conflicts with main
norlandrhagen Nov 19, 2024
410b2a3
missing return
norlandrhagen Nov 19, 2024
8a69963
add network
norlandrhagen Nov 19, 2024
3fca8e6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 19, 2024
34053b0
conftest fix
norlandrhagen Nov 19, 2024
5c26b1f
naming
norlandrhagen Nov 19, 2024
fb784dc
comment out integration test for now
norlandrhagen Nov 19, 2024
0444fd4
refactored test_dataset_from_zarr ZArray tests
norlandrhagen Nov 20, 2024
66fd456
adds zarr v3 req opt
norlandrhagen Nov 20, 2024
13fce09
zarr_v3 decorator
norlandrhagen Nov 20, 2024
c36962d
add more tests
norlandrhagen Nov 20, 2024
4be4906
wip
norlandrhagen Nov 21, 2024
ca5ff32
adds missing await
norlandrhagen Nov 21, 2024
88cbeca
more tests
norlandrhagen Nov 21, 2024
1fbdc9c
wip
norlandrhagen Nov 21, 2024
370621f
wip on v3
norlandrhagen Nov 21, 2024
9bb0653
add note + xfail v3
norlandrhagen Nov 21, 2024
7e03ea5
tmp run network
norlandrhagen Nov 21, 2024
5c1e331
revert
norlandrhagen Nov 21, 2024
9404625
update construct_virtual_array ordering
norlandrhagen Nov 22, 2024
1a5a960
merge
norlandrhagen Dec 3, 2024
cc7d68c
updated ABC after merge
norlandrhagen Dec 3, 2024
ac105ea
wip
norlandrhagen Dec 9, 2024
7b57bd0
Merge branch 'main' into zarr_reader
norlandrhagen Dec 9, 2024
ff01c92
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 9, 2024
4f2470a
working for v2 and v3, but only local
norlandrhagen Dec 10, 2024
0c1ff82
merge
norlandrhagen Dec 10, 2024
05d4050
cleanup test_zarr reader test
norlandrhagen Dec 11, 2024
f40ba28
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 11, 2024
b5fb802
cleanup after zarr-python issue report
norlandrhagen Dec 12, 2024
be5280f
Merge branch 'zarr_reader' of https://github.com/zarr-developers/Virt…
norlandrhagen Dec 12, 2024
690ffee
temp disabled validate_and_normalize_path_to_uri due to issue in zarr…
norlandrhagen Dec 16, 2024
98600e7
Merge branch 'main' into zarr_reader
norlandrhagen Dec 16, 2024
31a1b94
marked zarr integration test skipped b/c of zarr-v3 and kerchunk inco…
norlandrhagen Dec 16, 2024
795c428
fixes some async behavior, reading from s3 seems to work
norlandrhagen Dec 17, 2024
c0004c6
lint + uri_fmt
norlandrhagen Dec 17, 2024
60b8912
adds to releases.rst
norlandrhagen Dec 17, 2024
8240997
nit
norlandrhagen Dec 17, 2024
816e696
cleanup, comments and nits
norlandrhagen Dec 17, 2024
31aacf9
progress on mypy
norlandrhagen Dec 17, 2024
5d14b20
make mypy happy
norlandrhagen Dec 17, 2024
fb844b6
adds option for AsyncArray to _is_zarr_array
norlandrhagen Dec 18, 2024
421f53f
big async rewrite
norlandrhagen Dec 19, 2024
cedad11
merge w/ main
norlandrhagen Dec 19, 2024
1c5e42d
fixes merge conflict
norlandrhagen Dec 19, 2024
89d8555
bit of restructure
norlandrhagen Dec 19, 2024
c1a5218
nit
norlandrhagen Dec 19, 2024
6af84b4
WIP on ChunkManifest.from_arrays
norlandrhagen Dec 20, 2024
349386f
v2/v3 c chunk fix + build ChunkManifest from numpy arrays
norlandrhagen Dec 21, 2024
c776ab9
removed method of creating ChunkManifests from dicts
norlandrhagen Dec 21, 2024
fb6fff7
cleanup
norlandrhagen Dec 21, 2024
87c74d4
adds xfails to TestOpenVirtualDatasetZarr due to local filesystem zar…
norlandrhagen Dec 21, 2024
9e44a8a
Merge branch 'main' into zarr_reader
norlandrhagen Jan 9, 2025
87dbdae
some nits after merging w/ main
norlandrhagen Jan 9, 2025
855fb5a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 9, 2025
29434f1
updates zarr v3 req
norlandrhagen Jan 9, 2025
0dcfc91
Merge branch 'zarr_reader' of https://github.com/zarr-developers/Virt…
norlandrhagen Jan 9, 2025
5f7040c
lint
norlandrhagen Jan 9, 2025
d3b0a92
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 9, 2025
4716114
remove build_chunk_manifest_from_dict_mapping function since manifest…
norlandrhagen Jan 9, 2025
32f7060
Merge branch 'zarr_reader' of https://github.com/zarr-developers/Virt…
norlandrhagen Jan 9, 2025
dc6e6f8
tmp ignore lint
norlandrhagen Jan 9, 2025
9db4339
remove zarr fill_value skip
norlandrhagen Jan 9, 2025
4e0fb99
fixes network req import in test_integration
norlandrhagen Jan 9, 2025
72ae8b0
bump xarray to 2025.1.1 and icechunk to 0.1.0a10 in upstream
norlandrhagen Jan 9, 2025
177f2cf
merge w/ dep bump
norlandrhagen Jan 9, 2025
d61e593
move zarr import into type checking
norlandrhagen Jan 9, 2025
9edf706
move zarr import in test_zarr
norlandrhagen Jan 9, 2025
3e68537
adding back in missing nbytes property
norlandrhagen Jan 9, 2025
594d4a8
typing
norlandrhagen Jan 9, 2025
3c6dc54
tmp testing & removing old xfail
norlandrhagen Jan 10, 2025
dd20c8a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,24 @@ def netcdf4_file(tmpdir):
return filepath


@pytest.fixture()
def zarr_v2_store(tmpdir):
# Set up example xarray dataset
ds = xr.tutorial.open_dataset("air_temperature", chunks={})
# grabbing a piece and making sure there are multiple chunks present (2): Frozen({'time': (5, 5), 'lat': (9,), 'lon': (18,)})
chunked_subset = ds.isel(
time=slice(0, 10), lat=slice(0, 9), lon=slice(0, 18)
).chunk({"time": 5})

# Save it to disk as netCDF (in temporary directory)
filepath = f"{tmpdir}/air.zarr"

chunked_subset.to_zarr(filepath, zarr_format=2)
ds.close()

return filepath


@pytest.fixture
def netcdf4_virtual_dataset(netcdf4_file):
from virtualizarr import open_virtual_dataset
Expand Down
9 changes: 5 additions & 4 deletions virtualizarr/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@
KerchunkVirtualBackend,
NetCDF3VirtualBackend,
TIFFVirtualBackend,
ZarrV3VirtualBackend,
ZarrV3ChunkManifestVirtualBackend, # If this is kept, we should incorporate it into ZarrVirtualBackend
ZarrVirtualBackend,
)
from virtualizarr.utils import _FsspecFSFromFilepath, check_for_collisions

# TODO add entrypoint to allow external libraries to add to this mapping
VIRTUAL_BACKENDS = {
"kerchunk": KerchunkVirtualBackend,
"zarr_v3": ZarrV3VirtualBackend,
"zarr_v3": ZarrV3ChunkManifestVirtualBackend,
"zarr": ZarrVirtualBackend,
"dmrpp": DMRPPVirtualBackend,
# all the below call one of the kerchunk backends internally (https://fsspec.github.io/kerchunk/reference.html#file-format-backends)
"netcdf3": NetCDF3VirtualBackend,
Expand Down Expand Up @@ -71,8 +73,7 @@ def automatically_determine_filetype(

# TODO how do we handle kerchunk json / parquet here?
if Path(filepath).suffix == ".zarr":
# TODO we could imagine opening an existing zarr store, concatenating it, and writing a new virtual one...
raise NotImplementedError()
return FileType.zarr

# Read magic bytes from local or remote file
fpath = _FsspecFSFromFilepath(
Expand Down
8 changes: 6 additions & 2 deletions virtualizarr/readers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
from virtualizarr.readers.kerchunk import KerchunkVirtualBackend
from virtualizarr.readers.netcdf3 import NetCDF3VirtualBackend
from virtualizarr.readers.tiff import TIFFVirtualBackend
from virtualizarr.readers.zarr_v3 import ZarrV3VirtualBackend
from virtualizarr.readers.zarr import (
ZarrV3ChunkManifestVirtualBackend,
ZarrVirtualBackend,
)

__all__ = [
"DMRPPVirtualBackend",
Expand All @@ -13,5 +16,6 @@
"KerchunkVirtualBackend",
"NetCDF3VirtualBackend",
"TIFFVirtualBackend",
"ZarrV3VirtualBackend",
"ZarrVirtualBackend",
"ZarrV3ChunkManifestVirtualBackend",
]
18 changes: 13 additions & 5 deletions virtualizarr/readers/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,27 @@ def open_loadable_vars_and_indexes(
# TODO we are reading a bunch of stuff we know we won't need here, e.g. all of the data variables...
# TODO it would also be nice if we could somehow consolidate this with the reading of the kerchunk references
# TODO really we probably want a dedicated xarray backend that iterates over all variables only once
fpath = _FsspecFSFromFilepath(
filepath=filepath, reader_options=reader_options
).open_file()

# fpath can be `Any` thanks to fsspec.filesystem(...).open() returning Any.
# We'll (hopefully safely) cast it to what xarray is expecting, but this might let errors through.
fpath = _FsspecFSFromFilepath(filepath=filepath, reader_options=reader_options)

# Update the xarray open_dataset kwargs if Zarr

if fpath.filepath.suffix == ".zarr":
engine = "zarr"
xr_input = fpath.filepath

else:
engine = None
xr_input = fpath.open_file()

ds = open_dataset(
cast(XArrayOpenT, fpath),
cast(XArrayOpenT, xr_input),
drop_variables=drop_variables,
group=group,
decode_times=decode_times,
engine=engine,
)

if indexes is None:
Expand All @@ -87,7 +96,6 @@ def open_loadable_vars_and_indexes(
raise NotImplementedError()
else:
indexes = dict(**indexes) # for type hinting: to allow mutation

# TODO we should drop these earlier by using drop_variables
loadable_vars = {
str(name): var
Expand Down
Loading
Loading