3. 2015 MelCol¶
processed with pyrnet-0.2.16
The PyrNet was setup for calibration in a dense array on the Melpitz measurement field from 2015-05-06 to 2015-05-11. Cross-calibration is done versus reference observations from the TROPOS MObile RaDiation ObseRvatory (MORDOR) station.
3.1. Imports¶
#|dropcode
import os
import xarray as xr
import pandas as pd
import numpy as np
import datetime as dt
import matplotlib.pyplot as plt
import jstyleson as json
from pyrnet import pyrnet
3.2. Prepare PyrNet data¶
For calibration preparation the PyrNet data is processed to level l1b using a calibration factor of 7 (uV W-1 m2) for all pyranometers with the pyrnet process l1b tool. This is done to unify the conversion to sensor voltage during calibration and not run into valid_range limits for netcdf encoding. Here we generate the calibration.json file for the processing to l1b:
box_numbers = np.arange(1,101)
calibrations = {f"{bn:03d}":[7,7] for bn in box_numbers}
calibjson = {"2000-01-01": calibrations}
with open("pyrnet_calib_prep.json","w") as txt:
json.dump(calibjson, txt)
Within pyrnet_config.json:
{"file_calibration" : "pyrnet_calib_prep.json"}
Workflow for preparation
Prepare pyrnet_config_calibration_prep.json with contributors metadata and the dummy calibration config file.
$ pyrnet process l1a -c pyrnet_config.json raw_data/*.bin l1a/$ pyrnet process l1b_network -c pyrnet_config.json l1a/*.nc l1b_network/
3.3. Configuration¶
Set local data paths and lookup metadata.
pf_mordor = "mordor/{date:%Y-%m-%d}_Radiation.dat"
pf_pyrnet = "l1b_network/{date:%Y-%m-%d}_P1D_pyrnet_melcol_n000l1bf1s.c01.nc"
dates = pd.date_range("2015-05-06","2015-05-11")
stations = np.arange(1,101)
# lookup which box contains actually a pyranometer/ extra pyranometer
mainmask = []
for box in stations:
_, serials, _, _ = pyrnet.meta_lookup(dates[0],box=box)
mainmask.append( True if len(serials[0])>0 else False )
3.3.1. Load reference MORDOR data¶
#|dropcode
#|dropout
for i,date in enumerate(dates):
fname = pf_mordor.format(date=date)
df = pd.read_csv(
fname,
header=0,
skiprows=[0,2,3],
date_format="ISO8601",
parse_dates=[0],
index_col=0
)
dst = df.to_xarray().rename({"TIMESTAMP":"time"})
# drop not needed variables
keep_vars = ['TP2_Wm2'] # global shortwave irradiance
drop_vars = [v for v in dst if v not in keep_vars]
dst = dst.drop_vars(drop_vars)
# merge
if i == 0:
ds = dst.copy()
else:
ds = xr.concat((ds,dst),dim='time', data_vars='minimal', coords='minimal', compat='override')
mordor = ds.copy()
mordor = mordor.drop_duplicates("time", keep="last")
mordor
<xarray.Dataset> Dimensions: (time: 5183535) Coordinates:
time (time) datetime64[ns] 2015-05-06 … 2015-05-11T23:59:59.900000 Data variables: TP2_Wm2 (time) float64 0.0 0.0 0.0 0.0 0.0 0.0 … 0.0 0.0 0.0 0.0 0.0 0.0
3.3.2. Load PyrNet Data¶
#|dropcode
#|dropout
for i,date in enumerate(dates):
# read from thredds server
dst = xr.open_dataset(pf_pyrnet.format(date=date))
# drop not needed variables
keep_vars = ['ghi','szen']
drop_vars = [v for v in dst if v not in keep_vars]
dst = dst.drop_vars(drop_vars)
# unify time and station dimension to speed up merging
date = dst.time.values[0].astype("datetime64[D]")
timeidx = pd.date_range(date, date + np.timedelta64(1, 'D'), freq='1s', inclusive='left')
dst = dst.interp(time=timeidx)
dst = dst.reindex({"station": stations})
# merge
if i == 0:
ds = dst.copy()
else:
ds = xr.concat((ds,dst),dim='time', data_vars='minimal', coords='minimal', compat='override')
pyr = ds.copy()
pyr
<xarray.Dataset> Dimensions: (station: 100, maintenancetime: 50, time: 518400) Coordinates:
station (station) int64 1 2 3 4 5 6 7 8 … 94 95 96 97 98 99 100
maintenancetime (maintenancetime) datetime64[ns] 2015-05-12T07:55:50 ……
time (time) datetime64[ns] 2015-05-06 … 2015-05-11T23:59:59 Data variables: ghi (time, station) float64 0.0 nan nan 0.0 … nan 0.0 0.0 nan szen (time, station) float64 111.0 nan nan … 109.4 109.4 nan Attributes: (12/31) Conventions: CF-1.10, ACDD-1.3 title: TROPOS pyranometer network (PyrNet) observatio… history: 2024-11-04T23:59:36: Merged level l1b by pyrne… institution: Leibniz Institute for Tropospheric Research (T… source: TROPOS pyranometer network (PyrNet) references: https://doi.org/10.5194/amt-9-1153-2016 … … geospatial_lon_units: degE time_coverage_start: 2015-05-06T00:00:00 time_coverage_end: 2015-05-06T23:59:59 time_coverage_duration: P0DT23H59M59S time_coverage_resolution: P0DT0H0M1S site: [‘’, ‘’, ‘’, ‘’, ‘’, ‘’, ‘’, ‘’, ‘’, ‘’, ‘’, ‘…
3.4. Calibration¶
The calibration follows the ISO 9847:1992 - Solar energy — Calibration of field pyranometers by comparison to a reference pyranometer.
TODO: Revise versus 2023 EU version.
Cloudy sky treatment is applied.
3.4.1. Step 1¶
Drop Night measures and low signal measures from pyranometer data. Since calibration without incoming radiation doesnt work.
This data is kept for calibration:
solar zenith angle < 80° ( as recommended in ISO 9847)
Measured Voltage > 0.033 V, e.g. ADC count is 0 or 1 of 1023 (drop the lowest ~1%)
Voltage measured ($V_m$) at the logger is the amplified Senor voltage ($V_S$) by a gain of 300.
$ V_m = 300 V_S$
As the uncalibrated flux measurements ($F_U$) are calibrated with a fixed factor of 7 uV W-1 m2:
$ V_s = 71e-6 F_U $
# Set flux values to nan if no pyranometer is installed.
pyr.ghi.values = pyr.ghi.where(mainmask).values
# convert to measured voltage
pyr.ghi.values = pyr.ghi.values * 7 * 1e-6
# Step 1, select data
pyr = pyr.where(pyr.szen<80, drop=True)
pyr.ghi.values = pyr.ghi.where(pyr.ghi>0.033/300.).values
3.4.2. Step 2¶
Interpolate reference to PyrNet samples and combine to a single Dataset
# interpolate reference to PyrNet
mordor = mordor.interp(time=pyr.time)
# Calibration datasets for main and extra pyranometer
Cds_main = xr.Dataset(
data_vars={
'reference_Wm2': ('time', mordor['TP2_Wm2'].data),
'pyrnet_V': (('time','station'), pyr['ghi'].data)
},
coords= {
"time": pyr.time,
"station": pyr.station
}
)
3.4.3. Step 3¶
Remove outliers from series using xarray grouping and apply function. The following functions removes outliers (deviation more than 2% according to ISO 9847) from a selected group. This step involves calculating calibration series and the integration of one hour intervals to smooth out high variable situation, which would break the calibration even when time synchronization is slightly off. Also this gets rid of some random shading events like birds / chimney / rods in line of sigth, which would affect calibration otherwise. We following ISO 9847 5.4.1.1 equation (2) here.
def remove_outliers(x):
"""
x is an xarray dataset containing these variables:
coords: 'time' - datetime64
'pyrnet_V' - array - voltage measures of pyranometer
'reference_Wm2' - array - measured irradiance of reference
"""
# calculate calibration series for single samples
C = x['pyrnet_V'] / x['reference_Wm2']
# integrated series
ix = x.integrate('time')
M = ix['pyrnet_V'] / ix['reference_Wm2']
while np.any(np.abs(C-M) > 0.02*M):
#calculate as long there are outliers deviating more than 2 percent
x = x.where(np.abs(C-M) < 0.02*M)
C = x['pyrnet_V'] / x['reference_Wm2']
#integrated series
ix = x.integrate('time')
M = ix['pyrnet_V'] / ix['reference_Wm2']
#return the reduced dataset x
return x
# remove outliers
Cds_main = Cds_main.groupby('time.hour').apply(remove_outliers)
# hourly mean
Cds_main = Cds_main.coarsen(time=60*60,boundary='trim').mean(skipna=True)
3.4.4. Step 4¶
The series of measured voltage and irradiance is now without outliers. So we use equation 1 again to calculate from this reduced series the calibration factor for the instant samples.
C_main = 1e6*Cds_main['pyrnet_V'] / Cds_main['reference_Wm2']
3.4.5. Step 5¶
We just found the Calibration factor to be the mean of the reduced calibration factor series and the uncertainty to be the standard deviation of this reduced series. Steo 3, 4 and 5 are done for every pyranometer seperate.
C_main_mean = C_main.mean(dim='time',skipna=True)
C_main_std = C_main.std(dim='time',skipna=True)
3.5. Results¶
#|dropcode
fig, ax = plt.subplots(1,1, figsize=(10,5))
ax.set_title("Main Pyranometer")
ax.plot(C_main.time, C_main, ls ="", marker='.')
ax.set_xlabel("Date")
ax.set_ylabel("Calibration factor (uV / Wm-2)")
ax.grid(True)
fig.show()
plt.figure()
fig, ax = plt.subplots(1,1, figsize=(10,5))
ax.set_title("Main Pyranometer")
ax.plot(pyr.szen.interp_like(C_main), C_main, ls ="", marker='.')
ax.set_xlabel("solar zenith angle (deg)")
ax.set_ylabel("Calibration factor (uV / Wm-2)")
ax.grid(True)
fig.show()

<Figure size 640x480 with 0 Axes>

calibration_new = {}
print(f"Box: Main , Extra ")
for box in C_main_mean.station:
Cm = float(C_main_mean.sel(station=box).values)
Um = float(C_main_std.sel(station=box).values)
calibration_new.update({
f"{box:03d}": [np.round(Cm,2), None]
})
print(f"{box:3d}: {Cm:.2f} +- {Um:.3f} , {None}")
calibjson = {"2015-05-06": calibration_new}
with open("pyrnet_calib_new.json","w") as txt:
json.dump(calibjson, txt)
Box: Main , Extra
1: 7.44 +- 0.204 , None
4: 7.41 +- 0.210 , None
5: 7.40 +- 0.182 , None
6: 6.54 +- 0.088 , None
15: 7.34 +- 0.181 , None
16: 7.59 +- 0.190 , None
19: 7.46 +- 0.262 , None
21: 7.40 +- 0.200 , None
22: 7.40 +- 0.205 , None
26: 7.49 +- 0.150 , None
28: 7.47 +- 0.244 , None
29: 7.25 +- 0.165 , None
30: 7.55 +- 0.176 , None
34: 6.93 +- 0.162 , None
35: 7.43 +- 0.182 , None
37: 7.52 +- 0.148 , None
40: 7.37 +- 0.199 , None
42: 7.53 +- 0.213 , None
43: 7.26 +- 0.170 , None
46: 7.65 +- 0.179 , None
49: 7.63 +- 0.241 , None
50: 7.59 +- 0.176 , None
51: 7.35 +- 0.087 , None
53: 7.36 +- 0.256 , None
54: 7.35 +- 0.197 , None
55: 7.18 +- 0.153 , None
57: 6.63 +- 0.170 , None
62: 7.24 +- 0.167 , None
63: 7.38 +- 0.118 , None
64: 7.19 +- 0.111 , None
68: 6.68 +- 0.082 , None
71: 7.32 +- 0.186 , None
72: 7.26 +- 0.184 , None
74: 7.41 +- 0.096 , None
75: 6.52 +- 0.194 , None
77: 7.36 +- 0.089 , None
78: 6.63 +- 0.154 , None
80: 6.85 +- 0.102 , None
81: 7.34 +- 0.088 , None
84: 7.07 +- 0.198 , None
87: 7.26 +- 0.136 , None
88: 6.91 +- 0.102 , None
89: 7.31 +- 0.132 , None
90: 7.17 +- 0.152 , None
91: 7.37 +- 0.182 , None
92: 7.17 +- 0.169 , None
94: 6.57 +- 0.136 , None
95: 7.32 +- 0.203 , None
96: 7.39 +- 0.149 , None
98: 7.20 +- 0.210 , None
99: 7.34 +- 0.126 , None