From 340b2f500e78f4304b7fcc82a9564e1171d389c8 Mon Sep 17 00:00:00 2001 From: marqh Date: Mon, 2 Feb 2015 16:55:34 +0000 Subject: [PATCH] implicit shape --- lib/iris/fileformats/grib/_save_rules.py | 10 +++--- .../save_rules/test_shape_of_the_earth.py | 34 ++++++++++++++++--- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/lib/iris/fileformats/grib/_save_rules.py b/lib/iris/fileformats/grib/_save_rules.py index acb1c95f5c..0d31019ced 100644 --- a/lib/iris/fileformats/grib/_save_rules.py +++ b/lib/iris/fileformats/grib/_save_rules.py @@ -1,4 +1,4 @@ -# (C) British Crown Copyright 2010 - 2014, Met Office +# (C) British Crown Copyright 2010 - 2015, Met Office # # This file is part of Iris. # @@ -206,10 +206,10 @@ def shape_of_the_earth(cube, grib): gribapi.grib_set_long(grib, "shapeOfTheEarth", 6) else: gribapi.grib_set_long(grib, "shapeOfTheEarth", 1) - gribapi.grib_set_long(grib, - "scaleFactorOfRadiusOfSphericalEarth", 0) - gribapi.grib_set_long(grib, "scaledValueOfRadiusOfSphericalEarth", - ellipsoid.semi_major_axis) + gribapi.grib_set_long(grib, + "scaleFactorOfRadiusOfSphericalEarth", 0) + gribapi.grib_set_long(grib, "scaledValueOfRadiusOfSphericalEarth", + ellipsoid.semi_major_axis) # Oblate spheroid earth. else: if isinstance(cs, iris.coord_systems.OSGB): diff --git a/lib/iris/tests/unit/fileformats/grib/save_rules/test_shape_of_the_earth.py b/lib/iris/tests/unit/fileformats/grib/save_rules/test_shape_of_the_earth.py index 27aff045d6..de8cdde916 100644 --- a/lib/iris/tests/unit/fileformats/grib/save_rules/test_shape_of_the_earth.py +++ b/lib/iris/tests/unit/fileformats/grib/save_rules/test_shape_of_the_earth.py @@ -1,4 +1,4 @@ -# (C) British Crown Copyright 2014, Met Office +# (C) British Crown Copyright 2014 - 2015, Met Office # # This file is part of Iris. # @@ -28,12 +28,12 @@ import numpy as np -from iris.coord_systems import GeogCS, TransverseMercator, OSGB +from iris.coord_systems import GeogCS, TransverseMercator, OSGB, RotatedGeogCS 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 - +from iris.fileformats.grib._save_rules import grid_definition_template_5 class Test(tests.IrisTest, GdtTestMixin): def setUp(self): @@ -57,7 +57,8 @@ def test_radius_of_earth_6367470(self): test_cube = self._make_test_cube(cs=cs) shape_of_the_earth(test_cube, self.mock_grib) self._check_key('shapeOfTheEarth', 0) - self._spherical_earth_test_common(radius) + self._check_key("scaleFactorOfRadiusOfSphericalEarth", 255) + self._check_key("scaledValueOfRadiusOfSphericalEarth", -1) def test_radius_of_earth_6371229(self): # Test setting shapeOfTheEarth = 6 @@ -66,7 +67,8 @@ def test_radius_of_earth_6371229(self): test_cube = self._make_test_cube(cs=cs) shape_of_the_earth(test_cube, self.mock_grib) self._check_key('shapeOfTheEarth', 6) - self._spherical_earth_test_common(radius) + self._check_key("scaleFactorOfRadiusOfSphericalEarth", 255) + self._check_key("scaledValueOfRadiusOfSphericalEarth", -1) def test_spherical_earth(self): # Test setting shapeOfTheEarth = 1 @@ -110,6 +112,28 @@ def test_TransverseMercator_spherical(self): self._check_key('shapeOfTheEarth', 1) self._spherical_earth_test_common(radius) + def test__shape_of_earth_spherical(self): + cs = RotatedGeogCS(grid_north_pole_latitude=90.0, + grid_north_pole_longitude=0.0, + ellipsoid=GeogCS(52431.0)) + test_cube = self._make_test_cube(cs=cs) + grid_definition_template_5(test_cube, self.mock_grib) + self._check_key('shapeOfTheEarth', 1) + self._check_key('scaleFactorOfRadiusOfSphericalEarth', 0) + self._check_key('scaledValueOfRadiusOfSphericalEarth', 52431.0) + + def test__shape_of_earth_flattened(self): + ellipsoid = GeogCS(semi_major_axis=1456.0, semi_minor_axis=1123.0) + cs = RotatedGeogCS(grid_north_pole_latitude=90.0, + grid_north_pole_longitude=0.0, + ellipsoid=ellipsoid) + test_cube = self._make_test_cube(cs=cs) + grid_definition_template_5(test_cube, self.mock_grib) + self._check_key('shapeOfTheEarth', 7) + self._check_key('scaleFactorOfEarthMajorAxis', 0) + self._check_key('scaledValueOfEarthMajorAxis', 1456.0) + self._check_key('scaleFactorOfEarthMinorAxis', 0) + self._check_key('scaledValueOfEarthMinorAxis', 1123.0) if __name__ == "__main__": tests.main()