Skip to content

JoseAgustin/wrftoCF

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

wrftoCF — WRF-Chem Output to CF-Compliant NetCDF

Language: NCL CF Convention Based on

NCL scripts that convert native WRF-Chem wrfout NetCDF files into CF-compliant and ACDD-compatible NetCDF files. Extends the original wrfout_to_cf script by Mark Seefeldt (University of Colorado) to include WRF-Chem chemical trace gas and aerosol variables.


Table of Contents


Background

Native WRF and WRF-Chem wrfout files are difficult to use directly in many analysis and visualization tools because:

  • Variable names follow WRF-internal conventions rather than community standards.
  • Key variables such as wind components (U, V) are on the staggered WRF horizontal grid.
  • The vertical coordinate uses native WRF eta levels, not pressure levels or height.
  • Files contain many internal model-state variables not needed for most research applications.
  • NetCDF attributes are often incomplete or non-standard.

The CF (Climate and Forecast) metadata convention addresses these issues by defining standard variable attributes (standard_name, units, long_name, _FillValue, valid_range, etc.) and a time encoding convention, enabling interoperability with tools such as IDV, Panoply, VAPOR, and the MET verification suite.


What This Repository Adds

This repository is an extension of the original wrfout_to_cf script (v2.0.3, Mark Seefeldt, University of Colorado). The modifications made here are:

  1. WRF-Chem chemical variables — trace gases and aerosol species produced by WRF-Chem are included as selectable output variables alongside the standard meteorological fields.
  2. ACDD compatibility — global attributes following the Attribute Convention for Data Discovery (ACDD) are added to the output file, improving discoverability in data portals and catalogues.
  3. Two operational variants — one script for routine operational post-processing (operacional) and one developed for the PAPILA project (papila).

Requirements

Component Version Notes
NCL 6.6.2 (recommended) NCAR Command Language — download
WRF-NCL scripts Bundled with NCL Used internally for unstaggering grids, pressure interpolation, and WRF diagnostics

No compilation is required — NCL is an interpreted language. No additional libraries beyond a standard NCL installation are needed.

NCL v6.6.0+ users: A totype warning may appear for pressure-level output variables due to the deprecation of wrf_user_intrp3d. This is a cosmetic warning only and does not affect output correctness. See NCL End-of-Life Notice.


Repository Structure

wrftoCF/
├── wrfout_to_cf_operacional.ncl   # Operational post-processing variant
├── wrfout_to_cf_papila.ncl        # PAPILA project variant
└── README.md                      # This file

Scripts

wrfout_to_cf_operacional.ncl

General-purpose script for converting WRF-Chem output to CF-compliant NetCDF. Intended for routine operational post-processing of simulation output including both meteorological and chemical fields.

wrfout_to_cf_papila.ncl

Variant developed for the PAPILA (Prediction and Attribution of Present and Future Fluxes of Climate-Relevant Gases) project. Includes additional chemical species and ACDD global metadata tailored to that project's data management requirements.


Usage

Single file

ncl 'file_in="wrfout_d01_2020-01-01_00:00:00"' \
    'file_out="wrfpost_d01_2020-01-01_cf.nc"' \
    wrfout_to_cf_operacional.ncl

Alternatively, set file_in and file_out directly inside the script (near the top of the main program section) and call without arguments:

ncl wrfout_to_cf_operacional.ncl

Batch processing — multiple files

Option 1 — Process all wrfout_d* files in the current directory:

#!/bin/csh -f
foreach file_pre (`ls wrfout_d* | sed 's/\:00\:00//g'`)
  set file_in  = {$file_pre}:00:00
  set file_out = {$file_pre}-cf.nc
  ncl 'file_in="'{$file_in}'"' 'file_out="'{$file_out}'"' wrfout_to_cf_operacional.ncl
end

Option 2 — Loop over a year/month/day/domain matrix:

#!/bin/csh -f
set yyyy = ('2020' '2021')
set mm   = ('01' '02' '03' '04' '05' '06' '07' '08' '09' '10' '11' '12')
set hr   = ('00' '12')
set dom  = ('1' '2')

foreach y ($yyyy)
  foreach m ($mm)
    foreach d (01 02 03)    # adjust day range as needed
      foreach h ($hr)
        foreach n ($dom)
          set file_in  = wrfout_d0${n}_${y}-${m}-${d}_${h}:00:00
          set file_out = ${y}${m}${d}${h}-d0${n}-cf.nc
          ncl 'file_in="'{$file_in}'"' 'file_out="'{$file_out}'"' \
              wrfout_to_cf_operacional.ncl
        end
      end
    end
  end
end

Key Configuration Parameters

These parameters are set near the top of the NCL script. All subsetting index parameters accept (/0,9999/) to select the full available range.

Parameter Example value Description
file_in "wrfout_d01_2020-01-01_00:00:00" Path to the input wrfout NetCDF file
file_out "wrfpost_cf.nc" Path for the CF-compliant output file
TimeUnits "hours since 2001-01-01 00:00:00" Reference epoch for the CF time axis
pressure (/1000.,850.,700.,500.,300./) Target pressure levels for 3D pressure-level output (hPa)
limTime (/0,9999/) Time index range to subset from the input file
limS_N (/45,256/) South–North grid index range for spatial subsetting
limW_E (/41,151/) West–East grid index range for spatial subsetting
limPres (/0,4/) Pressure level index range for pressure-level output
limEta (/0,19/) Eta level index range for eta-level output
limSoil (/0,3/) Soil level index range
outPtop True / False Include the model top pressure variable (P_TOP)
outDateTime True / False Include a yyyymmddhh time field (not useful for sub-hourly output)
outUTCDate True / False Include yr, mo, dy, hr, mn individual time component fields

Selecting output variables

Variables are organised into named groups. To include a variable, both the group flag and the individual variable flag must be True. Setting a group flag to False excludes all variables in that group regardless of individual flags:

out2dMet        = True       ; enable the 2D surface meteorology group
out2dMet@T_2m   = True       ; include 2 m temperature
out2dMet@rh_2m  = True       ; include 2 m relative humidity
out2dMet@ws_10m = False      ; exclude 10 m wind speed

outEta          = False      ; disable entire 3D eta-level group (all variables excluded)

Output Variable Groups

2D Near-Surface Meteorology (out2dMet)

CF name Long name Standard name Units
SST Sea-Surface Temperature sea_surface_temperature K
T_sfc Temperature at the Surface surface_temperature K
p_sfc Pressure at the Surface surface_air_pressure hPa
slp Sea-Level Pressure (WRF-NCL) air_pressure_at_sea_level hPa
slp_b Sea-Level Pressure (lowest level) air_pressure_at_sea_level hPa
T_2m Temperature at 2 m air_temperature °C
Td_2m Dewpoint Temperature at 2 m dew_point_temperature °C
rh_2m Relative Humidity at 2 m relative_humidity %
u_10m_tr U-Component of Wind at 10 m (Earth) eastward_wind m s⁻¹
v_10m_tr V-Component of Wind at 10 m (Earth) northward_wind m s⁻¹
ws_10m Wind Speed at 10 m wind_speed m s⁻¹
wd_10m Wind Direction at 10 m wind_from_direction degrees
precip_g Accumulated Grid-Scale Precipitation large_scale_precipitation_amount mm
precip_c Accumulated Cumulus Precipitation convective_precipitation_amount mm
pblh PBL Height atmosphere_boundary_layer_thickness m
rho Air Density at Lowest Model Level air_density kg m⁻³

3D Meteorology on Eta Levels (outEta)

CF name Long name Units
p_e Pressure hPa
Z_e Geopotential Height m
T_e Temperature K
theta_e Potential Temperature K
r_v_e Water Vapor Mixing Ratio kg kg⁻¹
rh_e Relative Humidity %
u_tr_e U-Component of Wind (Earth) m s⁻¹
v_tr_e V-Component of Wind (Earth) m s⁻¹
ws_e Wind Speed m s⁻¹
w_e Vertical Wind Component m s⁻¹
r_cloud Cloud Water Mixing Ratio kg kg⁻¹
r_rain Rain Mixing Ratio kg kg⁻¹
r_ice Ice Mixing Ratio kg kg⁻¹
r_snow Snow Mixing Ratio kg kg⁻¹
r_graup Graupel Mixing Ratio kg kg⁻¹
pvo_e Potential Vorticity PVU
avo_e Absolute Vorticity 10⁻⁵ s⁻¹

3D Meteorology on Pressure Levels (outPressure)

Same variables as outEta but interpolated to the user-defined pressure levels set by the pressure parameter. Variable names use the suffix _p (e.g., T_p, ws_p, r_v_p).

Surface Energy Budget and Radiation (out2dRadFlx)

CF name Long name Units
SW_d Downwelling Shortwave at Surface (instantaneous) W m⁻²
LW_d Downwelling Longwave at Surface (instantaneous) W m⁻²
SW_u Upwelling Shortwave at Surface (instantaneous) W m⁻²
LW_u Upwelling Longwave at Surface (instantaneous) W m⁻²
LW_u_toa Upwelling Longwave at TOA W m⁻²
SH Sensible Heat Flux at Surface (instantaneous) W m⁻²
LH Latent Heat Flux at Surface (instantaneous) W m⁻²
MH Moisture Heat Flux at Surface (instantaneous) kg m⁻² s⁻¹
LWP Liquid Water Path kg m⁻²
IWP Ice Water Path kg m⁻²
albedo Surface Albedo
emiss_sfc Surface Emissivity
u_star Friction Velocity (u*) m s⁻¹

Accumulated counterparts (e.g., SW_d_acc, LH_acc) are also available in units of J m⁻².

Surface and Soil Variables (out2dLandSoil and outSoil)

Includes land mask, land use category, snow depth and water equivalent, snow density, sea ice fraction, soil temperature, soil moisture, soil liquid water, surface runoff, and sub-surface runoff. See the upstream variable reference for the full listing.

WRF-Chem Chemical Variables

This repository extends the original script to include chemical output from WRF-Chem. The exact set of available variables depends on the chemical mechanism configured for the WRF-Chem simulation (e.g., RADM2, RACM2, CBM-Z, MOZART, SAPRC). Typical additions include:

Category Example variables
Trace gases O₃, NO, NO₂, CO, SO₂, NH₃, HNO₃, individual VOC species
Particulate matter PM2.5, PM10
Aerosol species Sulfate, nitrate, ammonium, organic carbon (OC), elemental carbon (EC)
Photolysis rates J_NO2, J_O3D
Optical properties Aerosol optical depth (AOD)

Each chemical variable is written with the same CF standard attributes (standard_name, long_name, units, _FillValue) as the meteorological variables.


CF and ACDD Compliance

All output variables carry the following standard CF attributes where applicable:

Attribute Description
standard_name CF standard name (e.g., air_temperature)
long_name Human-readable description
units UDUNITS-compatible unit string
_FillValue Fill/missing value
missing_value Same as _FillValue
valid_min / valid_max Physical plausibility range
coordinates References the latitude/longitude coordinate variables

The CF time axis is encoded as:

time:units = "hours since YYYY-MM-DD HH:MM:SS" ;

where the reference epoch is controlled by the TimeUnits parameter.

In addition, these scripts write ACDD global attributes to the output file (e.g., title, summary, institution, source, history, geospatial_lat_min/max, time_coverage_start/end), improving discoverability in THREDDS catalogues and ERDDAP servers.


Validating the Output

CF and ACDD compliance of the output files can be verified with the IOOS Compliance Checker:

pip install compliance-checker
compliance-checker --test cf:1.7 --test acdd output_cf.nc

NCL End-of-Life Notice

NCAR stopped active development of NCL at version 6.6.2, pivoting to Python-based tools. NCL 6.6.2 remains available and functional for the foreseeable future, and these scripts will continue to work with it. The upstream wrfout_to_cf v2.0.3 is expected to be the final NCL release of that project.

For new projects, Python alternatives worth considering:

Tool Purpose
wrf-python WRF diagnostic functions ported to Python
xarray + cf_xarray CF-aware N-dimensional array manipulation
geocat-comp NCAR's Python successor to NCL diagnostics
netCDF4 Low-level NetCDF I/O in Python

Attribution

This work is an extension of:

Seefeldt, M. W. wrfout_to_cf.ncl — NCL script to create CF-compliant NetCDF files from native WRF output. University of Colorado.
https://sundowner.colorado.edu/wrfout_to_cf/overview.html

Extended by José Agustín García Reynoso to include WRF-Chem chemical variables and ACDD global metadata attributes.


README last updated: March 2026

About

Converts wrfoutput from WRF-chem to CF compliant

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages