Reduce_dimension on time taking e.g. most recent/least recent pixels

Is it somehow possible to use as a reducer something like the most or least recent pixel rather than doing something with the values of the pixels (mean, median,…)?

The main thing I’m trying to accomplish is that I’d like to have all pixels from different bands to be coming from the same source image.

Hi Pieter,

Could it be max_time you are looking for?

url = "https://openeo.cloud"
openeo.connect(url).authenticate_oidc()

spatial_extent_tap = {
    "east": 5.08,
    "north": 51.22,
    "south": 51.215,
    "west": 5.07,
}

datacube = connection.load_collection(
    "SENTINEL2_L2A",
    spatial_extent=spatial_extent_tap,
    temporal_extent=["2023-06-01", "2023-06-20"],
    bands=['B04', 'B03', 'B02'],
    max_cloud_cover=90,
)

datacube = datacube.max_time()  # Keep latest available pixels

datacube.download("max_time.tiff")

Possibly, but I thought that max_time is equivalent to reduce_dimension(dimension="t", reducer="max")… and I would think that that would be the maximum value per pixel in the time series though I do admit this is partly interpretation, as it isn’t crystal clear in the documentation

I just had a quick try, and specifying first as reducer doesn’t give an error, but isn’t documented… so not sure if I can rely on it.

Hi,

You can indeed use first or last in this case. It might give undesired results with nodata, for example on the edge of an image swat.

For those situations, you could use the logic of the best available pixel notebook:
https://documentation.dataspace.copernicus.eu/APIs/openEO/openeo-community-examples/python/RankComposites/bap_composite.html

max_time would indeed take the maximum pixel value, so is probably undesired.

Note that with the best available pixel code, pixels can come from a different date, but all bands in a pixel come from the same date.

Definitely interesting to check for my Sentinel 2 processing chain.

At the moment I was creating sentinel 1 mosaics rather than sentinel 2, but nonetheless I at least have some paths to explore further for that as well.

Thanks!

I looked into this further, and just using “first” as time dimension reducer for S1 collections seem to work fine. Also for locations on the border of two images, the nodata pixels are properly filtered out without needing to do e.g. explicit masking.

It would probably be a good idea to document the availability of the “first” reducer as I think in some cases it is a better fit than the other reducers?

1 Like

Glad to hear it works. In this case it is indeed a better option than max_time.

“first” and “last” are documented here: processes.html#first
When searching for “reduce” in the top left bar, you can find all other options.

Where/how would you expect this to be documented?

This reducer is already documented, e.g.: