Skip to content

Commit 93adaae

Browse files
committed
Make difference between Integrate and Aggregate more clear
1 parent c13ef5b commit 93adaae

5 files changed

Lines changed: 28 additions & 0 deletions

File tree

docs/src/API/API_public.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ MeteoBindings(
108108
### Parameterized window reducers
109109

110110
`Integrate()` defaults to `SumReducer()`; `Aggregate()` defaults to `MeanReducer()`.
111+
With the same reducer, they are runtime-equivalent.
112+
Use `Integrate` for accumulation semantics and `Aggregate` for summary-statistics semantics.
111113

112114
```julia
113115
ModelSpec(DailyModel()) |>

docs/src/model_execution.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ Inspection helpers:
5050
Policy parameterization:
5151
- `Integrate()` defaults to `SumReducer()`; you can pass another reducer, e.g. `Integrate(MeanReducer())` or `Integrate(vals -> maximum(vals) - minimum(vals))`.
5252
- `Aggregate()` defaults to `MeanReducer()`; you can pass reducers such as `Aggregate(MaxReducer())`.
53+
- Difference between `Integrate` and `Aggregate`: with the same reducer they are runtime-equivalent.
54+
In practice, only defaults and naming intent differ (`Integrate` for accumulation, `Aggregate` for summary statistics).
5355
- `Interpolate()` defaults to `mode=:linear, extrapolation=:linear`; use `Interpolate(; mode=:hold, extrapolation=:hold)` for hold behavior.
5456
- The same reducer objects are reused by meteo sampling (`MeteoBindings`) and by windowed policies (`Integrate`, `Aggregate`).
5557

src/time/multirate.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ Interpolate(; mode::Symbol=:linear, extrapolation::Symbol=:linear) = Interpolate
9898
Windowed policy for consumers running at coarser clocks.
9999
Values in the consumer window are reduced with `reducer`.
100100
101+
Intended meaning: integrate/accumulate quantities over a window (for example
102+
hourly flux to daily total). Default reducer is `SumReducer()`.
103+
104+
Important: `Integrate(r)` and `Aggregate(r)` are runtime-equivalent when they
105+
use the same reducer `r`; they only differ by default reducer and naming intent.
106+
101107
Built-in reducers can be shared with meteo sampling from `PlantMeteo`:
102108
`SumReducer()`, `MeanReducer()`, `MaxReducer()`, `MinReducer()`, `FirstReducer()`,
103109
`LastReducer()`.
@@ -118,6 +124,12 @@ end
118124
Windowed aggregation policy for consumers running at coarser clocks.
119125
Values in the consumer window are reduced with `reducer`.
120126
127+
Intended meaning: summarize window values as a statistic (for example mean/max).
128+
Default reducer is `MeanReducer()`.
129+
130+
Important: `Aggregate(r)` and `Integrate(r)` are runtime-equivalent when they
131+
use the same reducer `r`; they only differ by default reducer and naming intent.
132+
121133
Built-in reducers can be shared with meteo sampling from `PlantMeteo`:
122134
`SumReducer()`, `MeanReducer()`, `MaxReducer()`, `MinReducer()`, `FirstReducer()`,
123135
`LastReducer()`.

src/time/runtime/output_export.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ resampled temporal streams while simulation is running.
1919
- `policy::SchedulePolicy=HoldLast()`: resampling policy applied at export time.
2020
Common values are `HoldLast()`, `Integrate(...)`, `Aggregate(...)`,
2121
`Interpolate(...)`.
22+
`Integrate` and `Aggregate` are runtime-equivalent with the same reducer;
23+
they differ by default reducer (`SumReducer` vs `MeanReducer`) and intent.
2224
- `clock=nothing`: export clock. When `nothing`, export is evaluated at each
2325
simulation step (`ClockSpec(1.0, 0.0)`). Accepted explicit values are the same
2426
as model timestep specs (`Real`, `ClockSpec`, or fixed `Dates.Period`).

test/test-multirate-scaffolding.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,14 @@ using Test
5858
ts.caches[key] = HoldLastCache(1.0, 42.0)
5959
@test ts.caches[key] isa HoldLastCache
6060
@test ts.caches[key].v == 42.0
61+
62+
vals = [1.0, 2.0, 3.0]
63+
@test Integrate().reducer isa SumReducer
64+
@test Aggregate().reducer isa MeanReducer
65+
@test PlantSimEngine._window_reduce(vals, Integrate()) == 6.0
66+
@test PlantSimEngine._window_reduce(vals, Aggregate()) == 2.0
67+
@test PlantSimEngine._window_reduce(vals, Integrate(MeanReducer())) ==
68+
PlantSimEngine._window_reduce(vals, Aggregate(MeanReducer()))
69+
@test PlantSimEngine._window_reduce(vals, Integrate(SumReducer())) ==
70+
PlantSimEngine._window_reduce(vals, Aggregate(SumReducer()))
6171
end

0 commit comments

Comments
 (0)