1

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(
                destNameOrDestDS=destNameOrDestDS,
                srcDSOrSrcDSTab=srcDSOrSrcDSTab,
                srcSRS=srcSRS,
                dstSRS=dstSRS,
                dstNodata=float(srcNodata),
                format="NETCDF",
                xRes=xRes,
                yRes=yRes,
                targetAlignedPixels=targetAlignedPixels,
            )

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.

2 Answers 2

2

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.

3
  • I figured that since I found a 5 year old open issue on it, before migrating to github. Commented Apr 2, 2020 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
    Commented Jul 5, 2020 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. Commented Jul 6, 2020 at 14:40
0

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 and acknowledge you have read our privacy policy.

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