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

# Radiation

## Instrumentation

The BCO is equipped with a solar and terrestrial radiation measurement station, comprised of 4 radiation sensors attached to a SOLYS2
sun tracker. The instruments were installed on 2015-03-30 (see note: the data in the catalog switches format on 2015-10-15).

![Radiation sensor](./radiation.png)

More specifically, the apparatus sits on the top of the BCO container, $4.5\,\mathrm{m}$ above the ground, or $21.5\,\mathrm{m}$ above mean sea level

The 4 sensors are as follows:

 - shaded pyranometer mounted on table of sun tracker for diffuse radiation ([CMP21 by Kipp and Zonen](https://www.kippzonen.com/Product/14/CMP21-Pyranometer)),
 - non-shaded pyranometer mounted on table of sun tracker for diffuse radiation ([CMP21 by Kipp and Zonen](https://www.kippzonen.com/Product/14/CMP21-Pyranometer)),
    > **pyranometers** measure solar irradiance from a hemispherical field of view
    > **diffuse radiation** is the portion of incoming shortwave (SW) radiation due to atmospheric scattering
 - shaded pyrgeometer mounted on table of sun tracker for longwave (LW) radiation ([CGR4 by Kipp and Zonen](https://www.kippzonen.com/Product/17/CGR4-Pyrgeometer))
 - pyrheliometer mounted on the side of the sun tracker ([CPH1 by Kipp and Zonen](https://www.kippzonen.com/Product/18/CHP1-Pyrheliometer)) points directly into the sun.


Two sets of 4 sensors are used and exchanged simultaneously approximately every two years.

- Set 1: CMP21 \#140337, CMP21 \#140356, CGR4 \#140034 (replaced by 220446), CHP1 \#140059 (replaced by 160388)
- Set 2: CMP21 \#160654, CMP21 \#160653, CGR4 \#150139, CHP1 \#160388

The calibration is done by the DWD in Lindenberg, and the solar irradiance ($\mathrm{W} \mathrm{m}^{-2}$), the raw voltages, the sensitivities, and the housing temperatures of each of the 4 sensors are available.

## Data Availability

```{note}
Until 2015-10-15, the data was recorded in 10-second intervals and only included the processed
radiation readings in $\mathrm{W} \mathrm{m}^{-2}$ along with the housing temperatures of the 4 sensors.
On 2015-10-15, the instruments began recording data with 1-second time resolution, and the data includes
the two aforementioned fields as well as the raw voltages and corresponding sensitivities recorded by each
of the 4 sensors. This recording configuration is still in use, and the data which is currently available
separates the two configurations into `c1` and `c2`. In the next iteration, or 'level' of processing,
these two independent datasets will be merged to provide easier access to a longer time series.
```

The data is available as `.zarr` files in the catalog as:
 - `BCO.radiation_c1` (2015-03-30 to 2015-10-14)
 - `BCO.radiation_c2` (2015-10-15 to present)

And in analysis-ready form as a level 2 product at `BCO.radiation_l2` (2015-03-30 to present).

## Sample Plot

```{code-cell} python
import intake
import matplotlib.pylab as plt
from pvlib import clearsky
from pvlib.location import Location
import pandas as pd
import xarray as xr

cat = intake.open_catalog("https://tcodata.mpimet.mpg.de/catalog.yaml")
ds_rad = cat.BCO.radiation_c2(version=1).to_dask()

# select a few days of interest
subset = ds_rad.sel(time=slice("2016-07-03", "2016-07-05"))

# get clear sky calculated radiation for reference
lat, lon, alt = float(subset.lat), float(subset.lon), float(subset.alt)
bco = Location(lat, lon, 'UTC', alt, name = 'bco')
times = pd.to_datetime(subset.coords['time'].values)
cs = bco.get_clearsky(times).to_xarray().rename({'index': 'time'})
ds_cs = xr.merge([subset, cs])

# plot observed SW vs calculated clear-sky
ds_cs.SWD_global.plot(label='SW from non-shaded pyranometer')
ds_cs.ghi.plot(label='Clear-sky')
plt.legend(loc='upper left')
plt.ylabel('Solar Irradiance [W/m²]')
plt.title('BCO SW radiation vs. clear-sky calculated')
```

The full dataset:

```{code-cell} python
ds_rad
```
