Ejemplo n.º 1
0
 def test_external_mask_square(self):
     """Test the _calculate_neighbourhood method when an external mask is
     passed in and re-masking is applied."""
     plugin = NeighbourhoodProcessing("square", self.RADIUS)
     plugin.nb_size = self.nbhood_size
     result = plugin._calculate_neighbourhood(self.data_for_masked_tests,
                                              mask=self.mask)
     self.assertArrayAlmostEqual(result.data, self.expected_array)
     self.assertArrayAlmostEqual(result.mask, self.expected_mask)
Ejemplo n.º 2
0
    def test_masked_array_re_mask_true_square(self):
        """Test the _calculate_neighbourhood method when masked data is
        passed in and re-masking is applied."""

        input_data = np.ma.masked_where(self.mask == 0,
                                        self.data_for_masked_tests)
        plugin = NeighbourhoodProcessing("square", self.RADIUS)
        plugin.nb_size = self.nbhood_size
        result = plugin._calculate_neighbourhood(input_data)
        self.assertArrayAlmostEqual(result.data, self.expected_array)
        self.assertArrayAlmostEqual(result.mask, self.expected_mask)
Ejemplo n.º 3
0
    def test_masked_array_re_mask_false(self):
        """Test the _calculate_neighbourhood method when masked data is
        passed in and re-masking is not applied."""

        input_data = np.ma.masked_where(self.mask == 0,
                                        self.data_for_masked_tests)
        plugin = NeighbourhoodProcessing("square", self.RADIUS, re_mask=False)
        plugin.nb_size = self.nbhood_size
        result = plugin._calculate_neighbourhood(input_data)
        self.assertArrayAlmostEqual(result, self.expected_array)
        with self.assertRaises(AttributeError):
            result.mask
Ejemplo n.º 4
0
 def test_basic_square(self):
     """Test the _calculate_neighbourhood method with a square neighbourhood."""
     expected_array = np.array([
         [1.0, 1.0, 1.0, 1.0, 1.0],
         [1.0, 8 / 9, 8 / 9, 8 / 9, 1.0],
         [1.0, 8 / 9, 8 / 9, 8 / 9, 1.0],
         [1.0, 8 / 9, 8 / 9, 8 / 9, 1.0],
         [1.0, 1.0, 1.0, 1.0, 1.0],
     ])
     plugin = NeighbourhoodProcessing("square", self.RADIUS)
     plugin.nb_size = self.nbhood_size
     result = plugin._calculate_neighbourhood(self.data)
     self.assertArrayAlmostEqual(result, expected_array)
Ejemplo n.º 5
0
 def test_basic_square_sum(self):
     """Test the _calculate_neighbourhood method calculating a sum in
     a square neighbourhood."""
     expected_array = np.array([
         [4.0, 6.0, 6.0, 6.0, 4.0],
         [6.0, 8.0, 8.0, 8.0, 6.0],
         [6.0, 8.0, 8.0, 8.0, 6.0],
         [6.0, 8.0, 8.0, 8.0, 6.0],
         [4.0, 6.0, 6.0, 6.0, 4.0],
     ])
     plugin = NeighbourhoodProcessing("square", self.RADIUS, sum_only=True)
     plugin.nb_size = self.nbhood_size
     result = plugin._calculate_neighbourhood(self.data)
     self.assertArrayAlmostEqual(result, expected_array)
Ejemplo n.º 6
0
 def test_complex(self):
     """Test that data containing complex numbers is sensibly processed"""
     self.data = self.data.astype(complex)
     self.data[1, 3] = 0.5 + 0.5j
     self.data[4, 3] = 0.4 + 0.6j
     expected_array = np.array([
         [
             1.0 + 0.0j,
             1.0 + 0.0j,
             0.91666667 + 0.083333333j,
             0.91666667 + 0.083333333j,
             0.875 + 0.125j,
         ],
         [
             1.0 + 0.0j,
             0.88888889 + 0.0j,
             0.83333333 + 0.055555556j,
             0.83333333 + 0.055555556j,
             0.91666667 + 0.083333333j,
         ],
         [
             1.0 + 0.0j,
             0.88888889 + 0.0j,
             0.83333333 + 0.055555556j,
             0.83333333 + 0.055555556j,
             0.91666667 + 0.083333333j,
         ],
         [
             1.0 + 0.0j,
             0.88888889 + 0.0j,
             0.82222222 + 0.066666667j,
             0.82222222 + 0.066666667j,
             0.9 + 0.1j,
         ],
         [1.0 + 0.0j, 1.0 + 0.0j, 0.9 + 0.1j, 0.9 + 0.1j, 0.85 + 0.15j],
     ])
     plugin = NeighbourhoodProcessing("square", self.RADIUS)
     plugin.nb_size = self.nbhood_size
     result = plugin._calculate_neighbourhood(self.data)
     self.assertArrayAlmostEqual(result, expected_array)
Ejemplo n.º 7
0
    def test_external_mask_with_masked_data_square(self):
        """Test the _calculate_neighbourhood method when masked data is
        passed in and an external mask is passed in and re-masking is applied."""
        mask = np.array([
            [1, 0, 1, 1, 0],
            [1, 1, 1, 1, 0],
            [1, 0, 1, 1, 1],
            [1, 0, 1, 1, 0],
            [1, 0, 1, 1, 0],
        ])
        external_mask = np.array([
            [0, 1, 1, 1, 1],
            [0, 1, 1, 1, 1],
            [0, 1, 1, 1, 1],
            [0, 1, 1, 1, 1],
            [0, 1, 1, 1, 1],
        ])

        self.data = np.ma.masked_where(mask == 0, self.data_for_masked_tests)
        plugin = NeighbourhoodProcessing("square", self.RADIUS)
        plugin.nb_size = self.nbhood_size
        result = plugin._calculate_neighbourhood(self.data, external_mask)
        self.assertArrayAlmostEqual(result.data, self.expected_array)
        self.assertArrayAlmostEqual(result.mask, self.expected_mask)