Skip to content

Commit

Permalink
cwd -> cwb
Browse files Browse the repository at this point in the history
we are computing the balance (P-PET), not the deficit (PET-P)
  • Loading branch information
Christian Zang committed Oct 8, 2019
1 parent c23cccc commit 239f20c
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions R/add_indices.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ add_indices <- function(x, scales = c(1, 2, 3, 6, 12), id = "id", lat = "lat", t
ts_prec <- stats::ts(.x[[prec]], start = c(.x$year[1], .x$month[1]), frequency = 12)
ts_pet <- SPEI::hargreaves(ts_tmin, ts_tmax, Ra = NA, lat = .lat, Pre = ts_prec)
ts_cwb <- ts_prec - ts_pet
.x$cwd <- round(as.vector(ts_cwb), 2)
.x$cwb <- round(as.vector(ts_cwb), 2)
spei <- lapply(scales, function(x) round(SPEI::spei(ts_cwb, scale = x)$fitted, 2))
spi <- lapply(scales, function(x) round(SPEI::spi(ts_prec, scale = x)$fitted, 2))
for (j in 1:n_scales) {
Expand All @@ -47,7 +47,7 @@ add_indices <- function(x, scales = c(1, 2, 3, 6, 12), id = "id", lat = "lat", t
}
} else {
## write NA dummy output
.x$dmi <- .x$cwd <- NA_real_
.x$dmi <- .x$cwb <- NA_real_
for (j in 1:n_scales) {
spei_name <- paste0("spei", scales[j])
.x[[spei_name]] <- NA_real_
Expand Down

0 comments on commit 239f20c

Please sign in to comment.