Note
Go to the end to download the full example code.
USTAR Vekuri Threshold Detection¶
Detect USTAR threshold using the quantile-based Vekuri approach.
Uses quantile binning for both temperature and USTAR classes, which gives equal sample sizes per bin regardless of the underlying distribution. A 3-year sliding window bootstrap returns per-year p16/p50/p84 thresholds and a CUT (constant) threshold pooled across all years.
Load example data¶
import diive as dv
data = dv.load_exampledata_parquet_lae()
print(f"Data: {len(data)} records, {data.index.min().date()} to {data.index.max().date()}")
> Loaded .parquet file
/home/docs/checkouts/diive/checkouts/latest/diive/configs/exampledata/exampledat
a_PARQUET_CH-LAE_FP2025.X_22_IRGA75+IRGA72_FPC_NEE-QCF11-L3.2_2016-2017.parquet
(0.006 seconds).
Data: 35088 records, 2016-01-01 to 2017-12-31
Detect thresholds¶
detect() returns seasonal thresholds; get_annual_thresholds() returns the conservative annual maximum across seasons.
detector = dv.flux.UstarVekuriThresholdDetection(data, verbose=1)
thresholds = detector.detect()
print("\n" + detector.summary())
annual = detector.get_annual_thresholds()
print(f"\nAnnual threshold (max across seasons): {annual['threshold']:.4f} m/s")
> Detecting USTAR thresholds (Vekuri quantile-based approach) | 35088 records,
4 seasons, 6 TA classes, 20 USTAR classes
> Season 1: months [12, 1, 2]
> Season 2: months [3, 4, 5]
> Season 3: months [6, 7, 8]
> Season 4: months [9, 10, 11]
> Annual threshold: 0.4521 m/s
USTAR Threshold Detection Results (Vekuri Quantile Method)
============================================================
Season Threshold (m/s)
------------------------------------------------------------
Season 1 0.1769
Season 2 0.2557
Season 3 0.4521
Season 4 0.4344
Annual threshold (max across seasons): 0.4521 m/s
Multi-year bootstrap uncertainty¶
UstarBootstrapThresholds runs N bootstrap iterations per calendar year, then extracts percentile thresholds from the resulting distribution. p50 is the recommended annual threshold; p16/p84 bound the uncertainty. get_cut_threshold() pools all years into a single CUT threshold.
boot = dv.flux.UstarBootstrapThresholds(
df=data,
detector_class=dv.flux.UstarVekuriThresholdDetection,
n_iter=20, # kept small for the example; use n_iter=100 in production
percentiles=(16, 50, 84),
n_jobs=-1,
verbose=1,
)
annual_boot = boot.run()
cut = boot.get_cut_threshold()
print("\n" + boot.summary())
> Bootstrap USTAR thresholds: UstarVekuriThresholdDetection, 20 iterations x 2
windows (sequential), percentiles:
> 2016 (35088 records)...
> p50=0.4145 m/s (20/20 ok)
> 2017 (35088 records)...
> p50=0.4135 m/s (20/20 ok)
> CUT (pooled): p16=0.2897 p50=0.4142 p84=0.4729
USTAR Bootstrap Threshold Results
======================================================================
Method : UstarVekuriThresholdDetection
Iterations : 20 per window (3-yr sliding window)
Percentiles: p16, p50, p84
VUT thresholds (variable, per-year; m/s) [p50 = recommended; 3-yr-window smoothed]
----------------------------------------------------------------------
Year Window p16 p50 p84
2016 2016/2017 0.2975 0.4145 0.4741 (20/20)
2017 2016/2017 0.2878 0.4135 0.4673 (20/20)
CUT threshold (constant, pooled across all years)
----------------------------------------------------------------------
CUT all years 0.2897 0.4142 0.4729
Annual per-year thresholds¶
The bootstrap DataFrame contains one row per year. p50 is the recommended threshold to use for USTAR filtering.
print("\nPer-year bootstrap thresholds (m/s):")
print(annual_boot.round(4))
Per-year bootstrap thresholds (m/s):
p16 p50 p84
year
2016 0.2975 0.4145 0.4741
2017 0.2878 0.4135 0.4673
CUT threshold¶
The CUT (constant) threshold pools all years’ bootstrap samples and returns a single threshold stable across the full record.
CUT (constant) threshold (m/s):
p16: 0.2897
p50: 0.4142 <-- recommended
p84: 0.4729
Seasonal thresholds overview¶
The raw detect() output shows thresholds for each season.
import pandas as pd
print("\nSeasonal thresholds from detect():")
print(thresholds.round(4))
print("\n[OK] Vekuri USTAR detection complete.")
Seasonal thresholds from detect():
threshold
Season 1 0.1769
Season 2 0.2557
Season 3 0.4521
Season 4 0.4344
[OK] Vekuri USTAR detection complete.
Total running time of the script: (0 minutes 5.740 seconds)