CfRadial1 <-> CfRadial2#

Imports#

[1]:
import xarray as xr
from open_radar_data import DATASETS

import xradar as xd

Load Data#

[2]:
file = DATASETS.fetch("cfrad.20080604_002217_000_SPOL_v36_SUR.nc")
dtree = xd.io.open_cfradial1_datatree(file)
display(dtree)
/home/docs/checkouts/readthedocs.org/user_builds/xradar/conda/latest/lib/python3.12/site-packages/xradar/io/backends/cfradial1.py:349: FutureWarning: In a future version of xarray decode_timedelta will default to False rather than None. To silence this warning, set decode_timedelta to True, False, or a 'CFTimedeltaCoder' instance.
  ds = open_dataset(filename_or_obj, engine=engine, **kwargs)
/home/docs/checkouts/readthedocs.org/user_builds/xradar/conda/latest/lib/python3.12/site-packages/xradar/io/backends/cfradial1.py:349: FutureWarning: In a future version of xarray decode_timedelta will default to False rather than None. To silence this warning, set decode_timedelta to True, False, or a 'CFTimedeltaCoder' instance.
  ds = open_dataset(filename_or_obj, engine=engine, **kwargs)
<xarray.DatasetView> Size: 477B
Dimensions:              (sweep: 9)
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 ...
    latitude             float64 8B ...
    longitude            float64 8B ...
    altitude             float64 8B ...
    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

Transform CF2 to CF1#

[3]:
ds = dtree.xradar.to_cfradial1_dataset()
display(ds)
<xarray.Dataset> Size: 35MB
Dimensions:                            (time: 4343, range: 996, sweep: 9,
                                        r_calib: 1)
Coordinates:
  * time                               (time) datetime64[ns] 35kB 2008-06-04T...
  * range                              (range) float32 4kB 150.0 ... 1.494e+05
Dimensions without coordinates: sweep, r_calib
Data variables: (12/99)
    pulse_width                        (time) timedelta64[ns] 35kB 00:00:00 ....
    prt                                (time) timedelta64[ns] 35kB -1 days +2...
    prt_ratio                          (time) timedelta64[ns] 35kB -1 days +2...
    nyquist_velocity                   (time) float32 17kB 26.92 26.92 ... 26.92
    unambiguous_range                  (time) float32 17kB 1.5e+05 ... 1.5e+05
    antenna_transition                 (time) int8 4kB 0 0 0 0 0 0 ... 0 0 0 0 0
    ...                                 ...
    drift_correction                   float32 4B ...
    vertical_velocity_correction       float32 4B ...
    pressure_altitude_correction       float32 4B ...
    latitude_correction                float32 4B ...
    range_correction                   float32 4B ...
    tilt_correction                    float32 4B ...
Attributes: (12/13)
    Conventions:         Cf/Radial
    version:             1.2
    title:               TIMREX
    institution:
    references:
    source:
    ...                  ...
    comment:
    instrument_name:     SPOLRVP8
    site_name:
    scan_name:
    scan_id:             0
    platform_is_mobile:  false

Transform CF1 to CF2#

[4]:
dtree = ds.xradar.to_cfradial2_datatree()
display(dtree)
<xarray.DatasetView> Size: 477B
Dimensions:              (sweep: 9)
Dimensions without coordinates: sweep
Data variables:
    sweep_group_name     (sweep) <U7 252B 'sweep_0' 'sweep_1' ... 'sweep_8'
    sweep_fixed_angle    (sweep) float32 36B 0.4999 1.099 1.802 ... 9.102 12.8
    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 ...
    latitude             float64 8B ...
    longitude            float64 8B ...
    altitude             float64 8B ...
Attributes: (12/13)
    Conventions:         Cf/Radial
    version:             1.2
    title:               TIMREX
    institution:
    references:
    source:
    ...                  ...
    comment:
    instrument_name:     SPOLRVP8
    site_name:
    scan_name:
    scan_id:             0
    platform_is_mobile:  false
[5]:
del ds, dtree

Alternate Method#

We can directly use xarray to read the data and then transform it to CF2 datatree.

[6]:
ds = xr.open_dataset(file)
/tmp/ipykernel_5399/1845474439.py:1: FutureWarning: In a future version of xarray decode_timedelta will default to False rather than None. To silence this warning, set decode_timedelta to True, False, or a 'CFTimedeltaCoder' instance.
  ds = xr.open_dataset(file)
/tmp/ipykernel_5399/1845474439.py:1: FutureWarning: In a future version of xarray decode_timedelta will default to False rather than None. To silence this warning, set decode_timedelta to True, False, or a 'CFTimedeltaCoder' instance.
  ds = xr.open_dataset(file)
[7]:
ds
[7]:
<xarray.Dataset> Size: 35MB
Dimensions:                           (sweep: 9, r_calib: 1, time: 4343,
                                       range: 996)
Coordinates:
  * time                              (time) datetime64[ns] 35kB 2008-06-04T0...
  * range                             (range) float32 4kB 150.0 ... 1.494e+05
Dimensions without coordinates: sweep, r_calib
Data variables: (12/100)
    volume_number                     int32 4B ...
    platform_type                     |S32 32B ...
    primary_axis                      |S32 32B ...
    status_xml                        |S1 1B ...
    instrument_type                   |S32 32B ...
    radar_antenna_gain_h              float32 4B ...
    ...                                ...
    r_calib_index                     (time) int8 4kB ...
    measured_transmit_power_h         (time) float32 17kB ...
    measured_transmit_power_v         (time) float32 17kB ...
    scan_rate                         (time) float32 17kB ...
    DBZ                               (time, range) float32 17MB ...
    VR                                (time, range) float32 17MB ...
Attributes: (12/14)
    Conventions:         CF/Radial instrument_parameters radar_parameters rad...
    version:             1.2
    title:               TIMREX
    institution:
    references:
    source:
    ...                  ...
    instrument_name:     SPOLRVP8
    site_name:
    scan_name:
    scan_id:             0
    platform_is_mobile:  false
    n_gates_vary:        false
[8]:
radar = ds.xradar.to_cf2()
[9]:
display(radar)
<xarray.DatasetView> Size: 477B
Dimensions:              (sweep: 9)
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 ...
    latitude             float64 8B ...
    longitude            float64 8B ...
    altitude             float64 8B ...
    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
[ ]: