def test_no_realizations(self):
     """Test when the array has no realization coord."""
     cube = set_up_cube_with_no_realizations()
     radii = 5600
     neighbourhood_method = CircularNeighbourhood()
     result = NBHood(neighbourhood_method, radii).process(cube)
     self.assertIsInstance(result, Cube)
     expected = np.ones([1, 16, 16])
     expected[0, 6:9, 6:9] = ([0.91666667, 0.875,
                               0.91666667], [0.875, 0.83333333, 0.875],
                              [0.91666667, 0.875, 0.91666667])
     self.assertArrayAlmostEqual(result.data, expected)
Exemplo n.º 2
0
 def test_single_point_almost_edge(self):
     """Test behaviour for a non-zero grid cell quite near the edge."""
     cube = set_up_cube(zero_point_indices=[
         (0, 0, 7, 2)
     ])  # Just within range of the edge.
     expected = np.ones_like(cube.data)
     for index, slice_ in enumerate(SINGLE_POINT_RANGE_3_CENTROID):
         expected[0][0][5 + index][0:5] = slice_
     ranges = 3
     result = CircularNeighbourhood(
         weighted_mode=True).apply_circular_kernel(cube, ranges)
     self.assertArrayAlmostEqual(result.data, expected)
Exemplo n.º 3
0
 def test_single_point_adjacent_edge(self):
     """Test behaviour for a single non-zero grid cell near the edge."""
     cube = set_up_cube(
         zero_point_indices=[(0, 0, 7, 1)])  # Range 3 goes over the edge.
     expected = np.ones_like(cube.data)
     for index, slice_ in enumerate(SINGLE_POINT_RANGE_3_CENTROID):
         expected[0][0][5 + index][0:4] = slice_[1:]
     ranges = (3, 3)
     result = (
         CircularNeighbourhood(
             weighted_mode=True).apply_circular_kernel(cube, ranges))
     self.assertArrayAlmostEqual(result.data, expected)
Exemplo n.º 4
0
 def test_single_point_range_5(self):
     """Test behaviour with a non-zero point with a large range."""
     cube = set_up_cube()
     expected = np.ones_like(cube.data)
     for time_index in range(len(expected)):
         for index, slice_ in enumerate(SINGLE_POINT_RANGE_5_CENTROID):
             expected[0][time_index][3 + index][3:12] = slice_
     ranges = (5, 5)
     result = (
         CircularNeighbourhood(
             weighted_mode=True).apply_circular_kernel(cube, ranges))
     self.assertArrayAlmostEqual(result.data, expected)
Exemplo n.º 5
0
 def test_returns_adjusted_values(self):
     """Test returns the correct values."""
     expected = 9.2376043070399998
     neighbourhood_method = CircularNeighbourhood()
     radii = 20.0
     ens_factor = 0.8
     num_ens = 3.0
     width = 20.0
     result = NBHood(
         neighbourhood_method, radii,
         ens_factor=ens_factor).adjust_nsize_for_ens(num_ens, width)
     self.assertAlmostEqual(result, expected)
Exemplo n.º 6
0
 def test_returns_unchanged_for_ens1(self):
     """Test returns unchanged value when num_ens = 1.0."""
     expected = 20.0
     neighbourhood_method = CircularNeighbourhood()
     radii = 20.0
     ens_factor = 0.8
     num_ens = 1.0
     width = 20.0
     result = NBHood(
         neighbourhood_method, radii,
         ens_factor=ens_factor).adjust_nsize_for_ens(num_ens, width)
     self.assertAlmostEqual(result, expected)
 def test_multiple_realizations(self):
     """Test when the cube has a realization dimension."""
     cube = set_up_cube(num_realization_points=4)
     radii = 5600
     neighbourhood_method = CircularNeighbourhood()
     result = NBHood(neighbourhood_method, radii).process(cube)
     self.assertIsInstance(result, Cube)
     expected = np.ones([4, 1, 16, 16])
     expected[0, 0, 6:9, 6:9] = ([0.91666667, 0.875,
                                  0.91666667], [0.875, 0.83333333, 0.875],
                                 [0.91666667, 0.875, 0.91666667])
     self.assertArrayAlmostEqual(result.data, expected)
 def test_basic_float_cube_lead_times_is_none(self):
     """Test _find_radii returns a float with the correct value."""
     neighbourhood_method = CircularNeighbourhood()
     ens_factor = 0.8
     num_ens = 2.0
     radius = 6300
     plugin = NBHood(neighbourhood_method,
                     radius,
                     ens_factor=ens_factor)
     result = plugin._find_radii(num_ens)
     expected_result = 3563.8181771801998
     self.assertIsInstance(result, float)
     self.assertAlmostEqual(result, expected_result)
    def test_basic(self):
        """Test that a cube with correct data is produced by the run method"""
        data = np.array([[0.992, 0.968, 0.96, 0.968, 0.992],
                         [0.968, 0.944, 0.936, 0.944, 0.968],
                         [0.96, 0.936, 0.928, 0.936, 0.96],
                         [0.968, 0.944, 0.936, 0.944, 0.968],
                         [0.992, 0.968, 0.96, 0.968, 0.992]])

        cube = set_up_cube(
            zero_point_indices=((0, 0, 2, 2),), num_grid_points=5)[0, 0]
        result = CircularNeighbourhood().run(cube, self.RADIUS)
        self.assertIsInstance(cube, Cube)
        self.assertArrayAlmostEqual(result.data, data)
Exemplo n.º 10
0
 def test_multi_point_multitimes(self):
     """Test behaviour for points over multiple times."""
     cube = set_up_cube(zero_point_indices=[(0, 0, 10, 10), (0, 1, 7, 7)],
                        num_time_points=2)
     expected = np.ones_like(cube.data)
     for index, slice_ in enumerate(SINGLE_POINT_RANGE_3_CENTROID):
         expected[0][0][8 + index][8:13] = slice_
     for index, slice_ in enumerate(SINGLE_POINT_RANGE_3_CENTROID):
         expected[0][1][5 + index][5:10] = slice_
     ranges = (3, 3)
     result = (CircularNeighbourhood(
         weighted_mode=True).apply_circular_kernel(cube, ranges))
     self.assertArrayAlmostEqual(result.data, expected)
Exemplo n.º 11
0
    def test_radii_varying_with_lead_time_with_interpolation(self):
        """Test that a cube is returned for the following conditions:
        1. The radius varies with lead time.
        2. Linear interpolation is required to create values for the radii
        which are required but were not specified within the 'radii'
        argument."""

        radii = [10000, 30000]
        lead_times = [2, 4]
        neighbourhood_method = CircularNeighbourhood()
        plugin = NBHood(neighbourhood_method, radii, lead_times)
        result = plugin(self.multi_time_cube)
        self.assertIsInstance(result, Cube)
Exemplo n.º 12
0
 def test_single_point_flat(self):
     """Test behaviour for a single non-zero grid cell, flat weighting.
     Note that this gives one more grid cell range than weighted! As the
     affected area is one grid cell more in each direction, an equivalent
     range of 2 was chosen for this test."""
     cube = set_up_cube()
     expected = np.ones_like(cube.data)
     for index, slice_ in enumerate(SINGLE_POINT_RANGE_2_CENTROID_FLAT):
         expected[0][0][5 + index][5:10] = slice_
     ranges = (2, 2)
     result = (CircularNeighbourhood(
         weighted_mode=False).apply_circular_kernel(cube, ranges))
     self.assertArrayAlmostEqual(result.data, expected)
Exemplo n.º 13
0
 def test_single_point_range_5_small_domain(self):
     """Test behaviour - non-zero point, small domain, large range.
     This exhibits the undesirable edge reflection behaviour."""
     cube = set_up_cube(zero_point_indices=((0, 0, 1, 1), ),
                        num_grid_points=4)
     expected = np.array(
         [[[[0.97636177, 0.97533402, 0.97636177, 0.97944502],
            [0.97533402, 0.97430627, 0.97533402, 0.97841727],
            [0.97636177, 0.97533402, 0.97636177, 0.97944502],
            [0.97944502, 0.97841727, 0.97944502, 0.98252826]]]])
     ranges = (5, 5)
     result = (CircularNeighbourhood(
         weighted_mode=True).apply_circular_kernel(cube, ranges))
     self.assertArrayAlmostEqual(result.data, expected)
 def test_single_point_adjacent_corner(self):
     """Test behaviour for a non-zero grid cell near the corner."""
     cube = set_up_cube(
         zero_point_indices=[(0, 0, 1, 1)])  # Kernel goes over the corner.
     expected = np.ones_like(cube.data)
     for index, slice_ in enumerate(SINGLE_POINT_RANGE_3_CENTROID):
         if index == 0:
             continue
         expected[0][0][index - 1][0:4] = slice_[1:]
     ranges = 3
     result = (
         CircularNeighbourhood(
             weighted_mode=True).apply_circular_kernel(cube, ranges))
     self.assertArrayAlmostEqual(result.data, expected)
Exemplo n.º 15
0
    def test_radii_varying_with_lead_time_multiple_thresholds(self):
        """Test that a cube is returned for the following conditions:
        1. The radius varies wtih lead time.
        2. The cube contains multiple thresholds."""

        data = np.ones((2, 16, 16), dtype=np.float32)
        data[1, 7, 7] = 0
        cube = set_up_probability_cube(
            data,
            thresholds=[278, 279],
            spatial_grid="equalarea",
        )

        time_points = [
            datetime(2017, 11, 10, 2),
            datetime(2017, 11, 10, 3),
            datetime(2017, 11, 10, 4),
        ]
        cube = add_coordinate(
            cube,
            coord_points=time_points,
            coord_name="time",
            is_datetime="true",
            order=[1, 0, 2, 3],
        )

        lead_times = [2, 3, 4]
        radii = [5600, 7600, 9500]
        expected = np.ones_like(cube.data)
        expected[1, 0, 6:9, 6:9] = (
            [0.91666667, 0.875, 0.91666667],
            [0.875, 0.83333333, 0.875],
            [0.91666667, 0.875, 0.91666667],
        )
        expected[1, 1, 5:10, 5:10] = SINGLE_POINT_RANGE_3_CENTROID
        expected[1, 2, 4:11, 4:11] = (
            [1, 0.9925, 0.985, 0.9825, 0.985, 0.9925, 1],
            [0.9925, 0.98, 0.9725, 0.97, 0.9725, 0.98, 0.9925],
            [0.985, 0.9725, 0.965, 0.9625, 0.965, 0.9725, 0.985],
            [0.9825, 0.97, 0.9625, 0.96, 0.9625, 0.97, 0.9825],
            [0.985, 0.9725, 0.965, 0.9625, 0.965, 0.9725, 0.985],
            [0.9925, 0.98, 0.9725, 0.97, 0.9725, 0.98, 0.9925],
            [1, 0.9925, 0.985, 0.9825, 0.985, 0.9925, 1],
        )
        neighbourhood_method = CircularNeighbourhood()
        plugin = NBHood(neighbourhood_method, radii, lead_times)
        result = plugin(cube)
        self.assertIsInstance(result, Cube)
        self.assertArrayEqual(result[0].data, expected[0])
        self.assertArrayAlmostEqual(result[1].data, expected[1])
Exemplo n.º 16
0
    def test_single_point_almost_corner(self):
        """Test behaviour for a non-zero grid cell quite near a corner."""

        self.cube.data[2, 2] = 0

        # Just within corner range.

        expected = np.ones_like(self.cube.data)
        for index, slice_ in enumerate(SINGLE_POINT_RANGE_3_CENTROID):
            expected[index][0:5] = slice_
        ranges = 3
        result = CircularNeighbourhood(
            weighted_mode=True).apply_circular_kernel(self.cube, ranges)
        self.assertArrayAlmostEqual(result.data, expected)
Exemplo n.º 17
0
 def test_source_realizations(self):
     """Test when the array has source_realization attribute."""
     realization_list = [0, 1, 2, 3]
     cube = (set_up_cube_with_no_realizations(
         source_realizations=realization_list))
     radii = 5600
     neighbourhood_method = CircularNeighbourhood()
     plugin = NBHood(neighbourhood_method, radii)
     result = plugin.process(cube)
     self.assertIsInstance(result, Cube)
     expected = np.ones([1, 16, 16])
     expected[0, 6:9, 6:9] = ([0.91666667, 0.875,
                               0.91666667], [0.875, 0.83333333, 0.875],
                              [0.91666667, 0.875, 0.91666667])
     self.assertArrayAlmostEqual(result.data, expected)
Exemplo n.º 18
0
    def test_mask_cube(self):
        """Test that a NotImplementedError is raised, if a mask cube is passed
        in when using a circular neighbourhood, as this option is not
        supported."""

        data = np.ones((5, 5), dtype=np.float32)
        data[2, 2] = 0
        cube = set_up_variable_cube(
            data,
            spatial_grid="equalarea",
        )

        msg = "The use of a mask cube with a circular kernel is " "not yet implemented."
        with self.assertRaisesRegex(NotImplementedError, msg):
            CircularNeighbourhood().run(cube, self.RADIUS, mask_cube=cube)
Exemplo n.º 19
0
 def test_single_point_masked_other_point(self):
     """Test behaviour with a non-zero point next to a masked point.
     The behaviour here is not right, as the mask is ignored."""
     cube = set_up_cube()
     expected = np.ones_like(cube.data)
     mask = np.zeros_like(cube.data)
     mask[0][0][6][7] = 1
     cube.data = np.ma.masked_array(cube.data, mask=mask)
     for time_index in range(len(expected)):
         for index, slice_ in enumerate(SINGLE_POINT_RANGE_3_CENTROID):
             expected[0][time_index][5 + index][5:10] = slice_
     ranges = (3, 3)
     result = (CircularNeighbourhood(
         weighted_mode=True).apply_circular_kernel(cube, ranges))
     self.assertArrayAlmostEqual(result.data, expected)
Exemplo n.º 20
0
 def test_radii_varying_with_lead_time(self):
     """
     Test that a cube is returned when the radius varies with lead time.
     """
     cube = set_up_cube(num_time_points=3)
     iris.util.promote_aux_coord_to_dim_coord(cube, "time")
     time_points = cube.coord("time").points
     fp_points = [2, 3, 4]
     cube = add_forecast_reference_time_and_forecast_period(
         cube, time_point=time_points, fp_point=fp_points)
     radii = [10000, 20000, 30000]
     lead_times = [2, 3, 4]
     neighbourhood_method = CircularNeighbourhood()
     plugin = NBHood(neighbourhood_method, radii, lead_times)
     result = plugin.process(cube)
     self.assertIsInstance(result, Cube)
Exemplo n.º 21
0
 def test_interpolation(self):
     """Test that interpolation is working as expected in _find_radii."""
     fp_points = np.array([2, 3, 4])
     neighbourhood_method = CircularNeighbourhood()
     ens_factor = 0.8
     num_ens = 4.0
     fp_points = np.array([2, 3, 4])
     radii = [10000, 30000]
     lead_times = [2, 4]
     plugin = NBHood(neighbourhood_method,
                     radii,
                     lead_times=lead_times,
                     ens_factor=ens_factor)
     result = plugin._find_radii(num_ens, cube_lead_times=fp_points)
     expected_result = np.array([4000., 8000., 12000.])
     self.assertArrayAlmostEqual(result, expected_result)
Exemplo n.º 22
0
 def test_single_point_masked_to_null(self):
     """Test behaviour with a masked non-zero point. The behaviour here is
     not right, as the mask is ignored. This comes directly from the
     scipy.ndimage.correlate base behaviour."""
     cube = set_up_cube()
     expected = np.ones_like(cube.data)
     mask = np.zeros_like(cube.data)
     mask[0][0][7][7] = 1
     cube.data = np.ma.masked_array(cube.data, mask=mask)
     for time_index in range(len(expected)):
         for index, slice_ in enumerate(SINGLE_POINT_RANGE_3_CENTROID):
             expected[0][time_index][5 + index][5:10] = slice_
     ranges = 3
     result = CircularNeighbourhood(
         weighted_mode=True).apply_circular_kernel(cube, ranges)
     self.assertArrayAlmostEqual(result.data, expected)
Exemplo n.º 23
0
 def test_single_point_on_corner(self):
     """Test behaviour for a single non-zero grid cell on the corner."""
     cube = set_up_cube(
         zero_point_indices=[(0, 0, 0, 0)]
     )  # Point is right on the corner.
     expected = np.ones_like(cube.data)
     expected_centroid = np.array(
         [[0.592, 0.768, 0.92], [0.768, 0.872, 0.96], [0.92, 0.96, 0.992],]
     )
     for index, slice_ in enumerate(expected_centroid):
         expected[0][0][index][0:3] = slice_
     ranges = 3
     result = CircularNeighbourhood(weighted_mode=True).apply_circular_kernel(
         cube, ranges
     )
     self.assertArrayAlmostEqual(result.data, expected)
Exemplo n.º 24
0
 def test_point_pair(self):
     """Test behaviour for two nearby non-zero grid cells."""
     cube = set_up_cube(zero_point_indices=[(0, 0, 7, 6), (0, 0, 7, 8)])
     expected_snippet = np.array(
         [[0.992, 0.968, 0.952, 0.936, 0.952, 0.968, 0.992],
          [0.968, 0.944, 0.904, 0.888, 0.904, 0.944, 0.968],
          [0.96, 0.936, 0.888, 0.872, 0.888, 0.936, 0.96],
          [0.968, 0.944, 0.904, 0.888, 0.904, 0.944, 0.968],
          [0.992, 0.968, 0.952, 0.936, 0.952, 0.968, 0.992]])
     expected = np.ones_like(cube.data)
     for index, slice_ in enumerate(expected_snippet):
         expected[0][0][5 + index][4:11] = slice_
     ranges = (3, 3)
     result = (CircularNeighbourhood(
         weighted_mode=True).apply_circular_kernel(cube, ranges))
     self.assertArrayAlmostEqual(result.data, expected)
Exemplo n.º 25
0
    def test_radii_varying_with_lead_time_with_interpolation_check_data(self):
        """Test that a cube with the correct data is returned for the
        following conditions:
        1. The radius varies with lead time.
        2. Linear interpolation is required to create values for the radii
        which are required but were not specified within the 'radii'
        argument."""
        cube = set_up_cube(
            zero_point_indices=((0, 0, 7, 7), (
                0,
                1,
                7,
                7,
            ), (0, 2, 7, 7)),
            num_time_points=3,
        )
        expected = np.ones_like(cube.data)
        expected[0, 0, 6:9, 6:9] = (
            [0.91666667, 0.875, 0.91666667],
            [0.875, 0.83333333, 0.875],
            [0.91666667, 0.875, 0.91666667],
        )

        expected[0, 1, 5:10, 5:10] = SINGLE_POINT_RANGE_3_CENTROID

        expected[0, 2, 4:11, 4:11] = (
            [1, 0.9925, 0.985, 0.9825, 0.985, 0.9925, 1],
            [0.9925, 0.98, 0.9725, 0.97, 0.9725, 0.98, 0.9925],
            [0.985, 0.9725, 0.965, 0.9625, 0.965, 0.9725, 0.985],
            [0.9825, 0.97, 0.9625, 0.96, 0.9625, 0.97, 0.9825],
            [0.985, 0.9725, 0.965, 0.9625, 0.965, 0.9725, 0.985],
            [0.9925, 0.98, 0.9725, 0.97, 0.9725, 0.98, 0.9925],
            [1, 0.9925, 0.985, 0.9825, 0.985, 0.9925, 1],
        )

        iris.util.promote_aux_coord_to_dim_coord(cube, "time")
        time_points = cube.coord("time").points
        fp_points = [2, 3, 4]
        cube = add_forecast_reference_time_and_forecast_period(
            cube, time_point=time_points, fp_point=fp_points)
        radii = [5600, 9500]
        lead_times = [2, 4]
        neighbourhood_method = CircularNeighbourhood()
        plugin = NBHood(neighbourhood_method, radii, lead_times)
        result = plugin(cube)
        self.assertArrayAlmostEqual(result.data, expected)
Exemplo n.º 26
0
 def test_radii_varying_with_lead_time_with_interpolation(self):
     """Test that a cube is returned for the following conditions:
     1. The radius varies with lead time.
     2. Linear interpolation is required to create values for the radii
     which are required but were not specified within the 'radii'
     argument."""
     cube = set_up_cube(num_time_points=3)
     iris.util.promote_aux_coord_to_dim_coord(cube, "time")
     time_points = cube.coord("time").points
     fp_points = [2, 3, 4]
     cube = add_forecast_reference_time_and_forecast_period(
         cube, time_point=time_points, fp_point=fp_points)
     radii = [10000, 30000]
     lead_times = [2, 4]
     neighbourhood_method = CircularNeighbourhood()
     plugin = NBHood(neighbourhood_method, radii, lead_times)
     result = plugin.process(cube)
     self.assertIsInstance(result, Cube)
 def test_radii_varying_with_lead_time_fp_seconds(self):
     """
     Test that a cube fp coord is unchanged by the lead time calculation.
     """
     cube = set_up_cube(num_time_points=3)
     iris.util.promote_aux_coord_to_dim_coord(cube, "time")
     time_points = cube.coord("time").points
     fp_points = [2, 3, 4]
     cube = add_forecast_reference_time_and_forecast_period(
         cube, time_point=time_points, fp_point=fp_points)
     cube.coord("forecast_period").convert_units("seconds")
     radii = [10000, 20000, 30000]
     lead_times = [2, 3, 4]
     neighbourhood_method = CircularNeighbourhood()
     plugin = NBHood(neighbourhood_method, radii, lead_times)
     result = plugin.process(cube)
     self.assertIsInstance(result, Cube)
     self.assertEqual(cube.coord("forecast_period").units, "seconds")
Exemplo n.º 28
0
 def test_single_point_on_edge(self):
     """Test behaviour for a non-zero grid cell on the edge."""
     cube = set_up_cube(zero_point_indices=[(0, 0, 7, 0)
                                            ])  # On the (y) edge.
     expected = np.ones_like(cube.data)
     expected_centroid = np.array([
         [0.92, 0.96, 0.992],
         [0.848, 0.912, 0.968],
         [0.824, 0.896, 0.96],
         [0.848, 0.912, 0.968],
         [0.92, 0.96, 0.992],
     ])
     for index, slice_ in enumerate(expected_centroid):
         expected[0][0][5 + index][0:3] = slice_
     ranges = (3, 3)
     result = (CircularNeighbourhood(
         weighted_mode=True).apply_circular_kernel(cube, ranges))
     self.assertArrayAlmostEqual(result.data, expected)
Exemplo n.º 29
0
    def test_radii_varying_with_lead_time_check_data(self):
        """
        Test that the expected data is produced when the radius
        varies with lead time.
        """
        cube = set_up_cube(
            zero_point_indices=((0, 0, 7, 7), (
                0,
                1,
                7,
                7,
            ), (0, 2, 7, 7)),
            num_time_points=3,
        )
        expected = np.ones_like(cube.data)
        expected[0, 0, 6:9, 6:9] = (
            [0.91666667, 0.875, 0.91666667],
            [0.875, 0.83333333, 0.875],
            [0.91666667, 0.875, 0.91666667],
        )

        expected[0, 1, 5:10, 5:10] = SINGLE_POINT_RANGE_3_CENTROID

        expected[0, 2, 4:11, 4:11] = (
            [1, 0.9925, 0.985, 0.9825, 0.985, 0.9925, 1],
            [0.9925, 0.98, 0.9725, 0.97, 0.9725, 0.98, 0.9925],
            [0.985, 0.9725, 0.965, 0.9625, 0.965, 0.9725, 0.985],
            [0.9825, 0.97, 0.9625, 0.96, 0.9625, 0.97, 0.9825],
            [0.985, 0.9725, 0.965, 0.9625, 0.965, 0.9725, 0.985],
            [0.9925, 0.98, 0.9725, 0.97, 0.9725, 0.98, 0.9925],
            [1, 0.9925, 0.985, 0.9825, 0.985, 0.9925, 1],
        )

        iris.util.promote_aux_coord_to_dim_coord(cube, "time")
        time_points = cube.coord("time").points
        fp_points = [2, 3, 4]
        cube = add_forecast_reference_time_and_forecast_period(
            cube, time_point=time_points, fp_point=fp_points)
        radii = [5600, 7600, 9500]
        lead_times = [2, 3, 4]
        neighbourhood_method = CircularNeighbourhood()
        plugin = NBHood(neighbourhood_method, radii, lead_times)
        result = plugin(cube)
        self.assertArrayAlmostEqual(result.data, expected)
Exemplo n.º 30
0
    def test_single_point_on_edge(self):
        """Test behaviour for a non-zero grid cell on the edge."""

        self.cube.data[7, 0] = 0

        expected = np.ones_like(self.cube.data)
        expected_centroid = np.array([
            [0.92, 0.96, 0.992],
            [0.848, 0.912, 0.968],
            [0.824, 0.896, 0.96],
            [0.848, 0.912, 0.968],
            [0.92, 0.96, 0.992],
        ])
        for index, slice_ in enumerate(expected_centroid):
            expected[5 + index][0:3] = slice_
        ranges = 3
        result = CircularNeighbourhood(
            weighted_mode=True).apply_circular_kernel(self.cube, ranges)
        self.assertArrayAlmostEqual(result.data, expected)