Exemplo n.º 1
0
    def test_numpy_array(self, mock_set_double, grib_set_double_array):
        grib = None
        cube = iris.cube.Cube(np.array([1,2,3,4,5])) 

        grib_save_rules.data(cube, grib)

        mock_set_double.assert_any_call(grib, "missingValue", float(-1e9))
Exemplo n.º 2
0
    def test_numpy_array(self, mock_set_double, grib_set_double_array):
        grib = None
        cube = iris.cube.Cube(np.array([1, 2, 3, 4, 5]))

        grib_save_rules.data(cube, grib)

        mock_set_double.assert_any_call(grib, "missingValue", float(-1e9))
Exemplo n.º 3
0
    def test_masked_array(self, mock_set, mock_set_double, grib_set_double_array):
        grib = None
        cube = iris.cube.Cube(ma.MaskedArray([1,2,3,4,5], fill_value=54321)) 

        grib_save_rules.data(cube, grib)

        mock_set_double.assert_any_call(grib, "missingValue", float(54321))
Exemplo n.º 4
0
    def test_masked_array(self, mock_set, mock_set_double, grib_set_double_array):
        grib = None
        cube = iris.cube.Cube(ma.MaskedArray([1,2,3,4,5], fill_value=54321))

        grib_save_rules.data(cube, grib)

        mock_set_double.assert_any_call(grib, "missingValue", float(54321))
Exemplo n.º 5
0
 def test_simple(self):
     # Check the simple case of non-masked data with no scaling.
     cube = iris.cube.Cube(np.arange(5))
     grib_message = mock.sentinel.GRIB_MESSAGE
     with mock.patch(GRIB_API) as grib_api:
         data(cube, grib_message)
     # Check the use of a mask has been turned off.
     self.assertBitmapOff(grib_api)
     # Check the correct data values have been set.
     self.assertValues(grib_api, np.arange(5))
Exemplo n.º 6
0
 def test_scaling(self, mock_set_double, mock_set_double_array):
     # Show that data type known to be stored as %ge gets scaled
     grib = None
     cube = iris.cube.Cube(np.array([0.0, 0.25, 1.0]),
                           standard_name='cloud_area_fraction',
                           units=iris.unit.Unit('0.5'))
     grib_save_rules.data(cube, grib)
     callargs = mock_set_double_array.call_args_list
     self.assertEqual(len(callargs), 1)
     self.assertEqual(callargs[0][0][:2], (None, "values"))
     self.assertArrayAlmostEqual(callargs[0][0][2],
                                 np.array([0.0, 12.5, 50.0]))
Exemplo n.º 7
0
 def test_masked_with_finite_fill_value(self):
     cube = iris.cube.Cube(np.ma.MaskedArray([1.0, 2.0, 3.0, 1.0, 2.0, 3.0],
                                             mask=[0, 0, 0, 1, 1, 1],
                                             fill_value=2000))
     grib_message = mock.sentinel.GRIB_MESSAGE
     with mock.patch(GRIB_API) as grib_api:
         data(cube, grib_message)
     # Check the use of a mask has been turned on.
     FILL = 2000
     self.assertBitmapOn(grib_api, FILL)
     # Check the correct data values have been set.
     self.assertValues(grib_api, [1, 2, 3, FILL, FILL, FILL])
Exemplo n.º 8
0
 def test_scaled(self):
     # If the Cube's units don't match the units required by GRIB
     # ensure the data values are scaled correctly.
     cube = iris.cube.Cube(np.arange(5),
                           standard_name='geopotential_height', units='km')
     grib_message = mock.sentinel.GRIB_MESSAGE
     with mock.patch(GRIB_API) as grib_api:
         data(cube, grib_message)
     # Check the use of a mask has been turned off.
     self.assertBitmapOff(grib_api)
     # Check the correct data values have been set.
     self.assertValues(grib_api, np.arange(5) * 1000)
Exemplo n.º 9
0
 def test_masked_with_nan_fill_value(self):
     cube = iris.cube.Cube(np.ma.MaskedArray([1.0, 2.0, 3.0, 1.0, 2.0, 3.0],
                                             mask=[0, 0, 0, 1, 1, 1],
                                             fill_value=np.nan))
     grib_message = mock.sentinel.GRIB_MESSAGE
     with mock.patch(GRIB_API) as grib_api:
         data(cube, grib_message)
     # Check the use of a mask has been turned on and a suitable fill
     # value has been chosen.
     FILL = self.assertBitmapRange(grib_api, 1, 3)
     # Check the correct data values have been set.
     self.assertValues(grib_api, [1, 2, 3, FILL, FILL, FILL])
Exemplo n.º 10
0
 def test_scaling(self, mock_set_double, mock_set_double_array):
     # Show that data type known to be stored as %ge gets scaled
     grib = None
     cube = iris.cube.Cube(np.array([0.0, 0.25, 1.0]),
                           standard_name='cloud_area_fraction',
                           units=iris.unit.Unit('0.5'))
     grib_save_rules.data(cube, grib)
     callargs = mock_set_double_array.call_args_list
     self.assertEqual(len(callargs), 1)
     self.assertEqual(callargs[0][0][:2], (None, "values"))
     self.assertArrayAlmostEqual(callargs[0][0][2],
                                 np.array([0.0, 12.5, 50.0]))
Exemplo n.º 11
0
 def test_scaled_with_finite_fill_value(self):
     # When re-scaling masked data with a finite fill value, ensure
     # the fill value and any filled values are also re-scaled.
     cube = iris.cube.Cube(np.ma.MaskedArray([1.0, 2.0, 3.0, 1.0, 2.0, 3.0],
                                             mask=[0, 0, 0, 1, 1, 1],
                                             fill_value=2000),
                           standard_name='geopotential_height', units='km')
     grib_message = mock.sentinel.GRIB_MESSAGE
     with mock.patch(GRIB_API) as grib_api:
         data(cube, grib_message)
     # Check the use of a mask has been turned on.
     FILL = 2000 * 1000
     self.assertBitmapOn(grib_api, FILL)
     # Check the correct data values have been set.
     self.assertValues(grib_api, [1000, 2000, 3000, FILL, FILL, FILL])
Exemplo n.º 12
0
 def test_scaled_with_nan_fill_value(self):
     # When re-scaling masked data with a NaN fill value, ensure
     # a fill value is chosen which allows for the scaling, and any
     # filled values match the chosen fill value.
     cube = iris.cube.Cube(np.ma.MaskedArray([-1.0, 2.0, -1.0, 2.0],
                                             mask=[0, 0, 1, 1],
                                             fill_value=np.nan),
                           standard_name='geopotential_height', units='km')
     grib_message = mock.sentinel.GRIB_MESSAGE
     with mock.patch(GRIB_API) as grib_api:
         data(cube, grib_message)
     # Check the use of a mask has been turned on and a suitable fill
     # value has been chosen.
     FILL = self.assertBitmapRange(grib_api, -1000, 2000)
     # Check the correct data values have been set.
     self.assertValues(grib_api, [-1000, 2000, FILL, FILL])