diff --git a/.Rbuildignore b/.Rbuildignore index 4b3f9f2c270555351c5f4e1add8695d20d52e894..d02f20b72b33c6fe36201a5f4fea95c91d9b3e1d 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,3 +1,7 @@ ^.*\.Rproj$ ^\.Rproj\.user$ ^data-raw$ +^man-roxygen$ +^LICENSE\.md$ +[.]INI$ +^\.gitlab-ci\.yml$ diff --git a/DESCRIPTION b/DESCRIPTION index 11207c5d45aa004bd20298a40c2601c37be80435..c27e8ef70e112ee59510612c551353a52b19bb84 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -12,13 +12,15 @@ LazyData: true Suggests: R.utils, RandomFields, - testthat (>= 3.0.0) + testthat (>= 3.0.0), + yaml Config/testthat/edition: 3 Depends: R (>= 2.10) RoxygenNote: 7.1.2 Roxygen: list(markdown = TRUE) Imports: + config, logger, magrittr, terra, diff --git a/NAMESPACE b/NAMESPACE index ad1a24b82e4d51b12edb4af032d93b94b9d24f42..0b1ed7ef1380c5399d3476845477db28a34f0a37 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -19,4 +19,6 @@ export(sic_run_export) export(sic_run_fortran) export(split_reach) import(magrittr) +import(utils) import(xml2) +importFrom(stats,dist) diff --git a/R/create_section_txt.R b/R/create_section_txt.R index ed7e7590785fcbca5b26e0351129f7256da0c4a9..cd049c6f392d8df2863628771738c6b03a342a30 100644 --- a/R/create_section_txt.R +++ b/R/create_section_txt.R @@ -8,6 +8,7 @@ #' #' @return [character], section description in SIC text import format. #' @export +#' @import utils #' @examples #' # Trapezoidal section #' create_section_txt("Trapeze", 0, "T", list(B = 2, S = 1.5, ZF = 100, ZB = 102)) diff --git a/R/create_uniform_reach_txt.R b/R/create_uniform_reach_txt.R index 2594e8cfe0b117f4a41886eb5cc350f2ff6ec269..f003d0aab5cb74e9c4cafb0dfb70cb0031180886 100644 --- a/R/create_uniform_reach_txt.R +++ b/R/create_uniform_reach_txt.R @@ -3,7 +3,7 @@ #' @param abscissas [numeric] vector of section abscissas #' @param upstream_bed_elevation [numeric], upstream bed elevation (m) #' @param slope [numeric], bed slope of the reach (m/m) -#' @param names [character] vector of section names +#' @param section_names [character] vector of section names #' @inheritParams create_section_txt #' #' @return A [list] from which each item is a section exported by [create_section_txt]. diff --git a/R/dem_to_reach.R b/R/dem_to_reach.R index 173139f94bad9145c9664c17b3907d4375ce2ea6..135059303245093201a3f035046510082c1e5d45 100644 --- a/R/dem_to_reach.R +++ b/R/dem_to_reach.R @@ -10,9 +10,10 @@ #' @param start 1-length [numeric], starting value for the chainage (i.e. section abscissa) along the reach #' @param major_bed [logical], `TRUE` for major bed, `FALSE` for minor-medium bed #' -#' @return +#' @return A *ReachTxt* object which is a [list] of *SectionTxt* objects (see [create_section_txt]). #' @rdname dem_to_reach #' @export +#' @importFrom stats dist #' #' @examples #' ## Inputs preparation @@ -60,7 +61,9 @@ dem_to_reach_txt <- function(dem, node_coords, space_step, section_width, nb_poi return(reach_txt) } + #' @rdname dem_to_reach +#' @param section_centers See return value of [get_section_centers] #' @export dem_to_reach <- function(dem, node_coords, section_centers, section_width, nb_points = 50) { lapply(seq_len(nrow(section_centers)), function(i) { @@ -75,7 +78,7 @@ dem_to_reach <- function(dem, node_coords, section_centers, section_width, nb_po #' @inheritParams dem_to_reach #' @param section_center 2-lenght [numeric], coordinates of the section center #' -#' @return +#' @return A [matrix] with the coordinates of the x-z points in the cross-profile section referential #' @export #' #' @inherit dem_to_reach return examples diff --git a/R/get_result.R b/R/get_result.R index b2a41975632c6e13cbb010178c070948a123008c..8aba75babf3e4064bffe4a6cce88dd74925f6c8c 100644 --- a/R/get_result.R +++ b/R/get_result.R @@ -1,10 +1,10 @@ -#' Get resultat +#' Get a selection of variables from a simulation result #' #' @inheritParams sic_run_export -#' @param filter -#' @param m +#' @param filters [character] conditions to select columns in result table, see details +#' @param m [matrix] of results produced by [read_bin_result_matrix] #' -#' @return +#' @return [matrix] of results with columns selected by `filters`. #' @export #' @import magrittr #' @@ -50,8 +50,12 @@ get_result <- function(cfg, #' @return [matrix] with the simulation results #' @export #' -#' -read_bin_result_matrix <- function(cfg, scenario, variant) { +#' @examples +#' cfg <- cfg_tmp_project() +#' sic_run_fortran("fluvia", list(SCE = 1), cfg = cfg) +#' m <- read_bin_result_matrix(cfg, 1) +#' str(m) +read_bin_result_matrix <- function(cfg, scenario, variant = 0) { file <- paste0( paste(gsub("\\.xml", "", cfg$project$path), scenario, variant, sep = "_"), @@ -86,12 +90,23 @@ read_bin_result_matrix <- function(cfg, scenario, variant) { #' #' @return a [data.frame] with following columns: #' +#' - "bf", "sn", "nd", "pr", "ouv": location of the result with number of respectively reach, section, node, offtake, and device. +#' - "var": the name of the calculated variable +#' - "col": the column number in the matrix produced by [read_bin_result_matrix] +#' +#' @warning +#' Up to now, this function only handle results at sections. +#' #' @export #' @import xml2 #' @import magrittr #' #' @examples -get_result_tree <- function(cfg, scenario, variant) { +#' cfg <- cfg_tmp_project() +#' sic_run_fortran("fluvia", list(SCE = 1), cfg = cfg) +#' df <- get_result_tree(cfg, 1) +#' head(df) +get_result_tree <- function(cfg, scenario, variant = 0) { x <- read_xml(cfg$project$path) objs = c("Ouvrage", "Section", "Prise", "Noeud") names(objs) <- objs @@ -126,7 +141,7 @@ get_result_tree <- function(cfg, scenario, variant) { } result_tree_add <- function(df, loc, defcol, cols) { - loc <- utils::modifyList(list(bf = 0, sn = 0, nd = 0, pr = 0, ouv = 0), + loc <- modifyList(list(bf = 0, sn = 0, nd = 0, pr = 0, ouv = 0), loc) return(rbind(df, data.frame(as.data.frame(loc), var = defcol, col = cols))) } diff --git a/R/merge_reaches.R b/R/merge_reaches.R index dd3b31753f1de4b639ad7e1b8493ffa22c9ea667..16c31059b00be40e21ea0f6273e8afe072ca6148 100644 --- a/R/merge_reaches.R +++ b/R/merge_reaches.R @@ -1,8 +1,8 @@ -#' Merge several ReachTxt objects into one +#' Merge several *ReachTxt* objects into one #' -#' @param ... ReachTxt objects +#' @param ... *ReachTxt* objects #' -#' @return +#' @return a *ReachTxt* object (See [create_uniform_reach_txt] and [dem_to_reach]) containing the merged reaches. #' @export #' #' @examples diff --git a/R/sic_run_fortran.R b/R/sic_run_fortran.R index 57c986a5f2638ea89b9c54d017cc262ccdd89698..b62ceaf163804958877f099b7a7c798039518b97 100644 --- a/R/sic_run_fortran.R +++ b/R/sic_run_fortran.R @@ -7,7 +7,7 @@ #' @details If argument `params` is a [list], arguments are injected in the command line by taking the items of the list with the conversion #' `[key]=[value]`. If argument `params` is a [character] #' -#' @return +#' @return Error code returned by [shell]. #' @export #' #' @examples @@ -27,9 +27,11 @@ sic_run_fortran <- function(prog, params = list(), cfg = loadConfig()) { type = "cmd2" ) logger::log_debug(cmd_line) - shell( + ret <- shell( cmd_line, wait = T, translate = T ) + file.remove("FLUVIA.INI", "SIRENE.INI") + return(ret) } diff --git a/man/create_uniform_reach_txt.Rd b/man/create_uniform_reach_txt.Rd index f47a6405f510c7dafba40ecfe942730cfaccfcda..64040f86eb3c7a2ba93a99573081a8a5eeab5f1a 100644 --- a/man/create_uniform_reach_txt.Rd +++ b/man/create_uniform_reach_txt.Rd @@ -24,7 +24,7 @@ create_uniform_reach_txt( \item{profile}{\link{list} or \link{matrix}, profile of the section (See details)} -\item{names}{\link{character} vector of section names} +\item{section_names}{\link{character} vector of section names} } \value{ A \link{list} from which each item is a section exported by \link{create_section_txt}. diff --git a/man/dem_to_reach.Rd b/man/dem_to_reach.Rd index 0cbfdd85a49f2bf752e49380292b36390bfd6247..828b099c70a7ecf01245bb6c856e02324ea55c20 100644 --- a/man/dem_to_reach.Rd +++ b/man/dem_to_reach.Rd @@ -31,9 +31,11 @@ dem_to_reach(dem, node_coords, section_centers, section_width, nb_points = 50) \item{start}{1-length \link{numeric}, starting value for the chainage (i.e. section abscissa) along the reach} \item{major_bed}{\link{logical}, \code{TRUE} for major bed, \code{FALSE} for minor-medium bed} + +\item{section_centers}{See return value of \link{get_section_centers}} } \value{ - +A \emph{ReachTxt} object which is a \link{list} of \emph{SectionTxt} objects (see \link{create_section_txt}). } \description{ The coordinate system of \code{dem} should be a metric orthonormal coordinate system. diff --git a/man/dem_to_section.Rd b/man/dem_to_section.Rd index f3dcd7ec1de8c5b77e0e323a239874e3da02572e..8346460fb318ba141c7abf1f7223d5a3972f2561 100644 --- a/man/dem_to_section.Rd +++ b/man/dem_to_section.Rd @@ -18,7 +18,7 @@ dem_to_section(dem, node_coords, section_center, section_width, nb_points = 50) \item{nb_points}{1-length \link{numeric}, number of points to describe cross-section geometries} } \value{ - +A \link{matrix} with the coordinates of the x-z points in the cross-profile section referential } \description{ Create a section cross profile from a DEM diff --git a/man/get_result.Rd b/man/get_result.Rd index a7871bf0bfd0a37110ff572bc61afe0e44663182..55c1ca3e1f7a18592fbf95eae1939a2fb44c2dc2 100644 --- a/man/get_result.Rd +++ b/man/get_result.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/get_result.R \name{get_result} \alias{get_result} -\title{Get resultat} +\title{Get a selection of variables from a simulation result} \usage{ get_result( cfg, @@ -19,13 +19,15 @@ get_result( \item{variant}{\link{numeric}, the variant to read} -\item{m}{} +\item{filters}{\link{character} conditions to select columns in result table, see details} + +\item{m}{\link{matrix} of results produced by \link{read_bin_result_matrix}} } \value{ - +\link{matrix} of results with columns selected by \code{filters}. } \description{ -Get resultat +Get a selection of variables from a simulation result } \examples{ cfg <- cfg_tmp_project() diff --git a/man/get_result_tree.Rd b/man/get_result_tree.Rd index d885d1a06902d99ec5b168cd86c68009722231e2..f06e1a53fc151f52db5015b318d0e38cb6c97961 100644 --- a/man/get_result_tree.Rd +++ b/man/get_result_tree.Rd @@ -4,7 +4,7 @@ \alias{get_result_tree} \title{Get correspondence between network object and columns in result binary file} \usage{ -get_result_tree(cfg, scenario, variant) +get_result_tree(cfg, scenario, variant = 0) } \arguments{ \item{cfg}{a \link{config} object. Configuration to use. See \link{loadConfig} for details} @@ -15,7 +15,18 @@ get_result_tree(cfg, scenario, variant) } \value{ a \link{data.frame} with following columns: +\itemize{ +\item "bf", "sn", "nd", "pr", "ouv": location of the result with number of respectively reach, section, node, offtake, and device. +\item "var": the name of the calculated variable +\item "col": the column number in the matrix produced by \link{read_bin_result_matrix} +} } \description{ Get correspondence between network object and columns in result binary file } +\examples{ +cfg <- cfg_tmp_project() +sic_run_fortran("fluvia", list(SCE = 1), cfg = cfg) +df <- get_result_tree(cfg, 1) +head(df) +} diff --git a/man/merge_reaches.Rd b/man/merge_reaches.Rd index fa030e3e039bb72077bbf7428055310b2a90845e..1ca02aa21a10fea5b1cb2d1ccae56a057a79cfae 100644 --- a/man/merge_reaches.Rd +++ b/man/merge_reaches.Rd @@ -2,18 +2,18 @@ % Please edit documentation in R/merge_reaches.R \name{merge_reaches} \alias{merge_reaches} -\title{Merge several ReachTxt objects into one} +\title{Merge several \emph{ReachTxt} objects into one} \usage{ merge_reaches(...) } \arguments{ -\item{...}{ReachTxt objects} +\item{...}{\emph{ReachTxt} objects} } \value{ - +a \emph{ReachTxt} object (See \link{create_uniform_reach_txt} and \link{dem_to_reach}) containing the merged reaches. } \description{ -Merge several ReachTxt objects into one +Merge several \emph{ReachTxt} objects into one } \examples{ # Minor bed generation diff --git a/man/read_bin_result_matrix.Rd b/man/read_bin_result_matrix.Rd index 760544b420a8ef94f2994973f9b2b9673b9c4b59..c2e19eaedb4e0fd0195b9a6ef20f17c174050864 100644 --- a/man/read_bin_result_matrix.Rd +++ b/man/read_bin_result_matrix.Rd @@ -4,7 +4,7 @@ \alias{read_bin_result_matrix} \title{Read matrix of SIC simulation result file} \usage{ -read_bin_result_matrix(cfg, scenario, variant) +read_bin_result_matrix(cfg, scenario, variant = 0) } \arguments{ \item{cfg}{a \link{config} object. Configuration to use. See \link{loadConfig} for details} @@ -19,3 +19,9 @@ read_bin_result_matrix(cfg, scenario, variant) \description{ Read matrix of SIC simulation result file } +\examples{ +cfg <- cfg_tmp_project() +sic_run_fortran("fluvia", list(SCE = 1), cfg = cfg) +m <- read_bin_result_matrix(cfg, 1) +str(m) +} diff --git a/man/sic_run_fortran.Rd b/man/sic_run_fortran.Rd index 3ed6001297e9ebb0d986bd042dcb6642be878bb4..04d37b13249605bf293f82fb0315c5c4b474feb0 100644 --- a/man/sic_run_fortran.Rd +++ b/man/sic_run_fortran.Rd @@ -14,7 +14,7 @@ sic_run_fortran(prog, params = list(), cfg = loadConfig()) \item{cfg}{a \link{config} object. Configuration to use. See \link{loadConfig} for details} } \value{ - +Error code returned by \link{shell}. } \description{ Run Talweg, Fluvia or Sirene