From 23d8954b77e45515910273a8633574306e79f993 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Berthet?= Date: Wed, 24 Apr 2024 09:44:03 +0200 Subject: [PATCH] Release/cran261 (#244) * update github workflow * Read cluster desc bugfix when cluster exist (#242) * fix bug readClusterDesc when no cluster + cover ST and RES case * add test (init test for thermal + res) * cleaning * fix cran NOTE causing by bad url in doc + bad doc --- NEWS.md | 2 +- R/aggregateResult.R | 18 +++------ R/readClusterDesc.R | 32 +++++++-------- man/aggregatate_mc_all.Rd | 6 +-- man/aggregatate_mc_all_old.Rd | 57 --------------------------- tests/testthat/test-readClusterDesc.R | 40 ++++++++++++++++++- vignettes/antaresH5.Rmd | 1 - 7 files changed, 63 insertions(+), 93 deletions(-) delete mode 100644 man/aggregatate_mc_all_old.Rd diff --git a/NEWS.md b/NEWS.md index 4cd70501..9eb17f4b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,6 @@ > Copyright © 2016 RTE Réseau de transport d’électricité -# antaresRead 2.6.1 (devlopment) +# antaresRead 2.6.1 BUGFIXES : diff --git a/R/aggregateResult.R b/R/aggregateResult.R index b5efa718..b215e452 100644 --- a/R/aggregateResult.R +++ b/R/aggregateResult.R @@ -4,12 +4,10 @@ #' #' @param opts \code{list} of simulation parameters returned by the function \link{setSimulationPath} #' @param nbcl \code{numeric} Number of parralel process -#' @param verbose \code{numeric} show log in console. Defaut to 1 -#' \itemize{ -#' \item{0}{ : No log} -#' \item{1}{ : Short log} -#' \item{2}{ : Long log} -#'} +#' @param verbose \code{numeric} show log in console. Defaut to 1 +#' - 0 : No log +#' - 1 : Short log +#' - 2 : Long log #' @param timestep \code{character} antares timestep #' @param writeOutput \code{boolean} write result or not. #' @param mcWeights \code{numeric} vector of weigth for mcYears. @@ -689,12 +687,6 @@ parAggregateMCall <- function(opts, } #' @param opts \code{list} of simulation parameters returned by the function \link{setSimulationPath} -#' @param verbose \code{numeric} show log in console. Defaut to 1 -#' \itemize{ -#' \item{0}{ : No log} -#' \item{1}{ : Short log} -#' \item{2}{ : Long log} -#'} #' @param timestep \code{character} antares timestep #' @param writeOutput \code{boolean} write result or not. #' @param mcWeights \code{numeric} vector of weigth for mcYears. @@ -1533,7 +1525,7 @@ pmax.fast <- function(k,x) (x+k + abs(x-k))/2 #' #' @import data.table #' -#' @rdname aggregatate_mc_all_old +#' @noRd #' #' @examples #' \dontrun{ diff --git a/R/readClusterDesc.R b/R/readClusterDesc.R index 71caec89..dad0515e 100644 --- a/R/readClusterDesc.R +++ b/R/readClusterDesc.R @@ -107,8 +107,9 @@ readClusterSTDesc <- function(opts = simOptions()) { path <- file.path(opts$inputPath, dir) columns <- .generate_columns_by_type(dir = dir) + api_study <- is_api_study(opts) - if(opts$typeLoad == 'api'){ + if(api_study){ jsoncld <- read_secure_json(paste0(path, "&depth=4"), token = opts$token, timeout = opts$timeout, config = opts$httr_config) res <- rbindlist(mapply(function(X1, Y1){ @@ -125,13 +126,6 @@ readClusterSTDesc <- function(opts = simOptions()) { clusters[, .SD, .SDcols = order(names(clusters))] },jsoncld, names(jsoncld), SIMPLIFY = FALSE), fill = TRUE) - if(length(res) == 0){ - warning("No cluster description available.", call. = FALSE) - res <- setNames(data.table(matrix(nrow = 0, ncol = 2 + length(columns))), c("area", "cluster", columns)) - }else{ - res <- res[, .SD, .SDcols = c("area", "name", "group", names(res)[!names(res) %in%c("area", "name", "group")])] - } - }else{ @@ -149,15 +143,21 @@ readClusterSTDesc <- function(opts = simOptions()) { clusters[, c(ncol(clusters), 1:(ncol(clusters) - 1))] }) - if(length(res) == 0){ - warning("No cluster description available.", call. = FALSE) - res <- setNames(data.table(matrix(nrow = 0, ncol = 2 + length(columns))), c("area", "cluster", columns)) - }else{ - res <- as.data.table(res) - setnames(res, "name", "cluster") - - res$cluster <- as.factor(tolower(res$cluster)) + } + + if(length(res) == 0){ + mandatory_cols <- c("area","cluster") + warning("No cluster description available.", call. = FALSE) + res <- setNames(data.table(matrix(nrow = 0, ncol = length(mandatory_cols) + length(columns))), c(mandatory_cols, columns)) + }else{ + if(api_study){ + mandatory_cols <- c("area", "name", "group") + additional_cols <- setdiff(colnames(res),mandatory_cols) + res <- res[, .SD, .SDcols = c(mandatory_cols, additional_cols)] } + res <- as.data.table(res) + setnames(res, "name", "cluster") + res$cluster <- as.factor(tolower(res$cluster)) } res diff --git a/man/aggregatate_mc_all.Rd b/man/aggregatate_mc_all.Rd index d218c60c..4b4a1bc4 100644 --- a/man/aggregatate_mc_all.Rd +++ b/man/aggregatate_mc_all.Rd @@ -37,9 +37,9 @@ aggregateResult( \item{verbose}{\code{numeric} show log in console. Defaut to 1 \itemize{ -\item{0}{ : No log} -\item{1}{ : Short log} -\item{2}{ : Long log} +\item 0 : No log +\item 1 : Short log +\item 2 : Long log }} \item{timestep}{\code{character} antares timestep} diff --git a/man/aggregatate_mc_all_old.Rd b/man/aggregatate_mc_all_old.Rd deleted file mode 100644 index 4b5f414a..00000000 --- a/man/aggregatate_mc_all_old.Rd +++ /dev/null @@ -1,57 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/aggregateResult.R -\name{aggregateResult_old} -\alias{aggregateResult_old} -\alias{parAggregateMCall_old} -\title{Creation of Mc_all (only antares > V6)} -\usage{ -aggregateResult_old( - opts, - verbose = 1, - filtering = FALSE, - selected = NULL, - timestep = c("annual", "daily", "hourly", "monthly", "weekly"), - writeOutput = FALSE, - mcWeights = NULL, - mcYears = NULL -) - -parAggregateMCall_old( - opts, - nbcl = 8, - verbose = 1, - timestep = c("annual", "daily", "hourly", "monthly", "weekly"), - writeOutput = TRUE, - mcWeights = NULL, - mcYears = NULL -) -} -\arguments{ -\item{opts}{\code{list} of simulation parameters returned by the function \link{setSimulationPath}} - -\item{verbose}{\code{numeric} see logs (1) or not (0)} - -\item{filtering}{\code{boolean} filtering control} - -\item{selected}{\code{list} named list (pass to antaresRead) : list(areas = 'a', links = 'a - e')} - -\item{timestep}{\code{character} antares timestep} - -\item{writeOutput}{\code{boolean} write result or not.} - -\item{mcWeights}{\code{numeric} vector of weigth for mcYears.} - -\item{mcYears}{\code{numeric} mcYears to load.} - -\item{nbcl}{\code{numeric} Number of parralel process} -} -\description{ -Creation of Mc_all (only antares > V6) -} -\examples{ -\dontrun{ - aggregateResult(opts) - -} - -} diff --git a/tests/testthat/test-readClusterDesc.R b/tests/testthat/test-readClusterDesc.R index f62dd764..c7d14398 100644 --- a/tests/testthat/test-readClusterDesc.R +++ b/tests/testthat/test-readClusterDesc.R @@ -1,9 +1,42 @@ -## v860 ---- +# v860 ---- path_study_test <- grep(pattern = "86", x = studyPathSV8, value = TRUE) opts_study_test <- setSimulationPath(path_study_test, simulation = "input") +#minimal columns +mandatory_cols <- c("area","cluster") + +## Thermal ---- +test_that("test read cluster", { + + # function setSimulationPath() provide areas names with st-storage clusters + areas <- opts_study_test$areasWithClusters + + # read clusters informations + input <- readClusterDesc() + + # tests + testthat::expect_true("data.table" %in% class(input)) + testthat::expect_true(all(areas %in% unique(readClusterDesc()$area))) + testthat::expect_true(all(mandatory_cols %in% colnames(input))) + testthat::expect_true(nrow(input) == length(input$cluster)) + +}) + +## Renewables ---- +test_that("test read cluster renewables", { + + # function setSimulationPath() provide areas names with st-storage clusters + areas_res <- opts_study_test$areasWithRESClusters + + #Study not renewables (need activateRES() from antaresEditObject) + expect_error(readClusterResDesc(), + regexp = "readClusterDesc is available only on studies with 'renewable-generation-modelling'") + +}) + +## st-storage ---- test_that("test read cluster st-storage v860", { # function setSimulationPath() provide areas names with st-storage clusters @@ -14,5 +47,8 @@ test_that("test read cluster st-storage v860", { # tests testthat::expect_true("data.table" %in% class(input_st)) - testthat::expect_true(areas_st %in% unique(readClusterSTDesc()$area)) + testthat::expect_true(all(areas_st %in% unique(readClusterSTDesc()$area))) + testthat::expect_true(all(mandatory_cols %in% colnames(input_st))) + testthat::expect_true(nrow(input_st) == length(input_st$cluster)) + }) diff --git a/vignettes/antaresH5.Rmd b/vignettes/antaresH5.Rmd index ebe1ced5..ee292c1a 100644 --- a/vignettes/antaresH5.Rmd +++ b/vignettes/antaresH5.Rmd @@ -35,7 +35,6 @@ BiocManager::install("rhdf5") An other solution is to install manually these two packages from zip file. They are available here : https://bioconductor.org/packages/release/bioc/html/zlibbioc.html -http://bioconductor.org/packages/release/bioc/html/rhdf5.html ## Avantages of h5 transformation