示例#1
0
def test_erosion_partial(test_eopatch):
    mask_before = test_eopatch.mask_timeless["LULC"].copy()

    # skip forest and artificial surface
    specific_labels = [0, 1, 3, 4]
    erosion_task = ErosionTask(mask_feature=(FeatureType.MASK_TIMELESS, "LULC",
                                             "LULC_ERODED"),
                               disk_radius=1,
                               erode_labels=specific_labels)
    eopatch = erosion_task.execute(test_eopatch)

    mask_after = eopatch.mask_timeless["LULC_ERODED"].copy()

    assert not np.all(mask_before == mask_after)

    for label in CLASSES:
        if label == 0:
            assert np.sum(mask_after == label) >= np.sum(
                mask_before == label), "Error in the erosion process"
        elif label in specific_labels:
            assert np.sum(mask_after == label) <= np.sum(
                mask_before == label), "Error in the erosion process"
        else:
            assert_array_equal(mask_after == label,
                               mask_before == label,
                               err_msg="Error in the erosion process")
示例#2
0
    def test_erosion_partial(self):
        eopatch = EOPatch.load(self.TEST_PATCH_FILENAME, lazy_loading=True)
        mask_before = eopatch.mask_timeless['LULC'].copy()

        # skip forest and artificial surface
        specific_labels = [0, 1, 3, 4]
        erosion_task = ErosionTask(mask_feature=(FeatureType.MASK_TIMELESS,
                                                 'LULC', 'LULC_ERODED'),
                                   disk_radius=1,
                                   erode_labels=specific_labels)
        eopatch = erosion_task.execute(eopatch)

        mask_after = eopatch.mask_timeless['LULC_ERODED'].copy()

        self.assertFalse(np.all(mask_before == mask_after))

        for label in self.classes:
            if label == 0:
                self.assertGreaterEqual(np.sum(mask_after == label),
                                        np.sum(mask_before == label),
                                        msg="error in the erosion process")
            elif label in specific_labels:
                self.assertLessEqual(np.sum(mask_after == label),
                                     np.sum(mask_before == label),
                                     msg="error in the erosion process")
            else:
                self.assertEqual(np.sum(mask_after == label),
                                 np.sum(mask_before == label),
                                 msg="error in the erosion process")
示例#3
0
def test_erosion_full(test_eopatch):
    mask_before = test_eopatch.mask_timeless["LULC"].copy()

    erosion_task = ErosionTask(
        (FeatureType.MASK_TIMELESS, "LULC", "LULC_ERODED"), 1)
    eopatch = erosion_task.execute(test_eopatch)

    mask_after = eopatch.mask_timeless["LULC_ERODED"].copy()

    assert not np.all(mask_before == mask_after)

    for label in CLASSES:
        if label == 0:
            assert np.sum(mask_after == label) >= np.sum(
                mask_before == label), "Error in the erosion process"
        else:
            assert np.sum(mask_after == label) <= np.sum(
                mask_before == label), "Error in the erosion process"
示例#4
0
    def test_point_raster_sampler(self):
        # test erosion on all classes
        eopatch = EOPatch.load(self.TEST_PATCH_FILENAME, lazy_loading=True)
        mask_before = eopatch.mask_timeless['LULC'].copy()

        erosion_task = ErosionTask((FeatureType.MASK_TIMELESS, 'LULC', 'LULC_ERODED'), 1)
        eopatch = erosion_task.execute(eopatch)

        mask_after = eopatch.mask_timeless['LULC_ERODED'].copy()

        self.assertFalse(np.all(mask_before == mask_after))

        for label in self.classes:
            if label == 0:
                self.assertGreaterEqual(np.sum(mask_after == label), np.sum(mask_before == label),
                                        msg="error in the erosion process")
            else:
                self.assertLessEqual(np.sum(mask_after == label), np.sum(mask_before == label),
                                     msg="error in the erosion process")
示例#5
0
# TASK FOR LINEAR INTERPOLATION
# linear interpolation of full time-series and date resampling
resampled_range = ('2017-01-01', '2017-12-31', 16)
linear_interp = LinearInterpolation(
    'FEATURES',  # name of field to interpolate
    mask_feature=(FeatureType.MASK,
                  'IS_VALID'),  # mask to be used in interpolation
    copy_features=[(FeatureType.MASK_TIMELESS, 'LULC')],  # features to keep
    resample_range=resampled_range,  # set the resampling range
    bounds_error=False  # extrapolate with NaN's
)

# TASK FOR EROSION
# erode each class of the reference map
erosion = ErosionTask(mask_feature=(FeatureType.MASK_TIMELESS, 'LULC',
                                    'LULC_ERODED'),
                      disk_radius=1)

# TASK FOR SPATIAL SAMPLING
# Uniformly sample about pixels from patches
n_samples = int(1e5)  # no. of pixels to sample
ref_labels = [0, 1, 2, 3, 4,
              5]  # reference labels to take into account when sampling
spatial_sampling = PointSamplingTask(
    n_samples=n_samples,
    ref_mask_feature='LULC_ERODED',
    ref_labels=ref_labels,
    sample_features=[  # tag fields to sample
        (FeatureType.DATA, 'FEATURES'),
        (FeatureType.MASK_TIMELESS, 'LULC_ERODED')
    ])
示例#6
0
def test_erosion_value_error(invalid_input):
    with pytest.raises(ValueError):
        ErosionTask((FeatureType.MASK_TIMELESS, "LULC", "TEST"),
                    disk_radius=invalid_input)