def test_irregular_kernel(self):
     """Test a 2d slice."""
     expected = np.array([
         [
             [1.0, 1.0, 1.0, 1.0, 1.0],
             [1.0, 0.3, 1.0, 1.0, 1.0],
             [1.0, 0.3, 1.0, 0.3, 1.0],
             [1.0, 1.0, 0.3, 1.0, 1.0],
             [1.0, 1.0, 1.0, 1.0, 1.0],
         ],
         [
             [1.0, 1.0, 1.0, 1.0, 1.0],
             [1.0, 1.0, 1.0, 1.0, 1.0],
             [1.0, 1.0, 1.0, 1.0, 1.0],
             [1.0, 1.0, 1.0, 1.0, 1.0],
             [1.0, 1.0, 1.0, 1.0, 1.0],
         ],
         [
             [1.0, 1.0, 1.0, 1.0, 1.0],
             [1.0, 1.0, 1.0, 1.0, 1.0],
             [1.0, 1.0, 1.0, 1.0, 1.0],
             [1.0, 1.0, 1.0, 1.0, 1.0],
             [1.0, 1.0, 1.0, 1.0, 1.0],
         ],
     ])
     kernel = np.array([[0.0, 1.0, 0.0], [1.0, 0.0, 1.0], [0.0, 0.0, 1.0]])
     cube = self.cube[0, 0, :, :]
     plugin = GeneratePercentilesFromACircularNeighbourhood()
     plugin.percentiles = np.array([10, 50, 90])
     result = plugin.pad_and_unpad_cube(cube, kernel)
     self.assertIsInstance(result, Cube)
     self.assertArrayAlmostEqual(result.data, expected)
Ejemplo n.º 2
0
    def test_2d_slice(self):
        """Test a 2D slice."""

        expected = np.array([
            [
                [1.0, 1.0, 1.0, 1.0, 1.0],
                [1.0, 1.0, 0.4, 1.0, 1.0],
                [1.0, 0.4, 0.4, 0.4, 1.0],
                [1.0, 1.0, 0.4, 1.0, 1.0],
                [1.0, 1.0, 1.0, 1.0, 1.0],
            ],
            [
                [1.0, 1.0, 1.0, 1.0, 1.0],
                [1.0, 1.0, 1.0, 1.0, 1.0],
                [1.0, 1.0, 1.0, 1.0, 1.0],
                [1.0, 1.0, 1.0, 1.0, 1.0],
                [1.0, 1.0, 1.0, 1.0, 1.0],
            ],
            [
                [1.0, 1.0, 1.0, 1.0, 1.0],
                [1.0, 1.0, 1.0, 1.0, 1.0],
                [1.0, 1.0, 1.0, 1.0, 1.0],
                [1.0, 1.0, 1.0, 1.0, 1.0],
                [1.0, 1.0, 1.0, 1.0, 1.0],
            ],
        ], )
        kernel = np.array([[0.0, 1.0, 0.0], [1.0, 1.0, 1.0], [0.0, 1.0, 0.0]])
        self.cube.data[2, 2] = 0
        plugin = GeneratePercentilesFromACircularNeighbourhood()
        plugin.percentiles = np.array([10, 50, 90])
        result = plugin.pad_and_unpad_cube(self.cube, kernel)
        self.assertIsInstance(result, Cube)
        self.assertArrayAlmostEqual(result.data, expected)