Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…resRead into release/v8.7.0
  • Loading branch information
BERTHET Clement (Externe) committed Feb 16, 2024
2 parents 74b64be + 505c75a commit ed8f231
Show file tree
Hide file tree
Showing 87 changed files with 147 additions and 14,165 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]
release:
types: [published]
workflow_dispatch:

name: pkgdown

jobs:
pkgdown:
runs-on: ubuntu-latest
# Only restrict concurrency for non-PR jobs
concurrency:
group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }}
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
permissions:
contents: write
steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::pkgdown, local::.
needs: website

- name: Build site
run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
shell: Rscript {0}

- name: Deploy to GitHub pages 🚀
if: github.event_name != 'pull_request'
uses: JamesIves/[email protected]
with:
clean: false
branch: gh-pages
folder: docs
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ revdep/library/
/doc/
/Meta/
*.Rproj
docs
4 changes: 3 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ Authors@R: c(
person("Etienne", "Sanchez", role = "ctb"),
person("Assil", "Mansouri", role = "ctb"),
person("Clement", "Berthet", role = "ctb"),
person("Kamel", "Kemiha", role = "ctb"),
person("Abdallah", "Mahoudi", role = "ctb"),
person("RTE", role = "cph")
)
Description: Import, manipulate and explore results generated by 'Antares', a
powerful open source software developed by RTE (Réseau de Transport d’Électricité) to simulate and study electric power systems
(more information about 'Antares' here : <https://antares-simulator.org/>).
URL: https://github.com/rte-antares-rpackage/antaresRead
URL: https://github.com/rte-antares-rpackage/antaresRead, https://rte-antares-rpackage.github.io/antaresRead/
BugReports: https://github.com/rte-antares-rpackage/antaresRead/issues
License: GPL (>= 2) | file LICENSE
Imports:
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ BUGFIXES :
- returns an API exception if the requested study ID is incorrect
- `simulation` the simulation parameter works with negative values within the limit of the number of simulations
* correction in `readClusterDesc()` calls to add "opts"
* `readAntares()` :
- returns the right column names for details-timeStep.txt and details-res-timeStep.txt
* Correction in `.formatlist()`, read N-level list instead of 2.



# antaresRead 2.6.0
Expand Down
96 changes: 68 additions & 28 deletions R/importOutput.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#' is determined by the arguments "folder" and "file"
#' - "areas", "values" => areas
#' - "areas", "details" => clusters
#' - "areas", "details-res" => renewables clusters
#' - "links", "values" => links
#'
#' @return
Expand Down Expand Up @@ -277,6 +278,62 @@
)
}


#' .get_value_columns_details_file
#'
#' Private function used to get the column names for the details-timeStep.txt or details-res-timeStep.txt.
#' Used in .importOutputForClusters() and .importOutputForResClusters()
#' From the opts, we detect which outputs the user decides to take
#'
#' @return
#' a vector
#'
#' @noRd
#'
.get_value_columns_details_file <- function(opts, type) {

if(type == "details") {
# Order is important. There is a correspondance between elements.
all_thematic_variables <- c("DTG by plant", "NP Cost by plant", "NODU by plant")
colNames <- c("production", "NP Cost", "NODU")
if (opts$antaresVersion >= 830){
all_thematic_variables <- c(all_thematic_variables, "Profit by plant")
colNames <- c(colNames, "profit")
}
} else if(type == "details-res") {
# Order is important. There is a correspondance between elements.
all_thematic_variables <- c("RES generation by plant")
colNames <- c("production")
}
# With thematic-trimming enabled
if (opts$parameters$general$`thematic-trimming`) {
if ("variables selection" %in% names(opts$parameters)) {
var_selection <- opts$parameters$`variables selection`
selection_type <- unique(names(var_selection))
allowed_selection_type <- c("select_var -", "select_var +")
# Filter the vector to avoid other properties (for example : selected_vars_reset)
selection_type <- intersect(selection_type, allowed_selection_type)
# List with a repeated name
var_selection <- var_selection[which(names(var_selection) == selection_type)]
selected_variables <- unlist(var_selection, use.names = FALSE)
# Index of the variables found in the section "variables selection"
idx_vars <- which(all_thematic_variables %in% selected_variables)
if (length(idx_vars) > 0) {
if (selection_type == "select_var -") {
# vars to remove
colNames <- colNames[-idx_vars]
} else if (selection_type == "select_var +") {
# vars to keep
colNames <- colNames[idx_vars]
}
}
}
}

return(colNames)
}


#' .importOutputForClusters
#'
#' Private function used to import the output for the thermal clusters of one area
Expand All @@ -295,6 +352,7 @@
# To improve greatly the performance we use our knowledge of the position of
# the columns instead of using more general functions like dcast.
reshapeFun <- function(x) {

# Get cluster names
n <- names(x)
idx <- ! n %in% pkgEnv$idVars
Expand All @@ -304,28 +362,19 @@
idVarsId <- which(!idx)
idVarsNames <- n[idVarsId]

# Get final value columns
if (sum(idx) / length(clusterNames) == 4) {
colNames <- c("production", "NP Cost", "NODU", "profit")
} else if (sum(idx) / length(clusterNames) == 3) {
colNames <- c("production", "NP Cost", "NODU")
} else if (sum(idx) / length(clusterNames) == 2) {
colNames <- c("production", "NP Cost")
} else {
colNames <- c("production")
}
# Column names of the output table
colNames <- .get_value_columns_details_file(opts, "details")

# Loop over clusters
nclusters <- length(clusterNames)
ncols <- length(colNames)

res <- llply(1:nclusters, function(i) {
dt <- x[, c(nclusters * 0:(ncols - 1) + i, idVarsId), with = FALSE]
dt <- x[, c(nclusters * 0:(length(colNames) - 1) + i, idVarsId), with = FALSE]
setnames(dt, c(colNames, idVarsNames))
dt[, cluster := as.factor(clusterNames[i])]
dt
})

rbindlist(res)
}

Expand Down Expand Up @@ -436,9 +485,9 @@

res
}

}


#' .importOutputForResClusters
#'
#' Private function used to import the output for the renewable clusters of one area
Expand All @@ -457,6 +506,7 @@
# To improve greatly the performance we use our knowledge of the position of
# the columns instead of using more general functions like dcast.
reshapeFun <- function(x) {

# Get cluster names
n <- names(x)
idx <- ! n %in% pkgEnv$idVars
Expand All @@ -466,23 +516,14 @@
idVarsId <- which(!idx)
idVarsNames <- n[idVarsId]

# Get final value columns
# Get final value columns
# colNames <- c("resProduction")
if (sum(idx) / length(clusterNames) == 3) {
colNames <- c("production", "NP Cost", "NODU")
} else if (sum(idx) / length(clusterNames) == 2) {
colNames <- c("production", "NP Cost")
} else {
colNames <- c("production")
}
# Column names of the output table
colNames <- .get_value_columns_details_file(opts, "details-res")

# Loop over clusters
nclusters <- length(clusterNames)
ncols <- length(colNames)

res <- llply(1:nclusters, function(i) {
dt <- x[, c(nclusters * 0:(ncols - 1) + i, idVarsId), with = FALSE]
dt <- x[, c(nclusters * 0:(length(colNames) - 1) + i, idVarsId), with = FALSE]
setnames(dt, c(colNames, idVarsNames))
dt[, cluster := as.factor(clusterNames[i])]
dt
Expand All @@ -496,10 +537,9 @@
mcYears, showProgress, opts, reshapeFun, sameNames = FALSE,
objectDisplayName = "clustersRe", parallel = parallel)
)


}


#' .importOutputForBindingConstraints
#'
#' Private function used to import the output for binding constraints.
Expand Down
24 changes: 13 additions & 11 deletions R/readIniFile.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ readIniFile <- function(file, stringsAsFactors = FALSE) {
pairs <- X[seq(starts[i], ends[i])]
pairs <- pairs[pairs != ""]
pairs <- strsplit(pairs, "=")

key <- lapply(pairs, `[`, 1)
key <- unlist(key)
key <- trimws(key)

value <- lapply(pairs, `[`, 2)
value <- as.list(trimws(unlist(value)))
value <- lapply(value, function(x) {
Expand All @@ -83,7 +83,7 @@ readIniFile <- function(file, stringsAsFactors = FALSE) {
utils::type.convert(x, as.is = TRUE)
}
})

L[[i]] <- value
names(L[[i]]) <- key
}
Expand Down Expand Up @@ -131,15 +131,17 @@ readIniAPI <- function(study_id, path, host, token = NULL) {
if(is.name(x[index_list]))
return(x)
else{
elements <- unlist(x[index_list], use.names = FALSE)
if(class(elements)%in%"character"){
elements <- paste("'", elements, "'", sep="", collapse=",")
elements <- paste0("[", elements, "]")
}else{
elements <- paste0(elements, collapse= ",")
elements <- paste0("[", elements, "]")
for (sub_list in index_list){
elements <- unlist(x[sub_list], use.names = FALSE)
if(class(elements)%in%"character"){
elements <- paste("'", elements, "'", sep="", collapse=",")
elements <- paste0("[", elements, "]")
}else{
elements <- paste0(elements, collapse= ",")
elements <- paste0("[", elements, "]")
}
x[sub_list] <- elements
}
x[index_list] <- elements
x
}
})
Expand Down
Loading

0 comments on commit ed8f231

Please sign in to comment.