Skip to content

Commit

Permalink
Updated vignette and some functions (minor changes)
Browse files Browse the repository at this point in the history
  • Loading branch information
dazamora committed May 7, 2020
1 parent 8ae8cc3 commit 4eb6172
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 20 deletions.
8 changes: 3 additions & 5 deletions R/graphDWB.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#' followed by the evapotranspiration series and finally the runoff time series. \cr
#' @param tp Variable which is defined to choose the type of graph.
#' @param main Main title for the graph.
#' @param int logical. FALSE value to interactive vignette
#' @param ... Other parameters of the \pkg{dygraphs} package.
#'
#' @return Prints a dynamic graph according to the requirements.
Expand Down Expand Up @@ -74,7 +73,7 @@
#'
#' graphDWB(var, tp = 4, main = "General Comparison Sogamoso Basin")
#'
graphDWB <- function(var, tp, main, int = TRUE, ...){
graphDWB <- function(var, tp, main, ...){
nvar <- length(var)
if (nvar == 0){
stop('The list must contain at least one time series variable')
Expand Down Expand Up @@ -164,8 +163,7 @@ graphDWB <- function(var, tp, main, int = TRUE, ...){
} else {
stop('Wrong type of graph')
}
if(int){
if(interactive()){}
}

if(interactive())
return(plot)
}
10 changes: 6 additions & 4 deletions R/upForcing.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
#' # meteo <- upForcing(path_p = "./precip/", path_pet = "./pet/",
#' # file_type = "csv")
#'
upForcing <- function(path_p = "./precip/", path_pet = "./pet/", file_type = "raster", format = "GTiff"){
upForcing <- function(path_p = tempdir(), path_pet = tempdir(), file_type = "raster", format = "GTiff"){

if (!exists("path_pet")){
path_pet <- getwd()
Expand Down Expand Up @@ -75,9 +75,11 @@ upForcing <- function(path_p = "./precip/", path_pet = "./pet/", file_type = "ra
p_v <- raster::rasterToPoints(p)
pet_v <- raster::rasterToPoints(pet)
# ---- print forcings ----
dir.create("./forcings", showWarnings = F)
write.csv(p_v, "./forcings/precip.csv")
write.csv(pet_v, "./forcings/pet.csv")
# dir.create("./forcings", showWarnings = F)
# write.csv(p_v, "./forcings/precip.csv")
# write.csv(pet_v, "./forcings/pet.csv")
write.csv(p_v, "precip.csv")
write.csv(pet_v, "pet.csv")
} else { # load forcings in csv files
pet_files <- list.files(path_pet)
p_files <- list.files(path_p)
Expand Down
4 changes: 1 addition & 3 deletions man/graphDWB.Rd

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

2 changes: 1 addition & 1 deletion man/upForcing.Rd

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

Binary file removed vignettes/Sogamoso_Basin.jpg
Binary file not shown.
10 changes: 3 additions & 7 deletions vignettes/examples_dwbmodel.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ knitr::opts_chunk$set(

`DWBCalculator` is the function responsible for incorporating the DWB model calculations into the **DWBmodelUN** package. In this connection, the following example corresponds to an ungauged modeling exercise developed for the Sogamoso river basin (SRB) by (Duque, 2018).

```{r rstudio-create-pkg, echo = FALSE, fig.align= "center", fig.height=6, fig.width=6, dpi = 600}
knitr::include_graphics("Sogamoso_Basin.jpg", dpi = NA)
```

As a first step, the example starts with loading datasets generated for SRB that are required by DWB model and subsequently, the coordinates system of the input data are verified. The last step is to run `DWBCalculator` function in order to obtain a monthly streamflow simulated.

```{r echo=TRUE, results='hide'}
Expand Down Expand Up @@ -167,7 +163,7 @@ library(dygraphs)
data(P_sogamoso)
P.est <- ts(c(t(P_sogamoso[1, -2:-1])), star = c(2012, 1), frequency = 12)
var <- list("Precipitation" = P.est)
graphDWB(var, tp = 1, main = "Precipitation Lat:7.0 Lon:-72.94", int = FALSE)
graphDWB(var, tp = 1, main = "Precipitation Lat:7.0 Lon:-72.94")
```

### Second: Example with precipitation and runoff time series
Expand All @@ -180,7 +176,7 @@ P.est <- ts(c(t(P_sogamoso[1, -2:-1])), star = c(2012, 1), frequency = 12)
runoff.sim <- ts(simDWB.sogamoso[c(131:192) ,1], star = c(2012, 1), frequency = 12)
runoff.obs <- ts(EscSogObs[c(131:192) ,1] , star = c(2012, 1), frequency = 12)
var <- list("Precipitation" = P.est,"Runoff.sim" = runoff.sim, "Runoff.obs" = runoff.obs)
graphDWB(var, tp = 3, main = "DWB results at Sogamoso Basin", int = FALSE)
graphDWB(var, tp = 3, main = "DWB results at Sogamoso Basin")
```

### Third: Example with precipitation and runoff time series
Expand All @@ -193,7 +189,7 @@ P <- ts(c(t(P_sogamoso[1, -2:-1])), star = c(2012, 1), frequency = 12)
PET <- ts(c(t(PET_sogamoso[1, -2:-1])), star = c(2012, 1), frequency = 12)
runoff.sim <- ts(simDWB.sogamoso[c(131:192), 1], star = c(2012, 1), frequency = 12)
var <- list("P" = P,"PET" = PET, "Runoff.sim" = runoff.sim)
graphDWB(var, tp = 4, main = "General Comparison Sogamoso Basin", int = FALSE)
graphDWB(var, tp = 4, main = "General Comparison Sogamoso Basin")
```

## References
Expand Down

0 comments on commit 4eb6172

Please sign in to comment.