-
Notifications
You must be signed in to change notification settings - Fork 297
Improve setting GRIB2 key shapeOfTheEarth
#1491
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
2 commits
Select commit
Hold shift + click to select a range
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
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
142 changes: 142 additions & 0 deletions
142
lib/iris/tests/unit/fileformats/grib/save_rules/test_shape_of_the_earth.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,142 @@ | ||
| # (C) British Crown Copyright 2014, Met Office | ||
| # | ||
| # This file is part of Iris. | ||
| # | ||
| # Iris is free software: you can redistribute it and/or modify it under | ||
| # the terms of the GNU Lesser General Public License as published by the | ||
| # Free Software Foundation, either version 3 of the License, or | ||
| # (at your option) any later version. | ||
| # | ||
| # Iris is distributed in the hope that it will be useful, | ||
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| # GNU Lesser General Public License for more details. | ||
| # | ||
| # You should have received a copy of the GNU Lesser General Public License | ||
| # along with Iris. If not, see <http://www.gnu.org/licenses/>. | ||
| """ | ||
| Unit tests for | ||
| :meth:`iris.fileformats.grib._save_rules.shape_of_the_earth`. | ||
|
|
||
| """ | ||
|
|
||
| from __future__ import (absolute_import, division, print_function) | ||
|
|
||
| # Import iris.tests first so that some things can be initialised before | ||
| # importing anything else. | ||
| import iris.tests as tests | ||
|
|
||
| import numpy as np | ||
|
|
||
| from iris.coord_systems import GeogCS, RotatedGeogCS, TransverseMercator, OSGB | ||
| from iris.exceptions import TranslationError | ||
| from iris.tests.unit.fileformats.grib.save_rules import GdtTestMixin | ||
|
|
||
| from iris.fileformats.grib._save_rules import shape_of_the_earth | ||
|
|
||
|
|
||
| class Test(tests.IrisTest, GdtTestMixin): | ||
| def setUp(self): | ||
| GdtTestMixin.setUp(self) | ||
|
|
||
| def _spherical_earth_test_common(self, radius): | ||
| self._check_key('scaleFactorOfRadiusOfSphericalEarth', 0) | ||
| self._check_key('scaledValueOfRadiusOfSphericalEarth', radius) | ||
|
|
||
| def _oblate_spheroid_earth_test_common(self, semi_major_axis, | ||
| semi_minor_axis): | ||
| self._check_key('scaleFactorOfEarthMajorAxis', 0) | ||
| self._check_key('scaledValueOfEarthMajorAxis', semi_major_axis) | ||
| self._check_key('scaleFactorOfEarthMinorAxis', 0) | ||
| self._check_key('scaledValueOfEarthMinorAxis', semi_minor_axis) | ||
|
|
||
| def test_radius_of_earth_6367470(self): | ||
| # Test setting shapeOfTheEarth = 0 | ||
| radius = 6367470 | ||
| cs = GeogCS(semi_major_axis=radius) | ||
| test_cube = self._make_test_cube(cs=cs) | ||
| shape_of_the_earth(test_cube, self.mock_grib) | ||
| self._check_key('shapeOfTheEarth', 0) | ||
| self._check_key('scaleFactorOfRadiusOfSphericalEarth', 255) | ||
| self._check_key('scaledValueOfRadiusOfSphericalEarth', -1) | ||
|
|
||
| def test_radius_of_earth_6371229(self): | ||
| # Test setting shapeOfTheEarth = 6 | ||
| radius = 6371229 | ||
| cs = GeogCS(semi_major_axis=radius) | ||
| test_cube = self._make_test_cube(cs=cs) | ||
| shape_of_the_earth(test_cube, self.mock_grib) | ||
| self._check_key('shapeOfTheEarth', 6) | ||
| self._check_key('scaleFactorOfRadiusOfSphericalEarth', 255) | ||
| self._check_key('scaledValueOfRadiusOfSphericalEarth', -1) | ||
|
|
||
| def test_spherical_earth(self): | ||
| # Test setting shapeOfTheEarth = 1 | ||
| radius = 1.23 | ||
| cs = GeogCS(semi_major_axis=radius) | ||
| test_cube = self._make_test_cube(cs=cs) | ||
| shape_of_the_earth(test_cube, self.mock_grib) | ||
| self._check_key('shapeOfTheEarth', 1) | ||
| self._spherical_earth_test_common(radius) | ||
|
|
||
| def test_oblate_spheroid_earth(self): | ||
| # Test setting shapeOfTheEarth = 7 | ||
| semi_major_axis = 1.456 | ||
| semi_minor_axis = 1.123 | ||
| cs = GeogCS(semi_major_axis=semi_major_axis, | ||
| semi_minor_axis=semi_minor_axis) | ||
| test_cube = self._make_test_cube(cs=cs) | ||
| shape_of_the_earth(test_cube, self.mock_grib) | ||
| self._check_key('shapeOfTheEarth', 7) | ||
| self._oblate_spheroid_earth_test_common(semi_major_axis, | ||
| semi_minor_axis) | ||
|
|
||
| def test_OSGB(self): | ||
| # Test setting shapeOfTheEarth = 9 | ||
| cs = OSGB() | ||
| # The following are fixed for the OSGB coord system. | ||
| semi_major_axis, semi_minor_axis = (6377563.396, 6356256.909) | ||
| test_cube = self._make_test_cube(cs=cs) | ||
| shape_of_the_earth(test_cube, self.mock_grib) | ||
| self._check_key('shapeOfTheEarth', 9) | ||
| self._oblate_spheroid_earth_test_common(semi_major_axis, | ||
| semi_minor_axis) | ||
|
|
||
| def test_TransverseMercator_spherical(self): | ||
| # Test setting shapeOfTheEarth = 1 with a non-GeogCS coord system. | ||
| cs = TransverseMercator(49, -2, 400000, -100000, 0.9996012717, | ||
| ellipsoid=GeogCS(6377563.396)) | ||
| radius = 6377563.396 | ||
| test_cube = self._make_test_cube(cs=cs) | ||
| shape_of_the_earth(test_cube, self.mock_grib) | ||
| self._check_key('shapeOfTheEarth', 1) | ||
| self._spherical_earth_test_common(radius) | ||
|
|
||
| def test_RotatedGeogCS_spherical(self): | ||
| # Test setting shapeOfTheEarth = 1 with a RotatedGeogCS coord system. | ||
| radius = 52431.0 | ||
| cs = RotatedGeogCS(grid_north_pole_latitude=90.0, | ||
| grid_north_pole_longitude=0.0, | ||
| ellipsoid=GeogCS(radius)) | ||
| test_cube = self._make_test_cube(cs=cs) | ||
| shape_of_the_earth(test_cube, self.mock_grib) | ||
| self._check_key('shapeOfTheEarth', 1) | ||
| self._spherical_earth_test_common(radius) | ||
|
|
||
| def test_RotatedGeogCS_oblate_spheroid(self): | ||
| # Test setting shapeOfTheEarth = 7 with a RotatedGeogCS coord system. | ||
| semi_major_axis = 1456.0 | ||
| semi_minor_axis = 1123.0 | ||
| ellipsoid = GeogCS(semi_major_axis=semi_major_axis, | ||
| semi_minor_axis=semi_minor_axis) | ||
| cs = RotatedGeogCS(grid_north_pole_latitude=90.0, | ||
| grid_north_pole_longitude=0.0, | ||
| ellipsoid=ellipsoid) | ||
| test_cube = self._make_test_cube(cs=cs) | ||
| shape_of_the_earth(test_cube, self.mock_grib) | ||
| self._check_key('shapeOfTheEarth', 7) | ||
| self._oblate_spheroid_earth_test_common(semi_major_axis, | ||
| semi_minor_axis) | ||
|
|
||
| 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know 7 was the previous default, but why not 3?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this appears to me to be due to a default in Cartopy, which expects the units to be metres, not km
However this doesn't appear to be clear in the docstrings
#1491
I will try to get clarity on this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I left 3 out deliberately because separating 3 and 7 is conceptually quite hard as they are effectively identical keys with a difference of a factor of 1000 between them. If we currently support units of m then it seems extraneous to add or change the behaviour to expect km instead...