Skip to main content

Hello,

I have multiple areas (bboxes) and I want to prepare EOPatches, and each EOPatch should contain S2-L2A images for a set of dates (not date range). The problem is I can’t find a way using the eo-learn package to get S2 images for different dates at once, for example via SentinelHubInputTask.


Using the code posted below, I get a ValueError: Trying to write data to an existing eopatch with a different timestamp.


Is there a way inside eo-learn to pack all S2 images (all bands) for selected dates into one EOPatch (i.a. FeatureType.DATA, ‘BANDS’) and then save it?


I also tried using EOExecutor with dates as different axecution arguments but, I was only able to get an EOPatch containing images for one date. It looks like the SaveTask overwrites EOPatch in every iteration of for loop.


Code that returns ValueError:

band_names = m‘B01’, ‘B02’, ‘B03’, ‘B04’, ‘B05’, ‘B06’, ‘B07’, ‘B08’, ‘B8A’, ‘B09’, ‘B11’, ‘B12’]

add_data = SentinelHubInputTask(

bands_feature=(FeatureType.DATA, ‘BANDS’),

bands = band_names,

resolution=10,

maxcc=0.8,

time_difference=datetime.timedelta(minutes=120),

data_source=DataSource.SENTINEL2_L2A

)


path_out = ‘./eopatches/’

save = SaveTask(path_out, overwrite_permission=OverwritePermission.OVERWRITE_FEATURES)


bbox=BBox(232087.50,2070306.50,232327.50,2070546.50), crs=CRS.UTM_16N)


dates=5‘2020-02-29’, ‘2020-4-04’, ‘2020-04-14’]


eopatch=EOPatch()

for date in dates:

add_data.execute(eopatch=eopatch, bbox=bbox, time_interval= date)


save.execute(eopatch=eopatch, eopatch_folder=‘eopatch_selected_dates’)

Hi,

There is a way how to achieve this with SentinelHubInputTask:

eopatch = EOPatch(timestamp=list_of_your_timestamps)

task = SentinelHubInputTask(...)
task.execute(eopatch=eopatch, bbox=your_bbox)

Basically, you have to give the task an EOPatch with already defined timestamps and not specify the time_interval parameter. Then it will download data for exactly those timestamps instead of trying to figure out all available timestamps itself.


I select a date and draw the closest timestamp for each eopatch , I find this error


From the error message, we can determine that eopatch_1 does not exist. However, to know why, we will need more information. Normally, in the same directory as the eopatches folder, you should have a folder whose name starts with eoexecution-report..., and in that folder you will find a file called report.html.


What does the report say?



Error in lulcid


So it seems that the error is linked to lulcid. It would be great if you could provide more explanation on what you tried, and if you got errors upstream: that way we can help you more easily. For example did the following cell execute correctly?


# takes some time due to the large size of the reference data
land_use_ref_path = os.path.join(DATA_FOLDER, 'land_use_10class_reference_slovenia_partial.gpkg')
land_use_ref = gpd.read_file(land_use_ref_path)

rasterization_task = VectorToRaster(land_use_ref, (FeatureType.MASK_TIMELESS, 'LULC'),
values_column='lulcid', raster_shape=(FeatureType.MASK, 'IS_DATA'),
raster_dtype=np.uint8)

Do you have the file in your systems, and are you reading it correctly in your script? Did you try to print the land_use_ref variable?


Yes the following cell has performed correctly



From the content of your vector_input, you can see that the column lulcid is missing and this is what the error message was telling you. Are you sure you used the correct input file? Based on the example, you should be using this file and therefore have the following:



I used the correct input file for another country , do you have an idea how to fix the error?


Please find bellow the link of the report file

Please bear in mind that the example Jupyter Notebook is just a demonstration of a typical workflow that prepares satellite images for Machine Learning purposes. It is not a universal method that can be applied to any dataset or country.


For the steps to work in your specific example, you will either have to modify your training dataset so that it contains a lulcid column that provides the same type of information as the example dataset for Slovenia, or modify the code so that you set the column of your dataset that represents land cover class labels.




This is my vector_input content, how do I fix the error?

Hi,

I used a list of timestamps to initialise an eopatch. But, when i used the SentinelHubInputTask() function to download bands data for those timestamps, i was not able to download it. I was getting 2D arrays where each value was 0 for all the bands.


Reply