-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* basic structure for writing a zarr store containing manifests * write in nicely indented form * use pathlib for everything * documentation * docstrings * vendor zarr.utils.json_dumps * remove consolidated metadata, as v3 doesn't have this yet * license for vendoring part of zarr-python * change to write v3 * implement reading from v3-compliant stores * roundtripping test * forgot to add the file with the test * test dataset-level attributes * debugging print * try explicitly separating files from directories
- Loading branch information
1 parent
08774f7
commit e014bb7
Showing
9 changed files
with
378 additions
and
56 deletions.
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import xarray as xr | ||
import numpy as np | ||
import xarray.testing as xrt | ||
from virtualizarr import open_virtual_dataset, ManifestArray | ||
from virtualizarr.manifests.manifest import ChunkEntry | ||
|
||
|
||
def test_zarr_v3_roundtrip(tmpdir): | ||
arr = ManifestArray( | ||
chunkmanifest={"0.0": ChunkEntry(path="test.nc", offset=6144, length=48)}, | ||
zarray=dict( | ||
shape=(2, 3), | ||
dtype=np.dtype("<i8"), | ||
chunks=(2, 3), | ||
compressor=None, | ||
filters=None, | ||
fill_value=None, | ||
order="C", | ||
zarr_format=3, | ||
), | ||
) | ||
original = xr.Dataset({"a": (["x", "y"], arr)}, attrs={"something": 0}) | ||
|
||
original.virtualize.to_zarr(tmpdir / "store.zarr") | ||
roundtrip = open_virtual_dataset(tmpdir / "store.zarr", filetype="zarr_v3", indexes={}) | ||
|
||
xrt.assert_identical(roundtrip, original) |
Empty file.
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2015-2024 Zarr Developers <https://github.com/zarr-developers> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
Empty file.
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import json | ||
import numbers | ||
|
||
from typing import Any | ||
|
||
|
||
class NumberEncoder(json.JSONEncoder): | ||
def default(self, o): | ||
# See json.JSONEncoder.default docstring for explanation | ||
# This is necessary to encode numpy dtype | ||
if isinstance(o, numbers.Integral): | ||
return int(o) | ||
if isinstance(o, numbers.Real): | ||
return float(o) | ||
return json.JSONEncoder.default(self, o) | ||
|
||
|
||
def json_dumps(o: Any) -> bytes: | ||
"""Write JSON in a consistent, human-readable way.""" | ||
return json.dumps( | ||
o, indent=4, sort_keys=True, ensure_ascii=True, separators=(",", ": "), cls=NumberEncoder | ||
).encode("ascii") |
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.