Composite repeated observations of the same area#
Create a composite from aligned observations while keeping track of which observation supplied each selected value.
Choose a reducer and identify the observations#
Start with an aligned stack and keep an ordered mapping from submitted candidates to observation identifiers. If the observations use different grids, first align them to a target grid, then return here.
For a maximum-value composite, select the largest valid sample at each pixel and retain its provenance. The example submits A followed by B and uses each observation’s values as its selection keys.
Accumulate candidates under the memory limit#
Create a TemporalComposite plan and open a CompositeHostSession through host_session(). The example marks both samples in each candidate valid and requests provenance. Change memory_budget to the budget available for your workload.
import numpy as np
import cugeo.raster as raster
observations = [
(101, "A", np.array([[2, 9]], dtype=np.uint16)),
(102, "B", np.array([[7, 4]], dtype=np.uint16)),
]
names = {scene_id: name for scene_id, name, _ in observations}
valid = np.array([[True, True]])
reducer = raster.Reducer.argmax(fill=0, provenance=True)
plan = raster.TemporalComposite(
(1, 2), bands=1, dtype=np.uint16, reducer=reducer,
memory_budget=1 << 20,
)
with plan.host_session() as session:
for scene_id, name, values in observations:
session.accumulate(
values,
validity=valid,
key=values.astype(np.float64),
scene_id=scene_id,
)
result = session.finalize()
print("values:", result.data)
print("observations:", [[names[int(scene_id)] for scene_id in row]
for row in result.scene_id])
print("statuses:", result.status)
If the reducer requires multiple passes, preserve the candidate sequence when replaying it. The host replay sequence is exercised in cugeo-raster/python_tests/test_composite.py.
Read the selected value and its observation together#
Use finalize() for returned result arrays, as above, or finalize_into() for caller-provided destinations.
Check that the values are [7, 9]: the first pixel should identify B and the second A. Check that both statuses denote valid selections under the host status encoding. Repeat the check on a few pixels whose observations you already know in your own stack.