Convert NetCDF files

The examples below show how SILO’s NetCDF files can be converted to either

SILO’s gridded datasets are arranged in annual blocks. The examples show how the gridded dataset for a single day can be extracted from an annual file and converted to the desired format.

Software requirements

The examples use the Geospatial Data Abstraction Library (GDAL). See the GDAL binaries page for installation instructions, or you may wish to compile from source.

NOTE: It is recommended that a recent version of GDAL be used. Old versions may produce unexpected results.

The following examples have been tested on:

  • GDAL 2.2.1 on Windows x86-64
  • GDAL 1.9.1 on GNU/Linux x86-64.

Example 1. Extract a single time-slice and convert to ArcASCII format

The following command:

gdal_translate [annual_netcdf_file] \
    [daily_arcascii_file] -of AAIGrid -ot Float32 -b [day_of_year] \
    -unscale -a_nodata [missing_value] -co "DECIMAL_PRECISION=1"

will extract a single time-slice (day_of_year) from the input NetCDF file ( annual_netcdf_file), and output an ArcASCII file (daily_arcascii_file) in 32-bit floating point format (Float32) written with one decimal place ( "DECIMAL_PRECISION=1").

For example, to extract the daily grid for 1 September 1970 (244th day in the year) in ArcASCII format:

  1. Download the 1970 maximum temperature NetCDF file (1970.max_temp.nc). This can be done using a variety of methods.
  2. Extract the daily grid to file 19700901.max_temp.asc:
  3. gdal_translate 1970.max_temp.nc 19700901.max_temp.asc \
        -of AAIGrid -ot Float32 -b 244 -unscale -a_nodata -3276.8 \
        -co "DECIMAL_PRECISION=1"
    

Example 2. Extract a single time-slice and convert to a GeoTiff image

The following commands:

gdal_translate [annual_netcdf_file] tmp.nc \
    -of NetCDF -ot Float32 -b [day_of_year] -unscale -a_nodata [fill_value] \
    -a_srs [grid_projection]
gdaldem color-relief tmp.nc [colour_map_file] [daily_geotiff_file] \
    -of GTiff -alpha -nearest_color_entry -co "COMPRESS=DEFLATE"

will output the desired time-slice in GeoTiff format. The first command ( gdal_translate …) extracts the time-slice into a temporary NetCDF file (tmp.nc). The second command (gdaldem …) converts the temporary NetCDF file into a GeoTiff image using the given colour map (colour_map_file) and compression options (COMPRESS=DEFLATE).

A colour map is a text file specifying the colours used for mapping raster data to colour values. You may wish to use these sample maps which SILO constructed from images taken from the Bureau of Meteorology’s Climate Maps website:

For example, to extract the daily grid for 1 September 1970 (244th day in the year) in GeoTiff format:

  1. Download the 1970 maximum temperature NetCDF file (1970.max_temp.nc). This can be done using a variety of methods.
  2. Use ncdump to read the scale and offset attributes (see the metadata)
    ncdump -h 1970.max_temp.nc 
  3. Extract the daily grid to a temporary NetCDF file:
  4. gdal_translate 1970.max_temp.nc 19700901.max_temp.nc \
        -of NetCDF -a_nodata -3276.8 -ot Float32 -b 244 -unscale -a_srs epsg:4326
    

    (assuming add_offset was 0.0 and scale_factor was 0.1).

  5. Convert the temporary file to GeoTiff:
  6. gdaldem color-relief 19700901.max_temp.nc max_temp.clr \
        19700901.max_temp.tif -of GTiff -alpha -nearest_color_entry \
        -co "COMPRESS=DEFLATE"
    
Licence
Creative Commons Attribution 4.0 International (CC BY 4.0) ( http://creativecommons.org/licenses/by/4.0/ )
Last updated
18 Sep 2017