4  The tutorial example

Before applying the model to a real watershed, let us master the workflow with the official USGS tutorial example: a tiny grid of 10 × 10 cells of 10 m, with 2 property zones, rainfall in 2 periods, and 60 h of simulation. It runs in ~1 second and lets us understand each file without waiting for any processing.

NoteWhere is this watershed?

It is a teaching subset of only 100 m × 100 m distributed by the USGS with the program — a sample hillslope with no real watershed context (the UTM coordinates on the axes are inherited from the example grid, but the area is far too small to represent any actual place). In Parts 2+ of the short course we will apply the same workflow to the real watersheds of the Rio de Janeiro Highlands.

The files are in the exemplo_01/ folder of this repository, with the necessary fixes already applied (see the note at the end).

4.1 The terrain of the example

To build intuition before looking at the files one by one, here is the relief of the synthetic “watershed”:

Code
library(terra)
dem <- rast("../exemplo_01/data/dem.asc")

par(mfrow = c(1, 2), mar = c(2.5, 2.5, 2, 1))
hs <- shade(terrain(dem, "slope", unit = "radians"),
            terrain(dem, "aspect", unit = "radians"))
plot(hs, col = grey(seq(0.2, 1, length.out = 40)), legend = FALSE,
     main = "Shaded relief + contour lines")
contour(dem, add = TRUE, col = "#8b4513", labcex = 0.7)
persp(dem, theta = 35, phi = 32, expand = 0.55, col = "#e8d9b8",
      border = "#8a7550", main = "3D view", xlab = "x (m)", ylab = "y (m)",
      zlab = "elev. (m)")

The synthetic terrain of the tutorial: shaded relief with contour lines (left) and 3D perspective view (right).

4.2 Folder structure

exemplo_01\
├── tpx_in.txt      <- TopoIndex initialization file
├── tr_in.txt       <- TRIGRS initialization file (ALREADY FIXED)
├── data\           <- input grids (ESRI ASCII format, .asc)
└── Resultados\     <- TRIGRS outputs ("Results"; create it before running!)

4.3 The input grids, one by one

Each .asc file in the data\ folder answers one of the model’s questions. We will look at them in groups, always with the corresponding map next to the description.

4.3.1 Topography: dem.asc, slope.asc, directions.asc

  • dem.asc — the DEM: where all the geometry comes from;
  • slope.asc — slope in degrees (the δ in the FS formula);
  • directions.asc — D8 flow direction, used by TopoIndex to route runoff. The tutorial grid uses TopoIndex’s own numbering (option 2 in tpx_in.txt: 1=NW, 2=N, 3=NE, 4=W, 5=undefined, 6=E, 7=SW, 8=S, 9=SE); grids exported from ArcGIS/QGIS use the ESRI scheme (option 1: 1=E, 2=SE, 4=S, … 128=NE).
Code
slope <- rast("../exemplo_01/data/slope.asc")
dirs  <- rast("../exemplo_01/data/directions.asc")

par(mfrow = c(1, 3))
plot(dem,   main = "dem.asc — elevation (m)",        col = terrain.colors(25))
plot(slope, main = "slope.asc — slope (°)",
     col = hcl.colors(25, "YlOrRd", rev = TRUE))
plot(as.factor(dirs), main = "directions.asc — TopoIndex")

The three topographic grids. Note where the slope is steepest — that is where FS will drop first.

4.3.2 Soil: zones.asc, zmax.asc, depthwt.asc

  • zones.asc — which property zone each cell belongs to (the geotechnical/hydraulic parameters of each zone are set in tr_in.txt);
  • zmax.asc — maximum soil depth (the model’s impermeable base);
  • depthwt.asc — initial depth of the water table (WT; antecedent condition).
Code
zones <- rast("../exemplo_01/data/zones.asc")
zmax  <- rast("../exemplo_01/data/zmax.asc")
dwt   <- rast("../exemplo_01/data/depthwt.asc")

par(mfrow = c(1, 3))
plot(as.factor(zones), main = "zones.asc — property zones")
plot(zmax, main = "zmax.asc — soil depth (m)",
     col = hcl.colors(25, "BrwnYl", rev = TRUE))
plot(dwt,  main = "depthwt.asc — initial WT (m)",
     col = hcl.colors(25, "Blues", rev = TRUE))

The three soil grids of the tutorial: 2 property zones, soil 1.5–2.0 m deep, and an initial water table mostly at 1.5 m depth.

4.3.3 Design rainfall (hyetograph): rizero.asc, ri1.asc, ri2.asc

  • rizero.asc — long-term antecedent infiltration (maintains the initial state);
  • ri1.asc, ri2.asc — rainfall intensity of each period, in m/s (read only when the corresponding cri value in tr_in.txt is negative — see the initialization files below).

Rainfall enters TRIGRS as a stepped hyetograph: the total duration is divided into periods (nper in tr_in.txt), each with its own intensity — given as a uniform value or as an ri*.asc grid (spatially varying rainfall, e.g., interpolated from rain gauges or radar). The tutorial has two periods — 48 h of light antecedent rain and 12 h of a storm (deliberately exaggerated, to force instability on the tiny grid):

Code
tt  <- c(0, 48, 48, 60)
int <- c(3e-7, 3e-7, 9e-5, 9e-5) * 3.6e6      # m/s -> mm/h
plot(tt, int, type = "s", lwd = 3, col = "#1f78b4", las = 1,
     xlab = "time (h)", ylab = "intensity (mm/h)",
     main = "Tutorial rainfall: 2 periods")
polygon(c(0, 48, 48, 0), c(0, 0, 1.08, 1.08), col = "#a6cee344", border = NA)
polygon(c(48, 60, 60, 48), c(0, 0, 324, 324), col = "#1f78b444", border = NA)
text(24, 40, "period 1: 1.08 mm/h × 48 h", cex = 0.9)
text(47, 300, "period 2: 324 mm/h × 12 h", cex = 0.9, adj = 1)

The tutorial hyetograph: the uniform intensities cri of tr_in.txt (3×10⁻⁷ and 9×10⁻⁵ m/s) converted to mm/h — being positive, they are used instead of the ri1 and ri2 grids. The final storm is unrealistic on purpose — it is a teaching dataset.

4.4 The initialization files

Each program reads a text file with parameters and paths, in the folder where it is run:

  • tpx_in.txt (TopoIndex): points to the DEM and to the flow-direction grid; sets the D8 scheme (ESRI = 1, TopoIndex = 2) and which auxiliary lists/grids to save.
  • tr_in.txt (TRIGRS): the heart of the run. Among other things, it defines:
    • the number of zones and the geotechnical/hydraulic parameters of each zone (cohesion in Pa, friction angle φ in degrees, unit weight in N/m³, diffusivity in m²/s, Ksat in m/s, θsat, θres, Gardner’s α);
    • rainfall periods (nper), switching times (capt), and intensities (cri or ri*.asc grids);
    • the simulation depth, the initial water-table condition, and the model options (saturated/unsaturated, finite/infinite depth);
    • output times and which grids to write.
    A negative value of zmax, depth, rizero, or of an intensity cri tells TRIGRS to read the corresponding grid (zmax.asc, depthwt.asc, rizero.asc, ri*.asc) instead of using the value itself. In the tutorial, zmax = -3.001, depth = -2.4, and rizero = -1.0e-9, so these three grids are read; the intensities cri (3×10⁻⁷ and 9×10⁻⁵ m/s) are positive and are applied uniformly.

In the tutorial, the two zones of zones.asc receive these parameters (lines zone, 1 and zone, 2 of tr_in.txt):

Parameter (SI unit) Zone 1 Zone 2 Role in the model
Cohesion c’ (Pa) 3,500 8,000 strength that does not depend on normal stress
Friction φ’ (degrees) 35 31 frictional strength
Unit weight γs (N/m³) 22,000 22,000 weight of the soil column
Diffusivity D₀ (m²/s) 6.0×10⁻⁶ 8.0×10⁻⁴ speed of the pore-pressure response
Ksat (m/s) 1.0×10⁻⁷ 1.0×10⁻⁴ infiltration capacity
θsat / θres 0.45 / 0.05 0.45 / 0.06 saturated/residual water contents
Gardner’s α (1/m) −0.5 −8.0 K(ψ) curve of the unsaturated zone

Note the contrast: zone 1 has the higher friction angle but lower cohesion and is much less permeable (it responds slowly); zone 2 is more cohesive but has a lower friction angle and is much more permeable — the storm reaches it quickly. This interplay produces the instability pattern we will see in the next chapter.

4.5 Units — pitfall #1

TRIGRS works in SI units: meters, seconds, pascals. Rainfall enters in m/s:

\[ 50\ \text{mm/h} = \frac{50}{1000 \times 3600} = 1.39 \times 10^{-5}\ \text{m/s} \]

ImportantFixes we made to the original USGS example

If you download the example directly from the official distribution, three adjustments are needed (in this repository folder they are already done):

  1. In tr_in.txt, the paths pointed to Data/tutorial/, a folder that does not exist in the distribution — changed to data/;
  2. The TIdscelGrid_tutorial grid is written by TopoIndex with the .txt extension (not .asc) — the name in tr_in.txt was adjusted;
  3. The output folder (Resultados/) must exist before running — TRIGRS does not create it and fails silently when writing.