Hi @paolo.filippucci,
Can you show more explicitly what you tried? Feel free to paste the code in a code block.
Otherwise, I would suggest doing this via writing you own custom EOTasks, which enable you to create a reference feature.
Example 1: A specific date as a reference
Say you have an EOPatch with BANDS
feature of the FeatureType.DATA
type in your eopatch, and that there are 15 timestamps in the eopatch, where you would like to take the 8th timestamp as the reference. This means you have to create a FeatureType.DATA_TIMELESS
feature in your eopatch, where the mentioned task comes in, which can map an input feature to a new output feature.
from eolearn.core import EOPatch, EOTask, FeatureType
class TemporalSliceTask(EOTask):
def __init__(self, in_feature_name: str, out_feature_name: str, temporal_index: int):
self.in_feature = (FeatureType.DATA, in_feature_name)
self.out_feature = (FeatureType.DATA_TIMELESS, out_feature_name)
self.temporal_index = temporal_index
def execute(self, eopatch: EOPatch) -> EOPatch:
eopatch[self.out_feature] = eopatch[self.in_feature][self.temporal_index]
return eopatch
The task above accepts the input feature name, loads the data, selects the index, and then saves the output slice as a new timeless feature. You would use it like this:
slice_task = TemporalSliceTask(in_feature_name="BANDS", out_feature_name="BANDS_SLICE", temporal_index=7)
eop = slice_task.execute(eop)
Example 2: Temporal mean as a reference
Similar to the above, but the temporal mean of the input feature can be calculated to serve as a common reference. Here you can extend the task to use a cloud mask in order to not aggregate and ignore the cloudy areas.
import numpy as np
from eolearn.core import EOPatch, EOTask, FeatureType
class TemporalMeanTask(EOTask):
def __init__(self, in_feature_name: str, clm_feature_name: str, out_feature_name: str):
self.in_feature = (FeatureType.DATA, in_feature_name)
self.clm_feature = (FeatureType.MASK, clm_feature_name)
self.out_feature = (FeatureType.DATA_TIMELESS, out_feature_name)
def execute(self, eopatch: EOPatch) -> EOPatch:
data = eopatch[self.in_feature]
mask = eopatch[self.clm_feature]
data[mask] = np.nan # set cloudy area to np.nan
eopatch[self.out_feature] = np.nanmean(data, axis=0) # mean over the first (the temporal) axis, ignoring nans
return eopatch
Then, after calculating the reference feature, you can run the coregistration task and just provide the reference feature as a parameter.
Let me know if this helps. If not. I’d kindly ask you to provide a code snippet so we can faster determine where the issue lies.
Cheers,
Matic