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

# CIMH

## Instrumentation: Micro Rain Radar

The suite of micro-rain radar measurements available to the TCO group includes an MRR operated by the [Caribbean Institute for Meteorology and Hydrology](https://coconet.cimh.edu.bb/) (CIMH) on Barbados.

The CIMH is located at $13^{\circ}	9' \mathrm{N}, \, 59^{\circ} 37' \mathrm{W}$ and its altitude is $112 \, \mathrm{m}$ as per their [site](https://www.cimh.edu.bb/lib/inc/content/datainv.inc.php).

The [MRRs](https://metek.de/product/mrr-2/) are upward looking $24 \, \mathrm{GHz}$ micro-rain radars which detect fall velocity and rain rate of hydrometeors.

All data have a temporal resolution of $1 \, \mathrm{min}$, and the height ranges sampled are documented below. The MRRs resolve the height dimension with 31 distinct levels.

## Data Availability

Datasets are available in `.zarr` format in the catalog.
The three height range configurations for the MRR are as follows, and datasets are named according to these conventions:
 - 1: [100, 3100]
 - 2: [200, 6200]
 - 3: [35, 1085]

```{note}
There are very few days with configuration 3, so we currently do not provide this data in the catalog, although the package is capable of reading data with this height range.
```

The table below summarizes the available MRR Level 1 datasets:

| Site | Key | Start | Stop | Range |
| -------- | -------- | -------- | -------- | -------- |
| BCO | `BCO.mrr_c1` | 2015-01-16 | present | [100, 3100] |
| CIMH | `CIMH.mrr_c1` | 2009-12-19 | 2025-06-29 | [100, 3100] |
| EMBRAPA | `EMBRAPA.mrr_c2` | 2012-06-08 | 2016-02-29 | [200, 6400] |

## Sample Plots

Here we plot rain rate alongside MDQ (data quality of spectra in percent of spectra per time) for a day during the [EUREC4A](https://eurec4a.eu/) campaign.

```{code-cell} python
:tags: [hide-cell]
import intake
import numpy as np
import matplotlib.pyplot as plt
import xarray as xr
import matplotlib.colors as mcolors
import matplotlib.dates as mdates

def plot_rr_with_mdq(ds):
    """Plot rain rate alongside MDQ (spectrum data quality percent)."""
    time = ds.time.values
    height = ds.range.values
    RR = ds.RR.values
    MDQ = ds.MDQ.values
    title = ds.title

    fig = plt.figure(figsize=(12, 6), constrained_layout=True)
    gs = fig.add_gridspec(
        2, 2, 
        width_ratios=[20, 1], 
        height_ratios=[12, 1], 
        hspace=0.05, wspace=0.05
    )

    ax_main = fig.add_subplot(gs[0, 0])
    ax_mdq  = fig.add_subplot(gs[1, 0], sharex=ax_main)
    cax_rr  = fig.add_subplot(gs[0, 1])
    cax_mdq = fig.add_subplot(gs[1, 1])

    mesh = ax_main.pcolormesh(time, height, RR.T, shading="auto", cmap="PuBu")
    cbar = fig.colorbar(mesh, cax=cax_rr)
    cbar.set_label("rain rate (mm h-1)")

    ax_main.set_ylabel("height above sensor (m)")
    ax_main.set_title(f"{title} - rain rate")

    cmap = mcolors.LinearSegmentedColormap.from_list(
        "quality", ["red", "yellow", "green"]
    )
    norm = mcolors.Normalize(vmin=0, vmax=100)

    ax_mdq.imshow(
        MDQ[np.newaxis, :],
        aspect="auto",
        cmap=cmap,
        norm=norm,
        extent=[mdates.date2num(time[0]), mdates.date2num(time[-1]), 0, 1]
    )

    ax_mdq.set_yticks([])
    ax_mdq.set_xlabel("time")
    ax_mdq.xaxis.set_major_formatter(mdates.DateFormatter("%H:%M"))

    cbar_mdq = fig.colorbar(
        plt.cm.ScalarMappable(norm=norm, cmap=cmap),
        cax=cax_mdq
    )
    cbar_mdq.set_label("data qual (%)", loc="center")

    plt.show()
```

```{code-cell} python
# open catalog
cat = intake.open_catalog("https://tcodata.mpimet.mpg.de/catalog.yaml")

# select dataset
mrr = cat.CIMH.mrr_c1(version=1).to_dask()

# define subset
eurec4a = slice(np.datetime64("2020-01-24"), np.datetime64("2020-01-25"))

# plot
plot_rr_with_mdq(mrr.sel(time=eurec4a))
```

```{code-cell} python
# full dataset
mrr
```