Using world cover as mask timeless in eoworkflow

Hi

I want to try and use the 10m world cover by ESA as a feature mask timeless in my workflow.

I couldn’t find information on how to go about it.

My guess is to define a new data collection like this:

DataCollection.define(
        name='Global Land Cover',
        api_id='byoc-0b940c63-45dd-4e6b-8019-c3660b81b884',  #Type
        catalog_id='0b940c63-45dd-4e6b-8019-c3660b81b884', # collection_id
        service_url='services.sentinel-hub.com', # End point
        is_timeless=True
    )

and then maybe use it in SentinelHubInputTask with a filter task.

But I didn’t find any similar code in the EOlearn examples.

How can I accomplish this?

TNX

Hi @tonish,

The example below shows how you define new DataCollection using information from SH collections web page, and create SentinelHubInputTask that you can then add to your workflow.

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

from eolearn.core import EOPatch, FeatureType
from eolearn.io import SentinelHubInputTask

import matplotlib.pyplot as plt
import datetime as dt
import numpy as np

caspian_sea_bbox = BBox([49.9604, 44.7176, 51.0481, 45.2324], crs=CRS.WGS84)
time_interval = '2015-03-10', '2020-05-01'

glc = DataCollection.define(
    name='Global Land Cover, forest',
    api_id='byoc-f0a97620-0e88-4c1f-a1ac-bb388fabdf2c', # type 
    catalog_id='f0a97620-0e88-4c1f-a1ac-bb388fabdf2c',  # collectionId
    service_url='https://creodias.sentinel-hub.com',    # end point
    is_timeless=False,
    bands=[
        Band('Forest_Type_layer', (Unit.DN,), (np.float32,)),
        Band('Tree_CoverFraction_layer', (Unit.DN,), (np.float32,)),
    ]
)

input_task = SentinelHubInputTask(
    data_collection=glc,
    size=bbox_to_dimensions(caspian_sea_bbox, 200),
    bands_feature=(FeatureType.DATA, 'glc'),
    bands=['Forest_Type_layer']
)

eop = input_task.execute(bbox=caspian_sea_bbox, time_interval=time_interval)

The caveat is that the SentinelHubInputTask wants the results to be written to FeatureType.DATA, so you might have to create new Task that takes the particular time out of results and returns it as FeatureType.MASK_TIMELESS. Let us know if you run into additional troubles.

I modified your example and combined it with another input task to but I am getting the error:

ValueError: During execution of task SentinelHubInputTask: Trying to write data to an existing eopatch with a different timestamp.

Each task is working on its own but chaining them produces the error.
EDIT : glc_task returns 1 in the first dimension and add_data returns 2. But I couldn’t figure out how to resolve it.
I feel like there is something basic that I am missing here.
Also, how is this working without a SHconfig object?

AOI = BBox(bbox=[5.60, 52.68, 5.75, 52.63], crs=CRS.WGS84)
time_interval = '2020-01-01', '2020-01-20'

glc = DataCollection.define(
    name='Global Land Cover10m',
    api_id='byoc-0b940c63-45dd-4e6b-8019-c3660b81b884',  #Type
    catalog_id='0b940c63-45dd-4e6b-8019-c3660b81b884', # collection_id
    service_url='https://services.sentinel-hub.com', # End point
    is_timeless=False,
    bands=[
        Band('Map', (Unit.DN,), (np.float32,)),
    ]

band_names = ['B02', 'B03', 'B04']
add_data = SentinelHubInputTask(
    bands_feature=(FeatureType.DATA, 'BANDS'),
    bands = band_names,
    resolution=10,
    maxcc=0.8,
    time_difference=datetime.timedelta(minutes=120),
    data_collection=DataCollection.SENTINEL2_L1C,
    max_threads=5
)

glc_task = SentinelHubInputTask(
    data_collection=glc,
    size=bbox_to_dimensions(AOI, 200),
    bands_feature=(FeatureType.DATA, 'glc'),
    bands=['Map']
)

workflow = LinearWorkflow(glc_task,add_data)

result = workflow.execute({
    add_data: {'bbox': AOI, 'time_interval': time_interval},
    glc_task: {'bbox': AOI, 'time_interval': time_interval}
})