NetCDF

From GRASS-Wiki
Revision as of 21:06, 15 February 2012 by ⚠️Cmbarton (talk | contribs) (Added information about how to import NetCDF data into GRASS using r.in.gdal)
Jump to navigation Jump to search

Both netCDF import and export in GRASS GIS are basically driven by the GDAL library. Note that GDAL library needs to be compiled with netCDF support to enable GRASS to read and write this format.

netCDF import

The important key to importing NetCDF raster file via r.in.gdal is to specify the correct data subset in the input argument. NetCDF subset specifiers can be obtained from the output of gdalinfo.

For a file named sst.nc...

 gdalinfo sst.nc

...will produce a lot of output, including lines that look like this:

 SUBDATASET_3_NAME=NETCDF:"sst.nc":time_bnds

The input argument to r.in.gdal must contain all the information after the "=" in the format NETCDF:"[path to file in double quotes]":[variable name]. To import the time_bnds data from NetCDF file sst.nc into GRASS, you need to specify the input as follows:

 r.in.gdal input=NETCDF:"sst.nc":time_bnds output=sst

The time_bnds subset may contain multiple data bands. Information about the bands in a subset can be obtained by running gdalinfo on just the subset

 gdalinfo NETCDF:"sst.nc":time_bnds

...will produce output like this:

 Band 22 Block=180x1 Type=Float32, ColorInterp=Undefined
   NoData Value=1e+20
   Metadata:
     NETCDF_VARNAME=tos
     NETCDF_DIMENSION_time=645
     NETCDF_time_units=days since 2001-1-1

You can specify the bands you want to extract using the bands= argument of r.in.gdal

netCDF export

Sample datasets and mini-tutorial

  • (contributions welcome)