Skip to content

Commit

Permalink
Example update using climate4R.datasets
Browse files Browse the repository at this point in the history
  • Loading branch information
jbedia committed May 23, 2020
1 parent b3759a0 commit 8a2759e
Show file tree
Hide file tree
Showing 18 changed files with 96 additions and 52 deletions.
13 changes: 7 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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 <http://meteo.unican.es/climate4r>
Version: 3.2.0
Date: 2020-04-23
Date: 2020-05-23
Authors@R: as.person(c(
"Santander Meteorology Group <http://meteo.unican.es> [cph]",
"Joaquín Bedia <bediaj@unican.es> [aut, cre]",
Expand All @@ -46,7 +47,7 @@ Authors@R: as.person(c(
"Jorge B. Medina <bmedina@ifca.unican.es> [aut]",
"Beata Szabo-Takacs <szabo.b@czechglobe.cz> [ctb]",
"Max Tuni <max@predictia.es> [ctb]",
"Ana Casanueva <ana.casanueva@unican.es> [ctb]"))
"Ana Casanueva <ana.casanueva@unican.es> [aut]"))
BugReports: https://github.com/SantanderMetGroup/downscaleR/issues
URL: http://www.meteo.unican.es/climate4r
Encoding: UTF-8
Expand Down
3 changes: 1 addition & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -97,11 +96,11 @@ 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)
importFrom(transformeR,subsetDimension)
importFrom(transformeR,subsetGrid)
importFrom(transformeR,typeofGrid)
importFrom(utils,packageDescription)
importFrom(visualizeR,spatialPlot)
1 change: 1 addition & 0 deletions R/biasCorrection.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 21 additions & 15 deletions R/downscale.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -179,4 +185,4 @@ downscale <- function(y,
}
}
return(yp)
}
}
4 changes: 3 additions & 1 deletion R/downscaleCV.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 5 additions & 3 deletions R/downscalePredict.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
Expand Down Expand Up @@ -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)}
return(pred)}
1 change: 1 addition & 0 deletions R/downscaleTrain.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
5 changes: 4 additions & 1 deletion R/prepareData.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand Down
5 changes: 4 additions & 1 deletion R/prepareNewData.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down
18 changes: 10 additions & 8 deletions R/quickDiagnostics.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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){
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -293,4 +295,4 @@ dailyOutlook <- function(obs, raw, downscaled = NULL, location = c(-42.5, -3), y
grabGrob <- function(){
grid.echo()
grid.grab()
}
}
1 change: 1 addition & 0 deletions man/biasCorrection.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 20 additions & 13 deletions man/downscale.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions man/downscaleCV.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion man/downscalePredict.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/downscaleTrain.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8a2759e

Please sign in to comment.