xarray IRIS backend#

In this example, we read IRIS (sigmet) data files using the xradar iris 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 IRIS Volume Data#

fpath = "sigmet/SUR210819000227.RAWKPJV"
f = wradlib_data.DATASETS.fetch(fpath)
vol = xd.io.open_iris_datatree(f, reindex_angle=False)
Downloading file 'sigmet/SUR210819000227.RAWKPJV' from 'https://github.com/wradlib/wradlib-data/raw/main/data/sigmet/SUR210819000227.RAWKPJV' to '/home/docs/.cache/wradlib-data'.

Inspect RadarVolume#

display(vol)
<xarray.DataTree>
Group: /
β”‚   Dimensions:              (sweep: 1)
β”‚   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 '2021-08-19T00:02:28Z'
β”‚       time_coverage_end    <U20 80B '2021-08-19T00:02:49Z'
β”‚       sweep_fixed_angle    (sweep) float64 8B 0.5
β”‚       sweep_group_name     (sweep) int64 8B 0
β”‚   Attributes:
β”‚       Conventions:      None
β”‚       instrument_name:  Surgavere, Radar
β”‚       version:          None
β”‚       title:            None
β”‚       institution:      None
β”‚       references:       None
β”‚       source:           Sigmet
β”‚       history:          None
β”‚       comment:          Dual pol 250km hybrid surveillance task 0.5 deg 2.5minu...
β”‚       scan_name:        PPI1_H      
└── Group: /sweep_0
        Dimensions:            (azimuth: 359, range: 833)
        Coordinates:
          * azimuth            (azimuth) float32 1kB 0.03021 1.035 2.054 ... 358.0 359.0
            elevation          (azimuth) float32 1kB ...
            time               (azimuth) datetime64[ns] 3kB 2021-08-19T00:02:31.10400...
          * range              (range) float32 3kB 150.0 450.0 ... 2.494e+05 2.498e+05
        Data variables: (12/16)
            DBTH               (azimuth, range) float32 1MB ...
            DBZH               (azimuth, range) float32 1MB ...
            VRADH              (azimuth, range) float32 1MB ...
            WRADH              (azimuth, range) float32 1MB ...
            ZDR                (azimuth, range) float32 1MB ...
            KDP                (azimuth, range) float32 1MB ...
            ...                 ...
            SNRH               (azimuth, range) float32 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: 1)
β”‚   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 '2021-08-19T00:02:28Z'
β”‚       time_coverage_end    <U20 80B '2021-08-19T00:02:49Z'
β”‚       sweep_fixed_angle    (sweep) float64 8B 0.5
β”‚       sweep_group_name     (sweep) int64 8B 0
β”‚   Attributes:
β”‚       Conventions:      None
β”‚       instrument_name:  Surgavere, Radar
β”‚       version:          None
β”‚       title:            None
β”‚       institution:      None
β”‚       references:       None
β”‚       source:           Sigmet
β”‚       history:          None
β”‚       comment:          Dual pol 250km hybrid surveillance task 0.5 deg 2.5minu...
β”‚       scan_name:        PPI1_H      
└── Group: /sweep_0
        Dimensions:            (azimuth: 359, range: 833)
        Coordinates:
          * azimuth            (azimuth) float32 1kB 0.03021 1.035 2.054 ... 358.0 359.0
            elevation          (azimuth) float32 1kB ...
            time               (azimuth) datetime64[ns] 3kB 2021-08-19T00:02:31.10400...
          * range              (range) float32 3kB 150.0 450.0 ... 2.494e+05 2.498e+05
        Data variables: (12/16)
            DBTH               (azimuth, range) float32 1MB ...
            DBZH               (azimuth, range) float32 1MB ...
            VRADH              (azimuth, range) float32 1MB ...
            WRADH              (azimuth, range) float32 1MB ...
            ZDR                (azimuth, range) float32 1MB ...
            KDP                (azimuth, range) float32 1MB ...
            ...                 ...
            SNRH               (azimuth, range) float32 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: 1, azimuth: 359, range: 833)
    Coordinates:
      * azimuth            (azimuth) float32 1kB 0.03021 1.035 2.054 ... 358.0 359.0
        elevation          (azimuth) float32 1kB ...
        time               (azimuth) datetime64[ns] 3kB 2021-08-19T00:02:31.10400...
      * range              (range) float32 3kB 150.0 450.0 ... 2.494e+05 2.498e+05
    Dimensions without coordinates: sweep
    Data variables: (12/16)
        DBTH               (azimuth, range) float32 1MB ...
        DBZH               (azimuth, range) float32 1MB ...
        VRADH              (azimuth, range) float32 1MB ...
        WRADH              (azimuth, range) float32 1MB ...
        ZDR                (azimuth, range) float32 1MB ...
        KDP                (azimuth, range) float32 1MB ...
        ...                 ...
        SNRH               (azimuth, range) float32 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 it’s parent dataset.

display(swp.DBZH)
<xarray.DataArray 'DBZH' (azimuth: 359, range: 833)> Size: 1MB
[299047 values with dtype=float32]
Coordinates: (12/15)
  * azimuth     (azimuth) float32 1kB 0.03021 1.035 2.054 ... 357.0 358.0 359.0
    elevation   (azimuth) float64 3kB 0.5054 0.5054 0.5054 ... 0.5054 0.5054
    time        (azimuth) datetime64[ns] 3kB 2021-08-19T00:02:31.104000 ... 2...
  * range       (range) float32 3kB 150.0 450.0 750.0 ... 2.494e+05 2.498e+05
    x           (azimuth, range) float64 2MB 0.0791 0.2373 ... -4.211e+03
    y           (azimuth, range) float64 2MB 150.0 450.0 ... 2.493e+05 2.496e+05
    ...          ...
    bins        (azimuth, range) float32 1MB 150.0 450.0 ... 2.494e+05 2.498e+05
    sweep_mode  <U20 80B 'azimuth_surveillance'
    latitude    float64 8B 58.48
    longitude   float64 8B 25.52
    altitude    float64 8B 157.0
    crs_wkt     int64 8B 0
Attributes:
    standard_name:  radar_equivalent_reflectivity_factor_h
    long_name:      Equivalent reflectivity factor H
    units:          dBZ

Create 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 0x73bdf72a5550>
../../../_images/d533141c7f5c1e4568dfc32ba0f24d5b60765114c2dd8201593ac130803ce021.png
fig = plt.figure(figsize=(5, 5))
pm = swp.DBZH.wrl.vis.plot(crs={"latmin": 3e3}, fig=fig)
../../../_images/654665ee5e3a249ae8cbdd08401e1ac082b357fd56f62d162e93fb348cbe5590.png

Retrieve explicit group#

swp_b = xr.open_dataset(
    f, engine="iris", group="sweep_0", backend_kwargs=dict(reindex_angle=False)
)
display(swp_b)
<xarray.Dataset> Size: 13MB
Dimensions:            (azimuth: 359, range: 833)
Coordinates:
  * azimuth            (azimuth) float32 1kB 0.03021 1.035 2.054 ... 358.0 359.0
    elevation          (azimuth) float32 1kB ...
    time               (azimuth) datetime64[ns] 3kB ...
  * range              (range) float32 3kB 150.0 450.0 ... 2.494e+05 2.498e+05
    longitude          float64 8B ...
    latitude           float64 8B ...
    altitude           float64 8B ...
Data variables: (12/16)
    DBTH               (azimuth, range) float32 1MB ...
    DBZH               (azimuth, range) float32 1MB ...
    VRADH              (azimuth, range) float32 1MB ...
    WRADH              (azimuth, range) float32 1MB ...
    ZDR                (azimuth, range) float32 1MB ...
    KDP                (azimuth, range) float32 1MB ...
    ...                 ...
    SNRH               (azimuth, range) float32 1MB ...
    sweep_mode         <U20 80B ...
    sweep_number       int64 8B ...
    prt_mode           <U7 28B ...
    follow_mode        <U7 28B ...
    sweep_fixed_angle  float64 8B ...
Attributes:
    source:           Sigmet
    scan_name:        PPI1_H      
    instrument_name:  Surgavere, Radar
    comment:          Dual pol 250km hybrid surveillance task 0.5 deg 2.5minu...