NetCDF: Difference between revisions

From GRASS-Wiki
Jump to navigation Jump to search
(note gdal version)
Line 1: Line 1:
Both netCDF import and export in GRASS GIS are basically driven by the [http://www.gdal.org GDAL library]. Note that GDAL library needs to be compiled with [http://www.gdal.org/frmt_netcdf.html netCDF support] to enable GRASS to read and write this format.
Both netCDF import and export in GRASS GIS are basically driven by the [http://www.gdal.org GDAL library]. Note that GDAL library needs to be compiled with [http://www.gdal.org/frmt_netcdf.html netCDF support] to enable GRASS to read and write this format.
* ''Due to [http://trac.osgeo.org/gdal/wiki/NetCDF_Improvements important bug fixes] in the NetCDF driver, it is strongly recommended to use GDAL version 1.9 or newer.''


== netCDF import ==
== netCDF import ==

Revision as of 23:35, 22 November 2013

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.

  • Due to important bug fixes in the NetCDF driver, it is strongly recommended to use GDAL version 1.9 or newer.

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)