I have a netcdf file that is structured with precipitation grid values with dimensions (time, x, y)

When I perform gdal.warp (in python if that matters) I get a new file that has multiple bands that have dimensions (x, y), with the number of bands = len(time) of the previous file and time is not part of the new file.

Is there a way to preserve the dimensions, precipitation name, and time in the new file?

import gdal

warped = gdal.Warp(

So my source netcdf file looks like:

  • crs
  • QPE
  • time
  • x
  • y
  • z

where crs is the coordinate system and QPE is precipitation and then my output looks like:

  • Albers
  • Band1
  • Band2
  • Band3
  • x
  • y

I would like to preserve the original structure so combine the Bands into a single 3 dimensional array with time as the 3rd dimension.


NetCDF driver is documented in https://gdal.org/drivers/raster/netcdf.html

Creation Issues

This driver supports creation of NetCDF file following the CF-1 convention. You may create set of 2D datasets. Each variable array is named Band1, Band2, … BandN. Each band will have metadata tied to it giving a short description of the data it contains.

Is seems that you must use some other tool than GDAL for creating a 3D dataset.

  • I figured that since I found a 5 year old open issue on it, before migrating to github. Apr 2 '20 at 7:41
  • @JeffTilton hi, could you shared the solution? Probably could solve mu problem: I have thousand tiff file and need to convert it to netcdf with time dimension enabled and merge into single netcdf.
    – user97103
    Jul 5 '20 at 12:22
  • @user97103 you probably wouldn't like my solution, but you can see what I did here at the end of the warp method. I since learned of the rasterio package for xarray that uses gdal on the backend. It has a warp method, but I couldn't get it to work, although I didn't try hard since I had this set. I think that would be the better route. Jul 6 '20 at 14:40

You need to transform your data in .tiff with gdal_translate, make the resize with gdalwarp, and then back to .nc with gdal_translate again.

Tips for increased speed: https://trac.osgeo.org/gdal/wiki/UserDocs/GdalWarp

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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