Universal Format (UF)#

import cmweather  # noqa
import xarray as xr
from open_radar_data import DATASETS

import xradar as xd

Download#

Fetching Universal Format radar data file from open-radar-data repository.

import atexit
from pathlib import Path
from tempfile import TemporaryDirectory

tmpdir_obj = TemporaryDirectory()
atexit.register(tmpdir_obj.cleanup)  # remove even if you forget
tmpdir = Path(tmpdir_obj.name)


def get_temp_file(fname):
    import gzip
    import shutil

    fnamei = Path(DATASETS.fetch(fname))
    fnameo = tmpdir / fnamei.stem
    with gzip.open(fnamei) as fin:
        with open(fnameo, "wb") as fout:
            shutil.copyfileobj(fin, fout)
            fout.flush()
            fout.close()
    return fnameo


fname = get_temp_file("20110427_164233_rvp8-rel_v001_SUR.uf.gz")
Downloading file '20110427_164233_rvp8-rel_v001_SUR.uf.gz' from 'https://github.com/openradar/open-radar-data/raw/main/data/20110427_164233_rvp8-rel_v001_SUR.uf.gz' to '/home/docs/.cache/open-radar-data'.

xr.open_dataset#

Making use of the xarray uf backend. We also need to provide the group. Note, that we are using CfRadial2 group access pattern.

ds = xr.open_dataset(fname, group="sweep_0", engine="uf")
display(ds)
<xarray.Dataset> Size: 23MB
Dimensions:            (azimuth: 318, range: 997)
Coordinates:
  * azimuth            (azimuth) float64 3kB 22.88 23.88 24.91 ... 338.9 339.9
    elevation          (azimuth) float64 3kB ...
    time               (azimuth) datetime64[us] 3kB ...
  * range              (range) float32 4kB -436.5 -311.5 ... 1.239e+05 1.241e+05
    longitude          float64 8B ...
    latitude           float64 8B ...
    altitude           int64 8B ...
Data variables: (12/14)
    DBZH               (azimuth, range) float64 3MB ...
    DBTH               (azimuth, range) float64 3MB ...
    VRADH              (azimuth, range) float64 3MB ...
    WRADH              (azimuth, range) float64 3MB ...
    ZDR                (azimuth, range) float64 3MB ...
    KDP                (azimuth, range) float64 3MB ...
    ...                 ...
    RHOHV              (azimuth, range) float64 3MB ...
    sweep_mode         <U20 80B ...
    sweep_number       int64 8B ...
    prt_mode           <U7 28B ...
    follow_mode        <U7 28B ...
    sweep_fixed_angle  float64 8B ...
Attributes:
    source:           Sigmet/UF
    site_name:        MAX
    instrument_name:  rvp8-rel
    comment:          Sigmet I
import numpy as np

np.testing.assert_almost_equal(ds.sweep_fixed_angle.values, 0.703125)

Plot Time vs. Azimuth#

ds.azimuth.plot()
[<matplotlib.lines.Line2D at 0x7a1151d92210>]
../_images/e9ffccd779c5c0aba065ce78d0c7f63033d6f9d749dd0cc3fca121d0b88cb576.png

Plot Range vs. Time#

We need to sort by time and specify the y-coordinate.

ds.DBZH.sortby("time").plot(y="time", cmap="HomeyerRainbow")
<matplotlib.collections.QuadMesh at 0x7a1151bc9be0>
../_images/9d34beb2beed8fcbe4ef045993c7fec9f1235e92732970c8c7dd68c2885dfeef.png

Plot Range vs. Azimuth#

ds.DBZH.plot(cmap="HomeyerRainbow")
<matplotlib.collections.QuadMesh at 0x7a1151b9e990>
../_images/1f16d667fb99533f7b406d08ebe608521b4b377671f29b6f0be9c1f3669cf3e2.png

backend_kwargs#

Beside first_dim there are several additional backend_kwargs for the uf backend, which handle different aspects of angle alignment. This comes into play, when azimuth and/or elevation arrays are not evenly spacend and other issues.

help(xd.io.UFBackendEntrypoint)
Help on class UFBackendEntrypoint in module xradar.io.backends.uf:

class UFBackendEntrypoint(xarray.backends.common.BackendEntrypoint)
 |  Xarray BackendEntrypoint for Universal Format (UF) data.
 |
 |  Method resolution order:
 |      UFBackendEntrypoint
 |      xarray.backends.common.BackendEntrypoint
 |      builtins.object
 |
 |  Methods defined here:
 |
 |  open_dataset(
 |      self,
 |      filename_or_obj,
 |      *,
 |      mask_and_scale=True,
 |      decode_times=True,
 |      concat_characters=True,
 |      decode_coords=True,
 |      drop_variables=None,
 |      use_cftime=None,
 |      decode_timedelta=None,
 |      group=None,
 |      lock=None,
 |      first_dim='auto',
 |      reindex_angle=False,
 |      fix_second_angle=False,
 |      site_as_coords=True,
 |      optional=True
 |  )
 |      Backend open_dataset method used by Xarray in :py:func:`~xarray.open_dataset`.
 |
 |  ----------------------------------------------------------------------
 |  Data and other attributes defined here:
 |
 |  __annotations__ = {}
 |
 |  description = 'Open Universal Format (UF) files in Xarray'
 |
 |  open_dataset_parameters = ('filename_or_obj', 'mask_and_scale', 'decod...
 |
 |  url = 'https://xradar.rtfd.io/latest/io.html#uf-data-i-o'
 |
 |  ----------------------------------------------------------------------
 |  Methods inherited from xarray.backends.common.BackendEntrypoint:
 |
 |  __repr__(self) -> 'str'
 |      Return repr(self).
 |
 |  guess_can_open(self, filename_or_obj: 'T_PathFileOrDataStore') -> 'bool'
 |      Backend open_dataset method used by Xarray in :py:func:`~xarray.open_dataset`.
 |
 |  open_datatree(
 |      self,
 |      filename_or_obj: 'T_PathFileOrDataStore',
 |      *,
 |      drop_variables: 'str | Iterable[str] | None' = None
 |  ) -> 'DataTree'
 |      Backend open_datatree method used by Xarray in :py:func:`~xarray.open_datatree`.
 |
 |      If implemented, set the class variable supports_groups to True.
 |
 |  open_groups_as_dict(
 |      self,
 |      filename_or_obj: 'T_PathFileOrDataStore',
 |      *,
 |      drop_variables: 'str | Iterable[str] | None' = None
 |  ) -> 'dict[str, Dataset]'
 |      Opens a dictionary mapping from group names to Datasets.
 |
 |      Called by :py:func:`~xarray.open_groups`.
 |      This function exists to provide a universal way to open all groups in a file,
 |      before applying any additional consistency checks or requirements necessary
 |      to create a `DataTree` object (typically done using :py:meth:`~xarray.DataTree.from_dict`).
 |
 |      If implemented, set the class variable supports_groups to True.
 |
 |  ----------------------------------------------------------------------
 |  Data descriptors inherited from xarray.backends.common.BackendEntrypoint:
 |
 |  __dict__
 |      dictionary for instance variables
 |
 |  __weakref__
 |      list of weak references to the object
 |
 |  ----------------------------------------------------------------------
 |  Data and other attributes inherited from xarray.backends.common.BackendEntrypoint:
 |
 |  supports_groups = False
ds = xr.open_dataset(fname, group="sweep_0", engine="uf", first_dim="time")
display(ds)
<xarray.Dataset> Size: 23MB
Dimensions:            (time: 318, range: 997)
Coordinates:
  * time               (time) datetime64[us] 3kB 2011-04-27T16:42:32.749970 ....
    azimuth            (time) float64 3kB ...
    elevation          (time) float64 3kB ...
  * range              (range) float32 4kB -436.5 -311.5 ... 1.239e+05 1.241e+05
    longitude          float64 8B ...
    latitude           float64 8B ...
    altitude           int64 8B ...
Data variables: (12/14)
    DBZH               (time, range) float64 3MB ...
    DBTH               (time, range) float64 3MB ...
    VRADH              (time, range) float64 3MB ...
    WRADH              (time, range) float64 3MB ...
    ZDR                (time, range) float64 3MB ...
    KDP                (time, range) float64 3MB ...
    ...                 ...
    RHOHV              (time, range) float64 3MB ...
    sweep_mode         <U20 80B ...
    sweep_number       int64 8B ...
    prt_mode           <U7 28B ...
    follow_mode        <U7 28B ...
    sweep_fixed_angle  float64 8B ...
Attributes:
    source:           Sigmet/UF
    site_name:        MAX
    instrument_name:  rvp8-rel
    comment:          Sigmet I

open_uf_datatree#

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

help(xd.io.open_uf_datatree)
Help on function open_uf_datatree in module xradar.io.backends.uf:

open_uf_datatree(
    filename_or_obj,
    mask_and_scale=True,
    decode_times=True,
    concat_characters=True,
    decode_coords=True,
    drop_variables=None,
    use_cftime=None,
    decode_timedelta=None,
    sweep=None,
    first_dim='auto',
    reindex_angle=False,
    fix_second_angle=False,
    site_as_coords=True,
    optional=True,
    optional_groups=False,
    lock=None,
    **kwargs
)
    Open a Universal Format (UF) dataset as :py:class:`xarray.DataTree`.

    This function loads UF radar data into a DataTree structure, which
    organizes radar sweeps as separate nodes. Provides options for decoding time
    and applying various transformations to the data.

    Parameters
    ----------
    filename_or_obj : str, Path, file-like, or DataStore
        The path or file-like object representing the radar file.
        Path-like objects are interpreted as local or remote paths.

    mask_and_scale : bool, optional
        If True, replaces values in the dataset that match `_FillValue` with NaN
        and applies scale and offset adjustments. Default is True.

    decode_times : bool, optional
        If True, decodes time variables according to CF conventions. Default is True.

    concat_characters : bool, optional
        If True, concatenates character arrays along the last dimension, forming
        string arrays. Default is True.

    decode_coords : bool, optional
        If True, decodes the "coordinates" attribute to identify coordinates in the
        resulting dataset. Default is True.

    drop_variables : str or list of str, optional
        Specifies variables to exclude from the dataset. Useful for removing problematic
        or inconsistent variables. Default is None.

    use_cftime : bool, optional
        If True, uses cftime objects to represent time variables; if False, uses
        `np.datetime64` objects. If None, chooses the best format automatically.
        Default is None.

    decode_timedelta : bool, optional
        If True, decodes variables with units of time (e.g., seconds, minutes) into
        timedelta objects. If False, leaves them as numeric values. Default is None.

    sweep : int or list of int, optional
        Sweep numbers to extract from the dataset. If None, extracts all sweeps into
        a list. Default is the first sweep.

    first_dim : {"time", "auto"}, optional
        Defines the first dimension for each sweep. If "time," uses time as the
        first dimension. If "auto," determines the first dimension based on the sweep
        type (azimuth or elevation). Default is "auto."

    reindex_angle : bool or dict, optional
        Controls angle reindexing. If True or a dictionary, applies reindexing with
        specified settings (if given). Only used if `decode_coords=True`. Default is False.

    fix_second_angle : bool, optional
        If True, corrects errors in the second angle data, such as misaligned
        elevation or azimuth values. Default is False.

    site_as_coords : bool, optional
        Attaches radar site coordinates to the dataset if True. Default is True.

    optional : bool, optional
        If True, suppresses errors for optional dataset attributes, making them
        optional instead of required. Default is True.

    kwargs : dict
        Additional keyword arguments passed to `xarray.open_dataset`.

    Returns
    -------
    dtree : xarray.DataTree
        An `xarray.DataTree` representing the radar data organized by sweeps.
dtree = xd.io.open_uf_datatree(fname, sweep=4)
display(dtree)
<xarray.DataTree>
Group: /
│   Dimensions:              ()
│   Coordinates:
│       latitude             float64 8B 34.93
│       longitude            float64 8B -86.47
│       altitude             int64 8B 226
│   Data variables:
│       volume_number        int64 8B 0
│       platform_type        <U5 20B 'fixed'
│       instrument_type      <U5 20B 'radar'
│       time_coverage_start  <U20 80B '2011-04-27T16:43:51Z'
│       time_coverage_end    <U20 80B '2011-04-27T16:43:52Z'
│   Attributes:
│       Conventions:      None
│       instrument_name:  rvp8-rel
│       version:          None
│       title:            None
│       institution:      None
│       references:       None
│       source:           Sigmet/UF
│       history:          None
│       comment:          Sigmet I
│       site_name:        MAX
└── Group: /sweep_4
        Dimensions:            (azimuth: 318, range: 997)
        Coordinates:
          * azimuth            (azimuth) float64 3kB 22.86 23.86 24.88 ... 338.9 339.9
            elevation          (azimuth) float64 3kB 3.688 3.766 3.812 ... 3.891 3.859
            time               (azimuth) datetime64[us] 3kB 2011-04-27T16:43:52 ... 2...
            range              (range) float32 4kB -436.5 -311.5 ... 1.239e+05 1.241e+05
        Data variables: (12/14)
            DBZH               (azimuth, range) float64 3MB ...
            DBTH               (azimuth, range) float64 3MB ...
            VRADH              (azimuth, range) float64 3MB ...
            WRADH              (azimuth, range) float64 3MB ...
            ZDR                (azimuth, range) float64 3MB ...
            KDP                (azimuth, range) float64 3MB ...
            ...                 ...
            RHOHV              (azimuth, range) float64 3MB ...
            sweep_mode         <U20 80B 'azimuth_surveillance'
            sweep_number       int64 8B 4
            prt_mode           <U7 28B 'not_set'
            follow_mode        <U7 28B 'not_set'
            sweep_fixed_angle  float64 8B 3.797

Plot Sweep Range vs. Time#

dtree["sweep_4"].ds.DBZH.sortby("time").plot(y="time", cmap="HomeyerRainbow")
<matplotlib.collections.QuadMesh at 0x7a1152f29310>
../_images/c560c1ac281d8e36ab57e0539c3ba20964f6b5e0b1f504c5a6d73fa2fcd3028c.png

Plot Sweep Range vs. Azimuth#

dtree["sweep_4"].ds.DBZH.plot(cmap="HomeyerRainbow")
<matplotlib.collections.QuadMesh at 0x7a1136f0e490>
../_images/2f70cb7158cc6e8797e3b6d16915234a07b7f3d4fd841c22e505a770afb449db.png
dtree = xd.io.open_uf_datatree(fname, sweep="sweep_8")
display(dtree)
<xarray.DataTree>
Group: /
│   Dimensions:              ()
│   Coordinates:
│       latitude             float64 8B 34.93
│       longitude            float64 8B -86.47
│       altitude             int64 8B 226
│   Data variables:
│       volume_number        int64 8B 0
│       platform_type        <U5 20B 'fixed'
│       instrument_type      <U5 20B 'radar'
│       time_coverage_start  <U20 80B '2011-04-27T16:45:10Z'
│       time_coverage_end    <U20 80B '2011-04-27T16:45:11Z'
│   Attributes:
│       Conventions:      None
│       instrument_name:  rvp8-rel
│       version:          None
│       title:            None
│       institution:      None
│       references:       None
│       source:           Sigmet/UF
│       history:          None
│       comment:          Sigmet I
│       site_name:        MAX
└── Group: /sweep_8
        Dimensions:            (azimuth: 329, range: 919)
        Coordinates:
          * azimuth            (azimuth) float64 3kB 0.875 1.875 21.88 ... 358.9 359.9
            elevation          (azimuth) float64 3kB 10.09 10.05 9.688 ... 10.14 10.12
            time               (azimuth) datetime64[us] 3kB 2011-04-27T16:45:11.34954...
            range              (range) float32 4kB -436.5 -311.5 ... 1.142e+05 1.143e+05
        Data variables: (12/14)
            DBZH               (azimuth, range) float64 2MB ...
            DBTH               (azimuth, range) float64 2MB ...
            VRADH              (azimuth, range) float64 2MB ...
            WRADH              (azimuth, range) float64 2MB ...
            ZDR                (azimuth, range) float64 2MB ...
            KDP                (azimuth, range) float64 2MB ...
            ...                 ...
            RHOHV              (azimuth, range) float64 2MB ...
            sweep_mode         <U20 80B 'azimuth_surveillance'
            sweep_number       int64 8B 8
            prt_mode           <U7 28B 'not_set'
            follow_mode        <U7 28B 'not_set'
            sweep_fixed_angle  float64 8B 10.0
dtree = xd.io.open_uf_datatree(fname, sweep=[0, 1, 8])
display(dtree)
<xarray.DataTree>
Group: /
│   Dimensions:              ()
│   Coordinates:
│       latitude             float64 8B 34.93
│       longitude            float64 8B -86.47
│       altitude             int64 8B 226
│   Data variables:
│       volume_number        int64 8B 0
│       platform_type        <U5 20B 'fixed'
│       instrument_type      <U5 20B 'radar'
│       time_coverage_start  <U20 80B '2011-04-27T16:42:32Z'
│       time_coverage_end    <U20 80B '2011-04-27T16:45:11Z'
│   Attributes:
│       Conventions:      None
│       instrument_name:  rvp8-rel
│       version:          None
│       title:            None
│       institution:      None
│       references:       None
│       source:           Sigmet/UF
│       history:          None
│       comment:          Sigmet I
│       site_name:        MAX
├── Group: /sweep_0
│       Dimensions:            (azimuth: 318, range: 997)
│       Coordinates:
│         * azimuth            (azimuth) float64 3kB 22.88 23.88 24.91 ... 338.9 339.9
│           elevation          (azimuth) float64 3kB 0.25 0.25 0.25 ... 0.2656 0.25
│           time               (azimuth) datetime64[us] 3kB 2011-04-27T16:42:33.36911...
│           range              (range) float32 4kB -436.5 -311.5 ... 1.239e+05 1.241e+05
│       Data variables: (12/14)
│           DBZH               (azimuth, range) float64 3MB ...
│           DBTH               (azimuth, range) float64 3MB ...
│           VRADH              (azimuth, range) float64 3MB ...
│           WRADH              (azimuth, range) float64 3MB ...
│           ZDR                (azimuth, range) float64 3MB ...
│           KDP                (azimuth, range) float64 3MB ...
│           ...                 ...
│           RHOHV              (azimuth, range) float64 3MB ...
│           sweep_mode         <U20 80B 'azimuth_surveillance'
│           sweep_number       int64 8B 0
│           prt_mode           <U7 28B 'not_set'
│           follow_mode        <U7 28B 'not_set'
│           sweep_fixed_angle  float64 8B 0.7031
├── Group: /sweep_1
│       Dimensions:            (azimuth: 319, range: 997)
│       Coordinates:
│         * azimuth            (azimuth) float64 3kB 21.88 22.86 23.89 ... 338.9 339.9
│           elevation          (azimuth) float64 3kB 1.0 1.0 0.9688 ... 0.8906 0.8906
│           time               (azimuth) datetime64[us] 3kB 2011-04-27T16:42:53.45895...
│           range              (range) float32 4kB -436.5 -311.5 ... 1.239e+05 1.241e+05
│       Data variables: (12/14)
│           DBZH               (azimuth, range) float64 3MB ...
│           DBTH               (azimuth, range) float64 3MB ...
│           VRADH              (azimuth, range) float64 3MB ...
│           WRADH              (azimuth, range) float64 3MB ...
│           ZDR                (azimuth, range) float64 3MB ...
│           KDP                (azimuth, range) float64 3MB ...
│           ...                 ...
│           RHOHV              (azimuth, range) float64 3MB ...
│           sweep_mode         <U20 80B 'azimuth_surveillance'
│           sweep_number       int64 8B 1
│           prt_mode           <U7 28B 'not_set'
│           follow_mode        <U7 28B 'not_set'
│           sweep_fixed_angle  float64 8B 1.297
└── Group: /sweep_8
        Dimensions:            (azimuth: 329, range: 919)
        Coordinates:
          * azimuth            (azimuth) float64 3kB 0.875 1.875 21.88 ... 358.9 359.9
            elevation          (azimuth) float64 3kB 10.09 10.05 9.688 ... 10.14 10.12
            time               (azimuth) datetime64[us] 3kB 2011-04-27T16:45:11.34954...
            range              (range) float32 4kB -436.5 -311.5 ... 1.142e+05 1.143e+05
        Data variables: (12/14)
            DBZH               (azimuth, range) float64 2MB ...
            DBTH               (azimuth, range) float64 2MB ...
            VRADH              (azimuth, range) float64 2MB ...
            WRADH              (azimuth, range) float64 2MB ...
            ZDR                (azimuth, range) float64 2MB ...
            KDP                (azimuth, range) float64 2MB ...
            ...                 ...
            RHOHV              (azimuth, range) float64 2MB ...
            sweep_mode         <U20 80B 'azimuth_surveillance'
            sweep_number       int64 8B 8
            prt_mode           <U7 28B 'not_set'
            follow_mode        <U7 28B 'not_set'
            sweep_fixed_angle  float64 8B 10.0
dtree["sweep_0"]["sweep_fixed_angle"].values
array(0.703125)
dtree["sweep_8"]["sweep_fixed_angle"].values
array(10.)
dtree = xd.io.open_uf_datatree(fname)
display(dtree)
<xarray.DataTree>
Group: /
│   Dimensions:              ()
│   Coordinates:
│       latitude             float64 8B 34.93
│       longitude            float64 8B -86.47
│       altitude             int64 8B 226
│   Data variables:
│       volume_number        int64 8B 0
│       platform_type        <U5 20B 'fixed'
│       instrument_type      <U5 20B 'radar'
│       time_coverage_start  <U20 80B '2011-04-27T16:42:32Z'
│       time_coverage_end    <U20 80B '2011-04-27T16:46:50Z'
│   Attributes:
│       Conventions:      None
│       instrument_name:  rvp8-rel
│       version:          None
│       title:            None
│       institution:      None
│       references:       None
│       source:           Sigmet/UF
│       history:          None
│       comment:          Sigmet I
│       site_name:        MAX
├── Group: /sweep_0
│       Dimensions:            (azimuth: 318, range: 997)
│       Coordinates:
│         * azimuth            (azimuth) float64 3kB 22.88 23.88 24.91 ... 338.9 339.9
│           elevation          (azimuth) float64 3kB 0.25 0.25 0.25 ... 0.2656 0.25
│           time               (azimuth) datetime64[us] 3kB 2011-04-27T16:42:33.36911...
│           range              (range) float32 4kB -436.5 -311.5 ... 1.239e+05 1.241e+05
│       Data variables: (12/14)
│           DBZH               (azimuth, range) float64 3MB ...
│           DBTH               (azimuth, range) float64 3MB ...
│           VRADH              (azimuth, range) float64 3MB ...
│           WRADH              (azimuth, range) float64 3MB ...
│           ZDR                (azimuth, range) float64 3MB ...
│           KDP                (azimuth, range) float64 3MB ...
│           ...                 ...
│           RHOHV              (azimuth, range) float64 3MB ...
│           sweep_mode         <U20 80B 'azimuth_surveillance'
│           sweep_number       int64 8B 0
│           prt_mode           <U7 28B 'not_set'
│           follow_mode        <U7 28B 'not_set'
│           sweep_fixed_angle  float64 8B 0.7031
├── Group: /sweep_1
│       Dimensions:            (azimuth: 319, range: 997)
│       Coordinates:
│         * azimuth            (azimuth) float64 3kB 21.88 22.86 23.89 ... 338.9 339.9
│           elevation          (azimuth) float64 3kB 1.0 1.0 0.9688 ... 0.8906 0.8906
│           time               (azimuth) datetime64[us] 3kB 2011-04-27T16:42:53.45895...
│           range              (range) float32 4kB -436.5 -311.5 ... 1.239e+05 1.241e+05
│       Data variables: (12/14)
│           DBZH               (azimuth, range) float64 3MB ...
│           DBTH               (azimuth, range) float64 3MB ...
│           VRADH              (azimuth, range) float64 3MB ...
│           WRADH              (azimuth, range) float64 3MB ...
│           ZDR                (azimuth, range) float64 3MB ...
│           KDP                (azimuth, range) float64 3MB ...
│           ...                 ...
│           RHOHV              (azimuth, range) float64 3MB ...
│           sweep_mode         <U20 80B 'azimuth_surveillance'
│           sweep_number       int64 8B 1
│           prt_mode           <U7 28B 'not_set'
│           follow_mode        <U7 28B 'not_set'
│           sweep_fixed_angle  float64 8B 1.297
├── Group: /sweep_2
│       Dimensions:            (azimuth: 319, range: 997)
│       Coordinates:
│         * azimuth            (azimuth) float64 3kB 21.88 22.88 23.89 ... 338.9 339.9
│           elevation          (azimuth) float64 3kB 1.594 1.578 1.578 ... 1.562 1.547
│           time               (azimuth) datetime64[us] 3kB 2011-04-27T16:43:13.54489...
│           range              (range) float32 4kB -436.5 -311.5 ... 1.239e+05 1.241e+05
│       Data variables: (12/14)
│           DBZH               (azimuth, range) float64 3MB ...
│           DBTH               (azimuth, range) float64 3MB ...
│           VRADH              (azimuth, range) float64 3MB ...
│           WRADH              (azimuth, range) float64 3MB ...
│           ZDR                (azimuth, range) float64 3MB ...
│           KDP                (azimuth, range) float64 3MB ...
│           ...                 ...
│           RHOHV              (azimuth, range) float64 3MB ...
│           sweep_mode         <U20 80B 'azimuth_surveillance'
│           sweep_number       int64 8B 2
│           prt_mode           <U7 28B 'not_set'
│           follow_mode        <U7 28B 'not_set'
│           sweep_fixed_angle  float64 8B 2.0
├── Group: /sweep_3
│       Dimensions:            (azimuth: 318, range: 997)
│       Coordinates:
│         * azimuth            (azimuth) float64 3kB 22.86 23.86 24.86 ... 338.9 339.9
│           elevation          (azimuth) float64 3kB 2.516 2.516 2.516 ... 2.406 2.391
│           time               (azimuth) datetime64[us] 3kB 2011-04-27T16:43:32.59567...
│           range              (range) float32 4kB -436.5 -311.5 ... 1.239e+05 1.241e+05
│       Data variables: (12/14)
│           DBZH               (azimuth, range) float64 3MB ...
│           DBTH               (azimuth, range) float64 3MB ...
│           VRADH              (azimuth, range) float64 3MB ...
│           WRADH              (azimuth, range) float64 3MB ...
│           ZDR                (azimuth, range) float64 3MB ...
│           KDP                (azimuth, range) float64 3MB ...
│           ...                 ...
│           RHOHV              (azimuth, range) float64 3MB ...
│           sweep_mode         <U20 80B 'azimuth_surveillance'
│           sweep_number       int64 8B 3
│           prt_mode           <U7 28B 'not_set'
│           follow_mode        <U7 28B 'not_set'
│           sweep_fixed_angle  float64 8B 2.703
├── Group: /sweep_4
│       Dimensions:            (azimuth: 318, range: 997)
│       Coordinates:
│         * azimuth            (azimuth) float64 3kB 22.86 23.86 24.88 ... 338.9 339.9
│           elevation          (azimuth) float64 3kB 3.688 3.766 3.812 ... 3.891 3.859
│           time               (azimuth) datetime64[us] 3kB 2011-04-27T16:43:52 ... 2...
│           range              (range) float32 4kB -436.5 -311.5 ... 1.239e+05 1.241e+05
│       Data variables: (12/14)
│           DBZH               (azimuth, range) float64 3MB ...
│           DBTH               (azimuth, range) float64 3MB ...
│           VRADH              (azimuth, range) float64 3MB ...
│           WRADH              (azimuth, range) float64 3MB ...
│           ZDR                (azimuth, range) float64 3MB ...
│           KDP                (azimuth, range) float64 3MB ...
│           ...                 ...
│           RHOHV              (azimuth, range) float64 3MB ...
│           sweep_mode         <U20 80B 'azimuth_surveillance'
│           sweep_number       int64 8B 4
│           prt_mode           <U7 28B 'not_set'
│           follow_mode        <U7 28B 'not_set'
│           sweep_fixed_angle  float64 8B 3.797
├── Group: /sweep_5
│       Dimensions:            (azimuth: 318, range: 997)
│       Coordinates:
│         * azimuth            (azimuth) float64 3kB 22.88 23.86 24.88 ... 338.9 339.9
│           elevation          (azimuth) float64 3kB 4.984 4.984 4.969 ... 4.922 4.922
│           time               (azimuth) datetime64[us] 3kB 2011-04-27T16:44:12.06243...
│           range              (range) float32 4kB -436.5 -311.5 ... 1.239e+05 1.241e+05
│       Data variables: (12/14)
│           DBZH               (azimuth, range) float64 3MB ...
│           DBTH               (azimuth, range) float64 3MB ...
│           VRADH              (azimuth, range) float64 3MB ...
│           WRADH              (azimuth, range) float64 3MB ...
│           ZDR                (azimuth, range) float64 3MB ...
│           KDP                (azimuth, range) float64 3MB ...
│           ...                 ...
│           RHOHV              (azimuth, range) float64 3MB ...
│           sweep_mode         <U20 80B 'azimuth_surveillance'
│           sweep_number       int64 8B 5
│           prt_mode           <U7 28B 'not_set'
│           follow_mode        <U7 28B 'not_set'
│           sweep_fixed_angle  float64 8B 5.0
...
├── Group: /sweep_8
│       Dimensions:            (azimuth: 329, range: 919)
│       Coordinates:
│         * azimuth            (azimuth) float64 3kB 0.875 1.875 21.88 ... 358.9 359.9
│           elevation          (azimuth) float64 3kB 10.09 10.05 9.688 ... 10.14 10.12
│           time               (azimuth) datetime64[us] 3kB 2011-04-27T16:45:11.34954...
│           range              (range) float32 4kB -436.5 -311.5 ... 1.142e+05 1.143e+05
│       Data variables: (12/14)
│           DBZH               (azimuth, range) float64 2MB ...
│           DBTH               (azimuth, range) float64 2MB ...
│           VRADH              (azimuth, range) float64 2MB ...
│           WRADH              (azimuth, range) float64 2MB ...
│           ZDR                (azimuth, range) float64 2MB ...
│           KDP                (azimuth, range) float64 2MB ...
│           ...                 ...
│           RHOHV              (azimuth, range) float64 2MB ...
│           sweep_mode         <U20 80B 'azimuth_surveillance'
│           sweep_number       int64 8B 8
│           prt_mode           <U7 28B 'not_set'
│           follow_mode        <U7 28B 'not_set'
│           sweep_fixed_angle  float64 8B 10.0
├── Group: /sweep_9
│       Dimensions:            (azimuth: 351, range: 766)
│       Coordinates:
│         * azimuth            (azimuth) float64 3kB 0.875 1.844 2.875 ... 358.8 359.8
│           elevation          (azimuth) float64 3kB 11.91 11.89 11.86 ... 11.94 11.91
│           time               (azimuth) datetime64[us] 3kB 2011-04-27T16:45:31.45114...
│           range              (range) float32 3kB -436.5 -311.5 ... 9.506e+04 9.519e+04
│       Data variables: (12/14)
│           DBZH               (azimuth, range) float64 2MB ...
│           DBTH               (azimuth, range) float64 2MB ...
│           VRADH              (azimuth, range) float64 2MB ...
│           WRADH              (azimuth, range) float64 2MB ...
│           ZDR                (azimuth, range) float64 2MB ...
│           KDP                (azimuth, range) float64 2MB ...
│           ...                 ...
│           RHOHV              (azimuth, range) float64 2MB ...
│           sweep_mode         <U20 80B 'azimuth_surveillance'
│           sweep_number       int64 8B 9
│           prt_mode           <U7 28B 'not_set'
│           follow_mode        <U7 28B 'not_set'
│           sweep_fixed_angle  float64 8B 12.0
├── Group: /sweep_10
│       Dimensions:            (azimuth: 360, range: 658)
│       Coordinates:
│         * azimuth            (azimuth) float64 3kB 0.875 1.875 2.859 ... 358.9 359.9
│           elevation          (azimuth) float64 3kB 13.58 13.55 13.52 ... 13.59 13.59
│           time               (azimuth) datetime64[us] 3kB 2011-04-27T16:45:51.55068...
│           range              (range) float32 3kB -436.5 -311.5 ... 8.156e+04 8.169e+04
│       Data variables: (12/14)
│           DBZH               (azimuth, range) float64 2MB ...
│           DBTH               (azimuth, range) float64 2MB ...
│           VRADH              (azimuth, range) float64 2MB ...
│           WRADH              (azimuth, range) float64 2MB ...
│           ZDR                (azimuth, range) float64 2MB ...
│           KDP                (azimuth, range) float64 2MB ...
│           ...                 ...
│           RHOHV              (azimuth, range) float64 2MB ...
│           sweep_mode         <U20 80B 'azimuth_surveillance'
│           sweep_number       int64 8B 10
│           prt_mode           <U7 28B 'not_set'
│           follow_mode        <U7 28B 'not_set'
│           sweep_fixed_angle  float64 8B 14.0
├── Group: /sweep_11
│       Dimensions:            (azimuth: 360, range: 577)
│       Coordinates:
│         * azimuth            (azimuth) float64 3kB 0.8438 1.859 2.828 ... 358.9 359.8
│           elevation          (azimuth) float64 3kB 15.69 15.66 15.67 ... 15.7 15.67
│           time               (azimuth) datetime64[us] 3kB 2011-04-27T16:46:10.64260...
│           range              (range) float32 2kB -436.5 -311.5 ... 7.144e+04 7.156e+04
│       Data variables: (12/14)
│           DBZH               (azimuth, range) float64 2MB ...
│           DBTH               (azimuth, range) float64 2MB ...
│           VRADH              (azimuth, range) float64 2MB ...
│           WRADH              (azimuth, range) float64 2MB ...
│           ZDR                (azimuth, range) float64 2MB ...
│           KDP                (azimuth, range) float64 2MB ...
│           ...                 ...
│           RHOHV              (azimuth, range) float64 2MB ...
│           sweep_mode         <U20 80B 'azimuth_surveillance'
│           sweep_number       int64 8B 11
│           prt_mode           <U7 28B 'not_set'
│           follow_mode        <U7 28B 'not_set'
│           sweep_fixed_angle  float64 8B 16.0
├── Group: /sweep_12
│       Dimensions:            (azimuth: 360, range: 476)
│       Coordinates:
│         * azimuth            (azimuth) float64 3kB 0.8438 1.891 2.875 ... 358.9 359.9
│           elevation          (azimuth) float64 3kB 19.47 19.5 19.52 ... 19.47 19.47
│           time               (azimuth) datetime64[us] 3kB 2011-04-27T16:46:31.05084...
│           range              (range) float32 2kB -436.5 -311.5 ... 5.881e+04 5.894e+04
│       Data variables: (12/14)
│           DBZH               (azimuth, range) float64 1MB ...
│           DBTH               (azimuth, range) float64 1MB ...
│           VRADH              (azimuth, range) float64 1MB ...
│           WRADH              (azimuth, range) float64 1MB ...
│           ZDR                (azimuth, range) float64 1MB ...
│           KDP                (azimuth, range) float64 1MB ...
│           ...                 ...
│           RHOHV              (azimuth, range) float64 1MB ...
│           sweep_mode         <U20 80B 'azimuth_surveillance'
│           sweep_number       int64 8B 12
│           prt_mode           <U7 28B 'not_set'
│           follow_mode        <U7 28B 'not_set'
│           sweep_fixed_angle  float64 8B 19.5
└── Group: /sweep_13
        Dimensions:            (azimuth: 360, range: 422)
        Coordinates:
          * azimuth            (azimuth) float64 3kB 0.875 1.844 2.844 ... 358.9 359.9
            elevation          (azimuth) float64 3kB 21.97 22.03 22.08 ... 21.88 21.92
            time               (azimuth) datetime64[us] 3kB 2011-04-27T16:46:50.14840...
            range              (range) float32 2kB -436.5 -311.5 ... 5.206e+04 5.219e+04
        Data variables: (12/14)
            DBZH               (azimuth, range) float64 1MB ...
            DBTH               (azimuth, range) float64 1MB ...
            VRADH              (azimuth, range) float64 1MB ...
            WRADH              (azimuth, range) float64 1MB ...
            ZDR                (azimuth, range) float64 1MB ...
            KDP                (azimuth, range) float64 1MB ...
            ...                 ...
            RHOHV              (azimuth, range) float64 1MB ...
            sweep_mode         <U20 80B 'azimuth_surveillance'
            sweep_number       int64 8B 13
            prt_mode           <U7 28B 'not_set'
            follow_mode        <U7 28B 'not_set'
            sweep_fixed_angle  float64 8B 22.09
dtree["sweep_1"]
<xarray.DataTree 'sweep_1'>
Group: /sweep_1
    Dimensions:            (azimuth: 319, range: 997)
    Coordinates:
      * azimuth            (azimuth) float64 3kB 21.88 22.86 23.89 ... 338.9 339.9
        elevation          (azimuth) float64 3kB 1.0 1.0 0.9688 ... 0.8906 0.8906
        time               (azimuth) datetime64[us] 3kB 2011-04-27T16:42:53.45895...
        range              (range) float32 4kB -436.5 -311.5 ... 1.239e+05 1.241e+05
    Data variables: (12/14)
        DBZH               (azimuth, range) float64 3MB ...
        DBTH               (azimuth, range) float64 3MB ...
        VRADH              (azimuth, range) float64 3MB ...
        WRADH              (azimuth, range) float64 3MB ...
        ZDR                (azimuth, range) float64 3MB ...
        KDP                (azimuth, range) float64 3MB ...
        ...                 ...
        RHOHV              (azimuth, range) float64 3MB ...
        sweep_mode         <U20 80B 'azimuth_surveillance'
        sweep_number       int64 8B 1
        prt_mode           <U7 28B 'not_set'
        follow_mode        <U7 28B 'not_set'
        sweep_fixed_angle  float64 8B 1.297

clean up#

import time

for node in dtree.values():
    if hasattr(node, "close"):
        node.close()
for file in tmpdir.iterdir():
    if file.is_file():
        for _ in range(5):
            try:
                file.unlink()
                break
            except PermissionError:
                time.sleep(0.5)