Reading WRF data into Xarray and Visualizing the Output using hvPlot#
The typical data workflow within the Python ecosystem when working with Weather Research and Forecasting (WRF) data is to use the wrf-python package! Traditionally, it can be difficult to utilize the
xarray data model with WRF data, due to a few challenges:
WRF data not being CF-compliant (which makes it hard for xarray to properly construct the dataset out of the box using xr.open_dataset)
wrf-python requiring to interact with both netCDF4-python and xarray’s APIs (which can be a daunting task)
The lack of functionality in wrf-python needed to take full advantage of dask’s laziness and parallelism
In this example, we show how you can use the extremely experimental package
xWRF, to read in data and plot an interactive visualization of your data!
Again, the stress here is experimental such that this is a proof of concept - not meant to be used directly in workflows; but rather to show what is possible given further development.
By the end of this example, we will generate an interactive plot which looks like the following!
Before we start using
xwrf, we need to install it. We can install by following these steps!
Install this in your python environment using pip (
pip install git+https://github.com/NCAR/xwrf.git)
Open up a notebook and use the imports shown below!
xwrf provides an xarray backend, which helps with reading in the file. When you are working with non-cf-compliant datasets (ex. WRF output), this backends transform the file into a format that is easier to work with (ex. helpful coordinate information).
You could complete this task using a preprocess function (see xarray open_mfdataset documentation), but this would get tricky once you add more advanced IO functionality.
Here, we only need a few packages;
import glob import holoviews as hv import hvplot import hvplot.xarray import xarray as xr import xwrf from distributed import Client from ncar_jobqueue import NCARCluster hv.extension('bokeh')