---
jupytext:
  formats: md:myst
  text_representation:
    extension: .md
    format_name: myst
kernelspec:
  name: python3
  display_name: Python 3
---

```{include} ../../../_includes/license_block.md
```
# xarray IRIS backend

In this example, we read IRIS (sigmet) data files using the xradar `iris` xarray backend.

```{code-cell} python
import glob
import gzip
import io
import wradlib as wrl
import wradlib_data
import warnings
from IPython.display import display

import matplotlib.pyplot as plt
import numpy as np
import xradar as xd
import xarray as xr

warnings.filterwarnings("ignore")

```

## Load IRIS Volume Data

```{code-cell} python
fpath = "sigmet/SUR210819000227.RAWKPJV"
f = wradlib_data.DATASETS.fetch(fpath)
vol = xd.io.open_iris_datatree(f, reindex_angle=False)
```

## Inspect RadarVolume

```{code-cell} python
display(vol)
```

## Inspect root group

The `sweep` dimension contains the number of scans in this radar volume. Further the dataset consists of variables (location coordinates, time_coverage) and attributes (Conventions, metadata).

```{code-cell} python
vol.root
```

## Inspect sweep group(s)

The sweep-groups can be accessed via their respective keys. The dimensions consist of `range` and `time` with added coordinates `azimuth`, `elevation`, `range` and `time`. There will be variables like radar moments (DBZH etc.) and sweep-dependent metadata (like `fixed_angle`, `sweep_mode` etc.).

```{code-cell} python
display(vol["sweep_0"])
```

## Georeferencing

```{code-cell} python
swp = vol["sweep_0"].to_dataset(inherit="all_coords")
swp = swp.assign_coords(sweep_mode=swp.sweep_mode)
swp = swp.wrl.georef.georeference()
```

## Inspect radar moments

The DataArrays can be accessed by key or by attribute. Each DataArray has dimensions and coordinates of it's parent dataset.

```{code-cell} python
display(swp.DBZH)
```

## Create simple plot

Using xarray features a simple plot can be created like this. Note the `sortby('time')` method, which sorts the radials by time.

For more details on plotting radar data see under [Visualization](../../visualisation/plotting).

```{code-cell} python
swp.DBZH.sortby("time").plot(x="range", y="time", add_labels=False)
```

```{code-cell} python
fig = plt.figure(figsize=(5, 5))
pm = swp.DBZH.wrl.vis.plot(crs={"latmin": 3e3}, fig=fig)
```

## Retrieve explicit group

```{code-cell} python
swp_b = xr.open_dataset(
    f, engine="iris", group="sweep_0", backend_kwargs=dict(reindex_angle=False)
)
display(swp_b)
```
