Add precip module + SCS-CN equation: end-to-end rainfall->runoff pipeline#14
Merged
Conversation
…line
Closes the rainfall-runoff loop with synthetic precipitation. floodpath
now turns ANY precipitation depth raster into a per-cell runoff depth
raster via SCS-CN, with no pending data-source decision blocking the
pipeline. Real precipitation fetchers (ERA5 / IMERG / CHIRPS) plug into
this same interface in a follow-up.
floodpath.precip:
- PrecipGrid: depth (mm) + georef + source attribution + optional
(start, end) UTC window. total_volume_m3() helper for water-balance
diagnostics.
- uniform_precip(bbox, transform, shape, depth_mm) and
uniform_precip_like(grid, depth_mm) — synthetic spatially-flat input.
floodpath.runoff (extended):
- runoff.apply_scs_cn(cn, precip, initial_abstraction_ratio=0.2):
the SCS-CN equation
S = 25400/CN - 254
Ia = lambda * S
Q = (P - Ia)^2 / (P - Ia + S) if P > Ia, else 0
Defaults to NEH 630 Ch10's lambda=0.2; users can pass 0.05 for newer
calibrations. CN nodata propagates as NaN in Q (so consumers can
distinguish unmodelled cells from no-runoff cells).
- RunoffGrid: Q (mm) + georef + precip_source + stats() ignoring NaN.
Tests: 24 new — 6 for PrecipGrid + uniform_precip helpers, 18 for the
SCS-CN equation including pinned values at canonical CN/P pairs,
asymptotic limit (Q -> P - 1.2*S as P -> infinity), monotonicity in CN,
nodata propagation, custom lambda, and shape-mismatch errors. End-to-end
sanity: 100 mm uniform rain on the Robit Bata fixtures yields
mean Q = 67.5 mm, runoff coefficient C = Q/P = 0.674 (high — consistent
with the all-D HSG / cropland-dominant patch).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Why now (per discussion)
Building a uniform-precip input first lets us validate the SCS-CN math and the whole chain (landuse + soil → CN → Q) before tackling the precip data-source choice. When ERA5/IMERG/CHIRPS lands later, it returns a `PrecipGrid` and feeds the same `apply_scs_cn` — no consumer change.
Resolution alignment (the question that motivated this PR)
Each layer keeps its native resolution; `compute_curve_number` already upsamples HSG (~250 m) to the landuse grid (10 m) via nearest-neighbour. The eventual common grid for routing will be DEM 30 m; that reprojection step properly belongs to the routing module (next milestone after a real precip source).
Test plan
Notes