Whitebox QGIS Practice 31 — Stream Power Index of Two Basins: The Main Channel Set the Mean, the Slopes Set the Median

In practice 30 I compared where two basins are likely to stay wet, using the topographic wetness index (TWI). The same inputs answer the opposite question too. Not where water collects, but where the collected water, running down a slope, has the most power to scour its bed. When I want a first pass over erosion-prone ground before thinking about check dams or drains, the index I reach for is the Stream Power Index (SPI).

The formula is SPI = SCA × tan β. SCA is the D-infinity specific contributing area from practice 30 (m²/m) and β is the slope. TWI is the log of SCA divided by tan β; SPI is SCA multiplied by it. It grows where a cell receives a lot of water from upslope and is steep as well. This time I took the practice 30 outputs as they were, ran Whitebox StreamPowerIndex, and compared the two basins with Zonal statistics. The comparison flipped depending on which summary value I looked at, and most of this post is about that.

Data

I copied the practice 30 inputs and outputs into a new input folder (WB31_Input_20261120). The copies have the same hashes as the originals.

InputOriginContents
wb31_input_sca_dinf.tifPractice 30, DInf Flow AccumulationD-infinity specific contributing area from the breached DEM of practice 18 (max cost 0.03). 1 m cells, EPSG:26913, 1500×1500 cells
wb31_input_slope_deg.tifPractice 30, SlopeSlope of the same breached DEM in degrees. 0.020° to 88.65°, no 0° cells
wb31_input_basins_merged.shpPractice 26 merged polygonsVALUE 1 = interval basin (A−B) 1,218,780 m², VALUE 2 = basin B 211,372 m²
wb31_input_streams_cap0p03.tifPractice 18 streamsStreams at a 1 ha contributing-area threshold (for the map and for stream-cell statistics)

The reason for not recomputing SCA and slope is simple. To set practice 30's TWI next to this SPI, both indices have to come from exactly the same SCA and the same slope. Recompute either one and you can no longer tell whether a difference comes from the index or from the inputs.

Step 1: StreamPowerIndex

Open Processing Toolbox → WhiteboxTools → Geomorphometric Analysis → StreamPowerIndex. It has three inputs.

FieldValueReason
Input Specific Contributing Area (SCA) FileSpecific contributing area, D-inf (m2/m, practice 30)It has to be an SCA made with Log-transform turned off. A log-transformed SCA makes the multiplication meaningless.
Input Slope FileSlope, degrees (practice 30)Slope in degrees. The independent check below matched tan taken in degrees.
Specific Contributing Area (SCA) Exponent1.0 (default)The p in SPI = SCA^p × tan β. I kept the basic form. It is a research adjustment that weakens or strengthens the area term, and results are only comparable with the same value.
Output Filewb31_spi.tif
QGIS StreamPowerIndex dialog. Input Specific Contributing Area (SCA) File is Specific contributing area, D-inf (m2/m, practice 30), Input Slope File is Slope, degrees (practice 30), the SCA Exponent is 1.000000 and the output is wb31_spi.tif in the WB31_SPI_20261120 folder. Behind it the map shows the light purple interval basin and the orange basin B over a hillshade.
Figure 1. StreamPowerIndex dialog with the practice 30 SCA and slope, exponent left at the default of 1. The QGIS interface in the capture is in Korean.

The result spans from 0.00044 to 1,719,393, close to ten orders of magnitude. The median is 14.1, but the 99th percentile is 1,469 and the maximum is 1.7 million. The distribution inherits the long tail of SCA, so a linear colour ramp shows a few streams and paints everything else in one colour. I used stepped colours with breaks at 0.1, 1, 10, 100, 1,000 and 10,000. In a QGIS discrete ramp the legend value is the upper end of each class, so navy, for example, means cells above 1,000.

Stream power index map. The legend runs 0.1 pale yellow, 1 light green, 10 mint, 100 teal, 1,000 blue, 10,000 navy. Ridges are pale yellow, most slopes are mint and teal, and valleys and thin hillslope lines branch out in blue and navy. The purple line is the interval basin, the pink line is basin B, and the outlets ID 1 = A and ID 2 = B are marked at the top centre.
Figure 2. Stream power index. The class breaks are a factor of 10 apart.

Next to the TWI map (practice 30, figure 4) the valley lines look alike, but they behave differently. TWI is larger on gentle valley floors; along the same line, SPI is larger on the steeper upstream reaches. I zoomed in near the outlets and overlaid the practice 18 streams in red.

Close-up near the outlets. Red stream lines, the purple interval basin boundary and the pink basin B boundary lie over the stepped stream power index colours. Navy cells follow the red streams, and several navy and blue lines also run down slopes where there is no red stream line. The outlets ID 1 = A and ID 2 = B are at the upper right.
Figure 3. Close-up near the outlets (about 1:1,500). The red lines are the 1 ha streams.

The part worth a second look is the slopes without a red line. Hillslope hollows below the 1 ha stream threshold still carry long navy (above 1,000) and blue (above 100) lines. The contributing area is small, but where the slope is steep the product grows and lands in the same colour class as stream cells. These hollows are exactly where it is easy to say "no channel here, so it is fine" when you only look at extracted streams.

Step 2: Zonal statistics per basin

In Processing Toolbox → Raster analysis → Zonal statistics I used the practice 26 merged polygons and the SPI raster. The prefix is spi_, and the statistics are the same as in practice 30: count, mean, median, standard deviation, minimum and maximum. The output is wb31_basin_spi_stats.shp.

Zonal statistics attribute table. Row VALUE 1 has spi_count 1218780, spi_mean 248.2096733, spi_median 14.28938198, spi_stdev 4340.719164, spi_min 0.000590027, spi_max 695251.5; row VALUE 2 has spi_count 211372, spi_mean 147.5390604, spi_median 23.76921749, spi_stdev 1258.686884, spi_min 0.000804960, spi_max 78309.52343. On the map behind, labels read A-B mean 248.2 median 14.29 and B mean 147.5 median 23.77.
Figure 4. Zonal statistics table and basin labels.
ItemInterval basin A−BBasin B
Cells (m²)1,218,780211,372
Mean248.2147.5
Median14.2923.77
Standard deviation4,340.71,258.7
Maximum695,251.578,309.5
10th / 90th percentile2.24 / 89.973.50 / 134.08

By the mean, the interval basin is 1.7 times basin B. By the median, it is the other way round: B is 1.7 times larger. The standard deviation is 17 times the mean for A−B and 8.5 times for B. With a distribution this skewed, a single mean should not stand for a basin.

Why the mean flipped

I sorted the values and set the top 1% of cells aside.

ItemInterval basin A−BBasin B
Top 1% cells12,1882,114
Share of the SPI sum held by the top 1% cells83.4%58.1%
Mean without the top 1% cells41.662.4
Geometric mean14.4923.14
Stream cells (1 ha) count / median6,390 / 11,4931,371 / 4,895
Median of non-stream cells14.1723.52

In the interval basin, 1% of the cells hold 83% of the SPI sum. Remove them and the mean drops from 248 to 41.6, below B's 62.4. The main channel of A runs through the interval basin, and its cells have upslope areas in the hundreds of thousands of m², which puts their SPI in the tens or hundreds of thousands. The maximum of 695,252 appears to sit on that main channel. The stream-cell median is also 11,493 in the interval basin, more than twice B's 4,895. In other words, the difference in means was about whether a basin contains the main channel, not about the character of its slopes.

Looking only at non-stream cells, B is 23.5 and the interval basin 14.2. In the class shares of figure 5, B has 12.2% in the 100 to 1,000 class against 7.7% for the interval basin, and 23.1% in the 1 to 10 class against 34.6%. Most of B's slope cells sit one class higher.

Two-panel bar chart. The left panel shows the share of basin area by SPI class for the interval basin A-B (purple) and B (teal, hatched): below 1 4.7 and 2.9, 1-10 34.6 and 23.1, 10-100 51.7 and 60.0, 100-1,000 7.7 and 12.2, 1,000-10,000 0.9 and 1.5, 10,000 and above 0.4 and 0.3 percent. The right panel compares summary values: mean 248.2 and 147.5, mean without the top 1% cells 41.6 and 62.4, median 14.3 and 23.8, geometric mean 14.5 and 23.1. Axis labels are in Korean.
Figure 5. (a) Share of basin area by SPI class, (b) comparison by summary value. Only the mean is larger for the interval basin; every other value is larger for B. Chart labels are in Korean.

Same inputs as TWI, opposite sign

The geometric mean is the back-transformed mean of ln SPI, so it can be split into parts. Since ln SPI = ln SCA + ln tan β, the difference between the basins is:

  • Mean ln SCA: B 3.7625, interval basin 3.2619, difference +0.500
  • Mean ln tan β: B −0.6208, interval basin −0.5885, difference −0.032
  • Sum 0.468, which is a geometric-mean ratio of 23.14 / 14.49 = 1.60

For TWI in practice 30 the same two parts added up as 0.500 + 0.032 = 0.533. TWI divides by tan β, so B's slightly gentler slope raised its TWI; SPI multiplies by it, so the same difference trims SPI a little. The slope term is only about 0.03, though, and most of the difference comes from the 0.5 in ln SCA. On average each slope cell in B receives about e^0.5 ≈ 1.65 times more upslope area, so B is higher in both TWI and SPI. A slope that is both wetter and more erodible sounds contradictory, but both indices look at the same fact, more water passing through, from different angles.

Taken to the field: if the job is managing one main channel, the interval basin comes first. If the concern is scour or sediment from many small hollows on the slopes, I would look at the slopes of basin B first. This reading comes from terrain indices alone and has not been checked against measured erosion or soil conditions.

Independent check

  • I recomputed SCA × tan(slope in degrees) with numpy and compared it with the Whitebox output. Over 2,248,166 valid cells the largest relative difference is 6.0×10⁻⁸, and no cell exceeds 10⁻⁵. The exponent of 1.0 and the slope in degrees went in as intended.
  • The output SPI is EPSG:26913, 1500×1500, float32, with 1,834 NoData cells (−32768). It shares its grid with the input SCA, slope and DEM, and the NoData count matches the DEM.
  • Recomputing the six zonal statistics with basin masks rasterised at cell centres gives differences of 10⁻¹² or less for both basins.

Things to watch in practice

  • SPI has an extremely long tail. Comparing basins by the mean alone lets a few main-channel lines decide the result. Report the median, the geometric mean and the share held by the top few percent alongside it.
  • Map it with stepped colours on logarithmic breaks. A linear ramp shows only a handful of stream cells.
  • SPI is a relative index. Its magnitude depends on DEM resolution, the flow algorithm (D8 or D-infinity) and the SCA exponent p. To compare with another area, rebuild it with the same resolution and settings.
  • Look separately at hollows below the stream-extraction threshold. As in figure 3, lines with SPI above 1,000 appear where there is no stream line.
  • On a 1 m lidar DEM, man-made features such as road ditches and cut slopes can push SPI up. Check high-value cells against aerial imagery or in the field.

Next session

SPI only measures the relative size of the erosive force. With the same SCA and slope, Whitebox SedimentTransportIndex produces a value corresponding to the slope-length factor (LS) of the soil loss equation (RUSLE). Next time I plan to check whether this SPI and an LS-type index rank the two basins in the same order.

Work notes

This session was run by a QGIS startup script that filled in the same dialogs and ran them, and the screens are captures from that run. The original project was left untouched and the work was done in a copy (QGIS_Play_NaGeoAI_20261120_31_spi.qgz). The data source is USGS 3DEP (The National Map) tile 13SDE474426, and the original DTM is not redistributed. Figure 5, the percentiles, the top 1% share, the geometric means and their split, the stream-cell statistics and the independent check come from a separate script that re-reads the output files. QGIS 3.44.15, WhiteboxTools v2.2.0 (wbt_for_qgis plugin). First 12 characters of SHA-256:

  • Input specific contributing area 371c0096063a
  • Input slope 0971ac9f4ce6
  • Stream power index 17a50232deb2
  • Zonal statistics .shp / .dbf 235891ed214a / eb9cdcb01867

This is an English adaptation of a post in the Korean Whitebox QGIS practice series. The original is here.

This post was drafted with the help of AI tools and reviewed by the author. Tool features and data portals change over time, so check the official documentation when you practice.

Comments

Popular posts from this blog

What Is GeoAI, and How Does It Help Disaster Safety?

Getting Started with QGIS: What to Do First

Whitebox QGIS Practice 26 — Elevation Statistics of Two Basins: Means of 2,000.1 m and 1,924.3 m, a 76 m Gap