Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion iris_grib/_save_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,7 @@ def product_definition_template_1(cube, grib, full3d_cube=None):

"""
gribapi.grib_set(grib, "productDefinitionTemplateNumber", 1)
product_definition_template_common(cube, grib)
product_definition_template_common(cube, grib, full3d_cube)
Copy link
Member

Choose a reason for hiding this comment

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

Whoops ?!?
Another reason to have more integration tests, if this could get missed.

set_ensemble(cube, grib)


Expand Down
21 changes: 21 additions & 0 deletions iris_grib/tests/integration/round_trip/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# (C) British Crown Copyright 2018, Met Office
#
# This file is part of iris-grib.
#
# iris-grib is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# iris-grib is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with iris-grib. If not, see <http://www.gnu.org/licenses/>.
"""Integration tests for the :mod:`iris_grib._load_convert` and
:mod:`iris_grib._save_rules` packages."""

from __future__ import (absolute_import, division, print_function)
from six.moves import (filter, input, map, range, zip) # noqa
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# (C) British Crown Copyright 2018, Met Office
#
# This file is part of iris-grib.
#
# iris-grib is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# iris-grib is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with iris-grib. If not, see <http://www.gnu.org/licenses/>.
"""
Integration test for round-trip loading and saving of hybrid height and
hybrid pressure cubes.
"""

from __future__ import (absolute_import, division, print_function)
from six.moves import (filter, input, map, range, zip) # noqa

# import iris_grib.tests first so that some things can be initialised
# before importing anything else.
import iris_grib.tests as tests

from iris import load_cube, load_cubes, save
from iris.experimental.equalise_cubes import equalise_attributes


class TestHybridHeightRoundTrip(tests.IrisGribTest):
def setUp(self):
self.filepath = self.get_testdata_path(
Copy link
Member

Choose a reason for hiding this comment

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

Not sure this is actually worth a separate "setUp".
Depends if this will get shared with any other possible tests (later, presumably).

'faked_sample_hh_grib_data.grib2')
self.out_path = self.get_result_path(
Copy link
Member

Choose a reason for hiding this comment

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

I wouldn't store these results here (or even create this branch of the repo), as these are transient results.
Files living in tests/results should really be "independent" data that we want to store in the repo as a reference to compare results against.
Instead, I think it's appropriate to create temporary files which are then removed afterwards, using this pattern ...

'../results/integration/round_trips')
self.out_name = '/hybrid_height_cube.grib2'
self.outfile = self.out_path + self.out_name

def test_hybrid_height(self):
# Load air temperature cube.
cube, ref_cube = load_cubes(self.filepath,
('air_temperature', 'surface_altitude'))
# Save cubes separately
save([cube, ref_cube], self.outfile)
saved_cube = load_cube(self.outfile, 'air_temperature')
self.assertTrue(saved_cube == cube)


class TestHybridPressureRoundTrip(tests.IrisGribTest):
def setUp(self):
self.filepath = self.get_testdata_path(
'faked_sample_hp_grib_data.grib2')
self.out_path = self.get_result_path(
'../results/integration/round_trips')
self.out_name = '/hybrid_pressure_cube.grib2'
self.outfile = self.out_path + self.out_name

def test_hybrid_pressure(self):
# Load air temperature cube and surface air pressure reference cube
cube, ref_cube = load_cubes(self.filepath,
('air_temperature', 'air_pressure'))
# Save cubes separately
save([cube, ref_cube], self.outfile)
saved_cube = load_cube(self.outfile, 'air_temperature')

# Currently all attributes are lost when saving to grib, so we must
# equalise them in order to successfully compare all other aspects.
equalise_attributes([saved_cube, cube])

self.assertTrue(saved_cube == cube)




Binary file not shown.
Binary file not shown.