Note
Go to the end to download the full example code.
Moving Point (MP) USTAR Detection¶
Detect USTAR threshold using the Moving Point method (Papale et al., 2006).
Nighttime data is stratified by season, temperature class, and USTAR class. The threshold is where NEE stops increasing with rising USTAR (forward mode). A 3-year sliding window bootstrap returns per-year p16/p50/p84 thresholds and a CUT (constant) threshold pooled across all years.
import diive as dv
Load example data¶
df = dv.load_exampledata_parquet_lae()
print("=" * 70)
print("Moving Point (MP) USTAR Threshold Detection")
print("=" * 70)
print(f"\nData: {len(df)} records, {df.index.min().date()} to {df.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).
======================================================================
Moving Point (MP) USTAR Threshold Detection
======================================================================
Data: 35088 records, 2016-01-01 to 2017-12-31
Detect USTAR threshold¶
Initialize detector with DataFrame. Column names are auto-detected. detect() returns seasonal thresholds; get_annual_thresholds() returns the conservative annual maximum across seasons.
detector = dv.flux.UstarMovingPointDetection(
df=df,
nee_col=None, # NEE column; None = auto-detect (prefers NEE+QCF, then NEE)
ta_col=None, # Air temperature column; None = auto-detect (TA_*, then TA/TSYS/TAIR)
ustar_col=None, # USTAR column; None = auto-detect (*USTAR*, then U_STAR)
swin_col=None, # Shortwave-in column; None = auto-detect (*SW_IN*)
ta_classes_count=7, # Temperature stratification classes (ONEFlux default)
ustar_classes_count=20, # USTAR stratification classes per temperature class
forward_mode_n=2, # Forward-mode window size (Fw2); must be >= 1
season_groups=None, # Custom season month-groupings, e.g. [[12,1,2],[3,4,5],...]; None = default
bootstrapping_times=100, # Internal bootstrap iterations
verbose=1, # Verbosity level (0=silent)
)
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 (Papale et al., 2006) | 35088 records, 4 seasons,
7 TA classes, 20 USTAR classes
> Annual threshold (max across seasons): 0.5499 m/s
USTAR Threshold Detection Results (Papale et al., 2006)
============================================================
Season Threshold (m/s)
------------------------------------------------------------
Season 1 0.5198
Season 2 0.3259
Season 3 0.5499
Season 4 0.4964
Annual threshold (max across seasons): 0.5499 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=df,
detector_class=dv.flux.UstarMovingPointDetection,
detector_kwargs=dict(ta_classes_count=7, ustar_classes_count=20),
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: UstarMovingPointDetection, 20 iterations x 2
windows (sequential), percentiles:
> 2016 (35088 records)...
> p50=0.4996 m/s (20/20 ok)
> 2017 (35088 records)...
> p50=0.5757 m/s (20/20 ok)
> CUT (pooled): p16=0.4565 p50=0.5260 p84=0.6038
USTAR Bootstrap Threshold Results
======================================================================
Method : UstarMovingPointDetection
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.4570 0.4996 0.6045 (20/20)
2017 2016/2017 0.4570 0.5757 0.6006 (20/20)
CUT threshold (constant, pooled across all years)
----------------------------------------------------------------------
CUT all years 0.4565 0.5260 0.6038
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.457 0.4996 0.6045
2017 0.457 0.5757 0.6006
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.4565
p50: 0.5260 <-- recommended
p84: 0.6038
[OK] Moving Point USTAR detection complete.
Total running time of the script: (0 minutes 0.381 seconds)