Updating data in a EO patch

I am trying to re-create the blue dot observatory backend in the aws. How new imagery(observations) are added to the already available eo-patches from earlier observations?

Note: Few blogs and backend implementations have been written on the medium already about the blue dot project, but still it’s a bit difficult for beginners to get around the whole process. I aim to document the step-by-step implementation and my learning process. Right now I am at the stage of an overview survey, will soon start the implementation.

To expand on this, is it possible to have a script run that simply uses a time interval like

time_interval = (datetime.datetime(2017, 1, 1), datetime.datetime.today())

such that when you re-run the script it will only download the newest data for your ROI and add it to the patch? From my reading of core_tasks.py I don’t think that’s built in but perhaps someone has a solution.

Hi @Lex_Leo and @chase

Please see the snippet below:

from eolearn.core import (
    EOPatch, FeatureType, OverwritePermission,
    SaveTask, LoadTask, MergeEOPatchesTask, 
    EOTask
)
from eolearn.io import SentinelHubInputTask

from sentinelhub import (
    CRS, BBox, DataCollection, bbox_to_dimensions
)

import datetime as dt

class AppendSHData(EOTask):
    def __init__(self, sentinelhub_task):
        self.shtask = sentinelhub_task
        
    def execute(self, eopatch):
        bbox = eopatch.bbox
        time_interval = eopatch.timestamp[-1], dt.datetime.now()
        
        new_eop = self.shtask.execute(bbox=bbox, time_interval=time_interval)
        
        updated_eop = EOPatch.merge(eopatch, new_eop)
        
        return updated_eop

s2_data_task = SentinelHubInputTask(
    data_collection=DataCollection.SENTINEL2_L1C,
    size=bbox_to_dimensions(bbox, 40),
    bands_feature=(FeatureType.DATA, 'S2L1C'),
    bands=['B02','B03','B04'],
    additional_data=[(FeatureType.MASK, 'dataMask')],
    maxcc=0.5,
    time_difference=dt.timedelta(hours=2)
)

# creation of "existing" eopatch:

bbox = BBox(((460000, 510000), (465000, 515000)), crs=CRS('32633'))
time_interval = dt.date(2021,12,15), dt.date(2021,12,31)

eop = s2_data_task.execute(bbox=bbox, time_interval=time_interval)

# init the append task

update = AppendSHData(s2_data_task)

# create new eo-patch executing update task on existing eo-patch

new_eop = update.execute(eop)

print("Differences:")
print(set(new_eop.timestamp).difference(set(eop.timestamp)))

The AppendSHData will use SentinelHubInputTask (could be SentinelHubEvalscriptTask as well), execute it on existing eopatch metadata (bbox and last timestamp), and merge the new observations to existing eo-patch.

Please let me know if that helps.

1 Like

Just updating to say this worked really well for me. Is the preferred method to use EOPatch.save() or .load() instead of using the Workflow classes? What you provided makes more intuitive sense to me and seems more Pythonic as well, but I know there are Tasks that can be used too.

Happy to hear that the snippet was helpful.

Regarding the .save/.load vs SaveTask/LoadTask, I would typically use the former when I am “investigating” something in notebooks, and switch to proper tasks when I build an EOWorkflow that I use with EOExecutor.

1 Like