2

I have a Zarr file stored on a S3 custom storage (not AWS), that I want to save as a TIFF file locally. I'm trying to use GDAL for the first time here so I don't fully understand the methods. So far, I've been able to open the source file (Water Bodies from Copernicus land), but the 2 variables and all the dimensions (lat, lon, time) are opened each as a separate sub dataset :

ds.GetSubDatasets()

[('ZARR:"/vsis3/###/copernicus-land/water-bodies.zarr":/lat',
  'Array /lat'),
 ('ZARR:"/vsis3/###/copernicus-land/water-bodies.zarr":/lon',
  'Array /lon'),
 ('ZARR:"/vsis3/###/copernicus-land/water-bodies.zarr":/time',
  'Array /time'),
 ('ZARR:"/vsis3/###/copernicus-land/water-bodies.zarr":/QUAL',
  'Array /QUAL'),
 ('ZARR:"/vsis3/###/copernicus-land/water-bodies.zarr":/WB',
  'Array /WB'),
 ('ZARR:"/vsis3/###/copernicus-land/water-bodies.zarr":/crs',
  'Array /crs')]

So when I try to use gdal.Translate i get :

g = gdal.Translate("output.tif", ds, format="GTiff")

> RuntimeError: output.tif: Unable to export GeoTIFF files with zero bands.

And opening a subdataset :

sub_name = ds.GetSubDatasets()[4][0]
sub = gdal.Open(sub_name)

> RuntimeError: Indices of extra dimensions must be specified

I guess my problem is understanding the Dataset object, I don't get the transformation from dimensions to sub datasets.

1 Answer 1

1

I think you can output a slice of a subset, you can try and read the time data and in geospatial zarrs it is usually a one dimentional raster with the size (n x 1). where n is the available time slices.

time_ds = gdal.Open('ZARR:"/vsis3/###/copernicus-land/water-bodies.zarr":/time')

#this should give you the number of the time slices
available_time_slices = time_ds.RasterXSize

for example try and open the water bodies band slice one :

ds = gdal.Open('ZARR:"/vsis3/###/copernicus-land/water-bodies.zarr":/WB:0')

this dataset shoud be translatable into tiff ( sometimes the size is too much though). You could also consider using gdal.MultiDimTranslate function. I think you will also have to translate only a 2D slice of the data if you want a tiff output.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.