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
arw2arlwith its default variables (instantaneous winds) or, withwinds="averaged", its mass-coupled time-averaged winds (arw2arl -c2), taking WRF’swrfoutfiles as xarray opens them: one file, or several joined alongTime(xr.open_mfdataset(files, combine="nested", concat_dim="Time")). The result has sourceAWRF(which HYSPLIT andarlmet.sample_points()read as WRF), WRF’s own grid and model levels, and the index records’ forecast hour WRF’sXTIME(minutes since the start of the simulation) in hours.WRF
ARL
conversion
HGTSHGT
m
PSFCPRSS
Pa to hPa
RAINC+RAINNCTPP1
mm to m in the hour before, with
DIFRPBLHPBLH
m
USTUSTR
m s-1
SWDOWNDSWF
W m-2
HFX,LHSHTF, LHTF
W m-2, positive upward
T2T02M
K
U10,V10U10M, V10M
m s-1, along the grid’s axes
P+PBPRES
Pa to hPa
TTEMP
(T + 300) (P / 1000 hPa) ** (R / cp)U,VUWND, VWND
m s-1, as staggered: the west and south faces of each cell
WWWND
-W g P / (R TEMP (1 + 0.6077 QVAPOR))in hPa s-1, at the bottom of each layer, withDIFWQVAPORSPHU
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 topP_TOP, or with WRF’s hybrid coordinate (HYBRID_OPT2) aarlmet.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 withdo_avgflx_em = 1),UWND,VWNDandWWNDare WRF’sAVGFLX_RUM,AVGFLX_RVMandAVGFLX_WWMas stored: averaged over the output interval and coupled to the column mass (noDIFW, asarw2arl -c2writes them). The file also gets what HYSPLIT decouples them with:MUU0andMUV0(WRF’sMUU,MUV),MSFT,MSFUandMSFV(MAPFAC_M,MAPFAC_U,MAPFAC_V), all at the mass points’ faces as stored, andRGHS(ZNT) where the run has it. HYSPLIT andarlmet.sample_points()useUWND * 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 leastTimes,ZNU,P_TOP,P,PB,T,QVAPORand the winds. Single-level variables not in it are left out.winds (
Literal['instantaneous','averaged']) – Which winds to write: WRF’sU,VandWat the output time, or the mass-coupled averages over the interval before it (above).
- Returns:
The fields in
arlmet.open_dataset()’s layout (dimstime,level,y,x), with each variable’s ARLunitsandattrs["diff"]onTPP1and, for instantaneous winds,WWND. Every model level is kept (arw2arlkeeps 50 unless told otherwise);ds.isel(level=...)keeps fewer.- Return type:
- Raises:
ValueError – If a required variable or attribute is missing,
MAP_PROJis not 1, 2 or 3, orwindsis neither “instantaneous” nor “averaged”.
Notes
arw2arl’s TKE list is not converted.arlmet.open_dataset()andarlmet.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")