diff --git a/DESCRIPTION b/DESCRIPTION index b458370a..724f44c0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: downscaleR Depends: - R(>= 3.1.0), - transformeR(>= 1.5.0) + R(>= 3.5.0), + transformeR(>= 2.0.0) Imports: reticulate, lubridate, @@ -21,17 +21,18 @@ Imports: magrittr, sp, gridGraphics, - gridExtra + gridExtra, + visualizeR Suggests: + climate4R.datasets, loadeR, loadeR.ECOMS, - visualizeR, knitr, rmarkdown Type: Package Title: A climate4R package for statistical downscaling Version: 3.2.0 -Date: 2020-04-23 +Date: 2020-05-23 Authors@R: as.person(c( "Santander Meteorology Group [cph]", "Joaquín Bedia [aut, cre]", @@ -46,7 +47,7 @@ Authors@R: as.person(c( "Jorge B. Medina [aut]", "Beata Szabo-Takacs [ctb]", "Max Tuni [ctb]", - "Ana Casanueva [ctb]")) + "Ana Casanueva [aut]")) BugReports: https://github.com/SantanderMetGroup/downscaleR/issues URL: http://www.meteo.unican.es/climate4r Encoding: UTF-8 diff --git a/NAMESPACE b/NAMESPACE index 591a8cf1..19e85c00 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -77,7 +77,6 @@ importFrom(transformeR,binaryGrid) importFrom(transformeR,bindGrid) importFrom(transformeR,climatology) importFrom(transformeR,dataSplit) -importFrom(transformeR,draw.world.lines) importFrom(transformeR,fillGridDates) importFrom(transformeR,getCoordinates) importFrom(transformeR,getDim) @@ -97,7 +96,6 @@ importFrom(transformeR,isRegular) importFrom(transformeR,makeMultiGrid) importFrom(transformeR,mat2Dto3Darray) importFrom(transformeR,parallelCheck) -importFrom(transformeR,plotClimatology) importFrom(transformeR,redim) importFrom(transformeR,scaleGrid) importFrom(transformeR,selectPar.pplyFun) @@ -105,3 +103,4 @@ importFrom(transformeR,subsetDimension) importFrom(transformeR,subsetGrid) importFrom(transformeR,typeofGrid) importFrom(utils,packageDescription) +importFrom(visualizeR,spatialPlot) diff --git a/R/biasCorrection.R b/R/biasCorrection.R index 8679cf93..7dbf2dbf 100644 --- a/R/biasCorrection.R +++ b/R/biasCorrection.R @@ -194,6 +194,7 @@ #' @author S. Herrera, M. Iturbide, J. Bedia #' @export #' @examples \donttest{ +#' require(climate4R.datasets) #' data("EOBS_Iberia_pr") #' data("CORDEX_Iberia_pr") #' y <- EOBS_Iberia_pr diff --git a/R/downscale.R b/R/downscale.R index 077ff5c5..b4125139 100644 --- a/R/downscale.R +++ b/R/downscale.R @@ -48,38 +48,44 @@ #' @export #' @family downscaling.functions #' @importFrom transformeR scaleGrid -#' @examples +#' @examples \donttest{ +#' require(transformeR) +#' require(climate4R.datasets) +#' data("NCEP_Iberia_hus850") +#' data("NCEP_Iberia_ta850") #' x <- makeMultiGrid(NCEP_Iberia_hus850, NCEP_Iberia_ta850) #' newdata <- subsetGrid(x, years = 1994:1995) #' x <- subsetGrid(x, years = 1985:1993) #' # Loading predictands +#' data("VALUE_Iberia_pr") #' y <- VALUE_Iberia_pr #' y <- getTemporalIntersection(obs = y,prd = x, "obs" ) #' x <- getTemporalIntersection(obs = y,prd = x, "prd" ) #' ### Analogs ### #' # None -#' yp <- downscale(y,x,method = "analogs") -#' yp <- downscale(y,x,newdata,method = "analogs") +#' yp <- downscale(y, x, method = "analogs") +#' yp <- downscale(y, x, newdata, method = "analogs") #' # kfold -#' yp <- downscale(y,x,method = "analogs", n.pcs = 15, -#' cross.val = "kfold", folds = list(c(1985,1986,1987), -#' c(1988,1989,1990), -#' c(1991,1992,1993))) +#' yp <- downscale(y, x, method = "analogs", n.pcs = 15, +#' cross.val = "kfold", folds = list(c(1985, 1986, 1987), +#' c(1988, 1989, 1990), +#' c(1991, 1992, 1993))) #' # Leave-one-year-out -#' yp <- downscale(y,x,method = "analogs", n.pcs = 15, +#' yp <- downscale(y, x, method = "analogs", n.pcs = 15, #' cross.val = "loocv") #' #' ### GLM ### #' # None -#' yp <- downscale(y,x,method = "glm", simulate = FALSE, n.pcs = 10, +#' yp <- downscale(y, x, method = "glm", simulate = FALSE, n.pcs = 10, #' wet.threshold = 1) -#' yp <- downscale(y,x,method = "glm", simulate = TRUE, n.pcs = 10, +#' yp <- downscale(y, x, method = "glm", simulate = TRUE, n.pcs = 10, #' wet.threshold = 1) #' # kfold -#' yp <- downscale(y,x,method = "glm", simulate = FALSE, n.pcs = 10, -#' cross.val = "kfold", folds = list(c(1985,1986,1987), -#' c(1988,1989,1990), -#' c(1991,1992,1993))) +#' yp <- downscale(y, x, method = "glm", simulate = FALSE, n.pcs = 10, +#' cross.val = "kfold", folds = list(c(1985, 1986, 1987), +#' c(1988, 1989, 1990), +#' c(1991, 1992, 1993))) +#' } downscale <- function(y, x, @@ -179,4 +185,4 @@ downscale <- function(y, } } return(yp) -} \ No newline at end of file +} diff --git a/R/downscaleCV.R b/R/downscaleCV.R index 25ee4af5..7e20f59e 100644 --- a/R/downscaleCV.R +++ b/R/downscaleCV.R @@ -74,8 +74,9 @@ #' @family downscaling.functions #' @author J. Bano-Medina #' @export -#' @examples +#' @examples \donttest{ #' require(transformeR) +#' require(climate4R.datasets) #' data(NCEP_Iberia_hus850, NCEP_Iberia_ta850) #' x <- makeMultiGrid(NCEP_Iberia_hus850, NCEP_Iberia_ta850) #' x <- subsetGrid(x, years = 1985:1995) @@ -105,6 +106,7 @@ #' scaleGrid.args = list(type = "standardize"), #' method = "GLM", condition = "GT", threshold = 0, #' prepareData.args = list("local.predictors" = list(vars = "hus@850", n = 4))) +#' } downscaleCV <- function(x, y, method, sampling.strategy = "kfold.chronological", folds = 4, diff --git a/R/downscalePredict.R b/R/downscalePredict.R index 04c92024..8c23ac87 100644 --- a/R/downscalePredict.R +++ b/R/downscalePredict.R @@ -33,9 +33,10 @@ #' @importFrom transformeR gridArithmetics #' @importFrom sticky sticky #' @export -#' @examples +#' @examples \donttest{ #' # Loading data -#' library(downscaleR) +#' require(transformeR) +#' require(climate4R.datasets) #' data("VALUE_Iberia_tas") #' y <- VALUE_Iberia_tas #' data("NCEP_Iberia_hus850", "NCEP_Iberia_psl", "NCEP_Iberia_ta850") @@ -59,6 +60,7 @@ #' pred <- downscalePredict(newdata, model.analogs) # predicting #' # Plotting the results for station 5 #' plot(yt$Data[,5],pred$Data[,5]) +#' } downscalePredict <- function(newdata, model) { n <- length(newdata$x.global) # number of members @@ -175,4 +177,4 @@ downs.predict <- function(x, method, atomic_model){ analogs = pred <- analogs.test(x, atomic_model$dataset_x, atomic_model$dataset_y, atomic_model$dates, atomic_model$info), GLM = pred <- glm.predict(x, atomic_model$weights, atomic_model$info), NN = pred <- nn.predict(atomic_model, x)) - return(pred)} \ No newline at end of file + return(pred)} diff --git a/R/downscaleTrain.R b/R/downscaleTrain.R index 822001de..02aac95f 100644 --- a/R/downscaleTrain.R +++ b/R/downscaleTrain.R @@ -117,6 +117,7 @@ #' @examples \donttest{ #' # Loading data #' require(transformeR) +#' require(climate4R.datasets) #' data("VALUE_Iberia_tas") #' y <- VALUE_Iberia_tas #' data("NCEP_Iberia_hus850", "NCEP_Iberia_psl", "NCEP_Iberia_ta850") diff --git a/R/prepareData.R b/R/prepareData.R index 39b4af88..9a8eae17 100644 --- a/R/prepareData.R +++ b/R/prepareData.R @@ -70,8 +70,10 @@ #' @export #' #' @author J. Bedia, D. San-Martín and J.M. Gutiérrez -#' @examples +#' @examples \donttest{ +#' require(transformeR) #' # Loading data +#' require(climate4R.datasets) #' data("VALUE_Iberia_tas") #' y <- VALUE_Iberia_tas #' data("NCEP_Iberia_hus850", "NCEP_Iberia_psl", "NCEP_Iberia_ta850") @@ -88,6 +90,7 @@ #' # Using joined PCs and local predictors: the 4 closest gridboxes #' data <- prepareData(x = x, y = y,local.predictors = list(n=4, vars = getVarNames(x)), #' spatial.predictors = list(v.exp = 0.95, which.combine =getVarNames(x))) +#' } prepareData <- function(x, y, global.vars = NULL, combined.only = TRUE, spatial.predictors = NULL, local.predictors = NULL, extended.predictors = NULL) { y <- getTemporalIntersection(obs = y, prd = x, which.return = "obs") diff --git a/R/prepareNewData.R b/R/prepareNewData.R index 2daca31d..5c297f98 100644 --- a/R/prepareNewData.R +++ b/R/prepareNewData.R @@ -26,7 +26,9 @@ #' @family downscaling.helpers #' @importFrom transformeR getVarNames subsetGrid redim getShape getCoordinates grid2PCs getRefDates array3Dto2Dmat grid2PCs #' @importFrom magrittr %>% extract2 -#' @examples +#' @examples \donttest{ +#' require(transformeR) +#' require(climate4R.datasets) #' # Loading data #' data("VALUE_Iberia_tas") #' y <- VALUE_Iberia_tas @@ -36,6 +38,7 @@ #' data <- prepareData(x = x, y = y, spatial.predictors = list(v.exp = 0.95)) #' # Projecting a new dataset to the calculated EOFs #' newdata <- prepareNewData(x,data) +#' } prepareNewData <- function(newdata, data.structure) { x.varnames <- attr(data.structure, "predictor.vars") diff --git a/R/quickDiagnostics.R b/R/quickDiagnostics.R index 60337248..01b8150e 100644 --- a/R/quickDiagnostics.R +++ b/R/quickDiagnostics.R @@ -17,7 +17,8 @@ #' @return Two diagnostic plots with observed, simulated and (possibly) downscaled time series, and a QQ-plot by percentlies. #' @author M. Iturbide #' @export -#' @examples { +#' @examples \donttest{ +#' require(climate4R.datasets) #' data("VALUE_Iberia_pr") #' data("NCEP_Iberia_pr") #' y <- VALUE_Iberia_pr @@ -83,7 +84,8 @@ quickDiagnostics <- function(obs, #' @importFrom stats sd cor #' @importFrom grDevices rgb #' @keywords internal -#' @importFrom transformeR subsetGrid getCoordinates getYearsAsINDEX draw.world.lines aggregateGrid climatology plotClimatology interpGrid getGrid +#' @importFrom transformeR subsetGrid getCoordinates getYearsAsINDEX aggregateGrid climatology interpGrid getGrid +#' @importFrom visualizeR spatialPlot #' @importFrom sp SpatialPoints interannualOutlook <- function(obs, raw, downscaled = NULL, location = c(-42.5, -3), na.tolerance = .3, ylim = NULL, main = NULL){ @@ -189,11 +191,11 @@ interannualOutlook <- function(obs, raw, downscaled = NULL, location = c(-42.5, } } plcor <- - plotClimatology(corgrid, backdrop.theme = "countries", cuts = seq(-1,1,0.25), - key.space = "bottom", scales=list(draw = TRUE), - auto.key = T,par.settings=list(fontsize=list(text= 8)), - sp.layout = list(list(SpatialPoints(matrix(location,ncol = 2)), - first = FALSE, pch = 2, cex = 1.8, col = "black"))) + visualizeR::spatialPlot(corgrid, backdrop.theme = "countries", cuts = seq(-1,1,0.25), + key.space = "bottom", scales = list(draw = TRUE), + auto.key = TRUE, par.settings = list(fontsize = list(text = 8)), + sp.layout = list(list(SpatialPoints(matrix(location, ncol = 2)), + first = FALSE, pch = 2, cex = 1.8, col = "black"))) grid.arrange(pl, plcor, nrow = 1, ncol = 2, widths = c(1.4,1)) } #end @@ -293,4 +295,4 @@ dailyOutlook <- function(obs, raw, downscaled = NULL, location = c(-42.5, -3), y grabGrob <- function(){ grid.echo() grid.grab() -} \ No newline at end of file +} diff --git a/man/biasCorrection.Rd b/man/biasCorrection.Rd index 4b56eb5d..bc87168b 100644 --- a/man/biasCorrection.Rd +++ b/man/biasCorrection.Rd @@ -211,6 +211,7 @@ automatically adjusted by quantile methods. \examples{ \donttest{ +require(climate4R.datasets) data("EOBS_Iberia_pr") data("CORDEX_Iberia_pr") y <- EOBS_Iberia_pr diff --git a/man/downscale.Rd b/man/downscale.Rd index a8a56ae9..95c5a54e 100644 --- a/man/downscale.Rd +++ b/man/downscale.Rd @@ -58,37 +58,44 @@ When the climate variables are used as predictors instead of the PCs, these are using the mean and sigma parameters globally computed for the whole spatial domain. } \examples{ +\donttest{ +require(transformeR) +require(climate4R.datasets) +data("NCEP_Iberia_hus850") +data("NCEP_Iberia_ta850") x <- makeMultiGrid(NCEP_Iberia_hus850, NCEP_Iberia_ta850) newdata <- subsetGrid(x, years = 1994:1995) x <- subsetGrid(x, years = 1985:1993) # Loading predictands +data("VALUE_Iberia_pr") y <- VALUE_Iberia_pr y <- getTemporalIntersection(obs = y,prd = x, "obs" ) x <- getTemporalIntersection(obs = y,prd = x, "prd" ) ### Analogs ### # None -yp <- downscale(y,x,method = "analogs") -yp <- downscale(y,x,newdata,method = "analogs") +yp <- downscale(y, x, method = "analogs") +yp <- downscale(y, x, newdata, method = "analogs") # kfold -yp <- downscale(y,x,method = "analogs", n.pcs = 15, - cross.val = "kfold", folds = list(c(1985,1986,1987), - c(1988,1989,1990), - c(1991,1992,1993))) +yp <- downscale(y, x, method = "analogs", n.pcs = 15, + cross.val = "kfold", folds = list(c(1985, 1986, 1987), + c(1988, 1989, 1990), + c(1991, 1992, 1993))) # Leave-one-year-out -yp <- downscale(y,x,method = "analogs", n.pcs = 15, +yp <- downscale(y, x, method = "analogs", n.pcs = 15, cross.val = "loocv") ### GLM ### # None -yp <- downscale(y,x,method = "glm", simulate = FALSE, n.pcs = 10, +yp <- downscale(y, x, method = "glm", simulate = FALSE, n.pcs = 10, wet.threshold = 1) -yp <- downscale(y,x,method = "glm", simulate = TRUE, n.pcs = 10, +yp <- downscale(y, x, method = "glm", simulate = TRUE, n.pcs = 10, wet.threshold = 1) # kfold -yp <- downscale(y,x,method = "glm", simulate = FALSE, n.pcs = 10, - cross.val = "kfold", folds = list(c(1985,1986,1987), - c(1988,1989,1990), - c(1991,1992,1993))) +yp <- downscale(y, x, method = "glm", simulate = FALSE, n.pcs = 10, + cross.val = "kfold", folds = list(c(1985, 1986, 1987), + c(1988, 1989, 1990), + c(1991, 1992, 1993))) +} } \seealso{ downscaleTrain for training a downscaling model diff --git a/man/downscaleCV.Rd b/man/downscaleCV.Rd index f2e81e65..3dc5b24a 100644 --- a/man/downscaleCV.Rd +++ b/man/downscaleCV.Rd @@ -85,7 +85,9 @@ According to the concept of cross-validation, a particular year should not appea will raise an error, as 1989 appears in more than one fold. } \examples{ +\donttest{ require(transformeR) +require(climate4R.datasets) data(NCEP_Iberia_hus850, NCEP_Iberia_ta850) x <- makeMultiGrid(NCEP_Iberia_hus850, NCEP_Iberia_ta850) x <- subsetGrid(x, years = 1985:1995) @@ -116,6 +118,7 @@ pred <- downscaleCV(x,y,folds = 3, sampling.strategy = "kfold.chronological", method = "GLM", condition = "GT", threshold = 0, prepareData.args = list("local.predictors" = list(vars = "hus@850", n = 4))) } +} \seealso{ downscaleTrain for training a downscaling model downscalePredict for prediction for a a test dataset with a trained model for diff --git a/man/downscalePredict.Rd b/man/downscalePredict.Rd index d6c46420..d5f347bd 100644 --- a/man/downscalePredict.Rd +++ b/man/downscalePredict.Rd @@ -18,8 +18,10 @@ A regular/irregular grid object. Downscale data to local scales by statistical models previously obtained by \code{\link[downscaleR]{downscaleTrain}}. } \examples{ +\donttest{ # Loading data -library(downscaleR) +require(transformeR) +require(climate4R.datasets) data("VALUE_Iberia_tas") y <- VALUE_Iberia_tas data("NCEP_Iberia_hus850", "NCEP_Iberia_psl", "NCEP_Iberia_ta850") @@ -44,6 +46,7 @@ pred <- downscalePredict(newdata, model.analogs) # predicting # Plotting the results for station 5 plot(yt$Data[,5],pred$Data[,5]) } +} \seealso{ downscaleTrain for training a downscaling model prepareNewData for predictor preparation with new (test) data diff --git a/man/downscaleTrain.Rd b/man/downscaleTrain.Rd index 624b0e3b..a8451b27 100644 --- a/man/downscaleTrain.Rd +++ b/man/downscaleTrain.Rd @@ -120,6 +120,7 @@ If there are still doubts about the optional parameters despite the description \donttest{ # Loading data require(transformeR) +require(climate4R.datasets) data("VALUE_Iberia_tas") y <- VALUE_Iberia_tas data("NCEP_Iberia_hus850", "NCEP_Iberia_psl", "NCEP_Iberia_ta850") diff --git a/man/prepareData.Rd b/man/prepareData.Rd index 69ce0b03..3020351b 100644 --- a/man/prepareData.Rd +++ b/man/prepareData.Rd @@ -73,7 +73,10 @@ Configuration of data for flexible downscaling experiment definition \code{subset.vars}. } \examples{ +\donttest{ +require(transformeR) # Loading data +require(climate4R.datasets) data("VALUE_Iberia_tas") y <- VALUE_Iberia_tas data("NCEP_Iberia_hus850", "NCEP_Iberia_psl", "NCEP_Iberia_ta850") @@ -91,6 +94,7 @@ data <- prepareData(x = x, y = y,local.predictors = list(n=4, vars = getVarNames data <- prepareData(x = x, y = y,local.predictors = list(n=4, vars = getVarNames(x)), spatial.predictors = list(v.exp = 0.95, which.combine =getVarNames(x))) } +} \seealso{ \href{https://github.com/SantanderMetGroup/downscaleR/wiki/preparing-predictor-data}{downscaleR Wiki} for preparing predictors for downscaling and seasonal forecasting. diff --git a/man/prepareNewData.Rd b/man/prepareNewData.Rd index c892ea2a..3d6dc953 100644 --- a/man/prepareNewData.Rd +++ b/man/prepareNewData.Rd @@ -18,6 +18,9 @@ A named list with the components required by the downscaling method in order to Prepare the prediction data according to the definition of the experiment } \examples{ +\donttest{ +require(transformeR) +require(climate4R.datasets) # Loading data data("VALUE_Iberia_tas") y <- VALUE_Iberia_tas @@ -28,6 +31,7 @@ data <- prepareData(x = x, y = y, spatial.predictors = list(v.exp = 0.95)) # Projecting a new dataset to the calculated EOFs newdata <- prepareNewData(x,data) } +} \seealso{ \href{https://github.com/SantanderMetGroup/downscaleR/wiki/preparing-predictor-data}{downscaleR Wiki} for preparing predictors for downscaling and seasonal forecasting. diff --git a/man/quickDiagnostics.Rd b/man/quickDiagnostics.Rd index 7729fc8a..9ae1c24b 100644 --- a/man/quickDiagnostics.Rd +++ b/man/quickDiagnostics.Rd @@ -45,7 +45,8 @@ Two diagnostic plots with observed, simulated and (possibly) downscaled time ser Plots daily/annual series and the annual correlation map of different grid objects } \examples{ -{ +\donttest{ +require(climate4R.datasets) data("VALUE_Iberia_pr") data("NCEP_Iberia_pr") y <- VALUE_Iberia_pr