CfRadial1#

import xarray as xr
from open_radar_data import DATASETS

import xradar as xd

Download#

Fetching CfRadial1 radar data file from open-radar-data repository.

filename = DATASETS.fetch("cfrad.20080604_002217_000_SPOL_v36_SUR.nc")

xr.open_dataset#

Making use of the xarray cfradial1 backend. We also need to provide the group.

ds = xr.open_dataset(filename, group="sweep_0", engine="cfradial1")
display(ds)
<xarray.Dataset> Size: 4MB
Dimensions:                    (azimuth: 483, range: 996)
Coordinates:
  * azimuth                    (azimuth) float32 2kB 0.0 0.75 ... 358.5 359.2
    elevation                  (azimuth) float32 2kB ...
    time                       (azimuth) datetime64[ns] 4kB ...
  * range                      (range) float32 4kB 150.0 300.0 ... 1.494e+05
    latitude                   float64 8B ...
    longitude                  float64 8B ...
    altitude                   float64 8B ...
Data variables: (12/18)
    sweep_number               int32 4B ...
    sweep_mode                 <U20 80B ...
    prt_mode                   |S32 32B ...
    follow_mode                |S32 32B ...
    sweep_fixed_angle          float32 4B ...
    pulse_width                (azimuth) float32 2kB ...
    ...                         ...
    r_calib_index              (azimuth) int8 483B ...
    measured_transmit_power_h  (azimuth) float32 2kB ...
    measured_transmit_power_v  (azimuth) float32 2kB ...
    scan_rate                  (azimuth) float32 2kB ...
    DBZ                        (azimuth, range) float32 2MB ...
    VR                         (azimuth, range) float32 2MB ...

Plot Time vs. Azimuth#

We need to sort by time and specify the coordinate.

ds.azimuth.plot(y="time")
[<matplotlib.lines.Line2D at 0x7139422aa0d0>]
../_images/408a9f2d84cbc2f235b94168affb6eb6b85a18e75d2d825ed071590ed43f48c9.png

Plot Range vs. Time#

We need to sort by time and specify the coordinate.

ds.DBZ.sortby("time").plot(y="time")
<matplotlib.collections.QuadMesh at 0x713942149d30>
../_images/68957b6cdcb2da3b9eb9c11505d714df3eedb63a0ea093d3d7c65b6794e36378.png

Plot Range vs. Azimuth#

ds.DBZ.plot()
<matplotlib.collections.QuadMesh at 0x713939ff3d90>
../_images/9ebdef37595a74f23d7d0f50959fca20bbe7ba61fdfe9b9b3a03945d91f06c5b.png

backend_kwargs#

The cfradial1 backend can be parameterized via kwargs. Please observe the possibilities below.

?xd.io.CfRadial1BackendEntrypoint
ds = xr.open_dataset(filename, group="sweep_0", engine="cfradial1", first_dim="time")
display(ds)
<xarray.Dataset> Size: 4MB
Dimensions:                    (time: 483, range: 996)
Coordinates:
  * time                       (time) datetime64[ns] 4kB 2008-06-04T00:15:03 ...
    azimuth                    (time) float32 2kB ...
    elevation                  (time) float32 2kB ...
  * range                      (range) float32 4kB 150.0 300.0 ... 1.494e+05
    latitude                   float64 8B ...
    longitude                  float64 8B ...
    altitude                   float64 8B ...
Data variables: (12/18)
    sweep_number               int32 4B ...
    sweep_mode                 <U20 80B ...
    prt_mode                   |S32 32B ...
    follow_mode                |S32 32B ...
    sweep_fixed_angle          float32 4B ...
    pulse_width                (time) float32 2kB ...
    ...                         ...
    r_calib_index              (time) int8 483B ...
    measured_transmit_power_h  (time) float32 2kB ...
    measured_transmit_power_v  (time) float32 2kB ...
    scan_rate                  (time) float32 2kB ...
    DBZ                        (time, range) float32 2MB ...
    VR                         (time, range) float32 2MB ...
ds = xr.open_dataset(
    filename, group="sweep_1", engine="cfradial1", backend_kwargs=dict(first_dim="time")
)
display(ds)
<xarray.Dataset> Size: 4MB
Dimensions:                    (time: 483, range: 996)
Coordinates:
  * time                       (time) datetime64[ns] 4kB 2008-06-04T00:15:50 ...
    azimuth                    (time) float32 2kB ...
    elevation                  (time) float32 2kB ...
  * range                      (range) float32 4kB 150.0 300.0 ... 1.494e+05
    latitude                   float64 8B ...
    longitude                  float64 8B ...
    altitude                   float64 8B ...
Data variables: (12/18)
    sweep_number               int32 4B ...
    sweep_mode                 <U20 80B ...
    prt_mode                   |S32 32B ...
    follow_mode                |S32 32B ...
    sweep_fixed_angle          float32 4B ...
    pulse_width                (time) float32 2kB ...
    ...                         ...
    r_calib_index              (time) int8 483B ...
    measured_transmit_power_h  (time) float32 2kB ...
    measured_transmit_power_v  (time) float32 2kB ...
    scan_rate                  (time) float32 2kB ...
    DBZ                        (time, range) float32 2MB ...
    VR                         (time, range) float32 2MB ...

open_cfradial1_datatree#

The same works analoguous with the datatree loader. But additionally we can provide a sweep number or list.

?xd.open_datatree
dtree = xd.open_datatree(filename, engine="cfradial1",
    first_dim="time",
    optional=False,
)
display(dtree)
<xarray.DataTree>
Group: /
│   Dimensions:              (sweep: 9)
│   Coordinates:
│       latitude             float64 8B ...
│       longitude            float64 8B ...
│       altitude             float64 8B ...
│   Dimensions without coordinates: sweep
│   Data variables:
│       volume_number        int32 4B ...
│       time_coverage_start  |S32 32B ...
│       time_coverage_end    |S32 32B ...
│       sweep_group_name     (sweep) <U7 252B ...
│       sweep_fixed_angle    (sweep) float32 36B ...
│   Attributes:
│       Conventions:         CF/Radial instrument_parameters radar_parameters rad...
│       version:             1.2
│       title:               TIMREX
│       institution:         
│       references:          
│       source:              
│       history:             
│       comment:             
│       instrument_name:     SPOLRVP8
│       platform_is_mobile:  false
├── Group: /sweep_0
│       Dimensions:            (time: 483, range: 996)
│       Coordinates:
│         * time               (time) datetime64[ns] 4kB 2008-06-04T00:15:03 ... 2008...
│           azimuth            (time) float32 2kB ...
│           elevation          (time) float32 2kB ...
│         * range              (range) float32 4kB 150.0 300.0 ... 1.492e+05 1.494e+05
│       Data variables:
│           sweep_number       int32 4B ...
│           sweep_mode         <U20 80B ...
│           prt_mode           |S32 32B ...
│           follow_mode        |S32 32B ...
│           sweep_fixed_angle  float32 4B ...
│           DBZ                (time, range) float32 2MB ...
│           VR                 (time, range) float32 2MB ...
├── Group: /sweep_1
│       Dimensions:            (time: 483, range: 996)
│       Coordinates:
│         * time               (time) datetime64[ns] 4kB 2008-06-04T00:15:50 ... 2008...
│           azimuth            (time) float32 2kB ...
│           elevation          (time) float32 2kB ...
│         * range              (range) float32 4kB 150.0 300.0 ... 1.492e+05 1.494e+05
│       Data variables:
│           sweep_number       int32 4B ...
│           sweep_mode         <U20 80B ...
│           prt_mode           |S32 32B ...
│           follow_mode        |S32 32B ...
│           sweep_fixed_angle  float32 4B ...
│           DBZ                (time, range) float32 2MB ...
│           VR                 (time, range) float32 2MB ...
├── Group: /sweep_2
│       Dimensions:            (time: 482, range: 996)
│       Coordinates:
│         * time               (time) datetime64[ns] 4kB 2008-06-04T00:16:40 ... 2008...
│           azimuth            (time) float32 2kB ...
│           elevation          (time) float32 2kB ...
│         * range              (range) float32 4kB 150.0 300.0 ... 1.492e+05 1.494e+05
│       Data variables:
│           sweep_number       int32 4B ...
│           sweep_mode         <U20 80B ...
│           prt_mode           |S32 32B ...
│           follow_mode        |S32 32B ...
│           sweep_fixed_angle  float32 4B ...
│           DBZ                (time, range) float32 2MB ...
│           VR                 (time, range) float32 2MB ...
├── Group: /sweep_3
│       Dimensions:            (time: 483, range: 996)
│       Coordinates:
│         * time               (time) datetime64[ns] 4kB 2008-06-04T00:17:27 ... 2008...
│           azimuth            (time) float32 2kB ...
│           elevation          (time) float32 2kB ...
│         * range              (range) float32 4kB 150.0 300.0 ... 1.492e+05 1.494e+05
│       Data variables:
│           sweep_number       int32 4B ...
│           sweep_mode         <U20 80B ...
│           prt_mode           |S32 32B ...
│           follow_mode        |S32 32B ...
│           sweep_fixed_angle  float32 4B ...
│           DBZ                (time, range) float32 2MB ...
│           VR                 (time, range) float32 2MB ...
├── Group: /sweep_4
│       Dimensions:            (time: 481, range: 996)
│       Coordinates:
│         * time               (time) datetime64[ns] 4kB 2008-06-04T00:18:15 ... 2008...
│           azimuth            (time) float32 2kB ...
│           elevation          (time) float32 2kB ...
│         * range              (range) float32 4kB 150.0 300.0 ... 1.492e+05 1.494e+05
│       Data variables:
│           sweep_number       int32 4B ...
│           sweep_mode         <U20 80B ...
│           prt_mode           |S32 32B ...
│           follow_mode        |S32 32B ...
│           sweep_fixed_angle  float32 4B ...
│           DBZ                (time, range) float32 2MB ...
│           VR                 (time, range) float32 2MB ...
├── Group: /sweep_5
│       Dimensions:            (time: 482, range: 996)
│       Coordinates:
│         * time               (time) datetime64[ns] 4kB 2008-06-04T00:19:03 ... 2008...
│           azimuth            (time) float32 2kB ...
│           elevation          (time) float32 2kB ...
│         * range              (range) float32 4kB 150.0 300.0 ... 1.492e+05 1.494e+05
│       Data variables:
│           sweep_number       int32 4B ...
│           sweep_mode         <U20 80B ...
│           prt_mode           |S32 32B ...
│           follow_mode        |S32 32B ...
│           sweep_fixed_angle  float32 4B ...
│           DBZ                (time, range) float32 2MB ...
│           VR                 (time, range) float32 2MB ...
├── Group: /sweep_6
│       Dimensions:            (time: 482, range: 996)
│       Coordinates:
│         * time               (time) datetime64[ns] 4kB 2008-06-04T00:19:51 ... 2008...
│           azimuth            (time) float32 2kB ...
│           elevation          (time) float32 2kB ...
│         * range              (range) float32 4kB 150.0 300.0 ... 1.492e+05 1.494e+05
│       Data variables:
│           sweep_number       int32 4B ...
│           sweep_mode         <U20 80B ...
│           prt_mode           |S32 32B ...
│           follow_mode        |S32 32B ...
│           sweep_fixed_angle  float32 4B ...
│           DBZ                (time, range) float32 2MB ...
│           VR                 (time, range) float32 2MB ...
├── Group: /sweep_7
│       Dimensions:            (time: 484, range: 996)
│       Coordinates:
│         * time               (time) datetime64[ns] 4kB 2008-06-04T00:20:39 ... 2008...
│           azimuth            (time) float32 2kB ...
│           elevation          (time) float32 2kB ...
│         * range              (range) float32 4kB 150.0 300.0 ... 1.492e+05 1.494e+05
│       Data variables:
│           sweep_number       int32 4B ...
│           sweep_mode         <U20 80B ...
│           prt_mode           |S32 32B ...
│           follow_mode        |S32 32B ...
│           sweep_fixed_angle  float32 4B ...
│           DBZ                (time, range) float32 2MB ...
│           VR                 (time, range) float32 2MB ...
└── Group: /sweep_8
        Dimensions:            (time: 483, range: 996)
        Coordinates:
          * time               (time) datetime64[ns] 4kB 2008-06-04T00:21:28 ... 2008...
            azimuth            (time) float32 2kB ...
            elevation          (time) float32 2kB ...
          * range              (range) float32 4kB 150.0 300.0 ... 1.492e+05 1.494e+05
        Data variables:
            sweep_number       int32 4B ...
            sweep_mode         <U20 80B ...
            prt_mode           |S32 32B ...
            follow_mode        |S32 32B ...
            sweep_fixed_angle  float32 4B ...
            DBZ                (time, range) float32 2MB ...
            VR                 (time, range) float32 2MB ...

Plot Sweep Range vs. Time#

dtree["sweep_0"].ds.DBZ.plot()
<matplotlib.collections.QuadMesh at 0x713938703b10>
../_images/18efc5fef814c68be660108a4e269c1183010ded9f4c13a508d534668945adab.png

Plot Sweep Range vs. Azimuth#

dtree["sweep_0"].ds.DBZ.sortby("azimuth").plot(y="azimuth")
<matplotlib.collections.QuadMesh at 0x7139384a96d0>
../_images/6350135f3e3ca18170ea87a7e50015f5226e2707e765a355a29239ad68fe2eee.png
dtree = xd.open_datatree(filename, engine="cfradial1", sweep=[0, 1, 8])
display(dtree)
<xarray.DataTree>
Group: /
│   Dimensions:              (sweep: 9)
│   Coordinates:
│       latitude             float64 8B ...
│       longitude            float64 8B ...
│       altitude             float64 8B ...
│   Dimensions without coordinates: sweep
│   Data variables:
│       volume_number        int32 4B ...
│       platform_type        |S32 32B ...
│       primary_axis         |S32 32B ...
│       status_str           |S1 1B ...
│       instrument_type      |S32 32B ...
│       time_coverage_start  |S32 32B ...
│       time_coverage_end    |S32 32B ...
│       sweep_group_name     (sweep) <U7 252B ...
│       sweep_fixed_angle    (sweep) float32 36B ...
│   Attributes: (12/13)
│       Conventions:         CF/Radial instrument_parameters radar_parameters rad...
│       version:             1.2
│       title:               TIMREX
│       institution:         
│       references:          
│       source:              
│       ...                  ...
│       comment:             
│       instrument_name:     SPOLRVP8
│       site_name:           
│       scan_name:           
│       scan_id:             0
│       platform_is_mobile:  false
├── Group: /sweep_0
│       Dimensions:                    (azimuth: 483, range: 996)
│       Coordinates:
│         * azimuth                    (azimuth) float32 2kB 0.0 0.75 ... 358.5 359.2
│           elevation                  (azimuth) float32 2kB ...
│           time                       (azimuth) datetime64[ns] 4kB ...
│         * range                      (range) float32 4kB 150.0 300.0 ... 1.494e+05
│       Data variables: (12/18)
│           sweep_number               int32 4B ...
│           sweep_mode                 <U20 80B ...
│           prt_mode                   |S32 32B ...
│           follow_mode                |S32 32B ...
│           sweep_fixed_angle          float32 4B ...
│           pulse_width                (azimuth) float32 2kB ...
│           ...                         ...
│           r_calib_index              (azimuth) int8 483B ...
│           measured_transmit_power_h  (azimuth) float32 2kB ...
│           measured_transmit_power_v  (azimuth) float32 2kB ...
│           scan_rate                  (azimuth) float32 2kB ...
│           DBZ                        (azimuth, range) float32 2MB ...
│           VR                         (azimuth, range) float32 2MB ...
├── Group: /sweep_1
│       Dimensions:                    (azimuth: 483, range: 996)
│       Coordinates:
│         * azimuth                    (azimuth) float32 2kB 0.0 0.75 ... 358.5 359.2
│           elevation                  (azimuth) float32 2kB ...
│           time                       (azimuth) datetime64[ns] 4kB ...
│         * range                      (range) float32 4kB 150.0 300.0 ... 1.494e+05
│       Data variables: (12/18)
│           sweep_number               int32 4B ...
│           sweep_mode                 <U20 80B ...
│           prt_mode                   |S32 32B ...
│           follow_mode                |S32 32B ...
│           sweep_fixed_angle          float32 4B ...
│           pulse_width                (azimuth) float32 2kB ...
│           ...                         ...
│           r_calib_index              (azimuth) int8 483B ...
│           measured_transmit_power_h  (azimuth) float32 2kB ...
│           measured_transmit_power_v  (azimuth) float32 2kB ...
│           scan_rate                  (azimuth) float32 2kB ...
│           DBZ                        (azimuth, range) float32 2MB ...
│           VR                         (azimuth, range) float32 2MB ...
└── Group: /sweep_2
        Dimensions:                    (azimuth: 483, range: 996)
        Coordinates:
          * azimuth                    (azimuth) float32 2kB 0.0 0.75 ... 358.5 359.2
            elevation                  (azimuth) float32 2kB ...
            time                       (azimuth) datetime64[ns] 4kB ...
          * range                      (range) float32 4kB 150.0 300.0 ... 1.494e+05
        Data variables: (12/18)
            sweep_number               int32 4B ...
            sweep_mode                 <U20 80B ...
            prt_mode                   |S32 32B ...
            follow_mode                |S32 32B ...
            sweep_fixed_angle          float32 4B ...
            pulse_width                (azimuth) float32 2kB ...
            ...                         ...
            r_calib_index              (azimuth) int8 483B ...
            measured_transmit_power_h  (azimuth) float32 2kB ...
            measured_transmit_power_v  (azimuth) float32 2kB ...
            scan_rate                  (azimuth) float32 2kB ...
            DBZ                        (azimuth, range) float32 2MB ...
            VR                         (azimuth, range) float32 2MB ...
dtree = xd.open_datatree(filename, engine="cfradial1", sweep=["sweep_0", "sweep_4", "sweep_8"])
display(dtree)
<xarray.DataTree>
Group: /
│   Dimensions:              (sweep: 9)
│   Coordinates:
│       latitude             float64 8B ...
│       longitude            float64 8B ...
│       altitude             float64 8B ...
│   Dimensions without coordinates: sweep
│   Data variables:
│       volume_number        int32 4B ...
│       platform_type        |S32 32B ...
│       primary_axis         |S32 32B ...
│       status_str           |S1 1B ...
│       instrument_type      |S32 32B ...
│       time_coverage_start  |S32 32B ...
│       time_coverage_end    |S32 32B ...
│       sweep_group_name     (sweep) <U7 252B ...
│       sweep_fixed_angle    (sweep) float32 36B ...
│   Attributes: (12/13)
│       Conventions:         CF/Radial instrument_parameters radar_parameters rad...
│       version:             1.2
│       title:               TIMREX
│       institution:         
│       references:          
│       source:              
│       ...                  ...
│       comment:             
│       instrument_name:     SPOLRVP8
│       site_name:           
│       scan_name:           
│       scan_id:             0
│       platform_is_mobile:  false
├── Group: /sweep_0
│       Dimensions:                    (azimuth: 483, range: 996)
│       Coordinates:
│         * azimuth                    (azimuth) float32 2kB 0.0 0.75 ... 358.5 359.2
│           elevation                  (azimuth) float32 2kB ...
│           time                       (azimuth) datetime64[ns] 4kB ...
│         * range                      (range) float32 4kB 150.0 300.0 ... 1.494e+05
│       Data variables: (12/18)
│           sweep_number               int32 4B ...
│           sweep_mode                 <U20 80B ...
│           prt_mode                   |S32 32B ...
│           follow_mode                |S32 32B ...
│           sweep_fixed_angle          float32 4B ...
│           pulse_width                (azimuth) float32 2kB ...
│           ...                         ...
│           r_calib_index              (azimuth) int8 483B ...
│           measured_transmit_power_h  (azimuth) float32 2kB ...
│           measured_transmit_power_v  (azimuth) float32 2kB ...
│           scan_rate                  (azimuth) float32 2kB ...
│           DBZ                        (azimuth, range) float32 2MB ...
│           VR                         (azimuth, range) float32 2MB ...
├── Group: /sweep_1
│       Dimensions:                    (azimuth: 481, range: 996)
│       Coordinates:
│         * azimuth                    (azimuth) float32 2kB 0.0 0.75 ... 358.5 359.2
│           elevation                  (azimuth) float32 2kB ...
│           time                       (azimuth) datetime64[ns] 4kB ...
│         * range                      (range) float32 4kB 150.0 300.0 ... 1.494e+05
│       Data variables: (12/18)
│           sweep_number               int32 4B ...
│           sweep_mode                 <U20 80B ...
│           prt_mode                   |S32 32B ...
│           follow_mode                |S32 32B ...
│           sweep_fixed_angle          float32 4B ...
│           pulse_width                (azimuth) float32 2kB ...
│           ...                         ...
│           r_calib_index              (azimuth) int8 481B ...
│           measured_transmit_power_h  (azimuth) float32 2kB ...
│           measured_transmit_power_v  (azimuth) float32 2kB ...
│           scan_rate                  (azimuth) float32 2kB ...
│           DBZ                        (azimuth, range) float32 2MB ...
│           VR                         (azimuth, range) float32 2MB ...
└── Group: /sweep_2
        Dimensions:                    (azimuth: 483, range: 996)
        Coordinates:
          * azimuth                    (azimuth) float32 2kB 0.0 0.75 ... 358.5 359.2
            elevation                  (azimuth) float32 2kB ...
            time                       (azimuth) datetime64[ns] 4kB ...
          * range                      (range) float32 4kB 150.0 300.0 ... 1.494e+05
        Data variables: (12/18)
            sweep_number               int32 4B ...
            sweep_mode                 <U20 80B ...
            prt_mode                   |S32 32B ...
            follow_mode                |S32 32B ...
            sweep_fixed_angle          float32 4B ...
            pulse_width                (azimuth) float32 2kB ...
            ...                         ...
            r_calib_index              (azimuth) int8 483B ...
            measured_transmit_power_h  (azimuth) float32 2kB ...
            measured_transmit_power_v  (azimuth) float32 2kB ...
            scan_rate                  (azimuth) float32 2kB ...
            DBZ                        (azimuth, range) float32 2MB ...
            VR                         (azimuth, range) float32 2MB ...