def test_mean(self):
     """Test that the function adds the cubes correctly for mean."""
     operation = 'mean'
     plugin = CubeCombiner(operation)
     result = plugin.combine(self.cube1, self.cube2)
     expected_data = np.full((1, 2, 2), 1.1, dtype=np.float32)
     self.assertArrayAlmostEqual(result.data, expected_data)
 def test_min(self):
     """Test combine finds the min of the cubes correctly."""
     operation = 'min'
     plugin = CubeCombiner(operation)
     result = plugin.combine(self.cube1, self.cube2)
     expected_data = np.full((1, 2, 2), 0.5, dtype=np.float32)
     self.assertArrayAlmostEqual(result.data, expected_data)
 def test_basic(self):
     """Test that the function returns a Cube. """
     operation = '*'
     plugin = CubeCombiner(operation)
     result = plugin.combine(self.cube1, self.cube2)
     self.assertIsInstance(result, Cube)
     expected_data = np.full((1, 2, 2), 0.3, dtype=np.float32)
     self.assertArrayAlmostEqual(result.data, expected_data)
 def test_mean(self):
     """Test that the function adds the cubes correctly for mean."""
     operation = '+'
     plugin = CubeCombiner(operation)
     result = plugin.combine(self.cube1, self.cube3, operation)
     expected_data = np.zeros((1, 2, 2, 2))
     expected_data[0, 0, :, :] = 0.6
     expected_data[0, 1, :, :] = 1.4
     self.assertArrayAlmostEqual(result.data, expected_data)
 def test_min(self):
     """Test combine finds the min of the cubes correctly."""
     operation = 'min'
     plugin = CubeCombiner(operation)
     result = plugin.combine(self.cube1, self.cube3, operation)
     expected_data = np.zeros((1, 2, 2, 2))
     expected_data[0, 0, :, :] = 0.1
     expected_data[0, 1, :, :] = 0.6
     self.assertArrayAlmostEqual(result.data, expected_data)
 def test_minus(self):
     """Test combine minus the cubes correctly. """
     operation = '-'
     plugin = CubeCombiner(operation)
     result = plugin.combine(self.cube1, self.cube2, operation)
     expected_data = np.zeros((1, 2, 2, 2))
     expected_data[0, 0, :, :] = 0.4
     expected_data[0, 1, :, :] = 0.2
     self.assertArrayAlmostEqual(result.data, expected_data)
Beispiel #7
0
 def test_basic(self):
     """Test that the function returns a Cube. """
     operation = '*'
     plugin = CubeCombiner(operation)
     cube1 = self.cube1
     cube2 = cube1.copy()
     result = plugin.combine(cube1, cube2, operation)
     self.assertIsInstance(result, Cube)
     expected_data = np.zeros((1, 2, 2, 2))
     expected_data[0, 0, :, :] = 0.25
     expected_data[0, 1, :, :] = 0.36
     self.assertArrayAlmostEqual(result.data, expected_data)
    def process(self, cube_gust, cube_ws):
        """
        Create a cube containing the wind_gust diagnostic.

        Args:
            cube_gust (iris.cube.Cube):
                Cube contain one or more percentiles of wind_gust data.
            cube_ws (iris.cube.Cube):
                Cube contain one or more percentiles of wind_speed data.

        Returns:
            result (iris.cube.Cube):
                Cube containing the wind-gust diagnostic data.

        """

        # Extract wind-gust data
        (req_cube_gust, perc_coord_gust) = self.extract_percentile_data(
            cube_gust, self.percentile_gust, "wind_speed_of_gust")
        # Extract wind-speed data
        (req_cube_ws, perc_coord_ws) = (self.extract_percentile_data(
            cube_ws, self.percentile_windspeed, "wind_speed"))
        if perc_coord_gust.name() != perc_coord_ws.name():
            msg = ('Percentile coord of wind-gust data'
                   'does not match coord of wind-speed data'
                   ' {0:s} {1:s}.'.format(perc_coord_gust.name(),
                                          perc_coord_ws.name()))
            raise ValueError(msg)

        # Check times are compatible.
        msg = ('Could not match time coordinate')
        wg_time = req_cube_gust.coords('time')
        ws_time = req_cube_ws.coords('time')
        if len(wg_time) == 0 or len(ws_time) == 0:
            raise ValueError(msg)
        wg_time = wg_time[0]
        ws_time = ws_time[0]
        for i, point in enumerate(wg_time.points):
            if point != ws_time.points[i]:
                if wg_time.bounds is None:
                    raise ValueError(msg)
                if len(wg_time.bounds) >= i:
                    if len(wg_time.bounds[i]) == 2:
                        if ws_time.points[i] < wg_time.bounds[i][0]:
                            raise ValueError(msg)
                        elif ws_time.points[i] > wg_time.bounds[i][1]:
                            raise ValueError(msg)
                    else:
                        raise ValueError(msg)
                else:
                    raise ValueError(msg)

        # Add metadata to gust cube
        req_cube_gust = self.add_metadata(req_cube_gust)

        # Calculate wind-gust diagnostic using CubeCombiner
        plugin = CubeCombiner('max')
        result = plugin.combine(req_cube_gust, req_cube_ws)

        # Update metadata
        result = self.update_metadata_after_max(result, perc_coord_gust.name())

        return result