Ejemplo n.º 1
0
    def test_2d_cube_random_ordering(self):
        """
        Test that the plugin returns the correct cube data for a
        2d input cube, if random ordering is selected.
        """
        raw_data = np.array([[3], [2], [1]])

        post_processed_percentiles_data = np.array([[1], [2], [3]])

        raw_cube = self.raw_cube[:, :, 0, 0]
        raw_cube.data = raw_data
        post_processed_percentiles = (self.post_processed_percentiles[:, :, 0,
                                                                      0])
        post_processed_percentiles.data = post_processed_percentiles_data

        plugin = Plugin()
        result = plugin.process(post_processed_percentiles,
                                raw_cube,
                                random_ordering=True)

        permutations = list(itertools.permutations(raw_data))
        permutations = [np.array(permutation) for permutation in permutations]

        matches = [
            np.array_equal(aresult, result.data) for aresult in permutations
        ]
        self.assertIn(True, matches)
Ejemplo n.º 2
0
    def test_2d_cube_recycling_raw_ensemble_realizations(self):
        """
        Test that the plugin returns the correct cube data for a
        2d input cube, if the number of raw ensemble realizations is fewer
        than the number of percentiles required, and therefore, raw
        ensemble realization recycling is required.

        Case where two raw ensemble realizations are exactly the same,
        after the raw ensemble realizations have been recycled.
        The number of raw ensemble realizations are recycled in order to match
        the number of percentiles.

        After recycling the raw _data will be
        raw_data = np.array([[1],
                             [2],
                             [1]])

        If there's a tie, the re-ordering randomly allocates the ordering
        for the data from the raw ensemble realizations, which is why there are
        two possible options for the resulting post-processed ensemble
        realizations.

        Raw ensemble realizations
        1,  2
        Post-processed percentiles
        1,  2,  3
        After recycling raw ensemble realizations
        1,  2,  1
        As the second ensemble realization(with a data value of 2), is the
        highest value, the highest value from the post-processed percentiles
        will be the second ensemble realization data value within the
        post-processed realizations. The data values of 1 and 2 from the
        post-processed percentiles will then be split between the first
        and third post-processed ensemble realizations.

        """
        raw_data = np.array([[1], [2]])

        post_processed_percentiles_data = np.array([[1], [2], [3]])

        expected_first = np.array([[1], [3], [2]])

        expected_second = np.array([[2], [3], [1]])

        raw_cube = self.raw_cube[:2, :, 0, 0]
        raw_cube.data = raw_data
        post_processed_percentiles = (self.post_processed_percentiles[:, :, 0,
                                                                      0])
        post_processed_percentiles.data = post_processed_percentiles_data

        plugin = Plugin()
        result = plugin.process(post_processed_percentiles, raw_cube)
        permutations = [expected_first, expected_second]
        matches = [
            np.array_equal(aresult, result.data) for aresult in permutations
        ]
        self.assertIn(True, matches)
Ejemplo n.º 3
0
 def test_works_for_different_percentile_coord(self):
     """Test that it still works for different percentile coordinate"""
     cube = self.post_processed_percentiles
     cube.coord(self.perc_coord).rename("percentile_over_dummy")
     plugin = Plugin()
     result = plugin.process(cube, self.raw_cube)
     self.assertIsInstance(result, Cube)
     self.assertTrue(result.coords("realization"))
     self.assertArrayAlmostEqual(
         result.coord("realization").points, [0, 1, 2])
Ejemplo n.º 4
0
 def test_basic(self):
     """
     Test that the plugin returns an iris.cube.Cube and the cube has a
     realization coordinate.
     """
     plugin = Plugin()
     result = plugin.process(self.post_processed_percentiles, self.raw_cube)
     self.assertIsInstance(result, Cube)
     self.assertTrue(result.coords("realization"))
     self.assertArrayAlmostEqual(
         result.coord("realization").points, [0, 1, 2])
Ejemplo n.º 5
0
 def test_works_for_cubelist(self):
     """Test that the plugin works for a cubelist """
     plugin = Plugin()
     cubelist = CubeList([])
     for cube in self.post_processed_percentiles.slices_over("time"):
         cubelist.append(cube)
     result = plugin.process(cubelist, self.raw_cube)
     self.assertIsInstance(result, Cube)
     self.assertTrue(result.coords("realization"))
     self.assertArrayAlmostEqual(
         result.coord("realization").points, [0, 1, 2])