-
Notifications
You must be signed in to change notification settings - Fork 171
Sharing of representative datasets via compressed Zarr zips #2570
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
Merged
+184
−32
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
b6567ea
Add test_from_xarray_dataset_dict
VeckoTheGecko 2d66397
Add tooling for serializing and deserializing from JSON
VeckoTheGecko 3e55fbf
Account for datetimes by serializing to iso strings
VeckoTheGecko 3f1979f
Refactor to json.JSON*coder classes
VeckoTheGecko d247a70
Add note on cftime compat with error messaging
VeckoTheGecko ee0fa10
Update test
VeckoTheGecko f0b7b51
Update names
VeckoTheGecko 18cb1fb
Add compression option
VeckoTheGecko b848ad3
TMP: Add script to compare dumping metadata file sizes
VeckoTheGecko 67e63fb
Migrate to zarr compression
VeckoTheGecko e16cb4c
Fix script
VeckoTheGecko bc29541
Update script
VeckoTheGecko 4616898
Add informative error messaging
VeckoTheGecko 9f191b6
Update tests
VeckoTheGecko 03357ae
Update `posting-issues.md` doc page
VeckoTheGecko f633c6a
Update array replacement
VeckoTheGecko 074bd49
fix
VeckoTheGecko 18a845f
Remove script
VeckoTheGecko d9ad51c
Add test against different datasets
VeckoTheGecko 975dd75
Remove from_xarray_dataset_dict
VeckoTheGecko 5b9aa91
copy
VeckoTheGecko b758bee
Add comments
VeckoTheGecko b8678a9
Update docstring
VeckoTheGecko c64dace
Remove typevars
VeckoTheGecko ebb0a7a
Remove unused helper
VeckoTheGecko 3566c3f
Remove dep
VeckoTheGecko 1e56824
Add comment
VeckoTheGecko 9845be9
Update docs
VeckoTheGecko f4c2876
Update docs according to review feedback
VeckoTheGecko 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 hidden or 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 hidden or 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 hidden or 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
VeckoTheGecko marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or 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,79 @@ | ||
| import numpy as np | ||
| import pytest | ||
| import xarray as xr | ||
|
|
||
| from parcels._datasets import utils | ||
| from parcels._datasets.structured.generic import datasets | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def nonzero_ds(): | ||
| """Small dataset with nonzero data_vars and non-index coords for replace_arrays_with_zeros tests. | ||
|
|
||
| Uses 2D lon/lat as coords so they are regular (non-index) variables that can be zeroed. | ||
| """ | ||
| import dask.array as da | ||
|
|
||
| lon = np.array([[1.0, 2.0, 3.0, 4.0]] * 3) | ||
| lat = np.array([[10.0] * 4, [20.0] * 4, [30.0] * 4]) | ||
| return xr.Dataset( | ||
| { | ||
| "U": (["y", "x"], da.from_array(np.ones((3, 4)), chunks=-1)), | ||
| "V": (["y", "x"], da.from_array(np.full((3, 4), 2.0), chunks=-1)), | ||
| }, | ||
| coords={ | ||
| "lon": (["y", "x"], da.from_array(lon, chunks=-1)), | ||
| "lat": (["y", "x"], da.from_array(lat, chunks=-1)), | ||
| }, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("ds", [pytest.param(v, id=k) for k, v in datasets.items()]) | ||
| @pytest.mark.parametrize("except_for", [None, "coords"]) | ||
| def test_replace_arrays_with_zeros(ds, except_for): | ||
| # make sure doesn't error with range of datasets | ||
| utils.replace_arrays_with_zeros(ds, except_for=except_for) | ||
|
|
||
|
|
||
| def test_replace_arrays_with_zeros_none(nonzero_ds): | ||
| """except_for=None: all data_vars and coords replaced with zeros.""" | ||
| result = utils.replace_arrays_with_zeros(nonzero_ds, except_for=None) | ||
|
|
||
| for k in set(result.data_vars) | set(result.coords): | ||
| assert np.all(result[k].values == 0), f"{k!r} should be zero" | ||
|
|
||
|
|
||
| def test_replace_arrays_with_zeros_coords(nonzero_ds): | ||
| """except_for='coords': data_vars zeroed, coords preserved.""" | ||
| result = utils.replace_arrays_with_zeros(nonzero_ds, except_for="coords") | ||
|
|
||
| for k in result.data_vars: | ||
| assert np.all(result[k].values == 0), f"data_var {k!r} should be zero" | ||
|
|
||
| np.testing.assert_array_equal(result["lon"].values, nonzero_ds["lon"].values) | ||
| np.testing.assert_array_equal(result["lat"].values, nonzero_ds["lat"].values) | ||
|
|
||
|
|
||
| def test_replace_arrays_with_zeros_list(nonzero_ds): | ||
| """except_for=[...]: listed variables preserved, others zeroed.""" | ||
| result = utils.replace_arrays_with_zeros(nonzero_ds, except_for=["U", "lon"]) | ||
|
|
||
| np.testing.assert_array_equal(result["U"].values, nonzero_ds["U"].values) | ||
| np.testing.assert_array_equal(result["lon"].values, nonzero_ds["lon"].values) | ||
| assert np.all(result["V"].values == 0), "V should be zero" | ||
| assert np.all(result["lat"].values == 0), "lat should be zero" | ||
|
|
||
|
|
||
| def test_replace_arrays_with_zeros_does_not_mutate(nonzero_ds): | ||
| """Original dataset is not modified.""" | ||
| original_U = nonzero_ds["U"].values.copy() | ||
| original_lon = nonzero_ds["lon"].values.copy() | ||
| utils.replace_arrays_with_zeros(nonzero_ds, except_for=None) | ||
| np.testing.assert_array_equal(nonzero_ds["U"].values, original_U) | ||
| np.testing.assert_array_equal(nonzero_ds["lon"].values, original_lon) | ||
|
|
||
|
|
||
| def test_replace_arrays_with_zeros_invalid_key(nonzero_ds): | ||
| """Invalid key in except_for raises ValueError.""" | ||
| with pytest.raises(ValueError, match="not a valid item"): | ||
| utils.replace_arrays_with_zeros(nonzero_ds, except_for=["nonexistent"]) |
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.
Uh oh!
There was an error while loading. Please reload this page.