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 0x7c46421c5810>]
../_images/0a22054e982133725aabe15356a8e08e36a7e47672d3c4d9f91f73ba0e540403.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 0x7c4642225160>
../_images/51e48a5d39aee768e4821f972304b2c8b45d276ebbfae50d52d5d517a8ef54e0.png

Plot Range vs. Azimuth#

ds.DBZ.plot()
<matplotlib.collections.QuadMesh at 0x7c46390bf610>
../_images/eec984a9e477ddcc367b0609268c4c2a301f4b3a33297119751a8f61ff9f6719.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.io.open_cfradial1_datatree
dtree = xd.io.open_cfradial1_datatree(
    filename,
    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_0' 'sweep_1' ... 'sweep_8'
│       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 'azimuth_surveillance'
│           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 'azimuth_surveillance'
│           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 'azimuth_surveillance'
│           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 'azimuth_surveillance'
│           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 'azimuth_surveillance'
│           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 'azimuth_surveillance'
│           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 'azimuth_surveillance'
│           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 'azimuth_surveillance'
│           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 'azimuth_surveillance'
            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 0x7c46336196d0>
../_images/b404fcb2cfa76a10bec99d88959b55eaccf02327ac0555f8ef20dfd4c5f51152.png

Plot Sweep Range vs. Azimuth#

dtree["sweep_0"].ds.DBZ.sortby("azimuth").plot(y="azimuth")
<matplotlib.collections.QuadMesh at 0x7c46336c7250>
../_images/4664b5becde5c80f64c6a986c0632b620a8ebefb15fc07d1c0e36a28ff2be761.png
dtree = xd.io.open_cfradial1_datatree(filename, 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_0' 'sweep_1' ... 'sweep_8'
│       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 2008-06-04T00:15:...
│         * range                      (range) float32 4kB 150.0 300.0 ... 1.494e+05
│       Data variables: (12/18)
│           sweep_number               int32 4B ...
│           sweep_mode                 <U20 80B 'azimuth_surveillance'
│           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 2008-06-04T00:16:...
│         * range                      (range) float32 4kB 150.0 300.0 ... 1.494e+05
│       Data variables: (12/18)
│           sweep_number               int32 4B ...
│           sweep_mode                 <U20 80B 'azimuth_surveillance'
│           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 2008-06-04T00:21:...
          * range                      (range) float32 4kB 150.0 300.0 ... 1.494e+05
        Data variables: (12/18)
            sweep_number               int32 4B ...
            sweep_mode                 <U20 80B 'azimuth_surveillance'
            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.io.open_cfradial1_datatree(filename, 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_0' 'sweep_1' ... 'sweep_8'
│       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 2008-06-04T00:15:...
│         * range                      (range) float32 4kB 150.0 300.0 ... 1.494e+05
│       Data variables: (12/18)
│           sweep_number               int32 4B ...
│           sweep_mode                 <U20 80B 'azimuth_surveillance'
│           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 2008-06-04T00:18:...
│         * range                      (range) float32 4kB 150.0 300.0 ... 1.494e+05
│       Data variables: (12/18)
│           sweep_number               int32 4B ...
│           sweep_mode                 <U20 80B 'azimuth_surveillance'
│           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 2008-06-04T00:21:...
          * range                      (range) float32 4kB 150.0 300.0 ... 1.494e+05
        Data variables: (12/18)
            sweep_number               int32 4B ...
            sweep_mode                 <U20 80B 'azimuth_surveillance'
            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 ...