-
Notifications
You must be signed in to change notification settings - Fork 4
Zarr to irirs Cube: add tests and Zarr sample data #145
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
Closed
Closed
Changes from all commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
eed755f
add a user warning when data is not lazy
valeriupredoi f13b642
add a test module for zarrs
valeriupredoi 3f7cf4a
add tiny Zarr sample data
valeriupredoi 91ce068
add test
valeriupredoi edd6c36
make warning more robust
valeriupredoi 105031f
add Zarr3 test data
valeriupredoi 16fb588
rm erroneous file
valeriupredoi f6c2766
add zarr3 test
valeriupredoi 7846f77
make the warning better
valeriupredoi 2d2c661
full test suite
valeriupredoi 1796100
more general search meth
valeriupredoi ba10ec7
add extra deps and trigger GHA locally
valeriupredoi 74a7c0e
run just a simple pytest session
valeriupredoi d7a2698
pop a conda env file
valeriupredoi 16e28ca
use conda env file in GHA
valeriupredoi 6fdb0b9
run just simple pytest
valeriupredoi 1d6cddd
Merge branch 'main' into add_warning_and_tests
pp-mo 01cce51
Update lib/ncdata/xarray.py
valeriupredoi b7ad9f4
unreference uneeded conda env file
valeriupredoi cc79ff1
restore GHA workflow to original
valeriupredoi e2f607f
add comment
valeriupredoi 773de45
Update lib/ncdata/xarray.py
valeriupredoi edf06ac
remove user warning
valeriupredoi aba9fa6
remove test for warning
valeriupredoi 5f96f32
Merge branch 'add_warning_and_tests' of https://github.com/valeriupre…
valeriupredoi 1fb1db7
readd empty line
valeriupredoi 75e24cf
unrun GHA on push
valeriupredoi b48088a
Update tests/integration/test_zarr_to_iris.py
valeriupredoi 7365729
Update tests/integration/test_zarr_to_iris.py
valeriupredoi 33a9c80
Update tests/integration/test_zarr_to_iris.py
valeriupredoi 0518afe
shorten imports
valeriupredoi 5039d07
Merge branch 'add_warning_and_tests' of https://github.com/valeriupre…
valeriupredoi 8f4e4da
correct test for s3 connection
valeriupredoi 1c21daa
add dependency
valeriupredoi ec91745
remove zarr sample data
valeriupredoi 0d74e97
move zzarr sample data
valeriupredoi b6dd8cb
fix test for new sample data path
valeriupredoi f8dd7be
run pre-commit
valeriupredoi e7df68d
remove unify chunks
valeriupredoi f1a4c46
Merge branch 'main' into add_warning_and_tests
valeriupredoi 2ee710b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,6 @@ | |
| import netCDF4 | ||
| import netCDF4 as nc | ||
| import numpy as np | ||
|
|
||
| from ncdata import NcData, NcVariable | ||
|
|
||
|
|
||
|
|
||
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 |
|---|---|---|
|
|
@@ -3,7 +3,6 @@ | |
|
|
||
| import netCDF4 as nc | ||
| import numpy as np | ||
|
|
||
| from ncdata import NcData, NcVariable | ||
|
|
||
|
|
||
|
|
||
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
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
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
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,111 @@ | ||
| """Test conversion of remote and local Zarr store to iris Cube.""" | ||
|
|
||
| from importlib.resources import files as importlib_files | ||
| from pathlib import Path | ||
|
|
||
| import fsspec | ||
| import iris | ||
| import pytest | ||
| import xarray as xr | ||
| from ncdata.iris_xarray import cubes_from_xarray as conversion_func | ||
|
|
||
|
|
||
| def _return_kwargs(): | ||
| time_coder = xr.coders.CFDatetimeCoder(use_cftime=True) | ||
| return { | ||
| "consolidated": True, | ||
| "decode_times": time_coder, | ||
| "engine": "zarr", | ||
| "chunks": {}, | ||
| "backend_kwargs": {}, | ||
| } | ||
|
|
||
|
|
||
| def _run_checks(cube): | ||
| """Run some standard checks.""" | ||
| assert cube.var_name == "q" | ||
| assert cube.standard_name == "specific_humidity" | ||
| assert cube.long_name is None | ||
| coords = cube.coords() | ||
| coord_names = [coord.standard_name for coord in coords] | ||
| assert "longitude" in coord_names | ||
| assert "latitude" in coord_names | ||
|
|
||
|
|
||
| def test_load_zarr2_local(): | ||
| """Test loading a Zarr2 store from local FS.""" | ||
| zarr_path = ( | ||
| Path(importlib_files("tests")) | ||
| / "testdata" | ||
| / "zarr-sample-data" | ||
| / "example_field_0.zarr2" | ||
| ) | ||
|
|
||
| xr_kwargs = _return_kwargs() | ||
| zarr_xr = xr.open_dataset(zarr_path, **xr_kwargs) | ||
|
|
||
| cubes = conversion_func(zarr_xr) | ||
|
|
||
| assert len(cubes) == 1 | ||
| cube = cubes[0] | ||
| _run_checks(cube) | ||
|
|
||
|
|
||
| def test_load_zarr3_local(): | ||
| """Test loading a Zarr3 store from local FS.""" | ||
| zarr_path = ( | ||
| Path(importlib_files("tests")) | ||
| / "testdata" | ||
| / "zarr-sample-data" | ||
| / "example_field_0.zarr3" | ||
| ) | ||
|
|
||
| xr_kwargs = _return_kwargs() | ||
| zarr_xr = xr.open_dataset(zarr_path, **xr_kwargs) | ||
|
|
||
| cubes = conversion_func(zarr_xr) | ||
|
|
||
| assert len(cubes) == 1 | ||
| cube = cubes[0] | ||
| _run_checks(cube) | ||
|
|
||
|
|
||
| def _is_url_ok(url): | ||
| fs = fsspec.filesystem("http") | ||
| valid_zarr = True | ||
| try: | ||
| fs.open(str(url) + "/zarr.json", "rb") # Zarr3 | ||
| except Exception: # noqa: BLE001 | ||
| try: | ||
| fs.open(str(url) + "/.zmetadata", "rb") # Zarr2 | ||
| except Exception: # noqa: BLE001 | ||
| valid_zarr = False | ||
|
|
||
| return valid_zarr | ||
|
|
||
|
|
||
| S3_TEST_PATH = ( | ||
| "https://uor-aces-o.s3-ext.jc.rl.ac.uk/" | ||
| "esmvaltool-zarr/pr_Amon_CNRM-ESM2-1_02Kpd-11_r1i1p2f2_gr_200601-220112.zarr3" | ||
| ) | ||
| _S3_accessible = _is_url_ok(S3_TEST_PATH) | ||
|
|
||
|
|
||
| @pytest.mark.skipif(not _S3_accessible, reason="S3 url not accessible") | ||
| def test_load_remote_zarr(): | ||
| """Test loading a remote Zarr store. | ||
|
|
||
| This is a ~250MB compressed Zarr in an S3 bucket. | ||
| Conversion is done fully lazily, by passing chunks={} | ||
| to Xarray loader. Test takes ~3-4s and needs ~400MB res mem. | ||
| """ | ||
| zarr_path = S3_TEST_PATH | ||
|
|
||
| xr_kwargs = _return_kwargs() | ||
| zarr_xr = xr.open_dataset(zarr_path, **xr_kwargs) | ||
|
|
||
| cubes = conversion_func(zarr_xr) | ||
|
|
||
| assert isinstance(cubes, iris.cube.CubeList) | ||
| assert len(cubes) == 1 | ||
| assert cubes[0].has_lazy_data() | ||
3 changes: 3 additions & 0 deletions
3
tests/testdata/zarr-sample-data/example_field_0.zarr2/.zattrs
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,3 @@ | ||
| { | ||
| "Conventions": "CF-1.12" | ||
| } |
3 changes: 3 additions & 0 deletions
3
tests/testdata/zarr-sample-data/example_field_0.zarr2/.zgroup
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,3 @@ | ||
| { | ||
| "zarr_format": 2 | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.