From b9cb2657f2cbcf6be00d3367547d7866a2a9acf5 Mon Sep 17 00:00:00 2001 From: jbedia Date: Fri, 21 Jul 2017 09:43:58 +0200 Subject: [PATCH] Update/add on-screen messages --- R/petGrid.R | 2 ++ R/speiGrid.R | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/R/petGrid.R b/R/petGrid.R index 410be39..b250754 100644 --- a/R/petGrid.R +++ b/R/petGrid.R @@ -79,9 +79,11 @@ petGrid <- function(tasmin = NULL, method = c("thornthwaite", "hargreaves"), ...) { method <- match.arg(method, choices = c("thornthwaite", "hargreaves")) + message("[", Sys.time(), "] Computing PET-", method, " ...") out <- switch(method, "thornthwaite" = petGrid.th(tas, ...), "hargreaves" = petGrid.har(tasmin, tasmax, pr, ...)) + message("[", Sys.time(), "] Done") ## Recover the grid structure ----------------------- coords <- getCoordinates(out$ref.grid) pet.grid <- out$ref.grid diff --git a/R/speiGrid.R b/R/speiGrid.R index ce41465..8177949 100644 --- a/R/speiGrid.R +++ b/R/speiGrid.R @@ -50,7 +50,7 @@ speiGrid <- function(pr.grid, et0.grid = NULL, scale = 3, ...) { coords <- getCoordinates(pr.grid) dimNames <- getDim(pr.grid) n.mem <- getShape(pr.grid, "member") - method <- ifelse(is.null(et0.grid), "SPI", "SPEI") + method <- paste(ifelse(is.null(et0.grid), "SPI", "SPEI"), scale, sep = "-") message("[", Sys.time(), "] Computing ", method, " ...") spei.list <- lapply(1:n.mem, function(x) { pr <- subsetGrid(pr.grid, members = x, drop = TRUE) %>% extract2("Data") %>% array3Dto2Dmat() @@ -68,8 +68,8 @@ speiGrid <- function(pr.grid, et0.grid = NULL, scale = 3, ...) { pr.grid$Data <- do.call("abind", c(spei.list, along = -1L)) %>% unname() attr(pr.grid$Data, "dimensions") <- dimNames pr.grid <- redim(pr.grid, drop = TRUE) - pr.grid$Variable$varName <- paste(method, scale, sep = "_") - longname <- ifelse(method == "SPI", "Standardized Precipitation Index", "Standardized Precipitation-Evapotranspiration Index") + pr.grid$Variable$varName <- method + longname <- ifelse(grepl("SPI", method), "Standardized Precipitation Index", "Standardized Precipitation-Evapotranspiration Index") attr(pr.grid$Variable, "longname") <- paste(longname, scale) attr(pr.grid$Variable, "units") <- "n/d" attr(pr.grid$Variable, "daily_agg_cellfun") <- "sum"