Source

Target

Commits (16)
Showing with 120 additions and 134 deletions
+120 -134
stages:
- update_packages
- build
- checks
default:
......@@ -8,40 +6,36 @@ default:
image: r-base:latest
variables:
R_LIBS_USER: "$CI_PROJECT_DIR/ci/lib"
CHECK_DIR: "$CI_PROJECT_DIR/ci/logs"
BUILD_LOGS_DIR: "$CI_PROJECT_DIR/ci/logs/$CI_PROJECT_NAME.Rcheck"
cache:
paths:
- R_LIBS/
- $R_LIBS_USER
before_script:
- echo "R_LIBS='$(pwd)/R_LIBS'" > .Renviron
update_packages:
stage: update_packages
script:
- mkdir -p R_LIBS
- Rscript -e 'if(!dir.exists("R_LIBS/remotes")) install.packages("remotes", lib = "R_LIBS")'
- apt-get update && apt-get -y install libxml2-dev
- Rscript -e 'remotes::update_packages(c("dplyr", "rmarkdown", "readr", "lubridate", "zoo", "roxygen2", "DiagrammeR"), lib = "R_LIBS")'
- Rscript -e 'remotes::install_gitlab("HYCAR-Hydro/airgr@sd", host = "gitlab.irstea.fr", lib = "R_LIBS")'
build:
stage: build
- apt-get update && apt-get -y install libcurl4-openssl-dev libxml2-dev libssl-dev
- mkdir -p $R_LIBS_USER $BUILD_LOGS_DIR
- echo "R_LIBS='$R_LIBS_USER'" > .Renviron
- R -e 'if(!dir.exists(file.path(Sys.getenv("R_LIBS_USER"), "devtools"))) install.packages("devtools")'
- R -e 'remotes::install_gitlab("HYCAR-Hydro/airgr@dev", host = "gitlab.irstea.fr")'
- R -e 'devtools::install_deps(dep = T)'
- R -e "devtools::document(roclets = c('rd', 'collate', 'namespace'))"
.check:
stage: checks
script:
- apt-get update && apt-get -y install libxml2-dev
- Rscript -e "roxygen2::roxygenise()"
- R CMD build ../griwrm
artifacts:
paths:
- griwrm_*.tar.gz
- R -e 'devtools::check(check_dir = Sys.getenv("CHECK_DIR"), cran = !as.logical(Sys.getenv("NOT_CRAN")))'
- R -e 'if (length(devtools::check_failures(path = Sys.getenv("BUILD_LOGS_DIR"), note = FALSE)) > 0) stop()'
check_not_cran:
stage: checks
variables:
NOT_CRAN: "true"
script:
- R CMD check --no-manual griwrm_*.tar.gz
extends: .check
check_as_cran:
stage: checks
script:
- R CMD check --as-cran --no-manual griwrm_*.tar.gz
variables:
NOT_CRAN: "false"
extends: .check
Package: airGRiwrm
Title: airGR Integrated Water Resource Management
Version: 0.3.1
Authors@R:
person(given = "David",
family = "Dorchies",
role = c("aut", "cre"),
email = "david.dorchies@inrae.fr",
comment = c(ORCID = "0000-0002-6595-7984"))
Description: This R package aims to model water basin using airGR based semi-distributive model with the integration of human infrastructures and their management.
Version: 0.3.4
Authors@R: c(
person("David", "Dorchies", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-6595-7984"), email = "david.dorchies@inrae.fr"),
person("Olivier", "Delaigue", role = c("ctb"), comment = c(ORCID = "0000-0002-7668-8468"), email = "airGR@inrae.fr"),
person("Guillaume", "Thirel", role = c("ctb"), comment = c(ORCID = "0000-0002-1444-1830"))
)
Description: This R package aims to model water basin using 'airGR' based semi-distributive model with the integration of human infrastructures and their management.
License: AGPL-3
Encoding: UTF-8
LazyData: true
......@@ -16,8 +15,7 @@ RoxygenNote: 7.1.1
Imports:
dplyr,
utils,
airGR (>= 1.6.1.11),
methods
airGR (>= 1.6.1.11)
Suggests:
knitr,
rmarkdown,
......
#' Calibration of a semi-distributed run-off model
#'
#' @param InputsModel object of class \emph{GriwrmInputsModel}, see \code{\link{CreateInputsModel.Griwrm}} for details.
#' @param RunOptions object of class \emph{GriwrmRunOptions}, see \code{\link{CreateRunOptiosn.Griwrm}} for details.
#' @param InputsCrit object of class \emph{GriwrmInputsCrit}, see \code{\link{CreateInputsCrit.Griwrm}} for details.
#' @param CalibOptions object of class \emph{GriwrmCalibOptions}, see \code{\link{CreateCalibOptions.Griwrm}} for details.
#' @param InputsModel object of class \emph{GriwrmInputsModel}, see \code{\link{CreateInputsModel.GRiwrm}} for details.
#' @param RunOptions object of class \emph{GriwrmRunOptions}, see \code{\link{CreateRunOptiosn.GRiwrm}} for details.
#' @param InputsCrit object of class \emph{GriwrmInputsCrit}, see \code{\link{CreateInputsCrit.GRiwrm}} for details.
#' @param CalibOptions object of class \emph{GriwrmCalibOptions}, see \code{\link{CreateCalibOptions.GRiwrm}} for details.
#' @param useUpstreamQsim boolean describing if simulated (\code{TRUE}) or observed (\code{FALSE}) flows are used for calibration. Default is \code{TRUE}.
#' @param verbose (optional) boolean indicating if the function is run in verbose mode or not, default = \code{TRUE}
#' @param ... further arguments passed to \code{\link[airGR]{Calibration}}.
......
#' Title
#'
#' @param InputsModel object of class \emph{GriwrmInputsModel}, see \code{\link{CreateInputsModel.Griwrm}} for details.
#' @param InputsModel object of class \emph{GriwrmInputsModel}, see \code{\link{CreateInputsModel.GRiwrm}} for details.
#' @param ... further arguments passed to \code{\link[airGR]{CreateCalibOptions}}.
#'
#' @return \emph{GriwrmCalibOptions} object.
......
#' Create \emph{GriwrmInputsCrit} object for GR-IWRM.
#' @param InputsModel object of class \emph{GriwrmInputsModel}, see \code{\link{CreateInputsModel.Griwrm}} for details.
#' @param InputsModel object of class \emph{GriwrmInputsModel}, see \code{\link{CreateInputsModel.GRiwrm}} for details.
#' @param FUN_CRIT \[function (atomic or list)\] error criterion function (e.g. \code{\link[airGR]{ErrorCrit_RMSE}}, \code{\link[airGR]{ErrorCrit_NSE}})
#' @param RunOptions object of class \emph{GriwrmRunOptions}, see \code{[CreateRunOptions.Griwrm]} for details.
#' @param RunOptions object of class \emph{GriwrmRunOptions}, see \code{[CreateRunOptions.GRiwrm]} for details.
#' @param Qobs matrix or data frame containing observed flows. Column names correspond to nodes ID
#' @param ... further arguments passed to \code{\link[airGR]{CreateInputsCrit}}.
#'
......
#' Title
#'
#' @param InputsModel InputsModel for GR-IWRM (See \code{[CreateInputsModel.Griwrm]}) or AirGR (See \code{\link[airGR]{CreateInputsModel}})
#' @param InputsModel InputsModel for GR-IWRM (See \code{[CreateInputsModel.GRiwrm]}) or AirGR (See \code{\link[airGR]{CreateInputsModel}})
#' @param ... further arguments passed to or from other methods.
#'
#' @return
......
#' Create InputsModel object for a GRIWRM network
#'
#' @param x Griwrm object describing the diagram of the semi-distributed model, see \code{[Griwrm]}.
#' @param DateR Vector of POSIXlt observation time steps.
#' @param x GRiwrm object describing the diagram of the semi-distributed model, see \code{[GRiwrm]}.
#' @param DatesR Vector of POSIXt observation time steps.
#' @param Precip Matrix or data frame of numeric containing precipitation in mm. Column names correspond to node IDs.
#' @param PotEvap Matrix or data frame of numeric containing potential evaporation in mm. Column names correspond to node IDs.
#' @param Qobs Matrix or data frame of numeric containing potential observed flow in mm. Column names correspond to node IDs.
......@@ -10,7 +10,7 @@
#'
#' @return GriwrmInputsModel object equivalent to airGR InputsModel object for a semi-distributed model (See \code{\link[airGR]{CreateInputsModel}})
#' @export
CreateInputsModel.Griwrm <- function(x, DatesR, Precip, PotEvap, Qobs, verbose = TRUE, ...) {
CreateInputsModel.GRiwrm <- function(x, DatesR, Precip, PotEvap, Qobs, verbose = TRUE, ...) {
InputsModel <- CreateEmptyGriwrmInputsModel()
Qobs[is.na(Qobs)] <- -99 # airGRCreateInputsModel doesn't accept NA values
......@@ -38,7 +38,7 @@ CreateEmptyGriwrmInputsModel <- function() {
#' Create one InputsModel for a GRIWRM node
#'
#' @param id string of the node identifier
#' @param griwrm See \code{[Griwrm]}.
#' @param griwrm See \code{[GRiwrm]}.
#' @param DatesR vector of dates required to create the GR model and CemaNeige module inputs.
#' @param Precip time series of potential evapotranspiration (catchment average) (mm/time step).
#' @param PotEvap time series of potential evapotranspiration (catchment average) (mm/time step).
......
#' Create \emph{GriwrmRunOptions} object for running and calibrating model in GR-IWRM.
#'
#' @param InputsModel object of class \emph{GriwrmInputsModel}, see \code{\link{CreateInputsModel.Griwrm}} for details.
#' @param InputsModel object of class \emph{GriwrmInputsModel}, see \code{\link{CreateInputsModel.GRiwrm}} for details.
#' @param ... further arguments passed to \code{\link[airGR]{CreateOptions}}.
#'
#' @return \emph{GriwrmRunOptions} object for running and calibrating model in GR-IWRM.
......
#' Create \emph{RunOptions} object for airGR and GR-IWRM. See \code{\link[airGR]{CreateOptions}} and \code{[CreateOptions.GriwrmInputsModel]}.
#'
#' @param InputsModel object of class \emph{InputsModel} (see \code{\link[airGR]{CreateInputsModel}}) or \emph{GriwrmInputsModel} (See \code{[CreateInputsModel.Griwrm]}).
#' @param InputsModel object of class \emph{InputsModel} (see \code{\link[airGR]{CreateInputsModel}}) or \emph{GriwrmInputsModel} (See \code{[CreateInputsModel.GRiwrm]}).
#' @param ... further arguments passed to or from other methods.
#'
#' @return Object of \emph{RunOptions} class family
......
#' Display a diagram representing the network structure of a Griwrm object
#' Display a diagram representing the network structure of a GRiwrm object
#'
#' @param griwrm the Griwrm object to display.
#' @param griwrm the GRiwrm object to display.
#' @param display if `TRUE` displays the diagram with `DiagrammeR::mermaid`, return the mermaid code otherwise.
#' @param orientation Orientation of the graph. "LR" by default.
#'
......
......@@ -5,28 +5,28 @@
#' @param cols named list or vector for matching columns of `db` parameter. By default, mandatory columns names are: `id`, `down`, `length`. But other names can be handled with a named list or vector containing items defined as `"required name" = "column name in db"`.
#' @param keep_all Keep all column of `db` or keep only columns defined in `cols`
#'
#' @return `Griwrm` class object containing the description of diagram of the semi-distributed catchment model
#' @return `GRiwrm` class object containing the description of diagram of the semi-distributed catchment model
#' @export
Griwrm <- function(db, cols = list(id = "id", down = "down", length = "length", model = "model"), keep_all = FALSE) {
GRiwrm <- function(db, cols = list(id = "id", down = "down", length = "length", model = "model"), keep_all = FALSE) {
colsDefault <- list(id = "id", down = "down", length = "length", model = "model", area = "area")
cols <- utils::modifyList(colsDefault, as.list(cols))
db <- dplyr::rename(db, unlist(cols))
if(!keep_all) {
db <- dplyr::select(db, names(cols))
}
class(db) <- append(class(db), c("Griwrm", "Griwrm"))
class(db) <- append(class(db), c("GRiwrm", "GRiwrm"))
db
}
#' Sort the nodes from upstream to downstream.
#'
#' @param griwrm See \code{[Griwrm]}.
#' @param griwrm See \code{[GRiwrm]}.
#'
#' @return vector with the ordered node names.
#' @export
getNodeRanking <- function(griwrm) {
if(!is(griwrm, "Griwrm")) {
stop("getNodeRanking: griwrm argument should be of class Griwrm")
if(!inherits(griwrm, "GRiwrm")) {
stop("getNodeRanking: griwrm argument should be of class GRiwrm")
}
# Remove nodes without model (direct flow connections treated as upstream flows only)
griwrm <- griwrm[!is.na(griwrm$model),]
......
#' Title
#'
#' @param InputsModel object of class \emph{GriwrmInputsModel}, see \code{[CreateInputsModel.Griwrm]} for details.
#' @param RunOptions object of class \emph{GriwrmRunOptions}, see \code{[CreateRunOptions.Griwrm]} for details.
#' @param InputsModel object of class \emph{GriwrmInputsModel}, see \code{[CreateInputsModel.GRiwrm]} for details.
#' @param RunOptions object of class \emph{GriwrmRunOptions}, see \code{[CreateRunOptions.GRiwrm]} for details.
#' @param Param list of parameter. The list item names are the IDs of the sub-basins. Each item is a vector of numerical parameters.
#' @param verbose (optional) boolean indicating if the function is run in verbose mode or not, default = \code{TRUE}
#' @param ... Mandatory for S3 method signature function compatibility with generic.
......
#' Update InputsModel$Qupstream with simulated upstream flows provided by GriwrmOutputsModels object.
#'
#' @param InputsModel \emph{GriwrmInputsModel} object. See \code{[CreateInputsModel.Griwrm]}.
#' @param InputsModel \emph{GriwrmInputsModel} object. See \code{[CreateInputsModel.GRiwrm]}.
#' @param IndPeriod_Run numeric index of period to be used for the model run (-)
#' @param OutputsModel \emph{GriwrmOutputsModel} object provided by \code{[RunModel.GriwrmInputsModel]}.
#'
......
# airGR-IWRM: airGR based Integrated Water Resource Management R package
# airGRiwrm: airGR based Integrated Water Resource Management R package
airGR-IWRM is an extension of the airGR R package for managing semi-distributive hydrological model on an anthropized catchment.
airGRiwrm is an extension of the airGR R package for managing semi-distributive hydrological model on an anthropized catchment.
This package is developed as part of the IN-WOP project (http://www.waterjpi.eu/joint-calls/joint-call-2018-waterworks-2017/booklet/in-wop) by the mixed research unit G-EAU (https://g-eau.fr).
......@@ -11,7 +11,7 @@ This package is developed as part of the IN-WOP project (http://www.waterjpi.eu/
This package depends on airGR version 1.6. or more which is currently under development. To install it, use the following instruction:
```
remotes::install_gitlab("HYCAR-Hydro/airgr@sd", host = "gitlab.irstea.fr")
remotes::install_gitlab("HYCAR-Hydro/airgr@dev", host = "gitlab.irstea.fr")
```
### Local installation
......
id_sgl id_hydro lambert2.x lambert2.y area description id_aval distance_aval
TRANN_01 766626.06 2369152.25 1557.06 l'Aube à Trannes ARCIS_24 68100
GURGY_02 H2221010 689713.00 2320549.00 3819.77 L'Yonne à Gurgy COURL_23 83612
BRIEN_03 H2482010 695313.00 2332549.00 2979.77 L'Armançon à Brienon-sur-Armançon COURL_23 84653
STDIZ_04 H5071010 791113.00 2407349.00 2347.53 La Marne à Saint-Dizier CHALO_21 85570
PARIS_05 H5920010 602213.00 2427449.00 43824.66 La Seine à Paris
BAR-S_06 H0400010 751913.00 2348349.00 2340.37 La Seine à Bar-sur-Seine MERY-_22 79766
CHAUM_07 716518.38 2241747.00 216.50 L'Yonne à Chaumard GURGY_02 153074
CUSSY_08 H2172310 726013.00 2275149.00 247.99 Le Cousin à Cussy-les-Forges GURGY_02 91378
STGER_09 718512.88 2266649.25 402.74 La Cure à St-Germain GURGY_02 94152
GUILL_10 H2322020 731013.00 2282349.00 488.71 Le Serein à Guillon CHABL_12 66026
AISY-_11 H2452020 742413.00 2298149.00 1349.51 L'Armançon à Aisy-sur-Armançon BRIEN_03 102428
CHABL_12 H2342010 709613.00 2314149.00 1116.27 Le Serein à Chablis COURL_23 111781
NOGEN_13 685912.88 2389349.25 9182.39 La Seine à Nogent-sur-Seine MONTE_15 63215
EPISY_14 H3621010 633413.00 2371049.00 3916.71 Le Loing à Épisy ALFOR_16 89196
MONTE_15 645112.88 2376849.25 21199.39 La Seine à Montereau ALFOR_16 94475
ALFOR_16 H4340020 606013.00 2420349.00 30784.71 La Seine à Alfortville PARIS_05 9263
NOISI_17 H5841010 620913.00 2428949.00 12547.72 La Marne à Noisiel PARIS_05 39384
MONTR_18 H5752020 638013.00 2431849.00 1184.81 Le Grand Morin à Montry NOISI_17 37915
LOUVE_19 H5083050 791613.00 2393949.00 461.74 La Blaise à Louvemont CHALO_21 86165
LASSI_20 H1362010 759513.00 2385549.00 876.53 La Voire à Lassicourt ARCIS_24 43618
CHALO_21 H5201010 747713.00 2441349.00 6291.55 La Marne à Châlons-sur-Marne NOISI_17 237937
MERY-_22 H0810010 714913.00 2390949.00 3899.62 La Seine à Méry-sur-Seine NOGEN_13 49933
COURL_23 H2721010 660813.00 2370449.00 10687.35 L'Yonne à Courlon-sur-Yonne MONTE_15 26159
ARCIS_24 H1501010 733313.00 2394749.00 3594.60 L'Aube à Arcis-sur-Aube NOGEN_13 70926
VITRY_25 H5172010 768513.00 2418849.00 2109.14 La Saulx à Vitry-en-Perthois CHALO_21 38047
id_sgl;id_hydro;lambert2.x;lambert2.y;area;description;id_aval;distance_aval
TRANN_01;;766626.06;2369152.25;1557.06;L'Aube à Trannes;ARCIS_24;68100
GURGY_02;H2221010;689713.00;2320549.00;3819.77;L'Yonne à Gurgy;COURL_23;83612
BRIEN_03;H2482010;695313.00;2332549.00;2979.77;L'Armançon à Brienon-sur-Armançon;COURL_23;84653
STDIZ_04;H5071010;791113.00;2407349.00;2347.53;La Marne à Saint-Dizier;CHALO_21;85570
PARIS_05;H5920010;602213.00;2427449.00;43824.66;La Seine à Paris;;
BAR-S_06;H0400010;751913.00;2348349.00;2340.37;La Seine à Bar-sur-Seine;MERY-_22;79766
CHAUM_07;;716518.38;2241747.00;216.50;L'Yonne à Chaumard;GURGY_02;153074
CUSSY_08;H2172310;726013.00;2275149.00;247.99;Le Cousin à Cussy-les-Forges;GURGY_02;91378
STGER_09;;718512.88;2266649.25;402.74;La Cure à St-Germain;GURGY_02;94152
GUILL_10;H2322020;731013.00;2282349.00;488.71;Le Serein à Guillon;CHABL_12;66026
AISY-_11;H2452020;742413.00;2298149.00;1349.51;L'Armançon à Aisy-sur-Armançon;BRIEN_03;102428
CHABL_12;H2342010;709613.00;2314149.00;1116.27;Le Serein à Chablis;COURL_23;111781
NOGEN_13;;685912.88;2389349.25;9182.39;La Seine à Nogent-sur-Seine;MONTE_15;63215
EPISY_14;H3621010;633413.00;2371049.00;3916.71;Le Loing à Épisy;ALFOR_16;89196
MONTE_15;;645112.88;2376849.25;21199.39;La Seine à Montereau;ALFOR_16;94475
ALFOR_16;H4340020;606013.00;2420349.00;30784.71;La Seine à Alfortville;PARIS_05;9263
NOISI_17;H5841010;620913.00;2428949.00;12547.72;La Marne à Noisiel;PARIS_05;39384
MONTR_18;H5752020;638013.00;2431849.00;1184.81;Le Grand Morin à Montry;NOISI_17;37915
LOUVE_19;H5083050;791613.00;2393949.00;461.74;La Blaise à Louvemont;CHALO_21;86165
LASSI_20;H1362010;759513.00;2385549.00;876.53;La Voire à Lassicourt;ARCIS_24;43618
CHALO_21;H5201010;747713.00;2441349.00;6291.55;La Marne à Châlons-sur-Marne;NOISI_17;237937
MERY-_22;H0810010;714913.00;2390949.00;3899.62;La Seine à Méry-sur-Seine;NOGEN_13;49933
COURL_23;H2721010;660813.00;2370449.00;10687.35;L'Yonne à Courlon-sur-Yonne;MONTE_15;26159
ARCIS_24;H1501010;733313.00;2394749.00;3594.60;L'Aube à Arcis-sur-Aube;NOGEN_13;70926
VITRY_25;H5172010;768513.00;2418849.00;2109.14;La Saulx à Vitry-en-Perthois;CHALO_21;38047
id length down
AUBE-_P2 66500 ARCIS_24
AUBE-_R3 44500 ARCIS_24
MARNE_P23 3000 STDIZ_04
MARNE_P28 82420 CHALO_21
MARNE_R25 56870 CHALO_21
PANNEC_P 153074 GURGY_02
PANNEC_R 153074 GURGY_02
SEINE_P7 73766 MERY-_22
SEINE_R8 41766 MERY-_22
id;length;down
AUBE-_P2;66500;ARCIS_24
AUBE-_R3;44500;ARCIS_24
MARNE_P23;3000;STDIZ_04
MARNE_P28;82420;CHALO_21
MARNE_R25;56870;CHALO_21
PANNEC_P;153074;GURGY_02
PANNEC_R;153074;GURGY_02
SEINE_P7;73766;MERY-_22
SEINE_R8;41766;MERY-_22
......@@ -21,14 +21,14 @@ library(airGRiwrm)
List of nodes
```{r}
seine_nodes <- readr::read_delim(
seine_nodes <- read.table(
file = system.file("seine_data", "network_gauging_stations.txt", package = "airGRiwrm"),
delim = "\t"
sep = ";", header = TRUE, fileEncoding = "UTF-8", quote = "\""
)
seine_nodes
```
Create the Griwrm object which lists the nodes and describes the network diagram. It's a dataframe of class `Griwrm` and `Griwrm` with specific column names:
Create the GRiwrm object which lists the nodes and describes the network diagram. It's a dataframe of class `GRiwrm` and `GRiwrm` with specific column names:
- `id`: the identifier of the node in the network.
- `down`: the identifier of the next hydrological node downstream.
......@@ -36,12 +36,12 @@ Create the Griwrm object which lists the nodes and describes the network diagram
- `model`: Name of the hydrological model used (E.g. "RunModel_GR4J"). `NA` for other type of node.
- `area`: Area of the sub-catchment (km<sup>2</sup>). Used for hydrological model such as GR models. `NA` if not used.
`Griwrm` function helps to rename the columns of the dataframe and assign the variable classes.
`GRiwrm` function helps to rename the columns of the dataframe and assign the variable classes.
```{r}
seine_nodes$model <- "RunModel_GR4J"
# Generate the Griwrm object
griwrm <- Griwrm(seine_nodes, list(id = "id_sgl", down = "id_aval", length = "distance_aval"))
# Generate the GRiwrm object
griwrm <- GRiwrm(seine_nodes, list(id = "id_sgl", down = "id_aval", length = "distance_aval"))
griwrm
```
......@@ -79,10 +79,9 @@ for(id in griwrm$id) {
"https://stratus.irstea.fr/d/0b18e688851a45478f7a/files/?p=/climaware_hydro/Q_OBS_NAT",
paste0(id, "_NAT.txt&dl=1")
)
ts <- readr::read_delim(file = url,
delim = ";", skip = 16, trim_ws = TRUE)
ts <- read.table(url, sep = ";", skip = 16, header = TRUE)
# Date conversion to POSIX
ts$Date <- as.POSIXlt(lubridate::ymd(ts$Date))
ts$Date <- as.POSIXct(as.character(ts$Date), format = "%Y%m%d")
# Ptot column is merged into Precip dataframe
Precip <- MergeTS(Precip, id, ts[,c("Date", "Ptot")])
# ETP column is merged into PotEvap dataframe
......@@ -95,9 +94,9 @@ for(id in griwrm$id) {
Qobs <- MergeTS(Qobs, id, ts[,c("Date", "Qnat")])
}
DatesR <- Precip$DatesR
Precip$DateR <- NULL
PotEvap$DateR <- NULL
Qobs$DateR <- NULL
Precip$DatesR <- NULL
PotEvap$DatesR <- NULL
Qobs$DatesR <- NULL
```
## Generate the GRIWRM InputsModel object
......
......@@ -15,7 +15,6 @@ knitr::opts_chunk$set(echo = TRUE)
```{r}
library(airGRiwrm)
library(lubridate)
```
......@@ -34,7 +33,7 @@ load("_cache/V01.RData")
Data comes from calibration of ClimAware project with naturalised flows.
```{r}
ClimAwareParams <- readr::read_csv(
ClimAwareParams <- read.csv(
file = "https://stratus.irstea.fr/d/0b18e688851a45478f7a/files/?p=/climaware_hydro/Ident_NAT_P0P0.txt&dl=1"
)
......@@ -80,7 +79,7 @@ The user must at least define the following arguments:
```{r}
IndPeriod_Run <- seq(
which(InputsModel[[1]]$DatesR == (InputsModel[[1]]$DatesR[1] %m+% years(1))), # Set aside warm-up period
which(InputsModel[[1]]$DatesR == (InputsModel[[1]]$DatesR[1] + 365*24*60*60)), # Set aside warm-up period
length(InputsModel[[1]]$DatesR) # Until the end of the time series
)
```
......
......@@ -164,14 +164,14 @@ style MARNE_R25 fill:#fcc
Hence the topological connection to the reservoirs is described in the model as below:
```{r}
reservoir_connections <- readr::read_delim(
reservoir_connections <- read.table(
file = system.file("seine_data", "network_reservoir_connections.txt", package = "airGRiwrm"),
delim = "\t"
sep = ";", header = TRUE
)
reservoir_connections
```
Reservoir connections are added to the Griwrm object:
Reservoir connections are added to the GRiwrm object:
```{r}
reservoir_connections$model <- NA
......@@ -196,18 +196,14 @@ Then, we load observation data for each reservoir and each connection:
```{r}
for(reservoir_id in names(lCfgReservoirs)) {
df <- readr::read_delim(
df <- read.table(
file = file.path(
"https://stratus.irstea.fr/d/0b18e688851a45478f7a/files/?p=/Reservoir_current_rules",
paste0(lCfgReservoirs[[reservoir_id]]$file, "&dl=1")
),
delim = "\t",
col_types = readr::cols(
Date = readr::col_character(),
.default = readr::col_double()
)
sep = "\t", header = TRUE, fill = TRUE
)
df$Date <- format(as.POSIXlt(lubridate::dmy(df$Date)), "%Y-%m-%d")
df$Date <- format(as.POSIXct(df$Date))
Qreservoir <- merge(data.frame(Date = format(DatesR, "%Y-%m-%d")), df, by = "Date", all.x = TRUE)
for(connect in names(lCfgReservoirs[[reservoir_id]]$connections)) {
# Replace data gap by zeros (should be interpolated ?)
......@@ -224,7 +220,7 @@ for(reservoir_id in names(lCfgReservoirs)) {
}
}
# Convert flows from m3/s to m3/day
Qobs[,-1] <- Qobs[,-1] * 86400
Qobs <- Qobs * 86400
```
......@@ -298,10 +294,10 @@ for(id in ids) {
"https://stratus.irstea.fr/d/0b18e688851a45478f7a/files/?p=/climaware_hydro/Q_OBS_NAT",
paste0(id, "_BV.txt&dl=1")
)
ts <- readr::read_delim(file = url,
delim = ";", skip = 24, trim_ws = TRUE)
ts <- read.table(file = url,
sep = ";", skip = 24, header = TRUE)
# Date conversion to POSIX
ts$Date <- as.POSIXlt(lubridate::ymd(ts$Date))
ts$Date <- as.POSIXct(as.character(ts$Date), format = "%Y%m%d")
# Convert Qobs from l/s to mm/time step
ts$Q <- ts$Q * 86.4 / griwrm$area[griwrm$id == id] / 1000
# Setting data gaps to NA
......@@ -321,7 +317,7 @@ ReduceOutputsModel <- function(OutputsModels, IndPeriod) {
return(OutputsModelsOut)
}
QobsReservoirs <- Qobs[Qobs$DatesR < "2008-08-01",c("DatesR", reservoir_connections$id)]
QobsReservoirs <- Qobs[DatesR < "2008-08-01", reservoir_connections$id]
save(QobsReservoirs, Qobs2, griwrm2, ReduceOutputsModel, file = "_cache/V04.RData")
```
......
......@@ -43,7 +43,7 @@ Generate `GriwrmInputsModel` object
```{r}
Qobs3 <- cbind(Qobs2, QobsReservoirs)
iEnd <-which(DatesR == lubridate::ymd("2008-07-31"))
iEnd <-which(DatesR == as.POSIXct("2008-07-31"))
InputsModel3 <- CreateInputsModel(griwrm3, DatesR[1:iEnd], Precip[1:iEnd,], PotEvap[1:iEnd,], Qobs3)
```
......@@ -52,7 +52,7 @@ InputsModel3 <- CreateInputsModel(griwrm3, DatesR[1:iEnd], Precip[1:iEnd,], PotE
```{r}
IndPeriod_Run <- seq(
which(InputsModel3[[1]]$DatesR == (InputsModel3[[1]]$DatesR[1] + months(12))), # Set aside warm-up period
which(InputsModel3[[1]]$DatesR == (InputsModel3[[1]]$DatesR[1] + 365*24*60*60)), # Set aside warm-up period
length(InputsModel3[[1]]$DatesR) # Until the end of the time series
)
```
......