Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…aresRead into ant1432/feature
  • Loading branch information
berthetclement committed Jul 10, 2024
2 parents 82438dd + 96cedad commit 48d0a37
Show file tree
Hide file tree
Showing 23 changed files with 704 additions and 152 deletions.
6 changes: 4 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: antaresRead
Type: Package
Title: Import, Manipulate and Explore the Results of an 'Antares' Simulation
Version: 2.7.0
Version: 2.7.1
Authors@R: c(
person("Tatiana", "Vargas", email = "[email protected]", role = c("aut", "cre")),
person("Jalal-Edine", "ZAWAM", role = "aut"),
Expand All @@ -15,6 +15,7 @@ Authors@R: c(
person("Clement", "Berthet", role = "ctb"),
person("Kamel", "Kemiha", role = "ctb"),
person("Abdallah", "Mahoudi", role = "ctb"),
person("Nicolas", "Boitard", role = "ctb"),
person("RTE", role = "cph")
)
Description: Import, manipulate and explore results generated by 'Antares', a
Expand All @@ -40,7 +41,8 @@ Imports:
utils,
memuse,
purrr,
lifecycle
lifecycle,
assertthat
Suggests:
rhdf5 (>= 2.24.0),
testthat,
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export(ponderateMcAggregation)
export(readAntares)
export(readAntaresAreas)
export(readAntaresClusters)
export(readAntaresSTClusters)
export(readBindingConstraints)
export(readClusterDesc)
export(readClusterResDesc)
Expand Down Expand Up @@ -79,6 +80,7 @@ import(doParallel)
import(jsonlite)
import(parallel)
import(plyr)
importFrom(assertthat,assert_that)
importFrom(doParallel,registerDoParallel)
importFrom(grDevices,col2rgb)
importFrom(grDevices,rgb)
Expand Down
30 changes: 28 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
> Copyright © 2016 RTE Réseau de transport d’électricité
# antaresRead 2.7.1 (development)

NEW FEATURES:

* `readInputThermal()` :
- new parameter **areas** to get desired clusters from selected areas.
- new parameter **thermalAvailabilities** to import time series.
* `readInputRES()` new parameter **areas** to get desired clusters from selected areas.
* `setSimulationPath()` return a new parameter `binding` (for studies >= v8.7.0).
It contains a table with group dimensions of time series for binding constraints.
* `readAntares()` new parameter **clustersST** to read (output simulation) short-term clusters
* New function `readAntaresSTClusters()`


BREAKING CHANGES :

* `readInputThermal()` / `readInputRES()` default value when no time series in the selected clusters.

BUGFIXES :

* `readInputThermal()` return data from file data.txt with `thermalData` parameter
* `setSimulationPath()` has also the parameter **areasWithSTClusters** in 'output' mode


# antaresRead 2.7.0

### Breaking changes (Antares v8.7.0) :
Expand All @@ -24,7 +48,7 @@ Dependencies :



# antaresRead 2.6.2 (development)
# antaresRead 2.6.2

BUGFIXES :
* `readIniFile()` : avoid `utils::type.convert` on specific cases (ex : 789e or 123i)
Expand All @@ -46,6 +70,8 @@ BUGFIXES :
BREAKING CHANGES :

* `api_get()` has a new parameter to control JSON file parsing
* `readInputThermal()` default value when no time series in the selected clusters.
* `readInputRES()` default value when no time series in the selected clusters
* `readClusterDesc()`/ `readClusterRESDesc()` / `readClusterSTDesc()`
return empty dataTable and warning if no cluster in Antares study.

Expand All @@ -61,7 +87,7 @@ BREAKING CHANGES (Antares v8.6) :
* `readInputTS()` is now compatible to read time series with :
- "short-term storage"
- "mingen" (pmin hydro value)
* `setSimulationPath()` has new parameter `areasWithSTClusters` (name of area with "st-storage" cluster)
* `setSimulationPath()` has new parameter **areasWithSTClusters** (name of area with "st-storage" cluster)


BUGFIXES :
Expand Down
9 changes: 7 additions & 2 deletions R/importInput.R
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,13 @@

data$area <- area
data$cluster <- cl
data <- data[opts$timeIdMin:opts$timeIdMax]
data$timeId <- opts$timeIdMin:opts$timeIdMax

# index blocks
a <- opts$parameters$general$simulation.start
b <- opts$parameters$general$simulation.end

data <- data[a:b]
data$timeId <- a:b

changeTimeStep(data, timeStep, "daily", fun = "mean")
})
Expand Down
167 changes: 92 additions & 75 deletions R/importOutput.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#' - "areas", "values" => areas
#' - "areas", "details" => clusters
#' - "areas", "details-res" => renewables clusters
#' - "areas", "details-STstorage" => short-term clusters
#' - "links", "values" => links
#'
#' @return
Expand Down Expand Up @@ -281,30 +282,37 @@

#' .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()
#' Private function used to get the column names for the details-timeStep.txt, details-res-timeStep.txt, or details-STstorage-timeStep.txt.
#' Used in .importOutputForClusters(), .importOutputForResClusters(), and .importOutputForSTClusters()
#' From the opts, we detect which outputs the user decides to take
#'
#' @return
#' a vector
#'
#' @importFrom assertthat assert_that
#'
#' @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")
}
assert_that(type %in% c("details","details-res","details-STstorage"))

simulation_variables_names_by_support <- read.table(system.file(
"format_output","simulation_variables_names_by_support.csv",package="antaresRead"
),sep=";",fileEncoding="UTF-8",header = TRUE)

filtered_variables_names <- subset(simulation_variables_names_by_support,DETAILS_FILES_TYPE==type)
if (type=="details" && opts$antaresVersion < 830)
filtered_variables_names <- subset(filtered_variables_names,ANTARES_DISPLAYED_NAME!="Profit by plant")

# Order is important. There is a correspondance between elements
ordered_filtered_variables_names <- filtered_variables_names[
order(filtered_variables_names$ORDINAL_POSITION_BY_TOPIC),
]

all_thematic_variables <- ordered_filtered_variables_names$ANTARES_DISPLAYED_NAME
colNames <- ordered_filtered_variables_names$RPACKAGE_DISPLAYED_NAME

# With thematic-trimming enabled
if (opts$parameters$general$`thematic-trimming`) {
if ("variables selection" %in% names(opts$parameters)) {
Expand Down Expand Up @@ -346,36 +354,8 @@
.importOutputForClusters <- function(areas, timeStep, select = NULL, mcYears = NULL,
showProgress, opts, mustRun = FALSE, parallel) {

# In output files, there is one file per area with the follwing form:
# cluster1-var1 | cluster2-var1 | cluster1-var2 | cluster2-var2
# the following function reshapes the result to have variable cluster in column.
# 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
clusterNames <- tolower(unique(n[idx]))

# Id vars names
idVarsId <- which(!idx)
idVarsNames <- n[idVarsId]

# Column names of the output table
colNames <- .get_value_columns_details_file(opts, "details")

# Loop over clusters
nclusters <- length(clusterNames)

res <- llply(1:nclusters, function(i) {
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)
reshapeFun <- function(x){
.reshape_details_file(x,file_type="details",opts=opts)
}

if (!mustRun) {
Expand Down Expand Up @@ -490,6 +470,47 @@
}


#' .reshape_details_file
#'
#' In output files, there is one file per area with the follwing form:
#' cluster1-var1 | cluster2-var1 | cluster1-var2 | cluster2-var2
#' the following function reshapes the result to have variable cluster in column.
#' To improve greatly the performance we use our knowledge of the position of
#' the columns instead of using more general functions like dcast.
#'
#' @return
#' a data.table
#'
#' @noRd
#'
.reshape_details_file <- function(x,file_type,opts) {

# Get cluster names
n <- names(x)
idx <- ! n %in% pkgEnv$idVars
clusterNames <- tolower(unique(n[idx]))

# Id vars names
idVarsId <- which(!idx)
idVarsNames <- n[idVarsId]

# Column names of the output table
colNames <- .get_value_columns_details_file(opts=opts,type=file_type)

# Loop over clusters
nclusters <- length(clusterNames)

res <- llply(1:nclusters, function(i) {
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)
}


#' .importOutputForResClusters
#'
#' Private function used to import the output for the renewable clusters of one area
Expand All @@ -502,38 +523,11 @@
.importOutputForResClusters <- function(areas, timeStep, select = NULL, mcYears = NULL,
showProgress, opts, parallel) {

# In output files, there is one file per area with the follwing form:
# cluster1-var1 | cluster2-var1 | cluster1-var2 | cluster2-var2
# the following function reshapes the result to have variable cluster in column.
# 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
clusterNames <- tolower(unique(n[idx]))

# Id vars names
idVarsId <- which(!idx)
idVarsNames <- n[idVarsId]

# Column names of the output table
colNames <- .get_value_columns_details_file(opts, "details-res")

# Loop over clusters
nclusters <- length(clusterNames)

res <- llply(1:nclusters, function(i) {
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)
.reshape_details_file(x,file_type="details-res",opts=opts)
}

suppressWarnings(
.importOutput("areas", "details-res", "area", areas, timeStep, NULL,
mcYears, showProgress, opts, reshapeFun, sameNames = FALSE,
Expand All @@ -542,6 +536,29 @@
}


#' .importOutputForSTClusters
#'
#' Private function used to import the output for the short-term clusters of one area
#'
#' @return
#' a data.table
#'
#' @noRd
#'
.importOutputForSTClusters <- function(areas, timeStep, select = NULL, mcYears = NULL,
showProgress, opts, parallel) {

reshapeFun <- function(x) {
.reshape_details_file(x,file_type="details-STstorage",opts=opts)
}

suppressWarnings(
.importOutput("areas", "details-STstorage", "area", areas, timeStep, NULL,
mcYears, showProgress, opts, reshapeFun, sameNames = FALSE,
objectDisplayName = "clustersST", parallel = parallel)
)
}

#' .importOutputForBindingConstraints
#'
#' Private function used to import the output for binding constraints.
Expand Down
Loading

0 comments on commit 48d0a37

Please sign in to comment.