xradar is in an early stage of development, please report any issues here!

Iris/Sigmet - Reader#

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

Download#

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

[2]:
filename_single = DATASETS.fetch("SUR210819000227.RAWKPJV")
filename_volume = DATASETS.fetch("cor-main131125105503.RAW2049")
Downloading file 'SUR210819000227.RAWKPJV' from 'https://github.com/openradar/open-radar-data/raw/main/data/SUR210819000227.RAWKPJV' to '/home/docs/.cache/open-radar-data'.
Downloading file 'cor-main131125105503.RAW2049' from 'https://github.com/openradar/open-radar-data/raw/main/data/cor-main131125105503.RAW2049' to '/home/docs/.cache/open-radar-data'.

xr.open_dataset#

Making use of the xarray iris backend. We also need to provide the group. We use the group notation from CfRadial2.

[3]:
ds = xr.open_dataset(filename_single, group="sweep_0", engine="iris")
display(ds)
<xarray.Dataset> Size: 13MB
Dimensions:            (azimuth: 359, range: 833)
Coordinates:
    elevation          (azimuth) float32 1kB ...
    time               (azimuth) datetime64[ns] 3kB ...
  * range              (range) float32 3kB 150.0 450.0 ... 2.494e+05 2.498e+05
    longitude          float64 8B ...
    latitude           float64 8B ...
    altitude           float64 8B ...
  * azimuth            (azimuth) float32 1kB 0.03021 1.035 2.054 ... 358.0 359.0
Data variables: (12/16)
    DBTH               (azimuth, range) float32 1MB ...
    DBZH               (azimuth, range) float32 1MB ...
    VRADH              (azimuth, range) float32 1MB ...
    WRADH              (azimuth, range) float32 1MB ...
    ZDR                (azimuth, range) float32 1MB ...
    KDP                (azimuth, range) float32 1MB ...
    ...                 ...
    SNRH               (azimuth, range) float32 1MB ...
    sweep_mode         <U20 80B ...
    sweep_number       int64 8B ...
    prt_mode           <U7 28B ...
    follow_mode        <U7 28B ...
    sweep_fixed_angle  float64 8B ...

Plot Time vs. Azimuth#

[4]:
ds.azimuth.plot(y="time")
[4]:
[<matplotlib.lines.Line2D at 0x7ff82333c650>]
../_images/notebooks_Iris_7_1.png

Plot Range vs. Time#

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

[5]:
ds.DBZH.sortby("time").plot(y="time")
[5]:
<matplotlib.collections.QuadMesh at 0x7ff8230b51d0>
../_images/notebooks_Iris_9_1.png

Plot Range vs. Azimuth#

[6]:
ds.DBZH.plot(y="azimuth")
[6]:
<matplotlib.collections.QuadMesh at 0x7ff81aae7790>
../_images/notebooks_Iris_11_1.png

backend_kwargs#

Beside first_dim there are several additional backend_kwargs for the iris 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.

[7]:
help(xd.io.IrisBackendEntrypoint)
Help on class IrisBackendEntrypoint in module xradar.io.backends.iris:

class IrisBackendEntrypoint(xarray.backends.common.BackendEntrypoint)
 |  Xarray BackendEntrypoint for IRIS/Sigmet data.
 |
 |  Method resolution order:
 |      IrisBackendEntrypoint
 |      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, first_dim='auto', reindex_angle=False, fix_second_angle=False, site_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 IRIS/Sigmet files in Xarray'
 |
 |  open_dataset_parameters = ('filename_or_obj', 'mask_and_scale', 'decod...
 |
 |  url = 'https://xradar.rtfd.io/latest/io.html#iris-sigmet-data-i-o'
 |
 |  ----------------------------------------------------------------------
 |  Methods inherited from xarray.backends.common.BackendEntrypoint:
 |
 |  __repr__(self) -> 'str'
 |      Return repr(self).
 |
 |  guess_can_open(self, filename_or_obj: 'str | os.PathLike[Any] | BufferedIOBase | AbstractDataStore') -> 'bool'
 |      Backend open_dataset method used by Xarray in :py:func:`~xarray.open_dataset`.
 |
 |  open_datatree(self, filename_or_obj: 'str | os.PathLike[Any] | BufferedIOBase | AbstractDataStore', **kwargs: 'Any') -> 'DataTree'
 |      Backend open_datatree method used by Xarray in :py:func:`~xarray.open_datatree`.
 |
 |  ----------------------------------------------------------------------
 |  Data descriptors inherited from xarray.backends.common.BackendEntrypoint:
 |
 |  __dict__
 |      dictionary for instance variables
 |
 |  __weakref__
 |      list of weak references to the object

[8]:
ds = xr.open_dataset(filename_single, group="sweep_0", engine="iris", first_dim="time")
display(ds)
<xarray.Dataset> Size: 13MB
Dimensions:            (time: 359, range: 833)
Coordinates:
    elevation          (time) float32 1kB ...
  * time               (time) datetime64[ns] 3kB 2021-08-19T00:02:28.029000 ....
  * range              (range) float32 3kB 150.0 450.0 ... 2.494e+05 2.498e+05
    longitude          float64 8B ...
    latitude           float64 8B ...
    altitude           float64 8B ...
    azimuth            (time) float32 1kB ...
Data variables: (12/16)
    DBTH               (time, range) float32 1MB ...
    DBZH               (time, range) float32 1MB ...
    VRADH              (time, range) float32 1MB ...
    WRADH              (time, range) float32 1MB ...
    ZDR                (time, range) float32 1MB ...
    KDP                (time, range) float32 1MB ...
    ...                 ...
    SNRH               (time, range) float32 1MB ...
    sweep_mode         <U20 80B ...
    sweep_number       int64 8B ...
    prt_mode           <U7 28B ...
    follow_mode        <U7 28B ...
    sweep_fixed_angle  float64 8B ...

open_iris_datatree#

The same works analoguous with the datatree loader. But additionally we can provide a sweep string, number or list. The underlying xarray.Dataset can be accessed with property .ds.

[9]:
help(xd.io.open_iris_datatree)
Help on function open_iris_datatree in module xradar.io.backends.iris:

open_iris_datatree(filename_or_obj, **kwargs)
    Open Iris/Sigmet dataset as :py:class:`datatree.DataTree`.

    Parameters
    ----------
    filename_or_obj : str, Path, file-like or DataStore
        Strings and Path objects are interpreted as a path to a local or remote
        radar file

    Keyword Arguments
    -----------------
    sweep : int, list of int, optional
        Sweep number(s) to extract, default to first sweep. If None, all sweeps are
        extracted into a list.
    first_dim : str
        Can be ``time`` or ``auto`` first dimension. If set to ``auto``,
        first dimension will be either ``azimuth`` or ``elevation`` depending on
        type of sweep. Defaults to ``auto``.
    reindex_angle : bool or dict
        Defaults to False, no reindexing. Given dict should contain the kwargs to
        reindex_angle. Only invoked if `decode_coord=True`.
    fix_second_angle : bool
        If True, fixes erroneous second angle data. Defaults to ``False``.
    site_coords : bool
        Attach radar site-coordinates to Dataset, defaults to ``True``.
    kwargs : dict
        Additional kwargs are fed to :py:func:`xarray.open_dataset`.

    Returns
    -------
    dtree: datatree.DataTree
        DataTree

[10]:
dtree = xd.io.open_iris_datatree(filename_volume)
display(dtree)
<xarray.DatasetView> Size: 232B
Dimensions:              ()
Data variables:
    volume_number        int64 8B 0
    platform_type        <U5 20B 'fixed'
    instrument_type      <U5 20B 'radar'
    time_coverage_start  <U20 80B '2013-11-25T10:55:04Z'
    time_coverage_end    <U20 80B '2013-11-25T10:59:24Z'
    longitude            float64 8B -75.28
    altitude             float64 8B 143.0
    latitude             float64 8B 9.331
Attributes:
    Conventions:      None
    instrument_name:  None
    version:          None
    title:            None
    institution:      None
    references:       None
    source:           None
    history:          None
    comment:          im/exported using xradar
[11]:
dtree = xd.io.open_iris_datatree(filename_volume, sweep="sweep_8")
display(dtree)
<xarray.DatasetView> Size: 232B
Dimensions:              ()
Data variables:
    volume_number        int64 8B 0
    platform_type        <U5 20B 'fixed'
    instrument_type      <U5 20B 'radar'
    time_coverage_start  <U20 80B '2013-11-25T10:58:33Z'
    time_coverage_end    <U20 80B '2013-11-25T10:58:57Z'
    longitude            float64 8B -75.28
    altitude             float64 8B 143.0
    latitude             float64 8B 9.331
Attributes:
    Conventions:      None
    instrument_name:  None
    version:          None
    title:            None
    institution:      None
    references:       None
    source:           None
    history:          None
    comment:          im/exported using xradar
[12]:
dtree = xd.io.open_iris_datatree(filename_volume, sweep=[1, 2, 8])
display(dtree)
<xarray.DatasetView> Size: 232B
Dimensions:              ()
Data variables:
    volume_number        int64 8B 0
    platform_type        <U5 20B 'fixed'
    instrument_type      <U5 20B 'radar'
    time_coverage_start  <U20 80B '2013-11-25T10:55:30Z'
    time_coverage_end    <U20 80B '2013-11-25T10:58:57Z'
    longitude            float64 8B -75.28
    altitude             float64 8B 143.0
    latitude             float64 8B 9.331
Attributes:
    Conventions:      None
    instrument_name:  None
    version:          None
    title:            None
    institution:      None
    references:       None
    source:           None
    history:          None
    comment:          im/exported using xradar
[13]:
dtree = xd.io.open_iris_datatree(
    filename_volume,
    sweep=["sweep_0", "sweep_1", "sweep_8"],
)
display(dtree)
<xarray.DatasetView> Size: 232B
Dimensions:              ()
Data variables:
    volume_number        int64 8B 0
    platform_type        <U5 20B 'fixed'
    instrument_type      <U5 20B 'radar'
    time_coverage_start  <U20 80B '2013-11-25T10:55:04Z'
    time_coverage_end    <U20 80B '2013-11-25T10:58:57Z'
    longitude            float64 8B -75.28
    altitude             float64 8B 143.0
    latitude             float64 8B 9.331
Attributes:
    Conventions:      None
    instrument_name:  None
    version:          None
    title:            None
    institution:      None
    references:       None
    source:           None
    history:          None
    comment:          im/exported using xradar

Plot Time vs. Azimuth#

[14]:
dtree["sweep_0"].ds.azimuth.plot(y="time")
[14]:
[<matplotlib.lines.Line2D at 0x7ff81aa59d90>]
../_images/notebooks_Iris_22_1.png

Plot Sweep Range vs. Time#

We need to sort by time and specify the y-coordinate. Please also observe the different resolutions of this plot, compared to the Azimuth vs. Range plot below. This is due to second-resolution of the time coordinate.

[15]:
dtree["sweep_0"].ds.DBZH.sortby("time").plot(y="time")
[15]:
<matplotlib.collections.QuadMesh at 0x7ff81294fcd0>
../_images/notebooks_Iris_24_1.png

Plot Sweep Range vs. Azimuth#

[16]:
dtree["sweep_0"].ds.DBZH.plot()
[16]:
<matplotlib.collections.QuadMesh at 0x7ff812965210>
../_images/notebooks_Iris_26_1.png