Hacking with Environmental Data

Logo

WALD's help page for geospatial hackers

View ANU WALD GitHub

View ANU WALD website

View ANU WALD Slack channel

20 March 2020

GDAL and NetCDFs

by

Description

GDAL is a C++ library which also offers a series of command line tools for reading and converting between multiple raster data formats. On the NCI there are several version of GDAL available. To load GDAL you’ll need to type:

$ module load gdal

Or to load a specific version:

$ module load gdal/2.2.2

GDAL is quite old and was originally designed to work mainly with GeoTIFFs. NetCDFs can also be used but the interface requires using a weird notation. The problem is that NetCDFs can contain multiple variables inside and we need to be explicit about the variable that we want GDAL to use. For example, if we use gdalinfo to display the information of a NetCDF from the Fuel Moisture Content (FMC) collection on the NCI:

$ gdalinfo /g/data/ub8/au/FMC/c6/flam_c6_2001_h29v11.nc
Driver: netCDF/Network Common Data Format
Files: /g/data/ub8/au/FMC/c6/flam_c6_2001_h29v11.nc
Size is 512, 512

...

Subdatasets:
  SUBDATASET_1_NAME=NETCDF:"/g/data/ub8/au/FMC/c6/flam_c6_2001_h29v11.nc":flammability
  SUBDATASET_1_DESC=[88x2400x2400] flammability (32-bit floating-point)
  SUBDATASET_2_NAME=NETCDF:"/g/data/ub8/au/FMC/c6/flam_c6_2001_h29v11.nc":anomaly
  SUBDATASET_2_DESC=[88x2400x2400] anomaly (32-bit floating-point)
  SUBDATASET_3_NAME=NETCDF:"/g/data/ub8/au/FMC/c6/flam_c6_2001_h29v11.nc":quality_mask
  SUBDATASET_3_DESC=[88x2400x2400] quality_mask (8-bit integer)
Corner Coordinates:
Upper Left  (    0.0,    0.0)
Lower Left  (    0.0,  512.0)
Upper Right (  512.0,    0.0)
Lower Right (  512.0,  512.0)
Center      (  256.0,  256.0)

At the end of the output returned by gdalinfo there is a section listing the subdatasets contained in this file with a ‘handler’, which is how GDAL refers to each variable.

Now, we can use this handler with gdalinfo to visualise the contents of each variable in the NetCDF:

$ gdalinfo NETCDF:"/g/data/ub8/au/FMC/c6/flam_c6_2001_h29v11.nc":flammability/g/data/ub8/au/FMC/c6/flam_c6_2001_h29v11.nc

This command will print information relative to the Coordinate Reference System (CRS) of the variable, extents will also list the temporal dimension as bands in the file. This is another limitation of GDAL not being able to handle multidimensional files properly and having to map the extra dimensions into bands as if it was a GeoTIFF.

tags: