diff --git a/DESCRIPTION b/DESCRIPTION index df75780..88105ff 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: antaresViz Type: Package Title: Antares Visualizations -Version: 0.18.0 +Version: 0.18.1 Authors@R: c( person("Tatiana", "Vargas", email = "tatiana.vargas@rte-france.com", role = c("aut", "cre")), person("Jalal-Edine", "Zawam", role = "aut"), @@ -45,12 +45,12 @@ Imports: leaflet.minicharts (>= 0.5.3), assertthat, rAmCharts, - utils + utils, + lifecycle RoxygenNote: 7.2.2 Suggests: testthat, covr, - rhdf5 (>= 2.20.2), ggplot2, hexbin, knitr, diff --git a/NAMESPACE b/NAMESPACE index ac472e7..48d300b 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -56,6 +56,9 @@ importFrom(grDevices,rainbow) importFrom(grDevices,rgb) importFrom(graphics,par) importFrom(graphics,plot.default) +importFrom(lifecycle,deprecate_warn) +importFrom(lifecycle,deprecated) +importFrom(lifecycle,is_present) importFrom(methods,is) importFrom(plotly,add_bars) importFrom(plotly,add_heatmap) diff --git a/NEWS.md b/NEWS.md index ee6a721..52ee7dc 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,8 @@ Copyright 2016 RTE Reseau de transport d'electricite +# antaresViz 0.18.1 +* delete package dependecies `rhdf5` + # antaresViz 0.18.0 * fix deprecated dependencies (issue #200) * packages `rgeos`, `raster` removed and replaced by `sf` diff --git a/R/graph_utils.R b/R/graph_utils.R index f730f23..d41cd4c 100644 --- a/R/graph_utils.R +++ b/R/graph_utils.R @@ -289,71 +289,6 @@ } - - -#' List of h5 params -#' -#' @param X_I, list -#' @param xyCompare, character -#' -#' @noRd -.h5ParamList <- function(X_I, xyCompare, h5requestFilter = NULL){ - listParam <- lapply(1:length(X_I), function(i){ - x <- X_I[[i]] - if (.isSimOpts(x)){ - tmp <- .h5Inf(x) - h5_filter <- h5requestFilter[[i]] - h5_tables <- c("areas", "districts", "clusters", "links") - if (!is.null(h5_filter)){ - if (!(is.null(h5_filter$areas) & is.null(h5_filter$districts) & - is.null(h5_filter$links) & is.null(h5_filter$clusters))){ - h5_tables <- c("areas", "districts", "clusters", "links") - h5_tables <- h5_tables[which(c(!is.null(h5_filter$areas), !is.null(h5_filter$districts), - !is.null(h5_filter$clusters), !is.null(h5_filter$links)))] - } - } - tmp$tabl <- intersect(tmp$tabl, h5_tables) - rhdf5::H5close() - tmp - }else{ - mcY <- unique(unlist(lapply(x, function(y){unique(y$mcYears)}))) - timeStepS <- attributes(x)$timeStep - tabl <- names(x) - list( - timeStepS = timeStepS, - mcYearS = mcY, - tabl = tabl - ) - } - }) - res <- lapply(.transposeL(listParam), function(x){ - .compareOperation(x, xyCompare) - }) - - res$h5requestFilter <- h5requestFilter - res -} - -#' Load information from h5 file -#' -#' @param x, opts -#' -#' @noRd -.h5Inf <- function(x){ - fid <- rhdf5::H5Fopen(x$h5path) - timeStepS <- .getTimeStep(fid) - timeStepS <- as.character(timeStepS) - mcYearS <- x$mcYears - tabl <- .getTableInH5(fid, timeStepS[1]) - rhdf5::H5Fclose(fid) - xPart = list( - timeStepS = timeStepS, - mcYearS = mcYearS, - tabl = tabl - ) -} - - .transposeL <- function(data){ do.call(c, apply(do.call(rbind, data), 2, list)) } diff --git a/R/h5_utils.R b/R/h5_utils.R index 3405373..b7663b3 100644 --- a/R/h5_utils.R +++ b/R/h5_utils.R @@ -1,64 +1,64 @@ -.convertH5Filtering <- function(h5requestFiltering, x) -{ - if (length(h5requestFiltering) > 0) - { - if (!is.list(h5requestFiltering[[1]])){ - if (!any(c("simOptions", "antaresDataTable") %in% class(x))) - { - h5requestFiltering <- rep(list(h5requestFiltering), length(x)) - }else{ - h5requestFiltering <- list(h5requestFiltering) - } - }else{ - if (inherits(x, "list")){ - if (length(h5requestFiltering) != length(x)){ - h5requestFiltering <- h5requestFiltering[1:length(x) %% length(h5requestFiltering) + 1] - } - } - } - }else{ - if (!any(c("simOptions", "antaresDataTable") %in% class(x))) - { - h5requestFiltering <- replicate(length(x), list()) - }else{ - h5requestFiltering <- replicate(1, list()) - } - } - h5requestFiltering -} +# .convertH5Filtering <- function(h5requestFiltering, x) +# { +# if (length(h5requestFiltering) > 0) +# { +# if (!is.list(h5requestFiltering[[1]])){ +# if (!any(c("simOptions", "antaresDataTable") %in% class(x))) +# { +# h5requestFiltering <- rep(list(h5requestFiltering), length(x)) +# }else{ +# h5requestFiltering <- list(h5requestFiltering) +# } +# }else{ +# if (inherits(x, "list")){ +# if (length(h5requestFiltering) != length(x)){ +# h5requestFiltering <- h5requestFiltering[1:length(x) %% length(h5requestFiltering) + 1] +# } +# } +# } +# }else{ +# if (!any(c("simOptions", "antaresDataTable") %in% class(x))) +# { +# h5requestFiltering <- replicate(length(x), list()) +# }else{ +# h5requestFiltering <- replicate(1, list()) +# } +# } +# h5requestFiltering +# } -.getTableInH5 <- function(fid, timeStep){ - dataExist <- NULL - if (rhdf5::H5Lexists(fid, paste0(timeStep, "/areas"))) - { - dataExist <- c(dataExist, "areas") - } - if (rhdf5::H5Lexists(fid, paste0(timeStep, "/links"))) - { - dataExist <- c(dataExist, "links") - } - if (rhdf5::H5Lexists(fid, paste0(timeStep, "/clusters"))) - { - dataExist <- c(dataExist, "clusters") - } - if (rhdf5::H5Lexists(fid, paste0(timeStep, "/districts"))) - { - dataExist <- c(dataExist, "districts") - } - dataExist -} +# .getTableInH5 <- function(fid, timeStep){ +# dataExist <- NULL +# if (rhdf5::H5Lexists(fid, paste0(timeStep, "/areas"))) +# { +# dataExist <- c(dataExist, "areas") +# } +# if (rhdf5::H5Lexists(fid, paste0(timeStep, "/links"))) +# { +# dataExist <- c(dataExist, "links") +# } +# if (rhdf5::H5Lexists(fid, paste0(timeStep, "/clusters"))) +# { +# dataExist <- c(dataExist, "clusters") +# } +# if (rhdf5::H5Lexists(fid, paste0(timeStep, "/districts"))) +# { +# dataExist <- c(dataExist, "districts") +# } +# dataExist +# } -.getVariablesH5 <- function(fid, timeStep, tables){ - sapply(tables, function(X){ - struct <- .getstructure(fid, paste0(timeStep, "/", X, "/mcInd/", "/structure"))$variable - if ("timeId" %in% struct){ - struct <- struct[struct != "timeId"] - } - struct - }, simplify = FALSE) -} +# .getVariablesH5 <- function(fid, timeStep, tables){ +# sapply(tables, function(X){ +# struct <- .getstructure(fid, paste0(timeStep, "/", X, "/mcInd/", "/structure"))$variable +# if ("timeId" %in% struct){ +# struct <- struct[struct != "timeId"] +# } +# struct +# }, simplify = FALSE) +# } .getClustersNames <- function(fid, timeStep){ unique(unlist(lapply(strsplit(.getstructure(fid, paste0(timeStep, "/clusters/mcInd/structure"))$cluster, "/"), function(X)X[1]))) @@ -98,12 +98,12 @@ ) } -.getTimeStep <- function(fid){ - timeSteps <- sapply(c("hourly", "daily", "weekly", "monthly", "annual"), function(X){ - rhdf5::H5Lexists(fid, X) - }) - names(timeSteps[which(timeSteps == TRUE)]) -} +# .getTimeStep <- function(fid){ +# timeSteps <- sapply(c("hourly", "daily", "weekly", "monthly", "annual"), function(X){ +# rhdf5::H5Lexists(fid, X) +# }) +# names(timeSteps[which(timeSteps == TRUE)]) +# } .compareOperation <- function(a, opType){ if (length(a) == 1) return(unlist(unique(a))) diff --git a/R/h5_utils_plot.R b/R/h5_utils_plot.R index fd2418b..5b8e072 100644 --- a/R/h5_utils_plot.R +++ b/R/h5_utils_plot.R @@ -1,20 +1,20 @@ -.getstructure <- function(fid, strgp){ - 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 -} - -.tryCloseH5 <- function(){ - try(rhdf5::H5close(), silent = TRUE) -} +# .getstructure <- function(fid, strgp){ +# 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 +# } +# +# .tryCloseH5 <- function(){ +# try(rhdf5::H5close(), silent = TRUE) +# } diff --git a/R/map.R b/R/map.R index 9cbba1b..5e07d9b 100644 --- a/R/map.R +++ b/R/map.R @@ -75,7 +75,7 @@ #' @param h5requestFiltering Contains arguments used by default for h5 request, #' typically h5requestFiltering = list(mcYears = 3) #' @inheritParams prodStack -#' +#' @importFrom lifecycle is_present deprecate_warn deprecated #' #' @details #' @@ -181,14 +181,30 @@ plotMap <- function(x, compareOpts = list(), interactive = getInteractivity(), options = plotMapOptions(), - width = NULL, height = NULL, dateRange = NULL, xyCompare = c("union","intersect"), - h5requestFiltering = list(), - timeSteph5 = "hourly", - mcYearh5 = NULL, - tablesh5 = c("areas", "links"), + width = NULL, + height = NULL, + dateRange = NULL, + xyCompare = c("union","intersect"), + h5requestFiltering = deprecated(), + timeSteph5 = deprecated(), + mcYearh5 = deprecated(), + tablesh5 = deprecated(), sizeMiniPlot = FALSE,language = "en", hidden = NULL, ...) { + deprecated_vector_params <- c(lifecycle::is_present(h5requestFiltering), + lifecycle::is_present(timeSteph5), + lifecycle::is_present(mcYearh5), + lifecycle::is_present(tablesh5)) + + if(any(deprecated_vector_params)) + lifecycle::deprecate_warn( + when = "0.18.1", + what = "plotMap(h5requestFiltering)", + details = "all these parameters are relative to the 'rhdf5' package, + which is removed from the dependencies" + ) + .check_x(x) .check_compare_interactive(compare, interactive) @@ -251,7 +267,7 @@ plotMap <- function(x, } # .testXclassAndInteractive(x, interactive) - h5requestFiltering <- .convertH5Filtering(h5requestFiltering = h5requestFiltering, x = x) + # h5requestFiltering <- .convertH5Filtering(h5requestFiltering = h5requestFiltering, x = x) compareOptions <- .compOpts(x, compare) @@ -512,15 +528,15 @@ plotMap <- function(x, if (!interactive) { - listParamH5NoInt <- list( - timeSteph5 = timeSteph5, - mcYearh5 = mcYearh5, - tablesh5 = tablesh5, - h5requestFiltering = h5requestFiltering - ) + # listParamH5NoInt <- list( + # timeSteph5 = timeSteph5, + # mcYearh5 = mcYearh5, + # tablesh5 = tablesh5, + # h5requestFiltering = h5requestFiltering + # ) params <- .getParamsNoInt(x = x, refStudy = refStudy, - listParamH5NoInt = listParamH5NoInt, + listParamH5NoInt = NULL, compare = compare, compareOptions = compareOptions, processFun = processFun, @@ -560,7 +576,7 @@ plotMap <- function(x, { if(!is.null(params)) { - .tryCloseH5() + # .tryCloseH5() # udpate for mw 0.11 & 0.10.1 if(!is.null(params)){ ind <- .id %% length(params$x) @@ -617,82 +633,82 @@ plotMap <- function(x, .giveListFormat(x) }), - h5requestFiltering = mwSharedValue({h5requestFiltering}), + # h5requestFiltering = mwSharedValue({h5requestFiltering}), - paramsH5 = mwSharedValue({ - paramsH5List <- .h5ParamList(X_I = x_in, xyCompare = xyCompare, h5requestFilter = h5requestFiltering) - rhdf5::H5close() - paramsH5List - }), - H5request = mwGroup( - label = .getLabelLanguage("H5request", language), - timeSteph5 = mwSelect( - { - if(length(paramsH5) > 0){ - choices = paramsH5$timeStepS - names(choices) <- sapply(choices, function(x) .getLabelLanguage(x, language)) - } else { - choices <- NULL - } - choices - }, - value = paramsH5$timeStepS[1], - label = .getLabelLanguage("timeStep", language), - multiple = FALSE, .display = !"timeSteph5" %in% hidden - ), - tables = mwSelect( - { - if(length(paramsH5) > 0){ - choices = paramsH5[["tabl"]][paramsH5[["tabl"]] %in% c("areas", "links")] - names(choices) <- sapply(choices, function(x) .getLabelLanguage(x, language)) - } else { - choices <- NULL - } - choices - }, - value = { - if(.initial) {paramsH5[["tabl"]][paramsH5[["tabl"]] %in% c("areas", "links")]} else {NULL} - }, - label = .getLabelLanguage("table", language), multiple = TRUE, - .display = !"tables" %in% hidden - ), - mcYearH5 = mwSelectize( - choices = { - ch <- c("Average" = "", paramsH5[["mcYearS"]]) - names(ch)[1] <- .getLabelLanguage("Average", language) - ch - }, - value = { - if(.initial){paramsH5[["mcYearS"]][1]}else{NULL} - }, - label = .getLabelLanguage("mcYears to be imported", language), - multiple = TRUE, options = list(maxItems = 4), - .display = (!"mcYearH5" %in% hidden & !meanYearH5) - ), - meanYearH5 = mwCheckbox(value = FALSE, - label = .getLabelLanguage("Average mcYear", language), - .display = !"meanYearH5" %in% hidden), - .display = {any(unlist(lapply(x_in, .isSimOpts))) & !"H5request" %in% hidden} - ), - sharerequest = mwSharedValue({ - if(length(meanYearH5) > 0){ - if(meanYearH5){ - list(timeSteph5_l = timeSteph5, mcYearh_l = NULL, tables_l = tables) - } else { - list(timeSteph5_l = timeSteph5, mcYearh_l = mcYearH5, tables_l = tables) - } - } else { - list(timeSteph5_l = timeSteph5, mcYearh_l = mcYearH5, tables_l = tables) - } - }), - x_tranform = mwSharedValue({ - resXT <- .get_x_transform(x_in = x_in, - sharerequest = sharerequest, - refStudy = refStudy, - h5requestFilter = paramsH5$h5requestFilter ) - resXT - - }), + # paramsH5 = mwSharedValue({ + # paramsH5List <- .h5ParamList(X_I = x_in, xyCompare = xyCompare, h5requestFilter = h5requestFiltering) + # rhdf5::H5close() + # paramsH5List + # }), + # H5request = mwGroup( + # label = .getLabelLanguage("H5request", language), + # timeSteph5 = mwSelect( + # { + # if(length(paramsH5) > 0){ + # choices = paramsH5$timeStepS + # names(choices) <- sapply(choices, function(x) .getLabelLanguage(x, language)) + # } else { + # choices <- NULL + # } + # choices + # }, + # value = paramsH5$timeStepS[1], + # label = .getLabelLanguage("timeStep", language), + # multiple = FALSE, .display = !"timeSteph5" %in% hidden + # ), + # tables = mwSelect( + # { + # if(length(paramsH5) > 0){ + # choices = paramsH5[["tabl"]][paramsH5[["tabl"]] %in% c("areas", "links")] + # names(choices) <- sapply(choices, function(x) .getLabelLanguage(x, language)) + # } else { + # choices <- NULL + # } + # choices + # }, + # value = { + # if(.initial) {paramsH5[["tabl"]][paramsH5[["tabl"]] %in% c("areas", "links")]} else {NULL} + # }, + # label = .getLabelLanguage("table", language), multiple = TRUE, + # .display = !"tables" %in% hidden + # ), + # mcYearH5 = mwSelectize( + # choices = { + # ch <- c("Average" = "", paramsH5[["mcYearS"]]) + # names(ch)[1] <- .getLabelLanguage("Average", language) + # ch + # }, + # value = { + # if(.initial){paramsH5[["mcYearS"]][1]}else{NULL} + # }, + # label = .getLabelLanguage("mcYears to be imported", language), + # multiple = TRUE, options = list(maxItems = 4), + # .display = (!"mcYearH5" %in% hidden & !meanYearH5) + # ), + # meanYearH5 = mwCheckbox(value = FALSE, + # label = .getLabelLanguage("Average mcYear", language), + # .display = !"meanYearH5" %in% hidden), + # .display = {any(unlist(lapply(x_in, .isSimOpts))) & !"H5request" %in% hidden} + # ), + # sharerequest = mwSharedValue({ + # if(length(meanYearH5) > 0){ + # if(meanYearH5){ + # list(timeSteph5_l = timeSteph5, mcYearh_l = NULL, tables_l = tables) + # } else { + # list(timeSteph5_l = timeSteph5, mcYearh_l = mcYearH5, tables_l = tables) + # } + # } else { + # list(timeSteph5_l = timeSteph5, mcYearh_l = mcYearH5, tables_l = tables) + # } + # }), + # x_tranform = mwSharedValue({ + # resXT <- .get_x_transform(x_in = x_in, + # sharerequest = sharerequest, + # refStudy = refStudy, + # h5requestFilter = paramsH5$h5requestFilter ) + # resXT + # + # }), ##Stop h5 mcYear = mwSelect( diff --git a/R/zzz.R b/R/zzz.R index d3fdac6..4dbb38e 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -29,7 +29,6 @@ globalVariables( .timeIdToDate <- antaresRead:::.timeIdToDate .getTimeId <- antaresRead:::.getTimeId .mergeByRef <- antaresRead:::.mergeByRef -.requireRhdf5_Antares <- antaresRead:::.requireRhdf5_Antares .checkColumns <- antaresProcessing:::.checkColumns .checkAttrs <- antaresProcessing:::.checkAttrs @@ -309,9 +308,6 @@ colorsVars <- unique(rbindlist(list(colorsVars, col_fr))) timeStepType <- paste("/hourly", categoryVar, sep = "/") nameStructure <- paste0(timeStepType, typeOfData, "/structure") - H5locAntaresh5 <- rhdf5::H5Fopen(name = pathH5) - hourlyDataStructure <- rhdf5::h5read(H5locAntaresh5, name = nameStructure) - if (!is.null(area)){ indexCateroryInstance <- grep(area, hourlyDataStructure$area)[1] }else{ @@ -328,21 +324,4 @@ colorsVars <- unique(rbindlist(list(colorsVars, col_fr))) listIndex <- list(indexTimeId, indexAntVar, indexCateroryInstance, indexMcYear) #debug print(listIndex) - - hourlyData <- rhdf5::h5read( - H5locAntaresh5, - name = paste0(timeStepType, typeOfData, "/data"), - index = listIndex) - - hourlyData[,,,] <- newValue - - rhdf5::h5writeDataset( - obj = hourlyData, - h5loc = H5locAntaresh5, - name = paste0(timeStepType, typeOfData, "/data"), - index = listIndex - ) - - rhdf5::H5Fclose(h5file = H5locAntaresh5) - rhdf5::h5closeAll() } diff --git a/man/plotMap.Rd b/man/plotMap.Rd index f31c3b6..533fd9d 100644 --- a/man/plotMap.Rd +++ b/man/plotMap.Rd @@ -33,10 +33,10 @@ plotMap( height = NULL, dateRange = NULL, xyCompare = c("union", "intersect"), - h5requestFiltering = list(), - timeSteph5 = "hourly", - mcYearh5 = NULL, - tablesh5 = c("areas", "links"), + h5requestFiltering = deprecated(), + timeSteph5 = deprecated(), + mcYearh5 = deprecated(), + tablesh5 = deprecated(), sizeMiniPlot = FALSE, language = "en", hidden = NULL,