What is a NetCDF file?
NetCDF stands for Network Common Data Form and is a binary file format for storing scientific data, commonly used in meteorology, climatology, and Geographic Information System (GIS) applications. It was developed by the University Corporation for Atmospheric Research (UCAR) in 1988.
A netCDF file is self-describing as it always includes a header with information of the rest of the file, the binary arrays, and the names of the attributes. The format is machine-independent.
NetCDF files are widely used in multiple applications, for example, most of the Numerical Prediction Model Weather Research Forecast (WRF) input and output files are written in this format.
There are several versions of NetCDF files, including a netCDF-4/HDF5 format. HDF stands for Hierarchical Data Format, a standard used by NASA Earth Observing System.
NetCDF files are supported by a multitude of languages, such as C, FORTRAN, Python, R, Perl, MATLAB, and IDL.
The most popular command-line applications are:
- ncdump from Unidata, part of the NetCDF libraries. Outputs contents of a netCDF file as ASCII.
- NCAR Command Language (NCL) An interpreted language designed by the National Center for Atmospheric Research (NCAR).
- Climate Data Operators (CDO). A package developed by the Max-Planck-Institute for Meteorology
- NetCDF Operators (NCO) A suite of programs written in C and C++ under a GNU license.
There are also some graphical visualization packages such as ArcGIS, Panoply, and ncview.
Examples of operations with NetCDF files:
# Dump the header of a NetCDF file ncdump -h input.nc # Dump the whole NetCDF file ncdump input.nc # Dump the U wind component ncdump -v,U input.nc # Calculate wind speed from U and V cdo -s expr,'M=sqrt(U^2+V^2);' input.nc out.nc # Interpolate the file at 120m height cdo -s intlevel,120 input.nc out.nc # Interpolate a file to a different grid or mask cdo interpolate,input.nc masking.nc out.nc # Select a region defined by two latitudes [41.4, 42.5] and two longitudes [1.5, 2.2] cdo -s sellonlatbox,1.5,2.2,41.4,42.5 input.nc out.nc # Look up data values for a location [41.4,2.2] and time [20210903 08:00] cdo -outputtab,lon,lat,date,time,value -selyear,2021 -selmonth,09 -selday,03 -seltime,08:00 -remapnn,lon=2.2_lat=41.4 input.nc # Convert a GRIB file to NetCDf file cdo -f nc copy file.grb out.nc