-
Notifications
You must be signed in to change notification settings - Fork 296
Mesh saveload fix #6004
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
Merged
Mesh saveload fix #6004
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
802a4f3
Remove obsolete code which saves identical meshes separately.
pp-mo 9ab26dc
Better error messages for mis-configured mesh data variables.
pp-mo a4dad3a
Add tests for more intelligible errors.
pp-mo 4b06462
Add licence header.
pp-mo 5365ade
Fix test for changes to mesh saving.
pp-mo e57c30d
Inline method which was used just once, and specific to the use.
pp-mo 993189e
Add whatsnew entry.
pp-mo f7e87f5
Merge branch 'main' into mesh_saveload_fix
ESadek-MO 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
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
83 changes: 83 additions & 0 deletions
83
lib/iris/tests/unit/experimental/ugrid/load/test_meshload_checks.py
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,83 @@ | ||
# Copyright Iris contributors | ||
# | ||
# This file is part of Iris and is released under the BSD license. | ||
# See LICENSE in the root of the repository for full licensing details. | ||
"""Unit tests for mesh handling within iris netcdf loads.""" | ||
|
||
import pytest | ||
|
||
import iris | ||
from iris.experimental.ugrid.load import PARSE_UGRID_ON_LOAD | ||
|
||
from .test_load_meshes import ( | ||
_TEST_CDL_HEAD, | ||
_TEST_CDL_TAIL, | ||
cdl_to_nc, | ||
) | ||
|
||
|
||
class TestMeshLoad: | ||
def _create_testnc(self, location="node", meshdim="node"): | ||
# Add an extra (possibly mal-formed) mesh data to the testfile. | ||
if location is None: | ||
location_cdl = "" | ||
else: | ||
location_cdl = f'extra_data:location = "{location}" ;' | ||
|
||
extra_cdl = f""" | ||
float extra_data(levels, {meshdim}) ; | ||
extra_data:coordinates = "node_x node_y" ; | ||
{location_cdl} | ||
extra_data:mesh = "mesh" ; | ||
""" | ||
# Insert this into the definitions part of the 'standard' testfile CDL | ||
extended_cdl = _TEST_CDL_HEAD + extra_cdl + _TEST_CDL_TAIL | ||
testfile_path = cdl_to_nc(extended_cdl, tmpdir=self.tmpdir) | ||
return testfile_path | ||
|
||
@pytest.fixture(params=["nolocation", "badlocation", "baddim"]) | ||
def failnc(self, request, tmp_path_factory): | ||
self.param = request.param | ||
kwargs = {} | ||
if self.param == "nolocation": | ||
kwargs["location"] = None | ||
elif self.param == "badlocation": | ||
kwargs["location"] = "invalid_location" | ||
elif self.param == "baddim": | ||
kwargs["meshdim"] = "vertex" | ||
else: | ||
raise ValueError(f"unexpected param: {self.param}") | ||
|
||
self.tmpdir = tmp_path_factory.mktemp("meshload") | ||
return self._create_testnc(**kwargs) | ||
|
||
def test_extrameshvar__ok(self, tmp_path_factory): | ||
# Check that the default cdl construction loads OK | ||
self.tmpdir = tmp_path_factory.mktemp("meshload") | ||
testnc = self._create_testnc() | ||
with PARSE_UGRID_ON_LOAD.context(): | ||
iris.load(testnc) | ||
|
||
def test_extrameshvar__fail(self, failnc): | ||
# Check that the expected errors are raised in various cases. | ||
param = self.param | ||
if param == "nolocation": | ||
match_msg = ( | ||
"mesh data variable 'extra_data' has an " "invalid location='<empty>'." | ||
) | ||
elif param == "badlocation": | ||
match_msg = ( | ||
"mesh data variable 'extra_data' has an " | ||
"invalid location='invalid_location'." | ||
) | ||
elif param == "baddim": | ||
match_msg = ( | ||
"mesh data variable 'extra_data' does not have the node mesh " | ||
"dimension 'node', in its dimensions." | ||
) | ||
else: | ||
raise ValueError(f"unexpected param: {param}") | ||
|
||
with PARSE_UGRID_ON_LOAD.context(): | ||
with pytest.raises(ValueError, match=match_msg): | ||
iris.load(failnc) |
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
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.