示例#1
0
    def test_most_common_class_with_valid(self):
        *_, gl30_10 = random_test_data()

        expected = 50
        actual = most_common_class(gl30_10)[0]

        self.assertEqual(expected, actual)
示例#2
0
    def test_sample_occupied_with_valid_and_affine(self):
        *_, gl30_10 = random_test_data((2, 2))
        affine = Affine(30, 0, 0, 0, 30, 0)

        expected = [{
            'col': 0,
            'row': 1,
            'x': 0.0,
            'y': 30.0,
            'label': 80
        }, {
            'col': 1,
            'row': 0,
            'x': 30.0,
            'y': 0.0,
            'label': 50
        }, {
            'col': 0,
            'row': 0,
            'x': 0.0,
            'y': 0.0,
            'label': 90
        }]
        actual = sample_occupied(gl30_10, affine=affine, seed=42)

        self.assertEqual(expected, actual)
示例#3
0
    def test_superimpose_with_equal_shaped(self):
        treecover, loss, gain, _, gl30_10 = random_test_data()

        expected = (100, 100)
        actual = superimpose(gl30_10, treecover, gain, loss)

        self.assertEqual(expected, actual.shape)
        self.assertEqual(np.uint8, actual.dtype)
示例#4
0
    def test_frequency_with_valid(self):
        *_, gl30_10 = random_test_data()

        expected = OrderedDict(OrderedDict([(0, 877), (10, 888), (20, 919),
                                            (30, 876), (40, 938), (50, 957),
                                            (60, 916), (70, 915), (80, 930),
                                            (90, 903), (100, 881)]))
        actual = frequency(gl30_10)

        self.assertEqual(expected, actual)
示例#5
0
    def test_superimpose_with_valid_data(self):
        treecover, loss, gain, _, gl30_10 = random_test_data((5, 5))

        expected = np.array(
            [[0, 0, 0, 0, 0], [30, 60, 0, 0, 0], [10, 0, 0, 40, 50],
             [25, 0, 0, 0, 0], [0, 0, 25, 0, 0]],
            dtype=np.uint8)
        actual = superimpose(gl30_10, treecover, gain, loss)

        self.assertTrue(np.array_equal(expected, actual))
示例#6
0
    def test_reclassify_with_resolution(self):
        *_, gl30_10 = random_test_data((5, 5))

        expected = np.array(
            [[0, 0, 0, 0, 0], [0, 0, 0, 50, 0], [0, 0, 0, 0, 0],
             [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]],
            dtype=np.uint8)
        actual = reclassify(gl30_10, res=30, side_length=90)

        self.assertTrue(np.array_equal(expected, actual))
示例#7
0
    def test_treecover_similarity_with_mock_data(self):
        gfc, *_, gl30, _ = random_test_data()

        expected = [0.7075, 0.786, 0.881, 1.0]
        actual = treecover_agreement(gl30,
                                     gfc,
                                     canopy_densities=(0, 10, 20, 30),
                                     cover_classes=(20, ))

        self.assertEqual(expected, actual)
示例#8
0
    def test_sample_occupied_with_valid(self):
        *_, gl30_10 = random_test_data((2, 2))

        expected = [{
            'label': 80,
            'col': 0,
            'row': 1
        }, {
            'label': 50,
            'col': 1,
            'row': 0
        }, {
            'label': 90,
            'col': 0,
            'row': 0
        }]
        actual = sample_occupied(gl30_10, seed=42)

        self.assertEqual(expected, actual)
示例#9
0
    def test_superimpose_with_malicious_shapes(self):
        a = np.zeros((10, 10), dtype=np.uint8)
        treecover, loss, gain, *_ = random_test_data()

        with self.assertRaises(ValueError) as err:
            superimpose(a, treecover, gain, loss)