Counting number of image in time intervals

As per title, how to count the number of images in time intervals?

I am currently trying:

from openeo.processes import count

count_dc: DataCube = dc \
    .aggregate_temporal(
        intervals=t_intervals,
        reducer=lambda data: count(data),
        labels=[t_int[0] for t_int in t_intervals]
    )

Where I get:

[500] Internal: Failed to process synchronously on backend vito: OpenEoApiError(โ€˜[400] unknown: Unsupported operation: count (arguments: [data])โ€™)

Strangely this does work with openeo.processes.quantiles. Also tried using the process as a string (e.g. โ€œcountโ€) but no results as of yet.

Any ideas?

HI @jaaplangemeijer, could you please provide us the complete code to reproduce the issue?

The vito backend indeed does not yet support count inside a reducer.
A workaround would be setting all values to 1 and using sum, but Iโ€™m also happy to add an implementation for this, should not be too difficult.

I guess supporting it is the best option, any indication on priority/urgency?

Thanks!

Hi @clausmichele and @jeroen.dries! Thanks for the responses!

Setting values to one are using sum is not something I thought of myself. Priority is low if I have a workaround of course.

Thanks!

If you want to reproduce:

from openeo import connect, Connection
from openeo.rest.datacube import DataCube
from typing import Dict, Union, List

import pathlib

vito_url: str = "https://openeo.vito.be/openeo/1.0"
con: Connection = connect("openeo.cloud")
con.authenticate_oidc(provider_id="egi")

out_dir = pathlib.Path("output")
out_dir.mkdir(parents=True, exist_ok=True)

denia_harbour_bbox: Dict[str, Union[float, str]] = {"west": 0.10594089795383788, "east": 0.12937267590793944, "south": 38.83464299556706, "north": 38.85035302841166, "crs": "EPSG:4326"}
temporal_extent: List[str] = ["2020-08-01", "2021-01-01"]

collection = ("TERRASCOPE_S2_TOC_V2", ["B06", "B05", "B03"])
band_names: str = ["swir1", "nir", "green"]
dc: DataCube = con.load_collection(
        collection_id=collection[0],
        spatial_extent=denia_harbour_bbox,
        temporal_extent=temporal_extent,
        bands=collection[1]
    ).add_dimension(name="source_name", label=collection[0], type="other") \
    .rename_labels(dimension="bands", source=collection[1], target=band_names)

dr: pd.DatetimeIndex = pd.date_range(start=temporal_extent[0], end=temporal_extent[1], freq=f"{year_interval}YS")
t_intervals = [[str(d), str(dr[i+1])] for i, d in enumerate(dr[:-1])]

count_dc: DataCube = dc \
    .aggregate_temporal(
        intervals=t_intervals,
        reducer=lambda data: count(data),
        labels=[t_int[0] for t_int in t_intervals]
    )

count_dc.download(out_dir / "test.nc", format="netcdf")
1 Like