Adding calcution to band in image collections

When I dowload my images from the server I am missing the ndwi band in results. The ndwi calculation cube_ndwi = (B03 - B08) / (B03 + B08) was done from cube bands and then it was added t cube its band. (cube.add(cube_ndwi)) howver I can not see the it ndwi in my final result. however I can see the ndvi which was calculated before. How ndwi can be added to final result?

Hi @sulova.andrea ,
Maybe the problem is theprocess you are using ot merge the datacubes:
I guess that “add” should be used to perform a sum, while you need probably to use the “merge_cubes” operation. Can you try and see if this resolve your issue?

1 Like

@sulova.andrea as @paolo.filippucci said, you would need to use merge_cubes like this:

B03 ='B03')
B08 ='B08')

NDWI = (B03 - B08) / (B03 + B08)
NDWI = NDWI.add_dimension(name='bands',label='NDWI')

cube = cube.merge_cubes(NDWI)

The result will then contain B03, B08 and NDWI bands.

The most efficient approach is actually to use a built-in function from the client, it’s based on the ‘Awesome spectral indices’ project, which supports a large number of predefined indices. In this case, you simply need ‘append_index’

So in your case, it becomes:

from openeo.extra.spectral_indices.spectral_indices import append_index

it avoids doing a ‘merge_cubes’, making it a bit faster.

Thank you! append_index works well