Esempio n. 1
0
    def test_valid_single_interpolation(self):
        """Test interpolating to the mid point of the time range. Expect the
        data to be half way between, and the time coordinate should be at
        06Z November 11th 2017."""

        expected_data = np.ones((self.npoints, self.npoints)) * 4
        expected_time = [1509516000]
        expected_fp = 3 * 3600
        result, = TemporalInterpolation(interval_in_minutes=180).process(
            self.cube_time_0, self.cube_time_1)

        self.assertArrayAlmostEqual(expected_data, result.data)
        self.assertArrayAlmostEqual(result.coord('time').points, expected_time)
        self.assertAlmostEqual(
            result.coord('forecast_period').points[0], expected_fp)
    def test_valid_interpolation_from_given_list(self):
        """Test interpolating to a point defined in a list between the two
        input cube validity times. Check the data increments as expected and
        the time coordinates are also set correctly.

        NB Interpolation in iris is prone to float precision errors of order
        10E-6, hence the need to use AlmostEqual below."""

        result, = TemporalInterpolation(times=[self.time_extra]).process(
            self.cube_time_0, self.cube_time_1)
        expected_data = np.ones((self.npoints, self.npoints)) * 4
        expected_time = [1509516000]
        expected_fp = 3 * 3600

        self.assertArrayAlmostEqual(expected_data, result.data)
        self.assertArrayAlmostEqual(
            result.coord('time').points, expected_time, decimal=5)
        self.assertAlmostEqual(result.coord('forecast_period').points[0],
                               expected_fp)
        self.assertEqual(result.data.dtype, np.float32)
        self.assertEqual(str(result.coord('time').points.dtype), 'int64')
        self.assertEqual(str(result.coord('forecast_period').points.dtype),
                         'int32')