diff --git a/NEWS.md b/NEWS.md index 81a956fc..5bde60e1 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 : diff --git a/R/setSimulationPath.R b/R/setSimulationPath.R index 5df538e3..7967ace4 100644 --- a/R/setSimulationPath.R +++ b/R/setSimulationPath.R @@ -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. @@ -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 @@ -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)) } @@ -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)) + } +} diff --git a/R/zzz.R b/R/zzz.R index e1a7f4da..b2d34dec 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -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 ------------------------------------# diff --git a/man/setSimulationPath.Rd b/man/setSimulationPath.Rd index 2045eead..f085a136 100644 --- a/man/setSimulationPath.Rd +++ b/man/setSimulationPath.Rd @@ -62,8 +62,11 @@ each Monte-Carlo simulation.} \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. diff --git a/tests/testthat/test-setup.R b/tests/testthat/test-setSimulationPath.R similarity index 92% rename from tests/testthat/test-setup.R rename to tests/testthat/test-setSimulationPath.R index 42a6746a..06cfbf59 100644 --- a/tests/testthat/test-setup.R +++ b/tests/testthat/test-setSimulationPath.R @@ -2,6 +2,7 @@ context("Setup functions") +# v710---- sapply(studyPathS, function(studyPath){ suppressPackageStartupMessages(require(lubridate)) @@ -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") })