-
Notifications
You must be signed in to change notification settings - Fork 300
Simple support for selective netcdf loading. #4176
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
81330fb
Ultra-simple support for selective netcdf loading.
pp-mo 61c3c19
Add tests, support for var_name, whatsnew
lbdreyer e0167b8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] fa5561b
move _translate_constraints_to_var_callback to private function
lbdreyer faa14ef
review actions
lbdreyer 35d7022
[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
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
100 changes: 100 additions & 0 deletions
100
lib/iris/tests/unit/fileformats/netcdf/test__translate_constraints_to_var_callback.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,100 @@ | ||
| # Copyright Iris contributors | ||
| # | ||
| # This file is part of Iris and is released under the LGPL license. | ||
| # See COPYING and COPYING.LESSER in the root of the repository for full | ||
| # licensing details. | ||
| """ | ||
| Unit tests for | ||
| :func:`iris.fileformats.netcdf._translate_constraints_to_var_callback`. | ||
|
|
||
| """ | ||
|
|
||
| from unittest.mock import MagicMock | ||
|
|
||
| import iris | ||
| from iris.fileformats.cf import CFDataVariable | ||
| from iris.fileformats.netcdf import _translate_constraints_to_var_callback | ||
|
|
||
| # import iris tests first so that some things can be initialised before | ||
| # importing anything else | ||
| import iris.tests as tests | ||
|
|
||
|
|
||
| class Test(tests.IrisTest): | ||
| data_variables = [ | ||
| CFDataVariable("var1", MagicMock(standard_name="x_wind")), | ||
| CFDataVariable("var2", MagicMock(standard_name="y_wind")), | ||
| CFDataVariable("var1", MagicMock(long_name="x component of wind")), | ||
| CFDataVariable( | ||
| "var1", | ||
| MagicMock(standard_name="x_wind", long_name="x component of wind"), | ||
| ), | ||
| CFDataVariable("var1", MagicMock()), | ||
| ] | ||
|
|
||
| def test_multiple_constraints(self): | ||
| constrs = [ | ||
| iris.NameConstraint(standard_name="x_wind"), | ||
| iris.NameConstraint(var_name="var1"), | ||
| ] | ||
| result = _translate_constraints_to_var_callback(constrs) | ||
| self.assertIsNone(result) | ||
|
|
||
| def test_non_NameConstraint(self): | ||
| constr = iris.AttributeConstraint(STASH="m01s00i002") | ||
| result = _translate_constraints_to_var_callback(constr) | ||
| self.assertIsNone(result) | ||
|
|
||
| def test_str_constraint(self): | ||
| result = _translate_constraints_to_var_callback("x_wind") | ||
| self.assertIsNone(result) | ||
|
|
||
| def test_Constaint_with_name(self): | ||
| constr = iris.Constraint(name="x_wind") | ||
| result = _translate_constraints_to_var_callback(constr) | ||
| self.assertIsNone(result) | ||
|
|
||
| def test_NameConstraint_standard_name(self): | ||
| constr = iris.NameConstraint(standard_name="x_wind") | ||
| callback = _translate_constraints_to_var_callback(constr) | ||
| result = [callback(var) for var in self.data_variables] | ||
| self.assertArrayEqual(result, [True, False, False, True, False]) | ||
|
|
||
| def test_NameConstraint_long_name(self): | ||
| constr = iris.NameConstraint(long_name="x component of wind") | ||
| callback = _translate_constraints_to_var_callback(constr) | ||
| result = [callback(var) for var in self.data_variables] | ||
| self.assertArrayEqual(result, [False, False, True, True, False]) | ||
|
|
||
| def test_NameConstraint_var_name(self): | ||
| constr = iris.NameConstraint(var_name="var1") | ||
| callback = _translate_constraints_to_var_callback(constr) | ||
| result = [callback(var) for var in self.data_variables] | ||
| self.assertArrayEqual(result, [True, False, True, True, True]) | ||
|
|
||
| def test_NameConstraint_standard_name_var_name(self): | ||
| constr = iris.NameConstraint(standard_name="x_wind", var_name="var1") | ||
| callback = _translate_constraints_to_var_callback(constr) | ||
| result = [callback(var) for var in self.data_variables] | ||
| self.assertArrayEqual(result, [True, False, False, True, False]) | ||
|
|
||
| def test_NameConstraint_standard_name_long_name_var_name(self): | ||
| constr = iris.NameConstraint( | ||
| standard_name="x_wind", | ||
| long_name="x component of wind", | ||
| var_name="var1", | ||
| ) | ||
| callback = _translate_constraints_to_var_callback(constr) | ||
| result = [callback(var) for var in self.data_variables] | ||
| self.assertArrayEqual(result, [False, False, False, True, False]) | ||
|
|
||
| def test_NameConstraint_with_STASH(self): | ||
| constr = iris.NameConstraint( | ||
| standard_name="x_wind", STASH="m01s00i024" | ||
| ) | ||
| result = _translate_constraints_to_var_callback(constr) | ||
| self.assertIsNone(result) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| tests.main() |
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.