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
  • !11
An error occurred while fetching the assigned milestone of the selected merge_request.

Resolve "get_result: add a `t` column for the simulation time"

  • Review changes

  • Download
  • Patches
  • Plain diff
Merged Dorchies David requested to merge 15-get_result-add-a-t-column-for-the-simulation-time into main 3 years ago
  • Overview 0
  • Commits 1
  • Pipelines 2
  • Changes 3

Closes #15 (closed)

Edited 3 years ago by Dorchies David
Compare
  • main (base)

and
  • latest version
    165a1e33
    1 commit, 3 years ago

3 files
+ 40
− 4

    Preferences

    File browser
    Compare changes
R/get_result.R
+ 31
− 2
  • View file @ 165a1e33

  • Edit in single-file editor

  • Open in Web IDE


@@ -4,7 +4,15 @@
#' @param filters [character] conditions to select columns in result table, see details
#' @param m [matrix] of results produced by [read_bin_result_matrix]
#'
#' @return [matrix] of results with columns selected by `filters`.
#' @return [matrix] of results with a first column "t" with the simulation time
#' in seconds followed by columns selected by `filters`.
#'
#' Column names are a concatenation of nested SIC model elements separated by
#' the character "|" and numbered after the character ":". The variable is
#' represented by the item "var".
#' For example, water elevation in the first section of the first reach is:
#' "bf:1|sn:1|var:Z".
#'
#' @export
#' @import magrittr
#'
@@ -26,6 +34,24 @@ get_result <- function(cfg,
df_col %<>% tidyquery::query(paste("SELECT * WHERE", filters))
}
m <- m[, df_col$col, drop = FALSE]
# Compute time column
x <- read_xml(cfg$project$path)
xpath <-
sprintf("/Reseau/Flu[@nScenario=%d]/ListeRes/Res[@nVar=%d]",
scenario,
variant)
x_res <- xml_find_first(x, xpath)
attrs <- paste0("Tps", c("Debut", "Pas", "Sauv", "Fin"))
names(attrs) <- attrs
time_prms <- sapply(attrs, function(attr) {
as.numeric(xml_attr(x_res, attr))
})
tms <- seq(from = time_prms["TpsDebut"],
to = time_prms["TpsFin"],
by = time_prms["TpsPas"] * time_prms["TpsSauv"])
# set column names
column_names <- sapply(seq_len(nrow(df_col)),
function(i) {
df_col$col <- NULL
@@ -40,7 +66,10 @@ get_result <- function(cfg,
cols[sapply(cols, is.null)] <- NULL
paste(cols, collapse = "|")
})
colnames(m) <- column_names
m <- cbind(tms, m)
colnames(m) <- c("t", column_names)
return(m)
}
man/get_result.Rd
+ 8
− 1
  • View file @ 165a1e33

  • Edit in single-file editor

  • Open in Web IDE


@@ -24,7 +24,14 @@ get_result(
\item{m}{\link{matrix} of results produced by \link{read_bin_result_matrix}}
}
\value{
\link{matrix} of results with columns selected by \code{filters}.
\link{matrix} of results with a first column "t" with the simulation time
in seconds followed by columns selected by \code{filters}.
Column names are a concatenation of nested SIC model elements separated by
the character "|" and numbered after the character ":". The variable is
represented by the item "var".
For example, water elevation in the first section of the first reach is:
"bf:1|sn:1|var:Z".
}
\description{
Get a selection of variables from a simulation result
tests/testthat/test-get_result.R
+ 1
− 1
  • View file @ 165a1e33

  • Edit in single-file editor

  • Open in Web IDE


@@ -7,5 +7,5 @@ test_that("get_result returns a matrix with correct colnames", {
result <- get_result(cfg, 1, filters = c("bf=4", "var='Z'"))
expect_true(is.matrix(result))
expect_type(result, "double")
expect_equal(colnames(result), sprintf("bf:4|sn:%d|var:Z", 1:4))
expect_equal(colnames(result), c("t", sprintf("bf:4|sn:%d|var:Z", 1:4)))
})
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: 15-get_result-add-a-t-column-for-the-simulation-time

Menu

Explore Projects Groups Topics Snippets