This is an example Raven modelling workflow that exports to HTML. It assumes that you have a model built and wish to view the output. This Rmd file should be placed in the output directory, which is assumed to be one directory below the main file. To compile, open up in RStudio and hit ‘knit’ at the top of the screen- it will create a nice partially interactive HTML file. The R markdown file which generated this HTML example is available here. This is compatible with the Raven tutorial #2 model of the Alouette basin.
library(knitr)
library(RavenR)
library(dygraphs)
library(htmlwidgets)
knitr::opts_chunk$set(fig.width=10,fig.height=2.5) #default figure height
fileprefix <-"Alouette" # this needs to be modified for each new model
ravenfile <-"C:/TEMP/Raven.exe" # this one too!
runtag <-"" # or could be run1_ # this needs to be modified IF the :RunName command is used
outdir <-getwd()
outdir <-paste0(outdir,"/")
indir <-dirname(outdir)
This generates and runs the following command prompt command, thus running Raven:
Raven.exe [filename] -o [outputdir]
This step is not necessary if you have already run Raven.
RavenCMD <-paste(ravenfile," ",indir,"/",fileprefix," -o ",outdir,sep="");
invisible(system(RavenCMD));
#system(RavenCMD,intern = TRUE) # or use this to print all console output to HTML
An interactive dygraph hydrograph display:
hyd_file<-paste0(outdir,runtag,"Hydrographs.csv");
if (file.exists(hyd_file)){
hy<-rvn_hyd_read(hyd_file)
dyplot<-rvn_hyd_dygraph(hy,figheight = 300)
htmltools::tagList(dyplot)
}
A basic precipitation plot display:
forcing_file<-paste0(outdir,runtag,"ForcingFunctions.csv");
if (file.exists(forcing_file)){
ff_data <- rvn_forcings_read(forcing_file)
myplots <- rvn_forcings_plot(ff_data$forcings)
myplots$Precipitation
}
An interactive temperature display:
forcing_file<-paste0(outdir,runtag,"ForcingFunctions.csv");
if (file.exists(forcing_file)){
tempdata<-cbind(ff_data$forcings$temp_daily_min,ff_data$forcings$temp_daily_max)
iplot<-dygraph(tempdata,width=900,height=200)
htmltools::tagList(iplot)
}
A simple plot of watershed average snowpack:
wshed_file<-paste0(outdir,runtag,"WatershedStorage.csv");
if (file.exists(wshed_file)){
mywshd <- rvn_watershed_read(wshed_file)
plot(mywshd$watershed_storage$Snow,main='Snowpack (mm SWE)',col='blue')
}
Contents of the Diagnostics.csv file:
diag_file<-paste0(outdir,runtag,"Diagnostics.csv");
if (file.exists(diag_file)){
diagtab <- read.csv(diag_file, header = TRUE)
diagtab <-diagtab[1:(length(diagtab)-1)] #trims last unused column
kable(diagtab, caption="Model Diagnostics")
}
observed.data.series | filename | DIAG_NASH_SUTCLIFFE | DIAG_PCT_BIAS |
---|---|---|---|
HYDROGRAPH_ALL | C:/TEMP/Alouette//AlouetteObservedFlow.rvt | 0.82286 | 12.0729 |