From 9493f650726a6a31f2bfb37071f2bbf1f34a08f7 Mon Sep 17 00:00:00 2001 From: berthetclement Date: Tue, 25 Jun 2024 17:01:41 +0200 Subject: [PATCH] delete package rhdf5 from suggests and delete all functions who use it + delete tests --- DESCRIPTION | 1 - NAMESPACE | 5 - R/h5_antaresReadH5.R | 980 ------------------- R/h5_readInputs.R | 54 - R/h5_setSimulationPathH5.R | 77 -- R/h5_timeManagement.R | 133 --- R/h5_transformData.R | 36 - R/h5_writeData.R | 157 --- R/h5_writeH5ByYear.R | 492 ---------- R/h5utils.R | 26 - R/readAntares.R | 50 +- R/readClusterDesc.R | 2 +- R/readLayout.R | 14 +- R/zzz.R | 290 +++--- man/dot-getOptionsH5.Rd | 15 - man/dot-h5ReadAntares.Rd | 71 -- man/dot-writeAntaresH5Fun.Rd | 32 - man/isH5Opts.Rd | 14 - man/writeAntaresH5.Rd | 130 --- revdep/README.md | 27 +- revdep/cran.md | 7 +- revdep/failures.md | 74 +- revdep/problems.md | 74 +- tests/testthat/helper_init.R | 96 +- tests/testthat/test-h5ReadAntares.R | 175 ---- tests/testthat/test-h5_nodata.R | 14 - tests/testthat/test-h5_readInputs.R | 42 - tests/testthat/test-h5_setSimulationPathH5.R | 19 - tests/testthat/test-h5_write.R | 61 -- tests/testthat/test-viewAntares.R | 86 +- 30 files changed, 439 insertions(+), 2815 deletions(-) delete mode 100644 R/h5_antaresReadH5.R delete mode 100644 R/h5_readInputs.R delete mode 100644 R/h5_setSimulationPathH5.R delete mode 100644 R/h5_timeManagement.R delete mode 100644 R/h5_transformData.R delete mode 100644 R/h5_writeData.R delete mode 100644 R/h5_writeH5ByYear.R delete mode 100644 R/h5utils.R delete mode 100644 man/dot-getOptionsH5.Rd delete mode 100644 man/dot-h5ReadAntares.Rd delete mode 100644 man/dot-writeAntaresH5Fun.Rd delete mode 100644 man/isH5Opts.Rd delete mode 100644 man/writeAntaresH5.Rd delete mode 100644 tests/testthat/test-h5ReadAntares.R delete mode 100644 tests/testthat/test-h5_nodata.R delete mode 100644 tests/testthat/test-h5_readInputs.R delete mode 100644 tests/testthat/test-h5_setSimulationPathH5.R delete mode 100644 tests/testthat/test-h5_write.R diff --git a/DESCRIPTION b/DESCRIPTION index b7369c9a..08d8dd60 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -44,7 +44,6 @@ Imports: lifecycle, assertthat Suggests: - rhdf5 (>= 2.24.0), testthat, covr, knitr, diff --git a/NAMESPACE b/NAMESPACE index fff146e5..2dd11f06 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -21,9 +21,6 @@ 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) @@ -41,7 +38,6 @@ export(getGeographicTrimming) export(getIdCols) export(getLinks) export(hvdcModification) -export(isH5Opts) export(mergeDigests) export(parAggregateMCall) export(ponderateMcAggregation) @@ -71,7 +67,6 @@ export(setTimeoutAPI) export(showAliases) export(simOptions) export(viewAntares) -export(writeAntaresH5) export(writeDigest) import(bit64) import(data.table) diff --git a/R/h5_antaresReadH5.R b/R/h5_antaresReadH5.R deleted file mode 100644 index 3624cab1..00000000 --- a/R/h5_antaresReadH5.R +++ /dev/null @@ -1,980 +0,0 @@ -#' Read data -#' -#' @param path {character} path of h5file to load -#' @param areas see \link[antaresRead]{readAntares} -#' @param links see \link[antaresRead]{readAntares} -#' @param clusters see \link[antaresRead]{readAntares} -#' @param districts see \link[antaresRead]{readAntares} -#' @param mcYears see \link[antaresRead]{readAntares} -#' @param timeStep see \link[antaresRead]{readAntares} -#' @param select see \link[antaresRead]{readAntares} -#' @param showProgress see \link[antaresRead]{readAntares} -#' @param simplify see \link[antaresRead]{readAntares} -#' @param misc see \link[antaresRead]{readAntares} -#' @param thermalAvailabilities see \link[antaresRead]{readAntares} -#' @param hydroStorage see \link[antaresRead]{readAntares} -#' @param hydroStorageMaxPower see \link[antaresRead]{readAntares} -#' @param reserve see \link[antaresRead]{readAntares} -#' @param linkCapacity see \link[antaresRead]{readAntares} -#' @param mustRun see \link[antaresRead]{readAntares} -#' @param thermalModulation see \link[antaresRead]{readAntares} -#' @param perf \code{boolean}, eval performance during developpement time, to remove -#' -#' @import parallel plyr -#' -#' @keywords internal -#' @export -# Need to be export for antaresViz -.h5ReadAntares <- function(path, areas = NULL, links = NULL, clusters = NULL, - districts = NULL, mcYears = NULL, - misc = FALSE, thermalAvailabilities = FALSE, - hydroStorage = FALSE, hydroStorageMaxPower = FALSE, reserve = FALSE, - linkCapacity = FALSE, mustRun = FALSE, thermalModulation = FALSE, - timeStep = "hourly", select = NULL, showProgress = TRUE, - simplify = TRUE, perf = FALSE){ - - .requireRhdf5_Antares() - - if(!is.list(select)) - { - if(is.null(select)) - { - if(!is.null(areas)) - { - if(areas[1] == "all"){ - select <- c("all", select) - }} - - if(!is.null(links)) - { - if(links[1] == "all"){ - select <- c("all", select) - }} - - if(!is.null(clusters)) - { - if(clusters[1] == "all"){ - select <- c("all", select) - }} - if(!is.null(districts)) - { - if(districts[1] == "all"){ - select <- c("all", select) - }} - }else{ - if("allAreas" %in% select){ - select <- c(select, pkgEnvAntareasH5$varAreas) - } - - if("allLinks" %in% select){ - select <- c(select, pkgEnvAntareasH5$varLinks) - } - - if("allDistricts" %in% select){ - select <- c(select, pkgEnvAntareasH5$varDistricts) - } - } - } - - - if(!file.exists(path)){ - stop(paste0("File ", path, " not exist.")) - } - - if(perf){ - Beg <- Sys.time() - } - - ctrlselectlist <- FALSE - if(!is.list(select)){ - ctrlselectlist <- TRUE - } - - - if(ctrlselectlist){ - if(misc){ - select <- c(select, "misc") - } - if(thermalAvailabilities){ - select <- c(select, "thermalAvailabilities") - } - if(hydroStorage){ - select <- c(select, "hydroStorage") - } - if(hydroStorageMaxPower){ - select <- c(select, "hydroStorageMaxPower") - } - if(reserve){ - select <- c(select, "reserve") - } - if(linkCapacity){ - select <- c(select, "linkCapacity") - } - if(mustRun){ - select <- c(select, "mustRun") - } - if(thermalModulation){ - select <- c(select, "thermalModulation") - } - } - - - if(is.null(select)){ - select <- "all" - } - reqInfos <- .giveInfoRequest(select = select, - areas = areas, - links = links, - clusters = clusters, - clustersRes = NULL, - districts = districts, - mcYears = mcYears) - - reqInfos$clustersRes <- NULL - - select <- reqInfos$select - if(ctrlselectlist){ - select$clusters <- c(pkgEnvAntareasH5$varClusters, select$areas) - } - - - unselect <- reqInfos$unselect - - - - allCompute <- pkgEnv$allCompute - computeAdd <- unlist(select)[unlist(select) %in% allCompute] - computeAdd <- unique(computeAdd) - if(length(computeAdd) > 0){ - for(i in computeAdd) - { - assign(i, TRUE) - } - } - - for(i in allCompute){ - if(get(i)){ - select <- .addColumns(select, i) - } - } - - select <- sapply(names(select), function(X){ - as.vector(unlist(sapply(select[[X]], function(Y){ - if(is.null(pkgEnvAntareasH5$varAliasCreated[[Y]][[X]])){ - Y - }else{ - pkgEnvAntareasH5$varAliasCreated[[Y]][[X]] - } - }))) - }, simplify = FALSE) - - ctrl <- FALSE - if(!is.null(select$areas)) - { - if(select$areas[1] == "all"){ - ctrl <- TRUE - } - } - if(is.null(select$areas) | ctrl) - { - select$areas <- c(pkgEnvAntareasH5$varAreas,select$areas) - } - - ctrl <- FALSE - if(!is.null(select$links)) - { - if(select$links[1] == "all"){ - ctrl <- TRUE - } - } - - if(is.null(select$links)| ctrl) - { - select$links <- c(pkgEnvAntareasH5$varLinks, select$links) - } - - ctrl <- FALSE - if(!is.null(select$districts)) - { - if(select$districts[1] == "all"){ - ctrl <- TRUE - } - } - - if(is.null(select$districts) | ctrl) - { - select$districts <- c(pkgEnvAntareasH5$varDistricts, select$districts ) - } - ctrl <- FALSE - if(!is.null(select$clusters)) - { - if(select$clusters[1] == "all"){ - ctrl <- TRUE - } - } - - if(is.null(select$clusters) | ctrl) - { - select$clusters <- c(pkgEnvAntareasH5$varClusters, select$clusters ) - } - - - for(i in names(select)){ - if(length(which(! select[[i]] %in% unselect[[i]])) > 0) - { - select[[i]] <- select[[i]][which(! select[[i]] %in% unselect[[i]])] - } - } - - for(i in 1:length(select)){ - if(length(select[[i]]) > 1){ - if(length(which(select[[i]] == "all")) > 0){ - select[[i]] <- select[[i]][-c(which(select[[i]] == "all"))] - } - } - } - - ##End give select - - areas <- reqInfos$areas - links <- reqInfos$links - clusters <- reqInfos$clusters - districts <- reqInfos$districts - mcYears <- reqInfos$mcYears - synthesis <- reqInfos$synthesis - - synthesis <- is.null(mcYears) - - GP <- timeStep - - ##Open connection to h5 file - fid <- rhdf5::H5Fopen(path) - - #Load attibutes - attrib <- .loadAttributes(fid, timeStep) - - if(is.null(mcYears)){ - mcType <- "mcAll" - mcYears <- "mcAll" - }else{ - mcType <- "mcInd" - } - - ##Load areas - listOut <- list() - areas <- .loadAreas(areas = areas, - fid = fid, - select = select$areas, - mcYears = mcYears, - GP = GP, - mcType = mcType, - synthesis = synthesis, - simplify = simplify, - attrib = attrib) - # if("virtualNodes" %in% names(attrib)){ - # attr(areas, "virtualNodes") <- attrib$virtualNodes - # } - # - if(!is.null(areas)){ - listOut$areas <- areas - rm(areas) - } - - links <- .loadLinks(links = links, - fid = fid, - select = select$links, - mcYears = mcYears, - GP = GP, - mcType = mcType, - synthesis = synthesis, - simplify = simplify, - attrib = attrib) - - - if(!is.null(links)){ - listOut$links <- links - rm(links) - } - - districts <- .loadDistricts(districts = districts, - fid = fid, - select = select$districts, - mcYears = mcYears, - GP = GP, - mcType = mcType, - synthesis = synthesis, - simplify = simplify, - attrib = attrib) - - if(!is.null(districts)){ - listOut$districts <- districts - rm(districts) - } - clusters <- .loadClusters(clusters = clusters, - fid = fid, - select = select$clusters, - mcYears = mcYears, - GP = GP, - mcType = mcType, - synthesis = synthesis, - simplify = simplify, - attrib = attrib) - - if(!is.null(clusters)){ - listOut$clusters <- clusters - rm(clusters) - } - - if(length(listOut) == 1){ - - if(perf){ - TotalTime <-Sys.time() - Beg - cat(paste0("Time for loading : ", round(TotalTime, 3), "\n")) - objectS <- utils::object.size(listOut)/1024^2 - cat(paste0("Size of object loaded : ", round(objectS, 1), "Mo\n")) - cat(paste0("Mo/s loaded : ",round(as.numeric(objectS)/ as.numeric(TotalTime),1), "\n")) - dtaloded <- sum(unlist(lapply(listOut, function(X)prod(dim(X))))) - cat(paste0("Data loaded/s : ", round(dtaloded/ as.numeric(TotalTime) / 1000000, 2), " Millions", "\n")) - } - - listOut[[1]] - }else{ - listOut <- .addClassAndAttributes(listOut, synthesis, timeStep, - attrib$opts, simplify) - if("virtualNodes" %in% names(attrib)){ - attr(listOut, "virtualNodes") <- attrib$virtualNodes - } - - if(perf){ - TotalTime <-Sys.time() - Beg - cat(paste0("Time for loading : ", round(TotalTime, 3), "\n")) - objectS <- utils::object.size(listOut)/1024^2 - cat(paste0("Size of object loaded : ", round(objectS, 1), "Mo\n")) - cat(paste0("Mo/s loaded : ",round(as.numeric(objectS)/ as.numeric(TotalTime),1), "\n")) - dtaloded <- sum(unlist(lapply(listOut, function(X)prod(dim(X))))) - cat(paste0("Data loaded/s : ", round(dtaloded/ as.numeric(TotalTime) / 1000000, 2), " Millions", "\n")) - } - - listOut - } -} - - - - -#' Transform array to data.table -#' -#' @param array \code{array}, array to transform -#' -#' @return data.table -#' -#' @noRd -.arrayToDataTable <- function(array) -{ - dim <- 2 - ecraseDim <- dim(array)[dim] - dimS <- 1:length(dim(array)) - dimNot <- dimS[-dim] - prodDim <- prod(dim(array)[dimNot]) - arrayL <- list() - for(i in 1:dim(array)[2]){ - arrayL[[i]] <- unlist(array[,i,,]) - } - setattr(arrayL, "names", paste("V", 1:ecraseDim, sep = "")) - setattr(arrayL, "row.names", .set_row_names(prodDim)) - setattr(arrayL, "class", c("data.table", "data.frame")) - alloc.col(arrayL) -} - -#' Load antares simulation data -#' -#' @param fid \code{H5IdComponent} id of h5 file open which \link{rhdf5::H5Fopen} -#' @param index \code{list} index of data to load -#' @param GP \code{character} name of group to load -#' -#' @noRd -.optimH5Read <- function(fid, index = NULL, GP){ - - .requireRhdf5_Antares() - - did <- rhdf5::H5Dopen(fid, GP) - if(is.null(index)){ - return(rhdf5::H5Dread(did)) - }else{ - - h5spaceFile <- rhdf5::H5Dget_space(did) - maxSize <- rev(rhdf5::H5Sget_simple_extent_dims(h5spaceFile)$size) - - len <- length(maxSize) - K <- sapply(len:1, function(X){ - if(is.null(index[[len-X + 1]])){ - seq_len(maxSize[X]) - }else{index[[len-X + 1]]}} - ) - size <- unlist(lapply(K,length)) - h5spaceMem = rhdf5::H5Screate_simple(size) - W <- rhdf5::H5Screate_simple(rhdf5::H5Sselect_index(h5spaceFile, as.list(K)))@ID - - rhdf5::H5Dread(did, h5spaceFile = h5spaceFile, - h5spaceMem = h5spaceMem) - } - -} - -#' Give request stucture -#' -#' @param type \code{character} type of request, must be area, link, cluster or district -#' @param selectedRow \code{character} selectoin on raw (country, link, cluster ....) -#' @param selectedCol \code{character} columns to select -#' @param fid \code{H5IdComponent} id of h5 file open which \link[rhdf5]{H5Fopen} -#' @param GP \code{character} name of data.frame to load -#' @param mcType \code{character}, must be mcInd or mcAll -#' @param mcYears \code{numeric or character} mcYears to laod -#' -#' @noRd -.makeStructure <- function(type = "area", selectedRow, - selectedCol, fid, GP, mcType, mcYears){ - if(is.null(selectedCol)){ - selectedCol <- "all" - } - - typeS <- paste0(type, "s") - struct <- .getstructure(fid, paste0(GP, "/", typeS, "/", mcType, "/structure")) - - compname <- NULL - if(type == "cluster"){ - splitClust <- strsplit(struct[[type]], "/") - clusterClean <- unlist(lapply(splitClust, function(X){X[1]})) - struct[[type]] <- clusterClean - compname <- unlist(lapply(splitClust, function(X){X[2]})) - - } - - if(selectedRow[1] == "all"){ - indexType <- NULL - Name <- struct[[type]] - }else{ - indexType <- which(struct[[type]] %in% selectedRow) - Name <- struct[[type]][indexType] - if(type == "cluster"){ - compname <- compname[indexType] - } - } - if(selectedCol[1] == "all"){ - indexVar <- NULL - varKeep <- struct$variable - }else{ - indexVar <- which(struct$variable %in% selectedCol) - indexVar <- unique(c(1, indexVar)) - varKeep <- struct$variable[indexVar] - } - if(mcYears[1] == "all"){ - indexMC <- NULL - mcyLoad <- struct$mcYear - }else{ - if(mcYears[1] == "mcAll"){ - indexMC <- NULL - mcyLoad <- struct$mcYear - }else{ - indexMC <- which(struct$mcYear %in% mcYears) - mcyLoad <- struct$mcYear[indexMC] - } - } - return(list(Name = Name, varKeep = varKeep, index = list(NULL, indexVar, indexType, indexMC), - mcyLoad = mcyLoad, compname = compname)) -} - -#' Load areas -#' -#' @param areas \code{character}, area(s) to load -#' @param fid \code{H5IdComponent} id of h5 file open which \link[rhdf5]{H5Fopen} -#' @param select \code{character} columns to select -#' @param mcYears \code{numeric or character} mcYears to load -#' @param GP \code{character} name of data.frame to load -#' @param mcType \code{character}, must be mcInd or mcAll -#' @param synthesis \code{boolean} -#' @param simplify \code{boolean} -#' @param attrib \code{list} -#' -#' @noRd -#' -#' @importFrom stats setNames -.loadAreas <- function(areas, - fid, - select, - mcYears, - GP, - mcType, - synthesis, - simplify, - attrib){ - - .requireRhdf5_Antares() - - if(!is.null(areas)){ - - if(rhdf5::H5Lexists(fid, paste0(GP, "/areas/", mcType, "/structure"))) - { - - struct <- .makeStructure(type = "area", - selectedRow = areas, - selectedCol = select, - fid = fid, - GP = GP, - mcType = mcType, - mcYears = mcYears) - - - if(all(unlist(lapply(struct$index, is.null)))){ - areas <- .optimH5Read(fid = fid, - GP = paste0(GP, "/areas/", mcType, "/data")) - }else{ - areas <- .optimH5Read(fid = fid, - index = struct$index, - GP = paste0(GP, "/areas/", mcType, "/data")) - - } - - - #Format array - areas <- .formatArray(data = areas, struct = struct, nameColumns = "area", mcType = mcType) - - #Add time - tim <- getAllDateInfoFromDate(fid, GP) - areas[, c(names(tim)) := lapply( - X = setNames(tim, names(tim)), - FUN = rep, length.out = .N - )] - - .addClassAndAttributes(areas, - synthesis, - attrib$timeStep, - attrib$opts, - simplify = simplify, type = "areas") - areas - }else{ - message("No data corresponding to your areas query.") - return(NULL) - } - }else{NULL}} - -#' Load links -#' -#' @param links \code{character}, link(s) to load -#' @param fid \code{H5IdComponent} id of h5 file open which \link[rhdf5]{H5Fopen} -#' @param select \code{character} columns to select -#' @param mcYears \code{numeric or character} mcYears to load -#' @param GP \code{character} name of data.frame to load -#' @param mcType \code{character}, must be mcInd or mcAll -#' @param synthesis \code{boolean} -#' @param simplify \code{boolean} -#' @param attrib \code{list} -#' -#' @noRd -#' -#' @importFrom stats setNames -.loadLinks <- function(links, - fid, - select, - mcYears, - GP, - mcType, - synthesis, - simplify, - attrib){ - - .requireRhdf5_Antares() - - ##Load links - if(!is.null(links)){ - - if(rhdf5::H5Lexists(fid, paste0(GP, "/links/", mcType, "/structure"))) - { - - - struct <- .makeStructure(type = "link", - selectedRow = links, - selectedCol = select, - fid = fid, - GP = GP, - mcType = mcType, - mcYears = mcYears) - - - if(all(unlist(lapply(struct$index, is.null)))){ - links <- .optimH5Read(fid = fid, - GP = paste0(GP, "/links/", mcType, "/data")) - }else{ - links <- .optimH5Read(fid = fid, - index = struct$index, - GP = paste0(GP, "/links/", mcType, "/data")) - - } - - #Format array - links <- .formatArray(data = links, struct = struct, nameColumns = "link", mcType = mcType) - - #Add time - tim <- getAllDateInfoFromDate(fid, GP) - links[, c(names(tim)) := lapply( - X = setNames(tim, names(tim)), - FUN = rep, length.out = .N - )] - - .addClassAndAttributes(links, - synthesis, - attrib$timeStep, - attrib$opts, - simplify = simplify, type = "links") - links - }else{ - message("No data corresponding to your links query.") - return(NULL) - } - }else{NULL} -} - - - -#' Load districts -#' -#' @param districts \code{character}, district(s) to load -#' @param fid \code{H5IdComponent} id of h5 file open which \link[rhdf5]{H5Fopen} -#' @param select \code{character} columns to select -#' @param mcYears \code{numeric or character} mcYears to load -#' @param GP \code{character} name of data.frame to load -#' @param mcType \code{character}, must be mcInd or mcAll -#' @param synthesis \code{boolean} -#' @param simplify \code{boolean} -#' @param attrib \code{list} -#' -#' @noRd -#' -#' @importFrom stats setNames -.loadDistricts <- function(districts, - fid, - select, - mcYears, - GP, - mcType, - synthesis, - simplify, - attrib){ - - .requireRhdf5_Antares() - - if(!is.null(districts)){ - - if(rhdf5::H5Lexists(fid, paste0(GP, "/districts/", mcType, "/structure"))) - { - - struct <- .makeStructure(type = "district", - selectedRow = districts, - selectedCol = select, - fid = fid, - GP = GP, - mcType = mcType, - mcYears = mcYears) - - - if(all(unlist(lapply(struct$index, is.null)))){ - districts <- .optimH5Read(fid = fid, - GP = paste0(GP, "/districts/", mcType, "/data")) - }else{ - districts <- .optimH5Read(fid = fid, - index = struct$index, - GP = paste0(GP, "/districts/", mcType, "/data")) - - } - - - districts <- .formatArray(data = districts, struct = struct, nameColumns = "district", mcType = mcType) - - tim <- getAllDateInfoFromDate(fid, GP) - - #Add time - districts[, c(names(tim)) := lapply( - X = setNames(tim, names(tim)), - FUN = rep, length.out = .N - )] - - .addClassAndAttributes(districts, - synthesis, - attrib$timeStep, - attrib$opts, - simplify = simplify, type = "districts") - districts - }else{ - message("No data corresponding to your districts query.") - return(NULL) - }}else{NULL} -} - - - - -#' Load clusters -#' -#' @param clusters \code{character}, cluster(s) to load -#' @param fid \code{H5IdComponent} id of h5 file open which \link{rhdf5::H5Fopen} -#' @param select \code{character} columns to select -#' @param mcYears \code{numeric or character} mcYears to load -#' @param GP \code{character} name of data.frame to load -#' @param mcType \code{character}, must be mcInd or mcAll -#' @param synthesis \code{boolean} -#' @param simplify \code{boolean} -#' @param attrib \code{list} -#' -#' @noRd -#' -#' @importFrom stats setNames -.loadClusters <- function(clusters, - fid, - select, - mcYears, - GP, - mcType, - synthesis, - simplify, - attrib){ - - .requireRhdf5_Antares() - - if(!is.null(clusters)){ - - if(rhdf5::H5Lexists(fid, paste0(GP, "/clusters/", mcType, "/structure"))) - { - - - struct <- .makeStructure(type = "cluster", - selectedRow = clusters, - selectedCol = select, - fid = fid, - GP = GP, - mcType = mcType, - mcYears = mcYears) - - if(all(unlist(lapply(struct$index, is.null)))){ - clusters <- .optimH5Read(fid = fid, - GP = paste0(GP, "/clusters/", mcType, "/data")) - }else{ - clusters <- .optimH5Read(fid = fid, - index = struct$index, - GP = paste0(GP, "/clusters/", mcType, "/data")) - - } - - - dimclusters <- dim(clusters) - clusters <- .formatArray(data = clusters, struct = struct, nameColumns = "area", mcType = mcType) - - compname <- as.factor(struct$compname) - clusters[, "cluster" := rep(rep(compname, each = dimclusters[1]), dimclusters[4])] - tim <- getAllDateInfoFromDate(fid, GP) - - #Add time - clusters[, c(names(tim)) := lapply( - X = setNames(tim, names(tim)), - FUN = rep, length.out = .N - )] - - .addClassAndAttributes(clusters, - synthesis, - attrib$timeStep, - attrib$opts, - simplify = simplify, type = "clusters") - clusters - }else{ - message("No data corresponding to your clusters query.") - return(NULL) - }}else{NULL} -} - -#' Add structure information to data -#' -#' @param data \code{data.table} data load -#' @param struct \code{list} -#' @param nameColumns \code{character} column names -#' @param mcType \code{character}, must be mcInd, and mcAll -#' -#' @noRd -.formatArray <- function(data, struct, nameColumns, mcType){ - dimData <- dim(data) - data <- .arrayToDataTable(data) - nameS <- struct$varKeep - names(data) <- nameS - dataName <- as.factor(struct$Name) - data[, c(nameColumns[1]):= rep(rep(dataName, each = dimData[1]), dimData[4])] - if(mcType == "mcInd") - { - data[, "mcYear" := rep(struct$mcyLoad, each = dimData[1] * dimData[3])] - } - - integerVariableS <- integerVariable[integerVariable%in%names(data)] - if("timeId" %in% names(data)){ - integerVariableS <- c("timeId", integerVariableS) - } - - if(length(integerVariableS)){ - ordervar <- names(data)[ match(integerVariableS, names(data))] - minmax <- data[,lapply(.SD, max), .SDcols = ordervar]>2*10^9 - ordervar <- colnames(minmax)[!minmax] - if(length(ordervar)>0) - { - data[,c(ordervar) := lapply(.SD, as.integer), .SDcols = ordervar] - } - } - data -} - -#' @param select select column(s) -#' @param var var to add -#' -#' @noRd -.addColumns <- function(select, var){ - if(is.null(select)){ - return(var) - } - if(is.list(select)){ - return(lapply(select, function(X){c(X, var)})) - } - c(var, select) -} - - -.loadAttributes <- function(fid, timeStep){ - - .requireRhdf5_Antares() - - if(rhdf5::H5Lexists(fid, paste0(timeStep, "/attrib"))) - { - - did <- rhdf5::H5Dopen(fid, paste0(timeStep, "/attrib")) - attrib <- unserialize(charToRaw(rhdf5::H5Dread(did))) - rhdf5::H5Dclose(did) - - if(!is.null(attrib$opts$linksDef)){ - attrib$opts$linksDef <- data.table(attrib$opts$linksDef) - } - if(!is.null(attrib$opts$districtsDef)){ - attrib$opts$districtsDef <- data.table(attrib$opts$districtsDef) - } - }else{ - attrib <- NULL - } - attrib -} - - -.getstructure <- function(fid, strgp){ - .requireRhdf5_Antares() - gid <- rhdf5::H5Gopen(fid, strgp) - data <- rhdf5::h5dump(gid) - rhdf5::H5Gclose(gid) - if(length(which(data$reCalcVar!="")) > 0) - { - data$reCalcVar <- data$reCalcVar[which(data$reCalcVar!="")] - data$variable <- c(data$variable, data$reCalcVar) - data$reCalcVar <- NULL - } - data -} - - -#' -#' #' Use to transform inputs arguments to be passable to reading function -#' #' -#' #' -#' #' -#' #' @param select Character vector containing the name of the columns to import. See \link{readAntares} for further information. -#' #' @param areas Vector containing the names of the areas to import. See \link{readAntares} for further information. -#' #' @param links Vector containing the names of the links to import. See \link{readAntares} for further information. -#' #' @param clusters Vector containing the names of the clusters to import. See \link{readAntares} for further information. -#' #' @param districts Vector containing the names of the districts to import. See \link{readAntares} for further information. -#' #' @param mcYears Index of the Monte-Carlo years to import. See \link{readAntares} for further information. -#' #' -#' #' @return \code{list} -#' #' \itemize{ -#' #' \item select -#' #' \item areas -#' #' \item links -#' #' \item clusters -#' #' \item districts -#' #' \item mcYears -#' #' \item synthesis -#' #' \item computeAdd -#' #' } -#' #' -#' #' @noRd -#' .giveInfoRequest <- function(select, -#' areas, -#' links, -#' clusters, -#' districts, -#' mcYears){ -#' -#' if (!is.list(select)) select <- list(areas = select, links = select, districts = select) -#' ##Get unselect columns (by - operator) -#' unselect <- lapply(select, function(X){ -#' minusColumns <- grep("^-", X) -#' if(length(minusColumns)>0) -#' { -#' uns <- X[minusColumns] -#' gsub("^-", "", uns) -#' }else{ -#' NULL -#' } -#' }) -#' -#' ##Remove unselect columns -#' select <- lapply(select, function(X){ -#' minusColumns <- grep("^-", X) -#' if(length(minusColumns) > 0){ -#' X[-c(minusColumns)] -#' }else{ -#' X -#' } -#' }) -#' -#' -#' # Aliases for groups of variables -#' select <- llply(select, function(x) { -#' for (alias in names(pkgEnv$varAliases)) { -#' if (tolower(alias) %in% tolower(x)) x <- append(x, pkgEnv$varAliases[[alias]]$select) -#' } -#' x -#' }) -#' -#' allCompute <- pkgEnv$allCompute -#' computeAdd <- allCompute[allCompute%in%unlist(select)] -#' -#' if ("areas" %in% unlist(select) & is.null(areas)) areas <- "all" -#' if ("links" %in% unlist(select) & is.null(links)) { -#' if (!is.null(areas)) links <- getLinks(getAreas(areas, regexpSelect = FALSE)) -#' else links <- "all" -#' } -#' if ("clusters" %in% unlist(select) & is.null(clusters)) { -#' if (!is.null(areas)) clusters <- areas -#' else clusters <- "all" -#' } -#' if ("mcYears" %in% unlist(select) & is.null(mcYears)) mcYears <- "all" -#' -#' # If all arguments are NULL, import all areas -#' if (is.null(areas) & is.null(links) & is.null(clusters) & is.null(districts)) { -#' areas <- "all" -#' } -#' -#' # Check arguments validity. The function .checkArgs is defined below -#' synthesis <- is.null(mcYears) -#' -#' return(list(select = select, -#' areas = areas, -#' links = links, -#' clusters = clusters, -#' districts = districts, -#' mcYears = mcYears, -#' synthesis = synthesis, -#' computeAdd = computeAdd, -#' unselect = unselect)) -#' } - diff --git a/R/h5_readInputs.R b/R/h5_readInputs.R deleted file mode 100644 index 4d0eed9b..00000000 --- a/R/h5_readInputs.R +++ /dev/null @@ -1,54 +0,0 @@ -#' Import binding constraints -#' -#' @description -#' This function imports the binding constraints of an Antares project form an h5 file see also \link[antaresRead]{readBindingConstraints}. -#' -#' @param opts \code{list} of simulation parameters returned by the function \link[antaresRead]{setSimulationPath}. -#' -#' @noRd -h5ReadBindingConstraints <- function(opts){ - .requireRhdf5_Antares() - fid <- rhdf5::H5Fopen(opts$h5path) - timestep <- .getTimeStep(fid)[1] - out <- unserialize(charToRaw(rhdf5::h5read(fid, paste0(timestep , "/inputs/buildingcte")))) - rhdf5::h5closeAll() - out -} - -#' Import areas layout -#' -#' @description -#' This function imports the position of the areas from an h5 file. It may be useful for plotting the -#' network see also \link[antaresRead]{readLayout}. -#' -#' Be aware that the layout is read in the input files so they may have changed since a simulation has been run. -#' @param opts \code{list} of simulation parameters returned by the function \link[antaresRead]{setSimulationPath}. -#' -#' @noRd -h5ReadLayout <- function(opts){ - .requireRhdf5_Antares() - fid <- rhdf5::H5Fopen(opts$h5path) - timestep <- .getTimeStep(fid)[1] - out <- unserialize(charToRaw(rhdf5::h5read(fid, paste0(timestep , "/inputs/layout")))) - rhdf5::h5closeAll() - out -} - -#' Import cluster description -#' -#' @description -#' This function imports the characteristics of each cluster from an h5 file see also \link[antaresRead]{readClusterDesc}. -#' -#' Be aware that clusters descriptions are read in the input files so they may have changed since a simulation has been run. -#' @param opts \code{list} of simulation parameters returned by the function \link[antaresRead]{setSimulationPath}. -#' -#' @noRd -#' -h5ReadClusterDesc <- function(opts){ - .requireRhdf5_Antares() - fid <- rhdf5::H5Fopen(opts$h5path) - timestep <- .getTimeStep(fid)[1] - out <- unserialize(charToRaw(rhdf5::h5read(fid, paste0(timestep , "/inputs/cldesc")))) - rhdf5::h5closeAll() - out -} diff --git a/R/h5_setSimulationPathH5.R b/R/h5_setSimulationPathH5.R deleted file mode 100644 index a83b3ce1..00000000 --- a/R/h5_setSimulationPathH5.R +++ /dev/null @@ -1,77 +0,0 @@ -#' Set simulation path for h5 file -#' -#' @param path \code{character} path of a .h5 file or a repertory with .h5 file(s) -#' @param simulation \code{character} simulation number or name -#' -#' @noRd -#' -setSimulationPathH5 <- function(path, simulation = NULL){ - if(dir.exists(path)){ - allFiles <- list.files(path) - avaliableFile <- allFiles[grep(".h5$", allFiles)] - - if(length(avaliableFile) == 0){ - stop("Not available .h5 file in your directory") - } - if (!is.null(simulation)) { - if(simulation == 0) simulation <- NULL - } - if (is.null(simulation)) { - if (length(avaliableFile) == 1) { # Case 2 - simulation <- 1 - } else { # Case 3 - cat("Please, choose a simulation\n") - for (i in 1:length(avaliableFile)) { - cat(sprintf(" %s - %s\n", i, avaliableFile[i])) - } - simulation <- utils::type.convert(scan(what = character(), nmax = 1), as.is = TRUE) - } - } - - if(simulation == -1){ - simulation <- length(avaliableFile) - } - - if(is.character(simulation)){ - if(length(which(simulation == avaliableFile)) == 0){ - stop("Simulation not in your study") - } - } - - if(is.numeric(simulation)){ - simulation <- avaliableFile[simulation] - } - - path <- paste0(path, "/", simulation) - } else if(!file.exists(path) & !grepl(".h5$", path)){ - stop("Invalid path argument. File not found. Must be a .h5 file or a repertory with .h5 file(s)") - } else if(file.exists(path) & !grepl(".h5$", path)){ - stop("Invalid path argument. Must be a .h5 file or a repertory with .h5 file(s)") - } - - attributes <- .getOptionsH5(path) - options(antares=attributes) - attributes -} - -#' Get H5 options -#' -#' @param path \code{character} path of h5 file -#' -#' @keywords internal -#' @export -# Need to be export for antaresViz -.getOptionsH5 <- function(path){ - - .requireRhdf5_Antares() - fid <- rhdf5::H5Fopen(path) - attributes <- .loadAttributes(fid, "hourly") - attributes <- attributes$opts - attributes$h5 <- TRUE - attributes$h5path <- normalizePath(path) - attributes$studyPath <- NULL - attributes$simPath <- NULL - attributes$inputPath <- NULL - attributes$simDataPath <- NULL - attributes -} diff --git a/R/h5_timeManagement.R b/R/h5_timeManagement.R deleted file mode 100644 index cecb39ef..00000000 --- a/R/h5_timeManagement.R +++ /dev/null @@ -1,133 +0,0 @@ -#' Get timeId from antares study -#' -#' @param data \code{antaresDataList} see \link{readAntares} -#' @param timeStep \code{character} timeStep -#' -#' @noRd -getTime <- function(data, timeStep){ - time <- unique(data[[1]]$time) - current_locale <- Sys.getlocale(category = "LC_TIME") - Sys.setlocale("LC_TIME", "C") - if(timeStep %in% c("weekly", "monthly")){ - dt_date <- data.table(time = as.character(time)) - - }else if(timeStep == "annual"){ - dt_date <- data.table(time) - - }else{ - dt_date <- data.table(IDateTime(time, tz =" UTC")) - - } - Sys.setlocale("LC_TIME", current_locale) - dt_date -} - -#' Read time and generate column who can be calculate from time -#' -#' @param fid \code{H5IdComponent} id of h5 file open which \link[rhdf5]{H5Fopen} -#' @param group \code{group} group where time are stocked -#' -#' @noRd -#' -getAllDateInfoFromDate <- function(fid, group){ - # affectation des classes - - .requireRhdf5_Antares() - - groupT <- paste0(group, "/time") - did <- rhdf5::H5Dopen(fid, groupT) - datetime_data <- data.table(rhdf5::H5Dread(did)) - - - rhdf5::H5Dclose(did) - if(group %in% c("weekly", "annual")){ - return(datetime_data) - } - - current_locale <- Sys.getlocale(category = "LC_TIME") - # mise en locale english pour le time (extraction des mois) - Sys.setlocale("LC_TIME", "C") - if(group == c("monthly")){ - timCop <- datetime_data$time - timCop <- paste0(timCop, "-01") - timCop <- as.Date(timCop) - class(timCop) <- c("IDate", "Date") - datetime_data$month <- as.factor(toupper(format(timCop, format = "%b"))) - return(datetime_data) - } - idate <- NULL - itime <- NULL - class(datetime_data$idate) <- c("IDate", "Date") - class(datetime_data$itime) <- c("ITime") - # recuperation de la locale actuelle du pc - uniqueDate <- unique(datetime_data[,.SD, .SDcols = "idate"]) - uniqueTime <- unique(datetime_data[,.SD, .SDcols = "itime"]) - - - # Calcul day & mounth - uniqueDate[,c("day", "month") := list( - mday(idate), - as.factor(toupper(format(idate, format = "%b"))))] - - - - # calculs - datetime_data[, c("time") := list( - as.POSIXct(idate, time = itime, tz = "UTC") - )] - - if(group == "daily"){ - datetime_data$time <- as.Date(datetime_data$time) - } - - mthList <- c("APR", - "AUG", - "DEC", - "FEB", - "JAN", - "JUL", - "JUN", - "MAR", - "MAY", - "NOV", - "OCT", - "SEP") - - toAdd <- mthList[!mthList %in% levels(uniqueDate$month)] - if(length(toAdd)>0) - { - levels(uniqueDate$month) <- c(levels(uniqueDate$month), toAdd) - } - - if(group == "hourly") - { - uniqueTime[, c("hour") := as.factor(substring(as.character(itime), 1, 5))] - - } - uniqueDate$month <- factor(uniqueDate$month , levels(uniqueDate$month)[order(levels(uniqueDate$month))]) - - #Merge - datetime_data <- merge(datetime_data, uniqueDate) - datetime_data <- merge(datetime_data, uniqueTime, by = "itime") - datetime_data[, "idate" := NULL] - datetime_data[, "itime" := NULL] - setkey(datetime_data, "time") - Sys.setlocale("LC_TIME", current_locale) - datetime_data -} - - -#' Write time in h5 file -#' -#' @param data \code{antaresDataList} see \link{readAntares} -#' @param path \code{character} path of h5 file -#' @param group \code{group} group where time are stored -#' -#' @noRd -writeTime <- function(data, path, group){ - .requireRhdf5_Antares() - time <- getTime(data, group) - group <- paste0(group, "/time") - rhdf5::h5write(time, path, group) - rhdf5::h5closeAll() -} diff --git a/R/h5_transformData.R b/R/h5_transformData.R deleted file mode 100644 index 53cabc86..00000000 --- a/R/h5_transformData.R +++ /dev/null @@ -1,36 +0,0 @@ -#' Transform a \code{antaresDataList} object to be writable by \link{writeAntaresH5} -#' -#' @param data \code{antaresDataList} -#' @param areasKey \code{character} organization key for areas, define h5 group and subgroup -#' @param linksKey \code{character} organization key for links, define h5 group and subgroup -#' @param districtKey \code{character} organization key for districts, define h5 group and subgroup -#' @param clustersKey \code{character} organization key for clusters, define h5 group and subgroup -#' -#' @import data.table -#' -#' @noRd -#' -transformH5 <- function(data, - areasKey = c("area"), - linksKey = c("link"), - districtKey = c("district"), - clustersKey = c("area", "cluster")){ - - if("areas"%in%names(data)) - { - data$areas <- data$areas[, list(list(.SD)), by = areasKey] - } - if("links"%in%names(data)) - { - data$links <- data$links[, list(list(.SD)), by = linksKey] - } - if("districts"%in%names(data)) - { - data$districts <- data$districts[, list(list(.SD)), by = districtKey] - } - if("clusters"%in%names(data)) - { - data$clusters <- data$clusters[, list(list(.SD)), by = clustersKey] - } - data -} diff --git a/R/h5_writeData.R b/R/h5_writeData.R deleted file mode 100644 index d48137e4..00000000 --- a/R/h5_writeData.R +++ /dev/null @@ -1,157 +0,0 @@ -#' Write antares Study to a .h5 file -#' -#' @param data \code{antaresDataList} -#' @param path \code{character} path of h5 file -#' @param rootGroup \code{character} group will contain all h5 organization -#' @param writeStructure \code{boolean}, write group and subgroup (only for first MCyear) -#' @param mcAll \code{character}, write mcAll -#' @param compress \code{numeric}, compression level -#' -#' -#' @noRd -#' -writeAntaresData <- function(data, - path, - rootGroup = NULL, - writeStructure = TRUE, - mcAll = FALSE, - compress = 0){ - - if(!is.null(data$areas)){ - #Write areas - writeDataType(data = data, path = path, type = "areas", rootGroup = rootGroup, writeStructure = writeStructure, - mcAll = mcAll, compress = compress) - } - - if(!is.null(data$links)){ - #Write links - writeDataType(data = data, path = path, type = "links", rootGroup = rootGroup, writeStructure = writeStructure, - mcAll = mcAll, compress = compress) - } - if(!is.null(data$districts)){ - #Write districts - writeDataType(data = data, path = path, type = "districts", rootGroup = rootGroup, writeStructure = writeStructure, - mcAll = mcAll, compress = compress) - } - - if(!is.null(data$clusters)){ - #Write clusters - writeDataType(data = data, path = path, type = "clusters", rootGroup = rootGroup, writeStructure = writeStructure, - mcAll = mcAll, compress = compress) - } - -} - -#' Write data by type -#' -#' @param data \code{antaresDataList} -#' @param path \code{character} patch of h5 file -#' @param type \code{character} type of data to write, must be areas, links, districts or clusters -#' @param rootGroup \code{character} group will contain all h5 organization -#' @param writeStructure \code{boolean}, write group and subgroup (only for first MCyear) -#' @param mcAll \code{character}, write mcAll -#' @param compress \code{boolean}, compress level -#' -#' @noRd -#' -writeDataType <- function(data, - path, - type, - rootGroup = NULL, - writeStructure = TRUE, - mcAll = FALSE, - compress = 0){ - - - .requireRhdf5_Antares() - - if(!mcAll) - { - mcYears <- attr(data, "opts")$mcYears - }else{ - mcYears <- "all" - } - - data <- data[[type]] - if(type == "clusters"){ - data$cluster <- paste0(data$area, "/", data$cluster) - data[,"area" := NULL] - } - - - Group <- paste0(rootGroup, "/", type) - #Create group by type of data - if(writeStructure & !mcAll){ - rhdf5::h5createGroup(path, Group) - } - - #Control if we write mcAll or mcInd - if(mcAll){ - Group <- paste0(Group, "/", "mcAll") - }else{ - Group <- paste0(Group, "/", "mcInd") - - } - - #Create group for mc-ind or mc-all - if(writeStructure){ - rhdf5::h5createGroup(path, Group) - } - # print(data) - #Give structure for data - dimPreBuild <- names(data)[!names(data)%in%c("mcYear", "V1")] - dimStructure <- list() - dimStructure$variable <- names(data$V1[[1]]) - dimStructure <- c(dimStructure, sapply(dimPreBuild, function(X){ - as.character(unique(unlist(data[, .SD, .SDcols = X]))) - }, simplify = FALSE)) - dimStructure$mcYear <- mcYears - - #Give dim length - nbDim <- length(dimStructure) + 1 - nbTimeId <- nrow(data$V1[[1]]) - dimData <- unlist(c(nbTimeId, lapply(dimStructure, length))) - - - #Create array - groupData <- paste0(Group, "/data") - structData <- paste0(Group, "/structure") - if(writeStructure){ - rhdf5::h5createDataset(path, groupData, dims = dimData, chunk = c(dimData[1], 1, 1, 1), - level = compress, maxdims = c(dimData[1], - dimData[2] + 300, - dimData[3], - dimData[4])) - fid <- rhdf5::H5Fopen(path) - # dimStructure$reCalcVar <- rep("NoVariable", 100) - rhdf5::h5writeDataset(dimStructure, fid, structData, level = compress) - rhdf5::H5Fclose(fid) - structNew <- paste0(structData, "/reCalcVar") - rhdf5::h5createDataset(path, structNew, storage.mode = "character", level = compress , dims = 300, - size = 200) - - - } - - #Convert data to an array - arrayDatatowrite <- array(dim = dimData[1:(length(dimData)-1)]) - for(i in 1:nrow(data)){ - arrayDatatowrite[, , i] <- as.matrix(data$V1[[i]]) - } - - #Control index for write - index <- lapply(1:length(dim(arrayDatatowrite)), function(X)NULL) - - if(!mcAll) - { - index$LastDim <- which(data$mcYear[1] == mcYears) - }else{ - index$LastDim <- 1 - } - - #Write data - fid <- rhdf5::H5Fopen(path) - rhdf5::h5writeDataset(obj = arrayDatatowrite, fid, groupData, index = index) - rhdf5::H5Fclose(fid) - NULL -} diff --git a/R/h5_writeH5ByYear.R b/R/h5_writeH5ByYear.R deleted file mode 100644 index 4998caa7..00000000 --- a/R/h5_writeH5ByYear.R +++ /dev/null @@ -1,492 +0,0 @@ -#' Convert antares output to h5 file -#' -#' @param path \code{character} folder where h5 file will be write (default NULL) -#' @param timeSteps \code{character} timeSteps -#' @param opts \code{list} of simulation parameters returned by the function \link{setSimulationPath}. Default to \code{antaresRead::simOptions()} -#' @param writeMcAll \code{boolean} write mc-all -#' @param compress \code{numeric} compress level -#' @param misc \code{boolean} see \link[antaresRead]{readAntares} -#' @param thermalAvailabilities \code{boolean} see \link[antaresRead]{readAntares} -#' @param hydroStorage \code{boolean} see \link[antaresRead]{readAntares} -#' @param hydroStorageMaxPower \code{boolean} see \link[antaresRead]{readAntares} -#' @param reserve \code{boolean} see \link[antaresRead]{readAntares} -#' @param linkCapacity \code{boolean} see \link[antaresRead]{readAntares} -#' @param mustRun \code{boolean} see \link[antaresRead]{readAntares} -#' @param thermalModulation \code{boolean} see \link[antaresRead]{readAntares} -#' @param allData \code{boolean} add all data with a single call (writeMcAll, misc, thermalAvailabilities, hydroStorage, hydroStorageMaxPower -#' reserve, linkCapacity, mustRun, thermalModulation). -#' @param writeAllSimulations \code{boolean}, write all simulations of your antares study. -#' @param nbCores \code{numeric}, number of cores to use, only used if writeAllSimulations is TRUE -#' @param removeVirtualAreas \code{boolean}, remove virtual areas, see \link[antaresRead]{removeVirtualAreas} -#' @param storageFlexibility \code{character or list}, see \link[antaresRead]{removeVirtualAreas} -#' @param production \code{character or list}, see \link[antaresRead]{removeVirtualAreas} -#' @param reassignCosts \code{boolean or list}, see \link[antaresRead]{removeVirtualAreas} -#' @param newCols \code{boolean or list}, see \link[antaresRead]{removeVirtualAreas} -#' @param overwrite \code{boolean or list}, overwrite old file -#' @param supressMessages \code{boolean}, supress messages from \link[antaresRead]{readAntares} and \link[antaresRead]{removeVirtualAreas} -#' -#' @examples -#' -#' \dontrun{ -#' # Write simulation one by one -#' setSimulationPath("C:/Users/MyUser/Mystudy", 1) -#' writeAntaresH5(path="PATH_TO_YOUR_STUDY") -#' -#' # Write all simulations -#' setSimulationPath("C:/Users/MyUser/Mystudy") -#' writeAntaresH5(path="PATH_TO_YOUR_STUDY", writeAllSimulations = TRUE) -#' -#' # Choose timestep to write -#' setSimulationPath("C:/Users/MyUser/Mystudy", 1) -#' writeAntaresH5(path="PATH_TO_YOUR_STUDY", timeSteps = "hourly") -#' -#' # Write with additionnal information -#' writeAntaresH5(path="PATH_TO_YOUR_STUDY", timeSteps = "hourly", -#' misc = TRUE, thermalAvailabilities = TRUE, -#' hydroStorage = TRUE, hydroStorageMaxPower = TRUE, reserve = TRUE, -#' linkCapacity = TRUE, mustRun = TRUE, thermalModulation = TRUE) -#' -#' # Write all data with a shorcut -#' writeAntaresH5(path="PATH_TO_YOUR_STUDY", allData = TRUE) -#' -#' #Remove virtuals areas -#' -#' writeAntaresH5(path="PATH_TO_YOUR_STUDY", timeSteps = "hourly", overwrite = TRUE, -#' writeMcAll = FALSE, removeVirtualAreas = TRUE, -#' storageFlexibility = "psp in-2", -#' production = NULL, reassignCosts =FALSE, newCols = TRUE) -#' -#' #Remove virtuals areas more than one call -#' writeAntaresH5( -#' path="PATH_TO_YOUR_STUDY", -#' timeSteps = "hourly", -#' overwrite = TRUE, -#' writeMcAll = FALSE, -#' removeVirtualAreas = TRUE, -#' storageFlexibility = list("psp out", "psp in-2"), -#' production = list(NULL, NULL), -#' reassignCosts = list(TRUE, FALSE), -#' newCols = list(FALSE, TRUE) -#' ) -#' -#' -#' } -#' @export -writeAntaresH5 <- function(path = NULL, timeSteps = c("hourly", "daily", "weekly", "monthly", "annual"), - opts = simOptions(), - writeMcAll = TRUE, - compress = 1, - misc = FALSE, - thermalAvailabilities = FALSE, - hydroStorage = FALSE, - hydroStorageMaxPower = FALSE, - reserve = FALSE, - linkCapacity = FALSE, - mustRun = FALSE, - thermalModulation = FALSE, - allData = FALSE, - writeAllSimulations = FALSE, - nbCores = 4, - removeVirtualAreas = FALSE, - storageFlexibility = NULL, - production = NULL, - reassignCosts = FALSE, - newCols = TRUE, - overwrite = FALSE, supressMessages = FALSE){ - - if(!dir.exists(path)){ - stop(paste0("Folder ", path, " not found.")) - } - - if(allData){ - writeMcAll <- TRUE - misc <- TRUE - thermalAvailabilities <- TRUE - hydroStorage <- TRUE - hydroStorageMaxPower <- TRUE - reserve <- TRUE - linkCapacity <- TRUE - mustRun <- TRUE - thermalModulation <- TRUE - } - - .requireRhdf5_Antares() - - rhdf5::h5closeAll() - - if(!writeAllSimulations){ - simName <- unlist(strsplit(opts$simPath, "/")) - simName <- simName[length(simName)] - path <- paste0(path, "/", simName, ".h5") - - if(overwrite & file.exists(path)){ - file.remove(path) - } - - if(file.exists(path)){ - stop(paste0("File ", path, " already exist you must use overwrite argument if you want to overwrite")) - } - - - .writeAntaresH5Fun(path = path, - timeSteps = timeSteps, - opts = opts, - writeMcAll = writeMcAll, - compress = compress, - misc = misc, - thermalAvailabilities = thermalAvailabilities, - hydroStorage = hydroStorage, - hydroStorageMaxPower = hydroStorageMaxPower, - reserve = reserve, - linkCapacity = linkCapacity, - mustRun = mustRun, - thermalModulation = thermalModulation, - removeVirtualAreas = removeVirtualAreas, - storageFlexibility = storageFlexibility, - production = production, - reassignCosts = reassignCosts, - newCols = newCols, - supressMessages = supressMessages) - }else{ - studieSToWrite <- list.dirs(paste0(opts$studyPath, "/output"), recursive = FALSE, full.names = FALSE) - studieSToWrite <- setdiff(studieSToWrite, "maps") - if(length(studieSToWrite) > 0){ - studyPath <- opts$studyPath - if(nbCores>1) - { - if(!requireNamespace("parallel")) stop("Error loading 'parallel' package.") - - cl <- parallel::makeCluster(nbCores) - parallel::clusterEvalQ(cl, { - library(antaresRead) - }) - parallel::clusterExport(cl, c("path","opts","studyPath", - "timeSteps", - "writeMcAll", - "compress", - "misc", - "thermalAvailabilities", - "hydroStorage", - "hydroStorageMaxPower", - "reserve", - "linkCapacity", - "mustRun", - "thermalModulation", - "removeVirtualAreas", - "storageFlexibility", - "production", - "reassignCosts", - "newCols", - "overwrite", - ".writeAntaresH5Fun", - "supressMessages" - ), envir = environment()) - - parallel::parSapplyLB(cl, studieSToWrite, function(X){ - if(supressMessages) - { - opts <- suppressWarnings(suppressMessages(setSimulationPath(studyPath, X))) - }else{ - opts <- setSimulationPath(studyPath, X) - } - - if(!is.null(path)){ - pathStud <- paste0(path, "/", X, ".h5") - } - - if(overwrite & file.exists(pathStud)){ - file.remove(pathStud) - } - - if(file.exists(pathStud)){ - stop(paste0("File ", pathStud, " already exist you must use overwrite argument if you want to overwrite")) - } - - - .writeAntaresH5Fun(path = pathStud, - timeSteps = timeSteps, - opts = opts, - writeMcAll = writeMcAll, - compress = compress, - misc = misc, - thermalAvailabilities = thermalAvailabilities, - hydroStorage = hydroStorage, - hydroStorageMaxPower = hydroStorageMaxPower, - reserve = reserve, - linkCapacity = linkCapacity, - mustRun = mustRun, - thermalModulation = thermalModulation, - removeVirtualAreas = removeVirtualAreas, - storageFlexibility = storageFlexibility, - production = production, - reassignCosts = reassignCosts, - newCols = newCols, - supressMessages = supressMessages) - - - }) - parallel::stopCluster(cl) - - }else{ - sapply(studieSToWrite, function(X){ - if(supressMessages) - { - opts <- suppressWarnings(suppressMessages(setSimulationPath(studyPath, X))) - }else{ - opts <- setSimulationPath(studyPath, X) - } - - if(!is.null(path)){ - pathStud <- paste0(path, "/", X, ".h5") - } - - if(overwrite & file.exists(pathStud)){ - file.remove(pathStud) - } - if(file.exists(pathStud)){ - stop(paste0("File ", pathStud, " already exist you must use overwrite argument if you want to overwrite")) - } - - .writeAntaresH5Fun(path = pathStud, - timeSteps = timeSteps, - opts = opts, - writeMcAll = writeMcAll, - compress = compress, - misc = misc, - thermalAvailabilities = thermalAvailabilities, - hydroStorage = hydroStorage, - hydroStorageMaxPower = hydroStorageMaxPower, - reserve = reserve, - linkCapacity = linkCapacity, - mustRun = mustRun, - thermalModulation = thermalModulation, - removeVirtualAreas = removeVirtualAreas, - storageFlexibility = storageFlexibility, - production = production, - reassignCosts = reassignCosts, - newCols = newCols, - supressMessages = supressMessages) - - - }) - - } - } else { - message("No study.") - } - } - - - -} - -#' Convert antares output to h5 file -#' -#' @keywords internal -#' @export -.writeAntaresH5Fun <- function(path, - timeSteps, - opts, - writeMcAll, - compress, - misc, - thermalAvailabilities, - hydroStorage, - hydroStorageMaxPower, - reserve, - linkCapacity, - mustRun, - thermalModulation, - removeVirtualAreas, - storageFlexibility, - production, - reassignCosts, - newCols, - supressMessages){ - - .requireRhdf5_Antares() - - - if(is.null(path)){ - studPath <- unlist(strsplit(opts$simPath, "/")) - studName <- studPath[length(studPath)] - path <- paste0(studName, ".h5") - } - - #Close connection if exist - rhdf5::h5closeAll() - - #Create h5 file - rhdf5::h5createFile(path) - - #loop on timeStep - sapply(timeSteps, function(timeStep){ - - #Add mcAll - allMcYears <- opts$mcYears - if(writeMcAll){ - allMcYears <- c(allMcYears, -1) - } - - #Loop on MCyear - sapply(allMcYears, function(mcY) - { - - messageS <- ifelse(allMcYears[1] == mcY & timeSteps[1] == timeStep && !supressMessages, TRUE, FALSE) - if(allMcYears[1] == mcY){ - writeStructure = TRUE - }else{ - writeStructure = FALSE - } - mcAll <- FALSE - if(mcY == -1){ - mcY <- NULL - writeStructure <- TRUE - mcAll <- TRUE - } - - #Read data - if(messageS){ - res <- readAntares(areas = "all" , - links = "all", - clusters = "all", - districts = "all", - mcYears = mcY, - timeStep = timeStep, opts = opts, showProgress = FALSE, - misc = misc, thermalAvailabilities = thermalAvailabilities, - hydroStorage = hydroStorage, hydroStorageMaxPower = hydroStorageMaxPower, - reserve = reserve, linkCapacity = linkCapacity, mustRun = mustRun, - thermalModulation = thermalModulation) - - - }else{ - res <- suppressWarnings(suppressMessages(readAntares(areas = "all" , - links = "all", - clusters = "all", - districts = "all", - mcYears = mcY, - timeStep = timeStep, opts = opts, showProgress = FALSE, - misc = misc, thermalAvailabilities = thermalAvailabilities, - hydroStorage = hydroStorage, hydroStorageMaxPower = hydroStorageMaxPower, - reserve = reserve, linkCapacity = linkCapacity, mustRun = mustRun, - thermalModulation = thermalModulation))) - - } - - if(removeVirtualAreas){ - if(!(is.list(storageFlexibility))) - { - if(messageS){ - res <- removeVirtualAreas(res, - storageFlexibility = storageFlexibility, - production = production, - reassignCosts = reassignCosts, - newCols = newCols) - }else{ - res <- suppressWarnings(suppressMessages(removeVirtualAreas(res, - storageFlexibility = storageFlexibility, - production = production, - reassignCosts = reassignCosts, - newCols = newCols))) - } - }else{ - - for(i in 1:length(storageFlexibility)){ - res <- suppressWarnings( - suppressMessages( - removeVirtualAreas(res, - storageFlexibility = storageFlexibility[[i]], - production = production[[i]], - reassignCosts = reassignCosts[[i]], - newCols = newCols[[i]]))) - } - - } - } - - if(writeStructure & !mcAll){ - - - # Create group - rhdf5::h5closeAll() - rhdf5::h5createGroup(path, timeStep) - rhdf5::h5closeAll() - #Write time - writeTime(res, path, timeStep) - rhdf5::h5closeAll() - #Write attributes - - attrib <- attributes(res) - s <- serialize(attrib, NULL, ascii = TRUE) - rhdf5::h5write(rawToChar(s), path, paste0(timeStep, "/attrib")) - - # .writeAttributes(res = res, path = path, timeStep = timeStep) - - - - ###Write inputs - rhdf5::h5createGroup(path, paste0(timeStep, "/inputs")) - if(messageS){ - layout <- readLayout() - }else{ - layout <- suppressWarnings(suppressMessages(readLayout())) - } - s <- serialize(layout, NULL, ascii = TRUE) - rhdf5::h5write(rawToChar(s), path, paste0(timeStep, "/inputs/layout")) - - if(messageS){ - cldesc <- readClusterDesc() - }else{ - cldesc <- suppressWarnings(suppressMessages(readClusterDesc())) - } - s <- serialize(cldesc, NULL, ascii = TRUE) - rhdf5::h5write(rawToChar(s), path, paste0(timeStep, "/inputs/cldesc")) - if(messageS){ - bc <- readBindingConstraints() - }else{ - bc <- suppressWarnings(suppressMessages(readBindingConstraints())) - } - s <- serialize(bc, NULL, ascii = TRUE) - rhdf5::h5write(rawToChar(s), path, paste0(timeStep, "/inputs/buildingcte")) - - } - - #Remove useless data - ctrl <- sapply(1:length(res), function(i){ - if("day" %in% names(res[[i]])){ - res[[i]][, "day" := NULL] - } - if("month" %in% names(res[[i]])){ - res[[i]][, "month" := NULL] - } - if("hour" %in% names(res[[i]])){ - res[[i]][, "hour" := NULL] - } - if("time" %in% names(res[[i]])){ - res[[i]][, "time" := NULL] - } - invisible() - }) - gc() - - - if(is.null(mcY)){ - - lapply(res, function(X){ - X[, "mcYear" := "mcAll"] - - }) - } - #Transform for write - res <- transformH5(res,areasKey = c("area", "mcYear"), - linksKey = c("link", "mcYear"), - districtKey = c("district", "mcYear"), - clustersKey = c("area", "cluster", "mcYear")) - #Write data - writeAntaresData(res, path, timeStep, writeStructure, mcAll, compress) - }) - }) - rhdf5::h5closeAll() - message(paste0("File .h5 writed : ", path, "\n")) - invisible() -} diff --git a/R/h5utils.R b/R/h5utils.R deleted file mode 100644 index e7a71a70..00000000 --- a/R/h5utils.R +++ /dev/null @@ -1,26 +0,0 @@ -#Copyright © 2016 RTE Réseau de transport d’électricité - -#' Test if opts is h5 -#' -#' @description Test if the value returned by setSimulationPath() is referring to an h5 file -#' -#' @param opts , opts -#' @export -isH5Opts <- function(opts){ - v <- FALSE - if(!is.null(opts$h5)){ - if(opts$h5){ - v <- TRUE - } - } - v -} - - -.getTimeStep <- function(fid){ - .requireRhdf5_Antares() - timeSteps <- sapply(c("hourly", "daily", "weekly", "monthly", "annual"), function(X){ - rhdf5::H5Lexists(fid, X) - }) - names(timeSteps[which(timeSteps == TRUE)]) -} diff --git a/R/readAntares.R b/R/readAntares.R index 3cd256a1..94db2ab7 100644 --- a/R/readAntares.R +++ b/R/readAntares.R @@ -283,31 +283,31 @@ readAntares <- function(areas = NULL, links = NULL, clusters = NULL, } } - if(isH5Opts(opts)){ - - if(.requireRhdf5_Antares(stopP = FALSE)){ - return(.h5ReadAntares(path = opts$h5path, - areas = areas, - links = links, - clusters = clusters, - districts = districts, - misc = misc, - thermalAvailabilities = thermalAvailabilities, - hydroStorage = hydroStorage, - hydroStorageMaxPower = hydroStorageMaxPower, - reserve = reserve, - linkCapacity = linkCapacity, - mustRun = mustRun, - thermalModulation = thermalModulation, - select = select, - mcYears = mcYears, - timeStep = timeStep[1], - showProgress = showProgress, - simplify = simplify)) - } else { - stop(rhdf5_message) - } - } + # if(isH5Opts(opts)){ + # + # if(.requireRhdf5_Antares(stopP = FALSE)){ + # return(.h5ReadAntares(path = opts$h5path, + # areas = areas, + # links = links, + # clusters = clusters, + # districts = districts, + # misc = misc, + # thermalAvailabilities = thermalAvailabilities, + # hydroStorage = hydroStorage, + # hydroStorageMaxPower = hydroStorageMaxPower, + # reserve = reserve, + # linkCapacity = linkCapacity, + # mustRun = mustRun, + # thermalModulation = thermalModulation, + # select = select, + # mcYears = mcYears, + # timeStep = timeStep[1], + # showProgress = showProgress, + # simplify = simplify)) + # } else { + # stop(rhdf5_message) + # } + # } if (opts$mode == "Input") stop("Cannot use 'readAntares' in 'Input' mode.") diff --git a/R/readClusterDesc.R b/R/readClusterDesc.R index 0f117caf..5f9ea0c1 100644 --- a/R/readClusterDesc.R +++ b/R/readClusterDesc.R @@ -88,7 +88,7 @@ readClusterSTDesc <- function(opts = simOptions()) { .readClusterDesc(opts = opts, dir = "st-storage/clusters") } - +#' @importFrom stats setNames .readClusterDesc <- function(opts = simOptions(), dir = "thermal/clusters") { diff --git a/R/readLayout.R b/R/readLayout.R index ca3ffdbb..125078c9 100644 --- a/R/readLayout.R +++ b/R/readLayout.R @@ -88,13 +88,13 @@ readLayout <- function(opts = simOptions(), xyCompare = c("union","intersect")) stopifnot(class(opts) %in% "simOptions") - if(isH5Opts(opts)){ - if(.requireRhdf5_Antares(stopP = FALSE)){ - return(h5ReadLayout(opts)) - } else { - stop(rhdf5_message) - } - } + # if(isH5Opts(opts)){ + # if(.requireRhdf5_Antares(stopP = FALSE)){ + # return(h5ReadLayout(opts)) + # } else { + # stop(rhdf5_message) + # } + # } #if there are no areas return NULL if(length(opts$areaList)==0 | identical(opts$areaList,"")) { diff --git a/R/zzz.R b/R/zzz.R index 3ebc75fd..ba0f7a18 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -108,151 +108,151 @@ utils::globalVariables( "DETAILS_FILES_TYPE","ANTARES_DISPLAYED_NAME") ) -#----------------------------- HDF5 ------------------------------------# - - -is.installed <- function(mypkg) is.element(mypkg, utils::installed.packages()[,1]) - -rhdf5_version <- "2.24.0" -rhdf5_message <- "This function require 'rhdf5' (>= 2.24.0) package. - This is a bioconductor package. You can install it with : - source('https://bioconductor.org/biocLite.R') - biocLite('rhdf5')" - -# !! parameter versionCheck of requireNamespace does not work correctly, use utils::package_version instead -.requireRhdf5_Antares <- function(stopP = TRUE){ - if(.check_rhdf5(stopP = stopP)){ - if(.check_rhdf5_version(stopP = stopP)){ - return(TRUE) - } - } - return(FALSE) -} - -.stop_rhdf5_version <- function(stopP = TRUE) { - if(stopP){ - stop(rhdf5_message) - }else{ - return(FALSE) - } -} - -.check_rhdf5 <- function(stopP = TRUE){ - if(requireNamespace("rhdf5", quietly = TRUE)){ - return(TRUE) - }else{ - .stop_rhdf5_version(stopP) - } -} - -.check_rhdf5_version <- function(stopP = TRUE){ - if(utils::packageVersion("rhdf5") >= rhdf5_version){ - return(TRUE) - }else{ - .stop_rhdf5_version(stopP) - } -} - -# .addClassAndAttributes <- antaresRead:::.addClassAndAttributes - -pkgEnvAntareasH5 <- new.env() - -pkgEnvAntareasH5$varAreas <- c("OV. COST", "OP. COST", "MRG. PRICE", "CO2 EMIS.", "BALANCE", - "ROW BAL.", "PSP", "MISC. NDG", "LOAD", "H. ROR", "WIND", "SOLAR", - "NUCLEAR", "LIGNITE", "COAL", "GAS", "OIL", "MIX. FUEL", "MISC. DTG", - "H. STOR", "UNSP. ENRG", "SPIL. ENRG", "LOLD", "LOLP", "AVL DTG", - "DTG MRG", "MAX MRG", "NP COST", "NODU") - -pkgEnvAntareasH5$varAreas <- as.vector(sapply(pkgEnvAntareasH5$varAreas, function(X){paste0(X, c("", "_min", "_max", "_std"))})) - -pkgEnvAntareasH5$varDistricts <- pkgEnvAntareasH5$varAreas - -pkgEnvAntareasH5$varLinks <- c("FLOW LIN.", "UCAP LIN.", "FLOW QUAD.", - "CONG. FEE (ALG.)", "CONG. FEE (ABS.)", - "MARG. COST", "CONG. PROB +", "CONG. PROB -", "HURDLE COST") - -pkgEnvAntareasH5$varLinks <- as.vector(sapply(pkgEnvAntareasH5$varLinks, function(X){paste0(X, c("", "_min", "_max", "_std"))})) - -pkgEnvAntareasH5$varClusters <- c("production", "NP Cost", "NODU") - -pkgEnvAntareasH5$varAliasCreated <- list() - - -#misc -pkgEnvAntareasH5$varAliasCreated$misc$areas <- c("CHP", - "Bio_mass", - "Bio_gas", - "mustRunWasteTotal", - "GeoThermal", - "Other", - "PSP_input", - "ROW_Balance") - -pkgEnvAntareasH5$varAliasCreated$misc$districts <- c("CHP", - "Bio_mass", - "Bio_gas", - "mustRunWasteTotal", - "GeoThermal", - "Other", - "PSP_input", - "ROW_Balance") -#thermalAvailabilities -pkgEnvAntareasH5$varAliasCreated$thermalAvailabilities$clusters <- c("thermalAvailability", - "availableUnits") - - -#hydroStorage -pkgEnvAntareasH5$varAliasCreated$hydroStorage$areas <- c("hydroStorage") - -pkgEnvAntareasH5$varAliasCreated$hydroStorage$districts <- c("hydroStorage") - -#hydroStorageMaxPower -pkgEnvAntareasH5$varAliasCreated$hydroStorageMaxPower$areas <- c("hstorPMaxLow", - "hstorPMaxAvg", - "hstorPMaxHigh") - -pkgEnvAntareasH5$varAliasCreated$hydroStorageMaxPower$districts <- c("hstorPMaxLow", - "hstorPMaxAvg", - "hstorPMaxHigh") - -#reserve -pkgEnvAntareasH5$varAliasCreated$reserve$areas <- c("primaryRes", - "strategicRes", - "DSM", - "dayAhead") - -pkgEnvAntareasH5$varAliasCreated$reserve$districts <- c("primaryRes", - "strategicRes", - "DSM", - "dayAhead") - -#linkCapacity -pkgEnvAntareasH5$varAliasCreated$linkCapacity$links <- c("transCapacityDirect", - "transCapacityIndirect", - "impedances", - "hurdlesCostDirect", - "hurdlesCostIndirect") - -#mustRun -pkgEnvAntareasH5$varAliasCreated$mustRun$areas <- c("thermalPmin", - "mustRun", - "mustRunPartial", - "mustRunTotal") - -pkgEnvAntareasH5$varAliasCreated$mustRun$districts <- c("thermalPmin", - "mustRun", - "mustRunPartial", - "mustRunTotal") - -pkgEnvAntareasH5$varAliasCreated$mustRun$clusters <- c("thermalPmin", - "mustRun", - "mustRunPartial", - "mustRunTotal") - -pkgEnvAntareasH5$varAliasCreated$thermalModulation$clusters <- c("marginalCostModulation", - "marketBidModulation", - "capacityModulation", - "minGenModulation") +# #----------------------------- HDF5 ------------------------------------# +# +# +# is.installed <- function(mypkg) is.element(mypkg, utils::installed.packages()[,1]) +# +# rhdf5_version <- "2.24.0" +# rhdf5_message <- "This function require 'rhdf5' (>= 2.24.0) package. +# This is a bioconductor package. You can install it with : +# source('https://bioconductor.org/biocLite.R') +# biocLite('rhdf5')" +# +# # !! parameter versionCheck of requireNamespace does not work correctly, use utils::package_version instead +# .requireRhdf5_Antares <- function(stopP = TRUE){ +# if(.check_rhdf5(stopP = stopP)){ +# if(.check_rhdf5_version(stopP = stopP)){ +# return(TRUE) +# } +# } +# return(FALSE) +# } +# +# .stop_rhdf5_version <- function(stopP = TRUE) { +# if(stopP){ +# stop(rhdf5_message) +# }else{ +# return(FALSE) +# } +# } +# +# .check_rhdf5 <- function(stopP = TRUE){ +# if(requireNamespace("rhdf5", quietly = TRUE)){ +# return(TRUE) +# }else{ +# .stop_rhdf5_version(stopP) +# } +# } +# +# .check_rhdf5_version <- function(stopP = TRUE){ +# if(utils::packageVersion("rhdf5") >= rhdf5_version){ +# return(TRUE) +# }else{ +# .stop_rhdf5_version(stopP) +# } +# } +# +# # .addClassAndAttributes <- antaresRead:::.addClassAndAttributes +# +# pkgEnvAntareasH5 <- new.env() +# +# pkgEnvAntareasH5$varAreas <- c("OV. COST", "OP. COST", "MRG. PRICE", "CO2 EMIS.", "BALANCE", +# "ROW BAL.", "PSP", "MISC. NDG", "LOAD", "H. ROR", "WIND", "SOLAR", +# "NUCLEAR", "LIGNITE", "COAL", "GAS", "OIL", "MIX. FUEL", "MISC. DTG", +# "H. STOR", "UNSP. ENRG", "SPIL. ENRG", "LOLD", "LOLP", "AVL DTG", +# "DTG MRG", "MAX MRG", "NP COST", "NODU") +# +# pkgEnvAntareasH5$varAreas <- as.vector(sapply(pkgEnvAntareasH5$varAreas, function(X){paste0(X, c("", "_min", "_max", "_std"))})) +# +# pkgEnvAntareasH5$varDistricts <- pkgEnvAntareasH5$varAreas +# +# pkgEnvAntareasH5$varLinks <- c("FLOW LIN.", "UCAP LIN.", "FLOW QUAD.", +# "CONG. FEE (ALG.)", "CONG. FEE (ABS.)", +# "MARG. COST", "CONG. PROB +", "CONG. PROB -", "HURDLE COST") +# +# pkgEnvAntareasH5$varLinks <- as.vector(sapply(pkgEnvAntareasH5$varLinks, function(X){paste0(X, c("", "_min", "_max", "_std"))})) +# +# pkgEnvAntareasH5$varClusters <- c("production", "NP Cost", "NODU") +# +# pkgEnvAntareasH5$varAliasCreated <- list() +# +# +# #misc +# pkgEnvAntareasH5$varAliasCreated$misc$areas <- c("CHP", +# "Bio_mass", +# "Bio_gas", +# "mustRunWasteTotal", +# "GeoThermal", +# "Other", +# "PSP_input", +# "ROW_Balance") +# +# pkgEnvAntareasH5$varAliasCreated$misc$districts <- c("CHP", +# "Bio_mass", +# "Bio_gas", +# "mustRunWasteTotal", +# "GeoThermal", +# "Other", +# "PSP_input", +# "ROW_Balance") +# #thermalAvailabilities +# pkgEnvAntareasH5$varAliasCreated$thermalAvailabilities$clusters <- c("thermalAvailability", +# "availableUnits") +# +# +# #hydroStorage +# pkgEnvAntareasH5$varAliasCreated$hydroStorage$areas <- c("hydroStorage") +# +# pkgEnvAntareasH5$varAliasCreated$hydroStorage$districts <- c("hydroStorage") +# +# #hydroStorageMaxPower +# pkgEnvAntareasH5$varAliasCreated$hydroStorageMaxPower$areas <- c("hstorPMaxLow", +# "hstorPMaxAvg", +# "hstorPMaxHigh") +# +# pkgEnvAntareasH5$varAliasCreated$hydroStorageMaxPower$districts <- c("hstorPMaxLow", +# "hstorPMaxAvg", +# "hstorPMaxHigh") +# +# #reserve +# pkgEnvAntareasH5$varAliasCreated$reserve$areas <- c("primaryRes", +# "strategicRes", +# "DSM", +# "dayAhead") +# +# pkgEnvAntareasH5$varAliasCreated$reserve$districts <- c("primaryRes", +# "strategicRes", +# "DSM", +# "dayAhead") +# +# #linkCapacity +# pkgEnvAntareasH5$varAliasCreated$linkCapacity$links <- c("transCapacityDirect", +# "transCapacityIndirect", +# "impedances", +# "hurdlesCostDirect", +# "hurdlesCostIndirect") +# +# #mustRun +# pkgEnvAntareasH5$varAliasCreated$mustRun$areas <- c("thermalPmin", +# "mustRun", +# "mustRunPartial", +# "mustRunTotal") +# +# pkgEnvAntareasH5$varAliasCreated$mustRun$districts <- c("thermalPmin", +# "mustRun", +# "mustRunPartial", +# "mustRunTotal") +# +# pkgEnvAntareasH5$varAliasCreated$mustRun$clusters <- c("thermalPmin", +# "mustRun", +# "mustRunPartial", +# "mustRunTotal") +# +# pkgEnvAntareasH5$varAliasCreated$thermalModulation$clusters <- c("marginalCostModulation", +# "marketBidModulation", +# "capacityModulation", +# "minGenModulation") integerVariable <- as.character(unique(pkgEnv$formatName$Name[which(pkgEnv$formatName$digits == 0)])) integerVariable <- unlist(apply(expand.grid(integerVariable, c("", "_std", "_min", "_max")), 1, diff --git a/man/dot-getOptionsH5.Rd b/man/dot-getOptionsH5.Rd deleted file mode 100644 index 96801eeb..00000000 --- a/man/dot-getOptionsH5.Rd +++ /dev/null @@ -1,15 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/h5_setSimulationPathH5.R -\name{.getOptionsH5} -\alias{.getOptionsH5} -\title{Get H5 options} -\usage{ -.getOptionsH5(path) -} -\arguments{ -\item{path}{\code{character} path of h5 file} -} -\description{ -Get H5 options -} -\keyword{internal} diff --git a/man/dot-h5ReadAntares.Rd b/man/dot-h5ReadAntares.Rd deleted file mode 100644 index d7890a01..00000000 --- a/man/dot-h5ReadAntares.Rd +++ /dev/null @@ -1,71 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/h5_antaresReadH5.R -\name{.h5ReadAntares} -\alias{.h5ReadAntares} -\title{Read data} -\usage{ -.h5ReadAntares( - path, - areas = NULL, - links = NULL, - clusters = NULL, - districts = NULL, - mcYears = NULL, - misc = FALSE, - thermalAvailabilities = FALSE, - hydroStorage = FALSE, - hydroStorageMaxPower = FALSE, - reserve = FALSE, - linkCapacity = FALSE, - mustRun = FALSE, - thermalModulation = FALSE, - timeStep = "hourly", - select = NULL, - showProgress = TRUE, - simplify = TRUE, - perf = FALSE -) -} -\arguments{ -\item{path}{{character} path of h5file to load} - -\item{areas}{see \link[antaresRead]{readAntares}} - -\item{links}{see \link[antaresRead]{readAntares}} - -\item{clusters}{see \link[antaresRead]{readAntares}} - -\item{districts}{see \link[antaresRead]{readAntares}} - -\item{mcYears}{see \link[antaresRead]{readAntares}} - -\item{misc}{see \link[antaresRead]{readAntares}} - -\item{thermalAvailabilities}{see \link[antaresRead]{readAntares}} - -\item{hydroStorage}{see \link[antaresRead]{readAntares}} - -\item{hydroStorageMaxPower}{see \link[antaresRead]{readAntares}} - -\item{reserve}{see \link[antaresRead]{readAntares}} - -\item{linkCapacity}{see \link[antaresRead]{readAntares}} - -\item{mustRun}{see \link[antaresRead]{readAntares}} - -\item{thermalModulation}{see \link[antaresRead]{readAntares}} - -\item{timeStep}{see \link[antaresRead]{readAntares}} - -\item{select}{see \link[antaresRead]{readAntares}} - -\item{showProgress}{see \link[antaresRead]{readAntares}} - -\item{simplify}{see \link[antaresRead]{readAntares}} - -\item{perf}{\code{boolean}, eval performance during developpement time, to remove} -} -\description{ -Read data -} -\keyword{internal} diff --git a/man/dot-writeAntaresH5Fun.Rd b/man/dot-writeAntaresH5Fun.Rd deleted file mode 100644 index 5b58e29c..00000000 --- a/man/dot-writeAntaresH5Fun.Rd +++ /dev/null @@ -1,32 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/h5_writeH5ByYear.R -\name{.writeAntaresH5Fun} -\alias{.writeAntaresH5Fun} -\title{Convert antares output to h5 file} -\usage{ -.writeAntaresH5Fun( - path, - timeSteps, - opts, - writeMcAll, - compress, - misc, - thermalAvailabilities, - hydroStorage, - hydroStorageMaxPower, - reserve, - linkCapacity, - mustRun, - thermalModulation, - removeVirtualAreas, - storageFlexibility, - production, - reassignCosts, - newCols, - supressMessages -) -} -\description{ -Convert antares output to h5 file -} -\keyword{internal} diff --git a/man/isH5Opts.Rd b/man/isH5Opts.Rd deleted file mode 100644 index b2f35aa9..00000000 --- a/man/isH5Opts.Rd +++ /dev/null @@ -1,14 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/h5utils.R -\name{isH5Opts} -\alias{isH5Opts} -\title{Test if opts is h5} -\usage{ -isH5Opts(opts) -} -\arguments{ -\item{opts}{, opts} -} -\description{ -Test if the value returned by setSimulationPath() is referring to an h5 file -} diff --git a/man/writeAntaresH5.Rd b/man/writeAntaresH5.Rd deleted file mode 100644 index f76baab0..00000000 --- a/man/writeAntaresH5.Rd +++ /dev/null @@ -1,130 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/h5_writeH5ByYear.R -\name{writeAntaresH5} -\alias{writeAntaresH5} -\title{Convert antares output to h5 file} -\usage{ -writeAntaresH5( - path = NULL, - timeSteps = c("hourly", "daily", "weekly", "monthly", "annual"), - opts = simOptions(), - writeMcAll = TRUE, - compress = 1, - misc = FALSE, - thermalAvailabilities = FALSE, - hydroStorage = FALSE, - hydroStorageMaxPower = FALSE, - reserve = FALSE, - linkCapacity = FALSE, - mustRun = FALSE, - thermalModulation = FALSE, - allData = FALSE, - writeAllSimulations = FALSE, - nbCores = 4, - removeVirtualAreas = FALSE, - storageFlexibility = NULL, - production = NULL, - reassignCosts = FALSE, - newCols = TRUE, - overwrite = FALSE, - supressMessages = FALSE -) -} -\arguments{ -\item{path}{\code{character} folder where h5 file will be write (default NULL)} - -\item{timeSteps}{\code{character} timeSteps} - -\item{opts}{\code{list} of simulation parameters returned by the function \link{setSimulationPath}. Default to \code{antaresRead::simOptions()}} - -\item{writeMcAll}{\code{boolean} write mc-all} - -\item{compress}{\code{numeric} compress level} - -\item{misc}{\code{boolean} see \link[antaresRead]{readAntares}} - -\item{thermalAvailabilities}{\code{boolean} see \link[antaresRead]{readAntares}} - -\item{hydroStorage}{\code{boolean} see \link[antaresRead]{readAntares}} - -\item{hydroStorageMaxPower}{\code{boolean} see \link[antaresRead]{readAntares}} - -\item{reserve}{\code{boolean} see \link[antaresRead]{readAntares}} - -\item{linkCapacity}{\code{boolean} see \link[antaresRead]{readAntares}} - -\item{mustRun}{\code{boolean} see \link[antaresRead]{readAntares}} - -\item{thermalModulation}{\code{boolean} see \link[antaresRead]{readAntares}} - -\item{allData}{\code{boolean} add all data with a single call (writeMcAll, misc, thermalAvailabilities, hydroStorage, hydroStorageMaxPower -reserve, linkCapacity, mustRun, thermalModulation).} - -\item{writeAllSimulations}{\code{boolean}, write all simulations of your antares study.} - -\item{nbCores}{\code{numeric}, number of cores to use, only used if writeAllSimulations is TRUE} - -\item{removeVirtualAreas}{\code{boolean}, remove virtual areas, see \link[antaresRead]{removeVirtualAreas}} - -\item{storageFlexibility}{\code{character or list}, see \link[antaresRead]{removeVirtualAreas}} - -\item{production}{\code{character or list}, see \link[antaresRead]{removeVirtualAreas}} - -\item{reassignCosts}{\code{boolean or list}, see \link[antaresRead]{removeVirtualAreas}} - -\item{newCols}{\code{boolean or list}, see \link[antaresRead]{removeVirtualAreas}} - -\item{overwrite}{\code{boolean or list}, overwrite old file} - -\item{supressMessages}{\code{boolean}, supress messages from \link[antaresRead]{readAntares} and \link[antaresRead]{removeVirtualAreas}} -} -\description{ -Convert antares output to h5 file -} -\examples{ - -\dontrun{ -# Write simulation one by one -setSimulationPath("C:/Users/MyUser/Mystudy", 1) -writeAntaresH5(path="PATH_TO_YOUR_STUDY") - -# Write all simulations -setSimulationPath("C:/Users/MyUser/Mystudy") -writeAntaresH5(path="PATH_TO_YOUR_STUDY", writeAllSimulations = TRUE) - -# Choose timestep to write -setSimulationPath("C:/Users/MyUser/Mystudy", 1) -writeAntaresH5(path="PATH_TO_YOUR_STUDY", timeSteps = "hourly") - -# Write with additionnal information -writeAntaresH5(path="PATH_TO_YOUR_STUDY", timeSteps = "hourly", - misc = TRUE, thermalAvailabilities = TRUE, - hydroStorage = TRUE, hydroStorageMaxPower = TRUE, reserve = TRUE, - linkCapacity = TRUE, mustRun = TRUE, thermalModulation = TRUE) - -# Write all data with a shorcut -writeAntaresH5(path="PATH_TO_YOUR_STUDY", allData = TRUE) - -#Remove virtuals areas - -writeAntaresH5(path="PATH_TO_YOUR_STUDY", timeSteps = "hourly", overwrite = TRUE, - writeMcAll = FALSE, removeVirtualAreas = TRUE, - storageFlexibility = "psp in-2", - production = NULL, reassignCosts =FALSE, newCols = TRUE) - -#Remove virtuals areas more than one call -writeAntaresH5( - path="PATH_TO_YOUR_STUDY", - timeSteps = "hourly", - overwrite = TRUE, - writeMcAll = FALSE, - removeVirtualAreas = TRUE, - storageFlexibility = list("psp out", "psp in-2"), - production = list(NULL, NULL), - reassignCosts = list(TRUE, FALSE), - newCols = list(FALSE, TRUE) - ) - - -} -} diff --git a/revdep/README.md b/revdep/README.md index 0859531f..d4783322 100644 --- a/revdep/README.md +++ b/revdep/README.md @@ -10,20 +10,29 @@ |collate |French_France.utf8 | |ctype |French_France.utf8 | |tz |Europe/Paris | -|date |2024-06-14 | +|date |2024-06-25 | |rstudio |2023.12.0+369 Ocean Storm (desktop) | |pandoc |NA | # Dependencies -|package |old |new |Δ | -|:-----------|:-----|:-----|:--| -|antaresRead |2.7.0 |2.7.1 |* | -|cachem |NA |1.0.8 |* | -|fastmap |NA |1.1.1 |* | -|openssl |NA |2.1.2 |* | -|rlang |NA |1.1.3 |* | -|stringi |NA |1.8.3 |* | +|package |old |new |Δ | +|:-----------|:-----|:------|:--| +|antaresRead |2.7.0 |2.7.1 |* | +|cachem |NA |1.1.0 |* | +|cli |NA |3.6.3 |* | +|crayon |NA |1.5.3 |* | +|digest |NA |0.6.36 |* | +|fastmap |NA |1.2.0 |* | +|openssl |NA |2.2.0 |* | +|rlang |NA |1.1.4 |* | +|stringi |NA |1.8.4 |* | # Revdeps +## Failed to check (1) + +|package |version |error |warning |note | +|:----------|:-------|:------|:-------|:----| +|[antaresViz](failures.md#antaresviz)|0.18.0 |__+1__ | | | + diff --git a/revdep/cran.md b/revdep/cran.md index 29c19611..a11ae5fc 100644 --- a/revdep/cran.md +++ b/revdep/cran.md @@ -3,5 +3,10 @@ We checked 3 reverse dependencies, comparing R CMD check results across CRAN and dev versions of this package. * We saw 0 new problems - * We failed to check 0 packages + * We failed to check 1 packages +Issues with CRAN packages are summarised below. + +### Failed to check + +* antaresViz (NA) diff --git a/revdep/failures.md b/revdep/failures.md index 9a207363..46385cc2 100644 --- a/revdep/failures.md +++ b/revdep/failures.md @@ -1 +1,73 @@ -*Wow, no problems at all. :)* \ No newline at end of file +# antaresViz + +
+ +* Version: 0.18.0 +* GitHub: https://github.com/rte-antares-rpackage/antaresViz +* Source code: https://github.com/cran/antaresViz +* Date/Publication: 2023-09-25 09:50:09 UTC +* Number of recursive dependencies: 158 + +Run `revdepcheck::revdep_details(, "antaresViz")` for more info + +
+ +## Newly broken + +* checking whether package 'antaresViz' can be installed ... ERROR + ``` + Installation failed. + See 'D:/Users/berthetcle/Documents/Travail/Projets/packages/antaresRead/revdep/checks/antaresViz/new/antaresViz.Rcheck/00install.out' for details. + ``` + +## Installation + +### Devel + +``` +* installing *source* package 'antaresViz' ... +** package 'antaresViz' correctement décompressé et sommes MD5 vérifiées +** using staged installation +** R +** inst +** byte-compile and prepare package for lazy loading +Messages d'avis : +1: le package 'spMaps' a été compilé avec la version R 4.2.3 +2: le package 'sf' a été compilé avec la version R 4.2.3 +3: le package 'sp' a été compilé avec la version R 4.2.3 +Error in eval(exprs[i], envir) : + objet '.requireRhdf5_Antares' introuvable +Erreur : impossible de charger le code R depuis le package 'antaresViz' +Exécution arrêtée +ERROR: lazy loading failed for package 'antaresViz' +* removing 'D:/Users/berthetcle/Documents/Travail/Projets/packages/antaresRead/revdep/checks/antaresViz/new/antaresViz.Rcheck/antaresViz' + + +``` +### CRAN + +``` +* installing *source* package 'antaresViz' ... +** package 'antaresViz' correctement décompressé et sommes MD5 vérifiées +** using staged installation +** R +** inst +** byte-compile and prepare package for lazy loading +Messages d'avis : +1: le package 'spMaps' a été compilé avec la version R 4.2.3 +2: le package 'sf' a été compilé avec la version R 4.2.3 +3: le package 'sp' a été compilé avec la version R 4.2.3 +... +** testing if installed package can be loaded from temporary location +Avis : le package 'spMaps' a été compilé avec la version R 4.2.3 +Avis : le package 'sf' a été compilé avec la version R 4.2.3 +Avis : le package 'sp' a été compilé avec la version R 4.2.3 +** testing if installed package can be loaded from final location +Avis : le package 'spMaps' a été compilé avec la version R 4.2.3 +Avis : le package 'sf' a été compilé avec la version R 4.2.3 +Avis : le package 'sp' a été compilé avec la version R 4.2.3 +** testing if installed package keeps a record of temporary installation path +* DONE (antaresViz) + + +``` diff --git a/revdep/problems.md b/revdep/problems.md index 9a207363..46385cc2 100644 --- a/revdep/problems.md +++ b/revdep/problems.md @@ -1 +1,73 @@ -*Wow, no problems at all. :)* \ No newline at end of file +# antaresViz + +
+ +* Version: 0.18.0 +* GitHub: https://github.com/rte-antares-rpackage/antaresViz +* Source code: https://github.com/cran/antaresViz +* Date/Publication: 2023-09-25 09:50:09 UTC +* Number of recursive dependencies: 158 + +Run `revdepcheck::revdep_details(, "antaresViz")` for more info + +
+ +## Newly broken + +* checking whether package 'antaresViz' can be installed ... ERROR + ``` + Installation failed. + See 'D:/Users/berthetcle/Documents/Travail/Projets/packages/antaresRead/revdep/checks/antaresViz/new/antaresViz.Rcheck/00install.out' for details. + ``` + +## Installation + +### Devel + +``` +* installing *source* package 'antaresViz' ... +** package 'antaresViz' correctement décompressé et sommes MD5 vérifiées +** using staged installation +** R +** inst +** byte-compile and prepare package for lazy loading +Messages d'avis : +1: le package 'spMaps' a été compilé avec la version R 4.2.3 +2: le package 'sf' a été compilé avec la version R 4.2.3 +3: le package 'sp' a été compilé avec la version R 4.2.3 +Error in eval(exprs[i], envir) : + objet '.requireRhdf5_Antares' introuvable +Erreur : impossible de charger le code R depuis le package 'antaresViz' +Exécution arrêtée +ERROR: lazy loading failed for package 'antaresViz' +* removing 'D:/Users/berthetcle/Documents/Travail/Projets/packages/antaresRead/revdep/checks/antaresViz/new/antaresViz.Rcheck/antaresViz' + + +``` +### CRAN + +``` +* installing *source* package 'antaresViz' ... +** package 'antaresViz' correctement décompressé et sommes MD5 vérifiées +** using staged installation +** R +** inst +** byte-compile and prepare package for lazy loading +Messages d'avis : +1: le package 'spMaps' a été compilé avec la version R 4.2.3 +2: le package 'sf' a été compilé avec la version R 4.2.3 +3: le package 'sp' a été compilé avec la version R 4.2.3 +... +** testing if installed package can be loaded from temporary location +Avis : le package 'spMaps' a été compilé avec la version R 4.2.3 +Avis : le package 'sf' a été compilé avec la version R 4.2.3 +Avis : le package 'sp' a été compilé avec la version R 4.2.3 +** testing if installed package can be loaded from final location +Avis : le package 'spMaps' a été compilé avec la version R 4.2.3 +Avis : le package 'sf' a été compilé avec la version R 4.2.3 +Avis : le package 'sp' a été compilé avec la version R 4.2.3 +** testing if installed package keeps a record of temporary installation path +* DONE (antaresViz) + + +``` diff --git a/tests/testthat/helper_init.R b/tests/testthat/helper_init.R index 6f99f670..54962286 100644 --- a/tests/testthat/helper_init.R +++ b/tests/testthat/helper_init.R @@ -65,54 +65,54 @@ if (sourcedir != "") { untar(file.path(sourcedir, studies[s]), exdir = file.path(path0, studies_names[s])) } - if(.requireRhdf5_Antares(stopP = FALSE) & .runH5Test){ - - path_v6 <- file.path(path0, "antares-test-study-v6") - opts <- setSimulationPath(file.path(path_v6, "/test_case")) - suppressMessages({ - suppressWarnings({ - - #On cran we have only 2 threads so nbCore <- 1 - if(.runH5Test){ - nbCoresTestHelper <- 4 - }else{ - nbCoresTestHelper <- 1 - } - writeAntaresH5(path = path_v6, - misc = TRUE, thermalAvailabilities = TRUE, - hydroStorage = TRUE, hydroStorageMaxPower = TRUE, reserve = TRUE, - linkCapacity = TRUE,mustRun = TRUE, thermalModulation = TRUE, - overwrite=TRUE, nbCores = nbCoresTestHelper) - }) - }) - - #if you change the tar file then you must also change this file - # h5file <- "20190321-2217eco-test.h5" - h5file <- "20180423-1734eco-test.h5" - - deprintize<-function(f){ - return(function(...) {capture.output(w<-f(...));return(w);}); - } - - silentf <- deprintize(showAliases) - - alias <- silentf()$name - alias <- as.character(alias) - - - - timeStep <- c("hourly", "daily", "weekly", "monthly", "annual") - - assign("silentf", silentf, envir = globalenv()) - assign("tpDir", path_v6, envir = globalenv()) - assign("pathF", file.path(path_v6, "/", h5file), envir = globalenv()) - assign("h5file", h5file, envir = globalenv()) - assign("alias", alias, envir = globalenv()) - assign("compareValue", compareValue, envir = globalenv()) - assign("timeStep", timeStep, envir = globalenv()) - assign("optsG", opts, envir = globalenv()) - - } + # if(.requireRhdf5_Antares(stopP = FALSE) & .runH5Test){ + # + # path_v6 <- file.path(path0, "antares-test-study-v6") + # opts <- setSimulationPath(file.path(path_v6, "/test_case")) + # suppressMessages({ + # suppressWarnings({ + # + # #On cran we have only 2 threads so nbCore <- 1 + # if(.runH5Test){ + # nbCoresTestHelper <- 4 + # }else{ + # nbCoresTestHelper <- 1 + # } + # writeAntaresH5(path = path_v6, + # misc = TRUE, thermalAvailabilities = TRUE, + # hydroStorage = TRUE, hydroStorageMaxPower = TRUE, reserve = TRUE, + # linkCapacity = TRUE,mustRun = TRUE, thermalModulation = TRUE, + # overwrite=TRUE, nbCores = nbCoresTestHelper) + # }) + # }) + # + # #if you change the tar file then you must also change this file + # # h5file <- "20190321-2217eco-test.h5" + # h5file <- "20180423-1734eco-test.h5" + # + # deprintize<-function(f){ + # return(function(...) {capture.output(w<-f(...));return(w);}); + # } + # + # silentf <- deprintize(showAliases) + # + # alias <- silentf()$name + # alias <- as.character(alias) + # + # + # + # timeStep <- c("hourly", "daily", "weekly", "monthly", "annual") + # + # assign("silentf", silentf, envir = globalenv()) + # assign("tpDir", path_v6, envir = globalenv()) + # assign("pathF", file.path(path_v6, "/", h5file), envir = globalenv()) + # assign("h5file", h5file, envir = globalenv()) + # assign("alias", alias, envir = globalenv()) + # assign("compareValue", compareValue, envir = globalenv()) + # assign("timeStep", timeStep, envir = globalenv()) + # assign("optsG", opts, envir = globalenv()) + # + # } assign( x = "studyPathS", diff --git a/tests/testthat/test-h5ReadAntares.R b/tests/testthat/test-h5ReadAntares.R deleted file mode 100644 index 1672b2c0..00000000 --- a/tests/testthat/test-h5ReadAntares.R +++ /dev/null @@ -1,175 +0,0 @@ -context(".h5ReadAntares") - -if(.requireRhdf5_Antares(stopP = FALSE) & .runH5Test){ - sapply(pkgEnv$allCompute, function(X){ - test_that(paste0("Select : ", X, " timeStep : "),{ - skip_according_to_options() - - param1 <- list(path = pathF, areas = "a", mcYears = 1, select = X) - param2 <- list(path = pathF, areas = "a", mcYears = 1) - param2[[X]] <- TRUE - testthat::expect_true(identical(do.call(.h5ReadAntares, param1), - do.call(.h5ReadAntares, param2))) - }) - }) - - - ##Test - paramComparaison <- list( - areasAll = list(areas = "all"), - linksAll = list(links = "all"), - clustersAll = list(clusters = "all"), - districtsAll = list(districts = "all"), - areasAllMc1 = list(areas = "all", mcYears = 1), - linksAllMc1 = list(links = "all", mcYears = 1), - clustersAllMc1 = list(clusters = "all", mcYears = 1), - districtsAllMc1 = list(districts = "all", mcYears = 1), - areasAllMcAll = list(areas = "all", mcYears = "all"), - linksAllMcAll = list(links = "all", mcYears = "all"), - clustersAllMcAll = list(clusters = "all", mcYears = "all"), - districtsAllMcAll = list(districts = "all", mcYears = "all"), - areasaMcAll = list(area = "a", mcYears = "all"), - linksBCMcAll = list(links = "b - c", mcYears = "all"), - clustersaMcAll = list(clusters = "a", mcYears = "all"), - districtsABMcAll = list(districts = "a and b", mcYears = "all"), - linksFolowIn = list(links = "all", select = "FLOW LIN."), - areasSelectAll = list(areas = "all", select = "all"), - linksSelectAll = list(links = "all", select = "all"), - clusterSelectAll = list(clusters = "all", select = "all"), - districtsSelectAll = list(districts = "all", select = "all"), - allData = list(areas = "all", links = "all", clusters = "all", districts = "all"), - allDataMc1 = list(areas = "all", links = "all", clusters = "all", districts = "all", mcYears = 1), - allDataMc2 = list(areas = "all", links = "all", clusters = "all", districts = "all", mcYears = 2), - allDataMcAll = list(areas = "all", links = "all", clusters = "all", districts = "all", mcYears = "all"), - hourly = list(areas = "all", links = "all", clusters = "all", districts = "all", timeStep = "hourly"), - daily = list(areas = "all", links = "all", clusters = "all", districts = "all", timeStep = "daily"), - weekly = list(areas = "all", links = "all", clusters = "all", districts = "all", timeStep = "weekly"), - monthly = list(areas = "all", links = "all", clusters = "all", districts = "all", timeStep = "monthly"), - annual = list(areas = "all", links = "all", clusters = "all", districts = "all", timeStep = "annual") - ) - - sapply(names(paramComparaison), function(Z){ - test_that(paste(Z), { - skip_according_to_options() - - param1 <- paramComparaison[[Z]] - param2 <- param1 - - ##Silent - param1$showProgress <- FALSE - param2$perf <- FALSE - - ##End silent - param2$path <- pathF - - DF1 <- suppressWarnings({do.call(readAntares, param1)}) - DF2 <- do.call(.h5ReadAntares, param2) - expect_true(all(unlist(compareValue(DF1, DF2)))) - }) - }) - - test_that("Show perf", { - skip_according_to_options() - - param1 <- list(areas = "all") - param2 <- param1 - - ##Silent - param1$showProgress <- FALSE - param2$perf <- FALSE - - ##End silent - param2$path <- pathF - DF1 <- suppressWarnings({do.call(readAntares, param1)}) - DF2 <- do.call(.h5ReadAntares, param2) - expect_true(all(unlist(compareValue( DF1,DF2)))) - }) - - test_that("Show perf multi request", { - skip_according_to_options() - - param1 <- list(areas = "all", links = "all") - param2 <- param1 - - ##Silent - param1$showProgress <- FALSE - param2$perf <- FALSE - - ##End silent - param2$path <- pathF - DF1 <- suppressWarnings({do.call(readAntares, param1)}) - DF2 <- do.call(.h5ReadAntares, param2) - expect_true(all(unlist(compareValue( DF1,DF2)))) - }) - - - - #Test alias request - for(i in alias){ - paramComparaison[[i]] <- list(select = i) - } - - - #Test remove - for(i in alias){ - var <- strsplit(as.character(silentf(i)$select[1]), ",")[[1]] - var <- gsub("^ ", "",var) - for(j in var) - { - minus <- paste0("-", j) - paramComparaison[[paste(i,minus)]] <- list(select = c(i, minus)) - } - } - - cgtrl <- sapply("hourly", function(Z){ - ctrl <- sapply(names(paramComparaison), function(X){ - oldw <- getOption("warn") - options(warn = -1) - - test_that(paste(X, Z), { - skip_according_to_options() - - param1 <- paramComparaison[[X]] - param1$timeStep <- Z - param2 <- param1 - - ##Silent - param1$showProgress <- FALSE - param2$perf <- FALSE - - ##End silent - param2$path <- pathF - DF1 <- suppressWarnings({do.call(readAntares, param1)}) - DF2 <- do.call(.h5ReadAntares, param2) - if(!is(DF1, "antaresDataList")) - { - setorderv(DF1, getIdCols(DF1)) - }else{ - for(i in 1:length(DF1)){ - setorderv(DF1[[i]], getIdCols(DF1[[i]])) - } - } - if(!is(DF2, "antaresDataList")) - { - setorderv(DF2, getIdCols(DF2)) - }else{ - for(i in 1:length(DF2)){ - setorderv(DF2[[i]], getIdCols(DF2[[i]])) - } - } - expect_true(all(unlist(compareValue( DF1,DF2)))) - }) - invisible() - options(warn = oldw) - }) - invisible() - }) - - test_that("Bad path", { - skip_according_to_options() - - expect_error(.h5ReadAntares("toto"), "File toto not exist.") - - }) - -} diff --git a/tests/testthat/test-h5_nodata.R b/tests/testthat/test-h5_nodata.R deleted file mode 100644 index 4b0de6e0..00000000 --- a/tests/testthat/test-h5_nodata.R +++ /dev/null @@ -1,14 +0,0 @@ -context("h5 : No data") - -if(.requireRhdf5_Antares(stopP = FALSE) & .runH5Test){ - test_that("h5 : no data", { - skip_according_to_options() - - rhdf5::h5createFile("testnodata.h5") - rhdf5::h5createGroup("testnodata.h5", "hourly") - DF1 <- .h5ReadAntares("testnodata.h5", areas = "all", links = "all", clusters = "all", districts = "all") - rhdf5::h5closeAll() - expect_true(length(DF1) == 0) - unlink("testnodata.h5") - }) -} diff --git a/tests/testthat/test-h5_readInputs.R b/tests/testthat/test-h5_readInputs.R deleted file mode 100644 index ebc9927b..00000000 --- a/tests/testthat/test-h5_readInputs.R +++ /dev/null @@ -1,42 +0,0 @@ -context("h5 : read inputs") - -if(.requireRhdf5_Antares(stopP = FALSE) & .runH5Test){ - test_that("h5 : h5ReadBindingConstraints", { - skip_according_to_options() - - optsH5 <- setSimulationPathH5(tpDir, h5file) - re1 <- h5ReadBindingConstraints(optsH5) - re2 <- antaresRead::readBindingConstraints(opts) - for(i in 1:length(re1)){ - re1[[i]]$values <- data.frame(re1[[i]]$values ) - re2[[i]]$values <- data.frame(re2[[i]]$values ) - - } - expect_true(identical(re1, re2)) - }) - - - test_that("h5 : h5ReadLayout", { - skip_according_to_options() - - optsH5 <- setSimulationPathH5(tpDir, h5file) - re1 <- h5ReadLayout(optsH5) - re2 <- antaresRead::readLayout(opts) - - for(i in 1:length(re1)){ - re1[[i]] <- data.frame(re1[[i]]) - re2[[i]] <- data.frame(re2[[i]]) - } - expect_true(identical(re1, re2)) - }) - - test_that("h5 : h5ReadClusterDesc", { - skip_according_to_options() - - optsH5 <- setSimulationPathH5(tpDir, h5file) - re1 <- data.frame(h5ReadClusterDesc(optsH5)) - re2 <- data.frame(antaresRead::readClusterDesc(opts)) - expect_true(identical(re1, re2)) - }) - -} diff --git a/tests/testthat/test-h5_setSimulationPathH5.R b/tests/testthat/test-h5_setSimulationPathH5.R deleted file mode 100644 index 32cfe327..00000000 --- a/tests/testthat/test-h5_setSimulationPathH5.R +++ /dev/null @@ -1,19 +0,0 @@ -context("h5 : setSimulationPathH5") - -if(.requireRhdf5_Antares(stopP = FALSE) & .runH5Test){ - test_that("h5 : identical setSimulationPathH5", { - skip_according_to_options() - - identical(setSimulationPathH5(tpDir), setSimulationPathH5(tpDir, 1)) - expect_identical(setSimulationPathH5(tpDir), setSimulationPathH5(tpDir, 1)) - }) - - test_that("h5 : Error no file", { - skip_according_to_options() - - expect_error(setSimulationPathH5("badfilename"), - "Invalid path argument. File not found. Must be a .h5 file or a repertory with .h5 file(s)", fixed=TRUE) - }) - - -} diff --git a/tests/testthat/test-h5_write.R b/tests/testthat/test-h5_write.R deleted file mode 100644 index c823c3b7..00000000 --- a/tests/testthat/test-h5_write.R +++ /dev/null @@ -1,61 +0,0 @@ -context("h5 : write data") - -# for use travis in parallel -Sys.unsetenv("R_TESTS") - -if(.requireRhdf5_Antares(stopP = FALSE) & .runH5Test){ - tpDir2 <- gsub("[\\]", "/", tpDir) - tptpDir <- file.path(tpDir2, "/tpDir") - - dir.create(tptpDir) - test_that("h5 : write more than one studies mono thread", { - skip_according_to_options() - - writeAntaresH5(path = tptpDir, timeSteps = "annual", - writeAllSimulations = TRUE, nbCores = 1, opts = optsG) - - }) - VV <- utils::sessionInfo() - DoPar <- as.numeric(paste0(VV$R.version$major, VV$R.version$minor))>34 - - if(DoPar) - { - test_that("h5 : overwrite + alldata + multi-thread", { - skip_on_cran() - skip_according_to_options() - - writeAntaresH5(path = tptpDir, overwrite = TRUE, allData = TRUE, - timeSteps = "annual", writeAllSimulations = TRUE, - nbCores = 2, opts = optsG) - filesTptpDir<-dir(tptpDir) - expect_true(TRUE %in% grepl("h5", filesTptpDir)) - - }) - } - - test_that("h5 : overwrite + removeVirtualAreas", { - skip_according_to_options() - - writeAntaresH5(path = tptpDir, - overwrite = TRUE, - opts = optsG, - timeSteps = "hourly", - removeVirtualAreas = TRUE, - storageFlexibility = "c", - nbCores = 1) - filesTptpDir<-dir(tptpDir) - expect_true(TRUE %in% grepl("h5", filesTptpDir)) - - }) - - - unlink(tptpDir, recursive = TRUE) - - test_that("h5 : Bad path", { - skip_according_to_options() - - expect_error( writeAntaresH5(path='badPath'), "Folder badPath not found.") - - }) - -} diff --git a/tests/testthat/test-viewAntares.R b/tests/testthat/test-viewAntares.R index 7e0290f5..6a67ba3c 100644 --- a/tests/testthat/test-viewAntares.R +++ b/tests/testthat/test-viewAntares.R @@ -1,45 +1,45 @@ -context("viewAntares") - -sapply(studyPathS, function(studyPath){ - -opts <- setSimulationPath(studyPath) - -# describe("viewAntares", { -# with_mock( -# `utils::View` = function(x, title) {print(title)}, -# { -# it("views an antaresDataTable", { -# data <- readAntares(timeStep = "annual", select = "LOAD", showProgress = FALSE) -# expect_output(viewAntares(data), "data") -# }) -# -# it("views an antaresDataList", { -# data <- readAntares("all", "all", timeStep = "annual", -# select = c("LOAD", "FLOW LIN."), showProgress = FALSE) -# expect_output(viewAntares(data), "data\\$areas") -# expect_output(viewAntares(data), "data\\$links") -# }) -# } -# ) +# context("viewAntares") +# +# sapply(studyPathS, function(studyPath){ # -# with_mock( -# `utils::View` = function(x, title) {return(NULL)}, -# { -# it("displays a warning if there is more than 100 columns", { -# data <- readAntares(timeStep = "annual", showProgress = FALSE) -# expect_warning(viewAntares(data), "100 columns") -# }) -# } -# ) +# opts <- setSimulationPath(studyPath) +# +# # describe("viewAntares", { +# # with_mock( +# # `utils::View` = function(x, title) {print(title)}, +# # { +# # it("views an antaresDataTable", { +# # data <- readAntares(timeStep = "annual", select = "LOAD", showProgress = FALSE) +# # expect_output(viewAntares(data), "data") +# # }) +# # +# # it("views an antaresDataList", { +# # data <- readAntares("all", "all", timeStep = "annual", +# # select = c("LOAD", "FLOW LIN."), showProgress = FALSE) +# # expect_output(viewAntares(data), "data\\$areas") +# # expect_output(viewAntares(data), "data\\$links") +# # }) +# # } +# # ) +# # +# # with_mock( +# # `utils::View` = function(x, title) {return(NULL)}, +# # { +# # it("displays a warning if there is more than 100 columns", { +# # data <- readAntares(timeStep = "annual", showProgress = FALSE) +# # expect_warning(viewAntares(data), "100 columns") +# # }) +# # } +# # ) +# # }) # }) -}) -if(.requireRhdf5_Antares(stopP = FALSE) & .runH5Test){ - rhdf5::h5closeAll() -} - -if(.requireRhdf5_Antares(stopP = FALSE) & .runH5Test){ - if(dir.exists(tpDir)) - { - unlink(tpDir, recursive = TRUE) - } -} +# if(.requireRhdf5_Antares(stopP = FALSE) & .runH5Test){ +# rhdf5::h5closeAll() +# } +# +# if(.requireRhdf5_Antares(stopP = FALSE) & .runH5Test){ +# if(dir.exists(tpDir)) +# { +# unlink(tpDir, recursive = TRUE) +# } +# }