Session 9 · Putting it together

One day, one year

Sessions 3 to 8 took the model apart. This session puts it back together. Pick any day between October 1986 and September 1999 and follow its water through every step, with every variable and every formula filled in with that day's numbers. Then zoom out to a full year, check that no water is lost, and confirm that the model in your browser is the real one.

Time about 35 minutesNeeds Sessions 3–8
Watch this session first: a 6-minute narrated video with English subtitles. The page below goes further and lets you try each step yourself.

You will be able to

The daily loop

All of dCREST fits in a few lines of pseudo-code. The five states start from fixed initial values, and each day updates them in order:

SWE, W, SM, G, Fs = 0, 0, 0.5·wm, 0.3·hmaxaq, 0          # initial states
for each day t:
    L, SWE      = snow(P[t], T[t], SWE)                      # Session 3
    L, d, W     = canopy(L, PET[t], W)                       # Session 4: water and demand left
    if L > d:  Qint, Qov, SM'      = wet_soil(L, d, SM)    # Session 5, 6
    else:      Qint, Qov, SM', G   = dry_soil(L, d, SM, G) # Session 6
    SM, G, Qb, Qsp = aquifer(SM', G)                        # Session 7
    Qr, Fs      = fast_reservoir(Qov, Fs)                    # Session 8
    r[t]        = (Qr + Qint + Qb + Qsp) · (1 − lf)
Q = convolve(r, unit_hydrograph(nshape, kmult, area))       # Session 8, after the loop

The states carry the model's memory. Everything the model "knows" about the past, such as a wet winter, a dry summer or last week's storm, is held in those five numbers at the end of each day, plus the runoff of the last 29 days that the unit hydrograph is still delivering.

Step through a day

Try itEvery variable, every formula, any day
stepquantityformula, with today's numbersvalue

Stores in mm, fluxes in mm/day. "Before" values are the states left by the previous day. The model starts on 1 October 1986 from its initial states, so the first days are still settling (see "spin-up" below).

Things to look for

A year of the model

Try itStores and fluxes through one water year

Top: river flow (model and observed) and rain. Middle: the stores. Bottom: where evaporation came from. Drag across any chart to zoom all three.

Read the year from the stores. The soil fills through autumn and winter while evaporation is low, reaches near-capacity in late winter, when each storm then produces large runoff, and dries through summer. The aquifer follows the soil with a lag of weeks. The canopy is refilled by every rain and emptied by the next sunny days. Evaporation switches from canopy to soil to aquifer as the dry spells lengthen.

No water is lost

Over any period, everything that came in must have left or still be stored. For the whole test decade, using the run in your browser:

Term (1 Oct 1989 – 30 Sep 1999)mm

The residual is the size of rounding errors in computer arithmetic. (The rows are rounded to 0.1 mm, so adding them by hand can be off by a few tenths; the residual is computed from the unrounded values.) The package's test suite checks the same balance on synthetic catchments every time it runs and fails if the residual exceeds 10−12 of the precipitation.

Spin-up: forgetting the start

The model has to start from some initial state: half-full soil, an aquifer at 30% of capacity, no snow. Those guesses are wrong, but the model forgets them, because each day's state depends more on recent weather than on the distant past. To be safe, every run starts three years before the period that is scored, a spin-up. The widget below starts the model from very different initial soil and aquifer states and shows how quickly the runs converge.

Try itDifferent starts, same river

Soil water from four runs starting on 1 October 1986: soil empty, half full (the default), full, and full with a full aquifer. Within a few months they are indistinguishable, long before the scored period begins in October 1989.

Is this the real model?

Checking…

In Python

The same loop as the pseudo-code above, with the step functions from the earlier sessions (imported from the course module). It runs the test period and compares the result with a stored run of the PyTorch package.

Check your understanding

On 17 February 1990 only about 3 mm of rain fell, yet the model's river flow peaked. Where did the water come from?

From the previous day's storm: the fast reservoir released most of the 112 mm of overland flow it received on the 16th, and the unit hydrograph delivered it to the gauge over the next days.

Which five numbers carry all of the model's memory from one day to the next?

The states: snowpack SWE, canopy W, soil SM, aquifer G and fast reservoir Fs. (The unit hydrograph also spreads past runoff forward, but it holds no water of its own beyond what is still in transit.)

Why is the water-balance residual not exactly zero?

Computers store numbers with about 16 significant digits, so each of the tens of thousands of additions rounds slightly. The residual is the accumulated rounding, far below any physical meaning.

Why are the first three years of each run not scored?

The initial states are guesses. Three years of spin-up let the model forget them, so the scored period reflects the forcing and the parameters, not the starting point.

What to remember