Summaries¶
Summary statistics and tabulation: annual results tables, change tables, cross-validation error statistics, and flux bias statistics.
wrtds.summaries
¶
Summary tables and error statistics for WRTDS results.
Implements setupYears, tableChange, errorStats, and
fluxBiasStat from the R EGRET package.
setup_years(daily, pa_start=10, pa_long=12)
¶
Create annual results DataFrame.
Aggregates daily results into annual (or sub-annual period) summary
values. The period of analysis is defined by pa_start (starting
month) and pa_long (number of months).
Years where more than 10 % of days have missing ConcDay are
excluded.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
daily
|
Populated daily DataFrame with at least |
required | |
pa_start
|
Starting month of the analysis period (1-12). Default 10 (October = water year). |
10
|
|
pa_long
|
Length of the analysis period in months (1-12). Default 12 (full year). |
12
|
Returns:
| Type | Description |
|---|---|
|
DataFrame with columns: |
|
|
|
|
|
Flux values are rates in kg/day, not annual totals. |
Source code in wrtds/summaries.py
table_change(annual_results, year_points, flux_factor=0.00036525)
¶
Compute changes in flow-normalised values between specified years.
For each consecutive pair of years in year_points, compute absolute
change, percent change, slope, and percent slope for both FNConc
and FNFlux.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
annual_results
|
DataFrame from :func: |
required | |
year_points
|
List of years (as integers or floats) at which to evaluate changes. Must be in chronological order. |
required | |
flux_factor
|
Conversion factor from kg/day to desired flux units.
Default |
0.00036525
|
Returns:
| Type | Description |
|---|---|
|
DataFrame with one row per consecutive pair and columns: |
|
|
|
|
|
|
|
|
|
|
|
Flux values are in the units determined by flux_factor. |
Source code in wrtds/summaries.py
error_stats(sample, seed=None)
¶
Cross-validation error statistics.
Computes R-squared for log-concentration and log-flux, RMSE in log
units, and standard error of prediction in percent. Matches R
EGRET's errorStats function.
For censored observations, a random draw from the truncated
log-normal distribution is used (matching R's makeAugmentedSample).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample
|
Sample DataFrame with |
required | |
seed
|
Optional integer seed for reproducibility of censored observation randomisation. |
None
|
Returns:
| Type | Description |
|---|---|
|
Dict with keys |
|
|
|
Source code in wrtds/summaries.py
flux_bias_stat(sample)
¶
Flux bias statistic.
Measures systematic bias in the model's flux predictions at sampled
days. Matches R EGRET's fluxBiasStat.
Three variants are computed to handle censored data:
bias1: usesConcHighas the observed value (conservative for censored data, since the detection limit is an upper bound).bias2: usesConcLowas the observed value (uses 0 for left-censored whereConcLowisNaN).bias3: average ofbias1andbias2(recommended).
The formula is (estimated - observed) / estimated, where both
estimated and observed are flux-weighted sums (concentration * Q).
Positive values indicate overestimation; negative values indicate
underestimation. Values near zero indicate good performance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample
|
Sample DataFrame with |
required |
Returns:
| Type | Description |
|---|---|
|
Dict with keys |