Datacube to DataArray

How can the DEM be transformed to dataArray when DEM is still a cube?

dem.get_array() takes a long time and mean_time() keeps the dem as a datacube

dem = connection.load_collection('COPERNICUS_30', spatial_extent = spatial_extent,   
                                bands= ["DEM"])
dem = dem.mean_time()

Hi @sulova.andrea,
I found myself in a very similar situation. I can offer you two workarounds:

  1. dem=dem.reduce_dimension(reducer=‘mean’,dimension=‘t’) which allow you to remove the temporal dimension;
  2. dem=dem.drop_dimension(“t”) which it is probably the most correct but it has still to be fixed and therefore it works only if you connect to the development instance “https://openeo-dev.vito.be

Hope this helps
Paolo

1 Like

Thank you @paolo.filippucci.
Despite dropping the t dimension, the dem is still a datacube type

Yeah, but is has now just two dimensions, x and y, as you can see if you try to download it.

Hi Andrea,
in the Python client API, the ‘DataArray’ type that exists in the openEO process specification is not really visible.
Instead, processes that expect a DataArray need to be used in the context of a ‘callback’. In Paolo’s example of reduce_dimension, the ‘mean’ process is passed as a very simple callback into reduce_dimension, and on the server side will receive a DataArray as input.
Callbacks in the python client are explained here:
https://open-eo.github.io/openeo-python-client/processes.html#processes-with-child-callbacks

If you have a more concrete case of what you would like to do with the DataArray, I might be able to help a bit further!

best regards,
Jeroen

Thanks Jereon.
So what If we have this case:

in the old code:

dem = rxr.open_rasterio('srtm.tif')
type(dem)

transform = dem.rio.transform()
print(transform)
Affine(0.00027777777779320863, 0.0, 74.999861111,
       0.0, -0.00027777777779835176, 34.0001388

if we want to replace dem for collection this collection```

dem  = connection.load_collection('COPERNICUS_30', spatial_extent = spatial_extent,   
                                bands= ["DEM"])
dem = dem.reduce_dimension(reducer='mean',dimension='t') 

how can we apply it in a transform function?

See my other answer on the affine transform, openEO does it for you, so you don’t need to worry about applying the coordinate transformation!
In general, openEO code will be simpler then the rasterio variant as we do a number of things implicitly.