Skip to main content

Hey there,

I am currently playing around with the excellent eo-learn library and I am wondering if there is any EOTask or workflow that extracts bandwise mean and percentile values over the entire timeperiod?


I found MapFeatureTask, but I am struggling with accessing the single bands from my data set inside the function. So what I am currently doing is something like a nested loop in which I loop over all bands first and execute the workflow from new for each patch. Is this the way to go? Or how would you go on about this?


BAND_NAMES = ["B02","B03,"B04","B05","B06"]

#loop over band bands, and define workflow from new for each band
for b in range(len(BAND_NAMES)-1):

print(BAND_NAMES[b])
#extract band from my S2 Band Stack
move_band = ExtractBandsTask((FeatureType.DATA, 'S2_L2A_BANDS'),
(FeatureType.DATA, BAND_NAMES[b]),
[b])
#calculate mean
calc_mean = MapFeatureTask((FeatureType.DATA, BAND_NAMES[b]), # input features
(FeatureType.DATA_TIMELESS, '{}_mean'.format(BAND_NAMES[b])), # output feature
np.mean, # a function to apply to each feature
axis=0) # function's kwargs

#remove extracted temp. band again
remove_band = RemoveFeature((FeatureType.DATA, BAND_NAMES[b]))

# define the workflow
workflow = LinearWorkflow(load,
move_band,
calc_mean,
remove_band,
save)

for idx, patch_name in enumerate(patch_list):
print(patch_name)

extra_param = {load: {'eopatch_folder': patch_name},
save: {'eopatch_folder': patch_name}}

workflow.execute(extra_param)

Hi @siklar,


Your approach of extracting mean values for each band seems to be ok. However, I have a couple of suggestions for improvements:



  • Instead of creating and running a separate linear workflow for each band you can have one workflow with multiple tasks that extract bands. You can even chain these tasks one after another. The advantage of having a single workflow is that you save and load data only once.




  • Your task that calculates mean values also works on all bands together. Therefore you can switch the order with the ExtractBandsTask. This way you’ll first have a single task that calculates mean and afterward, you have multiple ExtractBandsTask tasks, one for each band.




Thank you for quick response, @maleksandrov! 🥳


Reply