xarray Rainbow5 backend#
In this example, we read Rainbow5 data files using the xradar rainbow xarray backend.
import glob
import gzip
import io
import wradlib as wrl
import wradlib_data
import warnings
from IPython.display import display
import matplotlib.pyplot as plt
import numpy as np
import xradar as xd
import xarray as xr
warnings.filterwarnings("ignore")
Load Rainbow5 Volume Data#
fpath = "rainbow/2013051000000600dBZ.vol"
f = wradlib_data.DATASETS.fetch(fpath)
vol = xd.io.open_rainbow_datatree(f, reindex_angle=False)
Downloading file 'rainbow/2013051000000600dBZ.vol' from 'https://github.com/wradlib/wradlib-data/raw/main/data/rainbow/2013051000000600dBZ.vol' to '/home/docs/.cache/wradlib-data'.
Inspect RadarVolume#
display(vol)
<xarray.DataTree>
Group: /
│ Dimensions: (sweep: 14)
│ Coordinates:
│ latitude float64 8B ...
│ longitude float64 8B ...
│ altitude float64 8B ...
│ Dimensions without coordinates: sweep
│ Data variables:
│ volume_number int64 8B 0
│ platform_type <U5 20B 'fixed'
│ instrument_type <U5 20B 'radar'
│ time_coverage_start <U20 80B '2013-05-10T00:00:06Z'
│ time_coverage_end <U20 80B '2013-05-10T00:03:14Z'
│ sweep_fixed_angle (sweep) float64 112B 0.6 1.4 2.4 3.5 ... 21.3 25.4 30.0
│ sweep_group_name (sweep) int64 112B 0 1 2 3 4 5 6 7 8 9 10 11 12 13
│ Attributes:
│ Conventions: None
│ instrument_name: None
│ version: None
│ title: None
│ institution: None
│ references: None
│ source: None
│ history: None
│ comment: im/exported using xradar
├── Group: /sweep_0
│ Dimensions: (azimuth: 361, range: 400)
│ Coordinates:
│ * azimuth (azimuth) float64 3kB 0.5055 1.549 2.505 ... 358.5 359.5
│ elevation (azimuth) float64 3kB ...
│ time (azimuth) datetime64[ns] 3kB 2013-05-10T00:00:15.50000...
│ * range (range) float32 2kB 125.0 375.0 ... 9.962e+04 9.988e+04
│ Data variables:
│ DBZH (azimuth, range) float64 1MB ...
│ sweep_mode <U20 80B ...
│ sweep_number int64 8B ...
│ prt_mode <U7 28B ...
│ follow_mode <U7 28B ...
│ sweep_fixed_angle float64 8B ...
├── Group: /sweep_1
│ Dimensions: (azimuth: 361, range: 400)
│ Coordinates:
│ * azimuth (azimuth) float64 3kB 0.5055 1.549 2.516 ... 358.5 359.5
│ elevation (azimuth) float64 3kB ...
│ time (azimuth) datetime64[ns] 3kB 2013-05-10T00:00:25.62121...
│ * range (range) float32 2kB 125.0 375.0 ... 9.962e+04 9.988e+04
│ Data variables:
│ DBZH (azimuth, range) float64 1MB ...
│ sweep_mode <U20 80B ...
│ sweep_number int64 8B ...
│ prt_mode <U7 28B ...
│ follow_mode <U7 28B ...
│ sweep_fixed_angle float64 8B ...
├── Group: /sweep_2
│ Dimensions: (azimuth: 361, range: 400)
│ Coordinates:
│ * azimuth (azimuth) float64 3kB 0.511 1.505 2.505 ... 358.5 359.5
│ elevation (azimuth) float64 3kB ...
│ time (azimuth) datetime64[ns] 3kB 2013-05-10T00:00:36.65151...
│ * range (range) float32 2kB 125.0 375.0 ... 9.962e+04 9.988e+04
│ Data variables:
│ DBZH (azimuth, range) float64 1MB ...
│ sweep_mode <U20 80B ...
│ sweep_number int64 8B ...
│ prt_mode <U7 28B ...
│ follow_mode <U7 28B ...
│ sweep_fixed_angle float64 8B ...
├── Group: /sweep_3
│ Dimensions: (azimuth: 361, range: 400)
│ Coordinates:
│ * azimuth (azimuth) float64 3kB 0.511 1.505 2.521 ... 358.5 359.5
│ elevation (azimuth) float64 3kB ...
│ time (azimuth) datetime64[ns] 3kB 2013-05-10T00:00:46.77272...
│ * range (range) float32 2kB 125.0 375.0 ... 9.962e+04 9.988e+04
│ Data variables:
│ DBZH (azimuth, range) float64 1MB ...
│ sweep_mode <U20 80B ...
│ sweep_number int64 8B ...
│ prt_mode <U7 28B ...
│ follow_mode <U7 28B ...
│ sweep_fixed_angle float64 8B ...
├── Group: /sweep_4
│ Dimensions: (azimuth: 361, range: 400)
│ Coordinates:
│ * azimuth (azimuth) float64 3kB 0.5 1.522 2.516 ... 358.5 359.5
│ elevation (azimuth) float64 3kB ...
│ time (azimuth) datetime64[ns] 3kB 2013-05-10T00:01:08.77272...
│ * range (range) float32 2kB 125.0 375.0 ... 9.962e+04 9.988e+04
│ Data variables:
│ DBZH (azimuth, range) float64 1MB ...
│ sweep_mode <U20 80B ...
│ sweep_number int64 8B ...
│ prt_mode <U7 28B ...
│ follow_mode <U7 28B ...
│ sweep_fixed_angle float64 8B ...
├── Group: /sweep_5
│ Dimensions: (azimuth: 361, range: 400)
│ Coordinates:
│ * azimuth (azimuth) float64 3kB 0.522 1.505 2.516 ... 358.5 359.5
│ elevation (azimuth) float64 3kB ...
│ time (azimuth) datetime64[ns] 3kB 2013-05-10T00:01:19.86363...
│ * range (range) float32 2kB 125.0 375.0 ... 9.962e+04 9.988e+04
│ Data variables:
│ DBZH (azimuth, range) float64 1MB ...
│ sweep_mode <U20 80B ...
│ sweep_number int64 8B ...
│ prt_mode <U7 28B ...
│ follow_mode <U7 28B ...
│ sweep_fixed_angle float64 8B ...
...
├── Group: /sweep_8
│ Dimensions: (azimuth: 361, range: 400)
│ Coordinates:
│ * azimuth (azimuth) float64 3kB 0.5 1.544 2.51 ... 358.5 359.5
│ elevation (azimuth) float64 3kB ...
│ time (azimuth) datetime64[ns] 3kB 2013-05-10T00:02:03.10606...
│ * range (range) float32 2kB 125.0 375.0 ... 9.962e+04 9.988e+04
│ Data variables:
│ DBZH (azimuth, range) float64 1MB ...
│ sweep_mode <U20 80B ...
│ sweep_number int64 8B ...
│ prt_mode <U7 28B ...
│ follow_mode <U7 28B ...
│ sweep_fixed_angle float64 8B ...
├── Group: /sweep_9
│ Dimensions: (azimuth: 361, range: 400)
│ Coordinates:
│ * azimuth (azimuth) float64 3kB 0.522 1.516 2.51 ... 358.5 359.5
│ elevation (azimuth) float64 3kB ...
│ time (azimuth) datetime64[ns] 3kB 2013-05-10T00:02:14.19696...
│ * range (range) float32 2kB 125.0 375.0 ... 9.962e+04 9.988e+04
│ Data variables:
│ DBZH (azimuth, range) float64 1MB ...
│ sweep_mode <U20 80B ...
│ sweep_number int64 8B ...
│ prt_mode <U7 28B ...
│ follow_mode <U7 28B ...
│ sweep_fixed_angle float64 8B ...
├── Group: /sweep_10
│ Dimensions: (azimuth: 361, range: 400)
│ Coordinates:
│ * azimuth (azimuth) float64 3kB 0.511 1.511 2.516 ... 358.5 359.5
│ elevation (azimuth) float64 3kB ...
│ time (azimuth) datetime64[ns] 3kB 2013-05-10T00:02:25.31818...
│ * range (range) float32 2kB 125.0 375.0 ... 9.962e+04 9.988e+04
│ Data variables:
│ DBZH (azimuth, range) float64 1MB ...
│ sweep_mode <U20 80B ...
│ sweep_number int64 8B ...
│ prt_mode <U7 28B ...
│ follow_mode <U7 28B ...
│ sweep_fixed_angle float64 8B ...
├── Group: /sweep_11
│ Dimensions: (azimuth: 361, range: 400)
│ Coordinates:
│ * azimuth (azimuth) float64 3kB 0.5 1.544 2.51 ... 358.5 359.5
│ elevation (azimuth) float64 3kB ...
│ time (azimuth) datetime64[ns] 3kB 2013-05-10T00:02:47.31818...
│ * range (range) float32 2kB 125.0 375.0 ... 9.962e+04 9.988e+04
│ Data variables:
│ DBZH (azimuth, range) float64 1MB ...
│ sweep_mode <U20 80B ...
│ sweep_number int64 8B ...
│ prt_mode <U7 28B ...
│ follow_mode <U7 28B ...
│ sweep_fixed_angle float64 8B ...
├── Group: /sweep_12
│ Dimensions: (azimuth: 361, range: 400)
│ Coordinates:
│ * azimuth (azimuth) float64 3kB 0.511 1.505 2.521 ... 358.5 359.5
│ elevation (azimuth) float64 3kB ...
│ time (azimuth) datetime64[ns] 3kB 2013-05-10T00:02:58.40909...
│ * range (range) float32 2kB 125.0 375.0 ... 9.962e+04 9.988e+04
│ Data variables:
│ DBZH (azimuth, range) float64 1MB ...
│ sweep_mode <U20 80B ...
│ sweep_number int64 8B ...
│ prt_mode <U7 28B ...
│ follow_mode <U7 28B ...
│ sweep_fixed_angle float64 8B ...
└── Group: /sweep_13
Dimensions: (azimuth: 361, range: 400)
Coordinates:
* azimuth (azimuth) float64 3kB 0.511 1.505 2.521 ... 358.5 359.5
elevation (azimuth) float64 3kB ...
time (azimuth) datetime64[ns] 3kB 2013-05-10T00:03:08.25757...
* range (range) float32 2kB 125.0 375.0 ... 9.962e+04 9.988e+04
Data variables:
DBZH (azimuth, range) float64 1MB ...
sweep_mode <U20 80B ...
sweep_number int64 8B ...
prt_mode <U7 28B ...
follow_mode <U7 28B ...
sweep_fixed_angle float64 8B ...Inspect root group#
The sweep dimension contains the number of scans in this radar volume. Further the dataset consists of variables (location coordinates, time_coverage) and attributes (Conventions, metadata).
vol.root
<xarray.DataTree>
Group: /
│ Dimensions: (sweep: 14)
│ Coordinates:
│ latitude float64 8B ...
│ longitude float64 8B ...
│ altitude float64 8B ...
│ Dimensions without coordinates: sweep
│ Data variables:
│ volume_number int64 8B 0
│ platform_type <U5 20B 'fixed'
│ instrument_type <U5 20B 'radar'
│ time_coverage_start <U20 80B '2013-05-10T00:00:06Z'
│ time_coverage_end <U20 80B '2013-05-10T00:03:14Z'
│ sweep_fixed_angle (sweep) float64 112B 0.6 1.4 2.4 3.5 ... 21.3 25.4 30.0
│ sweep_group_name (sweep) int64 112B 0 1 2 3 4 5 6 7 8 9 10 11 12 13
│ Attributes:
│ Conventions: None
│ instrument_name: None
│ version: None
│ title: None
│ institution: None
│ references: None
│ source: None
│ history: None
│ comment: im/exported using xradar
├── Group: /sweep_0
│ Dimensions: (azimuth: 361, range: 400)
│ Coordinates:
│ * azimuth (azimuth) float64 3kB 0.5055 1.549 2.505 ... 358.5 359.5
│ elevation (azimuth) float64 3kB ...
│ time (azimuth) datetime64[ns] 3kB 2013-05-10T00:00:15.50000...
│ * range (range) float32 2kB 125.0 375.0 ... 9.962e+04 9.988e+04
│ Data variables:
│ DBZH (azimuth, range) float64 1MB ...
│ sweep_mode <U20 80B ...
│ sweep_number int64 8B ...
│ prt_mode <U7 28B ...
│ follow_mode <U7 28B ...
│ sweep_fixed_angle float64 8B ...
├── Group: /sweep_1
│ Dimensions: (azimuth: 361, range: 400)
│ Coordinates:
│ * azimuth (azimuth) float64 3kB 0.5055 1.549 2.516 ... 358.5 359.5
│ elevation (azimuth) float64 3kB ...
│ time (azimuth) datetime64[ns] 3kB 2013-05-10T00:00:25.62121...
│ * range (range) float32 2kB 125.0 375.0 ... 9.962e+04 9.988e+04
│ Data variables:
│ DBZH (azimuth, range) float64 1MB ...
│ sweep_mode <U20 80B ...
│ sweep_number int64 8B ...
│ prt_mode <U7 28B ...
│ follow_mode <U7 28B ...
│ sweep_fixed_angle float64 8B ...
├── Group: /sweep_2
│ Dimensions: (azimuth: 361, range: 400)
│ Coordinates:
│ * azimuth (azimuth) float64 3kB 0.511 1.505 2.505 ... 358.5 359.5
│ elevation (azimuth) float64 3kB ...
│ time (azimuth) datetime64[ns] 3kB 2013-05-10T00:00:36.65151...
│ * range (range) float32 2kB 125.0 375.0 ... 9.962e+04 9.988e+04
│ Data variables:
│ DBZH (azimuth, range) float64 1MB ...
│ sweep_mode <U20 80B ...
│ sweep_number int64 8B ...
│ prt_mode <U7 28B ...
│ follow_mode <U7 28B ...
│ sweep_fixed_angle float64 8B ...
├── Group: /sweep_3
│ Dimensions: (azimuth: 361, range: 400)
│ Coordinates:
│ * azimuth (azimuth) float64 3kB 0.511 1.505 2.521 ... 358.5 359.5
│ elevation (azimuth) float64 3kB ...
│ time (azimuth) datetime64[ns] 3kB 2013-05-10T00:00:46.77272...
│ * range (range) float32 2kB 125.0 375.0 ... 9.962e+04 9.988e+04
│ Data variables:
│ DBZH (azimuth, range) float64 1MB ...
│ sweep_mode <U20 80B ...
│ sweep_number int64 8B ...
│ prt_mode <U7 28B ...
│ follow_mode <U7 28B ...
│ sweep_fixed_angle float64 8B ...
├── Group: /sweep_4
│ Dimensions: (azimuth: 361, range: 400)
│ Coordinates:
│ * azimuth (azimuth) float64 3kB 0.5 1.522 2.516 ... 358.5 359.5
│ elevation (azimuth) float64 3kB ...
│ time (azimuth) datetime64[ns] 3kB 2013-05-10T00:01:08.77272...
│ * range (range) float32 2kB 125.0 375.0 ... 9.962e+04 9.988e+04
│ Data variables:
│ DBZH (azimuth, range) float64 1MB ...
│ sweep_mode <U20 80B ...
│ sweep_number int64 8B ...
│ prt_mode <U7 28B ...
│ follow_mode <U7 28B ...
│ sweep_fixed_angle float64 8B ...
├── Group: /sweep_5
│ Dimensions: (azimuth: 361, range: 400)
│ Coordinates:
│ * azimuth (azimuth) float64 3kB 0.522 1.505 2.516 ... 358.5 359.5
│ elevation (azimuth) float64 3kB ...
│ time (azimuth) datetime64[ns] 3kB 2013-05-10T00:01:19.86363...
│ * range (range) float32 2kB 125.0 375.0 ... 9.962e+04 9.988e+04
│ Data variables:
│ DBZH (azimuth, range) float64 1MB ...
│ sweep_mode <U20 80B ...
│ sweep_number int64 8B ...
│ prt_mode <U7 28B ...
│ follow_mode <U7 28B ...
│ sweep_fixed_angle float64 8B ...
...
├── Group: /sweep_8
│ Dimensions: (azimuth: 361, range: 400)
│ Coordinates:
│ * azimuth (azimuth) float64 3kB 0.5 1.544 2.51 ... 358.5 359.5
│ elevation (azimuth) float64 3kB ...
│ time (azimuth) datetime64[ns] 3kB 2013-05-10T00:02:03.10606...
│ * range (range) float32 2kB 125.0 375.0 ... 9.962e+04 9.988e+04
│ Data variables:
│ DBZH (azimuth, range) float64 1MB ...
│ sweep_mode <U20 80B ...
│ sweep_number int64 8B ...
│ prt_mode <U7 28B ...
│ follow_mode <U7 28B ...
│ sweep_fixed_angle float64 8B ...
├── Group: /sweep_9
│ Dimensions: (azimuth: 361, range: 400)
│ Coordinates:
│ * azimuth (azimuth) float64 3kB 0.522 1.516 2.51 ... 358.5 359.5
│ elevation (azimuth) float64 3kB ...
│ time (azimuth) datetime64[ns] 3kB 2013-05-10T00:02:14.19696...
│ * range (range) float32 2kB 125.0 375.0 ... 9.962e+04 9.988e+04
│ Data variables:
│ DBZH (azimuth, range) float64 1MB ...
│ sweep_mode <U20 80B ...
│ sweep_number int64 8B ...
│ prt_mode <U7 28B ...
│ follow_mode <U7 28B ...
│ sweep_fixed_angle float64 8B ...
├── Group: /sweep_10
│ Dimensions: (azimuth: 361, range: 400)
│ Coordinates:
│ * azimuth (azimuth) float64 3kB 0.511 1.511 2.516 ... 358.5 359.5
│ elevation (azimuth) float64 3kB ...
│ time (azimuth) datetime64[ns] 3kB 2013-05-10T00:02:25.31818...
│ * range (range) float32 2kB 125.0 375.0 ... 9.962e+04 9.988e+04
│ Data variables:
│ DBZH (azimuth, range) float64 1MB ...
│ sweep_mode <U20 80B ...
│ sweep_number int64 8B ...
│ prt_mode <U7 28B ...
│ follow_mode <U7 28B ...
│ sweep_fixed_angle float64 8B ...
├── Group: /sweep_11
│ Dimensions: (azimuth: 361, range: 400)
│ Coordinates:
│ * azimuth (azimuth) float64 3kB 0.5 1.544 2.51 ... 358.5 359.5
│ elevation (azimuth) float64 3kB ...
│ time (azimuth) datetime64[ns] 3kB 2013-05-10T00:02:47.31818...
│ * range (range) float32 2kB 125.0 375.0 ... 9.962e+04 9.988e+04
│ Data variables:
│ DBZH (azimuth, range) float64 1MB ...
│ sweep_mode <U20 80B ...
│ sweep_number int64 8B ...
│ prt_mode <U7 28B ...
│ follow_mode <U7 28B ...
│ sweep_fixed_angle float64 8B ...
├── Group: /sweep_12
│ Dimensions: (azimuth: 361, range: 400)
│ Coordinates:
│ * azimuth (azimuth) float64 3kB 0.511 1.505 2.521 ... 358.5 359.5
│ elevation (azimuth) float64 3kB ...
│ time (azimuth) datetime64[ns] 3kB 2013-05-10T00:02:58.40909...
│ * range (range) float32 2kB 125.0 375.0 ... 9.962e+04 9.988e+04
│ Data variables:
│ DBZH (azimuth, range) float64 1MB ...
│ sweep_mode <U20 80B ...
│ sweep_number int64 8B ...
│ prt_mode <U7 28B ...
│ follow_mode <U7 28B ...
│ sweep_fixed_angle float64 8B ...
└── Group: /sweep_13
Dimensions: (azimuth: 361, range: 400)
Coordinates:
* azimuth (azimuth) float64 3kB 0.511 1.505 2.521 ... 358.5 359.5
elevation (azimuth) float64 3kB ...
time (azimuth) datetime64[ns] 3kB 2013-05-10T00:03:08.25757...
* range (range) float32 2kB 125.0 375.0 ... 9.962e+04 9.988e+04
Data variables:
DBZH (azimuth, range) float64 1MB ...
sweep_mode <U20 80B ...
sweep_number int64 8B ...
prt_mode <U7 28B ...
follow_mode <U7 28B ...
sweep_fixed_angle float64 8B ...Inspect sweep group(s)#
The sweep-groups can be accessed via their respective keys. The dimensions consist of range and time with added coordinates azimuth, elevation, range and time. There will be variables like radar moments (DBZH etc.) and sweep-dependent metadata (like fixed_angle, sweep_mode etc.).
display(vol["sweep_0"])
<xarray.DataTree 'sweep_0'>
Group: /sweep_0
Dimensions: (sweep: 14, azimuth: 361, range: 400)
Coordinates:
* azimuth (azimuth) float64 3kB 0.5055 1.549 2.505 ... 358.5 359.5
elevation (azimuth) float64 3kB ...
time (azimuth) datetime64[ns] 3kB 2013-05-10T00:00:15.50000...
* range (range) float32 2kB 125.0 375.0 ... 9.962e+04 9.988e+04
Dimensions without coordinates: sweep
Data variables:
DBZH (azimuth, range) float64 1MB ...
sweep_mode <U20 80B ...
sweep_number int64 8B ...
prt_mode <U7 28B ...
follow_mode <U7 28B ...
sweep_fixed_angle float64 8B ...Georeferencing#
swp = vol["sweep_0"].to_dataset(inherit="all_coords")
swp = swp.assign_coords(sweep_mode=swp.sweep_mode)
swp = swp.wrl.georef.georeference()
Inspect radar moments#
The DataArrays can be accessed by key or by attribute. Each DataArray has dimensions and coordinates of its parent dataset.
display(swp.DBZH)
<xarray.DataArray 'DBZH' (azimuth: 361, range: 400)> Size: 1MB
[144400 values with dtype=float64]
Coordinates: (12/15)
* azimuth (azimuth) float64 3kB 0.5055 1.549 2.505 ... 357.5 358.5 359.5
elevation (azimuth) float64 3kB 0.6 0.6 0.6 0.6 0.6 ... 0.6 0.6 0.6 0.6
time (azimuth) datetime64[ns] 3kB 2013-05-10T00:00:15.500000 ... 2...
* range (range) float32 2kB 125.0 375.0 625.0 ... 9.962e+04 9.988e+04
x (azimuth, range) float64 1MB 1.103 3.308 5.514 ... -859.2 -861.4
y (azimuth, range) float64 1MB 125.0 375.0 ... 9.96e+04 9.985e+04
... ...
bins (azimuth, range) float32 578kB 125.0 375.0 ... 9.988e+04
sweep_mode <U20 80B 'azimuth_surveillance'
latitude float64 8B 50.86
longitude float64 8B 6.38
altitude float64 8B 116.7
crs_wkt int64 8B 0
Attributes:
long_name: Equivalent reflectivity factor H
units: dBZ
standard_name: radar_equivalent_reflectivity_factor_hCreate simple plot#
Using xarray features a simple plot can be created like this. Note the sortby('time') method, which sorts the radials by time.
For more details on plotting radar data see under Visualization.
swp.DBZH.sortby("time").plot(x="range", y="time", add_labels=False)
<matplotlib.collections.QuadMesh at 0x7b237b661be0>
fig = plt.figure(figsize=(5, 5))
pm = swp.DBZH.wrl.vis.plot(crs={"latmin": 3e3}, fig=fig)
Retrieve explicit group#
swp_b = xr.open_dataset(
f, engine="rainbow", group="sweep_5", backend_kwargs=dict(reindex_angle=False)
)
display(swp_b)
<xarray.Dataset> Size: 1MB
Dimensions: (azimuth: 361, range: 400)
Coordinates:
* azimuth (azimuth) float64 3kB 0.522 1.505 2.516 ... 358.5 359.5
elevation (azimuth) float64 3kB ...
time (azimuth) datetime64[ns] 3kB ...
* range (range) float32 2kB 125.0 375.0 ... 9.962e+04 9.988e+04
longitude float64 8B ...
latitude float64 8B ...
altitude float64 8B ...
Data variables:
DBZH (azimuth, range) float64 1MB ...
sweep_mode <U20 80B ...
sweep_number int64 8B ...
prt_mode <U7 28B ...
follow_mode <U7 28B ...
sweep_fixed_angle float64 8B ...