Change data type of DataCubes

How to change data type of datacubes?

  • DEM is unit16
  • s2_cube is float32

We are trying to merge the cubes:
s2_cube = s2_cube.merge_cubes(dem_cube.resample_cube_spatial(s2_cube))

But we’ve got the error:

OpenEoApiError: [500] Internal: Server error: assertion failed: Band 8 cell type does not match, float32raw != uint16 (ref: r-3c5bdb5f15a4433da658841ef1bc33ab)

Could you please support us with this @jeroen.dries or @stefaan.lippens ?

Hi Andrea,
you can achieve a change of datatype by scaling the data. Could you try for instance:

s2_cube = s2_cube.linear_scale_range(0.0,1.0,0,10000)

Hope that works! Otherwise we may need to extend the merge_cubes to make it detect on this rather than failing.

Hi Jeroen,
Thanks for the workaround! It works but is a bit hacky so let me explain :slight_smile:

I would like to create data cube with S2 sun zenith and azimuth angles and the DEM. The first are saved as integers but without any scaling and the second as float. So I need to convert the angles to floats thus:

s2_cube = s2_cube.linear_scale_range(0,10000,0.0,1.0)
s2_cube = s2_cube.linear_scale_range(0.0,1.0,0.0,10000.0)

However, when merging the cubes this still gives as error:

Band 2 cell type does not match, float32raw != float32

So I guess that I need to do a similar operation on the DEM as I did on the S2 cube to convert it from float32raw to float32.

What would be really convenient is a NumPy style astype operator or an option in the merge_cubes to make the second cube perfectly fit the first (i.e. it would resample, reproject and convert type as necessary).

Hi,
in fact, this float32raw is a bit problematic in any case, and was causing trouble in the DEM loading:

Could you perhaps try again? I redeployed a version that should change the DEM data type.

I do agree that sometimes explicit type conversion might be more convenient than using linear_scale_range, I’ll need to log an issue for that in openEO processes, so we can define how it should look like.

Hi, it still gives the same error. But this works:

s2_cube = s2_cube.linear_scale_range(0,10000,0.0,1.0)
s2_cube = s2_cube.linear_scale_range(0.0,1.0,0.0,10000.0)
dem_cube = dem_cube.linear_scale_range(0,10000,0.0,1.0)
dem_cube = dem_cube.linear_scale_range(0.0,1.0,0.0,10000.0)
dem_cube = dem_cube.resample_cube_spatial(s2_cube)
merged_cube = s2_cube.merge_cubes(dem_cube)