-
Notifications
You must be signed in to change notification settings - Fork 19
Feat/masks review #199
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
Feat/masks review #199
Changes from all commits
f5974f6
03a181b
c958c05
5098759
e1e5958
a71f8a2
875a122
a50c718
9b577b4
a81f765
9c50040
9f1cc34
8e6e08d
f9c193c
446ec01
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,13 +25,14 @@ | |
|
|
||
|
|
||
| @cached(collection="grids", encoding="npz") | ||
| def _grids(name: str | list[float] | tuple[float, ...]) -> bytes: | ||
| """Get grid data by name. | ||
| def _get_grid_data(grid_id: str | list[float] | tuple[float, float]) -> bytes: | ||
| """Get grid data from the grid registry by identifier. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| name : str | ||
| The name of the grid | ||
| grid_id : str | list[float] | tuple[float, float] | ||
| The identifier of the grid, either a string like "o96" or a tuple/list | ||
| of two numbers (describing the resolution). | ||
|
Contributor
Author
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. For info: renamed function and added more info to docstring
Contributor
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.
Contributor
Author
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. Changed to |
||
|
|
||
| Returns | ||
| ------- | ||
|
|
@@ -40,30 +41,29 @@ def _grids(name: str | list[float] | tuple[float, ...]) -> bytes: | |
| """ | ||
| from anemoi.utils.config import load_config | ||
|
|
||
| if isinstance(name, (tuple, list)): | ||
| assert len(name) == 2, "Grid name must be a list or a tuple of length 2" | ||
| assert all(isinstance(i, (int, float)) for i in name), "Grid name must be a list or a tuple of numbers" | ||
| if name[0] == name[1]: | ||
| name = str(float(name[0])) | ||
| if isinstance(grid_id, (tuple, list)): | ||
| assert len(grid_id) == 2, "Grid name must be a list or a tuple of length 2" | ||
| assert all(isinstance(i, (int, float)) for i in grid_id), "Grid name must be a list or a tuple of numbers" | ||
| if grid_id[0] == grid_id[1]: | ||
| grid_id = str(float(grid_id[0])) | ||
| else: | ||
| name = str(float(name[0])) + "x" + str(float(name[1])) | ||
| name = name.replace(".", "p") | ||
| grid_id = str(float(grid_id[0])) + "x" + str(float(grid_id[1])) | ||
| grid_id = grid_id.replace(".", "p") | ||
|
|
||
| user_path = load_config().get("utils", {}).get("grids_path") | ||
| if user_path: | ||
| path = os.path.expanduser(os.path.join(user_path, f"grid-{name}.npz")) | ||
| path = os.path.expanduser(os.path.join(user_path, f"grid-{grid_id}.npz")) | ||
| if os.path.exists(path): | ||
| LOG.warning("Loading grids from custom user path %s", path) | ||
| with open(path, "rb") as f: | ||
| return f.read() | ||
| else: | ||
| LOG.warning("Custom user path %s does not exist", path) | ||
|
|
||
| # To add a grid | ||
| # To generate a grid | ||
| # anemoi-transform get-grid --source mars grid=o400,levtype=sfc,param=2t grid-o400.npz | ||
| # nexus-cli -u xxxx -p yyyy -s GET_INSTANCE --repository anemoi upload --remote-path grids --local-path grid-o400.npz | ||
|
|
||
| url = GRIDS_URL_PATTERN.format(name=name.lower()) | ||
| url = GRIDS_URL_PATTERN.format(name=grid_id.lower()) | ||
| LOG.warning("Downloading grids from %s", url) | ||
| response = requests.get(url) | ||
| response.raise_for_status() | ||
|
|
@@ -83,9 +83,6 @@ def lookup(name: str | list[float] | tuple[float, ...]) -> dict: | |
| dict | ||
| The grid data | ||
| """ | ||
| if isinstance(name, str) and name.endswith(".npz"): | ||
| return dict(np.load(name)) | ||
|
|
||
| data = _grids(name) | ||
| npz = np.load(BytesIO(data)) | ||
| return dict(npz) | ||
| is_npz_file = isinstance(name, str) and name.endswith(".npz") | ||
| data = name if is_npz_file else BytesIO(_get_grid_data(name)) | ||
| return dict(np.load(data)) | ||
yoel-zerah marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,8 +15,7 @@ | |
| # granted to it by virtue of its status as an intergovernmental organisation | ||
| # nor does it submit to any jurisdiction. | ||
|
|
||
| import logging | ||
|
|
||
| import pytest | ||
| from anemoi.utils.testing import cli_testing | ||
| from anemoi.utils.testing import skip_if_missing_command | ||
| from anemoi.utils.testing import skip_if_offline | ||
|
|
@@ -25,11 +24,10 @@ | |
|
|
||
| from .utils import compare_npz_files | ||
|
|
||
| LOG = logging.getLogger(__name__) | ||
yoel-zerah marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| @skip_if_offline | ||
| @skip_if_missing_command("mir") | ||
| @pytest.mark.slow | ||
| def test_make_regrid_matrix(get_test_data): | ||
| era5 = get_test_data("anemoi-transform/filters/regrid/2t-ea.grib") | ||
| carra = get_test_data("anemoi-transform/filters/regrid/2t-rr.grib") | ||
|
|
@@ -61,6 +59,7 @@ def test_regrid_matrix(get_test_data, test_source): | |
|
|
||
|
|
||
| @skip_if_offline | ||
| @pytest.mark.slow | ||
|
Contributor
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. where are we using this? as in do those run then at PR level, nightly or which is the frequency?
Contributor
Author
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. By default we won't be running them in the CI, which is as the same as in |
||
| def test_make_regrid_mask(get_test_data): | ||
| era5 = get_test_data("anemoi-transform/filters/regrid/2t-ea.grib") | ||
| carra = get_test_data("anemoi-transform/filters/regrid/2t-rr.grib") | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.