Commit 3f30fdb5 authored by Delaigue Olivier's avatar Delaigue Olivier
Browse files

Merge branch 'dev' into 'master'

CRAN v1.6.9.21

See merge request !26
parents 50265112 e8d4a9cf
Pipeline #19524 canceled with stages
in 4 minutes and 56 seconds
......@@ -2,3 +2,9 @@
^\.Rproj\.user$
^\.Rprofile$
^packrat/
^tests/tmp/
^\.gitlab-ci.yml$
^\.regressionignore$
^\.gitlab-ci\.yml$
^\.vscode$
^Rplots\.pdf$
.Rproj.user
# Specific files for airGR
packrat/lib*/
# Compiled files
/src/*.o
/src/*.so
/src/*.dll
/src-*
# Test temporary files
/tests/tmp/
*.pdf
!man/figures/*.pdf
######################################################################################################
### Generic .gitignore for R (source: https://github.com/github/gitignore/blob/master/R.gitignore) ###
######################################################################################################
# History files
.Rhistory
.Rapp.history
# Session Data files
.RData
airGR.Rproj
packrat/lib*/
# User-specific files
.Ruserdata
# Example code in package build process
*-Ex.R
# Output files from R CMD build
/*.tar.gz
# Output files from R CMD check
/*.Rcheck/
# RStudio files
.Rproj.user
# produced vignettes
vignettes/*.html
vignettes/*.pdf
# OAuth2 token, see https://github.com/hadley/httr/releases/tag/v0.3
.httr-oauth
# knitr and R markdown default cache directories
*_cache/
/cache/
# Temporary files created by R markdown
*.utf8.md
*.knit.md
# R Environment Variables
.Renviron
# pkgdown site
docs/
# vscode IDE
.vscode/*
*.code-workspace
.history/
stages:
- update_packages
- build
- regression
- tests
default:
before_script:
- echo "setwd(\"$(pwd)\")" > .Rprofile
- PATH=~/R/sources/R-${R_VERSION}/bin:$PATH
- rename "s/${R_VERSION}.airGR/airGR/" *.tar.gz
.update_packages:
stage: update_packages
only:
refs:
- tags
- schedules
script:
- Rscript -e "update.packages(ask=FALSE, repos=\"http://cran.r-project.org\")"
.build:
stage: build
script:
- cd ..
- echo "setwd(\"$(pwd)\")" > .Rprofile
- R CMD build airgr
- rename "s/airGR/${R_VERSION}.airGR/" airGR_*.tar.gz
- mv *.tar.gz airgr/
artifacts:
untracked: true
expire_in: 1 week
.regression:
stage: regression
script:
- Rscript tests/testthat/regression_tests.R stable
- R CMD INSTALL .
- Rscript tests/testthat/regression_tests.R dev
- Rscript tests/testthat/regression_tests.R compare
.check_not_cran:
stage: tests
variables:
NOT_CRAN: "true"
script:
- R CMD check airGR_*.tar.gz
.check_as_cran:
stage: tests
script:
- R CMD check --as-cran airGR_*.tar.gz
update_packages_patched:
variables:
R_VERSION: "patched"
extends: .update_packages
build_patched:
variables:
R_VERSION: "patched"
extends: .build
regression_patched:
variables:
R_VERSION: "patched"
extends: .regression
regression_devel:
only:
refs:
- schedules
variables:
R_VERSION: "devel"
extends: .regression
regression_oldrel:
only:
refs:
- schedules
variables:
R_VERSION: "oldrel"
extends: .regression
check_not_cran_patched:
variables:
R_VERSION: "patched"
extends: .check_not_cran
check_as_cran_patched:
variables:
R_VERSION: "patched"
extends: .check_as_cran
update_packages_devel:
variables:
R_VERSION: "devel"
extends: .update_packages
build_devel:
only:
refs:
- tags
- schedules
variables:
R_VERSION: "devel"
extends: .build
check_not_cran_devel:
only:
refs:
- tags
- schedules
variables:
R_VERSION: "devel"
extends: .check_not_cran
check_as_cran_devel:
only:
refs:
- tags
- schedules
variables:
R_VERSION: "devel"
extends: .check_as_cran
update_packages_oldrel:
variables:
R_VERSION: "oldrel"
extends: .update_packages
build_oldrel:
only:
refs:
- tags
- schedules
variables:
R_VERSION: "oldrel"
extends: .build
check_not_cran_oldrel:
only:
refs:
- tags
- schedules
variables:
R_VERSION: "oldrel"
extends: .check_not_cran
check_as_cran_oldrel:
only:
refs:
- tags
- schedules
variables:
R_VERSION: "oldrel"
extends: .check_as_cran
# .test-regression.ignore contains the list of topic/variables produces by
# documentation examples that should be ignore in the regression test
# The format of this file is: 5 lines of comments followed by one line by
# ignored variable : [Topic]<SPACE>[Variable].
# Example for ignoring OutputsModel variable produced by example("RunModel_GR2M"): RunModel_GR2M OutputsModel
RunModel_GR1A BasinObs
RunModel_GR1A ConvertFun
RunModel_GR1A NewTabSeries
RunModel_GR1A NewTimeFormat
RunModel_GR1A OutputsModel
RunModel_GR1A TabSeries
RunModel_GR1A TimeFormat
RunModel_GR1A YearFirstMonth
RunModel_GR2M BasinObs
RunModel_GR2M ConvertFun
RunModel_GR2M NewTabSeries
RunModel_GR2M NewTimeFormat
RunModel_GR2M OutputsModel
RunModel_GR2M RunOptions
RunModel_GR1A OutputsModel
Calibration_Michel CalibOptions
Calibration CalibOptions
CreateCalibOptions CalibOptions
# New version of the SeriesAggreg function
RunModel_GR2M TabSeries
RunModel_GR2M TimeFormat
SeriesAggreg BasinInfo
SeriesAggreg BasinObs
SeriesAggreg NewTabSeries
Package: airGR
Type: Package
Title: Suite of GR Hydrological Models for Precipitation-Runoff Modelling
Version: 1.4.3.65
Date: 2020-02-28
Version: 1.6.9.21
Date: 2021-01-13
Authors@R: c(
person("Laurent", "Coron", role = c("aut", "trl"), comment = c(ORCID = "0000-0002-1503-6204")),
person("Olivier", "Delaigue", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-7668-8468"), email = "airGR@inrae.fr"),
person("Guillaume", "Thirel", role = c("aut"), comment = c(ORCID = "0000-0002-1444-1830")),
person("David", "Dorchies", role = c("aut"), comment = c(ORCID = "0000-0002-6595-7984")),
person("Charles", "Perrin", role = c("aut", "ths"), comment = c(ORCID = "0000-0001-8552-1881")),
person("Claude", "Michel", role = c("aut", "ths")),
person("Vazken", "Andréassian", role = c("ctb", "ths"), comment = c(ORCID = "0000-0001-7124-9303")),
person("François", "Bourgin", role = c("ctb"), comment = c(ORCID = "0000-0002-2820-7260", vignette = "'Parameter estimation' vignettes")),
person("François", "Bourgin", role = c("ctb"), comment = c(ORCID = "0000-0002-2820-7260")),
person("Pierre", "Brigode", role = c("ctb"), comment = c(ORCID = "0000-0001-8257-0741")),
person("Nicolas", "Le Moine", role = c("ctb")),
person("Thibaut", "Mathevet", role = c("ctb"), comment = c(ORCID = "0000-0002-4142-4454")),
......@@ -19,12 +20,20 @@ Authors@R: c(
person("Raji", "Pushpalatha", role = c("ctb")),
person("Audrey", "Valéry", role = c("ctb"))
)
Depends: R (>= 3.0.1)
Suggests: knitr, rmarkdown, coda, DEoptim, dplyr, FME, ggmcmc, Rmalschains
Depends: R (>= 3.1.0)
Imports:
graphics,
grDevices,
stats,
utils
Suggests:
knitr, rmarkdown,
coda, DEoptim, dplyr, FME, ggmcmc, hydroPSO, imputeTS, Rmalschains,
testthat
Description: Hydrological modelling tools developed at INRAE-Antony (HYCAR Research Unit, France). The package includes several conceptual rainfall-runoff models (GR4H, GR5H, GR4J, GR5J, GR6J, GR2M, GR1A), a snow accumulation and melt model (CemaNeige) and the associated functions for their calibration and evaluation. Use help(airGR) for package description and references.
License: GPL-2
URL: https://hydrogr.github.io/airGR/
BugReports: https://gitlab.irstea.fr/HYCAR-Hydro/airgr/issues
BugReports: https://gitlab.irstea.fr/HYCAR-Hydro/airgr/-/issues
NeedsCompilation: yes
Encoding: UTF-8
VignetteBuilder: knitr
......@@ -8,7 +8,13 @@ useDynLib(airGR, .registration = TRUE)
#####################################
## S3 methods ##
#####################################
S3method("plot", "OutputsModel")
S3method('[', InputsModel)
S3method('[', OutputsModel)
S3method(plot, OutputsModel)
S3method(SeriesAggreg, data.frame)
S3method(SeriesAggreg, list)
S3method(SeriesAggreg, InputsModel)
S3method(SeriesAggreg, OutputsModel)
......@@ -45,6 +51,7 @@ export(RunModel_GR5H)
export(RunModel_GR4J)
export(RunModel_GR5J)
export(RunModel_GR6J)
export(RunModel_Lag)
export(SeriesAggreg)
export(TransfoParam)
export(TransfoParam_CemaNeige)
......@@ -56,10 +63,8 @@ export(TransfoParam_GR5H)
export(TransfoParam_GR4J)
export(TransfoParam_GR5J)
export(TransfoParam_GR6J)
export(plot.OutputsModel)
exportPattern(".FortranOutputs")
exportPattern(".ErrorCrit")
export(TransfoParam_Lag)
export(.ErrorCrit)
#####################################
......
This diff is collapsed.
......@@ -12,11 +12,16 @@ Calibration_Michel <- function(InputsModel,
if (!missing(FUN_CRIT)) {
FUN_CRIT <- match.fun(FUN_CRIT)
}
# Handling 'FUN_TRANSFO' from direct argument or provided by 'CaliOptions'
if (!is.null(FUN_TRANSFO)) {
FUN_TRANSFO <- match.fun(FUN_TRANSFO)
} else if(!is.null(CalibOptions$FUN_TRANSFO)) {
FUN_TRANSFO <- CalibOptions$FUN_TRANSFO
} else {
stop("'FUN_TRANSFO' is not provided neither as 'FUN_TRANSFO' argument or in 'CaliOptions' argument")
}
##_____Arguments_check_____________________________________________________________________
if (!inherits(InputsModel, "InputsModel")) {
stop("'InputsModel' must be of class 'InputsModel'")
......@@ -54,97 +59,6 @@ Calibration_Michel <- function(InputsModel,
warning("argument 'FUN_CRIT' is deprecated. The error criterion function is now automatically get from the 'InputsCrit' object")
}
##_check_FUN_TRANSFO
if (is.null(FUN_TRANSFO)) {
if (identical(FUN_MOD, RunModel_GR4H )) {
FUN_TRANSFO <- TransfoParam_GR4H
}
if (identical(FUN_MOD, RunModel_GR5H )) {
FUN_TRANSFO <- TransfoParam_GR5H
}
if (identical(FUN_MOD, RunModel_GR4J )) {
FUN_TRANSFO <- TransfoParam_GR4J
}
if (identical(FUN_MOD, RunModel_GR5J )) {
FUN_TRANSFO <- TransfoParam_GR5J
}
if (identical(FUN_MOD, RunModel_GR6J )) {
FUN_TRANSFO <- TransfoParam_GR6J
}
if (identical(FUN_MOD, RunModel_GR2M )) {
FUN_TRANSFO <- TransfoParam_GR2M
}
if (identical(FUN_MOD, RunModel_GR1A )) {
FUN_TRANSFO <- TransfoParam_GR1A
}
if (identical(FUN_MOD, RunModel_CemaNeige )) {
if (inherits(CalibOptions, "hysteresis")) {
FUN_TRANSFO <- TransfoParam_CemaNeigeHyst
} else {
FUN_TRANSFO <- TransfoParam_CemaNeige
}
}
if (identical(FUN_MOD, RunModel_CemaNeigeGR4H) | identical(FUN_MOD, RunModel_CemaNeigeGR5H) |
identical(FUN_MOD, RunModel_CemaNeigeGR4J) | identical(FUN_MOD, RunModel_CemaNeigeGR5J) | identical(FUN_MOD, RunModel_CemaNeigeGR6J)) {
if (identical(FUN_MOD, RunModel_CemaNeigeGR4H)) {
FUN1 <- TransfoParam_GR4H
}
if (identical(FUN_MOD, RunModel_CemaNeigeGR5H)) {
FUN1 <- TransfoParam_GR5H
}
if (identical(FUN_MOD, RunModel_CemaNeigeGR4J)) {
FUN1 <- TransfoParam_GR4J
}
if (identical(FUN_MOD, RunModel_CemaNeigeGR5J)) {
FUN1 <- TransfoParam_GR5J
}
if (identical(FUN_MOD, RunModel_CemaNeigeGR6J)) {
FUN1 <- TransfoParam_GR6J
}
if (inherits(CalibOptions, "hysteresis")) {
FUN2 <- TransfoParam_CemaNeigeHyst
} else {
FUN2 <- TransfoParam_CemaNeige
}
if (inherits(CalibOptions, "hysteresis")) {
FUN_TRANSFO <- function(ParamIn, Direction) {
Bool <- is.matrix(ParamIn)
if (!Bool) {
ParamIn <- rbind(ParamIn)
}
ParamOut <- NA * ParamIn
NParam <- ncol(ParamIn)
ParamOut[, 1:(NParam-4)] <- FUN1(ParamIn[, 1:(NParam-4)], Direction)
ParamOut[, (NParam-3):NParam ] <- FUN2(ParamIn[, (NParam-3):NParam ], Direction)
if (!Bool) {
ParamOut <- ParamOut[1, ]
}
return(ParamOut)
}
} else {
FUN_TRANSFO <- function(ParamIn, Direction) {
Bool <- is.matrix(ParamIn)
if (!Bool) {
ParamIn <- rbind(ParamIn)
}
ParamOut <- NA * ParamIn
NParam <- ncol(ParamIn)
ParamOut[, 1:(NParam-2)] <- FUN1(ParamIn[, 1:(NParam-2)], Direction)
ParamOut[, (NParam-1):NParam ] <- FUN2(ParamIn[, (NParam-1):NParam ], Direction)
if (!Bool) {
ParamOut <- ParamOut[1, ]
}
return(ParamOut)
}
}
}
if (is.null(FUN_TRANSFO)) {
stop("'FUN_TRANSFO' was not found (in 'Calibration' function)")
}
}
##_variables_initialisation
ParamFinalR <- NULL
ParamFinalT <- NULL
......@@ -231,7 +145,7 @@ Calibration_Michel <- function(InputsModel,
}
##Model_run
Param <- CandidatesParamR[iNew, ]
OutputsModel <- FUN_MOD(InputsModel, RunOptions, Param)
OutputsModel <- RunModel(InputsModel, RunOptions, Param, FUN_MOD = FUN_MOD)
##Calibration_criterion_computation
OutputsCrit <- ErrorCrit(InputsCrit, OutputsModel, verbose = FALSE)
......@@ -380,7 +294,7 @@ Calibration_Michel <- function(InputsModel,
for (iNew in 1:nrow(CandidatesParamR)) {
##Model_run
Param <- CandidatesParamR[iNew, ]
OutputsModel <- FUN_MOD(InputsModel, RunOptions, Param)
OutputsModel <- RunModel(InputsModel, RunOptions, Param, FUN_MOD = FUN_MOD)
##Calibration_criterion_computation
OutputsCrit <- ErrorCrit(InputsCrit, OutputsModel, verbose = FALSE)
if (!is.na(OutputsCrit$CritValue)) {
......@@ -441,7 +355,7 @@ Calibration_Michel <- function(InputsModel,
CandidatesParamR <- FUN_TRANSFO(CandidatesParamT, "TR")
##Model_run
Param <- CandidatesParamR[iNew, ]
OutputsModel <- FUN_MOD(InputsModel, RunOptions, Param)
OutputsModel <- RunModel(InputsModel, RunOptions, Param, FUN_MOD = FUN_MOD)
##Calibration_criterion_computation
OutputsCrit <- ErrorCrit(InputsCrit, OutputsModel, verbose = FALSE)
if (OutputsCrit$CritValue * OutputsCrit$Multiplier < CritOptim) {
......@@ -521,4 +435,3 @@ Calibration_Michel <- function(InputsModel,
}
......@@ -2,6 +2,7 @@ CreateCalibOptions <- function(FUN_MOD,
FUN_CALIB = Calibration_Michel,
FUN_TRANSFO = NULL,
IsHyst = FALSE,
IsSD = FALSE,
FixedParam = NULL,
SearchRanges = NULL,
StartParamList = NULL,
......@@ -17,6 +18,9 @@ CreateCalibOptions <- function(FUN_MOD,
if (!is.logical(IsHyst) | length(IsHyst) != 1L) {
stop("'IsHyst' must be a logical of length 1")
}
if (!is.logical(IsSD) | length(IsSD) != 1L) {
stop("'IsSD' must be a logical of length 1")
}
##check_FUN_MOD
BOOL <- FALSE
......@@ -75,6 +79,9 @@ CreateCalibOptions <- function(FUN_MOD,
if (IsHyst) {
ObjectClass <- c(ObjectClass, "hysteresis")
}
if (IsSD) {
ObjectClass <- c(ObjectClass, "SD")
}
if (!BOOL) {
stop("incorrect 'FUN_MOD' for use in 'CreateCalibOptions'")
return(NULL)
......@@ -98,52 +105,56 @@ CreateCalibOptions <- function(FUN_MOD,
##_set_FUN1
if (identical(FUN_MOD, RunModel_GR4H) |
identical(FUN_MOD, RunModel_CemaNeigeGR4H)) {
FUN1 <- TransfoParam_GR4H
FUN_GR <- TransfoParam_GR4H
}
if (identical(FUN_MOD, RunModel_GR5H) |
identical(FUN_MOD, RunModel_CemaNeigeGR5H)) {
FUN1 <- TransfoParam_GR5H
FUN_GR <- TransfoParam_GR5H
}
if (identical(FUN_MOD, RunModel_GR4J) |
identical(FUN_MOD, RunModel_CemaNeigeGR4J)) {
FUN1 <- TransfoParam_GR4J
FUN_GR <- TransfoParam_GR4J
}
if (identical(FUN_MOD, RunModel_GR5J) |
identical(FUN_MOD, RunModel_CemaNeigeGR5J)) {
FUN1 <- TransfoParam_GR5J
FUN_GR <- TransfoParam_GR5J
}
if (identical(FUN_MOD, RunModel_GR6J) |
identical(FUN_MOD, RunModel_CemaNeigeGR6J)) {
FUN1 <- TransfoParam_GR6J
FUN_GR <- TransfoParam_GR6J
}
if (identical(FUN_MOD, RunModel_GR2M)) {
FUN1 <- TransfoParam_GR2M
FUN_GR <- TransfoParam_GR2M
}
if (identical(FUN_MOD, RunModel_GR1A)) {
FUN1 <- TransfoParam_GR1A
FUN_GR <- TransfoParam_GR1A
}
if (identical(FUN_MOD, RunModel_CemaNeige)) {
if (IsHyst) {
FUN1 <- TransfoParam_CemaNeigeHyst
FUN_GR <- TransfoParam_CemaNeigeHyst
} else {
FUN1 <- TransfoParam_CemaNeige
FUN_GR <- TransfoParam_CemaNeige
}
}
if (is.null(FUN1)) {
stop("'FUN1' was not found")
if (is.null(FUN_GR)) {
stop("'FUN_GR' was not found")
return(NULL)
}
##_set_FUN2
if (IsHyst) {
FUN2 <- TransfoParam_CemaNeigeHyst
FUN_SNOW <- TransfoParam_CemaNeigeHyst
} else {
FUN2 <- TransfoParam_CemaNeige
FUN_SNOW <- TransfoParam_CemaNeige
}
##_set_FUN_LAG
if (IsSD) {
FUN_LAG <- TransfoParam_Lag
}
##_set_FUN_TRANSFO
if (sum(ObjectClass %in% c("GR4H", "GR5H", "GR4J", "GR5J", "GR6J", "GR2M", "GR1A", "CemaNeige")) > 0) {
FUN_TRANSFO <- FUN1
if (!IsSD) {
FUN_TRANSFO <- FUN_GR
} else {
if (IsHyst) {
FUN_TRANSFO <- function(ParamIn, Direction) {
Bool <- is.matrix(ParamIn)
if (!Bool) {
......@@ -151,14 +162,32 @@ CreateCalibOptions <- function(FUN_MOD,
}
ParamOut <- NA * ParamIn
NParam <- ncol(ParamIn)
ParamOut[, 1:(NParam - 4)] <- FUN1(ParamIn[, 1:(NParam - 4)], Direction)
ParamOut[, (NParam - 3):NParam] <- FUN2(ParamIn[, (NParam - 3):NParam], Direction)
ParamOut[, 2:NParam] <- FUN_GR(ParamIn[, 2:NParam], Direction)
ParamOut[, 1 ] <- FUN_LAG(as.matrix(ParamIn[, 1]), Direction)
if (!Bool) {
ParamOut <- ParamOut[1, ]
}
return(ParamOut)
}
}
} else {
if (IsHyst & !IsSD) {
FUN_TRANSFO <- function(ParamIn, Direction) {
Bool <- is.matrix(ParamIn)
if (!Bool) {
ParamIn <- rbind(ParamIn)
}
ParamOut <- NA * ParamIn