def setUpClass(cls): cls.test_cases = [ cls.InterpolationTestCase('linear', LinearInterpolation('NDVI', result_interval=(0.0, 1.0), mask_feature=(FeatureType.MASK, 'IS_VALID'), unknown_value=10), result_len=68, img_min=0.0, img_max=10.0, img_mean=0.720405, img_median=0.59765935), cls.InterpolationTestCase('linear_change_timescale', LinearInterpolation('NDVI', result_interval=(0.0, 1.0), mask_feature=(FeatureType.MASK, 'IS_VALID'), unknown_value=10, scale_time=1), result_len=68, img_min=0.0, img_max=10.0, img_mean=0.720405, img_median=0.597656965), cls.InterpolationTestCase('cubic', CubicInterpolation('NDVI', result_interval=(0.0, 1.0), mask_feature=(FeatureType.MASK, 'IS_VALID'), resample_range=('2015-01-01', '2018-01-01', 16), unknown_value=5, bounds_error=False), result_len=69, img_min=0.0, img_max=5.0, img_mean=1.3592644, img_median=0.6174331), cls.InterpolationTestCase('spline', SplineInterpolation('NDVI', result_interval=(-0.3, 1.0), mask_feature=(FeatureType.MASK, 'IS_VALID'), resample_range=('2016-01-01', '2018-01-01', 5), spline_degree=3, smoothing_factor=0, unknown_value=0), result_len=147, img_min=-0.3, img_max=1.0, img_mean=0.492752, img_median=0.53776133), cls.InterpolationTestCase('bspline', BSplineInterpolation('NDVI', unknown_value=-3, mask_feature=(FeatureType.MASK, 'IS_VALID'), resample_range=('2017-01-01', '2017-02-01', 50), spline_degree=5), result_len=1, img_min=-0.032482587, img_max=0.701796, img_mean=0.42080238, img_median=0.42889267), cls.InterpolationTestCase('akima', AkimaInterpolation('NDVI', unknown_value=0, mask_feature=(FeatureType.MASK, 'IS_VALID')), result_len=68, img_min=-0.13793105, img_max=0.860242, img_mean=0.53159297, img_median=0.59087014), cls.InterpolationTestCase('kriging interpolation', KrigingInterpolation('NDVI', result_interval=(-10, 10), resample_range=('2016-01-01', '2018-01-01', 5)), result_len=147, img_min=-0.252500534, img_max=0.659086704, img_mean=0.3825493, img_median=0.39931053), cls.InterpolationTestCase('nearest resample', NearestResampling('NDVI', result_interval=(0.0, 1.0), resample_range=('2016-01-01', '2018-01-01', 5)), result_len=147, img_min=-0.2, img_max=0.860242, img_mean=0.35143828, img_median=0.37481314, nan_replace=-0.2), cls.InterpolationTestCase('linear resample', LinearResampling('NDVI', result_interval=(0.0, 1.0), resample_range=('2016-01-01', '2018-01-01', 5)), result_len=147, img_min=-0.2, img_max=0.8480114, img_mean=0.350186, img_median=0.3393997, nan_replace=-0.2), cls.InterpolationTestCase('cubic resample', CubicResampling('NDVI', result_interval=(-0.2, 1.0), resample_range=('2015-01-01', '2018-01-01', 16), unknown_value=5), result_len=69, img_min=-0.2, img_max=5.0, img_mean=1.234881997, img_median=0.465670556, nan_replace=-0.2), cls.InterpolationTestCase('linear custom list', LinearInterpolation( 'NDVI', result_interval=(-0.2, 1.0), resample_range=('2015-09-01', '2016-01-01', '2016-07-01', '2017-01-01', '2017-07-01'), unknown_value=-2), result_len=5, img_min=-0.032482587, img_max=0.8427637, img_mean=0.5108417, img_median=0.5042224), cls.InterpolationTestCase('linear with bands and multiple masks', LinearInterpolation('BANDS-S2-L1C', result_interval=(0.0, 1.0), unknown_value=10, mask_feature=[(FeatureType.MASK, 'IS_VALID'), (FeatureType.MASK_TIMELESS, 'RANDOM_UINT8'), (FeatureType.LABEL, 'RANDOM_DIGIT')]), result_len=68, img_min=0.000200, img_max=10.0, img_mean=0.34815648, img_median=0.1003600) ] cls.copy_feature_cases = [ cls.InterpolationTestCase('cubic_copy_success', CubicInterpolation('NDVI', result_interval=(0.0, 1.0), mask_feature=( FeatureType.MASK, 'IS_VALID'), resample_range=( '2015-01-01', '2018-01-01', 16), unknown_value=5, bounds_error=False, copy_features=[ (FeatureType.MASK, 'IS_VALID'), (FeatureType.DATA, 'NDVI', 'NDVI_OLD'), (FeatureType.MASK_TIMELESS, 'LULC'), ]), result_len=69, img_min=0.0, img_max=5.0, img_mean=1.3592644, img_median=0.6174331), cls.InterpolationTestCase('cubic_copy_fail', CubicInterpolation('NDVI', result_interval=(0.0, 1.0), mask_feature=(FeatureType.MASK, 'IS_VALID'), resample_range=( '2015-01-01', '2018-01-01', 16), unknown_value=5, bounds_error=False, copy_features=[ (FeatureType.MASK, 'IS_VALID'), (FeatureType.DATA, 'NDVI'), (FeatureType.MASK_TIMELESS, 'LULC'), ]), result_len=69, img_min=0.0, img_max=5.0, img_mean=1.3592644, img_median=0.6174331), ] for test_case in cls.test_cases: test_case.execute() for test_case in cls.copy_feature_cases: try: test_case.execute() except ValueError: pass
# TASK FOR CONCATENATION concatenate = ConcatenateData('FEATURES', ['BANDS', 'NDVI', 'NDWI', 'NORM']) # TASK FOR FILTERING OUT TOO CLOUDY SCENES # keep frames with > 80 % valid coverage valid_data_predicate = ValidDataFractionPredicate(0.8) filter_task = SimpleFilterTask((FeatureType.MASK, 'IS_VALID'), valid_data_predicate) # 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
# ndvi ndvi_task = NormalizedDifferenceIndexTask((FeatureType.DATA, 'S2-BANDS-L2A'), (FeatureType.DATA, 'NDVI'), [7,3]) # interpolation lin_interp = LinearInterpolation((FeatureType.DATA, 'S2-BANDS-L2A'), mask_feature=(FeatureType.MASK, 'VALID_DATA'), copy_features=[(FeatureType.DATA, 'NDVI'), (FeatureType.DATA, 'FCI'), (FeatureType.DATA, 'ARVI'), (FeatureType.DATA, 'BSI'), (FeatureType.DATA, 'IAD'), (FeatureType.DATA, 'CTVI'), (FeatureType.DATA, 'GEMI'), (FeatureType.DATA, 'WDRVI'), (FeatureType.DATA, 'EVI'), (FeatureType.DATA, 'MTVI'), (FeatureType.DATA, 'CARI2'), (FeatureType.DATA, 'ATSAVI'), (FeatureType.DATA, 'GNDVI'), (FeatureType.DATA, 'MSR'), (FeatureType.DATA, 'NVI'), (FeatureType.DATA, 'RDVI')], resample_range=dates) # add false color infrared feature false_color_infrared_task = ZipFeatureTask({FeatureType.DATA: ['B08', 'B04', 'B03']}, (FeatureType.DATA, 'FCI'), false_color_infrared)
# layer='BANDS-S2-L1C', # feature=(FeatureType.DATA, 'BANDS'), # save under name 'BANDS' # resx='10m', # resolution x # resy='10m', # resolution y # maxcc=0.8, # maximum allowed cloud cover of original ESA tiles # ) cloud_classifier = get_s2_pixel_cloud_detector(average_over=2, dilation_size=1, all_bands=False) add_clm = AddCloudMaskTask(cloud_classifier, 'BANDS-S2CLOUDLESS', cm_size_y='80m', cm_size_x='80m', cmask_feature='CLM', # cloud mask name cprobs_feature='CLP' # cloud prob. map name ) linear_interp = LinearInterpolation( (FeatureType.DATA, 'BANDS'), # name of field to interpolate mask_feature=(FeatureType.MASK, 'IS_VALID'), # mask to be used in interpolation bounds_error=False # extrapolate with NaN's ) add_sh_valmask = AddValidDataMaskTask(SentinelHubValidData(), 'IS_VALID' # name of output mask ) execution_args = [] for id in broken_patches: execution_args.append({ load: {'eopatch_folder': 'eopatch_{}'.format(id)}, save: {'eopatch_folder': 'eopatch_{}'.format(id)} }) structuring_2d = [[0, 1, 0],
count_fields, train=False) # define a valid data mask used in interpolation valid_data = MapFeatureTask((FeatureType.MASK, 'CLOUD'), (FeatureType.MASK, 'VALID_DATA'), np.logical_not) # ndvi ndvi_task = NormalizedDifferenceIndexTask((FeatureType.DATA, 'S2-BANDS-L2A'), (FeatureType.DATA, 'NDVI'), [7,3]) # interpolation lin_interp = LinearInterpolation((FeatureType.DATA, 'S2-BANDS-L2A'), mask_feature=(FeatureType.MASK, 'VALID_DATA'), copy_features=[(FeatureType.DATA, 'NDVI')], # comment this out if NDVI is not used resample_range=dates) # sample only fields sample = SampleValid((FeatureType.MASK_TIMELESS, 'FIELD_ID'), fraction=1.0, no_data_value=0) # if invalid data are at beginning or end of time-series, pad with nearest value fillout = ValueFilloutTask((FeatureType.DATA, 'S2-BANDS-L2A')) workflow = ComposeTask([cloud_mask, #cloud_erosion, cloud_dilation, add_cc, #filter_task, count_train_fields, count_test_fields])
def setUpClass(cls): cls.test_cases = [ cls.InterpolationTestCase('linear', LinearInterpolation( 'ndvi', result_interval=(-0.3, -0.1), unknown_value=10), result_len=180, img_min=-0.3000, img_max=10.0, img_mean=-0.147169, img_median=-0.21132), cls.InterpolationTestCase( 'cubic', CubicInterpolation('ndvi', result_interval=(-0.3, -0.1), resample_range=('2015-01-01', '2018-01-01', 16), unknown_value=5), result_len=69, img_min=-0.3000, img_max=5.0, img_mean=1.30387, img_median=-0.1007357), cls.InterpolationTestCase( 'spline', SplineInterpolation('ndvi', result_interval=(-10, 10), resample_range=('2016-01-01', '2018-01-01', 5), spline_degree=3, smoothing_factor=0), result_len=147, img_min=-0.68187547, img_max=0.26355705, img_mean=-0.1886001, img_median=-0.18121514), cls.InterpolationTestCase('bspline', BSplineInterpolation( 'ndvi', unknown_value=-3, resample_range=('2017-01-01', '2017-02-01', 50), spline_degree=5), result_len=1, img_min=-0.20366311, img_max=0.035470814, img_mean=-0.04307341, img_median=-0.040708482), cls.InterpolationTestCase('akima', AkimaInterpolation('ndvi', unknown_value=0), result_len=180, img_min=-0.4821199, img_max=0.2299331, img_mean=-0.20141865, img_median=-0.213559), cls.InterpolationTestCase( 'nearest resample', NearestResampling('ndvi', result_interval=(-0.3, -0.1), resample_range=('2016-01-01', '2018-01-01', 5)), result_len=147, img_min=-0.3000, img_max=-0.1000, img_mean=-0.19651729, img_median=-0.20000, nan_replace=-0.2), cls.InterpolationTestCase( 'linear resample', LinearResampling('ndvi', result_interval=(-0.3, -0.1), resample_range=('2016-01-01', '2018-01-01', 5)), result_len=147, img_min=-0.3000, img_max=-0.1000, img_mean=-0.1946315, img_median=-0.20000, nan_replace=-0.2), cls.InterpolationTestCase( 'cubic resample', CubicResampling('ndvi', result_interval=(-0.3, -0.1), resample_range=('2015-01-01', '2018-01-01', 16), unknown_value=5), result_len=69, img_min=-0.3000, img_max=5.0, img_mean=1.22359, img_median=-0.181167, nan_replace=-0.2) ] for test_case in cls.test_cases: test_case.execute()
def setUpClass(cls): cls.test_cases = [ cls.InterpolationTestCase('linear', LinearInterpolation( 'ndvi', result_interval=(-0.3, -0.1), unknown_value=10), result_len=180, img_min=-0.3000, img_max=10.0, img_mean=-0.147169, img_median=-0.21132), cls.InterpolationTestCase( 'cubic', CubicInterpolation('ndvi', result_interval=(-0.3, -0.1), resample_range=('2015-01-01', '2018-01-01', 16), unknown_value=5), result_len=69, img_min=-0.3000, img_max=5.0, img_mean=1.30387, img_median=-0.1007357), cls.InterpolationTestCase( 'spline', SplineInterpolation('ndvi', result_interval=(-10, 10), resample_range=('2016-01-01', '2018-01-01', 5), spline_degree=3, smoothing_factor=0.5), result_len=147, img_min=-0.431703, img_max=0.116959, img_mean=-0.1948325, img_median=-0.1922528), cls.InterpolationTestCase('bspline', BSplineInterpolation( 'ndvi', unknown_value=-3, resample_range=('2017-01-01', '2017-02-01', 50), spline_degree=5), result_len=1, img_min=-0.161574, img_max=-0.0116416, img_mean=-0.085181, img_median=-0.0856696), cls.InterpolationTestCase('akima', AkimaInterpolation('ndvi', unknown_value=0), result_len=180, img_min=-0.4821199, img_max=0.2299331, img_mean=-0.20141865, img_median=-0.213559), cls.InterpolationTestCase( 'linear resample', LinearResampling('ndvi', result_interval=(-0.3, -0.1), resample_range=('2016-01-01', '2018-01-01', 5)), result_len=147, img_min=-0.3000, img_max=-0.1000, img_mean=-0.1946315, img_median=-0.20000, nan_replace=-0.2), cls.InterpolationTestCase( 'cubic resample', CubicResampling('ndvi', result_interval=(-0.3, -0.1), resample_range=('2015-01-01', '2018-01-01', 16), unknown_value=5), result_len=69, img_min=-0.3000, img_max=5.0, img_mean=1.22359, img_median=-0.181167, nan_replace=-0.2) ] for test_case in cls.test_cases: test_case.execute()