Exemplo n.º 1
0
 def test_basic_circular(self):
     """Test the _calculate_neighbourhood method with a circular neighbourhood."""
     expected_array = np.array([
         [1.0, 1.0, 1.0, 1.0, 1.0],
         [1.0, 1.0, 0.8, 1.0, 1.0],
         [1.0, 0.8, 0.8, 0.8, 1.0],
         [1.0, 1.0, 0.8, 1.0, 1.0],
         [1.0, 1.0, 1.0, 1.0, 1.0],
     ])
     plugin = NeighbourhoodProcessing("circular", self.RADIUS)
     plugin.kernel = self.circular_kernel
     result = plugin._calculate_neighbourhood(self.data)
     self.assertArrayAlmostEqual(result.data, expected_array)
Exemplo n.º 2
0
 def test_basic_circular_sum(self):
     """Test the _calculate_neighbourhood method calculating a sum in
     a circular neighbourhood."""
     expected_array = np.array([
         [5.0, 5.0, 5.0, 5.0, 5.0],
         [5.0, 5.0, 4.0, 5.0, 5.0],
         [5.0, 4.0, 4.0, 4.0, 5.0],
         [5.0, 5.0, 4.0, 5.0, 5.0],
         [5.0, 5.0, 5.0, 5.0, 5.0],
     ])
     plugin = NeighbourhoodProcessing("circular",
                                      self.RADIUS,
                                      sum_only=True)
     plugin.kernel = self.circular_kernel
     result = plugin._calculate_neighbourhood(self.data)
     self.assertArrayAlmostEqual(result.data, expected_array)
Exemplo n.º 3
0
    def test_masked_array_re_mask_true_circular(self):
        """Test the _calculate_neighbourhood method when masked data is
        passed in and re-masking is applied with a circular neighbourhood."""

        expected_array = np.array([
            [np.nan, 0.5, 0.5, 0.5, 1.0],
            [1.0, 1.0, 0.6, 0.5, 0.0],
            [np.nan, 1.0, 0.75, 0.4, 0.0],
            [np.nan, 1.0, 1.0, 0.5, 0.5],
            [np.nan, 1.0, 0.75, 0.5, 0.0],
        ])
        input_data = np.ma.masked_where(self.mask == 0,
                                        self.data_for_masked_tests)
        plugin = NeighbourhoodProcessing("circular", self.RADIUS)
        plugin.kernel = self.circular_kernel
        result = plugin._calculate_neighbourhood(input_data)

        self.assertArrayAlmostEqual(result.data, expected_array)
        self.assertArrayAlmostEqual(result.mask, self.expected_mask)