openeo-python-client icon indicating copy to clipboard operation
openeo-python-client copied to clipboard

Cumbersome way to calculate temporal difference between two cubes from custom processes

Open Pratichhya opened this issue 3 years ago • 1 comments

# 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()

Pratichhya avatar Dec 06 '22 14:12 Pratichhya

  • at least we should document how to use this CollectionMetadata trick 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)

soxofaan avatar Dec 07 '22 09:12 soxofaan