Note
Go to the end to download the full example code.
Correct Radiation Zero Offset (Nighttime)¶
Fix solar radiation measurements with nighttime offset. Uses solar geometry to identify nighttime and corrects non-zero radiation readings during night. Nighttime values are set to zero after offset correction.
Load radiation data and define site location¶
Solar radiation should be zero at night. However, sensors sometimes show small non-zero values during nighttime due to calibration drift or electronic noise. We correct this using solar geometry.
import diive as dv
from diive.configs.exampledata import load_exampledata_parquet_meteo_swin_1MIN
df = load_exampledata_parquet_meteo_swin_1MIN()
series = df['SW_IN_T1_47_1'].copy()
# Site location (CH-LAE - Laegeren)
SITE_LAT = 47.478333
SITE_LON = 8.364389
UTC_OFFSET = 1
print("Original radiation data:")
print(f" Range: {series.min():.2f} to {series.max():.2f} W/m²")
> Loaded .parquet file
/home/docs/checkouts/diive/checkouts/latest/diive/configs/exampledata/exampledat
a_PARQUET_CH-LAE_METEO_SW_IN_1MIN.parquet (0.002 seconds).
Original radiation data:
Range: -7.79 to 955.55 W/m²
Apply radiation zero offset correction¶
The correction:
Calculates potential radiation for each record from the site location
Flags records with potential radiation below 0.001 W/m² as nighttime
Takes the mean of each day’s nighttime values as that day’s offset
Subtracts the offset, sets nighttime to zero and clamps remaining negative values to zero
series_corr = dv.corrections.remove_nighttime_zero_offset(
series=series,
lat=SITE_LAT,
lon=SITE_LON,
utc_offset=UTC_OFFSET,
showplot=True
)
print("\nCorrected radiation data:")
print(f" Range: {series_corr.min():.2f} to {series_corr.max():.2f} W/m²")

Corrected radiation data:
Range: 0.00 to 956.14 W/m²
Verify nighttime correction¶
Check that radiation is properly zeroed at night after correction.
nighttime_mean_orig = series[series.index.hour < 6].mean()
nighttime_mean_corr = series_corr[series_corr.index.hour < 6].mean()
print(f"\nNighttime (00:00-06:00) radiation:")
print(f" Original: {nighttime_mean_orig:.3f} W/m²")
print(f" Corrected: {nighttime_mean_corr:.3f} W/m²")
print(f" Offset removed: {(nighttime_mean_orig - nighttime_mean_corr):.3f} W/m²")
Nighttime (00:00-06:00) radiation:
Original: 0.579 W/m²
Corrected: 1.825 W/m²
Offset removed: -1.246 W/m²
Total running time of the script: (0 minutes 0.678 seconds)