Open-EO / Open-EO/openeo-python-client
Better handling of "cube math" like `cube1 / cube2`
@soxofaan is already working on this.
Since Mar 10, 2025.
- Dominant language
- Python
- Stars
- 217
- Forks
- 56
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 2
Description
The python client has since long a compelling "band math" feature, e.g.:
red = s2cube.band("B04")
nir = s2cube.band("B08")
ndvi = (nir - red) / (nir + red)
which is translated to a reduce_dimension along band dimension with the appropriate reducer.
User however also naively try to use these kind of math expressions without using the .band() method, e.g.:
cube3 = cube1 / cube2
Which kind of works: it will produce a merge_cubes operation with an overlap resolver set to "divide" in this case.
As discussed in https://github.com/Open-EO/openeo-processes/issues/280 this is unfortunately a dangerous approach because it will give unexpected results in situations without 100% overlap
Alternative approach: use merge_cubes without overlap resolver to "stack" bands of both cubes in a single cube and do apply_dimension to combine the bands as desired to a new cube. This would involve quite a bit more steps, but will result in more correct calculation:
- before merge: rename bands to ensure 0 overlap. Also: if there are no bands yet: make sure there are
merge_cubesexplicitly without overlap resolver to make sure bands are stacked- use
apply_dimension(or maybereduce_dimensionin some cases) to implement the desired operation - remame bands again to what the user expects
Quite vital to get this working is that band name handling is correct and in line with how it works backend-side. This might be a bit challenging with load_stac use cases where band detection can be a bit fuzzy.
other related issues:
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.