NetCDF: Difference between revisions

From GRASS-Wiki
Jump to navigation Jump to search
m (+cat geodata)
 
(5 intermediate revisions by 4 users not shown)
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.
* ''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 ==
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


* see the [[GMT]] page and {{cmd|r.in.gdal}}
...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
 
* also see the [[GMT]] page and {{cmd|r.in.gdal}}


== netCDF export ==
== netCDF export ==
Line 7: Line 39:
* see {{cmd|r.out.gdal}}
* see {{cmd|r.out.gdal}}


* As part of a Google Summer of Code 2009 project Andrea Antonello has put together a [http://jgrass.wiki.software.bz.it/jgrass/weekly_reports GUI controlled GRASS raster timeseries to netCDF export tool using uDig].
* As part of a Google Summer of Code 2009 project Andrea Antonello has put together a [http://code.google.com/p/jgrass/wiki/SummerOfCode2009 GUI controlled GRASS raster timeseries to netCDF export tool using uDig].


== Sample datasets and mini-tutorial ==
== Sample datasets and mini-tutorial ==
Including conversion from global grid-registration to cell-center registration by cropping off northern, southern, and western rows of cells, then using r.region to set remaining in-bounds cell outer boundaries.


* (''contributions welcome'')
* (''contributions welcome'')
Line 15: Line 49:
[[Category: FAQ]]
[[Category: FAQ]]
[[Category: Geodata]]
[[Category: Geodata]]
[[Category: Import]]

Latest revision as of 00:03, 23 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

Including conversion from global grid-registration to cell-center registration by cropping off northern, southern, and western rows of cells, then using r.region to set remaining in-bounds cell outer boundaries.

  • (contributions welcome)