Skip to contents

This function can be used to calculate new farmR variables that account for events occurring n_step to 0 time steps before, or 0 to n_step time steps after a certain reference point in time (t_0). Decreasing weights are assigned to the considered time steps before or after the reference point using an exponential decay function with a certain decay_rate.

Usage

variable_decay(variable, n_steps, decay_rate)

Arguments

variable

Tibble of input variable were each columns is a subbasin and each row is a time step. The variables from the farmR object can also be used as is.

n_steps

Numeric value for the number of times steps before or after the reference point. Negative values consider time steps before and positive values after.

decay_rate

Numeric value that controls the rate of decay for the values of the time steps before or after.

Details

Application examples can be the consideration of antecedent precipitation, where recent events are more relevant than events that are several days ago (can act as a proxy for soil moisture).

Examples

if (FALSE) {
# Unit input, varying decay rates:
x <- data.frame(x_1 = c(0,0,0,0,1,0,0,0,0,0,0,0,0,0,0))
y1<- variable_decay(x, -10, 1)
y2<- variable_decay(x, -10, 0.8)
y3<- variable_decay(x, -10, 0.25)

plot(y1$x_1, type = "l", col = 1)
lines(y2$x_1, col = 2)
lines(y3$x_1, col = 3)

# Antecedent precipitation index with 5 time steps and a decay rate of 0.8:
pcp <- data.frame(pcp_1 = c(0,3,7,10,2,0,0,5,2,0))
time_steps <- -5
rate <- 0.8
api <- variable_decay(pcp, time_steps, rate)
plot(pcp$pcp_1, ylim = c(0,15), pch = 3)
lines(api$pcp_1)
}