arlmet.converters.from_wrf#

arlmet.converters.from_wrf(ds, *, winds='instantaneous')[source]#

Convert WRF-ARW output to a Dataset that arlmet.write_dataset() writes.

This is HYSPLIT’s arw2arl with its default variables (instantaneous winds) or, with winds="averaged", its mass-coupled time-averaged winds (arw2arl -c2), taking WRF’s wrfout files as xarray opens them: one file, or several joined along Time (xr.open_mfdataset(files, combine="nested", concat_dim="Time")). The result has source AWRF (which HYSPLIT and arlmet.sample_points() read as WRF), WRF’s own grid and model levels, and the index records’ forecast hour WRF’s XTIME (minutes since the start of the simulation) in hours.

WRF

ARL

conversion

HGT

SHGT

m

PSFC

PRSS

Pa to hPa

RAINC + RAINNC

TPP1

mm to m in the hour before, with DIFR

PBLH

PBLH

m

UST

USTR

m s-1

SWDOWN

DSWF

W m-2

HFX, LH

SHTF, LHTF

W m-2, positive upward

T2

T02M

K

U10, V10

U10M, V10M

m s-1, along the grid’s axes

P + PB

PRES

Pa to hPa

T

TEMP

(T + 300) (P / 1000 hPa) ** (R / cp)

U, V

UWND, VWND

m s-1, as staggered: the west and south faces of each cell

W

WWND

-W g P / (R TEMP (1 + 0.6077 QVAPOR)) in hPa s-1, at the bottom of each layer, with DIFW

QVAPOR

SPHU

kg kg-1

The levels are WRF’s half levels (ZNU) with the surface first: a sigma axis (vertical flag 1) whose offset is the model top P_TOP, or with WRF’s hybrid coordinate (HYBRID_OPT 2) a arlmet.WrfAxis (flag 5). The precipitation of a time step is what fell since the one before, scaled to one hour; the first time step has none, so join every file of a run before converting.

With winds="averaged" (a run with do_avgflx_em = 1), UWND, VWND and WWND are WRF’s AVGFLX_RUM, AVGFLX_RVM and AVGFLX_WWM as stored: averaged over the output interval and coupled to the column mass (no DIFW, as arw2arl -c2 writes them). The file also gets what HYSPLIT decouples them with: MUU0 and MUV0 (WRF’s MUU, MUV), MSFT, MSFU and MSFV (MAPFAC_M, MAPFAC_U, MAPFAC_V), all at the mass points’ faces as stored, and RGHS (ZNT) where the run has it. HYSPLIT and arlmet.sample_points() use UWND * MSFU / MUU0, …; arlmet.open_dataset() returns the stored values.

Parameters:
  • ds (Dataset) – WRF output with its global attributes (MAP_PROJ, CEN_LAT, DX, …) and at least Times, ZNU, P_TOP, P, PB, T, QVAPOR and the winds. Single-level variables not in it are left out.

  • winds (Literal['instantaneous', 'averaged']) – Which winds to write: WRF’s U, V and W at the output time, or the mass-coupled averages over the interval before it (above).

Returns:

The fields in arlmet.open_dataset()’s layout (dims time, level, y, x), with each variable’s ARL units and attrs["diff"] on TPP1 and, for instantaneous winds, WWND. Every model level is kept (arw2arl keeps 50 unless told otherwise); ds.isel(level=...) keeps fewer.

Return type:

Dataset

Raises:

ValueError – If a required variable or attribute is missing, MAP_PROJ is not 1, 2 or 3, or winds is neither “instantaneous” nor “averaged”.

Notes

arw2arl’s TKE list is not converted. arlmet.open_dataset() and arlmet.sample_points() read the winds of the result where WRF put them (AWRF).

Examples

>>> import xarray as xr
>>> import arlmet
>>> wrf = xr.open_mfdataset(
...     "wrfout_d01_2013-06-30_*", combine="nested", concat_dim="Time"
... )
>>> ds = arlmet.converters.from_wrf(wrf)
>>> arlmet.write_dataset(ds, "wrf.arl")