def test_clipping(self):
     """Test that the utility clips the processed cube to the same limits
     as the input cube."""
     result = clip_cube_data(self.processed_cube, self.minimum_value,
                             self.maximum_value)
     self.assertEqual(result.data.min(), self.minimum_value)
     self.assertEqual(result.data.max(), self.maximum_value)
Ejemplo n.º 2
0
 def test_clipping(self):
     """Test that the utility clips the processed cube to the same limits
     as the input cube when slicing over multiple x-y planes"""
     result = clip_cube_data(self.processed_cube, self.minimum_value,
                             self.maximum_value)
     self.assertEqual(result.data.min(), self.minimum_value)
     self.assertEqual(result.data.max(), self.maximum_value)
     self.assertEqual(result.attributes, self.processed_cube.attributes)
     self.assertEqual(result.cell_methods, self.processed_cube.cell_methods)
 def test_clipping_slices(self):
     """Test that the utility clips the processed cube to the same limits
     as the input cube, and that it does this when slicing over multiple
     x-y planes."""
     cube = set_up_probability_above_threshold_temperature_cube()
     minimum_value = cube.data.min()
     maximum_value = cube.data.max()
     processed_cube = cube.copy(data=cube.data * 2.0 - cube.data.mean())
     result = clip_cube_data(processed_cube, minimum_value, maximum_value)
     self.assertEqual(result.data.min(), minimum_value)
     self.assertEqual(result.data.max(), maximum_value)
     self.assertEqual(result.attributes, processed_cube.attributes)
     self.assertEqual(result.cell_methods, processed_cube.cell_methods)
Ejemplo n.º 4
0
    def _remove_padding_and_mask(
            self, neighbourhood_averaged_cube,
            original_cube, mask,
            grid_cells_x, grid_cells_y):
        """
        Remove the halo from the padded array and apply the mask, if required.
        If fraction option set, clip the data so values lie within
        the range of the original cube.

        Args:
            neighbourhood_averaged_cube (iris.cube.Cube):
                Cube containing the smoothed field after the square
                neighbourhood method has been applied.
            original_cube (iris.cube.Cube or None):
                The original cube slice.
            mask (iris.cube.Cube):
                The mask cube created by set_up_cubes_to_be_neighbourhooded.
            grid_cells_x (float):
                The number of grid cells along the x axis used to create a
                square neighbourhood.
            grid_cells_y (float):
                The number of grid cells along the y axis used to create a
                square neighbourhood.

        Returns:
            iris.cube.Cube:
                Cube containing the smoothed field after the square
                neighbourhood method has been applied and halo removed.
        """
        # Correct neighbourhood averages for masked data, which may have been
        # calculated using larger neighbourhood areas than are present in
        # reality.
        neighbourhood_averaged_cube = remove_halo_from_cube(
            neighbourhood_averaged_cube, grid_cells_x+1, grid_cells_y+1)
        if self.re_mask and mask.data.min() < 1.0:
            neighbourhood_averaged_cube.data = np.ma.masked_array(
                neighbourhood_averaged_cube.data,
                mask=np.logical_not(mask.data.squeeze()))
        # Add clipping
        if self.sum_or_fraction == "fraction":
            minimum_value = np.nanmin(original_cube.data)
            maximum_value = np.nanmax(original_cube.data)
            neighbourhood_averaged_cube = (
                clip_cube_data(neighbourhood_averaged_cube,
                               minimum_value, maximum_value))
        return neighbourhood_averaged_cube
Ejemplo n.º 5
0
 def test_basic(self):
     """Test that the utility returns a cube."""
     result = clip_cube_data(self.processed_cube, self.minimum_value,
                             self.maximum_value)
     self.assertIsInstance(result, Cube)