WRF NetCDF Extract&Join (wrfncxnj)

The output of the Weather Research and Forecasting model (WRF) is, by default, written in NetCDF files formatted according to specific WRF conventions. Most of the software packages (e.g. CDO) and international projects that involve climate modelling (CORDEX, CMIP, etc.) require CF conventions. Also, the way output data are produced by the model in a climate run (all variables in a single file split in time) does not match the modeller's usage pattern (usually requiring a few variables over the whole period). WRF NetCDF Extract&Join (wrfncxnj) addresses this problem in a flexible way. It is written in python, but is its designed to be invoked from the command line. Due to the large amount of available options it is usually preferable to call wrfncxnj from a Shell script. The main goal is to simplify the post-processing of large amounts of data generated by WRF, making it a less time-consuming and error-prone task. Since python is an interpreted language, WRF NetCDF Extract&Join does not need to be installed or compiled, and it has few dependencies, that can be installed from repositories in most linux distributions.

The tool has been originally developed at the University of Cantabria by Markel García-Díez, Jesús Fernández and Lluís Fita.


The last version of WRF NetCDF Extract&Join was released in 2014-05-15 and is available here:



WRF NetCDF Extract&Join does not need to be installed. It can be used directly after extracting the tarball. However, it has the following system dependencies:

Note that the netCDF4 python library is not equivalent to the python-netcdf package available from linux repositories. Currently, it must be downloaded from the web cited above.

Update: Another possibility (easier) is to install a scientific python distribution such as [Anaconda https://store.continuum.io/cshop/anaconda/], that already comes with this packages.


WRF NetCDF Extract&Join is invoked from the command line as:

python wrfncxnj.py [options] [files to process]

A description of all the options available can be obtained executing:

python wrfncxnj.py -h

The ASCII file wrfncxnj.table plays a central role in translating the WRF variables to CF conventions. This file can be modified by the user to meet its needs. The user interested in modifying the rest of the code should check the /TechnicalDescription. Users are highly encouraged to look into the code, play with it, and report back any bug or improvement.

The essential elements of the command line needed are the list of variables to be extracted, the output file (or pattern, is the output is to be splitted into variables or levels), the reference time for the time axis and the "wrfout" files, which can be provided as arguments. See the following example:

python wrfncxnj.py [flags] --split-variables --time-units="days since 1949-12-01_00:00:00" --output-pattern=EXPERIMENT_[varcf].nc -v "VAR1,VAR2,VAR3" wrfout1.nc wrfout2.nc ... wrfoutN.nc

This command would read variables VAR1, VAR2 and VAR3 from wrfout1.nc wrfout2.nc ... wrfoutN.nc and write them in separate files labelled by their CF name. Notice that VAR1, VAR2 and VAR3 are not the CF names of the variables, but the name that appears in the first column of wrfncxnj.table (usually, the variable name in WRF). Different wrfncxnj variables can share the same CF name, so the unique names for the variables are the WRF names (or the aliases in the first column of wrfncxnj.table).

In the present moment Extract&Join works both with WRF raw files, with the 3-D fields stored in eta levels, and with WRF files interpolated to pressure levels using the program p_interp. A modified p_interp has been developed by the group and will be released soon, but currently all the features should work with the version available in the WRF users page. Yet, this has not been fully tested. User must note than the flags -p, --split-levels, --sel-plevs, and the "p" value in wrfncxnj.table do not work if the input files are pure WRF raw data. Note also that the variable "Times" must be kept when files are filtered with p_interp, so wrfncxnj can use it to generate the time axis.

The easiest way to learn wrfncxnj.py is by means of examples.


Extract a single variable from a file or several

python wrfncxnj.py -o EXPERIMENT_tas.nc --time-units="days since 1949-12-01_00:00:00" -v T2 wrfout1.nc wrfout2.nc ... wrfoutN.nc

This command extracts the 2 meter temperature from N wrfout files and saves it in a single file named EXPERIMENT_tas.nc

Extract several variables into a single file

python wrfncxnj.py -p -o EXPERIMENT.nc --time-units="days since 1949-12-01_00:00:00" -v T2,Q2,QVAPOR wrfout1.nc wrfout2.nc ... wrfoutN.nc

This command extracts 2 m temperature, 2 m specific humidity and specific humidity 3-D field. They are all stored in a single file called EXPERIMENT.nc. -p flag is needed so a pressure axis is created in the output file. In case the wrfout files have not been passed trough p_interp, -z would be needed to create the eta level vertical axis.

Extract several variables into separate files, splitted by level

python wrfncxnj.py --split-variables --split-levels -output-pattern EXPERIMENT_[varcf]_[level].nc --time-units="days since 1949-12-01_00:00:00" -v T2,Q2,QVAPOR wrfout1.nc wrfout2.nc ... wrfoutN.nc  

This command does the same of the previous one, but stores each variable and level in a different file, which name is constructed from the pattern given with --output-pattern. The ---split-level option works both with pressure and soil levels. It is possible to filter them using the --plevs-filter and --slevs-filter flags (e.g. --plevs-filter="925,850,700,500,300").

Extract a derived variable

python wrfncxnj.py  -o EXPERIMENT_tdps.nc --time-units="days since 1949-12-01_00:00:00" -v TDPS wrfout1.nc wrfout2.nc ... wrfoutN.nc

This command uses T2,Q2 and PSFC to compute the 2 meter dew point temperature and saves it into a single file. To add a new derived variable, check wrfncxnj.table

Get the orography and landmask from geo_em.nc

python wrfncxnj.py --single-record -g /volume/DATA/WRF/domains/EXPERIMENT/geo_em.d01.nc --time-units="days since 1949-12-01_00:00:00" -v  HGT_M,LANDMASK -o EXPERIMENT_static.nc

This command extracts the terrain height and the land-sea mask from the output file produced by geogrid.exe. It uses the --single-record option to get a single time-step.

Add global attributes to the output files

The flag -a lets you add arbitrary gobal attributes to the files. These are provided in a text file (e.g. named global.attr) containing an attribute per line

Conventions "CF-1.4"
title "Evaluation run"
source "WRF 3.1.1 modified at the University of Cantabria"
institution "Universidad de Cantabria (Spain)"
references ""
comment "The simulation was forced with ERA-Interim data as boundary conditions"

python wrfncxnj.py -a global.attr -o EXPERIMENT_tas.nc -v T2 wrfout1.nc wrfout2.nc ... wrfoutN.nc