Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tomaster #260

Merged
merged 19 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 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.1
Version: 2.7.2.9000
Authors@R: c(
person("Tatiana", "Vargas", email = "[email protected]", role = c("aut", "cre")),
person("Jalal-Edine", "ZAWAM", role = "aut"),
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export(ponderateMcAggregation)
export(readAntares)
export(readAntaresAreas)
export(readAntaresClusters)
export(readAntaresSTClusters)
export(readBindingConstraints)
export(readClusterDesc)
export(readClusterResDesc)
Expand Down Expand Up @@ -98,6 +99,7 @@ importFrom(plyr,llply)
importFrom(purrr,quietly)
importFrom(shiny,getDefaultReactiveDomain)
importFrom(shiny,incProgress)
importFrom(shiny,isRunning)
importFrom(shiny,withProgress)
importFrom(stats,as.formula)
importFrom(stats,setNames)
Expand Down
19 changes: 18 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
> Copyright © 2016 RTE Réseau de transport d’électricité

# antaresRead 2.7.2.9000

NEW FEATURES:

* New function `readAntaresSTClusters()`
* `fread_antares()` shiny compatible with a conditional processing of the error messages

BREAKING CHANGES :

* `readClusterDesc()` / `readClusterResDesc()` / `readClusterSTDesc()` are updated with new endpoint "table mode".
- In "text" mode, functions return all properties (with default properties) according to study version.

BUGFIXES :

* `setSimulationPathAPI()`: control the existence of the output folder **links** or **areas** before reading the data (upgrade Antares Web)
* `readClusterDesc()` / `readClusterResDesc()` / `readClusterSTDesc()` return a data.table in API mode


# antaresRead 2.7.1

NEW FEATURES:
Expand All @@ -22,7 +40,6 @@ BUGFIXES :
* `setSimulationPath()` has also the parameter **areasWithSTClusters** in 'output' mode



# antaresRead 2.7.0

### Breaking changes (Antares v8.7.0) :
Expand Down
26 changes: 14 additions & 12 deletions R/importOutput.R
Original file line number Diff line number Diff line change
Expand Up @@ -377,14 +377,16 @@

# Get cluster capacity and must run mode
clusterDesc <- readClusterDesc(opts)
if(is.null(clusterDesc$must.run)) clusterDesc$must.run <- FALSE
clusterDesc[is.na(must.run), must.run := FALSE]
if (is.null(clusterDesc$min.stable.power)) clusterDesc$min.stable.power <- 0
clusterDesc[is.na(min.stable.power), min.stable.power := 0]
if(is.null(clusterDesc[["must-run"]]))
clusterDesc[["must-run"]] <- FALSE
clusterDesc[is.na(`must-run`), `must-run` := FALSE]
if (is.null(clusterDesc[["min-stable-power"]]))
clusterDesc[["min-stable-power"]] <- 0
clusterDesc[is.na(`min-stable-power`), `min-stable-power` := 0]
clusterDesc <- clusterDesc[, .(area, cluster,
capacity = nominalcapacity * unitcount,
min.stable.power,
must.run)]
`min-stable-power`,
`must-run`)]

# Are clusters in partial must run mode ?
mod <- llply(areas, .importThermalModulation, opts = opts, timeStep = "hourly")
Expand Down Expand Up @@ -449,16 +451,16 @@

}

.mergeByRef(res, clusterDesc[,.(area, cluster, must.run, min.stable.power)])
.mergeByRef(res, clusterDesc[,.(area, cluster, `must-run`, `min-stable-power`)])

if (is.null(res$NODU)) res[, thermalPmin := 0]
else res[, thermalPmin := min.stable.power * NODU]
else res[, thermalPmin := `min-stable-power` * NODU]

res[, `:=`(
mustRun = production * must.run,
mustRunTotal = production * must.run + mustRunPartial,
must.run = NULL,
min.stable.power = NULL
mustRun = production * `must-run`,
mustRunTotal = production * `must-run` + mustRunPartial,
`must-run` = NULL,
`min-stable-power` = NULL
)]

res[, thermalPmin := pmax(thermalPmin, mustRunTotal)]
Expand Down
4 changes: 2 additions & 2 deletions R/readAntares.R
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
#' similar to mustRunTotal except it also takes into account the production
#' induced by the minimum stable power of the units of a cluster. More
#' precisely, for a given cluster and a given time step, it is equal to
#' \code{min(NODU x min.stable.power, mustRunTotal)}.
#' \code{min(NODU x min-stable-power, mustRunTotal)}.
#' @param select
#' Character vector containing the name of the columns to import. If this
#' argument is \code{NULL}, all variables are imported. Special names
Expand Down Expand Up @@ -912,7 +912,7 @@ readAntaresAreas <- function(areas, links = TRUE, clusters = TRUE, clustersRes =
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)) {
if (is.null(areas) & is.null(links) & is.null(clusters) & is.null(districts) & is.null(clustersST)) {
areas <- "all"
}

Expand Down
54 changes: 53 additions & 1 deletion R/readAntaresClusters.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,56 @@ readAntaresClusters <- function(clusters, selected = c("production", "NP Cost",

subset(res, cluster %in% clusters, select = c(setdiff(colnames(res),c("production", "NP Cost", "NODU", "profit")),
intersect(colnames(res),selected))) #support for up to v8.4
}
}


#' Read output for a list of short-term storage clusters
#'
#' @param clustersST vector of short-term storage clusters to be imported
#' @param selected vector of thematic trimming
#' @inheritParams readAntares
#'
#' @return data.table of results for short-term storage clusters
#'
#' @export
readAntaresSTClusters <- function(clustersST, selected = c("P.injection", "levels", "P.withdrawal"),
timeStep = c("hourly", "daily", "weekly", "monthly", "annual"),
opts = simOptions(), parallel = FALSE, showProgress = TRUE) {

if (missing(clustersST)) {
stop("The function 'readAntaresSTClusters' expects a vector of short-term storage clusters names as argument.")
}
if ("Input" %in% opts$mode) {
stop("Cannot use 'readAntaresSTClusters' in 'Input' mode.")
}
if (opts$antaresVersion < 860) {
stop("Cannot use 'readAntaresSTClusters' for a study version < 860.")
}

##Add check control for all
allSTClusters <- readClusterSTDesc(opts = opts)[, c("area","cluster")]
allSTClusters$lower_cluster <- tolower(allSTClusters$cluster)
ind_cluster <- which(allSTClusters$lower_cluster %in% .checkArg(tolower(clustersST),
tolower(unique(allSTClusters$cluster)),
"short-term storage clusters %s do not exist in the simulation."))
clustersST <- allSTClusters$cluster[ind_cluster]

ind_cluster <- which(allSTClusters$lower_cluster %in% .checkArg(tolower(clustersST),
tolower(unique(allSTClusters[area %in% opts$areasWithSTClusters]$cluster)),
"short-term storage clusters %s have no output."))
clustersST <- unique(allSTClusters$cluster[ind_cluster])

output_st_clusters <- data.table()
if (length(clustersST) > 0) {
areas <- unique(allSTClusters[cluster %in% clustersST]$area)

res <- readAntares(clustersST = areas, timeStep = timeStep, opts = opts,
parallel = parallel, showProgress = showProgress)

output_st_clusters <- subset(res, cluster %in% clustersST, select = c(setdiff(colnames(res),c("P.injection", "levels", "P.withdrawal")),
intersect(colnames(res),selected))
)
}

return(output_st_clusters)
}
2 changes: 1 addition & 1 deletion R/readBindingConstraints.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
#'
#' @export
readBindingConstraints <- function(opts = simOptions()) {

##
# API BLOC
##
Expand Down
Loading
Loading