Skip to content

Commit 8ec114e

Browse files
author
marqh
committed
implicit shape
1 parent 0004056 commit 8ec114e

File tree

2 files changed

+32
-8
lines changed

2 files changed

+32
-8
lines changed

lib/iris/fileformats/grib/_save_rules.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,10 @@ def shape_of_the_earth(cube, grib):
206206
gribapi.grib_set_long(grib, "shapeOfTheEarth", 6)
207207
else:
208208
gribapi.grib_set_long(grib, "shapeOfTheEarth", 1)
209-
gribapi.grib_set_long(grib,
210-
"scaleFactorOfRadiusOfSphericalEarth", 0)
211-
gribapi.grib_set_long(grib, "scaledValueOfRadiusOfSphericalEarth",
212-
ellipsoid.semi_major_axis)
209+
gribapi.grib_set_long(grib,
210+
"scaleFactorOfRadiusOfSphericalEarth", 0)
211+
gribapi.grib_set_long(grib, "scaledValueOfRadiusOfSphericalEarth",
212+
ellipsoid.semi_major_axis)
213213
# Oblate spheroid earth.
214214
else:
215215
if isinstance(cs, iris.coord_systems.OSGB):

lib/iris/tests/unit/fileformats/grib/save_rules/test_shape_of_the_earth.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@
2828

2929
import numpy as np
3030

31-
from iris.coord_systems import GeogCS, TransverseMercator, OSGB
31+
from iris.coord_systems import GeogCS, TransverseMercator, OSGB, RotatedGeogCS
3232
from iris.exceptions import TranslationError
3333
from iris.tests.unit.fileformats.grib.save_rules import GdtTestMixin
3434

3535
from iris.fileformats.grib._save_rules import shape_of_the_earth
36-
36+
from iris.fileformats.grib._save_rules import grid_definition_template_5
3737

3838
class Test(tests.IrisTest, GdtTestMixin):
3939
def setUp(self):
@@ -57,7 +57,8 @@ def test_radius_of_earth_6367470(self):
5757
test_cube = self._make_test_cube(cs=cs)
5858
shape_of_the_earth(test_cube, self.mock_grib)
5959
self._check_key('shapeOfTheEarth', 0)
60-
self._spherical_earth_test_common(radius)
60+
self._check_key("scaleFactorOfRadiusOfSphericalEarth", 255)
61+
self._check_key("scaledValueOfRadiusOfSphericalEarth", -1)
6162

6263
def test_radius_of_earth_6371229(self):
6364
# Test setting shapeOfTheEarth = 6
@@ -66,7 +67,8 @@ def test_radius_of_earth_6371229(self):
6667
test_cube = self._make_test_cube(cs=cs)
6768
shape_of_the_earth(test_cube, self.mock_grib)
6869
self._check_key('shapeOfTheEarth', 6)
69-
self._spherical_earth_test_common(radius)
70+
self._check_key("scaleFactorOfRadiusOfSphericalEarth", 255)
71+
self._check_key("scaledValueOfRadiusOfSphericalEarth", -1)
7072

7173
def test_spherical_earth(self):
7274
# Test setting shapeOfTheEarth = 1
@@ -110,6 +112,28 @@ def test_TransverseMercator_spherical(self):
110112
self._check_key('shapeOfTheEarth', 1)
111113
self._spherical_earth_test_common(radius)
112114

115+
def test__shape_of_earth_spherical(self):
116+
cs = RotatedGeogCS(grid_north_pole_latitude=90.0,
117+
grid_north_pole_longitude=0.0,
118+
ellipsoid=GeogCS(52431.0))
119+
test_cube = self._make_test_cube(cs=cs)
120+
grid_definition_template_5(test_cube, self.mock_grib)
121+
self._check_key('shapeOfTheEarth', 1)
122+
self._check_key('scaleFactorOfRadiusOfSphericalEarth', 0)
123+
self._check_key('scaledValueOfRadiusOfSphericalEarth', 52431.0)
124+
125+
def test__shape_of_earth_flattened(self):
126+
ellipsoid = GeogCS(semi_major_axis=1456.0, semi_minor_axis=1123.0)
127+
cs = RotatedGeogCS(grid_north_pole_latitude=90.0,
128+
grid_north_pole_longitude=0.0,
129+
ellipsoid=ellipsoid)
130+
test_cube = self._make_test_cube(cs=cs)
131+
grid_definition_template_5(test_cube, self.mock_grib)
132+
self._check_key('shapeOfTheEarth', 7)
133+
self._check_key('scaleFactorOfEarthMajorAxis', 0)
134+
self._check_key('scaledValueOfEarthMajorAxis', 1456.0)
135+
self._check_key('scaleFactorOfEarthMinorAxis', 0)
136+
self._check_key('scaledValueOfEarthMinorAxis', 1123.0)
113137

114138
if __name__ == "__main__":
115139
tests.main()

0 commit comments

Comments
 (0)