Skip to content

Commit

Permalink
Ant1777/dimbcgroup (#251)
Browse files Browse the repository at this point in the history
* setSimulationPath() updated with new private function to add meta data group dimension for binding constraints

* setSimulationPath() doc updated with new parameter
  • Loading branch information
berthetclement authored Jun 10, 2024
1 parent 2022889 commit 0e7628a
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 2 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ NEW FEATURES:
- new parameter **areas** to get desired clusters from selected areas.
- new parameter **thermalAvailabilities** to import time series.
* `readInputRES()` new parameter **areas** to get desired clusters from selected areas.
* `setSimulationPath()` return a new parameter `binding` (for studies >= v8.7.0).
It contains a table with group dimensions of time series for binding constraints.

BREAKING CHANGES :

Expand Down
64 changes: 63 additions & 1 deletion R/setSimulationPath.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,11 @@
#' \item{districtList}{Vector of the available districts.}
#' \item{linkList}{Vector of the available links.}
#' \item{areasWithClusters}{Vector of areas containing clusters.}
#' \item{areasWithResClusters}{Vector of areas containing clusters renewable.}
#' \item{areasWithSTClusters}{Vector of areas containing clusters storage (>=v8.6.0).}
#' \item{variables}{Available variables for areas, districts and links.}
#' \item{parameters}{Other parameters of the simulation.}
#' \item{binding}{Table of time series dimensions for each group (>=v8.7.0).}
#' \item{timeIdMin}{
#' Minimum time id of the simulation. It is generally equal to one but can
#' be higher if working on a subperiod.
Expand Down Expand Up @@ -178,7 +181,7 @@
#'
#' @rdname setSimulationPath
setSimulationPath <- function(path, simulation = NULL) {

if (missing(path)) {
if (exists("choose.dir", getNamespace("utils"))) {
# choose.dir is defined only on Windows
Expand Down Expand Up @@ -219,6 +222,8 @@ setSimulationPath <- function(path, simulation = NULL) {
# the simulation folder.
if (is.null(res$simPath)) {
res <- append(res, .getInputOptions(res))
if(res$antaresVersion>=870)
res <- append(res, .getDimBCGroups(res))
} else {
res <- append(res, .getSimOptions(res))
}
Expand Down Expand Up @@ -628,3 +633,60 @@ setSimulationPath <- function(path, simulation = NULL) {
data.table(link = character(), from = character(), to = character())
}
}

# >= v8.7.0 to have dimension of TS for binding constraints
.getDimBCGroups <- function(list_options){
# list files
bc_path <- file.path(list_options$inputPath, "bindingconstraints")
bc_all_files <- list.files(bc_path, full.names = TRUE)
vector_size <- file.size(bc_all_files)

# return NULL if no BC
if(sum(vector_size)==0)
return(NULL)
else{
# return NULL if no .txt files (no values)
search_values <- grepl(x = bc_all_files, pattern = ".txt")
if(!any(search_values))
return(NULL)

# keep only values size >0
bc_name_values_files <- gsub('(.*)_.*',
'\\1',
grep(x = list.files(bc_path),
pattern = ".txt",
value = TRUE))

df_info_files <- data.table(path = bc_all_files[search_values],
size = vector_size[search_values],
bc_name = bc_name_values_files)
df_info_files <- df_info_files[size>0,]

# extract name + group from .ini properties
properties_group <- readIniFile(file = bc_all_files[!search_values])

df_groups <- do.call("rbind",
lapply(properties_group, function(x){
data.table(x$id,
x$group)
}))
names(df_groups)<-c("bc_name", "name_group")

# merge information
df_groups <- merge(df_info_files, df_groups)

# read + dim values files
res <- sapply(df_groups$path, function(x){
file <- data.table::fread(file = x)
dim(file)[2]
})

df_groups$dim <- res

# filter df with only one group with dim > 1
df_groups <- unique(df_groups[, c("name_group", "dim")])
df_groups <- df_groups[dim>1]

return(list(binding = df_groups))
}
}
2 changes: 1 addition & 1 deletion R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ utils::globalVariables(
"NODU", "min.stable.power", "thermalPmin", "name", "value",
"Folder", "Mode", "Stats", "Name", "progNam", "mrgprice", "isLOLD_cum",
"...To", "upstream", "downstream", "LOLD", "LOLD_data", "LOLP", "warn_for_status",
"MRG. PRICE", "H. LEV", "V2", "V1")
"MRG. PRICE", "H. LEV", "V2", "V1", "size")
)

#----------------------------- HDF5 ------------------------------------#
Expand Down
3 changes: 3 additions & 0 deletions man/setSimulationPath.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

context("Setup functions")

# v710----
sapply(studyPathS, function(studyPath){

suppressPackageStartupMessages(require(lubridate))
Expand Down Expand Up @@ -176,4 +177,19 @@ test_that("Folder 'maps' is not interpreted as a study (#49)", {
})

}

test_that("No meta info binding study < 870", {
opts <- setSimulationPath(studyPath, "input")
expect_null(opts$binding)
})

})

# v870----
test_that("New meta data for group dimension of binding constraints", {
# read latest version study
path_study_test <- grep(pattern = "87", x = studyPathSV8, value = TRUE)
opts_study_test <- setSimulationPath(path_study_test, simulation = "input")

expect_is(opts_study_test$binding, "data.table")
})

0 comments on commit 0e7628a

Please sign in to comment.