Updating values of a subset of bands in a DataCube

Hi all,

I am trying to perform a rather simple operation, yet I struggle to implement it with the openeo python API.

I have a DataCube from SENTINEL1_GRD collection, which passes through the sar_backscatter function. I noticed that resulting bands are float32 when downloaded in NetCDF, which eats bandwidth and storage. I want to cast those values to int16. I therefore would like to apply clipping / scaling of VV and VH bands, and a different clipping / scaling to the local_incidence_angle (because it has a different dynamic range). And then I would like to ensure that everything casts to int16.

I ran into the following:

  • local_incidence_angle is not recognized as an ouptut band of the sar_backscatter function (but it exists when downloading the NetCDF). I therefore can not isolate it in a separate DataCube with filter_bands
  • I can only scale the whole DataCube through the linear_scale_range, which applies the same scaling to all bands
  • If I isolate VV and VH through filter_bands, I can scale them separately but then I can not merge into a single DataCube with merge_cubes because I can not isolate local_incidence_angle with filter_bands
  • I can cast to int with apply(processes.int) but I do not know how to ensure int16.

The same issue applies to viewing and sun incidence angles in SENTINEL2_L2A collection. The angles gets casted to int16 in the final NetCDF, which discards most of their dynamic.I would like to scale them before downloading but I run into the same kind of troubles.

Do you have an idea on how to do this ?

Thanks a lot for your help,

Hi Julien,

for more complex band logic, we recommend writing a callback like this:

from openeo.processes import array_create
def normalization(bands):
      return array_create([bands['VV'].linear_scale_range(...),bands['VH'].linear_scale_range(...), bands['angle']])
 sigma0.rename_labels(['VV','VH','angle']).apply_dimension(process=normalization,dimension="bands")

The extra ‘rename_labels’ will fix the missing ‘angle’ label, which is indeed a mismatch between datacube and metadata that we need to solve.

Thanks a lot, this worked fine. By any chance, do you know how I can update the nodata value of the DataCube ? The resulting NetCDF is int32 and not int16, but all values have their range within [0,10000], I assume that the only thing preventing it to be int16 is that each band now has NoData Value=-2147483647 (which makes no sense).

Hi Julien,
apologies for the delay, we had some holidays last week in Belgium.
Normally, the nodata value should have been converted to a value in the int16 as well. Do you perhaps have a job id? I can try to see what happened.

best regards,
Jeroen