Trends¶
Trend analysis functions: pairwise comparison (run_pairs), group comparison
(run_groups), and annual time series (run_series) with CQTC/QTC decomposition.
wrtds.trends
¶
Trend analysis: generalized flow normalization and trend decomposition (EGRET 3.0).
Implements runPairs, runGroups, and runSeries from the R EGRET
package. These functions decompose water-quality trends into a
concentration-discharge trend component (CQTC) — change in the C-Q
relationship itself — and a discharge trend component (QTC) — change
driven by shifts in the discharge distribution.
The key idea is generalized flow normalization: instead of averaging
across the entire historical discharge distribution (stationary FN), the
discharge distribution is restricted to a sliding window of
2 * window_side + 1 years centred on the target year.
bin_qs_windowed(daily, center_year, window_side)
¶
Group historical log-discharge by day-of-year within a time window.
Like :func:~wrtds.flow_norm.bin_qs but restricted to years within
[center_year - window_side, center_year + window_side].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
daily
|
Populated daily DataFrame. |
required | |
center_year
|
Centre year of the window (integer or decimal year). |
required | |
window_side
|
Half-width of the window in years. |
required |
Returns:
| Type | Description |
|---|---|
|
Dict mapping |
Source code in wrtds/trends.py
run_pairs(sample, daily, year1, year2, window_side=7, pa_start=10, pa_long=12, fit_params=None)
¶
Compare flow-normalised values between two specific years.
Estimates separate 1-year surfaces for year1 and year2, then decomposes the total change into a CQTC (concentration-discharge trend component) and a QTC (discharge trend component).
The notation xAB means:
- A = which year's C-Q surface (1 = year1, 2 = year2)
- B = which flow distribution (0 = stationary / full record, 1 = year1's window, 2 = year2's window)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample
|
Populated sample DataFrame. |
required | |
daily
|
Populated daily DataFrame. |
required | |
year1
|
First comparison year. |
required | |
year2
|
Second comparison year. |
required | |
window_side
|
Half-window for generalized flow normalisation (years). Use 0 for stationary flow normalisation only. |
7
|
|
pa_start
|
Period of analysis start month (10 = water year). |
10
|
|
pa_long
|
Period of analysis length in months. |
12
|
|
fit_params
|
Dict of regression parameters
( |
None
|
Returns:
| Type | Description |
|---|---|
|
DataFrame with index |
|
|
|
|
|
Concentration in mg/L, flux in 10^6 kg/year. |
Source code in wrtds/trends.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 | |
run_groups(daily, surfaces, surface_index, group1_years, group2_years, window_side=7, pa_start=10, pa_long=12)
¶
Compare flow-normalised averages across two groups of years.
Uses the existing full-period surface and averages annual flow-normalised values over each year group.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
daily
|
Populated daily DataFrame. |
required | |
surfaces
|
3-D surfaces array (from full fit). |
required | |
surface_index
|
Grid parameters dict. |
required | |
group1_years
|
|
required | |
group2_years
|
|
required | |
window_side
|
Half-window for generalized flow normalisation. |
7
|
|
pa_start
|
Period of analysis start month. |
10
|
|
pa_long
|
Period of analysis length in months. |
12
|
Returns:
| Type | Description |
|---|---|
|
DataFrame with same format as :func: |
Source code in wrtds/trends.py
run_series(daily, surfaces, surface_index, window_side=7, pa_start=10, pa_long=12)
¶
Compute annual time series of generalized flow-normalised values.
For each year in the record, flow normalisation uses the discharge
distribution from a sliding window of 2 * window_side + 1 years
centred on the target year.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
daily
|
Populated daily DataFrame (must have |
required | |
surfaces
|
3-D surfaces array. |
required | |
surface_index
|
Grid parameters dict. |
required | |
window_side
|
Half-window for generalized flow normalisation. Use 0 for standard (stationary) flow normalisation. |
7
|
|
pa_start
|
Period of analysis start month. |
10
|
|
pa_long
|
Period of analysis length in months. |
12
|
Returns:
| Type | Description |
|---|---|
|
Daily DataFrame with updated |
|
|
computed using generalized flow normalisation. |