
Carry donor gauges' year-to-year departures onto an ungauged site
Source:R/wet_departure_carry.R
wet_departure_carry.RdGives a site with no record of its own (or a short one) the departure of
each year from normal, as the weighted mean of its donor gauges'
departures. Each donor's departure is taken from its own baseline mean, so
a donor's size does not matter, only how its years vary. The donors are
the k gauges nearest the target in predictor space (easting and
northing in km in BC Albers, EPSG:3005, and log drainage area, each
divided by its standard deviation over stations), weighted by inverse
distance as the monthly shares' and the daily shape's donors are. In a year
a donor has no value, it is dropped and the remaining weights renormalised
to sum to 1; a year no donor has is not returned.
Usage
wet_departure_carry(
x,
stations,
target,
k = 5,
baseline = 1981:2010,
min_baseline = 10,
weights = c("distance", "covariance", "covariance_pick"),
modelled = NULL
)Arguments
- x
Window statistics in
wet_window_stats()'s long format (station_number,variable,period,year,value) for the donors and, if it has any record, the target. Eachvariableandperiodis carried on its own. Every donor chosen must have at leastmin_baselineyears inbaseline.- stations
data.frame(station_number, lon, lat, drainage_area_gross_km2), as fromwet_station_select(), with a row for the target and every station inx.- target
The target's station number, or any id with a row in
stations.- k
Number of donors.
- baseline
Baseline years.
- min_baseline
Fewest baseline years a donor needs, and the target needs for
value.- weights
How the donors are weighted.
"distance"(the default): theknearest, by inverse distance."covariance": the samek, each weight multiplied bymax(r, 0), whereris the correlation between the target's and the donor's modelled values inmodelled(log values for flow, days for*_cov_day) over the years both have; anrfrom fewer than 30 years, or undefined, counts as 0."covariance_pick": among the 15 nearest, thekwith the highestr, weighted bymax(r, 0)alone. Where every donor chosen weighs 0, the covariance options fall back to"distance"for that statistic.- modelled
For the covariance options only: modelled values in
x's long format, such as routed PCIC flow at each gauge's segment fromwet_routed_years()throughwet_window_stats(), with rows for the target and every donor the option considers. A station with rows for some statistics and none for another (a segment routed to 0 has no*_cov_day) has no years there, so itsris 0.
Value
A data frame: station_number (the target), variable, period,
year, anomaly (log, or days for *_cov_day), pct_normal,
n_donors (present that year), donors ("station:weight" pairs
used that year, separated by spaces) and value: the target's baseline
mean carried by the anomaly, only where the target has its own
baseline in x, else NA. Under the covariance options each pair in
donors also carries the donor's r ("station:weight:r"), and a
column weighting says which weighting was used: the option, or
"distance" where it fell back.
Details
A departure is a log ratio, log(value / baseline mean), reported also as
percent of normal, 100 * (exp(anomaly) - 1), the scale
cd::cd_anomaly() uses. A statistic named *_cov_day (a day of the
window) departs in days instead, and has no percent of normal.
How donors are chosen
The nearest gauge is not always the most alike: a gauge next door can sit
higher or hold more snow. weights = "covariance_pick" lets a model of
the rivers choose instead, in five steps, for each statistic and window on
its own:
The model's years.
modelledholds a modelled value per year at the target and at each candidate donor, such as routed PCIC flow on each one's stream segment, 1951–2012.Departures. Each place's modelled years become departures from its own mean, on the log scale (days for
*_cov_day), so a big river and a small creek can both have a "20 % wetter than usual" year.How alike. For each candidate,
ris the correlation between its modelled departures and the target's over the years both have: 1 when they rise and fall together, 0 when they are unrelated. Fewer than 30 shared years counts as 0.Pick and weight. Among the 15 candidates nearest the target (by position and catchment size, as for
"distance"), thekwith the highestrare kept, a tie going to the nearer, each weighted bymax(r, 0). If every one weighs 0, it falls back to"distance": theknearest, weighted by distance.Borrow measured years. In each year, the target's departure is the weighted mean of those donors' measured departures from their own baseline means, as with
"distance". The model only chooses the donors, so the target's own record never does, and the borrowed years run as long as the donors' records do.
With about 60 years, a correlation is uncertain by roughly 0.13, so
picking the top k partly rewards luck. Whether the model's choice
predicts better than distance is therefore a question for held-out
gauges, not for r: wet's chinook pilots use it at a site only where it
did.
Examples
# Two donors share a wet year in 1990; the target, ungauged, gets it too
yrs <- 1975:2000
wet <- ifelse(yrs == 1990, 1.5, 1)
x <- data.frame(station_number = rep(c("D1", "D2"), each = length(yrs)),
variable = "q_mean", period = "migration", year = rep(yrs, 2),
value = c(20 * wet, 300 * wet))
st <- data.frame(station_number = c("D1", "D2", "T"), lon = c(-126.6, -127.8, -126.5),
lat = c(54.4, 55.1, 54.3), drainage_area_gross_km2 = c(2300, 900, 360))
a <- wet_departure_carry(x, st, "T", k = 2)
a[a$year %in% 1989:1991, c("year", "anomaly", "pct_normal", "donors")]
#> year anomaly pct_normal donors
#> 15 1989 -0.02469261 -2.439024 D1:0.5770 D2:0.4230
#> 16 1990 0.38077250 46.341463 D1:0.5770 D2:0.4230
#> 17 1991 -0.02469261 -2.439024 D1:0.5770 D2:0.4230