Eddy Covariance Flux Processing Examples¶
Examples demonstrating flux processing, quality control, and gap-filling for averaged (e.g. 30-minute) eddy covariance data. Raw high-frequency (10/20 Hz) tooling lives in dyco.
Terminology¶
Directory abbreviations used throughout flux processing examples:
lowres/— Low-resolution (e.g., 30-minute) flux data processing. Typically averaged or aggregated time series.
Contents¶
Post-Processing Chain¶
postprocessingchain/postprocessingchain_level2.py — Level 2 in isolation: load a real EddyPro FLUXNET output file,
init_flux_data, thenrun_level2to expand the EddyPro quality diagnostics into per-test flags and one overall QCF. Showslevel2_test_inputs(which column each test reads), the QCF-filtered vs. high-quality (QCF=0) series, and the effect of the accept threshold. The smallest standalone entry point into the chain.postprocessingchain/postprocessingchain_runchain.py — Single-call
run_chain(data, FluxConfig)example. Minimal config drives the full L2→L4.2 pipeline with sensible defaults. The easy path; use this when you want the chain to “just work”.postprocessingchain/postprocessingchain_composable.py — Full L2→L4.2 pipeline using composable callables; RF, XGBoost, and MDS gap-filling from the same L3.3 state; on-demand
gap_stats()after L3.3;plot_gapfilled_heatmaps()(side-by-side heatmap comparison) andplot_cumulative_comparison()(all methods on one axes) after L4.1; then all fourrun_level42_*partitioning callables (run_level42_partitioningselects one by method and mode). The full-control path — every detector class, model hyperparameter, MDS tolerance, and diagnostic flag is reachable here.postprocessingchain/postprocessingchain_partitioning.py — Level 4.2 on the
run_chainpath: all four partitioning ports enabled through thepartition_*flags ofFluxConfig(partition_method/partition_modeselect one instead). Shows which driver columns each port reads,partition_gapfill_method(which L4.1 gap-filled NEE feeds the nighttime variants), and how the per-USTAR-scenario output columns are named (RECO_NT_OF_CUT_50).
NEE Partitioning (Level 4.2)¶
partitioning/partitioning_nighttime_oneflux.py — Nighttime method (Reichstein et al. 2005), ONEFlux port →
*_NT_OF. Fits a Lloyd & Taylor temperature response to nighttime NEE, extrapolates to daytime for RECO, thenGPP = RECO - NEE.partitioning/partitioning_nighttime_reddyproc.py — Nighttime method (Reichstein et al. 2005), REddyProc
sMRFluxPartitionport →*_NT_RP. A second, independent port of the same paper: differs in the day/night split (potential radiation, needs longitude + UTC offset), the E0 fitting, and it partitions the whole record with a single E0.partitioning/partitioning_daytime_reddyproc.py — Daytime method (Lasslop et al. 2010), REddyProc
partitionNEEGLport →*_DT_RP. Fits a rectangular-hyperbola light-response curve to daytime NEE in short windows, with E0 held fixed from a nighttime estimate.partitioning/partitioning_daytime_oneflux.py — Daytime method (Lasslop et al. 2010), ONEFlux
flux_part_gl2010/ FLUXNET2015 port →*_DT_OF. Uses both measured and gap-filled drivers; the day/night split is measuredRg > 4, with no solar geometry or latitude.partitioning/partitioning_comparison.py — All four ports on the same input, compared against each other and against the bundled REddyProc reference columns. Best for choosing a method, or seeing how much the choice matters.
dv.flux.PartitioningNEE(method=..., mode=...) runs any of the four ports: method='nighttime' or 'daytime', mode='oneflux' (default) or 'reddyproc'.
Low-Resolution Flux Processing¶
lowres/flux_timelag_analysis.py — Time lag detection and visualization for gas concentrations
lowres/flux_common.py — Flux variable base detection and nomenclature
lowres/flux_hqflux.py — Highest-quality flux filtering with Hampel outlier detection
lowres/flux_selfheating.py — SCOP self-heating correction (quick demo)
lowres/flux_selfheating_production.py — Complete production workflow: scaling factors from parallel measurements, applied to long-term data
lowres/flux_uncertainty.py — Random uncertainty estimation (PAS20 method)
lowres/flux_ustar_mp_detection.py — Moving Point (MP) USTAR detection (Papale et al. 2006) with multi-year bootstrap
lowres/flux_ustar_vekuri_detection.py — Quantile-based USTAR detection (Vekuri method) with multi-year bootstrap
lowres/flux_ustar_method_comparison.py — Side-by-side comparison of ONEFlux and Vekuri USTAR approaches
Use Cases¶
Process eddy covariance flux data — single-call driver:
from diive.flux.postprocessingchain import (
FluxConfig, init_flux_data, run_chain,
)
cfg = FluxConfig(
fluxcol='FC',
ustar_thresholds=[0.18], ustar_labels=['CUT_50'],
outlier_sigma_daytime=5.5, outlier_sigma_nighttime=5.5,
gapfilling_features=['TA_1_1_1', 'SW_IN_1_1_1', 'VPD_kPa_1_1_1'],
level2_test_settings={'ssitc': {'apply': True, 'setflag_timeperiod': None}},
mds_swin='SW_IN_1_1_1', mds_ta='TA_1_1_1', mds_vpd='VPD_kPa_1_1_1',
)
data = init_flux_data(df, fluxcol='FC', site_lat=47.48, site_lon=8.36, utc_offset=1)
data = run_chain(data, cfg)
results = data.fpc_df # all per-level and gap-filled columns
cols = data.gapfilled_cols() # {'mds': {'CUT_50': '...'}, 'rf': {...}}, 'xgb' with gapfill_xgb=True
Composable per-level API — for custom L3.2 outlier pipelines, custom feature engineering, or per-level inspection, call each run_level* directly. See examples/flux/postprocessingchain/postprocessingchain_composable.py.
Analyze time lag and measurement quality:
import diive as dv
# Detect optimal time lags for gas concentrations
analysis = dv.flux.TimeLagAnalysis(
df=df,
ignore_fringe_bins=[5, 10],
lag_window_min=0.10,
lag_window_max=1.00
)
co2_results = analysis.analyze_gas('CO2')
fig = analysis.plot_gas('CO2', outdir='output/')
# Quantify measurement uncertainty (VPD in kPa; pass vpd_in_kpa=False for hPa)
randunc = dv.flux.RandomUncertaintyPAS20(
df=df,
fluxcol='NEE_CUT_REF_orig', # measured flux
fluxgapfilledcol='NEE_CUT_REF_f', # gap-filled flux
tacol='Tair_f',
vpdcol='VPD_f',
vpd_in_kpa=False, # VPD_f is in hPa in the example data
swincol='Rg_f',
)
randunc.run()
uncertainty = randunc.randunc_series
Running Examples¶
# Complete multi-level processing workflow (recommended starting point)
uv run python examples/flux/postprocessingchain/postprocessingchain_composable.py
# NEE partitioning (Level 4.2)
uv run python examples/flux/postprocessingchain/postprocessingchain_partitioning.py
uv run python examples/flux/partitioning/partitioning_nighttime_oneflux.py
uv run python examples/flux/partitioning/partitioning_nighttime_reddyproc.py
uv run python examples/flux/partitioning/partitioning_daytime_reddyproc.py
uv run python examples/flux/partitioning/partitioning_daytime_oneflux.py
uv run python examples/flux/partitioning/partitioning_comparison.py
# Low-resolution (30-min) processing
uv run python examples/flux/lowres/flux_timelag_analysis.py
uv run python examples/flux/lowres/flux_selfheating.py
uv run python examples/flux/lowres/flux_uncertainty.py
uv run python examples/flux/lowres/flux_ustar_mp_detection.py
uv run python examples/flux/lowres/flux_ustar_vekuri_detection.py
uv run python examples/flux/lowres/flux_ustar_method_comparison.py
# Run all flux examples
uv run python examples/run_all_examples.py
Standards & Best Practices¶
Swiss FluxNet levels — Data flows through 6 levels (L2→L3.1→L3.2→L3.3→L4.1→L4.2). L4.2 (NEE→GPP+RECO partitioning) is optional
Swiss FluxNet methodology — Quality flags, storage correction, USTAR filtering
Units — MDS, partitioning and
RandomUncertaintyPAS20expect air temperature in °C, VPD in kPa (passvpd_in_kpa=Falsefor hPa) and radiation in W m-2. They do not check unitsQC/QF flags — Combine multiple quality tests into single QCF flag
Uncertainty propagation — Random + systematic uncertainty estimation
Low-Resolution Flux Processing Examples¶
Low-resolution (30-minute) eddy-covariance flux processing, mostly with data from the Swiss FluxNet site CH-LAE (some examples use CH-DAV or CH-CHA). Covers time lag detection, quality filtering, self-heating correction, uncertainty estimation, and turbulence thresholds.
Examples¶
Time Lag Detection¶
flux_timelag_analysis.py — Time lag detection and visualization for gas concentrations using covariance analysis
Base Flux Detection & Quality¶
flux_common.py — Detect flux variable nomenclature and base gas measurements
flux_hqflux.py — Extract highest-quality flux records using Hampel outlier filtering
Self-Heating Correction (SCOP)¶
flux_selfheating.py — Quick demonstration of SCOP workflow (5 USTAR classes, 5 bootstrap runs)
flux_selfheating_production.py — Complete production workflow: calibrate a scaling-factor table on one period with parallel measurements (20 classes, 20 bootstrap runs for the example; use 100 in production) and apply it to a held-back period with no reference
Measurement Uncertainty & Turbulence¶
flux_uncertainty.py — Random uncertainty estimation using the PAS20 method (Pastorello et al. 2020)
flux_ustar_mp_detection.py — Moving Point (MP) friction velocity detection for nighttime turbulence thresholds (Papale et al. 2006)
flux_ustar_vekuri_detection.py — Simplified quantile-based friction velocity detection (Vekuri method)
flux_ustar_method_comparison.py — Compare ONEFlux and Vekuri USTAR detection approaches
All three USTAR examples use UstarBootstrapThresholds as the multi-year bootstrap wrapper. It runs N iterations per calendar year using a 3-year sliding window, then returns VUT (variable, per-year p16/p50/p84 — get_vut_thresholds() / run()) and CUT (constant, pooled across all years — get_cut_threshold()) thresholds, following the FLUXNET/ONEFlux convention. diive’s VUT is smoothed over the 3-year window (the year plus its two neighbours) for stability, which differs from the strict single-year ONEFlux VUT. The detection algorithm (moving point vs. quantile-based) is swapped via detector_class.
Running Examples¶
# Run one example
uv run python examples/flux/lowres/flux_timelag_analysis.py
# Run more low-res flux examples
uv run python examples/flux/lowres/flux_selfheating.py
uv run python examples/flux/lowres/flux_selfheating_production.py
uv run python examples/flux/lowres/flux_uncertainty.py
Key Concepts¶
Self-heating correction (SCOP method):
Sun-induced heating of open-path IRGA sensors creates spurious negative CO2 flux
Correction uses physics-based unscaled term (FCT_UNSC) scaled by factors from parallel measurements
Scaling factors binned by USTAR and time-of-day, reusable across seasons
Quality filtering:
Hampel filter for identifying robust flux estimates
USTAR-based selection for stable atmospheric conditions
Uncertainty: Random measurement uncertainty following the PAS20 method (Pastorello et al. 2020)
Related Documentation¶
Flux Post-Processing Chain — Multi-level L2-L4.2 workflow
Source:
diive/flux/lowres/
Self-Heating Correction: Complete Production Workflow
NEE Partitioning Examples¶
Splitting net ecosystem exchange (NEE) into gross primary production (GPP) and ecosystem
respiration (RECO). Four faithful ports of the standard reference routines: two nighttime
(Reichstein et al. 2005) and two daytime (Lasslop et al. 2010), one of each from ONEFlux (_OF)
and from REddyProc (_RP).
5 examples, one per method plus a comparison.
Contents¶
partitioning_nighttime_oneflux.py — ONEFlux nighttime, per calendar year, output tagged
*_NT_OF.partitioning_nighttime_reddyproc.py — REddyProc nighttime, one temperature sensitivity for the whole record, output tagged
*_NT_RP.partitioning_daytime_reddyproc.py — REddyProc daytime light-response curves,
*_DT_RP.partitioning_daytime_oneflux.py — ONEFlux daytime,
*_DT_OF.partitioning_comparison.py — all four on the same data, side by side.
Because each method tags its output columns differently, all four can be kept in one dataframe and compared directly.
One entry point¶
dv.flux.PartitioningNEE (or the function dv.flux.partition_nee) runs any of the four ports.
method picks 'nighttime' or 'daytime', mode picks 'oneflux' (default, the ICOS
and FLUXNET2015 approach) or 'reddyproc'. The results are those of the matching class:
import diive as dv
part = dv.flux.PartitioningNEE(
nee=df['NEE_CUT_REF_orig'], method='nighttime', mode='oneflux',
ta=df['Tair_orig'], sw_in=df['Rg_orig'], nee_f=df['NEE_CUT_REF_f'],
ta_f=df['Tair_f'], lat=46.815,
).run()
part.reco, part.gpp # RECO_NT_OF, GPP_NT_OF
In the post-processing chain the same switches are FluxConfig(partition_method=...,
partition_mode=...) and run_level42_partitioning(data, method=..., mode=...).
Units¶
Inputs are in physical units: air temperature in °C, VPD in kPa, radiation in W m-2. The ports state the units they expect in their docstrings and do not validate them, so passing hPa where kPa is expected produces a plausible-looking wrong answer.
Running Examples¶
uv run python examples/flux/partitioning/partitioning_comparison.py
uv run python examples/run_all_examples.py
Flux Post-Processing Chain Examples¶
Post-processing of Level-1 eddy covariance fluxes through the Swiss FluxNet levels: quality flag expansion (L2), storage correction (L3.1), outlier removal (L3.2), u* filtering (L3.3), gap-filling (L4.1) and NEE partitioning (L4.2).
4 examples covering both entry points into the chain.
Contents¶
postprocessingchain_composable.py — the composable per-level API: one function per level, each taking the
FluxLevelDatacontainer and returning a new one. Full control over every detector and model setting, and the path to branch several gap-filling methods from the same filtered state.postprocessingchain_runchain.py — the single-call driver: one
FluxConfig, onerun_chain. Fixed sensible defaults, much less to write.postprocessingchain_level2.py — Level 2 on its own, showing the per-test flag settings.
postprocessingchain_partitioning.py — Level 4.2, splitting NEE into GPP and RECO with all four partitioning variants.
partition_methodandpartition_modeselect a single one.
Which entry point?¶
run_chain when the standard pipeline is what you want. The composable functions when you need to
override anything FluxConfig does not expose — a specific outlier detector, model
hyperparameters, or a custom sequence of Level-3.2 tests.
Running Examples¶
uv run python examples/flux/postprocessingchain/postprocessingchain_composable.py
uv run python examples/run_all_examples.py
Flux Post-Processing Chain - Level 2 (Quality Flags)
Flux Post-Processing Chain - NEE Partitioning (Level 4.2)
Flux Post-Processing Chain - Single-Call run_chain