diff --git a/DESCRIPTION b/DESCRIPTION
index da20bb6a..3f0a0b37 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -37,7 +37,8 @@ Imports:
httr,
utils,
memuse,
- purrr
+ purrr,
+ lifecycle
Suggests:
rhdf5 (>= 2.24.0),
testthat,
diff --git a/NAMESPACE b/NAMESPACE
index 1badafdd..a3692c35 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -1,119 +1,120 @@
-# Generated by roxygen2: do not edit by hand
-
-S3method("[",antaresDataTable)
-S3method(as.antaresDataList,antaresDataList)
-S3method(as.antaresDataList,antaresDataTable)
-S3method(as.antaresDataList,data.frame)
-S3method(as.antaresDataList,default)
-S3method(as.antaresDataList,list)
-S3method(as.antaresDataTable,antaresDataTable)
-S3method(as.antaresDataTable,data.frame)
-S3method(as.antaresDataTable,default)
-S3method(copyToClipboard,antaresDataList)
-S3method(copyToClipboard,data.frame)
-S3method(copyToClipboard,default)
-S3method(copyToClipboard,matrix)
-S3method(merge,antaresDataTable)
-S3method(print,antaresDataList)
-S3method(print,antaresDataTable)
-S3method(print,simOptions)
-S3method(subset,antaresDataList)
-S3method(summary,bindingConstraints)
-S3method(viewAntares,antaresDataList)
-S3method(viewAntares,default)
-export(.getOptionsH5)
-export(.h5ReadAntares)
-export(.writeAntaresH5Fun)
-export(aggregateResult)
-export(api_delete)
-export(api_get)
-export(api_post)
-export(api_put)
-export(as.antaresDataList)
-export(as.antaresDataTable)
-export(changeTimeStep)
-export(copyToClipboard)
-export(extractDataList)
-export(getAlias)
-export(getAreas)
-export(getDistricts)
-export(getGeographicTrimming)
-export(getIdCols)
-export(getLinks)
-export(hvdcModification)
-export(isH5Opts)
-export(mergeDigests)
-export(parAggregateMCall)
-export(ponderateMcAggregation)
-export(readAntares)
-export(readAntaresAreas)
-export(readAntaresClusters)
-export(readBindingConstraints)
-export(readClusterDesc)
-export(readClusterResDesc)
-export(readClusterSTDesc)
-export(readDigestFile)
-export(readIni)
-export(readIniAPI)
-export(readIniFile)
-export(readInputRES)
-export(readInputTS)
-export(readInputThermal)
-export(readLayout)
-export(readOptimCriteria)
-export(removeVirtualAreas)
-export(setAlias)
-export(setHvdcAreas)
-export(setRam)
-export(setSimulationPath)
-export(setSimulationPathAPI)
-export(setTimeoutAPI)
-export(showAliases)
-export(simOptions)
-export(viewAntares)
-export(writeAntaresH5)
-export(writeDigest)
-import(bit64)
-import(data.table)
-import(doParallel)
-import(jsonlite)
-import(parallel)
-import(plyr)
-importFrom(doParallel,registerDoParallel)
-importFrom(grDevices,col2rgb)
-importFrom(grDevices,rgb)
-importFrom(httr,DELETE)
-importFrom(httr,GET)
-importFrom(httr,POST)
-importFrom(httr,PUT)
-importFrom(httr,accept_json)
-importFrom(httr,add_headers)
-importFrom(httr,content)
-importFrom(httr,content_type_json)
-importFrom(httr,http_status)
-importFrom(httr,stop_for_status)
-importFrom(httr,timeout)
-importFrom(memuse,Sys.meminfo)
-importFrom(methods,is)
-importFrom(pbapply,pblapply)
-importFrom(pbapply,pboptions)
-importFrom(plyr,llply)
-importFrom(purrr,quietly)
-importFrom(shiny,getDefaultReactiveDomain)
-importFrom(shiny,incProgress)
-importFrom(shiny,withProgress)
-importFrom(stats,as.formula)
-importFrom(stats,setNames)
-importFrom(stats,weighted.mean)
-importFrom(stringi,stri_replace_last_fixed)
-importFrom(stringr,str_match)
-importFrom(stringr,str_replace)
-importFrom(stringr,str_split)
-importFrom(utils,URLencode)
-importFrom(utils,View)
-importFrom(utils,read.table)
-importFrom(utils,setTxtProgressBar)
-importFrom(utils,txtProgressBar)
-importFrom(utils,type.convert)
-importFrom(utils,untar)
-importFrom(utils,write.table)
+# Generated by roxygen2: do not edit by hand
+
+S3method("[",antaresDataTable)
+S3method(as.antaresDataList,antaresDataList)
+S3method(as.antaresDataList,antaresDataTable)
+S3method(as.antaresDataList,data.frame)
+S3method(as.antaresDataList,default)
+S3method(as.antaresDataList,list)
+S3method(as.antaresDataTable,antaresDataTable)
+S3method(as.antaresDataTable,data.frame)
+S3method(as.antaresDataTable,default)
+S3method(copyToClipboard,antaresDataList)
+S3method(copyToClipboard,data.frame)
+S3method(copyToClipboard,default)
+S3method(copyToClipboard,matrix)
+S3method(merge,antaresDataTable)
+S3method(print,antaresDataList)
+S3method(print,antaresDataTable)
+S3method(print,simOptions)
+S3method(subset,antaresDataList)
+S3method(summary,bindingConstraints)
+S3method(viewAntares,antaresDataList)
+S3method(viewAntares,default)
+export(.getOptionsH5)
+export(.h5ReadAntares)
+export(.writeAntaresH5Fun)
+export(aggregateResult)
+export(api_delete)
+export(api_get)
+export(api_post)
+export(api_put)
+export(as.antaresDataList)
+export(as.antaresDataTable)
+export(changeTimeStep)
+export(copyToClipboard)
+export(extractDataList)
+export(getAlias)
+export(getAreas)
+export(getDistricts)
+export(getGeographicTrimming)
+export(getIdCols)
+export(getLinks)
+export(hvdcModification)
+export(isH5Opts)
+export(mergeDigests)
+export(parAggregateMCall)
+export(ponderateMcAggregation)
+export(readAntares)
+export(readAntaresAreas)
+export(readAntaresClusters)
+export(readBindingConstraints)
+export(readClusterDesc)
+export(readClusterResDesc)
+export(readClusterSTDesc)
+export(readDigestFile)
+export(readIni)
+export(readIniAPI)
+export(readIniFile)
+export(readInputRES)
+export(readInputTS)
+export(readInputThermal)
+export(readLayout)
+export(readOptimCriteria)
+export(removeVirtualAreas)
+export(setAlias)
+export(setHvdcAreas)
+export(setRam)
+export(setSimulationPath)
+export(setSimulationPathAPI)
+export(setTimeoutAPI)
+export(showAliases)
+export(simOptions)
+export(viewAntares)
+export(writeAntaresH5)
+export(writeDigest)
+import(bit64)
+import(data.table)
+import(doParallel)
+import(jsonlite)
+import(parallel)
+import(plyr)
+importFrom(doParallel,registerDoParallel)
+importFrom(grDevices,col2rgb)
+importFrom(grDevices,rgb)
+importFrom(httr,DELETE)
+importFrom(httr,GET)
+importFrom(httr,POST)
+importFrom(httr,PUT)
+importFrom(httr,accept_json)
+importFrom(httr,add_headers)
+importFrom(httr,content)
+importFrom(httr,content_type_json)
+importFrom(httr,http_status)
+importFrom(httr,stop_for_status)
+importFrom(httr,timeout)
+importFrom(lifecycle,deprecated)
+importFrom(memuse,Sys.meminfo)
+importFrom(methods,is)
+importFrom(pbapply,pblapply)
+importFrom(pbapply,pboptions)
+importFrom(plyr,llply)
+importFrom(purrr,quietly)
+importFrom(shiny,getDefaultReactiveDomain)
+importFrom(shiny,incProgress)
+importFrom(shiny,withProgress)
+importFrom(stats,as.formula)
+importFrom(stats,setNames)
+importFrom(stats,weighted.mean)
+importFrom(stringi,stri_replace_last_fixed)
+importFrom(stringr,str_match)
+importFrom(stringr,str_replace)
+importFrom(stringr,str_split)
+importFrom(utils,URLencode)
+importFrom(utils,View)
+importFrom(utils,read.table)
+importFrom(utils,setTxtProgressBar)
+importFrom(utils,txtProgressBar)
+importFrom(utils,type.convert)
+importFrom(utils,untar)
+importFrom(utils,write.table)
diff --git a/NEWS.md b/NEWS.md
index 992a76e1..fece1c36 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -4,7 +4,12 @@
### Breaking changes (Antares v8.7) :
-* Existing function `readBindingConstraints()` (cf. Antares v8.7 changelog)
+* `readBindingConstraints()` read now Scenarized RHS for binding constraints (cf. Antares v8.7 changelog)
+ - returns a new list structure
+
+BUGFIXES :
+
+* `readBindingConstraints()` read well study >= v8.3.2
# antaresRead 2.6.1 (devlopment)
diff --git a/R/antaresRead-package.R b/R/antaresRead-package.R
new file mode 100644
index 00000000..425b3c1c
--- /dev/null
+++ b/R/antaresRead-package.R
@@ -0,0 +1,7 @@
+#' @keywords internal
+"_PACKAGE"
+
+## usethis namespace: start
+#' @importFrom lifecycle deprecated
+## usethis namespace: end
+NULL
diff --git a/R/readBindingConstraints.R b/R/readBindingConstraints.R
index 64204ed9..ac2ee782 100644
--- a/R/readBindingConstraints.R
+++ b/R/readBindingConstraints.R
@@ -21,7 +21,6 @@
#' \item{values}{values used by the constraint. It contains one line per time step
#' and three columns "less", "greater" and "equal"}
#'
-#' The \code{summary} method returns a data.frame with one line per constraint.
#'
#'
#' @examples
@@ -35,7 +34,6 @@
#'
#' @export
readBindingConstraints <- function(opts = simOptions()) {
-
if(isH5Opts(opts)){
if(.requireRhdf5_Antares(stopP = FALSE)){
return(h5ReadBindingConstraints(opts))
@@ -44,151 +42,260 @@ readBindingConstraints <- function(opts = simOptions()) {
}
}
+ ##
+ # API BLOC
+ ##
+
if(opts$typeLoad == 'api'){
- bindingConstraints <- read_secure_json(file.path(opts$inputPath, "bindingconstraints", "bindingconstraints"),
- opts$token, timeout = opts$timeout, config = opts$httr_config)
+ bindingConstraints <- read_secure_json(file.path(opts$inputPath,
+ "bindingconstraints",
+ "bindingconstraints"),
+ opts$token,
+ timeout = opts$timeout,
+ config = opts$httr_config)
}else{
- path <- file.path(opts$inputPath, "bindingconstraints/bindingconstraints.ini")
- bindingConstraints <- readIniFile(path, stringsAsFactors = FALSE)
+ path <- file.path(opts$inputPath,
+ "bindingconstraints/bindingconstraints.ini")
+ bindingConstraints <- readIniFile(path,
+ stringsAsFactors = FALSE)
}
+ ##
+ # Exception if no properties
+ ##
+
if(length(bindingConstraints) == 0) {
warning("It looks like there is no binding constraints is this study.")
return(NULL)
}
- # read txt files
- for (i in 1:length(bindingConstraints)) {
- # check to return 0 values if empty file (only for < v870)
- nrows <- switch(bindingConstraints[[i]]$type,
- hourly = 24*7*52,
- daily = 7 * 52,
- weekly = 52,
- monthly = 12,
- annual = 1)
-
- # v870
- if(opts$antaresVersion>=870){
- path_lt <- file.path(opts$inputPath,
- sprintf("bindingconstraints/%s.txt",
- paste0(bindingConstraints[[i]]$id, "_lt")))
- path_gt <- file.path(opts$inputPath,
- sprintf("bindingconstraints/%s.txt",
- paste0(bindingConstraints[[i]]$id, "_gt")))
- path_eq <- file.path(opts$inputPath,
- sprintf("bindingconstraints/%s.txt",
- paste0(bindingConstraints[[i]]$id, "_eq")))
-
- suppressWarnings(
- tmp_values <- lapply(c(path_lt, path_gt, path_eq),
- fread_antares, opts = opts)
- )
-
- names(tmp_values) <- c("lt", "gt", "eq")
+ ##
+ # read values txt files
+ ##
+ bindingConstraints <- lapply(bindingConstraints,
+ .read_binding_values,
+ opts = opts)
+
+ ##
+ # manage full list object
+ ##
+
+ # to return named list
+ constraintNames <- sapply(bindingConstraints,
+ `[[`,
+ "id")
+
+ # re structure list ($properties, $coefs, $values)
+ # [breaking changes] add "$properties" for all version
+ bindingConstraints <- lapply(bindingConstraints,
+ .manage_list_structure,
+ opts = opts)
+
+ names(bindingConstraints) <- constraintNames
+ class(bindingConstraints) <- "bindingConstraints"
+ bindingConstraints
+}
+
+# read values files for every binding of study
+.read_binding_values <- function(binding_object,
+ opts = simOptions()){
+ # dimension according to parameter "type" to return default value (TS file)
+ nrows <- switch(binding_object$type,
+ hourly = 24*7*52,
+ daily = 7 * 52,
+ weekly = 52,
+ monthly = 12,
+ annual = 1)
+
+ # v870
+ if(opts$antaresVersion>=870){
+
+ parse_type <- switch(binding_object$operator,
+ less = "lt",
+ greater = "gt",
+ equal = "eq",
+ both = c("lt", "gt")) # "both" case ?
+
+ path_file_value <- file.path(opts$inputPath,
+ sprintf("bindingconstraints/%s.txt",
+ paste0(binding_object$id,
+ "_",
+ parse_type)))
+
+ # check if "both" case
+ both_case <- binding_object$operator %in% "both"
+
+ # check path file
+ # multiple path for "both" case
+ if(!all(file.exists(path_file_value)))
+ stop("Time series file for binding constraint ",
+ binding_object$id,
+ " not exist",
+ call. = FALSE)
+
+ # Read files
+ # both case
+ if(both_case){
+ tmp_values <- lapply(path_file_value,
+ fread_antares,
+ opts = opts)
+ names(tmp_values) <- c("less", "greater")
+ }
+ else
+ tmp_values <- fread_antares(opts = opts,
+ file = path_file_value)
+
+
+ # check empty values to return default values
+ # both case
+ default_scenarised_values <- as.data.table(
+ matrix(0L, nrow = nrows, ncol = 1))
+
+ if(both_case){
+ check_nrow <- unlist(lapply(tmp_values, nrow))
+ if(any(check_nrow %in% 0)){
+ warning("Time series files for binding constraint ",
+ binding_object$id,
+ " are empty",
+ call. = FALSE)
+
+ tmp_values[["less"]] <- default_scenarised_values
+ tmp_values[["greater"]] <- default_scenarised_values
+ }
+ }
+ else
+ if(nrow(tmp_values)==0){
+ warning("Time series file for binding constraint ",
+ binding_object$id,
+ " is empty",
+ call. = FALSE)
+ tmp_values <- default_scenarised_values
+ }
+
+ # return
+ binding_object$values <- tmp_values
+ return(binding_object)
+
+ }else{ # <870 (legacy)
+ path <- file.path(opts$inputPath,
+ sprintf("bindingconstraints/%s.txt",
+ binding_object$id))
+
+ # why return 0 if file.size(path) == 0 ?
+ if(opts$typeLoad != "api" && file.size(path) == 0){
+ binding_object$values <- as.data.table(
+ matrix(0L, nrow = nrows, 3))
+ setnames(binding_object$values,
+ names(binding_object$values),
+ c("less", "greater", "equal"))
+ return(binding_object)
+ }
+ else{
+ # binding_object$values <- fread(path)
+ tmp_values <- fread_antares(opts = opts, file = path)
# this test do nothing => tmp_values never NULL
- # return 0 row/col for empty file or error if file does not exist
+ # return 0 row/col for empty file or error if file does not exist
if(is.null(tmp_values)){
- tmp_values <- list(`lt`= matrix(0L, nrow = nrows),
- `gt`= matrix(0L, nrow = nrows),
- `eq`= matrix(0L, nrow = nrows))
+ tmp_values <- as.data.table(matrix(0L, nrow = nrows, 3))
}
- bindingConstraints[[i]]$values <- tmp_values
- }else{
- path <- file.path(opts$inputPath, sprintf("bindingconstraints/%s.txt", bindingConstraints[[i]]$id))
-
- # why return 0 if file.size(path) == 0 ?
- if(opts$typeLoad != "api" && file.size(path) == 0){
- bindingConstraints[[i]]$values <- as.data.table(matrix(0L, nrow = nrows, 3))
- setnames(bindingConstraints[[i]]$values,
- names(bindingConstraints[[i]]$values),
- c("less", "greater", "equal"))
- }
- else{
- # bindingConstraints[[i]]$values <- fread(path)
- tmp_values <- fread_antares(opts = opts, file = path)
-
- # this test do nothing => tmp_values never NULL
- # return 0 row/col for empty file or error if file does not exist
- if(is.null(tmp_values)){
- tmp_values <- as.data.table(matrix(0L, nrow = nrows, 3))
- }
-
- bindingConstraints[[i]]$values <- tmp_values
- setnames(bindingConstraints[[i]]$values,
- names(bindingConstraints[[i]]$values),
- c("less", "greater", "equal"))
- }
+ binding_object$values <- tmp_values
+ setnames(binding_object$values,
+ names(binding_object$values),
+ c("less", "greater", "equal"))
+ return(binding_object)
}
- }
+ }
+}
+
+# build list structure according to antares version
+.manage_list_structure <- function(binding_object,
+ opts = simOptions()){
+ # default names of parameters (core parameters)
+ names_elements <- c("name", "id", "enabled", "type", "operator", "values")
- res <- unname(bindingConstraints)
+ # get links information from list
+ coefs_elements <- setdiff(names(binding_object),
+ names_elements)
+ coefs_values <- binding_object[which(names(binding_object) %in%
+ coefs_elements)]
- constraintNames <- vapply(res, function(x) x$name, character(1))
+ ##
+ # manage properties with version (filter)
+ ##
+ # filter on parameters to keep only links information
- # re structure list
- res <- lapply(res, function(x) {
- coefs <- x
- # default names of parameters
- names_elements <- c("name", "id", "enabled", "type", "operator", "values")
+ # v832
+ if (opts$antaresVersion>=832){
+ names_elements_832 <- c("filter-year-by-year",
+ "filter-synthesis")
+ elements_832 <- binding_object[which(names(binding_object) %in%
+ names_elements_832)]
- # v832
- if (opts$antaresVersion>=832)
- names_elements <- append(names_elements,
- c("filter-year-by-year", "filter-synthesis"))
-
- # v870
- if(opts$antaresVersion>=870)
- names_elements <- append(names_elements, "group")
-
- for (v in names_elements) {
- coefs[[v]] <- NULL
- }
+ coefs_values[names_elements_832] <- NULL
+ }
+
+ # v870
+ if(opts$antaresVersion>=870){
+ names_elements_870 <- "group"
+ elements_870 <- binding_object[which(names(binding_object) %in%
+ names_elements_870)]
- # update list
-
- # v870
- if(opts$antaresVersion>=870)
- list(
- enabled = x$enabled,
- timeStep = x$type,
- operator = x$operator,
- `filter-year-by-year` = x$`filter-year-by-year`,
- `filter-synthesis` = x$`filter-synthesis`,
- group = x$group,
- coefs = unlist(coefs),
- values = x$values)
- # v832
- else if(opts$antaresVersion>=832)
- list(
- enabled = x$enabled,
- timeStep = x$type,
- operator = x$operator,
- `filter-year-by-year` = x$`filter-year-by-year`,
- `filter-synthesis` = x$`filter-synthesis`,
- coefs = unlist(coefs),
- values = x$values)
- else
- list(
- enabled = x$enabled,
- timeStep = x$type,
- operator = x$operator,
- coefs = unlist(coefs),
- values = x$values)
- })
+ coefs_values[names_elements_870] <- NULL
+ }
+
+ ##
+ # update list
+ ##
+
+ # core elements list
+ core_list <- list(
+ properties = list(
+ name = binding_object$name,
+ id = binding_object$id,
+ enabled = binding_object$enabled,
+ timeStep = binding_object$type,
+ operator = binding_object$operator),
+ coefs = unlist(coefs_values),
+ values = binding_object$values)
+
+ # add properties according to version
+ # decreasing approach
+
+ # v870
+ if(opts$antaresVersion>=870){
+ list_870 <- list()
+ list_870$properties = append(core_list$properties,
+ c(
+ unlist(elements_832),
+ unlist(elements_870)))
+ list_870 <- append(list_870,
+ core_list[c(2,3)])
+ return(list_870)
+ }
+ # v832
+ if(opts$antaresVersion>=832){
+ list_832 <- list()
+ list_832$properties = append(core_list$properties,
+ unlist(elements_832))
+ list_832 <- append(list_832,
+ core_list[c(2,3)])
+ return(list_832)
+ }
- names(res) <- constraintNames
- class(res) <- "bindingConstraints"
- res
+ return(core_list)
}
+#' `r lifecycle::badge("deprecated")`
+#' @title Display equation of binding constraint
#' @param object Object returned by readBindingConstraints
#' @param ... Unused
#'
+#' @return A data.frame with one line per constraint.
#' @export
-#' @rdname readBindingConstraints
summary.bindingConstraints <- function(object, ...) {
+ lifecycle::deprecate_warn(">= 2.7.0", "antaresRead::summary.bindingConstraints()")
equations <- vapply(object, FUN.VALUE = character(1), function(x) {
coefs <- sprintf(
"%s %s x %s",
@@ -201,7 +308,7 @@ summary.bindingConstraints <- function(object, ...) {
lhs <- gsub("^ (\\+ )?", "", lhs)
lhs <- gsub("1 x ", "", lhs)
- if (x$operator == "both") {
+ if (x$properties$operator == "both") {
# Left inequality
rhs <- mean(x$values$greater)
range <- range(x$values$greater)
@@ -219,9 +326,9 @@ summary.bindingConstraints <- function(object, ...) {
res <- sprintf("%s < [%s, %s]", res, range[1], range[2])
}
} else {
- operator <- switch(x$operator, equal = "=", less = "<", greater = ">")
- rhs <- mean(x$values[[x$operator]])
- range <- range(x$values[[x$operator]])
+ operator <- switch(x$properties$operator, equal = "=", less = "<", greater = ">")
+ rhs <- mean(x$values[[x$properties$operator]])
+ range <- range(x$values[[x$properties$operator]])
if(range[1] == range[2]) {
res <- sprintf("%s %s %s", lhs, operator, rhs)
} else {
@@ -232,8 +339,8 @@ summary.bindingConstraints <- function(object, ...) {
res
})
- timeStep <- vapply(object, function(x) x$timeStep, character(1))
- enabled <- vapply(object, function(x) x$enabled, logical(1))
+ timeStep <- vapply(object, function(x) x$properties$timeStep, character(1))
+ enabled <- vapply(object, function(x) x$properties$enabled, logical(1))
data.frame(
enabled = enabled,
diff --git a/R/utils_api.R b/R/utils_api.R
index 921e2715..40284089 100644
--- a/R/utils_api.R
+++ b/R/utils_api.R
@@ -7,9 +7,13 @@ fread_antares <- function(opts, file, ...) {
endpoint = I(file),
query = list(formatted = FALSE)
)
- tryCatch(fread(response, ...), error = function(e) {message(file); message(e)})
+ suppressWarnings(
+ tryCatch(fread(response, ...), error = function(e){
+ message(file); message(e)
+ }))
} else {
- fread(file, ...)
+ suppressWarnings(
+ fread(file, ...))
}
}
diff --git a/inst/test_empty_study/empty_study_v870.tar.gz b/inst/test_empty_study/empty_study_v870.tar.gz
index ed122d64..947872f9 100644
Binary files a/inst/test_empty_study/empty_study_v870.tar.gz and b/inst/test_empty_study/empty_study_v870.tar.gz differ
diff --git a/inst/test_v8/test_case_study_v870.tar.gz b/inst/test_v8/test_case_study_v870.tar.gz
index 793d5323..55a85fce 100644
Binary files a/inst/test_v8/test_case_study_v870.tar.gz and b/inst/test_v8/test_case_study_v870.tar.gz differ
diff --git a/man/antaresRead-package.Rd b/man/antaresRead-package.Rd
new file mode 100644
index 00000000..4e332077
--- /dev/null
+++ b/man/antaresRead-package.Rd
@@ -0,0 +1,41 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/antaresRead-package.R
+\docType{package}
+\name{antaresRead-package}
+\alias{antaresRead}
+\alias{antaresRead-package}
+\title{antaresRead: Import, Manipulate and Explore the Results of an 'Antares' Simulation}
+\description{
+Import, manipulate and explore results generated by 'Antares', a powerful open source software developed by RTE (Réseau de Transport d’Électricité) to simulate and study electric power systems (more information about 'Antares' here : \url{https://antares-simulator.org/}).
+}
+\seealso{
+Useful links:
+\itemize{
+ \item \url{https://github.com/rte-antares-rpackage/antaresRead}
+ \item Report bugs at \url{https://github.com/rte-antares-rpackage/antaresRead/issues}
+}
+
+}
+\author{
+\strong{Maintainer}: Tatiana Vargas \email{tatiana.vargas@rte-france.com}
+
+Authors:
+\itemize{
+ \item Jalal-Edine ZAWAM
+ \item Francois Guillem
+ \item Benoit Thieurmel
+ \item Titouan Robert
+}
+
+Other contributors:
+\itemize{
+ \item Frederic Breant [contributor]
+ \item Victor Perrier [contributor]
+ \item Etienne Sanchez [contributor]
+ \item Assil Mansouri [contributor]
+ \item Clement Berthet [contributor]
+ \item RTE [copyright holder]
+}
+
+}
+\keyword{internal}
diff --git a/man/figures/lifecycle-archived.svg b/man/figures/lifecycle-archived.svg
new file mode 100644
index 00000000..48f72a6f
--- /dev/null
+++ b/man/figures/lifecycle-archived.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/man/figures/lifecycle-defunct.svg b/man/figures/lifecycle-defunct.svg
new file mode 100644
index 00000000..01452e5f
--- /dev/null
+++ b/man/figures/lifecycle-defunct.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/man/figures/lifecycle-deprecated.svg b/man/figures/lifecycle-deprecated.svg
new file mode 100644
index 00000000..4baaee01
--- /dev/null
+++ b/man/figures/lifecycle-deprecated.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/man/figures/lifecycle-experimental.svg b/man/figures/lifecycle-experimental.svg
new file mode 100644
index 00000000..d1d060e9
--- /dev/null
+++ b/man/figures/lifecycle-experimental.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/man/figures/lifecycle-maturing.svg b/man/figures/lifecycle-maturing.svg
new file mode 100644
index 00000000..df713101
--- /dev/null
+++ b/man/figures/lifecycle-maturing.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/man/figures/lifecycle-questioning.svg b/man/figures/lifecycle-questioning.svg
new file mode 100644
index 00000000..08ee0c90
--- /dev/null
+++ b/man/figures/lifecycle-questioning.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/man/figures/lifecycle-stable.svg b/man/figures/lifecycle-stable.svg
new file mode 100644
index 00000000..e015dc81
--- /dev/null
+++ b/man/figures/lifecycle-stable.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/man/figures/lifecycle-superseded.svg b/man/figures/lifecycle-superseded.svg
new file mode 100644
index 00000000..75f24f55
--- /dev/null
+++ b/man/figures/lifecycle-superseded.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/man/readBindingConstraints.Rd b/man/readBindingConstraints.Rd
index af6e6928..51c8052e 100644
--- a/man/readBindingConstraints.Rd
+++ b/man/readBindingConstraints.Rd
@@ -2,20 +2,13 @@
% Please edit documentation in R/readBindingConstraints.R
\name{readBindingConstraints}
\alias{readBindingConstraints}
-\alias{summary.bindingConstraints}
\title{Read binding constraints}
\usage{
readBindingConstraints(opts = simOptions())
-
-\method{summary}{bindingConstraints}(object, ...)
}
\arguments{
\item{opts}{list of simulation parameters returned by the function
\code{\link{setSimulationPath}}}
-
-\item{object}{Object returned by readBindingConstraints}
-
-\item{...}{Unused}
}
\value{
\code{readBindingConstraints} returns an object of class \code{bindingConstraints}.
@@ -27,8 +20,6 @@ a list with the following elements:
\item{coefficients}{elements containing the coefficients used by the constraint}
\item{values}{values used by the constraint. It contains one line per time step
and three columns "less", "greater" and "equal"}
-
-The \code{summary} method returns a data.frame with one line per constraint.
}
\description{
This function reads the binding constraints of an Antares project.
diff --git a/man/summary.bindingConstraints.Rd b/man/summary.bindingConstraints.Rd
new file mode 100644
index 00000000..f00ec913
--- /dev/null
+++ b/man/summary.bindingConstraints.Rd
@@ -0,0 +1,19 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/readBindingConstraints.R
+\name{summary.bindingConstraints}
+\alias{summary.bindingConstraints}
+\title{Display equation of binding constraint}
+\usage{
+\method{summary}{bindingConstraints}(object, ...)
+}
+\arguments{
+\item{object}{Object returned by readBindingConstraints}
+
+\item{...}{Unused}
+}
+\value{
+A data.frame with one line per constraint.
+}
+\description{
+\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}}
+}
diff --git a/tests/testthat/helper_init.R b/tests/testthat/helper_init.R
index 94c0e486..6f99f670 100644
--- a/tests/testthat/helper_init.R
+++ b/tests/testthat/helper_init.R
@@ -170,3 +170,28 @@ skip_according_to_options <- function() {
}
pathAPI <- "http://localhost:8080/studies/antaresStd/"
+
+
+# study empty ----
+ # latest version of study
+ # empty study to test exceptions
+sourcedir_empty_study <- system.file("test_empty_study",
+ package = "antaresRead")
+
+setup_study_empty <- function(dir_path){
+ studies <- list.files(dir_path, pattern = "\\.tar\\.gz$",
+ full.names = TRUE)
+ # choose pattern
+ studies <- studies[grep(x = studies,
+ pattern = "v87")]
+ # untar etude
+ path_sty <- file.path(tempdir(),
+ "study_empty_latest_version")
+ untar(studies[1], exdir = path_sty) # version latest
+ study_temp_path <- file.path(path_sty, "test_case")
+
+ assign("study_empty_latest_version",
+ file.path(path_sty,
+ "test_case"),
+ envir = globalenv())
+}
diff --git a/tests/testthat/test-bindingConstraints.R b/tests/testthat/test-bindingConstraints.R
deleted file mode 100644
index c0c83ae5..00000000
--- a/tests/testthat/test-bindingConstraints.R
+++ /dev/null
@@ -1,37 +0,0 @@
-context("bindingConstraints")
-
-
-sapply(studyPathS, function(studyPath){
-
-opts <- setSimulationPath(studyPath, 0)
-
-describe("readBindingConstraints", {
- it("returns an object of class 'bindingConstraints'", {
- constraints <- readBindingConstraints(opts)
- expect_is(constraints, "bindingConstraints")
- })
-})
-
-
-describe("summary.bindingConstraints", {
- it ("returns a data.frame describing the constraints", {
- constraints <- readBindingConstraints(opts)
- sumConstraints <- summary(constraints)
- expect_is(sumConstraints, "data.frame")
- expect_true(all(c("enabled", "timeStep", "equation") %in% names(sumConstraints)))
- })
-})
-
-
-describe("Both operator", {
- it ("returns a data.frame describing the constraints", {
- constraints <- readBindingConstraints(opts)
- constraints[[1]]$operator <- "both"
- sumConstraints <- summary(constraints)
- expect_is(sumConstraints, "data.frame")
- expect_true(all(c("enabled", "timeStep", "equation") %in% names(sumConstraints)))
- })
-})
-
-
-})
diff --git a/tests/testthat/test-readBindingConstraints.R b/tests/testthat/test-readBindingConstraints.R
index 7a58701a..2e9128d1 100644
--- a/tests/testthat/test-readBindingConstraints.R
+++ b/tests/testthat/test-readBindingConstraints.R
@@ -19,18 +19,16 @@ test_that("summary.bindingConstraints",{
test_that("Both operator",{
constraints <- readBindingConstraints(opts)
- constraints[[1]]$operator <- "both"
+ constraints[[1]]$properties$operator <- "both"
sumConstraints <- summary(constraints)
expect_is(sumConstraints, "data.frame")
expect_true(all(c("enabled", "timeStep", "equation") %in%
names(sumConstraints)))
})
-##delete study ----
-#unlink(studyPathS, recursive = TRUE)
# >= v800 ----
-#
+
opts <- antaresRead::setSimulationPath(studyPathSV8[1], "input")
test_that("test if exist data value file", {
@@ -40,7 +38,8 @@ test_that("test if exist data value file", {
testthat::expect_equal(class(bc), "bindingConstraints")
names_bc_test <- paste0(names(bc), ".txt")
- path_test_bc <- paste0(file.path(opts$inputPath, "bindingconstraints", names_bc_test))
+ path_test_bc <- paste0(file.path(opts$inputPath, "bindingconstraints",
+ names_bc_test))
# test if values files exists
testthat::expect_true(all(unlist(lapply(path_test_bc, file.exists))))
@@ -48,6 +47,142 @@ test_that("test if exist data value file", {
# >= v870 ----
-#
+# read latest version of empty study
+setup_study_empty(sourcedir_empty_study)
+opts_test_empty <- antaresRead::setSimulationPath(study_empty_latest_version,
+ "input")
+
+# read latest version study
+path_study_test <- grep(pattern = "87", x = studyPathSV8, value = TRUE)
+opts_study_test <- setSimulationPath(path_study_test, simulation = "input")
+
+## empty study test ----
+test_that("Read scenarised BC with empty study", {
+
+ bc <- readBindingConstraints(opts = opts_test_empty)
+
+ # test exception
+ testthat::expect_equal(bc, NULL)
+
+})
+
+## test object structure ----
+test_that("test object structure", {
+
+ bc <- readBindingConstraints(opts = opts_study_test)
+
+ # test class object
+ testthat::expect_equal(class(bc), "bindingConstraints")
+
+ # test structure object
+ # every BC must have 3 named elements
+ nb_items <- unlist(lapply(bc, length))
+
+ testthat::expect_true(all(nb_items %in% 3))
+
+ # every BC must be named
+ names_items <- unlist(lapply(bc, names))
+
+ testthat::expect_true(all(names_items
+ %in% c("properties", "coefs", "values")))
+})
+
+# test values / operator ----
+test_that("data verification based on the 'operator' property", {
+ bc <- readBindingConstraints(opts = opts_study_test)
+
+ # test values
+ # one or two txt files are associated with one BC
+ # only "both" values have two .txt files
+ bc_prop <- lapply(bc, `[[`, "properties")
+ bc_id <- lapply(bc_prop, `[[`, "id")
+ bc_operator <- lapply(bc_prop, `[[`, "operator")
+
+ # list all values
+ path_bc_values <- file.path(opts_study_test$inputPath,
+ "bindingconstraints")
+ list_values_bc <- list.files(path = path_bc_values, pattern = ".txt")
+
+ # test "less" (one file must be present)
+ index <- bc_operator %in% "less"
+ id_bc <- names(bc_operator[index])
+
+ nb_file_present <- length(grep(pattern = id_bc,
+ x = list_values_bc))
+
+ testthat::expect_true(nb_file_present %in% 1)
+
+ # test "greater" (one file must be present)
+ index <- bc_operator %in% "greater"
+ id_bc <- names(bc_operator[index])
+
+ nb_file_present <- length(grep(pattern = id_bc,
+ x = list_values_bc))
+
+ testthat::expect_true(nb_file_present %in% 1)
+
+ # test "equal" (one file must be present)
+ index <- bc_operator %in% "equal"
+ id_bc <- names(bc_operator[index])
+
+ nb_file_present <- length(grep(pattern = id_bc,
+ x = list_values_bc))
+
+ testthat::expect_true(nb_file_present %in% 1)
+
+ # test "both" (two file must be present)
+ index <- bc_operator %in% "both"
+ id_bc <- names(bc_operator[index])
+
+ nb_file_present <- length(grep(pattern = id_bc,
+ x = list_values_bc))
+
+ testthat::expect_true(nb_file_present %in% 2)
+
+})
+
+## test default values ----
+test_that("test if default values are well returned", {
+ bc <- readBindingConstraints(opts = opts_study_test)
+
+ # if txt values files are empty, default value is returned
+
+ # check empty values files
+ # list all values
+ path_bc_values <- file.path(opts_study_test$inputPath,
+ "bindingconstraints")
+
+ list_path_values_bc <- list.files(path = path_bc_values,
+ pattern = ".txt",
+ full.names = TRUE)
+ list_values_bc <- list.files(path = path_bc_values, pattern = ".txt")
+
+ # check empty size
+ is_value_null <- file.size(list_path_values_bc) %in% 0
+
+ list_values_bc_null <- list_values_bc[is_value_null]
+
+ # check bindings concerned
+ list_null_values <- lapply(names(bc),
+ grepl,
+ x= list_values_bc_null)
+
+ is_true_null <- unlist(lapply(list_null_values,
+ all))
+
+ bc_default_values <- bc[is_true_null]
+
+ # two data frames are returned for "both" case
+ less_values_default <- bc_default_values[[names(bc_default_values)]]$values$less
+ testthat::expect_true(sum(less_values_default) %in% 0)
+
+ greater_values_default <- bc_default_values[[names(bc_default_values)]]$values$greater
+ testthat::expect_true(sum(greater_values_default) %in% 0)
+
+ # test if length of default values are ok with timestep
+ # daily => 364
+ testthat::expect_true(dim(bc_default_values[[names(bc_default_values)]]$values$greater)[1]
+ %in% 364)
+ })