WRF data and Xarray

WRF data, from the Weather Research and Forecasting Model, is supported by and commonly used by NCAR scientists. Unfortunately, WRF datafiles are not formatted by the now-popular CF conventions that make it easy to load them into an Xarray dataset: WRF time is in bytes and lat-lon coordinates are stored in a separate file from the data itself.

We encourage scientists to use Xarray because it provides data structures for in-memory analytics that utilize and preserve labels.

While it may take a few extra steps, WRF data is still compatible with Xarray. We acknowled that these steps are not intuitive to scientists that have been using WRF for years but are new to Xarray or Python in general.

This notebook demonstrates using a WRF datafile with the Xarray module and the manipulations necessary to get the dataset into CF conventions understood by Xarray.

[1]:
import xarray as xr
import matplotlib.pyplot as plt
import pandas as pd
from ngallery_utils import DATASETS

First, take a look at the WRF dataset:

[2]:
path = DATASETS.fetch("T2_RR_F_2014_08.nc")
ds_wrf = xr.open_dataset(path)
ds_wrf
Downloading file 'T2_RR_F_2014_08.nc' from 'ftp://ftp.cgd.ucar.edu/archive/aletheia-data/tutorial-data/T2_RR_F_2014_08.nc' to '/home/jovyan/aletheia-data/tutorial-data'.
[2]:
<xarray.Dataset>
Dimensions:      (Time: 720, south_north: 159, west_east: 159)
Dimensions without coordinates: Time, south_north, west_east
Data variables:
    PREC_ACC_NC  (Time, south_north, west_east) float32 ...
    T2           (Time, south_north, west_east) float32 ...
    Times        (Time) |S19 b'2014-08-01_00:00:00' ... b'2014-08-30_23:00:00'
    U10          (Time, south_north, west_east) float32 ...
    V10          (Time, south_north, west_east) float32 ...
Attributes:
    TITLE:                            OUTPUT FROM WRF V3.9 MODEL
    START_DATE:                      2014-08-01_00:00:00
    SIMULATION_START_DATE:           2014-08-01_00:00:00
    WEST-EAST_GRID_DIMENSION:        160
    SOUTH-NORTH_GRID_DIMENSION:      160
    BOTTOM-TOP_GRID_DIMENSION:       51
    DX:                              1000.0
    DY:                              1000.0
    SKEBS_ON:                        0
    SPEC_BDY_FINAL_MU:               1
    USE_Q_DIABATIC:                  0
    GRIDTYPE:                        C
    DIFF_OPT:                        1
    KM_OPT:                          4
    DAMP_OPT:                        3
    DAMPCOEF:                        0.2
    KHDIF:                           0.0
    KVDIF:                           0.0
    MP_PHYSICS:                      28
    RA_LW_PHYSICS:                   4
    RA_SW_PHYSICS:                   4
    SF_SFCLAY_PHYSICS:               1
    SF_SURFACE_PHYSICS:              4
    BL_PBL_PHYSICS:                  1
    CU_PHYSICS:                      0
    SF_LAKE_PHYSICS:                 0
    SURFACE_INPUT_SOURCE:            1
    SST_UPDATE:                      1
    GRID_FDDA:                       0
    GFDDA_INTERVAL_M:                0
    GFDDA_END_H:                     0
    GRID_SFDDA:                      0
    SGFDDA_INTERVAL_M:               0
    SGFDDA_END_H:                    0
    HYPSOMETRIC_OPT:                 2
    USE_THETA_M:                     0
    GWD_OPT:                         0
    SF_URBAN_PHYSICS:                0
    SF_OCEAN_PHYSICS:                0
    SHCU_PHYSICS:                    0
    MFSHCONV:                        0
    FEEDBACK:                        0
    SMOOTH_OPTION:                   2
    SWRAD_SCAT:                      1.0
    W_DAMPING:                       1
    DT:                              5.0
    RADT:                            10.0
    BLDT:                            0.0
    CUDT:                            0.0
    AER_OPT:                         3
    SWINT_OPT:                       0
    AER_TYPE:                        1
    AER_AOD550_OPT:                  1
    AER_ANGEXP_OPT:                  1
    AER_SSA_OPT:                     1
    AER_ASY_OPT:                     1
    AER_AOD550_VAL:                  0.12
    AER_ANGEXP_VAL:                  1.3
    AER_SSA_VAL:                     0.85
    AER_ASY_VAL:                     0.9
    MOIST_ADV_OPT:                   1
    SCALAR_ADV_OPT:                  1
    TKE_ADV_OPT:                     1
    DIFF_6TH_OPT:                    0
    DIFF_6TH_FACTOR:                 0.12
    OBS_NUDGE_OPT:                   0
    BUCKET_MM:                       100.0
    BUCKET_J:                        1000000000.0
    PREC_ACC_DT:                     60.0
    ISFTCFLX:                        0
    ISHALLOW:                        0
    ISFFLX:                          1
    ICLOUD:                          1
    ICLOUD_CU:                       0
    TRACER_PBLMIX:                   1
    SCALAR_PBLMIX:                   1
    YSU_TOPDOWN_PBLMIX:              0
    GRAV_SETTLING:                   0
    OPT_SFC:                         1
    DVEG:                            4
    OPT_CRS:                         1
    OPT_BTR:                         2
    OPT_RUN:                         1
    OPT_FRZ:                         1
    OPT_INF:                         1
    OPT_RAD:                         3
    OPT_ALB:                         2
    OPT_SNF:                         4
    OPT_TBOT:                        1
    OPT_STC:                         1
    OPT_GLA:                         1
    OPT_RSF:                         1
    DFI_OPT:                         0
    SIMULATION_INITIALIZATION_TYPE:  REAL-DATA CASE
    WEST-EAST_PATCH_START_UNSTAG:    1
    WEST-EAST_PATCH_END_UNSTAG:      159
    WEST-EAST_PATCH_START_STAG:      1
    WEST-EAST_PATCH_END_STAG:        160
    SOUTH-NORTH_PATCH_START_UNSTAG:  1
    SOUTH-NORTH_PATCH_END_UNSTAG:    159
    SOUTH-NORTH_PATCH_START_STAG:    1
    SOUTH-NORTH_PATCH_END_STAG:      160
    BOTTOM-TOP_PATCH_START_UNSTAG:   1
    BOTTOM-TOP_PATCH_END_UNSTAG:     50
    BOTTOM-TOP_PATCH_START_STAG:     1
    BOTTOM-TOP_PATCH_END_STAG:       51
    GRID_ID:                         2
    PARENT_ID:                       1
    I_PARENT_START:                  85
    J_PARENT_START:                  89
    PARENT_GRID_RATIO:               3
    CEN_LAT:                         60.36686
    CEN_LON:                         7.049286
    TRUELAT1:                        30.0
    TRUELAT2:                        50.0
    MOAD_CEN_LAT:                    60.0
    STAND_LON:                       5.59998
    POLE_LAT:                        90.0
    POLE_LON:                        0.0
    GMT:                             0.0
    JULYR:                           2014
    JULDAY:                          214
    MAP_PROJ:                        1
    MAP_PROJ_CHAR:                   Lambert Conformal
    MMINLU:                          USGS
    NUM_LAND_CAT:                    28
    ISWATER:                         16
    ISLAKE:                          28
    ISICE:                           24
    ISURBAN:                         1
    ISOILWATER:                      14
    HYBRID_OPT:                      -1
    ETAC:                            0.0
    history:                         Tue Feb  5 11:36:06 2019: ncrcat all_T2_...
    NCO:                             netCDF Operators version 4.7.4 (http://n...
    nco_openmp_thread_number:        1
    history_of_appended_files:       Tue Feb  5 11:36:06 2019: Appended file ...