Note
Go to the end to download the full example code.
NEE Partitioning: comparison of all diive methods¶
diive ships faithful Python ports of four reference NEE partitioning routines:
Nighttime ONEFlux (Reichstein et al. 2005),
NighttimePartitioningOneFlux(_NT_OFcolumns)Nighttime REddyProc (Reichstein et al. 2005),
NighttimePartitioningReddyProc(_NT_RPcolumns)Daytime REddyProc (Lasslop et al. 2010),
DaytimePartitioningReddyProc(_DT_RPcolumns)Daytime ONEFlux (Lasslop et al. 2010),
DaytimePartitioningOneFlux(_DT_OFcolumns)
The two nighttime methods fit the temperature response of nighttime NEE; the two
daytime methods fit a light-response curve to daytime NEE. They estimate the
same quantities (GPP and RECO) from different parts of the diel cycle and via
different reference implementations, so they do not produce identical numbers.
This example runs all four on the same input and compares them against each
other and against the bundled REddyProc reference columns (Reco_CUT_REF /
GPP_CUT_REF_f for the nighttime methods, Reco_DT_CUT_REF /
GPP_DT_CUT_REF for the daytime methods).
Best for: choosing a partitioning method, or seeing how much the choice matters.
The four classes can also be reached through one entry point,
PartitioningNEE, with method='nighttime' or
'daytime' and mode='oneflux' (default, the ICOS and FLUXNET2015
approach) or 'reddyproc'.
Load data¶
import matplotlib.pyplot as plt
import numpy as np
import diive as dv
df = dv.load_exampledata_parquet()
# One growing season (April-September 2017): all four methods see identical input,
# which is what the comparison needs, over the season where GPP and RECO are both
# large enough for the methods to disagree visibly. A full year is dominated by the
# two daytime ports, whose E0 smoother costs minutes once the window count grows.
df = df.loc[(df.index.year == 2017) & (df.index.month.isin([4, 5, 6, 7, 8, 9]))].copy()
print("Comparing 2 NIGHTTIME methods (*_NT_OF, *_NT_RP) and 2 DAYTIME methods (*_DT_RP, *_DT_OF)")
print(f"Period: {df.index.min().date()} to {df.index.max().date()} ({len(df)} records)")
> 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.050
seconds).
Comparing 2 NIGHTTIME methods (*_NT_OF, *_NT_RP) and 2 DAYTIME methods (*_DT_RP, *_DT_OF)
Period: 2017-04-01 to 2017-09-30 (8784 records)
Run all four ports on identical inputs¶
All four take NEE, air temperature and incoming shortwave radiation, measured or gap-filled as each method requires. The REddyProc ports additionally need longitude and the UTC offset (solar-time day/night split); the daytime ports additionally need VPD (the light-response curve’s VPD term).
of = dv.flux.NighttimePartitioningOneFlux(
nee=df['NEE_CUT_REF_orig'], 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().results
nt = dv.flux.NighttimePartitioningReddyProc(
nee=df['NEE_CUT_REF_orig'], ta=df['Tair_orig'], sw_in=df['Rg_orig'],
nee_f=df['NEE_CUT_REF_f'], ta_f=df['Tair_f'],
lat=46.815, lon=9.855, utc_offset=1,
).run().results
dt = dv.flux.DaytimePartitioningReddyProc(
nee=df['NEE_CUT_REF_orig'], ta=df['Tair_f'], vpd=df['VPD_f'], sw_in=df['Rg_f'],
lat=46.815, lon=9.855, utc_offset=1, vpd_in_kpa=False, # VPD_f is in hPa
).run().results
# The ONEFlux daytime method uses ONEFlux's measured-radiation day/night split
# (no latitude) and needs both the measured and gap-filled drivers.
dt_of = dv.flux.DaytimePartitioningOneFlux(
nee=df['NEE_CUT_REF_orig'], ta=df['Tair_orig'], sw_in=df['Rg_orig'],
ta_f=df['Tair_f'], sw_in_f=df['Rg_f'], vpd=df['VPD_f'], vpd_in_kpa=False,
).run().results
# Reference columns: nighttime methods share the NT reference, the daytime methods
# share the DT reference.
reco_ref_nt, gpp_ref_nt = df['Reco_CUT_REF'], df['GPP_CUT_REF_f']
reco_ref_dt, gpp_ref_dt = df['Reco_DT_CUT_REF'], df['GPP_DT_CUT_REF']
> Nighttime partitioning (Reichstein et al. 2005) starting for 1 year(s).
────── Nighttime NEE Partitioning ONEFlux (Reichstein et al. 2005) Report ──────
Reference: Reichstein et al. (2005),
https://doi.org/10.1111/j.1365-2486.2005.001002.x
RECO GPP
Year Records filled filled RECO mean GPP mean E0
2017 8,784 8,784 8,784 4.56 6.08 160.79
(100%) (100%)
outlier-robust: RECO mean 4.20, GPP mean 5.71
Fluxes in umol m-2 s-1.
v Nighttime partitioning finished.
> Nighttime partitioning ReddyProc (Reichstein et al. 2005) starting for 8784
records (48 per day).
───── Nighttime NEE Partitioning REddyProc (Reichstein et al. 2005) Report ─────
Reference: Wutzler et al. (2018), https://doi.org/10.5194/bg-15-5015-2018
RECO GPP
Year Records filled filled RECO mean GPP mean E0 [K]
2017 8,784 8,784 8,784 4.69 6.20 129.75
(100%) (100%)
Fluxes in umol m-2 s-1.
v Nighttime partitioning (ReddyProc) finished.
> Daytime partitioning ReddyProc (Lasslop et al. 2010) starting for 8784
records (48 per day).
─────── Daytime NEE Partitioning REddyProc (Lasslop et al. 2010) Report ────────
Reference: Wutzler et al. (2018), https://doi.org/10.5194/bg-15-5015-2018
RECO GPP
Year Records filled filled RECO mean GPP mean E0 [K]
2017 8,784 8,784 8,784 2.53 4.28 202.69
(100%) (100%)
Fluxes in umol m-2 s-1.
v Daytime partitioning (ReddyProc) finished.
> Daytime partitioning ONEFlux (Lasslop et al. 2010) starting for 1 year(s).
──────── Daytime NEE Partitioning ONEFlux (Lasslop et al. 2010) Report ─────────
Reference: Pastorello et al. (2020), https://doi.org/10.1038/s41597-020-0534-3
RECO GPP
Year Records filled filled RECO mean GPP mean E0
2017 8,784 8,784 8,784 3.01 4.34 189.25
(100%) (100%)
GPP standard error mean 0.93
Fluxes in umol m-2 s-1.
v Daytime partitioning (ONEFlux) finished.
Numerical comparison¶
Each port vs its own bundled reference, and pairs of ports against each other.
def _r(a, b):
m = a.notna() & b.notna()
return np.corrcoef(a[m], b[m])[0, 1]
print("\nRECO vs reference:")
print(f" diive (ONEFLUX nighttime) vs reference (NT): {_r(of['RECO_NT_OF'], reco_ref_nt):.4f}")
print(f" diive (REddyProc nighttime) vs reference (NT): {_r(nt['RECO_NT_RP'], reco_ref_nt):.4f}")
print(f" diive (REddyProc daytime) vs reference (DT): {_r(dt['RECO_DT_RP'], reco_ref_dt):.4f}")
print(f" diive (ONEFLUX daytime) vs reference (DT): {_r(dt_of['RECO_DT_OF'], reco_ref_dt):.4f}")
print("\nGPP vs reference:")
print(f" diive (ONEFLUX nighttime) vs reference (NT): {_r(of['GPP_NT_OF'], gpp_ref_nt):.4f}")
print(f" diive (REddyProc nighttime) vs reference (NT): {_r(nt['GPP_NT_RP'], gpp_ref_nt):.4f}")
print(f" diive (REddyProc daytime) vs reference (DT): {_r(dt['GPP_DT_RP'], gpp_ref_dt):.4f}")
print(f" diive (ONEFLUX daytime) vs reference (DT): {_r(dt_of['GPP_DT_OF'], gpp_ref_dt):.4f}")
print("\nMethods against each other (RECO / GPP):")
print(f" ONEFLUX-nt vs REddyProc-nt: {_r(of['RECO_NT_OF'], nt['RECO_NT_RP']):.4f} / "
f"{_r(of['GPP_NT_OF'], nt['GPP_NT_RP']):.4f}")
print(f" REddyProc-nt vs REddyProc-dt: {_r(nt['RECO_NT_RP'], dt['RECO_DT_RP']):.4f} / "
f"{_r(nt['GPP_NT_RP'], dt['GPP_DT_RP']):.4f}")
print(f" REddyProc-dt vs ONEFLUX-dt: {_r(dt['RECO_DT_RP'], dt_of['RECO_DT_OF']):.4f} / "
f"{_r(dt['GPP_DT_RP'], dt_of['GPP_DT_OF']):.4f}")
print("\nMeans (umol m-2 s-1):")
print(f" RECO ONEFLUX-nt {of['RECO_NT_OF'].mean():.3f} REddyProc-nt {nt['RECO_NT_RP'].mean():.3f} "
f"REddyProc-dt {dt['RECO_DT_RP'].mean():.3f} ONEFLUX-dt {dt_of['RECO_DT_OF'].mean():.3f}")
print(f" GPP ONEFLUX-nt {of['GPP_NT_OF'].mean():.3f} REddyProc-nt {nt['GPP_NT_RP'].mean():.3f} "
f"REddyProc-dt {dt['GPP_DT_RP'].mean():.3f} ONEFLUX-dt {dt_of['GPP_DT_OF'].mean():.3f}")
RECO vs reference:
diive (ONEFLUX nighttime) vs reference (NT): 0.9806
diive (REddyProc nighttime) vs reference (NT): 0.9632
diive (REddyProc daytime) vs reference (DT): 0.8006
diive (ONEFLUX daytime) vs reference (DT): 0.3695
GPP vs reference:
diive (ONEFLUX nighttime) vs reference (NT): 0.9977
diive (REddyProc nighttime) vs reference (NT): 0.9957
diive (REddyProc daytime) vs reference (DT): 0.9711
diive (ONEFLUX daytime) vs reference (DT): 0.8850
Methods against each other (RECO / GPP):
ONEFLUX-nt vs REddyProc-nt: 0.9764 / 0.9973
REddyProc-nt vs REddyProc-dt: 0.6677 / 0.8704
REddyProc-dt vs ONEFLUX-dt: 0.4584 / 0.9116
Means (umol m-2 s-1):
RECO ONEFLUX-nt 4.564 REddyProc-nt 4.691 REddyProc-dt 2.532 ONEFLUX-dt 3.007
GPP ONEFLUX-nt 6.078 REddyProc-nt 6.204 REddyProc-dt 4.280 ONEFLUX-dt 4.343
Time-series comparison (daily means + cumulative)¶
Three panels on a shared x-axis: RECO daily means (top), GPP daily means (middle), and the running cumulative of both RECO and GPP (bottom). Each method has its own distinct colour (Okabe-Ito colour-blind-safe palette); the diive ports are solid, the bundled references dotted. In the cumulative panel colour still encodes the method, while RECO is solid and GPP dashed.
# Okabe-Ito colour-blind-safe palette, one colour per method.
COLORS = {
'of': '#0072B2', # diive ONEFLUX nighttime - blue
'nt': '#E69F00', # diive REddyProc nighttime - orange
'dt': '#009E73', # diive REddyProc daytime - bluish green
'dt_of': '#56B4E9', # diive ONEFLUX daytime - sky blue
'ref_nt': '#CC79A7', # REddyProc reference (NT) - reddish purple
'ref_dt': '#D55E00', # REddyProc reference (DT) - vermillion
}
def _daily(s):
return s.resample('D').mean()
def _cumulative(s):
return s.fillna(0.0).cumsum()
fig, (ax_reco, ax_gpp, ax_cum) = plt.subplots(3, 1, figsize=(13, 10), sharex=True)
fig.subplots_adjust(left=0.07, right=0.98, top=0.94, bottom=0.06, hspace=0.13)
ax_reco.plot(_daily(of['RECO_NT_OF']), color=COLORS['of'], lw=1.4, label='diive (ONEFLUX nighttime)')
ax_reco.plot(_daily(nt['RECO_NT_RP']), color=COLORS['nt'], lw=1.4, label='diive (REddyProc nighttime)')
ax_reco.plot(_daily(dt['RECO_DT_RP']), color=COLORS['dt'], lw=1.4, label='diive (REddyProc daytime)')
ax_reco.plot(_daily(dt_of['RECO_DT_OF']), color=COLORS['dt_of'], lw=1.4, label='diive (ONEFLUX daytime)')
ax_reco.plot(_daily(reco_ref_nt), color=COLORS['ref_nt'], lw=1.0, ls=':', label='REddyProc reference (NT)')
ax_reco.plot(_daily(reco_ref_dt), color=COLORS['ref_dt'], lw=1.0, ls=':', label='REddyProc reference (DT)')
ax_reco.set_ylabel('RECO (umol m-2 s-1)')
ax_reco.legend(ncol=3, frameon=False, fontsize=8)
ax_gpp.plot(_daily(of['GPP_NT_OF']), color=COLORS['of'], lw=1.4, label='diive (ONEFLUX nighttime)')
ax_gpp.plot(_daily(nt['GPP_NT_RP']), color=COLORS['nt'], lw=1.4, label='diive (REddyProc nighttime)')
ax_gpp.plot(_daily(dt['GPP_DT_RP']), color=COLORS['dt'], lw=1.4, label='diive (REddyProc daytime)')
ax_gpp.plot(_daily(dt_of['GPP_DT_OF']), color=COLORS['dt_of'], lw=1.4, label='diive (ONEFLUX daytime)')
ax_gpp.plot(_daily(gpp_ref_nt), color=COLORS['ref_nt'], lw=1.0, ls=':', label='REddyProc reference (NT)')
ax_gpp.plot(_daily(gpp_ref_dt), color=COLORS['ref_dt'], lw=1.0, ls=':', label='REddyProc reference (DT)')
ax_gpp.set_ylabel('GPP (umol m-2 s-1)')
ax_gpp.legend(ncol=3, frameon=False, fontsize=8)
# Cumulative: colour = method, RECO solid, GPP dashed.
for s, key, ls, label in [
(of['RECO_NT_OF'], 'of', '-', 'RECO ONEFLUX-nt'),
(nt['RECO_NT_RP'], 'nt', '-', 'RECO REddyProc-nt'),
(dt['RECO_DT_RP'], 'dt', '-', 'RECO REddyProc-dt'),
(dt_of['RECO_DT_OF'], 'dt_of', '-', 'RECO ONEFLUX-dt'),
(of['GPP_NT_OF'], 'of', '--', 'GPP ONEFLUX-nt'),
(nt['GPP_NT_RP'], 'nt', '--', 'GPP REddyProc-nt'),
(dt['GPP_DT_RP'], 'dt', '--', 'GPP REddyProc-dt'),
(dt_of['GPP_DT_OF'], 'dt_of', '--', 'GPP ONEFLUX-dt'),
]:
ax_cum.plot(_cumulative(s), color=COLORS[key], ls=ls, lw=1.3, label=label)
ax_cum.set_ylabel('cumulative flux (umol m-2 s-1)')
ax_cum.set_xlabel('2017')
ax_cum.legend(ncol=2, frameon=False, fontsize=8)
for ax in (ax_reco, ax_gpp):
ax.axhline(0, color='#455A64', lw=0.8)
fig.suptitle('diive NEE partitioning: ONEFLUX nighttime vs REddyProc nighttime vs '
'REddyProc daytime vs ONEFLUX daytime - daily means and cumulative (CH-DAV 2017)')
plt.show()

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