openeo-python-client
openeo-python-client copied to clipboard
Cumbersome way to calculate temporal difference between two cubes from custom processes
# load before flash flood params
before_date = ["2021-06-13","2021-06-13"]
after_date = ["2021-07-18", "2021-07-18"]
# Create a processing graph from the NDWI process using an active openEO connection
before_ndwi = eoconn.datacube_from_process("NDWI", namespace="vito", date=before_date
,polygon=aoi)
# Create a processing graph from the NDWI process using an active openEO connection
after_ndwi = eoconn.datacube_from_process("NDWI", namespace="vito", date=after_date
,polygon=aoi)
from openeo.metadata import CollectionMetadata
before_ndwi.metadata = CollectionMetadata({"cube:dimensions":{"t":{"type":"temporal"}}})
after_ndwi.metadata = CollectionMetadata({"cube:dimensions":{"t":{"type":"temporal"}}})
# final result
# compute the change between pre and post image
merging_cubes = after_ndwi.merge_cubes(-before_ndwi)
differenced_cube = merging_cubes.reduce_dimension(dimension="t",reducer='sum')
#differenced_cube.download()
- at least we should document how to use this
CollectionMetadatatrick to monkeypatch a metadata-less datacube so that the client does not complain about absent dimension when doing, e.g. temporal reduction - next step could also be to make the process more ergonomic, e.g. less boilerplate to declare that a cube has some dimension, or a way to disable metadata-checking (e.g. automatically when datacube comes from
datacube_from_process)