cmosig / sentle

Sentinel-1 & Sentinel-2 data cubes at large scale (bigger-than-memory) on any machine with integrated cloud detection, snow masking, harmonization, merging, and temporal composites.
MIT License
22 stars 2 forks source link

aggregate function is called on singular timestamps even though time_composite is set to None #12

Closed cmosig closed 1 month ago

cmosig commented 3 months ago

Only noticable when cloud/snow mask is returned.

When there are no clouds detected for an aggregated pixel, then the mask is set to np.nan instead of zero. np.nan should be reserved in all masks when there is no S2 data.

When we return the cloud mask... https://github.com/cmosig/sentle/blob/02f77c1dbdebe0fd545e9a584776c61c5e2d154c/sentle/sentle.py#L691 ...we only count non-zero values for the later mean operation: https://github.com/cmosig/sentle/blob/02f77c1dbdebe0fd545e9a584776c61c5e2d154c/sentle/sentle.py#L703 Meaning this will create a div by zero error for the cloud mask, resulting in an np.nan for values that should actually be clear sky.

Fix: put an if time_composite_freq is not None: here: https://github.com/cmosig/sentle/blob/02f77c1dbdebe0fd545e9a584776c61c5e2d154c/sentle/sentle.py#L699C5-L703C41

And as an additional enhancement one could turn off counting values entirely when not aggregating: -> saves RAM and processing

cmosig commented 3 months ago

There should also be no merge when the number of timestamps to merge is 1, which can happen when the aggregate window is very small.