def test_point(self):
        t_coord = mock.Mock()
        t_coord.has_bounds = mock.Mock(return_value=False)
        t_coord.points = [15]

        cube = mock.Mock()
        cube.coord = mock.Mock(return_value=t_coord)
        rt, rt_meaning, fp, fp_meaning = _missing_forecast_period(cube)

        t_coord.units.assert_has_call(mock.call.num2date(15))
        self.assertEqual((rt_meaning, fp, fp_meaning), (2, 0, 1))
    def test_bounds(self):
        t_coord = mock.Mock()
        t_coord.has_bounds = mock.Mock(return_value=True)
        t_coord.points = [15]
        t_coord.bounds = np.array([[10, 20]])

        cube = mock.Mock()
        cube.coord = mock.Mock(return_value=t_coord)
        rt, rt_meaning, fp, fp_meaning = _missing_forecast_period(cube)

        t_coord.units.assert_has_call(mock.call.num2date(10))
        self.assertEqual((rt_meaning, fp, fp_meaning), (2, 0, 1))
예제 #3
0
    def test_no_bounds(self):
        t_coord = DimCoord(15, 'time', units='hours since epoch')
        cube = Cube(23)
        cube.add_aux_coord(t_coord)

        res = _missing_forecast_period(cube)
        expected_rt = datetime.datetime(1970, 1, 1, 15, 0)
        expected_rt_type = 3
        expected_fp = 0
        expected_fp_type = 1
        expected = (expected_rt, expected_rt_type, expected_fp,
                    expected_fp_type)
        self.assertEqual(res, expected)
    def test_no_bounds(self):
        t_coord = DimCoord(15, 'time', units='hours since epoch')
        cube = Cube(23)
        cube.add_aux_coord(t_coord)

        res = _missing_forecast_period(cube)
        expected_rt = datetime.datetime(1970, 1, 1, 15, 0)
        expected_rt_type = 3
        expected_fp = 0
        expected_fp_type = 1
        expected = (expected_rt,
                    expected_rt_type,
                    expected_fp,
                    expected_fp_type)
        self.assertEqual(res, expected)
    def test_with_bounds(self):
        t_coord = DimCoord(15, 'time', bounds=[14, 16],
                           units='hours since epoch')
        cube = Cube(23)
        cube.add_aux_coord(t_coord)

        res = _missing_forecast_period(cube)
        expected_rt = t_coord.units.num2date(14)
        expected_rt_type = 3
        expected_fp = 0
        expected_fp_type = 1
        expected = (expected_rt,
                    expected_rt_type,
                    expected_fp,
                    expected_fp_type)
        self.assertEqual(res, expected)
예제 #6
0
    def test_with_bounds(self):
        t_coord = DimCoord(3, 'time', bounds=[2, 4], units='days since epoch')
        frt_coord = DimCoord(8,
                             'forecast_reference_time',
                             units='hours since epoch')
        cube = Cube(23)
        cube.add_aux_coord(t_coord)
        cube.add_aux_coord(frt_coord)

        res = _missing_forecast_period(cube)
        expected_rt = datetime.datetime(1970, 1, 1, 8, 0)
        expected_rt_type = 1
        expected_fp = 2 * 24 - 8
        expected_fp_type = 1
        expected = (expected_rt, expected_rt_type, expected_fp,
                    expected_fp_type)
        self.assertEqual(res, expected)
    def test_with_bounds(self):
        t_coord = DimCoord(3, 'time', bounds=[2, 4], units='days since epoch')
        frt_coord = DimCoord(8, 'forecast_reference_time',
                             units='hours since epoch')
        cube = Cube(23)
        cube.add_aux_coord(t_coord)
        cube.add_aux_coord(frt_coord)

        res = _missing_forecast_period(cube)
        expected_rt = datetime.datetime(1970, 1, 1, 8, 0)
        expected_rt_type = 1
        expected_fp = 2 * 24 - 8
        expected_fp_type = 1
        expected = (expected_rt,
                    expected_rt_type,
                    expected_fp,
                    expected_fp_type)
        self.assertEqual(res, expected)
    def test_no_bounds(self):
        t_coord = DimCoord(3, 'time', units='days since epoch')
        frt_coord = DimCoord(8, 'forecast_reference_time',
                             units='hours since epoch')
        cube = Cube(23)
        cube.add_aux_coord(t_coord)
        cube.add_aux_coord(frt_coord)

        res = _missing_forecast_period(cube)
        expected_rt = frt_coord.units.num2date(8)
        expected_rt_type = 1
        expected_fp = 3 * 24 - 8
        expected_fp_type = 1
        expected = (expected_rt,
                    expected_rt_type,
                    expected_fp,
                    expected_fp_type)
        self.assertEqual(res, expected)