def test_product_definition(self, mock_set):
        cube = self.cube
        cell_method = CellMethod(method="sum", coords=["time"])
        cube.add_cell_method(cell_method)

        product_definition_template_8(cube, mock.sentinel.grib)
        mock_set.assert_any_call(mock.sentinel.grib, "productDefinitionTemplateNumber", 8)
    def test_product_definition(self, mock_set):
        cube = self.cube
        cell_method = CellMethod(method='sum', coords=['time'])
        cube.add_cell_method(cell_method)

        product_definition_template_8(cube, mock.sentinel.grib)
        mock_set.assert_any_call(mock.sentinel.grib,
                                 "productDefinitionTemplateNumber", 8)
 def test_cell_method_coord_name_fail(self, mock_set):
     cube = self.cube
     cell_method = CellMethod(method='mean', coords=['season'])
     cube.add_cell_method(cell_method)
     with self.assertRaisesRegexp(
             ValueError, "Expected a cell method with a coordinate "
             "name of 'time'"):
         product_definition_template_8(cube, mock.sentinel.grib)
 def test_multiple_cell_method_coords(self, mock_set):
     cube = self.cube
     cell_method = CellMethod(method='sum',
                              coords=['time', 'forecast_period'])
     cube.add_cell_method(cell_method)
     with self.assertRaisesRegexp(ValueError,
                                  'Cannot handle multiple coordinate name'):
         product_definition_template_8(cube, mock.sentinel.grib)
    def test_unrecognised(self, mock_set):
        cube = self.cube
        cell_method = CellMethod(method='95th percentile', coords=['time'])
        cube.add_cell_method(cell_method)

        product_definition_template_8(cube, mock.sentinel.grib)
        mock_set.assert_any_call(mock.sentinel.grib,
                                 "typeOfStatisticalProcessing", 255)
 def test_multiple_points(self, mock_set):
     # Add time coord with multiple points.
     coord = DimCoord([23, 24, 25], 'time',
                      bounds=[[22, 23], [23, 24], [24, 25]],
                      units=Unit('days since epoch', calendar='standard'))
     self.cube.add_aux_coord(coord, 0)
     with self.assertRaisesRegexp(
             ValueError, 'Expected length one time coordinate'):
         product_definition_template_8(self.cube, mock.sentinel.grib)
 def test_more_than_two_bounds(self, mock_set):
     # Add time coord with more than two bounds.
     coord = DimCoord(23, 'time', bounds=[21, 22, 23],
                      units=Unit('days since epoch', calendar='standard'))
     self.cube.add_aux_coord(coord)
     with self.assertRaisesRegexp(
             ValueError, 'Expected time coordinate with two bounds, '
             'got 3 bounds'):
         product_definition_template_8(self.cube, mock.sentinel.grib)
Beispiel #8
0
 def test_stats_type_max(self, mock_set):
     grib = None
     cube = iris.cube.Cube(np.array([1.0]))
     time_unit = iris.unit.Unit('hours since 1970-01-01 00:00:00')
     time_coord = iris.coords.DimCoord([0.0],
                                       bounds=[0.0, 1],
                                       standard_name='time',
                                       units=time_unit)
     cube.add_aux_coord(time_coord, ())
     cube.add_cell_method(iris.coords.CellMethod('minimum', time_coord))
     grib_save_rules.product_definition_template_8(cube, grib)
     mock_set.assert_any_call(grib, "typeOfStatisticalProcessing", 3)
 def test_stats_type_max(self, mock_set):
     grib = None
     cube = iris.cube.Cube(np.array([1.0]))
     time_unit = iris.unit.Unit('hours since 1970-01-01 00:00:00')
     time_coord = iris.coords.DimCoord([0.0],
                                       bounds=[0.0, 1],
                                       standard_name='time',
                                       units=time_unit)
     cube.add_aux_coord(time_coord, ())
     cube.add_cell_method(iris.coords.CellMethod('minimum', time_coord))
     grib_save_rules.product_definition_template_8(cube, grib)
     mock_set.assert_any_call(grib, "typeOfStatisticalProcessing", 3)
    def test_other_cell_methods(self, mock_set):
        cube = stock.lat_lon_cube()
        # Rename cube to avoid warning about unknown discipline/parameter.
        cube.rename('air_temperature')
        coord = DimCoord(23, 'time', bounds=[0, 24],
                         units=Unit('hours since epoch'))
        cube.add_aux_coord(coord)
        # Add one time cell method and another unrelated one.
        cell_method = CellMethod(method='mean', coords=['elephants'])
        cube.add_cell_method(cell_method)
        cell_method = CellMethod(method='sum', coords=['time'])
        cube.add_cell_method(cell_method)

        product_definition_template_8(cube, mock.sentinel.grib)
        mock_set.assert_any_call(mock.sentinel.grib, 'numberOfTimeRange', 1)
    def test_360_day_calendar(self, mock_set):
        cube = self.cube
        # End bound is 1972-05-07 10:27:07
        coord = DimCoord(23.0, 'time', bounds=[0.452, 20314.452],
                         units=Unit('hours since epoch', calendar='360_day'))
        cube.add_aux_coord(coord)

        grib = mock.sentinel.grib
        product_definition_template_8(cube, grib)

        mock_set.assert_any_call(
            grib, "yearOfEndOfOverallTimeInterval", 1972)
        mock_set.assert_any_call(
            grib, "monthOfEndOfOverallTimeInterval", 5)
        mock_set.assert_any_call(
            grib, "dayOfEndOfOverallTimeInterval", 7)
        mock_set.assert_any_call(
            grib, "hourOfEndOfOverallTimeInterval", 10)
        mock_set.assert_any_call(
            grib, "minuteOfEndOfOverallTimeInterval", 27)
        mock_set.assert_any_call(
            grib, "secondOfEndOfOverallTimeInterval", 7)