From af9bfec1aae6710db521cacc8b54ad33e2acbb62 Mon Sep 17 00:00:00 2001 From: Robert Chlumsky Date: Wed, 17 Apr 2024 13:53:31 -0400 Subject: [PATCH 1/3] Update rvn_download.R Updated Raven url to https from http --- R/rvn_download.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/R/rvn_download.R b/R/rvn_download.R index f6cb46a..0695bff 100644 --- a/R/rvn_download.R +++ b/R/rvn_download.R @@ -1,10 +1,10 @@ #' @title Downloads Raven #' #' @description -#' Downloads Raven executable from the \href{http://raven.uwaterloo.ca/Downloads.html}{Raven webpage}. +#' Downloads Raven executable from the \href{https://raven.uwaterloo.ca/Downloads.html}{Raven webpage}. #' #' @details -#' Files are downloaded from the Raven webpage (\url{http://raven.uwaterloo.ca/Downloads.html}) and placed +#' Files are downloaded from the Raven webpage (\url{https://raven.uwaterloo.ca/Downloads.html}) and placed #' in a temporary directory while the executable is extracted. This helps prevent any unwanted files being #' saved on your system outside of temporary directories if the function is interrupted. The executable is placed in the #' RavenR/extdata directory, wherever RavenR is installed on your system. @@ -85,7 +85,7 @@ rvn_download<-function(version=NA,NetCDF=FALSE,check=FALSE,copy_path=NULL) } platform <- tolower(os) - url <- "http://raven.uwaterloo.ca/Downloads.html" + url <- "https://raven.uwaterloo.ca/Downloads.html" html <- paste(readLines(url), collapse="\n") matched <- str_match_all(html, " Date: Wed, 17 Apr 2024 14:36:20 -0400 Subject: [PATCH 2/3] Update rvn_rvi_write_template.R Added SAC-SMA template to rvn_rvi_write_template --- R/rvn_rvi_write_template.R | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/R/rvn_rvi_write_template.R b/R/rvn_rvi_write_template.R index 25e1925..3ee816b 100644 --- a/R/rvn_rvi_write_template.R +++ b/R/rvn_rvi_write_template.R @@ -19,7 +19,7 @@ #' for ease of getting started with a model using Raven. #' #' The template_name parameter should be one of "UBCWM", "HBV-EC", "HBV-Light", "GR4J", -#' "CdnShield", "MOHYSE", "HMETS", "HYPR", or "HYMOD". +#' "CdnShield", "MOHYSE", "HMETS", "HYPR", "HYMOD", or "SAC-SMA". #' #' This function uses the same model template files that are provided in the Raven User's manual, Appendix D. #' @@ -44,7 +44,7 @@ rvn_rvi_write_template <- function(template_name="UBCWM", filename=NULL, filetype="rvi ASCII Raven", author="RavenR", description=NULL) { - known_templates <- c("UBCWM", "HBV-EC", "HBV-Light", "GR4J", "CdnShield", "MOHYSE", "HMETS", "HYPR", "HYMOD") + known_templates <- c("UBCWM", "HBV-EC", "HBV-Light", "GR4J", "CdnShield", "MOHYSE", "HMETS", "HYPR", "HYMOD", "SAC-SMA") if (is.null(template_name) | template_name %notin% known_templates) { stop("template_name must be one of the available model templates, see function details") @@ -477,6 +477,39 @@ rvn_rvi_write_template <- function(template_name="UBCWM", filename=NULL, # +", + +"SAC-SMA"=" +:StartDate 2000-01-01 00:00:00 +:Duration 365 +:TimeStep 1.0 + +# Model options for SAC-SMA emulation +#------------------------------------------------------------------------ +:PotentialMeltMethod POTMELT_DEGREE_DAY +:RainSnowFraction RAINSNOW_DATA +:Evaporation PET_DATA +:CatchmentRoute ROUTE_DUMP +:Routing ROUTE_NONE + +:SoilModel SOIL_MULTILAYER 7 + +:Alias UZ_T SOIL[0] +:Alias UZ_F SOIL[1] +:Alias LZ_T SOIL[2] +:Alias LZ_PF SOIL[3] +:Alias LZ_PS SOIL[4] + +:HydrologicProcesses + :SnowBalance SNOBAL_SIMPLE_MELT SNOW PONDED_WATER + :Precipitation RAVEN_DEFAULT ATMOS_PRECIP MULTIPLE + :SoilEvaporation SOILEVAP_SACSMA MULTIPLE ATMOSPHERE + :SoilBalance SOILBAL_SACSMA MULTIPLE MULTIPLE + :OpenWaterEvaporation OPEN_WATER_RIPARIAN SURFACE_WATER ATMOSPHERE +:EndHydrologicProcesses + +# + " ) From f213eabb8fdbd41ee8df2e46a29c7ac74240d485 Mon Sep 17 00:00:00 2001 From: rchlumsk Date: Mon, 6 May 2024 11:15:58 -0400 Subject: [PATCH 3/3] Minor fixes, added rvn_csv_read, added blended templates to rvi templates, updated .dat tables closes #114 closes #117 --- DESCRIPTION | 6 +- NAMESPACE | 2 + R/rvn_csv_read.R | 93 +++++++++++++++++ R/rvn_rvi_write_template.R | 125 +++++++++++++++++++++-- R/rvn_rvt_write_met.R | 20 +--- R/rvn_utilities.R | 11 +- inst/extdata/RavenAlgParams.dat | 12 ++- inst/extdata/RavenParameters.dat | 23 ++++- inst/extdata/RavenProcessConnections.dat | 5 + man/RavenR-package.Rd | 15 +++ man/rvn_csv_read.Rd | 41 ++++++++ man/rvn_download.Rd | 4 +- man/rvn_rvh_write.Rd | 4 +- man/rvn_rvi_write_template.Rd | 4 +- man/rvn_rvt_write_met.Rd | 10 -- vignettes/Introduction_to_RavenR.Rmd | 5 +- 16 files changed, 326 insertions(+), 54 deletions(-) create mode 100644 R/rvn_csv_read.R create mode 100644 man/rvn_csv_read.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 1a00765..b110628 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: RavenR Type: Package Title: Raven Hydrological Modelling Framework R Support and Analysis -Version: 2.2.0 -Date: 2022-10-28 +Version: 2.2.1 +Date: 2024-05-06 Authors@R: c( person("Robert", "Chlumsky", email = "rchlumsk@uwaterloo.ca", role = c("cre","aut"), comment = c(ORCID = "0000-0002-1303-5064")), person("James", "Craig", email = "jrcraig@uwaterloo.ca", role = c("ctb","aut"), comment = c(ORCID = "0000-0003-2715-7166")), @@ -52,6 +52,6 @@ URL: https://github.com/rchlumsk/RavenR License: GPL-3 Encoding: UTF-8 LazyData: TRUE -RoxygenNote: 7.1.2 +RoxygenNote: 7.3.1 VignetteBuilder: knitr LinkingTo: Rcpp diff --git a/NAMESPACE b/NAMESPACE index e992149..b9d83c3 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -15,6 +15,7 @@ export(rvn_apply_wyearly) export(rvn_apply_wyearly_which_max_xts) export(rvn_budyko_plot) export(rvn_calc_runoff_coeff) +export(rvn_csv_read) export(rvn_cum_plot_flow) export(rvn_custom_output_plot) export(rvn_custom_read) @@ -102,6 +103,7 @@ importFrom(cowplot,draw_label) importFrom(cowplot,ggdraw) importFrom(cowplot,plot_grid) importFrom(crayon,green) +importFrom(dplyr,"%>%") importFrom(dplyr,across) importFrom(dplyr,all_of) importFrom(dplyr,as_tibble) diff --git a/R/rvn_csv_read.R b/R/rvn_csv_read.R new file mode 100644 index 0000000..ea06f5c --- /dev/null +++ b/R/rvn_csv_read.R @@ -0,0 +1,93 @@ +#' @title Read in generic Raven output csv files +#' +#' @description +#' Reads in output csv files produced by Raven. +#' +#' @details +#' Expects a full file path to the Raven output file. +#' +#' The timezone is provided by the tzone argument as "UTC" by default, and should be adjusted by +#' the user to the local time zone as needed, based on the model run. +#' +#' @param ff full file path to the csv file +#' @param tzone string indicating the timezone of the data in ff +#' @param xtsformat boolean whether to return in xts format (if date and/or hour found) +#' @return \item{data frame (as xts if set with \code{xtsformat}) read from the file} +#' @seealso \code{\link{rvn_hyd_read}} for reading Hydrographs output files +#' +#' @examples +#' # create full file path +#' ff <- system.file("extdata","ReservoirStages.csv", package="RavenR") +#' +#' # read in the Reservoir file with the generic call +#' myres <- rvn_csv_read(ff) +#' +#' # view contents +#' head(myres) +#' +#' @export rvn_csv_read +#' @importFrom xts xts +#' @importFrom dplyr %>% +#' @importFrom xts xts +#' @importFrom utils read.csv +rvn_csv_read <- function(ff=NA, tzone="UTC", xtsformat=TRUE) { + + if (missing(ff)) { + stop("Requires the full file path to the Raven csv output file.") + } + + #read output + dd <- read.csv(ff,header=TRUE,nrows=5) + # careful in date-time formats; excel can screw it up if csv is saved over. This works for + # an untouched Raven output file + + cols <- colnames(dd) + classes <- rep(NA,length(cols)) + if ("time" %in% cols) { + classes[which(cols=="time")] <- "integer" + } + if ("date" %in% cols) { + classes[which(cols=="date")] <- "Date" + } + if ("hour" %in% cols) { + classes[which(cols=="hour")] <- "character" + } + + # re-read with specified colClasses + dd <- read.csv(ff,header=TRUE,colClasses = classes,na.strings=c("---",'NA')) + + dt <- NULL + if ("date" %in% cols) { + if ("hour" %in% cols) { + dt <- as.POSIXct(paste(dd$date,dd$hour), format="%Y-%m-%d %H:%M:%S", tz=tzone) + } else { + dt <- as.Date(dd$date) + } + # check if dt converted properly + if (any(is.na(dt))) { + warning("date and time failed to convert from date and hour columns, please check file format.") + dt <- NULL + } + } + + # change all dots to underscore + newcols <- cols %>% + gsub("\\.\\.\\.","\\.\\.",x=.) %>% + gsub("\\.\\.","\\.",x=.) %>% + gsub("\\.","_",x=.) + + # trim all last underscores + for (i in 1:length(newcols)) { + if (rvn_substrRight(newcols[i],1) == "_") { + newcols[i] <- rvn_substrMRight(newcols[i],1) + } + } + colnames(dd) <- newcols + + # change to xtsformat if desired + if (xtsformat & !is.null(dt)) { + dd <- xts(order.by=dt,x=dd) + } + + return(dd) +} diff --git a/R/rvn_rvi_write_template.R b/R/rvn_rvi_write_template.R index 3ee816b..176c0d2 100644 --- a/R/rvn_rvi_write_template.R +++ b/R/rvn_rvi_write_template.R @@ -7,7 +7,7 @@ #' @param filename Name of the rvi file, with extension (optional) #' @param overwrite boolean whether to overwrite file if it already exists (default \code{FALSE}) #' @param writeheader boolean whether to write a header to the rvi file (default \code{TRUE}) -#' @param filetype File extension, Encoding, Raven version (e.g. "rvp ASCII Raven 2.9.1") (optional) +#' @param filetype File extension, Encoding, Raven version (e.g. "rvp ASCII Raven v3.8") (optional) #' @param author Name of file author (optional) #' @param description File Description for header (e.g., Basin or project information, R script name) (optional) #' @@ -19,7 +19,7 @@ #' for ease of getting started with a model using Raven. #' #' The template_name parameter should be one of "UBCWM", "HBV-EC", "HBV-Light", "GR4J", -#' "CdnShield", "MOHYSE", "HMETS", "HYPR", "HYMOD", or "SAC-SMA". +#' "CdnShield", "MOHYSE", "HMETS", "HYPR", "HYMOD", "SAC-SMA", "blended", or "blended_v2". #' #' This function uses the same model template files that are provided in the Raven User's manual, Appendix D. #' @@ -44,7 +44,8 @@ rvn_rvi_write_template <- function(template_name="UBCWM", filename=NULL, filetype="rvi ASCII Raven", author="RavenR", description=NULL) { - known_templates <- c("UBCWM", "HBV-EC", "HBV-Light", "GR4J", "CdnShield", "MOHYSE", "HMETS", "HYPR", "HYMOD", "SAC-SMA") + known_templates <- c("UBCWM", "HBV-EC", "HBV-Light", "GR4J", "CdnShield", "MOHYSE", "HMETS", "HYPR", + "HYMOD", "SAC-SMA", "blended","blended_v2") if (is.null(template_name) | template_name %notin% known_templates) { stop("template_name must be one of the available model templates, see function details") @@ -490,7 +491,7 @@ rvn_rvi_write_template <- function(template_name="UBCWM", filename=NULL, :RainSnowFraction RAINSNOW_DATA :Evaporation PET_DATA :CatchmentRoute ROUTE_DUMP -:Routing ROUTE_NONE +:Routing ROUTE_NONE :SoilModel SOIL_MULTILAYER 7 @@ -498,14 +499,124 @@ rvn_rvi_write_template <- function(template_name="UBCWM", filename=NULL, :Alias UZ_F SOIL[1] :Alias LZ_T SOIL[2] :Alias LZ_PF SOIL[3] -:Alias LZ_PS SOIL[4] +:Alias LZ_PS SOIL[4] :HydrologicProcesses :SnowBalance SNOBAL_SIMPLE_MELT SNOW PONDED_WATER - :Precipitation RAVEN_DEFAULT ATMOS_PRECIP MULTIPLE + :Precipitation RAVEN_DEFAULT ATMOS_PRECIP MULTIPLE :SoilEvaporation SOILEVAP_SACSMA MULTIPLE ATMOSPHERE :SoilBalance SOILBAL_SACSMA MULTIPLE MULTIPLE - :OpenWaterEvaporation OPEN_WATER_RIPARIAN SURFACE_WATER ATMOSPHERE + :OpenWaterEvaporation OPEN_WATER_RIPARIAN SURFACE_WATER ATMOSPHERE +:EndHydrologicProcesses + +# + +", + "blended"=" +:StartDate 2000-01-01 00:00:00 +:Duration 365 +:TimeStep 1.0 +:Method ORDERED_SERIES +:Interpolation INTERP_NEAREST_NEIGHBOR + +:PotentialMeltMethod POTMELT_HMETS +:RainSnowFraction RAINSNOW_HBV +:SWRadiationMethod SW_RAD_NONE # no radiation is faster +:Evaporation PET_DATA +:CatchmentRoute ROUTE_DUMP +:Routing ROUTE_NONE +:SoilModel SOIL_MULTILAYER 2 + +:Alias DELAYED_RUNOFF CONVOLUTION[1] + +:HydrologicProcesses + :Precipitation RAVEN_DEFAULT ATMOS_PRECIP MULTIPLE + :ProcessGroup #infiltration group + :Infiltration INF_HMETS PONDED_WATER MULTIPLE + :Infiltration INF_VIC_ARNO PONDED_WATER MULTIPLE + :Infiltration INF_HBV PONDED_WATER MULTIPLE + :EndProcessGroup CALCULATE_WTS 0.556 0.5 + :Overflow OVERFLOW_RAVEN SOIL[0] DELAYED_RUNOFF + :ProcessGroup #quickflow group + :Baseflow BASE_LINEAR_ANALYTIC SOIL[0] SURFACE_WATER # interflow, really + :Baseflow BASE_VIC SOIL[0] SURFACE_WATER + :Baseflow BASE_TOPMODEL SOIL[0] SURFACE_WATER + :EndProcessGroup CALCULATE_WTS 0.556 0.5 + :Percolation PERC_LINEAR SOIL[0] SOIL[1] # recharge + :Overflow OVERFLOW_RAVEN SOIL[1] DELAYED_RUNOFF + :Percolation PERC_LINEAR SOIL[1] SOIL[2] # loss to deep gw + :ProcessGroup #evaporation group + :SoilEvaporation SOILEVAP_ALL SOIL[0] ATMOSPHERE # AET + :SoilEvaporation SOILEVAP_TOPMODEL SOIL[0] ATMOSPHERE # AET + :EndProcessGroup CALCULATE_WTS 0.5 + :Convolve CONVOL_GAMMA CONVOLUTION[0] SURFACE_WATER # 'surface runoff' + :Convolve CONVOL_GAMMA_2 DELAYED_RUNOFF SURFACE_WATER # 'delayed runoff' + :ProcessGroup #quickflow group + :Baseflow BASE_LINEAR_ANALYTIC SOIL[1] SURFACE_WATER + :Baseflow BASE_POWER_LAW SOIL[1] SURFACE_WATER + :EndProcessGroup CALCULATE_WTS 0.5 + :ProcessGroup #snow balance group + :SnowBalance SNOBAL_HMETS MULTIPLE MULTIPLE + :SnowBalance SNOBAL_SIMPLE_MELT SNOW PONDED_WATER + :SnowBalance SNOBAL_HBV MULTIPLE MULTIPLE + :EndProcessGroup CALCULATE_WTS 0.556 0.5 +:EndHydrologicProcesses + +# + +", + "blended_v2"=" +:StartDate 2000-01-01 00:00:00 +:Duration 365 +:TimeStep 1.0 +:Method ORDERED_SERIES + +:SoilModel SOIL_MULTILAYER 3 + +:Evaporation PET_BLENDED +:BlendedPETWeights PET_GRANGERGRAY 0.556 PET_HAMON 0.5 PET_PENMAN_MONTEITH + +:PotentialMeltMethod POTMELT_BLENDED +:BlendedPotMeltWeights POTMELT_HMETS 0.5 POTMELT_RESTRICTED + +:RainSnowFraction RAINSNOW_HBV # RAINSNOW_DATA +:PrecipIceptFract PRECIP_ICEPT_USER +:CatchmentRoute ROUTE_DUMP +:Routing ROUTE_NONE + +:Alias DELAYED_RUNOFF CONVOLUTION[1] + +:HydrologicProcesses + :Precipitation RAVEN_DEFAULT ATMOS_PRECIP MULTIPLE + :CanopyDrip CANDRIP_RUTTER CANOPY PONDED_WATER + :Abstraction ABST_PERCENTAGE PONDED_WATER DEPRESSION + :OpenWaterEvaporation OPEN_WATER_EVAP DEPRESSION ATMOSPHERE + :CanopyEvaporation CANEVP_MAXIMUM CANOPY ATMOSPHERE + :CanopySnowEvap CANEVP_MAXIMUM CANOPY_SNOW ATMOSPHERE + :Seepage SEEP_LINEAR DEPRESSION SOIL[1] + :Infiltration INF_HMETS PONDED_WATER MULTIPLE + :Overflow OVERFLOW_RAVEN SOIL[0] DELAYED_RUNOFF + :ProcessGroup #quickflow/interflow group + :Baseflow BASE_POWER_LAW SOIL[0] SURFACE_WATER + :Baseflow BASE_THRESH_POWER SOIL[0] SURFACE_WATER + :EndProcessGroup CALCULATE_WTS 0.5 + :Percolation PERC_LINEAR SOIL[0] SOIL[1] # recharge + :CapillaryRise CRISE_HBV SOIL[1] SOIL[0] + :Overflow OVERFLOW_RAVEN SOIL[1] DELAYED_RUNOFF + :Percolation PERC_LINEAR SOIL[1] SOIL[2] # loss to deep gw + :CapillaryRise CRISE_HBV SOIL[2] SOIL[1] + :ProcessGroup #evaporation group + :SoilEvaporation SOILEVAP_ALL SOIL[0] ATMOSPHERE # AET + :SoilEvaporation SOILEVAP_ROOT SOIL[0] ATMOSPHERE # AET + :SoilEvaporation SOILEVAP_SEQUEN SOIL[0] ATMOSPHERE # AET + :EndProcessGroup CALCULATE_WTS 0.556 0.5 + :Convolve CONVOL_GAMMA CONVOLUTION[0] SURFACE_WATER # 'surface runoff' + :Convolve CONVOL_GAMMA_2 DELAYED_RUNOFF SURFACE_WATER # 'delayed runoff' + :ProcessGroup #baseflow group + :Baseflow BASE_POWER_LAW SOIL[1] SURFACE_WATER + :Baseflow BASE_THRESH_POWER SOIL[1] SURFACE_WATER + :EndProcessGroup CALCULATE_WTS 0.5 + :SnowBalance SNOBAL_HBV MULTIPLE MULTIPLE :EndHydrologicProcesses # diff --git a/R/rvn_rvt_write_met.R b/R/rvn_rvt_write_met.R index 199202e..f420177 100644 --- a/R/rvn_rvt_write_met.R +++ b/R/rvn_rvt_write_met.R @@ -47,12 +47,6 @@ #' that this works for iterations of this function. metdata must include the columns #' ELEV, LAT, and LON if station data is to be written, else the meta data file will not be created. #' -#' write_redirect will print out the :RedirectToFile commands into the file specified -#' by filename_stndata, if write_stndata is \code{TRUE}. These commands can be copied into the main model's -#' .rvt file to redirect to the produced time series files. The function will -#' append to the file if it already exists, meaning that this works for -#' iterations of this function. -#' #' The function has several built-in data quality checks. These include: #' #' * checking that the time interval is consistent for each station; @@ -75,8 +69,6 @@ #' @param met_file_prefix (optional) prefixes the file name (default: "met_") #' @param prd (optional) data period to use in .rvt file #' @param write_stndata (optional) write the gauge data to a separate .rvt file -#' @param write_redirect (optional) write the :RedirectToFile commands in a -#' separate .rvt file #' @param filename_stndata (optional) name of the station data file created (if \code{write_stndata=TRUE}) #' @param NA_value (optional) value to use for NA values in rvt file (default -1.2345 for Raven format) #' @return \item{TRUE}{return \code{TRUE} if the function is executed properly} @@ -103,7 +95,7 @@ #' @importFrom dplyr filter #' @importFrom zoo coredata rvn_rvt_write_met <- function(metdata, rvt_met_mapping=NULL, filenames=NULL, met_file_prefix='met_', prd=NULL, - write_stndata = TRUE, write_redirect=TRUE, filename_stndata = "met_stndata.rvt", + write_stndata = TRUE, filename_stndata = "met_stndata.rvt", NA_value=-1.2345) { # data("rvn_rvt_mappings_data") @@ -301,18 +293,10 @@ rvn_rvt_write_met <- function(metdata, rvt_met_mapping=NULL, filenames=NULL, me writeLines(sprintf(" :Latitude %.6f", md$LAT[k]),fc) writeLines(sprintf(" :Longitude %.6f", md$LON[k]),fc) writeLines(sprintf(" :Elevation %.2f", md$ELEV[k]),fc) + writeLines(sprintf(" :RedirectToFile %s", md$rvt.name[k]),fc) writeLines(":EndGauge\n",fc) } - ## Write Redirect commands in stndata file - if(write_redirect) { - # writeLines("\n",fc) - # fc.redirect = file(rd_file, open = "a+") - for(k in 1:nrow(md)){ - writeLines(sprintf(":RedirectToFile %s", md$rvt.name[k]),fc) - } - } - close(fc) message(sprintf("rvn_rvt_write_met: Done writing station data to %s", filename_stndata)) } diff --git a/R/rvn_utilities.R b/R/rvn_utilities.R index daa0377..e660c18 100644 --- a/R/rvn_utilities.R +++ b/R/rvn_utilities.R @@ -516,7 +516,6 @@ rvn_fortify_xts <- function(x) return(y) } - #' @title Provide known options for Raven rvi options #' #' @description @@ -701,6 +700,15 @@ get_rvt_data_type_mapping <- function() { ), "RESERVOIR_NETINFLOW"=list( "units"="m3/s" + ), + "WATER_LEVEL"=list( + "units"="m" + ), + "STREAM_TEMPERATURE"=list( + "units"="dC" + ), + "STREAM_CONCENTRATION"=list( + "units"="mg/L" ) ) @@ -765,6 +773,7 @@ get_rvt_met_mapping_weathercan <- function() { "TOTAL_SNOW"=list("SNOWFALL"), "MAX_TEMP"=list("TEMP_MAX"), "MIN_TEMP"=list("TEMP_MIN"), + "MEAN_TEMP"=list("TEMP_AVE"), "WIND_SPD"=list("WIND_VEL"), # warning on unit conversion "REL_HUM"=list("REL_HUMIDITY"), "PRECIP_AMT"=list("PRECIP"), # add warning on unit conversion diff --git a/inst/extdata/RavenAlgParams.dat b/inst/extdata/RavenAlgParams.dat index ce7ca5a..029fba8 100644 --- a/inst/extdata/RavenAlgParams.dat +++ b/inst/extdata/RavenAlgParams.dat @@ -37,6 +37,11 @@ SOILEVAP_HYPR SoilEvaporation PET_CORRECTION SOIL SOILEVAP_HYPR SoilEvaporation MAX_DEP_AREA_FRAC LULT SOILEVAP_HYPR SoilEvaporation PONDED_EXP LULT SOILEVAP_HYPR SoilEvaporation DEP_MAX LULT +SOILEVAP_HYMOD2 SoilEvaporation HYMOD2_G LULT +SOILEVAP_HYMOD2 SoilEvaporation HYMOD2_Kmax LULT +SOILEVAP_HYMOD2 SoilEvaporation HYMOD2_exp LULT +SOILEVAP_HYMOD2 SoilEvaporation PDM_B LULT +SOILEVAP_PDM SoilEvaporation PDM_B LULT LAKE_EVAP_BASIC LakeEvaporation LAKE_PET_CORR LULT OPEN_WATER_EVAP OpenWaterEvaporation OW_PET_CORR LULT @@ -152,16 +157,17 @@ ABST_SCS Abstraction SCS_CN LULT ABST_SCS Abstraction SCS_IA_FRACTION LULT ABST_PDMROF Abstraction PDMROF_B LULT ABST_PDMROF Abstraction DEP_MAX LULT -DFLOW_THRESHPOW DepressionOverflow DEP_THRESHHOLD LULT +DFLOW_THRESHPOW DepressionOverflow DEP_THRESHOLD LULT DFLOW_THRESHPOW DepressionOverflow DEP_N LULT DFLOW_THRESHPOW DepressionOverflow DEP_MAX_FLOW LULT DFLOW_THRESHPOW DepressionOverflow DEP_MAX LULT -DFLOW_LINEAR DepressionOverflow DEP_THRESHHOLD LULT +DFLOW_LINEAR DepressionOverflow DEP_THRESHOLD LULT DFLOW_LINEAR DepressionOverflow DEP_K LULT -DFLOW_WEIR DepressionOverflow DEP_THRESHHOLD LULT +DFLOW_WEIR DepressionOverflow DEP_THRESHOLD LULT DFLOW_WEIR DepressionOverflow DEP_CRESTRATIO LULT SEEPAGE_LINEAR Seepage DEP_SEEP_K LULT + # JRC: missing GR4J, HMETS, MOHYSE, CONVOLUTION... ROUTE_DIFFUSIVE_WAVE RoutingMethod MANNINGS_N SUBBASIN diff --git a/inst/extdata/RavenParameters.dat b/inst/extdata/RavenParameters.dat index 88591e5..f5470ea 100644 --- a/inst/extdata/RavenParameters.dat +++ b/inst/extdata/RavenParameters.dat @@ -1,6 +1,6 @@ #RavenParameters.dat -#parameter name, class type, units, autogeneratable, reasonable default, minimum, maximum -#xxx provided as a missing value placeholder +#parameter name, class type, units, autogeneratable, reasonable default, (reasonable) minimum, (reasonable) maximum +#xxx or -9999 provided as a missing value placeholder - Disclaimer: all parameter ranges should be checked when applied in practice! FOREST_COVERAGE LULT [0..1] False 0 0 1 FOREST_COV LULT [0..1] False 0 0 1 @@ -23,7 +23,7 @@ HBV_GLACIER_KMIN LULT [-] False 0.05 -9999 -9999 GLAC_STORAGE_COEFF LULT [1/d] False 0.1 0 1 HBV_GLACIER_AG LULT [-] False 0.05 -9999 -9999 ABST_PERCENT LULT [0..1] False 0.1 0 1 -DEP_MAX LULT [mm] False 6.29 0 20 +DEP_MAX LULT [mm] False 50 0 200 SCS_CN LULT [-] False 50 -9999 -9999 SCS_IA_FRACTION LULT [0..1] False 0.2 0 1 PDMROF_B LULT [-] False 4.0 0.05 10 @@ -33,6 +33,11 @@ DEP_MAX_FLOW LULT [mm/d] False 0.1 0.0 -9999 DEP_K LULT [-] False 0.1 0.0 -9999 DEP_CRESTRATIO LULT [m/m] False 0.0 10 -9999 DEP_SEEP_K LULT [-] False 0.1 0.0 -9999 +PET_VAP_COEFF LULT [mm/d/kPa] False 1.5 1.0 3.0 +PET_LIN_COEFF LULT [mm/d/K] False -9999 0.0 -9999 +WINDVEL_CORR LULT [-] True 1.0 0.0 4.0 +RELHUM_CORR LULT [-] True 1.0 0.5 1.5 +LAKESNOW_BUFFER_HT LULT [-] False 10 0 1000 POROSITY SOIL [0..1] True 0.4 0.0 1.0 VIC_ALPHA SOIL [-] False -9999 -9999 -9999 @@ -118,8 +123,8 @@ MANNINGS_N SUBBASIN [-] False -9999 -9999 9999 SLOPE SUBBASIN [-] False 0.01 0.0 10 RAIN_CORR SUBBASIN [1] True 1.0 0.5 2.0 SNOW_CORR SUBBASIN [1] True 1.0 0.5 2.0 -GAMMA_SHAPE SUBBASIN [-] False 1.0 0.1 10 -GAMMA_SCALE SUBBASIN [1/d] False 3.0 0.1 20 +GAMMA_SHAPE SUBBASIN [-] False 3.0 0.1 10 +GAMMA_SCALE SUBBASIN [1/d] False 1.0 0.1 20 #Newly Added #soil_struct @@ -189,6 +194,8 @@ DRIP_PROPORTION VEG [1/d] False 0.2 0 1 MAX_INTERCEPT_RATE VEG [mm/d] False 10 0 9999 CHU_MATURITY VEG [-] False 2800 0 9999 UPTAKE_MODERATOR VEG [-] True 1 0 1 +CAP_LAI_RATIO VEG [-] True 0.15 0.05 2 +SNOCAP_LAI_RATIO VEG [-] True 0.6 0.2 8 #veg_var_struct LAI VEG [m2/m2] False 4.0 0.0 7 @@ -273,3 +280,9 @@ ASSIMILATION_FACT GLOBAL [0..1] True 1 0 1 ASSIM_UPSTREAM_DECAY GLOBAL [1/km] True 0.01 0 1 ASSIM_TIME_DECAY GLOBAL [1/d] True 0.2 0 1 RESERVOIR_DEMOND_MULT GLOBAL [0..1] False 0 0 1 +HBVEC_LAPSE_UPPER GLOBAL [mm/d/km] True 0 0 0.1 +HBVEC_LAPSE_RATE GLOBAL [mm/d/km] True 0.08 0 0.1 +HBVEC_LAPSE_ELEV GLOBAL [masl] True 5000 3000 7000 +TIME_TO_PEAK_MULTIPLIER GLOBAL [-] True 1 0 5 +GAMMA_SHAPE_MULTIPLIER GLOBAL [-] True 1 0 5 +GAMMA_SCALE_MULTIPLIER GLOBAL [-] True 1 0 5 diff --git a/inst/extdata/RavenProcessConnections.dat b/inst/extdata/RavenProcessConnections.dat index c3d0c5d..e73cd2b 100644 --- a/inst/extdata/RavenProcessConnections.dat +++ b/inst/extdata/RavenProcessConnections.dat @@ -109,6 +109,8 @@ SOILEVAP_UBC SoilEvaporation SOIL[0] ATMOSPHERE SOILEVAP_GR4J SoilEvaporation SOIL[0] ATMOSPHERE SOILEVAP_LINEAR SoilEvaporation SOIL[0] ATMOSPHERE SOILEVAP_ALL SoilEvaporation SOIL[0] ATMOSPHERE +SOLIEVAP_PDM SoilEvaporation SOIL[0] ATMOSPHERE +SOILEVAP_HYMOD2 SoilEvaporation SOIL[0] ATMOSPHERE RAVEN_DEFAULT Recharge ATMOS_PRECIP SOIL #------------------------------------------------- # SNOW PROCESSES @@ -212,6 +214,9 @@ ABST_FILL Abstraction PONDED_WATER DEPRESSION ABST_SCS Abstraction PONDED_WATER DEPRESSION ABST_PDMROF Abstraction PONDED_WATER DEPRESSION ABST_PDMROF Abstraction PONDED_WATER SURFACE_WATER +ABST_UWFS Abstraction PONDED_WATER DEPRESSION +ABST_UWFS Abstraction PONDED_WATER SURFACE_WATER +ABST_UWFS Abstraction MIN_DEP_DEFICIT MIN_DEP_DEFICIT DFLOW_THRESHPOW DepressionOverflow DEPRESSION SURFACE_WATER DFLOW_LINEAR DepressionOverflow DEPRESSION SURFACE_WATER DFLOW_WEIR DepressionOverflow DEPRESSION SURFACE_WATER diff --git a/man/RavenR-package.Rd b/man/RavenR-package.Rd index ce438cb..15bec60 100644 --- a/man/RavenR-package.Rd +++ b/man/RavenR-package.Rd @@ -2,6 +2,7 @@ % Please edit documentation in R/RavenR-package.R \docType{package} \name{RavenR-package} +\alias{RavenR} \alias{RavenR-package} \title{RavenR} \description{ @@ -24,3 +25,17 @@ See also \href{http://www.civil.uwaterloo.ca/jrcraig/}{James R. Craig's research page} for software downloads, including the \href{http://raven.uwaterloo.ca/}{Raven webpage}. } +\author{ +\strong{Maintainer}: Robert Chlumsky \email{rchlumsk@uwaterloo.ca} (\href{https://orcid.org/0000-0002-1303-5064}{ORCID}) + +Authors: +\itemize{ + \item James Craig \email{jrcraig@uwaterloo.ca} (\href{https://orcid.org/0000-0003-2715-7166}{ORCID}) [contributor] + \item Leland Scantlebury \email{lscantlebury@uwaterloo.ca} [contributor] + \item Simon Lin \email{simon.lin@uwaterloo.ca} [contributor] + \item Sarah Grass \email{sgrass@nhcweb.com} [contributor] + \item Genevieve Brown \email{genevieve.wbrown@gmail.com} [contributor] + \item Rezgar Arabzadeh \email{rarabzad@uwaterloo.ca} [contributor] +} + +} diff --git a/man/rvn_csv_read.Rd b/man/rvn_csv_read.Rd new file mode 100644 index 0000000..a703e08 --- /dev/null +++ b/man/rvn_csv_read.Rd @@ -0,0 +1,41 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/rvn_csv_read.R +\name{rvn_csv_read} +\alias{rvn_csv_read} +\title{Read in generic Raven output csv files} +\usage{ +rvn_csv_read(ff = NA, tzone = "UTC", xtsformat = TRUE) +} +\arguments{ +\item{ff}{full file path to the csv file} + +\item{tzone}{string indicating the timezone of the data in ff} + +\item{xtsformat}{boolean whether to return in xts format (if date and/or hour found)} +} +\value{ +\item{data frame (as xts if set with \code{xtsformat}) read from the file} +} +\description{ +Reads in output csv files produced by Raven. +} +\details{ +Expects a full file path to the Raven output file. + +The timezone is provided by the tzone argument as "UTC" by default, and should be adjusted by +the user to the local time zone as needed, based on the model run. +} +\examples{ +# create full file path +ff <- system.file("extdata","ReservoirStages.csv", package="RavenR") + +# read in the Reservoir file with the generic call +myres <- rvn_csv_read(ff) + +# view contents +head(myres) + +} +\seealso{ +\code{\link{rvn_hyd_read}} for reading Hydrographs output files +} diff --git a/man/rvn_download.Rd b/man/rvn_download.Rd index bc0a857..0d6168a 100644 --- a/man/rvn_download.Rd +++ b/man/rvn_download.Rd @@ -19,10 +19,10 @@ rvn_download(version = NA, NetCDF = FALSE, check = FALSE, copy_path = NULL) Returns \code{TRUE} if executed successfully } \description{ -Downloads Raven executable from the \href{http://raven.uwaterloo.ca/Downloads.html}{Raven webpage}. +Downloads Raven executable from the \href{https://raven.uwaterloo.ca/Downloads.html}{Raven webpage}. } \details{ -Files are downloaded from the Raven webpage (\url{http://raven.uwaterloo.ca/Downloads.html}) and placed +Files are downloaded from the Raven webpage (\url{https://raven.uwaterloo.ca/Downloads.html}) and placed in a temporary directory while the executable is extracted. This helps prevent any unwanted files being saved on your system outside of temporary directories if the function is interrupted. The executable is placed in the RavenR/extdata directory, wherever RavenR is installed on your system. diff --git a/man/rvn_rvh_write.Rd b/man/rvn_rvh_write.Rd index 1b64a70..93b6b7f 100644 --- a/man/rvn_rvh_write.Rd +++ b/man/rvn_rvh_write.Rd @@ -54,9 +54,9 @@ separate the SubBasins and HRUs in different files. } \section{Functions}{ \itemize{ -\item \code{rvn_rvh_overwrite}: Overwrite contents of original .rvh file -}} +\item \code{rvn_rvh_overwrite()}: Overwrite contents of original .rvh file +}} \examples{ ## Example: write a blank rvh file ## create some blank tables diff --git a/man/rvn_rvi_write_template.Rd b/man/rvn_rvi_write_template.Rd index b7a599b..9e396eb 100644 --- a/man/rvn_rvi_write_template.Rd +++ b/man/rvn_rvi_write_template.Rd @@ -23,7 +23,7 @@ rvn_rvi_write_template( \item{writeheader}{boolean whether to write a header to the rvi file (default \code{TRUE})} -\item{filetype}{File extension, Encoding, Raven version (e.g. "rvp ASCII Raven 2.9.1") (optional)} +\item{filetype}{File extension, Encoding, Raven version (e.g. "rvp ASCII Raven v3.8") (optional)} \item{author}{Name of file author (optional)} @@ -41,7 +41,7 @@ novel model configurations are provided which may be helpful to the user. These for ease of getting started with a model using Raven. The template_name parameter should be one of "UBCWM", "HBV-EC", "HBV-Light", "GR4J", - "CdnShield", "MOHYSE", "HMETS", "HYPR", or "HYMOD". + "CdnShield", "MOHYSE", "HMETS", "HYPR", "HYMOD", "SAC-SMA", "blended", or "blended_v2". This function uses the same model template files that are provided in the Raven User's manual, Appendix D. diff --git a/man/rvn_rvt_write_met.Rd b/man/rvn_rvt_write_met.Rd index 3c78865..9ccd2a2 100644 --- a/man/rvn_rvt_write_met.Rd +++ b/man/rvn_rvt_write_met.Rd @@ -11,7 +11,6 @@ rvn_rvt_write_met( met_file_prefix = "met_", prd = NULL, write_stndata = TRUE, - write_redirect = TRUE, filename_stndata = "met_stndata.rvt", NA_value = -1.2345 ) @@ -29,9 +28,6 @@ rvn_rvt_write_met( \item{write_stndata}{(optional) write the gauge data to a separate .rvt file} -\item{write_redirect}{(optional) write the :RedirectToFile commands in a -separate .rvt file} - \item{filename_stndata}{(optional) name of the station data file created (if \code{write_stndata=TRUE})} \item{NA_value}{(optional) value to use for NA values in rvt file (default -1.2345 for Raven format)} @@ -86,12 +82,6 @@ meterological station in Raven. The function will append to the file if it alrea that this works for iterations of this function. metdata must include the columns ELEV, LAT, and LON if station data is to be written, else the meta data file will not be created. -write_redirect will print out the :RedirectToFile commands into the file specified -by filename_stndata, if write_stndata is \code{TRUE}. These commands can be copied into the main model's -.rvt file to redirect to the produced time series files. The function will -append to the file if it already exists, meaning that this works for -iterations of this function. - The function has several built-in data quality checks. These include: * checking that the time interval is consistent for each station; diff --git a/vignettes/Introduction_to_RavenR.Rmd b/vignettes/Introduction_to_RavenR.Rmd index 72cfa17..b643f17 100644 --- a/vignettes/Introduction_to_RavenR.Rmd +++ b/vignettes/Introduction_to_RavenR.Rmd @@ -221,7 +221,8 @@ The Raven User's Manual (Appendix D) provides a number of model templates that c We can call this command to create a template rvi file for one of these models as per below. ```{r RVI write template example} -tf <- file.path(tempdir(), "mymodel.rvi") +td <- tempdir() # temporary directory to write model files to +tf <- file.path(td,"mymodel.rvi") rvn_rvi_write_template(template_name="HMETS", filename=tf, @@ -264,6 +265,8 @@ An rvp template file could be generated by running Raven with the `:CreateRVPTem ```{r Create RVP template file, eval=FALSE} rvn_run(fileprefix = "mymodel", + indir=td, # temporary directory created earlier + outdir=td, # write to same temporary directory rvi_options=":CreateRVPTemplate", showoutput = TRUE) ```