The water balance's daily shape within the month (#70): where a month's
water falls among its days, carried from gauges to ungauged watersheds. A
gauge's within-month weights w are its day-of-year flow divided by its
month's total (wet_station_doy(), then the internal
wet_shape_within()), so each month's weights sum to 1. Two methods:
Arguments
- d
data.frameof the gauges, with thestaticcolumns.- w
Matrix of within-month weights, one row per row of
dand 365 columns (a common year).- method
"donor"or"basis".- static
Names of the predictor columns in
d.- k
Donors per watershed (
"donor"), capped at the number of gauges.- n_comp
Principal components kept (
"basis"), capped at the rank.Optional matrix of the gauges' 12 monthly shares (
"basis"only); a fit made with them needs them at prediction too.
Details
"donor": a new watershed takes the inverse-distance mean of the weights of itsknearest gauges in the space of thestaticpredictors, each divided by the gauges' standard deviation. Distance weights are1 / (d + 1e-6 * median(d)); a gauge at distance 0 takes the whole weight."basis": principal components of the gauges' centred ratio to flat (w * days), the firstn_comp, whose scores are regressed by ordinary least squares on thestaticpredictors and, when given, the 12 monthlyshares. A prediction is reconstructed, floored at 0 and renormalised per month; a month whose reconstruction is all 0 or less falls back to flat.
Both apply through wet_shape_predict(), and wet_shape_daily() turns
monthly means and weights into daily flows that keep every monthly mean.
Examples
set.seed(1)
m <- wet:::wet_doy_month()
# eight gauges: a freshet whose timing within May moves with elevation
d <- data.frame(elev = seq(300, 2000, length.out = 8), e_km = 1:8, n_km = 8:1)
q <- t(sapply(d$elev, function(e) dnorm(1:365, 120 + e / 50, 30) + 1e-3))
w <- wet:::wet_shape_within(q)
fit <- wet_shape_fit(d, w, "donor", static = c("elev", "e_km", "n_km"), k = 3)
w_new <- wet_shape_predict(fit, data.frame(elev = 1000, e_km = 4.5, n_km = 4.5))
tapply(w_new[1, ], m, sum) # each month sums to 1
#> 1 2 3 4 5 6 7 8 9 10 11 12
#> 1 1 1 1 1 1 1 1 1 1 1 1
