xarray RADOLAN backend

In this example, we read RADOLAN data files using the xarray radolan backend.

[ ]:
import glob
import os
import wradlib as wrl
import warnings
warnings.filterwarnings('ignore')
import matplotlib.pyplot as pl
import numpy as np
import xarray as xr
try:
    get_ipython().magic("matplotlib inline")
except:
    pl.ion()

Load RADOLAN Data

[ ]:
fpath = 'radolan/misc/raa01-rw_10000-1408030950-dwd---bin.gz'
f = wrl.util.get_wradlib_data_file(fpath)
comp = wrl.io.open_radolan_dataset(f)

Inspect Data

[ ]:
display(comp)

Plotting

[ ]:
comp.RW.plot.pcolormesh(x='x', y='y')
pl.gca().set_aspect('equal')

Inspect RADOLAN moments

The DataArrays can be accessed by key or by attribute. Each DataArray has dimensions and coordinates of it’s parent dataset.

[ ]:
display(comp.RW)

Create simple plot

Using xarray features a simple plot can be created like this.

[ ]:
comp.RW.plot(x="x", y="y", add_labels=False)
[ ]:
fig = pl.figure(figsize=(10,10))
ax = fig.add_subplot(111)
comp.RW.plot(x="x", y="y", ax=ax)

Mask some values

[ ]:
ds = comp['RW'].where(comp['RW'] >= 1)
ds.plot()

Export to NetCDF4

[ ]:
# fix _FillValue
comp.RW.encoding["_FillValue"] = 65535
[ ]:
comp.to_netcdf("test_radolan.nc")

Import again

[ ]:
comp1 = xr.open_dataset("test_radolan.nc")
comp1

Check equality

[ ]:
xr.testing.assert_equal(comp, comp1)

More RADOLAN loading mechanisms

Use xr.open_dataset

[ ]:
comp2 = xr.open_dataset(f, engine="radolan")
display(comp2)

Use xr.open_mfdataset to retrieve timeseries

[ ]:
#fpath = 'radolan/misc/raa01-rw_10000-1408030950-dwd---bin.gz'
fpath = wrl.util.get_wradlib_data_path()
f = os.path.join(fpath, 'radolan/misc/raa01-sf_10000-1305*.gz')
[ ]:
comp3 = xr.open_mfdataset(f, engine="radolan")
display(comp3)