[GIS] Sum many netCDF rasters

geotiff-tiffnetcdfqgisraster

For the first time, I am using NetCDF data files containing daily data about soil moisture at a global level.

I want to be able to obtain monthly mean value of soil moisture for each grid cell.

There is one NetCDF file for each day, and each file contains four bands. I only need the first band which contains the data I want.

Using QGIS 1.8, I encounter the following problems:

1. Loading the rasters

When I want to load the 31 rasters related to January (example), I can select the 31 files, but then, I have to select the band I am interested in for each layer, one by one. Is there a way to load all of them, but automatically select the band I want?

enter image description here

2. Converting the layers

The data comes in a floating number format. I detected some issues when it comes to sum values. However, when I convert the layer to a .tiff raster, it seems to transform the value into an integer. This is what I want, but GDAL doesn't want to batch convert all the files into .tiff, either because of the file names of because of the multiband issue. Is there a way to batch convert NetCDF files into .tiff?

enter image description here

3. Batch summing the layers

Finally, even if I have the layer in .tiff format, I wonder if there is an easier way to sum all the values than by using RasterCalculator. Is there a tool than batch sums up rasters within a folder?
Also, I noticed that I cannot use RasterCalculator directly on the NetCDF layers because of the file names. If the solution is on this trail, is there a way to batch change the name of a layer within a NetCDF file?

Best Answer

1. Loading the raster

Batch convert with gdal_translate the daily soil moisture NetCDF files into GDAL VRT format specifying the band you want to use. Example (band 1):

gdal_translate -of VRT -b 1 netcdf:inputfile.nc:variable_name outputfile.vrt

2. Converting the layers

Batch convert VRTs into GTiff format always with gdal_translate, if you really need it. Example:

gdal_translate -ot Int32 inputfile.vrt outputfile.tif

3. Batch summing the layers

Is there a tool than batch sums up rasters within a folder?

Use gdal_calc.py. Example:

gdal_calc.py -A input1.tif -B input2.tif --outfile=result.tif --calc="A+B"

Is there a way to batch change the name of a layer within a NetCDF file?

If you use the VRT format, you can name the layers as you want.