Skip to content
GitLab
    • Explore Projects Groups Topics Snippets
Projects Groups Topics Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Register
  • Sign in
  • R Rsic2
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
  • Issues 3
    • Issues 3
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 2
    • Merge requests 2
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar

La forge institutionnelle d'INRAE étant en production depuis le 10 juin 2025, nous vous invitons à y créer vos nouveaux projets.

  • SIC2SIC2
  • Rsic2
  • Merge requests
  • !10
An error occurred while fetching the assigned milestone of the selected merge_request.

Resolve "Crash de Talweg sur les distances de lit majeur"

  • Review changes

  • Download
  • Patches
  • Plain diff
Merged Dorchies David requested to merge 13-crash-de-talweg-sur-les-distances-de-lit-majeur into main 3 years ago
  • Overview 0
  • Commits 6
  • Pipelines 5
  • Changes 19

Closes #13 (closed)

Edited 3 years ago by Dorchies David
Compare
  • version 3
    8b651051
    3 years ago

  • version 2
    16151c9e
    3 years ago

  • version 1
    d4e59c10
    3 years ago

  • main (base)

and
  • latest version
    13601dba
    6 commits, 3 years ago

  • version 3
    8b651051
    3 commits, 3 years ago

  • version 2
    16151c9e
    2 commits, 3 years ago

  • version 1
    d4e59c10
    1 commit, 3 years ago

19 files
+ 179
− 31

    Preferences

    File browser
    Compare changes
R/dem_to_reach.R
+ 8
− 2
  • View file @ 13601dba

  • Edit in single-file editor

  • Open in Web IDE


@@ -3,7 +3,7 @@
@@ -3,7 +3,7 @@
#' The coordinate system of `dem` should be a metric orthonormal coordinate system.
#' The coordinate system of `dem` should be a metric orthonormal coordinate system.
#'
#'
#' @param dem [terra::SpatRaster] object with altitude data (m).
#' @param dem [terra::SpatRaster] object with altitude data (m).
#' @param node_coords [matrix] with coordinates of starting and ending points of the line to browse
#' @param node_coords a 2x2 [matrix] with coordinates of starting and ending points of the line to browse
#' @param space_step 1-length [numeric], distance between each section (m)
#' @param space_step 1-length [numeric], distance between each section (m)
#' @param section_width 1-length [numeric], width of the sections to create
#' @param section_width 1-length [numeric], width of the sections to create
#' @param nb_points 1-length [numeric], number of points to describe cross-section geometries
#' @param nb_points 1-length [numeric], number of points to describe cross-section geometries
@@ -66,6 +66,8 @@ dem_to_reach_txt <- function(dem, node_coords, space_step, section_width, nb_poi
@@ -66,6 +66,8 @@ dem_to_reach_txt <- function(dem, node_coords, space_step, section_width, nb_poi
#' @param section_centers See return value of [get_section_centers]
#' @param section_centers See return value of [get_section_centers]
#' @export
#' @export
dem_to_reach <- function(dem, node_coords, section_centers, section_width, nb_points = 50) {
dem_to_reach <- function(dem, node_coords, section_centers, section_width, nb_points = 50) {
 
if (nrow(node_coords) != 2 || ncol(node_coords) != 2)
 
stop("`node_coords` should be a matrix of dimensions 2x2")
lapply(seq_len(nrow(section_centers)), function(i) {
lapply(seq_len(nrow(section_centers)), function(i) {
section_center <- section_centers[i,]
section_center <- section_centers[i,]
dem_to_section(dem, node_coords, section_center, section_width, nb_points)
dem_to_section(dem, node_coords, section_center, section_width, nb_points)
@@ -95,8 +97,12 @@ dem_to_section <- function(dem, node_coords, section_center, section_width, nb_p
@@ -95,8 +97,12 @@ dem_to_section <- function(dem, node_coords, section_center, section_width, nb_p
seq(x[1], x[2], length.out = nb_points)
seq(x[1], x[2], length.out = nb_points)
})
})
z <- terra::extract(dem, section_points, method = "bilinear")$lyr.1
z <- terra::extract(dem, section_points, method = "bilinear")$lyr.1
x_points <- sapply(seq_len(nrow(section_points)), function(i) {as.numeric(dist(section_points[c(1,i), ]))})
x_points <- sapply(
 
seq_len(nrow(section_points)),
 
function(i) {as.numeric(dist(section_points[c(1,i), ]))}
 
)
m <- matrix(c(x_points, z), ncol = 2)
m <- matrix(c(x_points, z), ncol = 2)
 
m <- m[!is.na(m[, 2]), ]
colnames(m) <- c("x", "z")
colnames(m) <- c("x", "z")
return(m)
return(m)
}
}
R/loadConfig.R
+ 5
− 2
  • View file @ 13601dba

  • Edit in single-file editor

  • Open in Web IDE


@@ -15,8 +15,9 @@
@@ -15,8 +15,9 @@
#' path: Path/To/Xml/Project/File.xml
#' path: Path/To/Xml/Project/File.xml
#' ```
#' ```
#'
#'
#' Moreover, the `sic_path` can be defined with the environment variable "SICPATH". This setting is a default which is overwritten
#' Moreover, the `sic_path` can be defined with the environment variable "SICPATH".
#' by the path defined in the user YAML file, which is also overwritten by the one define by the `sic_path` argument.
#' This setting is a default which is overwritten by the path defined in the user YAML file,
 
#' which is also overwritten by the one define by the `sic_path` argument.
#'
#'
#' @return A configuration as it is returned by [config::get].
#' @return A configuration as it is returned by [config::get].
#'
#'
@@ -34,6 +35,8 @@
@@ -34,6 +35,8 @@
#' - `INTERF`: default `INTERF` parameter injected in command line arguments of TALWEG, FLUVIA, SIRENE
#' - `INTERF`: default `INTERF` parameter injected in command line arguments of TALWEG, FLUVIA, SIRENE
#' - `project`
#' - `project`
#' - `path`: Path to the XML project file (should be defined by `xml_path` parameter or in the user config file)
#' - `path`: Path to the XML project file (should be defined by `xml_path` parameter or in the user config file)
 
#' - `stricklers`: A vector of 2 [numeric] values representing respectively
 
#' the default minor and medium bed Strickler coefficients to apply with [sic_import_reaches]
#'
#'
#' @export
#' @export
#'
#'
R/merge_reaches.R → R/merge.ReachTxt.R
+ 6
− 4
  • View file @ 13601dba

  • Edit in single-file editor

  • Open in Web IDE


#' Merge several *ReachTxt* objects into one
#' Merge several *ReachTxt* objects into one
#'
#'
#' @param ... *ReachTxt* objects
#' @param x First *ReachTxt* object to merge
 
#' @param y Second *ReachTxt* object to merge
 
#' @param ... Other *ReachTxt* objects to merge
#'
#'
#' @return a *ReachTxt* object (See [create_uniform_reach_txt] and [dem_to_reach]) containing the merged reaches.
#' @return a *ReachTxt* object (See [create_uniform_reach_txt] and [dem_to_reach]) containing the merged reaches.
#' @export
#' @export
@@ -28,9 +30,9 @@
@@ -28,9 +30,9 @@
#' maj_reach <- dem_to_reach_txt(dem, node_coords, space_step, section_width, major_bed = TRUE)
#' maj_reach <- dem_to_reach_txt(dem, node_coords, space_step, section_width, major_bed = TRUE)
#'
#'
#' # Merge reaches into one
#' # Merge reaches into one
#' reach <- merge_reaches(min_reach, maj_reach)
#' reach <- merge(min_reach, maj_reach)
merge_reaches <- function(...) {
merge.ReachTxt <- function(x, y = NULL, ...) {
reaches <- list(...)
reaches <- c(list(x, y), list(...))
lapply(reaches, function(reach) {
lapply(reaches, function(reach) {
if (!inherits(reach, "ReachTxt")) stop("Parameters must be of class ReachTxt")
if (!inherits(reach, "ReachTxt")) stop("Parameters must be of class ReachTxt")
})
})
R/sic_import_reaches.R
+ 58
− 2
  • View file @ 13601dba

  • Edit in single-file editor

  • Open in Web IDE


@@ -25,7 +25,7 @@
@@ -25,7 +25,7 @@
#' maj_reach <- dem_to_reach_txt(dem, node_coords, space_step, section_width, major_bed = TRUE)
#' maj_reach <- dem_to_reach_txt(dem, node_coords, space_step, section_width, major_bed = TRUE)
#'
#'
#' # Merge minor and major beds and split into 2 reaches
#' # Merge minor and major beds and split into 2 reaches
#' reach <- merge_reaches(min_reach, maj_reach)
#' reach <- merge(min_reach, maj_reach)
#' reaches <- split_reach(reach, seq(0, 10000, 5000))
#' reaches <- split_reach(reach, seq(0, 10000, 5000))
#'
#'
#' \dontrun{
#' \dontrun{
@@ -55,14 +55,70 @@ sic_import_reaches <- function(reaches, import_mode = "ImportXml_UPDATE", cfg =
@@ -55,14 +55,70 @@ sic_import_reaches <- function(reaches, import_mode = "ImportXml_UPDATE", cfg =
type = "cmd2"
type = "cmd2"
)
)
logger::log_debug(cmd_line)
logger::log_debug(cmd_line)
shell(
ret <- shell(
cmd_line,
cmd_line,
wait = T,
wait = T,
translate = T
translate = T
)
)
 
update_portion_abscissas(cfg)
 
return(ret)
}
}
write_reach_txt <- function(file, reach) {
write_reach_txt <- function(file, reach) {
s <- unlist(reach)
s <- unlist(reach)
writeLines(s, file)
writeLines(s, file)
}
}
 
 
#' Update abscissas of Strickler portions in a SIC model
 
#'
 
#' @description
 
#' As [sic_import_reaches] redefines abscissas in the reaches, and as the Stricklers
 
#' are defined with abscissas, geometry importation can lead to an inconsistent model.
 
#'
 
#' So the aim of this function is to reset Strickler definitions of the whole model
 
#' to a default value with one Strickler portion by reach with correct abscissas.
 
#'
 
#' @template param_cfg
 
#' @param stricklers 2-length [numeric], Strickler coefficient to apply for minor bed and medium bed respectively
 
#'
 
#' @return Use for side effect on the XML project file.
 
#'
 
#' @family sic_import_reaches
 
#'
 
#' @export
 
#'
 
#' @examples
 
#' \dontrun{
 
#' cfg <- cfg_tmp_project()
 
#' update_portion_abscissas(cfg, KMin = 50)
 
#'
 
#' # Display first Strickler definitions encountered in the XML file
 
#' x <- read_xml(cfg$project$path)
 
#' xml_find_first(x, "//Stricklers")
 
#' }
 
update_portion_abscissas <- function(cfg,
 
stricklers = cfg$project$stricklers) {
 
x <- read_xml(cfg$project$path)
 
x_biefs <- xml_find_all(x, "//Bief")
 
lapply(x_biefs, function(x) {
 
XD <- x %>% xml_find_first(".//Liste_Sections/SectionMin") %>% xml_attr("abscisse")
 
XF <- x %>% xml_find_last(".//Liste_Sections/SectionMin") %>% xml_attr("abscisse")
 
x_stricklers <- xml_find_all(x, ".//Stricklers")
 
lapply(x_stricklers, function(x) {
 
x_portion <- xml_find_first(x, "./Portion")
 
xml_attr(x_portion, "XD") <- XD
 
xml_attr(x_portion, "XF") <- XF
 
xml_set_text(xml_child(x_portion, "KMin"), as.character(stricklers[1]))
 
xml_set_text(xml_child(x_portion, "KMoy"), as.character(stricklers[2]))
 
# Delete other defined portions in the reach
 
other_portions <- xml_siblings(x_portion)
 
lapply(other_portions, xml_remove)
 
})
 
})
 
write_xml(x, cfg$project$path)
 
}
 
 
xml_find_last <- function(x, path) {
 
x_all <- xml_find_all(x, path)
 
return(x_all[length(x_all)])
 
}
R/sic_inputs.R
+ 1
− 1
  • View file @ 13601dba

  • Edit in single-file editor

  • Open in Web IDE


@@ -49,7 +49,7 @@ sic_write_par <- function(cfg, scenario, sicInputs) {
@@ -49,7 +49,7 @@ sic_write_par <- function(cfg, scenario, sicInputs) {
sParFileName = sic_get_par_filename(cfg, scenario)
sParFileName = sic_get_par_filename(cfg, scenario)
df = data.frame(C1 = "// PAR file for SIC",
df = data.frame(C1 = "// PAR file for SIC",
C2 = "automatically generated by rsci2",
C2 = "automatically generated by rsic2",
C3 = "",
C3 = "",
stringsAsFactors = FALSE)
stringsAsFactors = FALSE)
i = 0
i = 0
Assignee
Dorchies David's avatar
Dorchies David
Assign to
0 Reviewers
None
Request review from
Labels
0
None
0
None
    Assign labels
  • Manage project labels

Milestone
No milestone
None
None
Time tracking
No estimate or time spent
Lock merge request
Unlocked
0
0 Participants
Reference:
Source branch: 13-crash-de-talweg-sur-les-distances-de-lit-majeur

Menu

Explore Projects Groups Topics Snippets