-
Notifications
You must be signed in to change notification settings - Fork 44
Save LAEA grid #343
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
trexfeathers
merged 7 commits into
SciTools:main
from
abooton:add_LAEA_template_140_saving
Nov 21, 2023
Merged
Save LAEA grid #343
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
56a2885
Add saving for the Lambert Azimuthual Equal Area grid
abooton 55ab21e
fix line length test_grid_definition_template_140.py
abooton 8c6d1fc
Fix LambertAzimuthalEqualArea import
abooton 70d35ef
flake8
abooton fd05ca8
Altering names standardParallel to standardParallelInMicrodegrees and…
abooton 9ab66a5
Add: Raise execption if false_easting or false_northing is not zero
abooton 9ca9e7f
Fixing string comparison in __fail_false_easting_northing test
abooton 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
133 changes: 133 additions & 0 deletions
133
iris_grib/tests/unit/save_rules/test_grid_definition_template_140.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,133 @@ | ||
| # Copyright iris-grib contributors | ||
| # | ||
| # This file is part of iris-grib 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 :meth:`iris_grib._save_rules.grid_definition_template_140`. | ||
| """ | ||
|
|
||
| # Import iris_grib.tests first so that some things can be initialised before | ||
| # importing anything else. | ||
| import iris_grib.tests as tests | ||
|
|
||
| import numpy as np | ||
|
|
||
| import iris.coords | ||
| from iris.coord_systems import GeogCS, LambertAzimuthalEqualArea | ||
| from iris.exceptions import TranslationError | ||
|
|
||
| from iris_grib._save_rules import ( | ||
| grid_definition_template_140 as grid_definition_template, | ||
| ) | ||
| from iris_grib.tests.unit.save_rules import GdtTestMixin | ||
|
|
||
|
|
||
| class FakeGribError(Exception): | ||
| pass | ||
|
|
||
|
|
||
| class Test(tests.IrisGribTest, GdtTestMixin): | ||
| def setUp(self): | ||
| self.default_ellipsoid = GeogCS(semi_major_axis=6377563.396, | ||
| semi_minor_axis=6356256.909) | ||
| self.test_cube = self._make_test_cube() | ||
|
|
||
| GdtTestMixin.setUp(self) | ||
|
|
||
| def _make_test_cube(self, cs=None, x_points=None, y_points=None): | ||
| # Create a cube with given properties, or minimal defaults. | ||
| if cs is None: | ||
| cs = self._default_coord_system() | ||
| if x_points is None: | ||
| x_points = self._default_x_points() | ||
| if y_points is None: | ||
| y_points = self._default_y_points() | ||
|
|
||
| x_coord = iris.coords.DimCoord(x_points, 'projection_x_coordinate', | ||
| units='m', coord_system=cs) | ||
| y_coord = iris.coords.DimCoord(y_points, 'projection_y_coordinate', | ||
| units='m', coord_system=cs) | ||
| test_cube = iris.cube.Cube(np.zeros((len(y_points), len(x_points)))) | ||
| test_cube.add_dim_coord(y_coord, 0) | ||
| test_cube.add_dim_coord(x_coord, 1) | ||
| return test_cube | ||
|
|
||
| def _default_coord_system(self, false_easting=0, false_northing=0): | ||
| return LambertAzimuthalEqualArea(latitude_of_projection_origin=54.9, | ||
| longitude_of_projection_origin=-2.5, | ||
| false_easting=false_easting, | ||
| false_northing=false_northing, | ||
| ellipsoid=self.default_ellipsoid) | ||
|
|
||
| def test__template_number(self): | ||
| grid_definition_template(self.test_cube, self.mock_grib) | ||
| self._check_key('gridDefinitionTemplateNumber', 140) | ||
|
|
||
| def test__shape_of_earth(self): | ||
| grid_definition_template(self.test_cube, self.mock_grib) | ||
| self._check_key('shapeOfTheEarth', 7) | ||
| self._check_key('scaleFactorOfEarthMajorAxis', 0) | ||
| self._check_key('scaledValueOfEarthMajorAxis', 6377563.396) | ||
| self._check_key('scaleFactorOfEarthMinorAxis', 0) | ||
| self._check_key('scaledValueOfEarthMinorAxis', 6356256.909) | ||
|
|
||
| def test__grid_shape(self): | ||
| test_cube = self._make_test_cube(x_points=np.arange(13), | ||
| y_points=np.arange(6)) | ||
| grid_definition_template(test_cube, self.mock_grib) | ||
| self._check_key('Nx', 13) | ||
| self._check_key('Ny', 6) | ||
|
|
||
| def test__grid_points(self): | ||
| test_cube = self._make_test_cube(x_points=[1e6, 3e6, 5e6, 7e6], | ||
| y_points=[4e6, 9e6]) | ||
| grid_definition_template(test_cube, self.mock_grib) | ||
| self._check_key("latitudeOfFirstGridPoint", 81330008) | ||
| self._check_key("longitudeOfFirstGridPoint", 98799008) | ||
| self._check_key("Dx", 2e9) | ||
| self._check_key("Dy", 5e9) | ||
|
|
||
| # specific to grid_definition_template_140 | ||
| def test__template_specifics(self): | ||
| grid_definition_template(self.test_cube, self.mock_grib) | ||
| self._check_key("standardParallelInMicrodegrees", 54900000) | ||
| self._check_key("centralLongitudeInMicrodegrees", 357500000) | ||
|
|
||
| def test__scanmode(self): | ||
| grid_definition_template(self.test_cube, self.mock_grib) | ||
| self._check_key('iScansPositively', 1) | ||
| self._check_key('jScansPositively', 1) | ||
|
|
||
| def test__scanmode_reverse(self): | ||
| test_cube = self._make_test_cube(x_points=np.arange(7e6, 0, -1e6)) | ||
| grid_definition_template(test_cube, self.mock_grib) | ||
| self._check_key('iScansPositively', 0) | ||
| self._check_key('jScansPositively', 1) | ||
|
|
||
| def __fail_false_easting_northing(self, false_easting, false_northing): | ||
| cs = self._default_coord_system(false_easting=false_easting, | ||
| false_northing=false_northing) | ||
| test_cube = self._make_test_cube(cs=cs) | ||
| msg = ('non zero false easting ({:.2f}) or ' | ||
| 'non zero false northing ({:.2f})' | ||
| '; unsupported by GRIB Template 3.140' | ||
| '.').format(false_easting, false_northing) | ||
trexfeathers marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| with self.assertRaisesRegex( | ||
| TranslationError, | ||
| msg): | ||
| grid_definition_template(test_cube, self.mock_grib) | ||
|
|
||
| def test__fail_false_easting(self): | ||
| self.__fail_false_easting_northing(10.0, 0.0) | ||
|
|
||
| def test__fail_false_northing(self): | ||
| self.__fail_false_easting_northing(0.0, 10.0) | ||
|
|
||
| def test__fail_false_easting_northing(self): | ||
| self.__fail_false_easting_northing(10.0, 10.0) | ||
|
|
||
|
|
||
| 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.