wiki:ADAGUC

Version 16 (modified by maartenplieger, 16 years ago) ( diff )

--

ADAGUC netCDF - * CURRENTLY UNDER CONSTRUCTION *

The ADAGUC netCDF driver reads and writes files which comply with the ADAGUC Data Products Standard ADAGUC website (Atmospheric Data Access for the Geospatial User Community). ADAGUC files are created by using the NetCDF4 API. The NetCDF4 API has the ability to store files in the HDF5 file format while remaining backwards compatible with previous versions of netCDF. The ADAGUC driver supports the creation of NetCDF3 and NetCDF4 files. In NetCDF3 mode the driver writes NetCDF files, in NetCDF4 mode the driver writes HDF5 files. ADAGUC netCDF files follow the Climate and Forecast (CF) 1.2 and ISO:19115 metadata conventions. Besides these conventions the format provides space for specific product metadata.

The file structure

The ADAGUC internal file structure contains variables which can be subdivided in three types: variables to store the metadata, variables to store the dimension scales and variables to store the data. A schematic overview of the ADAGUC file structure for the different types is given in the file structure figure (below on the left). The three types of variables (metadata, dimension scales and data) are indicated with A, B and C respectively.

(A) Metadata - Metadata is stored in attributes which are assigned to a variable. The variables ‘product’, ‘iso_dataset’ and ‘projection’ are used to store the metadata.

(B) Dimension scales - Dimension scales are used as coordinate variables and time intervals. They provide information about geolocation and time to the data variables. The dimension scales follow the NetCDF Climate and Forecast (CF) Metadata Conventions. Dimension scales are lists containing coordinates or time intervals. The dimension scale figure shows geographic raster data with the dimensions time, lat and lon. Its size is, in this example, 4x6x12. This means that there are 4 indexes for time, 6 for latitude and 12 for longitude. According to the CF conventions the dimensions should have the order time, lat, lon. In case the raster data uses a geographic coordinate system, the required dimensions are time, lat and lon which represent the center of the pixel. When the raster data is projected the dimension scales x and y are included which represent the projected coordinates. The dimension scales lat and lon become a function of y and x (see the right part of the file structure), providing the latitude and longitude at the location of y and x, respectively. In this case y and x contain the projected coordinates, while lat and lon represent the geographic latitudes and longitudes in degrees at location y, x. For detailed information see the NetCDF Climate and Forecast (CF) Metadata Conventions.

(C) Data - This part contains the data in the file structure. The data is stored in variables which are functions of the dimension scales. For geographic raster data the variable is a function of time, lat and lon. For projected raster data the variable is a function of time, y and x, as can be seen in the illustration of the file structure. The ADAGUC format currently supports X, Y and time dimensions, stored as dimension scales in the file according the CF Conventions. The driver supports two ways of time sub-setting. The first is by making selections in time by choosing band numbers, the second is by providing the time in the file name. By using gdalinfo on the ADAGUC file the available band numbers and dimensions are listed. With this information a subset can be read with for example:

gdalinfo ADAGUC:thefile.nc:variable:time=20

Left: filestructure; Right: dimension scales


GDAL Creation options

Creation options can be used to provide additional metadata and set the behavior of the driver. Metadata attributes set as a creation option override already existing metadata attributes.

METANCML – It is possible to provide additional metadata which is stored in an NcML XML file. The attributes from the groups product, iso_dataset, projection and custom are copied. When the name of the dataset is specified in the product::variables attribute, specific dataset attributes can be placed under the group with the name of the dataset. A sample file is inluded in the sample ADAGUC zip file (see section sample ADAGUC file).

FORCENC3 – When set to true, the NetCDF4 driver writes in NetCDF3 mode. When unspecified the value is FALSE, in this case the driver writes in NetCDF4 mode.

VALSTART and VALSTOP – Overwrites the product validity_start and product validity_stop attributes in the product group. For example: –co “VALSTART=20080921T101900”

DATASETNAME - Specifies the name of the dataset

LONGNAME, STDNAME and UNITS – Sets the long_name, standard_name and units attributes of the dataset.

NAN – Sets the no data value of the dataset. The _FillValue attribute of the dataset is filled with the NAN number.


Building the driver

Download the required libraries
The ADAGUC netCDF driver requires at least the netCDF-4.0, HDF-1.8.1 and UDUNITS-1 packages to be installed.

Configuring the libraries

  • HDF5 library:
    ./configure --prefix=<installdir> --with-default-api-version=v16
  • netCDF4 library:
    ./configure --prefix=<installdir> --with-hdf5=<installdir> --enable-netcdf-4 --enable-cxx-4 --enable-shared
  • UDUNITS library:
    Un SUSE I had to export several environment variables to make it work:
    export FC=g77
    export CPPFLAGS=-Df2cFortran
    export CC=gcc
    export CXX=g++
    export LD_MATH=-lm
    ./configure --prefix=<installdir>

Installing the GDAL ADAGUC driver

The driver consists of two files, adagucdataset.h and adagucdataset.cpp. These should be copied to the gdal/frmts/netcdf/ directory, so they reside besides the netCDF and GMT driver.

  • 1. Copy adagucdataset.h and adagucdataset.cpp to the ./<gdaldir>/frmts/netcdf/ directory
  • 2. Update the GNUmakefile and makefile.vc in the ./<gdaldir>/frmts/netCDF/ directory by adding the object with name: adagucdataset.o to the already existing objects.
  • 3. Add the registration entry point declaration GDALRegister_ADAGUC() to gdal/gcore/gdal_frmts.h, at the location above the already existing netCDF driver:

In gdal/gcore/gdal_frmts.h:

…
void CPL_DLL GDALRegister_GMT(void);
void CPL_DLL GDALRegister_ADAGUC(void);
void CPL_DLL GDALRegister_netCDF(void);
…
  • 4. Add a call to the registration function to frmts/gdalallregister.c, in the already existing netcdf ifdef:

In frmts/gdalallregister.c:

…
#ifdef FRMT_netcdf
GDALRegister_GMT();
GDALRegister_ADAGUC();
GDALRegister_netCDF();
#endif
…

In step 3 and 4 the ADAGUC register entries should be put above the netCDF register entry, to make sure that ADAGUC files are not opened by the netCDF driver. The ADAGUC driver will only open ADAGUC files, by checking the existence of the iso_dataset and product variables.

Configuring GDAL
To make sure that the libraries are found during the compilation process you can use ./configure LIBS="-lhdf5 -lhdf5_hl -ludunits $LIBS".
Use --with-netcdf=<path to install tree> to build GDAL with the NetCDF library.


Sample ADAGUC files

[This zip file contains a folder with sample ADAGUC files. The folder contains two different datasets. The first contains Sciamachy level 3 tropospheric NO2 measurements obtained from http://www.temis.nl. The second file contains precipitation radar data from the Royal Dutch Meteorological Institute (KNMI, http://www.knmi.nl). The radar dataset has been resampled to 256x256 pixels to make it suitable for this example. The radar dataset contains 24 Radar precipitation images with 5 minute interval ranging from 2008-07-20 00:00:00 till 2008-07-201 01:55:00. This radar dataset is included purely to demonstrate the use of the time dimension. The file is created from a source ADAGUC NetCDF4 file (not included). When translating from an ADAGUC file all time dimensions with corresponding units are copied. It is also possible to subset time by using the select band option -b. Multiple bands can be selected. A single image can also be opened by using ADAGUC:filename.nc:varname.nc:dimname=value, e.g. ADAGUC:RADAR_EXP.NC:NL25_PCP:time=45 The first NO2 dataset is fully ADAGUC compliant and contains metadata obtained from the NCML file.


gdal commands

Create NetCDF4/HDF5 file:

    gdal_translate -of ADAGUC\
     -co "METANCML=SCIA__TEST_R___TMTNO2__L3.xml"\
     -co "VALSTART=20080601T00:00:00.00000"\
     -co "VALSTOP=20080701T00:00:00.00000"\
     SCIA__TEST_R___TMTNO2__L3__20080601T000000_20080701T000000.asc\
     SCIA__TEST_R___TMTNO2__L3__20080601T000000_20080701T000000.h5

Create NetCDF3 file:

    gdal_translate -of ADAGUC\
     -co "METANCML=SCIA__TEST_R___TMTNO2__L3.xml"\
     -co "VALSTART=20080601T00:00:00.00000"\
     -co "VALSTOP=20080701T00:00:00.00000"\
     -co "FORCENC3=TRUE"\
     SCIA__TEST_R___TMTNO2__L3__20080601T000000_20080701T000000.asc\
     SCIA__TEST_R___TMTNO2__L3__20080601T000000_20080701T000000.h5

Create Resampled Precipitation Radar NetCDF3 file with time dimension:

     gdal_translate -of ADAGUC\
     -co "FORCENC3=TRUE" -outsize 256 256 -co "NAN=255"\
     RADAR_EXP.h5\
     RAD___TEST_R_C_NL25PCP_L___20080720T000000_200807201T015500_0001_resampledto256x256.nc

Copy a subset from the radar file to a GeoTiff file:

     gdal_translate -of GTiff ADAGUC:inputfile.nc:NL25_PCP:time=45 outputfile.tif

View ADAGUC files

The driver supports writing in netcdf3 and netcdf4 mode. In case of netcdf3, the files can be viewed with:

The radar dataset can also be animated by Unidata's IDV.


TODO

This is the first release of the driver. Therefore it possible that there are glitches using the driver. The driver has been tested with GDAL 1.5.2 on SuSe linux.
There are still things left to do:

  • Support for scale and offset factors has not yet been implemented
  • Bug testing!

Attachments (7)

Download all attachments as: .zip

Note: See TracWiki for help on using the wiki.