Skip to content

Commit 9e1775f

Browse files
committed
Add: Raise execption if false_easting or false_northing is not zero
1 parent fd05ca8 commit 9e1775f

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

iris_grib/_save_rules.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,12 @@ def grid_definition_template_140(cube, grib):
707707
central_lon / _DEFAULT_DEGREES_UNITS)
708708
eccodes.codes_set(grib, 'resolutionAndComponentFlags',
709709
0x1 << _RESOLUTION_AND_COMPONENTS_GRID_WINDS_BIT)
710+
if cs.false_easting != 0.0 or cs.false_northing != 0.0:
711+
msg = ('non zero false easting ({:.2f}) or '
712+
'non zero false northing ({:.2f})'
713+
'; unsupported by GRIB Template 3.140'
714+
'.').format(cs.false_easting, cs.false_northing)
715+
raise TranslationError(rf"{msg}")
710716

711717

712718
def grid_definition_section(cube, grib):

iris_grib/tests/unit/save_rules/test_grid_definition_template_140.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import iris.coords
1818
from iris.coord_systems import GeogCS, LambertAzimuthalEqualArea
19+
from iris.exceptions import TranslationError
1920

2021
from iris_grib._save_rules import (
2122
grid_definition_template_140 as grid_definition_template,
@@ -53,9 +54,11 @@ def _make_test_cube(self, cs=None, x_points=None, y_points=None):
5354
test_cube.add_dim_coord(x_coord, 1)
5455
return test_cube
5556

56-
def _default_coord_system(self):
57+
def _default_coord_system(self, false_easting=0, false_northing=0):
5758
return LambertAzimuthalEqualArea(latitude_of_projection_origin=54.9,
5859
longitude_of_projection_origin=-2.5,
60+
false_easting=false_easting,
61+
false_northing=false_northing,
5962
ellipsoid=self.default_ellipsoid)
6063

6164
def test__template_number(self):
@@ -103,6 +106,28 @@ def test__scanmode_reverse(self):
103106
self._check_key('iScansPositively', 0)
104107
self._check_key('jScansPositively', 1)
105108

109+
def __fail_false_easting_northing(self, false_easting, false_northing):
110+
cs = self._default_coord_system(false_easting=false_easting,
111+
false_northing=false_northing)
112+
test_cube = self._make_test_cube(cs=cs)
113+
msg = ('non zero false easting ({:.2f}) or '
114+
'non zero false northing ({:.2f})'
115+
'; unsupported by GRIB Template 3.140'
116+
'.').format(false_easting, false_northing)
117+
with self.assertRaisesRegex(
118+
TranslationError,
119+
rf"{msg}"):
120+
grid_definition_template(test_cube, self.mock_grib)
121+
122+
def test__fail_false_easting(self):
123+
self.__fail_false_easting_northing(10, 0)
124+
125+
def test__fail_false_northing(self):
126+
self.__fail_false_easting_northing(0, 10)
127+
128+
def test__fail_false_easting_northing(self):
129+
self.__fail_false_easting_northing(10, 10)
130+
106131

107132
if __name__ == "__main__":
108133
tests.main()

0 commit comments

Comments
 (0)