NetCDF format
This is intended as a short introduction to netCDF data. The complete netCDF documentation can be found on the UNIDATA web site.
Quick links to
- Climate and Forecast (CF) Metadata Convention Page from CEDA
- List of downloadable software to write, read and handle NetCDF files
Contents
- What is NetCDF?
- Why use NetCDF?
- NetCDF and the Climate and Forecast (CF) Metadata Convention
- What's in a NetCDF file? – Example.
- Reading and writing NetCDF files – Including links to downloadable software packages.
- Further information – On NetCDF and the Climate Forecast (CF) Metadata Convention.
What is netCDF?
NetCDF (network Common Data Form) is an interface for array-orientated data access and a library that provides an implementation of that interface. Many groups have adopted netCDF as a standard way to represent their scientific data. The netCDF software was developed at the Unidata Program Center in Boulder Colorado USA.
Why use netCDF?
The NetCDF format has a wide range of reasons why it is one of CEDA's recommended formats, including:
- being extensively used within the atmospheric and oceanic science communities.
- being a portable self-describing binary data format.
- it is network-transparent, meaning that it can be accessed by computers that store integers, characters and floating-point numbers in different ways.
- it provides direct-access: a small subset of a large dataset may be accessed efficiently, without first reading through all the preceding data.
- it is appendable: data can be appended to a netCDF dataset along one dimension without copying the dataset or redefining its structure.
- datasets can be read and written in a number of languages, these include C, C++, FORTRAN, IDL, Python, Perl, and Java.
- the different language implementations are freely available from the UNIDATA ftp area
- several graphics packages support netCDF input, making it very easy to display and analyse netCDF datasets. For instance FERRET and UVCDAT provide both command line and graphical user interfaces for displaying and analysing gridded data.
- netCDF is completely and methodically documented in UNIDATA's NetCDF User's Guide.
- several groups have defined conventions for netCDF files, to enable the exchange of data. CEDA has adopted the Climate and Forecasting (CF) conventions for netCDF data.
NetCDF and CF conventions
CEDA supports and strongly recommends the compliance with the Climate and Forecast (CF) Metadata Convention.
The CF conventions are guidelines and recommendations as to where to put information within a netCDF file, and they provide advice as to what type of information you might want to include. CF conventions allow the creator of the dataset to include information about the data and the dataset itself (metadata) in a structured way, which makes it easier for other users to retrieve the information. Global attributes describe the general properties and origins of the dataset while local attributes are used to characterise the recorded variables.
CEDA provides an Introduction to the CF Convention, illustrated by some examples.
What's in a netCDF file?
This is best described with the following very simple example of a netCDF file with CF conventions applied. In this you will see that a netCDF dataset (the filename ends in .nc) is made up of three basic components:
- variables
- dimensions
- attributes
The variables store the actual data, the dimensions give the relevant dimension information for the variables, and the attributes provide auxiliary information about the variables or the dataset itself. You can study an example of a netCDF file and see more details of the components in a netCDF dataset. The global attributes can also be added to the netCDF file, following CF conventions.
Reading and writing netCDF
The popularity of netCDF stems from its portability and relative ease of use. Although it is a binary data format the netCDF distribution comes complete with the ncdump utility which produces an ASCII dump of the dataset and thereby provides a quick-look facility. You can also generate netCDF files from ASCII data files using the ncgen utility.
The datasets are commonly written and read using library routines. The library routines are sensibly named and relatively consistently named across the different language implementations.
Help and tools
1. Guidance and tools provided by CEDA:
- Installing the netCDF package provided by Unidata and trying out ncgen and ncdump. – Converting NetCDF to ASCII.
- XCONV/CONVSH – Allows visualisation, conversion and subsetting of NetCDF data on Unix/Linux systems.
- NetCDF format checker – If you wish to check that files are correctly formatted before uploading them to CEDA, please use this online tool.
2. Selected links to available online software packages to write, read and handle NetCDF files:
Software for Manipulating or Displaying NetCDF Data – A list of links to a variety of freely available and commercial or licensed software packages to create or handle NetCDF files, provided by Unidata at UCAR (USA).
- cf-python: a Python Earth Science data analysis library that is built on a complete implementation of the CF data model.
- iris: a powerful, format-agnostic, community-driven Python package for analysing and visualising Earth science data.
- NCL: NCAR Command Language (NCL), an interpreted language designed for scientific data analysis and visualisation. It supports netCDF-3/4, GRIB-1/2, HDF4-SDS, HDF4-EOS, HDF5-EOS and shapefiles.
- xarray: (formerly xray) is an open-source project and Python package that makes working with labelled multi-dimensional arrays simple, efficient, and fun!
Further information
For a more extensive description you are urged to read the UNIDATA documentation on netCDF.
The UNIDATA documentation also provides the File Format Specification for netCDF and Best Practice recommendations on writing netCDF files.
The NetCDF Climate and Forecast (CF) Metadata Convention defines metadata that provide a definitive description of what the data in each variable represents, and of the spatial and temporal properties of the data. The CF conventions generalize and extend the COARDS conventions developed under the sponsoring of NOAA.