From 85b4e51dbe599437a264c63933e5b06c18d79b10 Mon Sep 17 00:00:00 2001 From: Eroteida Sanchez Garcia Date: Mon, 9 Mar 2020 12:05:16 +0000 Subject: [PATCH 1/6] Uploading function 'PlotPDFsOLE.R' --- NAMESPACE | 1 + R/PlotPDFsOLE.R | 240 +++++++++++++++++++++++++++ man/Analogs.Rd | 16 +- man/BEI_PDFBest.Rd | 13 +- man/CST_Analogs.Rd | 11 +- man/CST_Anomaly.Rd | 3 +- man/CST_BEI_Weighting.Rd | 9 +- man/CST_Calibration.Rd | 12 +- man/CST_CategoricalEnsCombination.Rd | 10 +- man/CST_EnsClustering.Rd | 16 +- man/CST_MergeDims.Rd | 8 +- man/CST_MultiEOF.Rd | 10 +- man/CST_QuantileMapping.Rd | 13 +- man/CST_RainFARM.Rd | 17 +- man/CST_SplitDim.Rd | 3 +- man/Calibration.Rd | 12 +- man/EnsClustering.Rd | 18 +- man/MergeDims.Rd | 8 +- man/MultiEOF.Rd | 16 +- man/PlotCombinedMap.Rd | 26 +-- man/PlotForecastPDF.Rd | 17 +- man/PlotMostLikelyQuantileMap.Rd | 11 +- man/PlotPDFsOLE.Rd | 59 +++++++ man/RFSlope.Rd | 3 +- man/RainFARM.Rd | 22 +-- man/s2dv_cube.Rd | 12 +- 26 files changed, 365 insertions(+), 221 deletions(-) create mode 100644 R/PlotPDFsOLE.R create mode 100644 man/PlotPDFsOLE.Rd diff --git a/NAMESPACE b/NAMESPACE index bd5d0f16..78954a95 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -27,6 +27,7 @@ export(MultiEOF) export(PlotCombinedMap) export(PlotForecastPDF) export(PlotMostLikelyQuantileMap) +export(PlotPDFsOLE) export(RFSlope) export(RainFARM) export(SplitDim) diff --git a/R/PlotPDFsOLE.R b/R/PlotPDFsOLE.R new file mode 100644 index 00000000..760798f2 --- /dev/null +++ b/R/PlotPDFsOLE.R @@ -0,0 +1,240 @@ +#' Plotting two probability density gaussian functions and the optimal linear +#' estimation (OLE) as result of combining them. +#' +#' @author Eroteida Sanchez-Garcia - AEMET, //email{esanchezg@aemet.es} +#' +#' @description This function plots two probability density gaussian functions +#' and the optimal linear estimation (OLE) as result of combining them. +#' +#' @param pdf_1 A numeric array with a dimension named 'statistic', containg +#' two parameters: mean' and 'standard deviation' of the first gaussian pdf +#' to combining. +#' @param pdf_2 A numeric array with a dimension named 'statistic', containg +#' two parameters: mean' and 'standard deviation' of the second gaussian pdf +#' to combining. +#' @param nsigma (optional) A numeric value for setting the limits of X axis. +#' (Default nsigma = 3). +#' @param plotfile (optional) A filename where the plot will be saved. +#' (Default: the plot is not saved). +#' @param width (optional) A numeric value indicating the plot width in +#' units ("in", "cm", or "mm"). (Default width = 30). +#' @param height (optional) A numeric value indicating the plot height. +#' (Default height = 15). +#' @param units (optional) A character value indicating the plot size +#' unit. (Default units = 'cm'). +#' @param dpi (optional) A numeric value indicating the plot resolution. +#' (Default dpi = 300). +#' +#' @return PlotPDFsOLE() returns a ggplot object containing the plot. +#' +#' @import ggplot2 +#' +#' @examples +#' Example for PlotPDFs function +#' pdf_1 <- c(1.1,0.6) +#' attr(pdf_1, "name") <- "NAO1" +#' dim(pdf_1) <- c(statistic = 2) +#' pdf_2 <- c(1,0.5) +#' attr(pdf_2, "name") <- "NAO2" +#' dim(pdf_2) <- c(statistic = 2) +#' +#' PlotPDFsOLE(pdf_1, pdf_2) +#' +#'@export +PlotPDFsOLE <- function(pdf_1, pdf_2, nsigma = 3, plotfile = NULL, + width = 30, height = 15, + units = "cm", dpi = 300) { + + if (!is.numeric(dpi)) { + stop("Parameter 'dpi' must be numeric.") + } + if (length(dpi) > 1) { + warning("Parameter 'dpi' has length greater than 1 and ", + "only the first element will be used.") + dpi <- dpi[1] + } + if (!is.character(units)) { + stop("Parameter 'units' must be character") + } + if (length(units) > 1) { + warning("Parameter 'units' has length greater than 1 and ", + "only the first element will be used.") + units <- units[1] + } + if(!(units %in% c("in", "cm", "mm"))) { + stop("Parameter 'units' must be equal to 'in', 'cm' or 'mm'.") + } + if (!is.numeric(height)) { + stop("Parameter 'height' must be numeric.") + } + if (length(height) > 1) { + warning("Parameter 'height' has length greater than 1 and ", + "only the first element will be used.") + height <- height[1] + } + if (!is.numeric(width)) { + stop("Parameter 'width' must be numeric.") + } + if (length(width) > 1) { + warning("Parameter 'width' has length greater than 1 and ", + "only the first element will be used.") + width <- width[1] + } + if(!is.null(plotfile)){ + if (!is.character(plotfile)) { + stop("Parameter 'plotfile' must be a character string ", + "indicating the path and name of output png file.") + } + } + if (!is.numeric(nsigma)) { + stop("Parameter 'nsigma' must be numeric.") + } + if (length(nsigma) > 1) { + warning("Parameter 'nsigma' has length greater than 1 and ", + "only the first element will be used.") + nsigma <- nsigma[1] + } + if (!is.array(pdf_1)) { + stop("Parameter 'pdf_1' must be an array.") + } + if (!is.array(pdf_2)) { + stop("Parameter 'pdf_2' must be an array.") + } + if (!is.numeric(pdf_1)) { + stop("Parameter 'pdf_1' must be a numeric array.") + } + if (!is.numeric(pdf_2)) { + stop("Parameter 'pdf_2' must be a numeric array.") + } + if (is.null(names(dim(pdf_1))) || + is.null(names(dim(pdf_2)))) { + stop("Parameters 'pdf_1' and 'pdf_2' ", + "should have dimmension names.") + } + if(!('statistic' %in% names(dim(pdf_1)))) { + stop("Parameter 'pdf_1' must have dimension 'statistic.") + } + if(!('statistic' %in% names(dim(pdf_2)))) { + stop("Parameter 'pdf_2' must have dimension 'statistic.") + } + if (length(dim(pdf_1)) != 1) { + stop("Parameter 'pdf_1' must have only dimension 'statistic.") + } + if (length(dim(pdf_2)) != 1) { + stop("Parameter 'pdf_2' must have only dimension 'statistic.") + } + if ((dim(pdf_1)['statistic'] != 2) & (dim(pdf_2)['statistic'] != 2)) { + stop("Length of dimension 'statistic'", + "of parameter 'pdf_1' and 'pdf_2' must be equal to 2.") + } + if(!is.null(attr(pdf_1, "name"))){ + if(!is.character(attr(pdf_1, "name"))){ + stop("The 'name' attribute of parameter 'pdf_1' must be a character ", + "indicating the name of the variable of parameter 'pdf_1'.") + } + } + if(is.null(attr(pdf_1, "name"))){ + name1 <- "variable 1" + } else { + name1 <- attr(pdf_1, "name") + } + if(is.null(attr(pdf_2, "name"))){ + name2 <- "Variable 2" + } else { + name2 <- attr(pdf_2, "name") + } + + #----------------------------------------------------------------------------- + # Set parameters of gaussian distributions (mean and sd) + #----------------------------------------------------------------------------- + mean1 <- pdf_1[1] + sigma1 <- pdf_1[2] + mean2 <- pdf_2[1] + sigma2 <- pdf_2[2] + pdfBest <- CombinedPDFs(pdf_1, pdf_2) + meanBest <- pdfBest[1] + sigmaBest <- pdfBest[2] + + + #----------------------------------------------------------------------------- + # Plot the gaussian distributions + #----------------------------------------------------------------------------- + nameBest <- paste0(name1, " + ", name2) + graphicTitle <- "OPTIMAL LINEAR ESTIMATION" + xlimSup <- max(nsigma*sigmaBest+meanBest, nsigma*sigma1+mean1, + nsigma*sigma2+mean2) + xlimInf <- min(-nsigma*sigmaBest+meanBest, -nsigma*sigma1+mean1, + -nsigma*sigma2+mean2) + # deltax <- 0.02 + deltax <- (xlimSup - xlimInf)/10000 + + x <- seq(xlimInf,xlimSup,deltax) + df1 <- data.frame(x=x,y=dnorm(x,mean=mean1, sd=sigma1), + type=name1) + df2 <- data.frame(x=x,y=dnorm(x,mean=mean2, sd=sigma2), + type=name2) + df3 <- data.frame(x=x,y=dnorm(x,mean=meanBest, sd=sigmaBest), + type=nameBest) + df123 <- rbind(df1,df2,df3) + label1 <- paste0(name1, ": N(mean=",round(mean1,2),", sd=", round(sigma1,2), + ")") + label2 <- paste0(name2, ": N(mean=",round(mean2,2),", sd=", round(sigma2,2), + ")") + labelBest <- paste0(nameBest, ": N(mean=",round(meanBest,2),", sd=", + round(sigmaBest,2), ")") + cols <- c("#DC3912", "#13721A", "#1F5094") + names(cols) <- c(name1, name2, nameBest) + g <- ggplot(df123)+geom_line(aes(x,y,colour=type), size=rel(1.2)) + + g <- g + scale_colour_manual(values = cols, + limits = c(name1, name2, nameBest), + labels = c(label1, label2, labelBest)) + g <- g + theme(plot.title=element_text(size=rel(1.1), colour="black", + face= "bold"), + axis.text.x = element_text(size=rel(1.2)), + axis.text.y = element_text(size=rel(1.2)), + axis.title.x = element_blank(), + legend.title = element_blank(), + legend.position = c(1,1), legend.justification = c(1,1), + legend.text = element_text(face = "bold")) + g <- g + ggtitle(graphicTitle) + g <- g + labs(y="probability", size=rel(1.9)) + g <- g + stat_function(fun = dnorm_limit, args = list(mean=mean1, sd=sigma1), + fill = cols[name1], alpha=0.2, geom="area") + g <- g + stat_function(fun = dnorm_limit, args = list(mean=mean2, sd=sigma2), + fill = cols[name2], alpha=0.2, geom="area") + g <- g + stat_function(fun = dnorm_limit, args = list(mean=meanBest, + sd=sigmaBest), + fill = cols[nameBest], alpha=0.2, geom="area") + + + #----------------------------------------------------------------------------- + # Save to plotfile if needed, and return plot + #----------------------------------------------------------------------------- + if (!is.null(plotfile)) { + ggsave(plotfile, g, width = width, height = height, + units = units, dpi = dpi) + } + return(g) +} + +# Auxiliar function to plot +CombinedPDFs <- function(pdf_1, pdf_2) { + mean_1 <- pdf_1[1] + sigma_1 <- pdf_1[2] + mean_2 <- pdf_2[1] + sigma_2 <- pdf_2[2] + a_1 <- (sigma_2^2)/((sigma_1^2)+(sigma_2^2)) + a_2 <- (sigma_1^2)/((sigma_1^2)+(sigma_2^2)) + pdf_mean <- a_1*mean_1 + a_2*mean_2 + pdf_sigma <- sqrt((sigma_1^2)*(sigma_2^2)/((sigma_1^2)+(sigma_2^2))) + data <- c(pdf_mean, pdf_sigma) + dim(data) <- c(statistic = 2) + return(data) +} + +dnorm_limit <- function(x,mean,sd){ + y <- dnorm(x,mean,sd) + y[x mean+sd] <- NA + return(y) +} diff --git a/man/Analogs.Rd b/man/Analogs.Rd index 06107c07..52d9ff97 100644 --- a/man/Analogs.Rd +++ b/man/Analogs.Rd @@ -4,19 +4,9 @@ \alias{Analogs} \title{Analogs based on large scale fields.} \usage{ -Analogs( - expL, - obsL, - time_obsL, - expVar = NULL, - obsVar = NULL, - criteria = "Large_dist", - lonVar = NULL, - latVar = NULL, - region = NULL, - nAnalogs = NULL, - return_list = FALSE -) +Analogs(expL, obsL, time_obsL, expVar = NULL, obsVar = NULL, + criteria = "Large_dist", lonVar = NULL, latVar = NULL, + region = NULL, nAnalogs = NULL, return_list = FALSE) } \arguments{ \item{expL}{an array of N named dimensions containing the experimental field diff --git a/man/BEI_PDFBest.Rd b/man/BEI_PDFBest.Rd index 0ba24a84..f120258d 100644 --- a/man/BEI_PDFBest.Rd +++ b/man/BEI_PDFBest.Rd @@ -4,16 +4,9 @@ \alias{BEI_PDFBest} \title{Computing the Best Index PDFs combining Index PDFs from two SFSs} \usage{ -BEI_PDFBest( - index_obs, - index_hind1, - index_hind2, - index_fcst1 = NULL, - index_fcst2 = NULL, - method_BC = "none", - time_dim_name = "time", - na.rm = FALSE -) +BEI_PDFBest(index_obs, index_hind1, index_hind2, index_fcst1 = NULL, + index_fcst2 = NULL, method_BC = "none", time_dim_name = "time", + na.rm = FALSE) } \arguments{ \item{index_obs}{Index (e.g. NAO index) array from an observational database diff --git a/man/CST_Analogs.Rd b/man/CST_Analogs.Rd index d7dd5e14..c9166de6 100644 --- a/man/CST_Analogs.Rd +++ b/man/CST_Analogs.Rd @@ -4,15 +4,8 @@ \alias{CST_Analogs} \title{Downscaling using Analogs based on large scale fields.} \usage{ -CST_Analogs( - expL, - obsL, - time_obsL, - expVar = NULL, - obsVar = NULL, - region = NULL, - criteria = "Large_dist" -) +CST_Analogs(expL, obsL, time_obsL, expVar = NULL, obsVar = NULL, + region = NULL, criteria = "Large_dist") } \arguments{ \item{expL}{an 's2dv_cube' object containing the experimental field on the diff --git a/man/CST_Anomaly.Rd b/man/CST_Anomaly.Rd index 07691ea7..b214a31a 100644 --- a/man/CST_Anomaly.Rd +++ b/man/CST_Anomaly.Rd @@ -4,7 +4,8 @@ \alias{CST_Anomaly} \title{Anomalies relative to a climatology along selected dimension with or without cross-validation} \usage{ -CST_Anomaly(exp = NULL, obs = NULL, cross = FALSE, memb = TRUE, dim_anom = 3) +CST_Anomaly(exp = NULL, obs = NULL, cross = FALSE, memb = TRUE, + dim_anom = 3) } \arguments{ \item{exp}{an object of class \code{s2dv_cube} as returned by \code{CST_Load} function, containing the seasonal forecast experiment data in the element named \code{$data}.} diff --git a/man/CST_BEI_Weighting.Rd b/man/CST_BEI_Weighting.Rd index d6f65bb5..9c0f5a9d 100644 --- a/man/CST_BEI_Weighting.Rd +++ b/man/CST_BEI_Weighting.Rd @@ -4,13 +4,8 @@ \alias{CST_BEI_Weighting} \title{Weighting SFSs of a CSTools object.} \usage{ -CST_BEI_Weighting( - var_exp, - aweights, - terciles = NULL, - type = "ensembleMean", - time_dim_name = "time" -) +CST_BEI_Weighting(var_exp, aweights, terciles = NULL, + type = "ensembleMean", time_dim_name = "time") } \arguments{ \item{var_exp}{An object of the class 's2dv_cube' containing the variable diff --git a/man/CST_Calibration.Rd b/man/CST_Calibration.Rd index 891e2e5f..c357fac5 100644 --- a/man/CST_Calibration.Rd +++ b/man/CST_Calibration.Rd @@ -4,15 +4,9 @@ \alias{CST_Calibration} \title{Forecast Calibration} \usage{ -CST_Calibration( - exp, - obs, - cal.method = "mse_min", - eval.method = "leave-one-out", - multi.model = F, - na.fill = T, - ncores = 1 -) +CST_Calibration(exp, obs, cal.method = "mse_min", + eval.method = "leave-one-out", multi.model = F, na.fill = T, + ncores = 1) } \arguments{ \item{exp}{an object of class \code{s2dv_cube} as returned by \code{CST_Load} function, containing the seasonal forecast experiment data in the element named \code{$data}.} diff --git a/man/CST_CategoricalEnsCombination.Rd b/man/CST_CategoricalEnsCombination.Rd index c23f8341..7175b7fe 100644 --- a/man/CST_CategoricalEnsCombination.Rd +++ b/man/CST_CategoricalEnsCombination.Rd @@ -4,14 +4,8 @@ \alias{CST_CategoricalEnsCombination} \title{Make categorical forecast based on a multi-model forecast with potential for calibrate} \usage{ -CST_CategoricalEnsCombination( - exp, - obs, - cat.method = "pool", - eval.method = "leave-one-out", - amt.cat = 3, - ... -) +CST_CategoricalEnsCombination(exp, obs, cat.method = "pool", + eval.method = "leave-one-out", amt.cat = 3, ...) } \arguments{ \item{exp}{an object of class \code{s2dv_cube} as returned by \code{CST_Load} function, containing the seasonal forecast experiment data in the element named \code{$data}. The amount of forecasting models is equal to the size of the \code{dataset} dimension of the data array. The amount of members per model may be different. The size of the \code{member} dimension of the data array is equal to the maximum of the ensemble members among the models. Models with smaller ensemble sizes have residual indices of \code{member} dimension in the data array filled with NA values.} diff --git a/man/CST_EnsClustering.Rd b/man/CST_EnsClustering.Rd index 154541d5..de71d4e3 100644 --- a/man/CST_EnsClustering.Rd +++ b/man/CST_EnsClustering.Rd @@ -4,18 +4,10 @@ \alias{CST_EnsClustering} \title{Ensemble clustering} \usage{ -CST_EnsClustering( - exp, - time_moment = "mean", - numclus = NULL, - lon_lim = NULL, - lat_lim = NULL, - variance_explained = 80, - numpcs = NULL, - time_percentile = 90, - cluster_dim = "member", - verbose = F -) +CST_EnsClustering(exp, time_moment = "mean", numclus = NULL, + lon_lim = NULL, lat_lim = NULL, variance_explained = 80, + numpcs = NULL, time_percentile = 90, cluster_dim = "member", + verbose = F) } \arguments{ \item{exp}{An object of the class 's2dv_cube', containing the variables to be analysed. diff --git a/man/CST_MergeDims.Rd b/man/CST_MergeDims.Rd index 0762e83f..2c483840 100644 --- a/man/CST_MergeDims.Rd +++ b/man/CST_MergeDims.Rd @@ -4,12 +4,8 @@ \alias{CST_MergeDims} \title{Function to Merge Dimensions} \usage{ -CST_MergeDims( - data, - merge_dims = c("ftime", "monthly"), - rename_dim = NULL, - na.rm = FALSE -) +CST_MergeDims(data, merge_dims = c("ftime", "monthly"), + rename_dim = NULL, na.rm = FALSE) } \arguments{ \item{data}{a 's2dv_cube' object} diff --git a/man/CST_MultiEOF.Rd b/man/CST_MultiEOF.Rd index 036a6470..5fea8a50 100644 --- a/man/CST_MultiEOF.Rd +++ b/man/CST_MultiEOF.Rd @@ -4,14 +4,8 @@ \alias{CST_MultiEOF} \title{EOF analysis of multiple variables} \usage{ -CST_MultiEOF( - datalist, - neof_max = 40, - neof_composed = 5, - minvar = 0.6, - lon_lim = NULL, - lat_lim = NULL -) +CST_MultiEOF(datalist, neof_max = 40, neof_composed = 5, + minvar = 0.6, lon_lim = NULL, lat_lim = NULL) } \arguments{ \item{datalist}{A list of objects of the class 's2dv_cube', containing the variables to be analysed. diff --git a/man/CST_QuantileMapping.Rd b/man/CST_QuantileMapping.Rd index ad8f4b6c..90319622 100644 --- a/man/CST_QuantileMapping.Rd +++ b/man/CST_QuantileMapping.Rd @@ -4,16 +4,9 @@ \alias{CST_QuantileMapping} \title{Quantiles Mapping for seasonal or decadal forecast data} \usage{ -CST_QuantileMapping( - exp, - obs, - exp_cor = NULL, - sample_dims = c("sdate", "ftime", "member"), - sample_length = NULL, - method = "QUANT", - ncores = NULL, - ... -) +CST_QuantileMapping(exp, obs, exp_cor = NULL, sample_dims = c("sdate", + "ftime", "member"), sample_length = NULL, method = "QUANT", + ncores = NULL, ...) } \arguments{ \item{exp}{an object of class \code{s2dv_cube}} diff --git a/man/CST_RainFARM.Rd b/man/CST_RainFARM.Rd index 1c609e08..0ed45f49 100644 --- a/man/CST_RainFARM.Rd +++ b/man/CST_RainFARM.Rd @@ -4,20 +4,9 @@ \alias{CST_RainFARM} \title{RainFARM stochastic precipitation downscaling of a CSTools object} \usage{ -CST_RainFARM( - data, - nf, - weights = 1, - slope = 0, - kmin = 1, - nens = 1, - fglob = FALSE, - fsmooth = TRUE, - nprocs = 1, - time_dim = NULL, - verbose = FALSE, - drop_realization_dim = FALSE -) +CST_RainFARM(data, nf, weights = 1, slope = 0, kmin = 1, nens = 1, + fglob = FALSE, fsmooth = TRUE, nprocs = 1, time_dim = NULL, + verbose = FALSE, drop_realization_dim = FALSE) } \arguments{ \item{data}{An object of the class 's2dv_cube' as returned by `CST_Load`, diff --git a/man/CST_SplitDim.Rd b/man/CST_SplitDim.Rd index ee93aedc..8ce20c97 100644 --- a/man/CST_SplitDim.Rd +++ b/man/CST_SplitDim.Rd @@ -4,7 +4,8 @@ \alias{CST_SplitDim} \title{Function to Split Dimension} \usage{ -CST_SplitDim(data, split_dim = "time", indices = NULL, freq = "monthly") +CST_SplitDim(data, split_dim = "time", indices = NULL, + freq = "monthly") } \arguments{ \item{data}{a 's2dv_cube' object} diff --git a/man/Calibration.Rd b/man/Calibration.Rd index 9f884671..cefc3f83 100644 --- a/man/Calibration.Rd +++ b/man/Calibration.Rd @@ -4,15 +4,9 @@ \alias{Calibration} \title{Forecast Calibration} \usage{ -Calibration( - exp, - obs, - cal.method = "mse_min", - eval.method = "leave-one-out", - multi.model = F, - na.fill = T, - ncores = 1 -) +Calibration(exp, obs, cal.method = "mse_min", + eval.method = "leave-one-out", multi.model = F, na.fill = T, + ncores = 1) } \arguments{ \item{exp}{an array containing the seasonal forecast experiment data.} diff --git a/man/EnsClustering.Rd b/man/EnsClustering.Rd index 2fd8a3f1..d7284ef5 100644 --- a/man/EnsClustering.Rd +++ b/man/EnsClustering.Rd @@ -4,20 +4,10 @@ \alias{EnsClustering} \title{Ensemble clustering} \usage{ -EnsClustering( - data, - lat, - lon, - time_moment = "mean", - numclus = NULL, - lon_lim = NULL, - lat_lim = NULL, - variance_explained = 80, - numpcs = NULL, - time_percentile = 90, - cluster_dim = "member", - verbose = T -) +EnsClustering(data, lat, lon, time_moment = "mean", numclus = NULL, + lon_lim = NULL, lat_lim = NULL, variance_explained = 80, + numpcs = NULL, time_percentile = 90, cluster_dim = "member", + verbose = T) } \arguments{ \item{data}{A matrix of dimensions 'dataset member sdate ftime lat lon' containing the variables to be analysed.} diff --git a/man/MergeDims.Rd b/man/MergeDims.Rd index 7539ef6e..d6b261ad 100644 --- a/man/MergeDims.Rd +++ b/man/MergeDims.Rd @@ -4,12 +4,8 @@ \alias{MergeDims} \title{Function to Split Dimension} \usage{ -MergeDims( - data, - merge_dims = c("time", "monthly"), - rename_dim = NULL, - na.rm = FALSE -) +MergeDims(data, merge_dims = c("time", "monthly"), rename_dim = NULL, + na.rm = FALSE) } \arguments{ \item{data}{an n-dimensional array with named dimensions} diff --git a/man/MultiEOF.Rd b/man/MultiEOF.Rd index dd0fc7fe..c38116de 100644 --- a/man/MultiEOF.Rd +++ b/man/MultiEOF.Rd @@ -4,19 +4,9 @@ \alias{MultiEOF} \title{EOF analysis of multiple variables starting from an array (reduced version)} \usage{ -MultiEOF( - data, - lon, - lat, - time, - lon_dim = "lon", - lat_dim = "lat", - neof_max = 40, - neof_composed = 5, - minvar = 0.6, - lon_lim = NULL, - lat_lim = NULL -) +MultiEOF(data, lon, lat, time, lon_dim = "lon", lat_dim = "lat", + neof_max = 40, neof_composed = 5, minvar = 0.6, lon_lim = NULL, + lat_lim = NULL) } \arguments{ \item{data}{A multidimensional array with dimension \code{"var"}, diff --git a/man/PlotCombinedMap.Rd b/man/PlotCombinedMap.Rd index 616b84f9..62e26904 100644 --- a/man/PlotCombinedMap.Rd +++ b/man/PlotCombinedMap.Rd @@ -4,27 +4,11 @@ \alias{PlotCombinedMap} \title{Plot Multiple Lon-Lat Variables In a Single Map According to a Decision Function} \usage{ -PlotCombinedMap( - maps, - lon, - lat, - map_select_fun, - display_range, - map_dim = "map", - brks = NULL, - cols = NULL, - col_unknown_map = "white", - mask = NULL, - col_mask = "grey", - bar_titles = NULL, - legend_scale = 1, - fileout = NULL, - width = 8, - height = 5, - size_units = "in", - res = 100, - ... -) +PlotCombinedMap(maps, lon, lat, map_select_fun, display_range, + map_dim = "map", brks = NULL, cols = NULL, + col_unknown_map = "white", mask = NULL, col_mask = "grey", + bar_titles = NULL, legend_scale = 1, fileout = NULL, width = 8, + height = 5, size_units = "in", res = 100, ...) } \arguments{ \item{maps}{List of matrices to plot, each with (longitude, latitude) dimensions, or 3-dimensional array with the dimensions (longitude, latitude, map). Dimension names are required.} diff --git a/man/PlotForecastPDF.Rd b/man/PlotForecastPDF.Rd index c04b43c1..3eee4e33 100644 --- a/man/PlotForecastPDF.Rd +++ b/man/PlotForecastPDF.Rd @@ -4,18 +4,11 @@ \alias{PlotForecastPDF} \title{Plot one or multiple ensemble forecast pdfs for the same event} \usage{ -PlotForecastPDF( - fcst, - tercile.limits, - extreme.limits = NULL, - obs = NULL, - plotfile = NULL, - title = "Set a title", - var.name = "Varname (units)", - fcst.names = NULL, - add.ensmemb = c("above", "below", "no"), - color.set = c("ggplot", "s2s4e", "hydro") -) +PlotForecastPDF(fcst, tercile.limits, extreme.limits = NULL, + obs = NULL, plotfile = NULL, title = "Set a title", + var.name = "Varname (units)", fcst.names = NULL, + add.ensmemb = c("above", "below", "no"), color.set = c("ggplot", + "s2s4e", "hydro")) } \arguments{ \item{fcst}{a dataframe or array containing all the ensember members for each forecast. If \code{'fcst'} is an array, it should have two labelled dimensions, and one of them should be \code{'members'}. If \code{'fcsts'} is a data.frame, each column shoul be a separate forecast, with the rows beeing the different ensemble members.} diff --git a/man/PlotMostLikelyQuantileMap.Rd b/man/PlotMostLikelyQuantileMap.Rd index 4c400b18..0d984ede 100644 --- a/man/PlotMostLikelyQuantileMap.Rd +++ b/man/PlotMostLikelyQuantileMap.Rd @@ -4,15 +4,8 @@ \alias{PlotMostLikelyQuantileMap} \title{Plot Maps of Most Likely Quantiles} \usage{ -PlotMostLikelyQuantileMap( - probs, - lon, - lat, - cat_dim = "bin", - bar_titles = NULL, - col_unknown_cat = "white", - ... -) +PlotMostLikelyQuantileMap(probs, lon, lat, cat_dim = "bin", + bar_titles = NULL, col_unknown_cat = "white", ...) } \arguments{ \item{probs}{a list of bi-dimensional arrays with the named dimensions 'latitude' (or 'lat') and 'longitude' (or 'lon'), with equal size and in the same order, or a single tri-dimensional array with an additional dimension (e.g. 'bin') for the different categories. The arrays must contain probability values between 0 and 1, and the probabilities for all categories of a grid cell should not exceed 1 when added.} diff --git a/man/PlotPDFsOLE.Rd b/man/PlotPDFsOLE.Rd new file mode 100644 index 00000000..14d42637 --- /dev/null +++ b/man/PlotPDFsOLE.Rd @@ -0,0 +1,59 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/PlotPDFsOLE.R +\name{PlotPDFsOLE} +\alias{PlotPDFsOLE} +\title{Plotting two probability density gaussian functions and the optimal linear +estimation (OLE) as result of combining them.} +\usage{ +PlotPDFsOLE(pdf_1, pdf_2, nsigma = 3, plotfile = NULL, width = 30, + height = 15, units = "cm", dpi = 300) +} +\arguments{ +\item{pdf_1}{A numeric array with a dimension named 'statistic', containg +two parameters: mean' and 'standard deviation' of the first gaussian pdf +to combining.} + +\item{pdf_2}{A numeric array with a dimension named 'statistic', containg +two parameters: mean' and 'standard deviation' of the second gaussian pdf + to combining.} + +\item{nsigma}{(optional) A numeric value for setting the limits of X axis. +(Default nsigma = 3).} + +\item{plotfile}{(optional) A filename where the plot will be saved. +(Default: the plot is not saved).} + +\item{width}{(optional) A numeric value indicating the plot width in +units ("in", "cm", or "mm"). (Default width = 30).} + +\item{height}{(optional) A numeric value indicating the plot height. +(Default height = 15).} + +\item{units}{(optional) A character value indicating the plot size +unit. (Default units = 'cm').} + +\item{dpi}{(optional) A numeric value indicating the plot resolution. +(Default dpi = 300).} +} +\value{ +PlotPDFsOLE() returns a ggplot object containing the plot. +} +\description{ +This function plots two probability density gaussian functions +and the optimal linear estimation (OLE) as result of combining them. +} +\examples{ +Example for PlotPDFs function +pdf_1 <- c(1.1,0.6) +attr(pdf_1, "name") <- "NAO1" +dim(pdf_1) <- c(statistic = 2) +pdf_2 <- c(1,0.5) +attr(pdf_2, "name") <- "NAO2" +dim(pdf_2) <- c(statistic = 2) + +PlotPDFsOLE(pdf_1, pdf_2) + +} +\author{ +Eroteida Sanchez-Garcia - AEMET, //email{esanchezg@aemet.es} +} diff --git a/man/RFSlope.Rd b/man/RFSlope.Rd index db3f0e10..5308ef8c 100644 --- a/man/RFSlope.Rd +++ b/man/RFSlope.Rd @@ -4,7 +4,8 @@ \alias{RFSlope} \title{RainFARM spectral slopes from an array (reduced version)} \usage{ -RFSlope(data, kmin = 1, time_dim = NULL, lon_dim = "lon", lat_dim = "lat") +RFSlope(data, kmin = 1, time_dim = NULL, lon_dim = "lon", + lat_dim = "lat") } \arguments{ \item{data}{Array containing the spatial precipitation fields to downscale. diff --git a/man/RainFARM.Rd b/man/RainFARM.Rd index 0db84679..e0fa9a10 100644 --- a/man/RainFARM.Rd +++ b/man/RainFARM.Rd @@ -4,24 +4,10 @@ \alias{RainFARM} \title{RainFARM stochastic precipitation downscaling (reduced version)} \usage{ -RainFARM( - data, - lon, - lat, - nf, - weights = 1, - nens = 1, - slope = 0, - kmin = 1, - fglob = FALSE, - fsmooth = TRUE, - nprocs = 1, - time_dim = NULL, - lon_dim = "lon", - lat_dim = "lat", - drop_realization_dim = FALSE, - verbose = FALSE -) +RainFARM(data, lon, lat, nf, weights = 1, nens = 1, slope = 0, + kmin = 1, fglob = FALSE, fsmooth = TRUE, nprocs = 1, + time_dim = NULL, lon_dim = "lon", lat_dim = "lat", + drop_realization_dim = FALSE, verbose = FALSE) } \arguments{ \item{data}{Precipitation array to downscale. diff --git a/man/s2dv_cube.Rd b/man/s2dv_cube.Rd index b0ce8966..f57d5ed3 100644 --- a/man/s2dv_cube.Rd +++ b/man/s2dv_cube.Rd @@ -4,16 +4,8 @@ \alias{s2dv_cube} \title{Creation of a 's2dv_cube' object} \usage{ -s2dv_cube( - data, - lon = NULL, - lat = NULL, - Variable = NULL, - Datasets = NULL, - Dates = NULL, - when = NULL, - source_files = NULL -) +s2dv_cube(data, lon = NULL, lat = NULL, Variable = NULL, + Datasets = NULL, Dates = NULL, when = NULL, source_files = NULL) } \arguments{ \item{data}{an array with any number of named dimensions, typically an object output from CST_Load, with the following dimensions: dataset, member, sdate, ftime, lat and lon.} -- GitLab From 081bb730ab94a12c4d7aa474c72e77c61988f799 Mon Sep 17 00:00:00 2001 From: Eroteida Sanchez Garcia Date: Mon, 9 Mar 2020 12:51:51 +0000 Subject: [PATCH 2/6] Fixing 1 error for function 'PlotPDFsOLE.R' --- R/PlotPDFsOLE.R | 2 +- man/PlotPDFsOLE.Rd | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/R/PlotPDFsOLE.R b/R/PlotPDFsOLE.R index 760798f2..a647ff12 100644 --- a/R/PlotPDFsOLE.R +++ b/R/PlotPDFsOLE.R @@ -30,7 +30,7 @@ #' @import ggplot2 #' #' @examples -#' Example for PlotPDFs function +#' # Example 1 #' pdf_1 <- c(1.1,0.6) #' attr(pdf_1, "name") <- "NAO1" #' dim(pdf_1) <- c(statistic = 2) diff --git a/man/PlotPDFsOLE.Rd b/man/PlotPDFsOLE.Rd index 14d42637..6980cc56 100644 --- a/man/PlotPDFsOLE.Rd +++ b/man/PlotPDFsOLE.Rd @@ -43,7 +43,7 @@ This function plots two probability density gaussian functions and the optimal linear estimation (OLE) as result of combining them. } \examples{ -Example for PlotPDFs function +# Example 1 pdf_1 <- c(1.1,0.6) attr(pdf_1, "name") <- "NAO1" dim(pdf_1) <- c(statistic = 2) -- GitLab From 314832a814509183e0e18a61119ee47ee240f9f8 Mon Sep 17 00:00:00 2001 From: Eroteida Sanchez Garcia Date: Thu, 14 May 2020 08:43:52 +0000 Subject: [PATCH 3/6] Fixing and adding examples in vignette BestEstimateIndex_vignette.Rmd --- vignettes/BestEstimateIndex_vignette.Rmd | 306 +++++++++++++---------- 1 file changed, 173 insertions(+), 133 deletions(-) diff --git a/vignettes/BestEstimateIndex_vignette.Rmd b/vignettes/BestEstimateIndex_vignette.Rmd index e577eeb2..e549533f 100644 --- a/vignettes/BestEstimateIndex_vignette.Rmd +++ b/vignettes/BestEstimateIndex_vignette.Rmd @@ -1,134 +1,174 @@ ---- -author: "Eroteida Sánchez-García" -date: "`r Sys.Date()`" -output: rmarkdown::html_vignette -vignette: > - %\VignetteEngine{knitr::knitr} - %\VignetteIndexEntry{Achiving Best Estimate Index} - %\usepackage[utf8]{inputenc} ---- - -Achiving the Precipitation Best prediction giving the NAO index -------------------------------------------------------------------- - -The boreal winter precipitation forecast, acumulated from November to March, can be improved by considering the NAO index. The first step is to find the best estimation of winter NAO, given by two Seasonal Forecast System (SFS). The second step is to employ the enhanced NAO index pdf to produce weights for a SFS (it could be the same or a different SFS from the previous one). The third step is to apply this weights to a precipitation field. The methodology has been proved to improve the skill on precipitation forecast in the iberian peninsula given the relation between the winter precipitation and the NAO index in seasonal time scale (Sánchez-García, E., Voces-Aboy, J., Navascués, N., & Rodríguez-Camino, E. (2019). Regionally improved seasonal forecast of precipitation through Best estimation of winter NAO, Adv. Sci. Res., 16, 165174, ). - -This document is aim to ilustrate a practical use of the functions included in CSTools applying this methodology. - - -## Loading packages and data - -Open an R sesion and load library CSTools: - -``` -library(CSTools) -``` -The required data to applied this methodology are: -- the winter index NAO for two (or three) different SFS in a reference period (hindcast) and in a future simulation (forecast), -- the observed (reconstructed) NAO index in the reference period and -- the acumulated precipitation field from a SFS that aims to be improved (hindcast or hindcast and forecast) - -Given the memory limitations, the following example uses synthetic data. - -The first SFS is a dynamical model containing 25 ensemble members and its output will be save in the object `NAO_hind1` for the 20 years reference period and `NAO_fcst1` for a next season forecast. -The second SFS is a empirical model, so, the `NAO_hind2` and `NAO_fcst2` are characterized by a mean and standard deviation saved in the 'statistics' dimension. - -The synthetic data is created by running the following lines: - - -``` -NAO_obs <- rnorm(3, sd=3) -dim(NAO_obs) <- c(time = 3) -NAO_hind1 <- rnorm(3 * 6, sd=3) -dim(NAO_hind1) <- c(time = 3, member = 6) -NAO_hind2_mean <- rnorm(3, sd=3) -NAO_hind2_sd <- rnorm(3, mean=5, sd=1) -NAO_hind2 <- cbind(NAO_hind2_mean,NAO_hind2_sd) -dim(NAO_hind2) <- c(time=3, statistic=2) - -``` - -The acumulated precipiation field (only march for memory limiations) is loaded by running: - -``` -lonlat_prec$data <- apply(lonlat_prec$data, c(1, 2, 3, 5, 6), sum) -``` - - -## 1- Best Estimate Index NAO - -The function `PDFBest` performes the next steps: - - improves the PDF NAO index for each SFS (it could use bias correction method) and - - does a statistical combination of these improved NAO indexes. -Its output is an array containing the parameters (mean and starndar deviation) of the PDF for the reference period. - - -``` -pdf_hind_best <- BEI_PDFBest(NAO_obs, NAO_hind1, NAO_hind2, index_fcst1 = NULL, - index_fcst2 = NULL, method_BC = 'none', - time_dim_name = 'time', na.rm = FALSE) -``` - - -## 2- Compute weights using the Best Estimation of Index NAO - - -An array of weights is calculated for a SFS. This SFS could be a different SFS than the ones in section 1. -The function WeightIndex computes these weights for each ensemble's member based on the best NAO PDF estimate. - - -``` -weights_hind <- BEI_Weights(NAO_hind1, pdf_hind_best) -names(dim(weights_hind))[1] <- 'sdate' -``` - -The expected dimensions of these weights are 'member' and temporal dimension. - - -## 3- Apply weights to a precipitation field - - -The function `CST_BEI_Weighting` computes the ensemble mean or the terciles probabilities for a climate variable. -The corrected precipitation field is obtained by running: - -``` -em_prec <- CST_BEI_Weighting(lonlat_prec, weights_hind, type = 'ensembleMean', time_dim_name = 'sdate') -prob_prec <- CST_BEI_Weighting(lonlat_prec, weights_hind, type = 'probs', ) -``` - -## Comparison and visualization - -The original model output can be compared against the BEI corrected field. -To do this a equiprobability weights are created and they are applied to the original precipitation field: - - -``` -aweights_raw <- rep(1/6, 3 * 6) -dim(aweights_raw) <- dim(weights_hind) - -em_prec_raw <- CST_BEI_Weighting(lonlat_prec, aweights_raw, type = 'ensembleMean', time_dim_name = 'sdate') -prob_prec_raw <- CST_BEI_Weighting(lonlat_prec, aweights_raw, type = 'probs', time_dim_name = 'sdate') - -``` - -A map with the probability that the total precipitation will be in the lower/normal/upper tercile based on the Best Estimate Index NAO could be obtained using the 'PlotEquiMap' function or 'PlotMostLikelyQuantileMap' function from 'CSToools' package. - -The following figures show the probabilities for lower tercile for precipitation from November to March 2012/13 for ECMWF S5 system applying the methodology exposed or not, obtained using real data: -- NAO indices from the ECMWF-S5 dynamical model and the S-ClimWaRe empirical model from AEMET from 1997 to 2016 for computing the Best Estimation of Index NAO fro this hindcast period. -- The winter precipitation (from November to March) from 1997 to 2016 over Iberia Peninsula from he ECMWF-S5 dynamical model with resolution 0.5º x 0.5º, to weighting with the previous Best Estimation of Index NAO. - - -![](./Figures/BestEstimateIndex_fig1.png){width=70%} - -![](./Figures/BestEstimateIndex_fig3.png){width=70%} - - - -In a similar way we can plot the map with the probability that the total precipitation from November 2012 to -March 2013, for example, will be in the lower tercile from ECMWF Seasonal Forecast System 5 (raw) to compare results running the code: - - - -![](./Figures/BestEstimateIndex_fig2.png){width=70%} - +--- +author: "Eroteida Sánchez-García" +date: "`r Sys.Date()`" +output: rmarkdown::html_vignette +vignette: > + %\VignetteEngine{knitr::knitr} + %\VignetteIndexEntry{Achiving Best Estimate Index} + %\usepackage[utf8]{inputenc} +--- + +Achiving the Precipitation Best prediction giving the NAO index +------------------------------------------------------------------- + +The boreal winter precipitation forecast, acumulated from November to March, can be improved by considering the NAO index. The first step is to find the best estimation of winter NAO, given by two Seasonal Forecast System (SFS). The second step is to employ the enhanced NAO index pdf to produce weights for a SFS (it could be the same or a different SFS from the previous one). The third step is to apply this weights to a precipitation field. The methodology has been proved to improve the skill on precipitation forecast in the iberian peninsula given the relation between the winter precipitation and the NAO index in seasonal time scale (Sánchez-García, E., Voces-Aboy, J., Navascués, N., & Rodríguez-Camino, E. (2019). Regionally improved seasonal forecast of precipitation through Best estimation of winter NAO, Adv. Sci. Res., 16, 165174, ). + +This document is aim to ilustrate a practical use of the functions included in CSTools applying this methodology. + + +## Loading packages and data + +Open an R sesion and load library CSTools: + +``` +library(CSTools) +``` +The required data to applied this methodology are: +- the observed (reconstructed) NAO index in the reference period +- the winter index NAO for two different SFSs (SFS1 and SFS2, to combine both of them) in a reference period (hindcast) and in a future simulation (forecast) +- the winter index NAO and the acumulated precipitation field from a SFS that aims to be improved (hindcast and forecast) + +Given the memory limitations, the following example uses synthetic data. + +The SFS1 system is a dynamical model containing 25 ensemble members and its output will be save in the object `NAO_hind1` for the 20 years reference period and `NAO_fcst1` for a next season forecast. +The second SFS, SFS2, is a empirical model, so, the `NAO_hind2` and `NAO_fcst2` are characterized by a mean and standard deviation saved in the 'statistics' dimension. +The model for improving is a dynamical model containing 25 ensemble members. +The synthetic data is created by running the following lines: + + +``` +# observations +NAO_obs <- rnorm(20, sd=3) +dim(NAO_obs) <- c(time = 20) + +# hindcast and forecast of a dynamical SFS 1 +NAO_hind1 <- rnorm(20 * 2 * 25, sd=2.5) +dim(NAO_hind1) <- c(time = 20, member = 50) +NAO_fcst1 <- rnorm(2*51, sd=2.5) +dim(NAO_fcst1) <- c(time = 1, member = 102) + +# hindcast and forecast of an empirical SFS 2 +NAO_hind2_mean <- rnorm(20, sd=3) +NAO_hind2_sd <- rnorm(20, mean=5, sd=1) +NAO_hind2 <- cbind(NAO_hind2_mean, NAO_hind2_sd) +dim(NAO_hind2) <- c(time=20, statistic=2) +NAO_fcst2_mean <- rnorm(1, sd=3) +NAO_fcst2_sd <- rnorm(1, mean=5, sd=1) +NAO_fcst2 <- cbind(NAO_fcst2_mean, NAO_fcst2_sd) +dim(NAO_fcst2) <- c(time=1, statistic=2) + +``` + +The winter index NAO and the acumulated precipiation field from the dynamical SFS that aims to be improved could be created by running: + +``` +# NAO index of a SFS to compute weights for each ensemble's member +NAO_hind <- rnorm(20 * 25, sd=2.5) +dim(NAO_hind) <- c(time = 20, member = 25) +NAO_fcst <- rnorm(51, sd=2.5) +dim(NAO_fcst) <- c(time = 1, member = 51) + +# The acumulated precipiation field +prec_hind <- rnorm(20 * 25 * 21 * 31, mean=30, sd=10) +dim(prec_hind) <- c(time = 20, member = 25, lat = 21, lon = 31) +prec_hind <- list(data = prec_hind) +class(prec_hind) <- 's2dv_cube' +prec_fcst <- rnorm(51 * 21 * 31, mean=25,sd=8) +dim(prec_fcst) <- c(time = 1, member = 51, lat = 21, lon = 31) +prec_fcst <- list(data = prec_fcst) +class(prec_fcst) <- 's2dv_cube' + +``` + + +## 1- Best Estimate Index NAO + +The function `PDFBest` performes the next steps: + - improves the PDF NAO index for each SFS (it could use bias correction method) and + - does a statistical combination of these improved NAO indexes. +Its output is an array containing the parameters (mean and starndar deviation) of the PDF for the reference period (hindcast) or forecast period. + + +``` +# for hindcast +pdf_hind_best <- BEI_PDFBest(NAO_obs, NAO_hind1, NAO_hind2, index_fcst1 = NULL, + index_fcst2 = NULL, method_BC = 'none', + time_dim_name = 'time', na.rm = FALSE) +# for forecast +pdf_fcst_best <- BEI_PDFBest (NAO_obs, NAO_hind1, NAO_hind2, index_fcst1 = NAO_fcst1, + index_fcst2 = NAO_fcst2, method_BC = 'none', + time_dim_name = 'time', na.rm = FALSE) +``` + + +## 2- Compute weights using the Best Estimation of Index NAO + + +An array of weights is calculated for the SFS. This SFS could be the same or different SFS than the ones in section 1. +The function WeightIndex computes these weights for each ensemble's member based on the best NAO PDF estimate. + + +``` +# for hindcast +weights_hind <- BEI_Weights(NAO_hind, pdf_hind_best) +# for forecast +weights_fcst <- BEI_Weights(NAO_fcst, pdf_fcst_best) + +``` + +The expected dimensions of these weights are 'member' and temporal dimension. + + +## 3- Apply weights to a precipitation field + + +The function `CST_BEI_Weighting` computes the ensemble mean or the terciles probabilities for a climate variable. +The ensemble mean and the probabilities of terciles from the weighted precipitation field is obtained by running: + +``` +# for hindcast +em_prec_hind <- CST_BEI_Weighting(prec_hind, weights_hind, type = 'ensembleMean') +prob_prec_hind <- CST_BEI_Weighting(prec_hind, weights_hind, type = 'probs') + +# for forecast +em_prec_fcst <- CST_BEI_Weighting(prec_fcst, weights_fcst, type = 'ensembleMean') +prob_prec_fcst <- CST_BEI_Weighting(prec_fcst, weights_fcst, type = 'probs') + +``` + +## Comparison and visualization + +The original model output can be compared against the BEI corrected field. +To do this a equiprobability weights are created for hindcast period and they are applied to the original precipitation field: + + +``` +aweights_raw <- rep(1/25, 20 * 25) +dim(aweights_raw) <- dim(weights_hind) + +em_prec_raw <- CST_BEI_Weighting(prec_hind, aweights_raw, type = 'ensembleMean') +prob_prec_raw <- CST_BEI_Weighting(prec_hind, aweights_raw, type = 'probs') + +``` + +A map with the probability that the total precipitation will be in the lower/normal/upper tercile based on the Best Estimate Index NAO could be obtained using the 'PlotEquiMap' function or 'PlotMostLikelyQuantileMap' function from 'CSToools' package. + +The following figures show the probabilities for lower tercile for precipitation from November to March 2012/13 for ECMWF S5 system applying the methodology exposed or not, obtained using real data: +- NAO indices from the ECMWF-S5 dynamical model and the S-ClimWaRe empirical model from AEMET from 1997 to 2016 for computing the Best Estimation of Index NAO fro this hindcast period. +- The winter precipitation (from November to March) from 1997 to 2016 over Iberia Peninsula from he ECMWF-S5 dynamical model with resolution 0.5º x 0.5º, to weighting with the previous Best Estimation of Index NAO. + + +![](./Figures/BestEstimateIndex_fig1.png){width=70%} + +![](./Figures/BestEstimateIndex_fig3.png){width=70%} + + + +In a similar way we can plot the map with the probability that the total precipitation from November 2012 to +March 2013, for example, will be in the lower tercile from ECMWF Seasonal Forecast System 5 (raw) to compare results running the code: + + + +![](./Figures/BestEstimateIndex_fig2.png){width=70%} + ![](./Figures/BestEstimateIndex_fig4.png){width=70%} \ No newline at end of file -- GitLab From 9384185359ad8b95842e8704606db2823e06eb2d Mon Sep 17 00:00:00 2001 From: Eroteida Sanchez Garcia Date: Thu, 18 Jun 2020 11:16:23 +0000 Subject: [PATCH 4/6] Fixing code of PlotPDFsOLE function and adding test-PlotPDFsOLE.R file --- R/PlotPDFsOLE.R | 90 +++++++++++----------- tests/testthat/test-PlotPDFsOLE.R | 121 ++++++++++++++++++++++++++++++ 2 files changed, 169 insertions(+), 42 deletions(-) create mode 100644 tests/testthat/test-PlotPDFsOLE.R diff --git a/R/PlotPDFsOLE.R b/R/PlotPDFsOLE.R index a647ff12..c7239c73 100644 --- a/R/PlotPDFsOLE.R +++ b/R/PlotPDFsOLE.R @@ -45,42 +45,43 @@ PlotPDFsOLE <- function(pdf_1, pdf_2, nsigma = 3, plotfile = NULL, width = 30, height = 15, units = "cm", dpi = 300) { - if (!is.numeric(dpi)) { - stop("Parameter 'dpi' must be numeric.") - } - if (length(dpi) > 1) { - warning("Parameter 'dpi' has length greater than 1 and ", - "only the first element will be used.") - dpi <- dpi[1] - } - if (!is.character(units)) { - stop("Parameter 'units' must be character") - } - if (length(units) > 1) { - warning("Parameter 'units' has length greater than 1 and ", - "only the first element will be used.") - units <- units[1] - } - if(!(units %in% c("in", "cm", "mm"))) { - stop("Parameter 'units' must be equal to 'in', 'cm' or 'mm'.") - } - if (!is.numeric(height)) { - stop("Parameter 'height' must be numeric.") - } - if (length(height) > 1) { - warning("Parameter 'height' has length greater than 1 and ", - "only the first element will be used.") - height <- height[1] - } - if (!is.numeric(width)) { - stop("Parameter 'width' must be numeric.") - } - if (length(width) > 1) { - warning("Parameter 'width' has length greater than 1 and ", - "only the first element will be used.") - width <- width[1] - } + if(!is.null(plotfile)){ + if (!is.numeric(dpi)) { + stop("Parameter 'dpi' must be numeric.") + } + if (length(dpi) > 1) { + warning("Parameter 'dpi' has length greater than 1 and ", + "only the first element will be used.") + dpi <- dpi[1] + } + if (!is.character(units)) { + stop("Parameter 'units' must be character") + } + if (length(units) > 1) { + warning("Parameter 'units' has length greater than 1 and ", + "only the first element will be used.") + units <- units[1] + } + if(!(units %in% c("in", "cm", "mm"))) { + stop("Parameter 'units' must be equal to 'in', 'cm' or 'mm'.") + } + if (!is.numeric(height)) { + stop("Parameter 'height' must be numeric.") + } + if (length(height) > 1) { + warning("Parameter 'height' has length greater than 1 and ", + "only the first element will be used.") + height <- height[1] + } + if (!is.numeric(width)) { + stop("Parameter 'width' must be numeric.") + } + if (length(width) > 1) { + warning("Parameter 'width' has length greater than 1 and ", + "only the first element will be used.") + width <- width[1] + } if (!is.character(plotfile)) { stop("Parameter 'plotfile' must be a character string ", "indicating the path and name of output png file.") @@ -112,18 +113,18 @@ PlotPDFsOLE <- function(pdf_1, pdf_2, nsigma = 3, plotfile = NULL, "should have dimmension names.") } if(!('statistic' %in% names(dim(pdf_1)))) { - stop("Parameter 'pdf_1' must have dimension 'statistic.") + stop("Parameter 'pdf_1' must have dimension 'statistic'.") } if(!('statistic' %in% names(dim(pdf_2)))) { - stop("Parameter 'pdf_2' must have dimension 'statistic.") + stop("Parameter 'pdf_2' must have dimension 'statistic'.") } if (length(dim(pdf_1)) != 1) { - stop("Parameter 'pdf_1' must have only dimension 'statistic.") + stop("Parameter 'pdf_1' must have only dimension 'statistic'.") } if (length(dim(pdf_2)) != 1) { - stop("Parameter 'pdf_2' must have only dimension 'statistic.") + stop("Parameter 'pdf_2' must have only dimension 'statistic'.") } - if ((dim(pdf_1)['statistic'] != 2) & (dim(pdf_2)['statistic'] != 2)) { + if ((dim(pdf_1)['statistic'] != 2) || (dim(pdf_2)['statistic'] != 2)) { stop("Length of dimension 'statistic'", "of parameter 'pdf_1' and 'pdf_2' must be equal to 2.") } @@ -133,6 +134,12 @@ PlotPDFsOLE <- function(pdf_1, pdf_2, nsigma = 3, plotfile = NULL, "indicating the name of the variable of parameter 'pdf_1'.") } } + if(!is.null(attr(pdf_2, "name"))){ + if(!is.character(attr(pdf_2, "name"))){ + stop("The 'name' attribute of parameter 'pdf_2' must be a character ", + "indicating the name of the variable of parameter 'pdf_2'.") + } + } if(is.null(attr(pdf_1, "name"))){ name1 <- "variable 1" } else { @@ -212,8 +219,7 @@ PlotPDFsOLE <- function(pdf_1, pdf_2, nsigma = 3, plotfile = NULL, # Save to plotfile if needed, and return plot #----------------------------------------------------------------------------- if (!is.null(plotfile)) { - ggsave(plotfile, g, width = width, height = height, - units = units, dpi = dpi) + ggsave(plotfile, g, width = width, height = height, units = units, dpi = dpi) } return(g) } diff --git a/tests/testthat/test-PlotPDFsOLE.R b/tests/testthat/test-PlotPDFsOLE.R new file mode 100644 index 00000000..bd1279d9 --- /dev/null +++ b/tests/testthat/test-PlotPDFsOLE.R @@ -0,0 +1,121 @@ +context("Generic tests") + +test_that("Sanity checks", { + pdf_1 <- c(1.1,0.6) + attr(pdf_1, "name") <- "NAO1" + dim(pdf_1) <- c(statistic = 2) + pdf_2 <- c(1,0.5) + attr(pdf_2, "name") <- "NAO2" + dim(pdf_2) <- c(statistic = 2) + + expect_error(PlotPDFsOLE(pdf_1, pdf_2, nsigma = 3, plotfile = "plot.png", + width = 30, height = 15, + units = "cm", dpi = '300') , + "Parameter 'dpi' must be numeric.") + + expect_error(PlotPDFsOLE(pdf_1, pdf_2, nsigma = 3, plotfile = "plot.png", + width = 30, height = 15, + units = 20, dpi = 300) , + "Parameter 'units' must be character") + + expect_error(PlotPDFsOLE(pdf_1, pdf_2, nsigma = 3, plotfile = "plot.png", + width = 30, height = 15, + units = "dm", dpi = 300) , + "Parameter 'units' must be equal to 'in', 'cm' or 'mm'.") + + expect_error(PlotPDFsOLE(pdf_1, pdf_2, nsigma = 3, plotfile = "plot.png", + width = 30, height = '15', + units = "cm", dpi = 300) , + "Parameter 'height' must be numeric.") + + expect_error(PlotPDFsOLE(pdf_1, pdf_2, nsigma = 3, plotfile = "plot.png", + width = list(30), height = 15, + units = "cm", dpi = 300) , + "Parameter 'width' must be numeric.") + + expect_error(PlotPDFsOLE(pdf_1, pdf_2, nsigma = 3, plotfile = 0, + width = 30, height = 15, + units = "cm", dpi = 300) , + paste0("Parameter 'plotfile' must be a character string ", + "indicating the path and name of output png file.")) + + expect_error(PlotPDFsOLE(pdf_1, pdf_2, nsigma = '3', plotfile = NULL, + width = 30, height = 15, + units = "cm", dpi = 300) , + "Parameter 'nsigma' must be numeric.") + + pdf_1 <- list(1.1,0.6) + attr(pdf_1, "name") <- "NAO1" + expect_error(PlotPDFsOLE(pdf_1, pdf_2, nsigma = 3, plotfile = NULL, + width = 30, height = 15, + units = "cm", dpi = 300) , + "Parameter 'pdf_1' must be an array.") + + pdf_1 <- c('1.1','0.6') + attr(pdf_1, "name") <- "NAO1" + dim(pdf_1) <- c(statistic = 2) + expect_error(PlotPDFsOLE(pdf_1, pdf_2, nsigma = 3, plotfile = NULL, + width = 30, height = 15, + units = "cm", dpi = 300) , + "Parameter 'pdf_1' must be a numeric array.") + + pdf_1 <- c(1.1,0.6) + attr(pdf_1, "name") <- "NAO1" + dim(pdf_1) <- c(2) + expect_error(PlotPDFsOLE(pdf_1, pdf_2, nsigma = 3, plotfile = NULL, + width = 30, height = 15, + units = "cm", dpi = 300) , + paste0("Parameters 'pdf_1' and 'pdf_2' ", + "should have dimmension names.")) + + pdf_1 <- c(1.1,0.6) + attr(pdf_1, "name") <- "NAO1" + dim(pdf_1) <- c(statisti = 2) + expect_error(PlotPDFsOLE(pdf_1, pdf_2, nsigma = 3, plotfile = NULL, + width = 30, height = 15, + units = "cm", dpi = 300) , + "Parameter 'pdf_1' must have dimension 'statistic'.") + + pdf_1 <- c(1.1,0.6) + attr(pdf_1, "name") <- "NAO1" + dim(pdf_1) <- c(statistic = 2, model = 1) + expect_error(PlotPDFsOLE(pdf_1, pdf_2, nsigma = 3, plotfile = NULL, + width = 30, height = 15, + units = "cm", dpi = 300) , + "Parameter 'pdf_1' must have only dimension 'statistic'.") + + pdf_1 <- c(1.1, 0.6, 0.2) + attr(pdf_1, "name") <- "NAO1" + dim(pdf_1) <- c(statistic = 3) + expect_error(PlotPDFsOLE(pdf_1, pdf_2, nsigma = 3, plotfile = NULL, + width = 30, height = 15, + units = "cm", dpi = 300) , + paste0("Length of dimension 'statistic'", + "of parameter 'pdf_1' and 'pdf_2' must be equal to 2.")) + + pdf_1 <- c(1.1, 0.6) + attr(pdf_1, "name") <- 12 + dim(pdf_1) <- c(statistic = 2) + expect_error(PlotPDFsOLE(pdf_1, pdf_2, nsigma = 3, plotfile = NULL, + width = 30, height = 15, + units = "cm", dpi = 300) , + paste0("The 'name' attribute of parameter 'pdf_1' must be a character ", + "indicating the name of the variable of parameter 'pdf_1'.")) + + pdf_1 <- c(1.1,0.6) + attr(pdf_1, "name") <- "NAO1" + dim(pdf_1) <- c(statistic = 2) + pdf_2 <- c(1,0.5) + attr(pdf_2, "name") <- 12 + dim(pdf_2) <- c(statistic = 2) + + expect_error(PlotPDFsOLE(pdf_1, pdf_2, nsigma = 3, plotfile = NULL, + width = 30, height = 15, + units = "cm", dpi = 300) , + paste0("The 'name' attribute of parameter 'pdf_2' must be a character ", + "indicating the name of the variable of parameter 'pdf_2'.")) + + + + +}) -- GitLab From 7bae72e7a55e06ff5940b7f4f2bf1fe7bd3d05d0 Mon Sep 17 00:00:00 2001 From: nperez Date: Fri, 19 Jun 2020 18:46:22 +0200 Subject: [PATCH 5/6] documentation automatically generated with devtools --- NAMESPACE | 3 --- man/Analogs.Rd | 16 +++++++++++++--- man/BEI_PDFBest.Rd | 13 ++++++++++--- man/CST_Analogs.Rd | 11 +++++++++-- man/CST_BEI_Weighting.Rd | 9 +++++++-- man/CST_CategoricalEnsCombination.Rd | 10 ++++++++-- man/CST_MergeDims.Rd | 8 ++++++-- man/CST_MultiEOF.Rd | 10 ++++++++-- man/CST_QuantileMapping.Rd | 13 ++++++++++--- man/CST_RainFARM.Rd | 17 ++++++++++++++--- man/CST_SplitDim.Rd | 3 +-- man/MergeDims.Rd | 8 ++++++-- man/MultiEOF.Rd | 16 +++++++++++++--- man/PlotCombinedMap.Rd | 26 +++++++++++++++++++++----- man/PlotForecastPDF.Rd | 17 ++++++++++++----- man/PlotMostLikelyQuantileMap.Rd | 11 +++++++++-- man/PlotPDFsOLE.Rd | 12 ++++++++++-- man/RFSlope.Rd | 3 +-- man/RainFARM.Rd | 22 ++++++++++++++++++---- man/s2dv_cube.Rd | 12 ++++++++++-- 20 files changed, 186 insertions(+), 54 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 7f245fb1..696a3e89 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -30,11 +30,8 @@ export(MultiEOF) export(PlotCombinedMap) export(PlotForecastPDF) export(PlotMostLikelyQuantileMap) -<<<<<<< HEAD export(PlotPDFsOLE) -======= export(PlotTriangles4Categories) ->>>>>>> master export(RFSlope) export(RainFARM) export(RegimesAssign) diff --git a/man/Analogs.Rd b/man/Analogs.Rd index 52d9ff97..06107c07 100644 --- a/man/Analogs.Rd +++ b/man/Analogs.Rd @@ -4,9 +4,19 @@ \alias{Analogs} \title{Analogs based on large scale fields.} \usage{ -Analogs(expL, obsL, time_obsL, expVar = NULL, obsVar = NULL, - criteria = "Large_dist", lonVar = NULL, latVar = NULL, - region = NULL, nAnalogs = NULL, return_list = FALSE) +Analogs( + expL, + obsL, + time_obsL, + expVar = NULL, + obsVar = NULL, + criteria = "Large_dist", + lonVar = NULL, + latVar = NULL, + region = NULL, + nAnalogs = NULL, + return_list = FALSE +) } \arguments{ \item{expL}{an array of N named dimensions containing the experimental field diff --git a/man/BEI_PDFBest.Rd b/man/BEI_PDFBest.Rd index f120258d..0ba24a84 100644 --- a/man/BEI_PDFBest.Rd +++ b/man/BEI_PDFBest.Rd @@ -4,9 +4,16 @@ \alias{BEI_PDFBest} \title{Computing the Best Index PDFs combining Index PDFs from two SFSs} \usage{ -BEI_PDFBest(index_obs, index_hind1, index_hind2, index_fcst1 = NULL, - index_fcst2 = NULL, method_BC = "none", time_dim_name = "time", - na.rm = FALSE) +BEI_PDFBest( + index_obs, + index_hind1, + index_hind2, + index_fcst1 = NULL, + index_fcst2 = NULL, + method_BC = "none", + time_dim_name = "time", + na.rm = FALSE +) } \arguments{ \item{index_obs}{Index (e.g. NAO index) array from an observational database diff --git a/man/CST_Analogs.Rd b/man/CST_Analogs.Rd index c9166de6..d7dd5e14 100644 --- a/man/CST_Analogs.Rd +++ b/man/CST_Analogs.Rd @@ -4,8 +4,15 @@ \alias{CST_Analogs} \title{Downscaling using Analogs based on large scale fields.} \usage{ -CST_Analogs(expL, obsL, time_obsL, expVar = NULL, obsVar = NULL, - region = NULL, criteria = "Large_dist") +CST_Analogs( + expL, + obsL, + time_obsL, + expVar = NULL, + obsVar = NULL, + region = NULL, + criteria = "Large_dist" +) } \arguments{ \item{expL}{an 's2dv_cube' object containing the experimental field on the diff --git a/man/CST_BEI_Weighting.Rd b/man/CST_BEI_Weighting.Rd index 9c0f5a9d..d6f65bb5 100644 --- a/man/CST_BEI_Weighting.Rd +++ b/man/CST_BEI_Weighting.Rd @@ -4,8 +4,13 @@ \alias{CST_BEI_Weighting} \title{Weighting SFSs of a CSTools object.} \usage{ -CST_BEI_Weighting(var_exp, aweights, terciles = NULL, - type = "ensembleMean", time_dim_name = "time") +CST_BEI_Weighting( + var_exp, + aweights, + terciles = NULL, + type = "ensembleMean", + time_dim_name = "time" +) } \arguments{ \item{var_exp}{An object of the class 's2dv_cube' containing the variable diff --git a/man/CST_CategoricalEnsCombination.Rd b/man/CST_CategoricalEnsCombination.Rd index 7175b7fe..c23f8341 100644 --- a/man/CST_CategoricalEnsCombination.Rd +++ b/man/CST_CategoricalEnsCombination.Rd @@ -4,8 +4,14 @@ \alias{CST_CategoricalEnsCombination} \title{Make categorical forecast based on a multi-model forecast with potential for calibrate} \usage{ -CST_CategoricalEnsCombination(exp, obs, cat.method = "pool", - eval.method = "leave-one-out", amt.cat = 3, ...) +CST_CategoricalEnsCombination( + exp, + obs, + cat.method = "pool", + eval.method = "leave-one-out", + amt.cat = 3, + ... +) } \arguments{ \item{exp}{an object of class \code{s2dv_cube} as returned by \code{CST_Load} function, containing the seasonal forecast experiment data in the element named \code{$data}. The amount of forecasting models is equal to the size of the \code{dataset} dimension of the data array. The amount of members per model may be different. The size of the \code{member} dimension of the data array is equal to the maximum of the ensemble members among the models. Models with smaller ensemble sizes have residual indices of \code{member} dimension in the data array filled with NA values.} diff --git a/man/CST_MergeDims.Rd b/man/CST_MergeDims.Rd index 2c483840..0762e83f 100644 --- a/man/CST_MergeDims.Rd +++ b/man/CST_MergeDims.Rd @@ -4,8 +4,12 @@ \alias{CST_MergeDims} \title{Function to Merge Dimensions} \usage{ -CST_MergeDims(data, merge_dims = c("ftime", "monthly"), - rename_dim = NULL, na.rm = FALSE) +CST_MergeDims( + data, + merge_dims = c("ftime", "monthly"), + rename_dim = NULL, + na.rm = FALSE +) } \arguments{ \item{data}{a 's2dv_cube' object} diff --git a/man/CST_MultiEOF.Rd b/man/CST_MultiEOF.Rd index 5fea8a50..036a6470 100644 --- a/man/CST_MultiEOF.Rd +++ b/man/CST_MultiEOF.Rd @@ -4,8 +4,14 @@ \alias{CST_MultiEOF} \title{EOF analysis of multiple variables} \usage{ -CST_MultiEOF(datalist, neof_max = 40, neof_composed = 5, - minvar = 0.6, lon_lim = NULL, lat_lim = NULL) +CST_MultiEOF( + datalist, + neof_max = 40, + neof_composed = 5, + minvar = 0.6, + lon_lim = NULL, + lat_lim = NULL +) } \arguments{ \item{datalist}{A list of objects of the class 's2dv_cube', containing the variables to be analysed. diff --git a/man/CST_QuantileMapping.Rd b/man/CST_QuantileMapping.Rd index 90319622..ad8f4b6c 100644 --- a/man/CST_QuantileMapping.Rd +++ b/man/CST_QuantileMapping.Rd @@ -4,9 +4,16 @@ \alias{CST_QuantileMapping} \title{Quantiles Mapping for seasonal or decadal forecast data} \usage{ -CST_QuantileMapping(exp, obs, exp_cor = NULL, sample_dims = c("sdate", - "ftime", "member"), sample_length = NULL, method = "QUANT", - ncores = NULL, ...) +CST_QuantileMapping( + exp, + obs, + exp_cor = NULL, + sample_dims = c("sdate", "ftime", "member"), + sample_length = NULL, + method = "QUANT", + ncores = NULL, + ... +) } \arguments{ \item{exp}{an object of class \code{s2dv_cube}} diff --git a/man/CST_RainFARM.Rd b/man/CST_RainFARM.Rd index 0ed45f49..1c609e08 100644 --- a/man/CST_RainFARM.Rd +++ b/man/CST_RainFARM.Rd @@ -4,9 +4,20 @@ \alias{CST_RainFARM} \title{RainFARM stochastic precipitation downscaling of a CSTools object} \usage{ -CST_RainFARM(data, nf, weights = 1, slope = 0, kmin = 1, nens = 1, - fglob = FALSE, fsmooth = TRUE, nprocs = 1, time_dim = NULL, - verbose = FALSE, drop_realization_dim = FALSE) +CST_RainFARM( + data, + nf, + weights = 1, + slope = 0, + kmin = 1, + nens = 1, + fglob = FALSE, + fsmooth = TRUE, + nprocs = 1, + time_dim = NULL, + verbose = FALSE, + drop_realization_dim = FALSE +) } \arguments{ \item{data}{An object of the class 's2dv_cube' as returned by `CST_Load`, diff --git a/man/CST_SplitDim.Rd b/man/CST_SplitDim.Rd index 8ce20c97..ee93aedc 100644 --- a/man/CST_SplitDim.Rd +++ b/man/CST_SplitDim.Rd @@ -4,8 +4,7 @@ \alias{CST_SplitDim} \title{Function to Split Dimension} \usage{ -CST_SplitDim(data, split_dim = "time", indices = NULL, - freq = "monthly") +CST_SplitDim(data, split_dim = "time", indices = NULL, freq = "monthly") } \arguments{ \item{data}{a 's2dv_cube' object} diff --git a/man/MergeDims.Rd b/man/MergeDims.Rd index d6b261ad..7539ef6e 100644 --- a/man/MergeDims.Rd +++ b/man/MergeDims.Rd @@ -4,8 +4,12 @@ \alias{MergeDims} \title{Function to Split Dimension} \usage{ -MergeDims(data, merge_dims = c("time", "monthly"), rename_dim = NULL, - na.rm = FALSE) +MergeDims( + data, + merge_dims = c("time", "monthly"), + rename_dim = NULL, + na.rm = FALSE +) } \arguments{ \item{data}{an n-dimensional array with named dimensions} diff --git a/man/MultiEOF.Rd b/man/MultiEOF.Rd index c38116de..dd0fc7fe 100644 --- a/man/MultiEOF.Rd +++ b/man/MultiEOF.Rd @@ -4,9 +4,19 @@ \alias{MultiEOF} \title{EOF analysis of multiple variables starting from an array (reduced version)} \usage{ -MultiEOF(data, lon, lat, time, lon_dim = "lon", lat_dim = "lat", - neof_max = 40, neof_composed = 5, minvar = 0.6, lon_lim = NULL, - lat_lim = NULL) +MultiEOF( + data, + lon, + lat, + time, + lon_dim = "lon", + lat_dim = "lat", + neof_max = 40, + neof_composed = 5, + minvar = 0.6, + lon_lim = NULL, + lat_lim = NULL +) } \arguments{ \item{data}{A multidimensional array with dimension \code{"var"}, diff --git a/man/PlotCombinedMap.Rd b/man/PlotCombinedMap.Rd index 702d31ee..c45d1afb 100644 --- a/man/PlotCombinedMap.Rd +++ b/man/PlotCombinedMap.Rd @@ -4,11 +4,27 @@ \alias{PlotCombinedMap} \title{Plot Multiple Lon-Lat Variables In a Single Map According to a Decision Function} \usage{ -PlotCombinedMap(maps, lon, lat, map_select_fun, display_range, - map_dim = "map", brks = NULL, cols = NULL, - col_unknown_map = "white", mask = NULL, col_mask = "grey", - bar_titles = NULL, legend_scale = 1, fileout = NULL, width = 8, - height = 5, size_units = "in", res = 100, ...) +PlotCombinedMap( + maps, + lon, + lat, + map_select_fun, + display_range, + map_dim = "map", + brks = NULL, + cols = NULL, + col_unknown_map = "white", + mask = NULL, + col_mask = "grey", + bar_titles = NULL, + legend_scale = 1, + fileout = NULL, + width = 8, + height = 5, + size_units = "in", + res = 100, + ... +) } \arguments{ \item{maps}{List of matrices to plot, each with (longitude, latitude) dimensions, or 3-dimensional array with the dimensions (longitude, latitude, map). Dimension names are required.} diff --git a/man/PlotForecastPDF.Rd b/man/PlotForecastPDF.Rd index 3eee4e33..c04b43c1 100644 --- a/man/PlotForecastPDF.Rd +++ b/man/PlotForecastPDF.Rd @@ -4,11 +4,18 @@ \alias{PlotForecastPDF} \title{Plot one or multiple ensemble forecast pdfs for the same event} \usage{ -PlotForecastPDF(fcst, tercile.limits, extreme.limits = NULL, - obs = NULL, plotfile = NULL, title = "Set a title", - var.name = "Varname (units)", fcst.names = NULL, - add.ensmemb = c("above", "below", "no"), color.set = c("ggplot", - "s2s4e", "hydro")) +PlotForecastPDF( + fcst, + tercile.limits, + extreme.limits = NULL, + obs = NULL, + plotfile = NULL, + title = "Set a title", + var.name = "Varname (units)", + fcst.names = NULL, + add.ensmemb = c("above", "below", "no"), + color.set = c("ggplot", "s2s4e", "hydro") +) } \arguments{ \item{fcst}{a dataframe or array containing all the ensember members for each forecast. If \code{'fcst'} is an array, it should have two labelled dimensions, and one of them should be \code{'members'}. If \code{'fcsts'} is a data.frame, each column shoul be a separate forecast, with the rows beeing the different ensemble members.} diff --git a/man/PlotMostLikelyQuantileMap.Rd b/man/PlotMostLikelyQuantileMap.Rd index 0d984ede..4c400b18 100644 --- a/man/PlotMostLikelyQuantileMap.Rd +++ b/man/PlotMostLikelyQuantileMap.Rd @@ -4,8 +4,15 @@ \alias{PlotMostLikelyQuantileMap} \title{Plot Maps of Most Likely Quantiles} \usage{ -PlotMostLikelyQuantileMap(probs, lon, lat, cat_dim = "bin", - bar_titles = NULL, col_unknown_cat = "white", ...) +PlotMostLikelyQuantileMap( + probs, + lon, + lat, + cat_dim = "bin", + bar_titles = NULL, + col_unknown_cat = "white", + ... +) } \arguments{ \item{probs}{a list of bi-dimensional arrays with the named dimensions 'latitude' (or 'lat') and 'longitude' (or 'lon'), with equal size and in the same order, or a single tri-dimensional array with an additional dimension (e.g. 'bin') for the different categories. The arrays must contain probability values between 0 and 1, and the probabilities for all categories of a grid cell should not exceed 1 when added.} diff --git a/man/PlotPDFsOLE.Rd b/man/PlotPDFsOLE.Rd index 6980cc56..f2e2be8c 100644 --- a/man/PlotPDFsOLE.Rd +++ b/man/PlotPDFsOLE.Rd @@ -5,8 +5,16 @@ \title{Plotting two probability density gaussian functions and the optimal linear estimation (OLE) as result of combining them.} \usage{ -PlotPDFsOLE(pdf_1, pdf_2, nsigma = 3, plotfile = NULL, width = 30, - height = 15, units = "cm", dpi = 300) +PlotPDFsOLE( + pdf_1, + pdf_2, + nsigma = 3, + plotfile = NULL, + width = 30, + height = 15, + units = "cm", + dpi = 300 +) } \arguments{ \item{pdf_1}{A numeric array with a dimension named 'statistic', containg diff --git a/man/RFSlope.Rd b/man/RFSlope.Rd index 5308ef8c..db3f0e10 100644 --- a/man/RFSlope.Rd +++ b/man/RFSlope.Rd @@ -4,8 +4,7 @@ \alias{RFSlope} \title{RainFARM spectral slopes from an array (reduced version)} \usage{ -RFSlope(data, kmin = 1, time_dim = NULL, lon_dim = "lon", - lat_dim = "lat") +RFSlope(data, kmin = 1, time_dim = NULL, lon_dim = "lon", lat_dim = "lat") } \arguments{ \item{data}{Array containing the spatial precipitation fields to downscale. diff --git a/man/RainFARM.Rd b/man/RainFARM.Rd index e0fa9a10..0db84679 100644 --- a/man/RainFARM.Rd +++ b/man/RainFARM.Rd @@ -4,10 +4,24 @@ \alias{RainFARM} \title{RainFARM stochastic precipitation downscaling (reduced version)} \usage{ -RainFARM(data, lon, lat, nf, weights = 1, nens = 1, slope = 0, - kmin = 1, fglob = FALSE, fsmooth = TRUE, nprocs = 1, - time_dim = NULL, lon_dim = "lon", lat_dim = "lat", - drop_realization_dim = FALSE, verbose = FALSE) +RainFARM( + data, + lon, + lat, + nf, + weights = 1, + nens = 1, + slope = 0, + kmin = 1, + fglob = FALSE, + fsmooth = TRUE, + nprocs = 1, + time_dim = NULL, + lon_dim = "lon", + lat_dim = "lat", + drop_realization_dim = FALSE, + verbose = FALSE +) } \arguments{ \item{data}{Precipitation array to downscale. diff --git a/man/s2dv_cube.Rd b/man/s2dv_cube.Rd index f57d5ed3..b0ce8966 100644 --- a/man/s2dv_cube.Rd +++ b/man/s2dv_cube.Rd @@ -4,8 +4,16 @@ \alias{s2dv_cube} \title{Creation of a 's2dv_cube' object} \usage{ -s2dv_cube(data, lon = NULL, lat = NULL, Variable = NULL, - Datasets = NULL, Dates = NULL, when = NULL, source_files = NULL) +s2dv_cube( + data, + lon = NULL, + lat = NULL, + Variable = NULL, + Datasets = NULL, + Dates = NULL, + when = NULL, + source_files = NULL +) } \arguments{ \item{data}{an array with any number of named dimensions, typically an object output from CST_Load, with the following dimensions: dataset, member, sdate, ftime, lat and lon.} -- GitLab From 56724d7e9602f30ecafc6c570c17c7eaec6cd207 Mon Sep 17 00:00:00 2001 From: nperez Date: Fri, 19 Jun 2020 18:48:34 +0200 Subject: [PATCH 6/6] PlotPDFsOLE listed in NEWS --- NEWS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS.md b/NEWS.md index f3ebd2b3..208fec39 100644 --- a/NEWS.md +++ b/NEWS.md @@ -8,6 +8,8 @@ + CST_Anomaly allows to smooth the climatology with filter.span parameter + PlotTriangles4Categories new plotting function to convert any 3-d numerical array to a grid of coloured triangles. + CST_WeatherRegimes/WeatherRegimes and CST_RegimeAssign/RegimeAssign + + PlotPDFsOLE plots two probability density gaussian functions and the optimal linear estimation + - Fixes + CST_Anomaly handles exp, obs or both + PlotForecastPDF vignette displays figures correctly -- GitLab