Skip to content

Commit

Permalink
Merge pull request #1606 from marqh/gribProcessedData
Browse files Browse the repository at this point in the history
Grib processed data
  • Loading branch information
bjlittle committed Apr 7, 2015
2 parents 7890a72 + 8967474 commit b1d38ca
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 3 deletions.
15 changes: 12 additions & 3 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 @@ -164,9 +164,18 @@ def identification(cube, grib):
# operational product, operational test, research product, etc
# (missing for now)
gribapi.grib_set_long(grib, "productionStatusOfProcessedData", 255)

# Code table 1.4
# analysis, forecast, processed satellite, processed radar,
# (analysis and forecast products for now)
gribapi.grib_set_long(grib, "typeOfProcessedData", 2)
if cube.coords('realization'):
# assume realization will always have 1 and only 1 point
# as cubes saving to GRIB2 a 2D horizontal slices
if cube.coord('realization').points[0] != 0:
gribapi.grib_set_long(grib, "typeOfProcessedData", 4)
else:
gribapi.grib_set_long(grib, "typeOfProcessedData", 3)
else:
gribapi.grib_set_long(grib, "typeOfProcessedData", 2)


###############################################################################
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# (C) British Crown Copyright 2015, Met Office
#
# This file is part of Iris.
#
# Iris 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 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. If not, see <http://www.gnu.org/licenses/>.
"""Unit tests for `iris.fileformats.grib.grib_save_rules.identification`."""

from __future__ import (absolute_import, division, print_function)

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

import gribapi
import mock

import iris.fileformats.grib
from iris.fileformats.grib._save_rules import identification
import iris.tests.stock as stock
from iris.tests.test_grib_load import TestGribSimple


GRIB_API = 'iris.fileformats.grib._save_rules.gribapi'


class Test(TestGribSimple):
@tests.skip_data
def test_no_realization(self):
cube = stock.simple_pp()
grib = mock.Mock()
mock_gribapi = mock.Mock(spec=gribapi)
with mock.patch(GRIB_API, mock_gribapi):
identification(cube, grib)

mock_gribapi.assert_has_calls(
[mock.call.grib_set_long(grib, "typeOfProcessedData", 2)])

@tests.skip_data
def test_realization_0(self):
cube = stock.simple_pp()
realisation = iris.coords.AuxCoord((0,), standard_name='realization',
units='1')
cube.add_aux_coord(realisation)

grib = mock.Mock()
mock_gribapi = mock.Mock(spec=gribapi)
with mock.patch(GRIB_API, mock_gribapi):
identification(cube, grib)

mock_gribapi.assert_has_calls(
[mock.call.grib_set_long(grib, "typeOfProcessedData", 3)])

@tests.skip_data
def test_realization_n(self):
cube = stock.simple_pp()
realisation = iris.coords.AuxCoord((2,), standard_name='realization',
units='1')
cube.add_aux_coord(realisation)

grib = mock.Mock()
mock_gribapi = mock.Mock(spec=gribapi)
with mock.patch(GRIB_API, mock_gribapi):
identification(cube, grib)

mock_gribapi.assert_has_calls(
[mock.call.grib_set_long(grib, "typeOfProcessedData", 4)])


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

0 comments on commit b1d38ca

Please sign in to comment.