Note
Go to the end to download the full example code.
Correct Relative Humidity Saturation¶
Fix relative humidity measurements that exceed 100% (physically impossible). The correction detects excess values, calculates daily mean offset, and caps the maximum at 100%.
Load and scale RH data¶
Real-world RH measurements sometimes exceed 100% due to sensor calibration drift or processing artifacts. We load example RH data and scale it to simulate this common issue.
import diive as dv
from diive.configs.exampledata import load_exampledata_parquet_meteo_rh_1MIN
df = load_exampledata_parquet_meteo_rh_1MIN()
series = df['RH_T1_47_1'].copy()
# Scale to simulate high RH values exceeding 100%
series = series.multiply(1.4)
print("Original RH data:")
print(f" Range: {series.min():.2f}% to {series.max():.2f}%")
print(f" Values exceeding 100%: {(series > 100).sum()}")
> Loaded .parquet file
/home/docs/checkouts/diive/checkouts/latest/diive/configs/exampledata/exampledat
a_PARQUET_CH-LAE_METEO_RH_1MIN.parquet (0.002 seconds).
Original RH data:
Range: 25.73% to 140.42%
Values exceeding 100%: 615
Apply RH offset correction¶
The correction takes the mean excess above 100% of each day as that day’s offset. Days without excess get the offset interpolated from the nearest days with excess, or carried from the first or last such day. The offset is subtracted from every record. Values still above 100% are then capped at 100%.
series_corr = dv.corrections.remove_relativehumidity_offset(series=series, showplot=True)
print("\nCorrected RH data:")
print(f" Range: {series_corr.min():.2f}% to {series_corr.max():.2f}%")
print(f" Values exceeding 100% after correction: {(series_corr > 100).sum()}")

Corrected RH data:
Range: 7.87% to 100.00%
Values exceeding 100% after correction: 0
Summary¶
The correction successfully removed the saturation issue while preserving the underlying signal structure. Daily variability and long-term patterns remain intact.
print(f"\nCorrection applied:")
print(f" Mean offset removed: {(series - series_corr).mean():.2f}%")
Correction applied:
Mean offset removed: 20.22%
Total running time of the script: (0 minutes 0.694 seconds)