コード例 #1
0
ファイル: test_utilities.py プロジェクト: nivnac/improver
    def test_multiple_timesteps(self):
        """
        Test that the data has been reshaped correctly when there are multiple timesteps.
        The array contents are also checked.  The output cube has only a single percentile,
        which is therefore demoted to a scalar coordinate.
        """
        expected = np.array([
            [[4.0, 4.71428571], [5.42857143, 6.14285714]],
            [[6.85714286, 7.57142857], [8.28571429, 9.0]],
        ])

        cubelist = CubeList([])
        for i, hour in enumerate([7, 8]):
            cubelist.append(
                set_up_percentile_cube(
                    np.array([expected[i, :, :]], dtype=np.float32),
                    np.array([50], dtype=np.float32),
                    units="degC",
                    time=datetime(2015, 11, 23, hour),
                    frt=datetime(2015, 11, 23, 6),
                ))
        percentile_cube = cubelist.merge_cube()

        reshaped_array = restore_non_percentile_dimensions(
            percentile_cube.data.flatten(),
            next(percentile_cube.slices_over("percentile")),
            1,
        )
        self.assertArrayAlmostEqual(reshaped_array, expected)
コード例 #2
0
ファイル: test_utilities.py プロジェクト: nivnac/improver
 def test_multiple_percentiles(self):
     """
     Test the result is an array with the expected shape and contents.
     """
     reshaped_array = restore_non_percentile_dimensions(
         self.input_data, self.cube, 3)
     self.assertIsInstance(reshaped_array, np.ndarray)
     self.assertArrayAlmostEqual(reshaped_array, self.expected_data)
コード例 #3
0
ファイル: test_utilities.py プロジェクト: nivnac/improver
 def test_single_percentile(self):
     """
     Test the array size and contents if the percentile coordinate is scalar.
     """
     expected = np.array(
         [[226.15, 237.4, 248.65], [259.9, 271.15, 282.4],
          [293.65, 304.9, 316.15]],
         dtype=np.float32,
     )
     reshaped_array = restore_non_percentile_dimensions(
         self.input_data[0], self.cube, 1)
     self.assertArrayAlmostEqual(reshaped_array, expected)