wrf.getvar

wrf.getvar(wrfin, varname, timeidx=0, method=u'cat', squeeze=True, cache=None, meta=True, **kwargs)

Returns basic diagnostics from the WRF ARW model output.

A table of all available diagnostics is below.

Variable Name Description Available Units Additional Keyword Arguments
avo Absolute Vorticity 10-5 s-1  
eth/theta_e Equivalent Potential Temperature

K

degC

degF

units (str) : Set to desired units. Default is ‘K’.
cape_2d 2D cape (mcape/mcin/lcl/lfc) J kg-1 ; J kg-1 ; m ; m missing (float): Fill value for output only
cape_3d 3D cape and cin J kg-1 missing (float): Fill value for output only
ctt Cloud Top Temperature

degC

K

degF

units (str) : Set to desired units. Default is ‘degC’.
cloudfrac Cloud Fraction %  
dbz Reflectivity dBZ

do_variant (boolean): Set to True to enable variant calculation. Default is False.

do_liqskin (boolean): Set to True to enable liquid skin calculation. Default is False.

mdbz Maximum Reflectivity dBZ

do_variant (boolean): Set to True to enable variant calculation. Default is False.

do_liqskin (boolean): Set to True to enable liquid skin calculation. Default is False.

geopt/geopotential Full Model Geopotential m2 s-2  
helicity Storm Relative Helicity m2 s-2 top (float): The top level for the calculation in meters. Default is 3000.0.
lat Latitude decimal degrees  
lon Longitude decimal degrees  
omg/omega Omega Pa s-1  
p/pres

Full Model Pressure

(in specified units)

Pa

hPa

mb

torr

mmhg

atm

units (str) : Set to desired units. Default is ‘Pa’.
pressure Full Model Pressure (hPa) hPa  
pvo Potential Vorticity PVU  
pw Precipitable Water kg m-2  
rh Relative Humidity %  
rh2 2m Relative Humidity %  
slp Sea Level Pressure

hPa

hPa

mb

torr

mmhg

atm

units (str) : Set to desired units. Default is ‘hPa’.
ter Model Terrain Height

m

km

dm

ft

mi

units (str) : Set to desired units. Default is ‘m’.
td2 2m Dew Point Temperature

degC

K

degF

units (str) : Set to desired units. Default is ‘degC’.
td Dew Point Temperature

degC

K

degF

units (str) : Set to desired units. Default is ‘degC’.
tc Temperature in Celsius degC  
th/theta Potential Temperature

K

degC

degF

units (str) : Set to desired units. Default is ‘K’.
temp Temperature (in specified units)

K

degC

degF

units (str) : Set to desired units. Default is ‘K’.
tk Temperature in Kelvin K  
times Times in the File or Sequence    
xtimes

XTIME Coordinate

(if applicable)

minutes since

start of

model run

 
tv Virtual Temperature

K

degC

degF

units (str) : Set to desired units. Default is ‘K’.
twb Wet Bulb Temperature

K

degC

degF

units (str) : Set to desired units. Default is ‘K’.
updraft_helicity Updraft Helicity m2 s-2

bottom (float): The bottom level for the calculation in meters. Default is 2000.0.

top (float): The top level for the calculation in meters. Default is 5000.0.

ua U-component of Wind on Mass Points

m s-1

km h-1

mi h-1

kt

ft s-1

units (str) : Set to desired units. Default is ‘m s-1’.
va V-component of Wind on Mass Points

m s-1

km h-1

mi h-1

kt

ft s-1

units (str) : Set to desired units. Default is ‘m s-1’.
wa W-component of Wind on Mass Points

m s-1

km h-1

mi h-1

kt

ft s-1

units (str) : Set to desired units. Default is ‘m s-1’.
uvmet10

10 m U and V Components of Wind

Rotated to Earth Coordinates

m s-1

km h-1

mi h-1

kt

ft s-1

units (str) : Set to desired units. Default is ‘m s-1’.
uvmet

U and V Components of Wind

Rotated to Earth Coordinates

m s-1

km h-1

mi h-1

kt

ft s-1

units (str) : Set to desired units. Default is ‘m s-1’.
wspd_wdir

Wind Speed and Direction (wind_from_direction)

in Grid Coordinates

m s-1

km h-1

mi h-1

kt

ft s-1

units (str) : Set to desired units. Default is ‘m s-1’.
wspd_wdir10

10m Wind Speed and Direction (wind_from_direction)

in Grid Coordinates

m s-1

km h-1

mi h-1

kt

ft s-1

units (str) : Set to desired units. Default is ‘m s-1’.
uvmet_wspd_wdir

Wind Speed and Direction (wind_from_direction)

Rotated to Earth Coordinates

m s-1

km h-1

mi h-1

kt

ft s-1

units (str) : Set to desired units. Default is ‘m s-1’.
uvmet10_wspd_wdir

10m Wind Speed and Direction (wind_from_direction)

Rotated to Earth Coordinates

m s-1

km h-1

mi h-1

kt

ft s-1

units (str) : Set to desired units. Default is ‘m s-1’.
z/height Full Model Height on Mass Levels

m

km

dm

ft

mi

msl (boolean): Set to False to return AGL values. True is for MSL. Default is True.

units (str) : Set to desired units. Default is ‘m’.

Parameters:
  • wrfin (netCDF4.Dataset, Nio.NioFile, or an iterable) – WRF-ARW NetCDF data as a netCDF4.Dataset, Nio.NioFile or an iterable sequence of the aforementioned types.
  • varname (str) – The variable name.
  • timeidx (int or wrf.ALL_TIMES, optional) – The desired time index. This value can be a positive integer, negative integer, or wrf.ALL_TIMES (an alias for None) to return all times in the file or sequence. The default is 0.
  • method (str, optional) – The aggregation method to use for sequences. Must be either ‘cat’ or ‘join’. ‘cat’ combines the data along the Time dimension. ‘join’ creates a new dimension for the file index. The default is ‘cat’.
  • squeeze (bool, optional) – Set to False to prevent dimensions with a size of 1 from being automatically removed from the shape of the output. Default is True.
  • cache (dict, optional) – A dictionary of (varname, ndarray) that can be used to supply pre-extracted NetCDF variables to the computational routines. It is primarily used for internal purposes, but can also be used to improve performance by eliminating the need to repeatedly extract the same variables used in multiple diagnostics calculations, particularly when using large sequences of files. Default is None.
  • meta (bool, optional) – Set to False to disable metadata and return numpy.ndarray instead of xarray.DataArray. Default is True.
  • **kwargs – Optional keyword arguments for certain diagnostics. See table above.
Returns:

If xarray is enabled and the meta parameter is True, then the result will be a xarray.DataArray object. Otherwise, the result will be a numpy.ndarray object with no metadata.

Return type:

xarray.DataArray or numpy.ndarray

Raises:
  • ValueError – Raised when an invalid diagnostic type or keyword argument is passed to the routine.
  • FortranError – Raised when a problem occurs during a Fortran calculation.

Examples

Using netCDF4

from netCDF4 import Dataset
from wrf import getvar

wrfnc = Dataset("wrfout_d02_2010-06-13_21:00:00")
slp = getvar(wrfnc, "slp")

Using PyNIO

from Nio import open_file
from wrf import getvar

wrfnc = open_file("wrfout_d02_2010-06-13_21:00:00"+".nc", "r")
slp = getvar(wrfnc, "slp")

Using Iterables:

import os
from netCDF4 import Dataset
from wrf import getvar

filedir = "/path/to/wrf/files"
wrfin = [Dataset(f) for f in os.listdir(filedir)
        if f.startswith("wrfout_d02_")]

uvmet = getvar(wrfin, "uvmet", timeidx=3, units="kt")