Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/iris/fileformats/grib/_save_rules.py
Original file line number Diff line number Diff line change
@@ -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.
#
Expand Down Expand Up @@ -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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this tightening necessary? See SciTools#1491 (comment)

# Oblate spheroid earth.
else:
if isinstance(cs, iris.coord_systems.OSGB):
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
#
Expand Down Expand Up @@ -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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function should not be imported in this test module as a test module for this function already exists.


class Test(tests.IrisTest, GdtTestMixin):
def setUp(self):
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per my above. This test should return the correct results without needing to be run through this function first, I believe.

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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above.

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()