This repository contains the code for the R-package that provides functions for all the routine steps in running the SOFUN model:
- Setup of the model environment
- Preparation of input files
- Calibrating model parameters
- Running the model
- Reading outputs into R
- Evaluating outputs (benchmarking)
Get this R-package by
install_github("stineb/rsofun")
Note that the package rsofun
requires a large number of other R-packages (dependencies). Some are required only for specific tasks (e.g. creating certain plots or applying certain calibration methods). These are loaded optionally (XXX TODO XXX). Others are essential as the source code is generally implemented adopting tidyverse
syntax. Essential dependencies need to be installed beforehand and are loaded with the library(rsofun)
call. These are:
dplyr
tidyr
purrr
readr
rlang
stringr
ggplot2
lubridate
Metrics
mgcv
ncdf4
optimr
Suggested dependencies are:
GenSA
: used bycalib_sofun()
, ifsettings_calib$method=="gensa"
, see calib_sofun.RBayesianTools
: used bycalib_sofun()
, ifsettings_calib$method=="BayesianTools"
, see calib_sofun.Rcaret
: used bygapfill_nn()
, see gapfill_nn.R and prepare_input_sofun.Rneuralnet
: used bygapfill_nn()
andeval_response_neuralnet()
, see eval_response_neuralnet.R and gapfill_nn.Rnnet
: used bygapfill_nn()
andeval_response_neuralnet()
, see eval_response_neuralnet.R and gapfill_nn.RhydroGOF
: used byanalyse_modobs()
to calculate the Nash-Sutcliffe model efficiency, see analyse_modobs.R
Install required dependencies by:
list_of_packages <- c( "dplyr", "tidyr", "purrr", "readr", "rlang", "stringr",
"ggplot2", "lubridate", "Metrics", "mgcv", "ncdf4", "optimr"
)
new_packages <- list_of_packages[!(list.of.packages %in% installed.packages()[,"Package"])]
if( length(new_packages)>0 ) install.packages(new_packages)
Several functions require external programs called by system()
calls from within R. Required programs need to be installed beforehand, as follows:
- NCO. Is used by
get_pointdata_()
functions (executing the Bash script"./extract_pointdata_byfil.sh"
with NCO commandncks
). Before usingrsofun
, install NCO on a Mac by
brew tap homebrew/science
brew install nco
- CDO. Is used by the
proc_ncout_sofun_bysite()
function (executing Bash script"./proc_output_sofun.sh"
with CDO commandcdo mergetime
). Before usingrsofun
, install CDO on a Mac by
brew install cdo
Apparently, CDO is no longer available as a Homebrew formula (right?). Unse MacPorts instead:
sudo port install cdo
Examples are given in several vignettes, also available here.