Optimum Range Detection

Find optimal driver variable ranges for optimized response.

Demonstrates finding the air temperature range where net ecosystem productivity (NEE) is optimized during daytime, with analysis of data distribution within, above, and below the optimum range.

Best for: Identifying operating conditions for ecosystem processes

Load data

import diive as dv

df_orig = dv.load_exampledata_parquet()

# Filter to daytime data (solar radiation > 20 W/m^2)
df = df_orig.copy()
df = df.loc[df['Rg_f'] > 20]
  > Loaded .parquet file
/home/docs/checkouts/diive/checkouts/latest/diive/configs/exampledata/exampledat
a_PARQUET_CH-DAV_FP2022.5_2013-2022_ID20230206154316_30MIN.parquet (0.051
seconds).

Find optimum temperature range

# Find optimum temperature range for maximum CO2 uptake (minimum NEE)
optrange = dv.analysis.FindOptimumRange(
    df=df,
    xcol='Tair_f',  # Driver variable (air temperature)
    ycol='NEE_CUT_REF_f',  # Response variable (net ecosystem productivity)
    n_bins=100,  # Number of quantile-based bins along x
    bins_agg='median',  # Aggregate y within each bin using median
    rwinsize=0.1,  # Rolling window = 10% of total bins
    ragg='mean',  # Smooth bin medians with rolling mean
    define_optimum='min',  # Minimum NEE = maximum CO2 uptake
    threshold=0.95,  # Optimum range = bins within top 5% of curve amplitude
    prominence_threshold=1.0,  # Warn if peak is less than 1 std above curve mean
)

# Calculate optimum range
optrange.find_optimum()
> Optimum min found in bin: (14.3, 14.603]  /  value: -6.761454545454546

Results

results = optrange.results_optrange
print(f"Optimum temperature range: {results['optimum_xstart']:.2f} to {results['optimum_xend']:.2f} C")
print(f"Mean NEE in optimum range: {results['optimum_ymean']:.3f} umol/m2/s")
print(f"Optimum prominent: {results['is_optimum_prominent']}  (prominence={results['optimum_prominence']:.2f})")

# Show percentage of data in optimum range
vals_in_range = results['vals_in_optimum_range_df']
print("\nPercentage of data in optimum range (by year):")
print(vals_in_range[['vals_inoptimum_perc']])
Optimum temperature range: 12.20 to 18.90 C
Mean NEE in optimum range: -6.671 umol/m2/s
Optimum prominent: True  (prominence=1.17)

Percentage of data in optimum range (by year):
category  vals_inoptimum_perc
year
2013                19.672131
2014                18.167958
2015                18.678526
2016                18.922723
2017                19.379152
2018                29.825016
2019                20.912451
2020                21.280626
2021                19.056557
2022                24.260945

Visualization

optrange.showfig(
    xunit='degC',  # x-axis unit label: "Tair_f [degC]"
    yunit='umol m-2 s-1',  # y-axis unit label: "NEE_CUT_REF_f [umol m-2 s-1]"
    # xlabel='Air temperature',  # override full x label (optional)
    # ylabel='NEE',              # override full y label (optional)
)
analysis optimumrange

Total running time of the script: (0 minutes 0.462 seconds)

Gallery generated by Sphinx-Gallery