Skip to content

Commit

Permalink
mean thermal ts v2
Browse files Browse the repository at this point in the history
  • Loading branch information
pvictor committed Sep 17, 2019
1 parent fc2557e commit 8d3b449
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 1 deletion.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: antaresThermalTS
Title: Extended Shutdown Simulation with 'Antares' for Power Groups
Version: 0.0.4
Version: 0.0.5
Authors@R: c(
person("Victor", "Perrier", email = "victor.perrier@dreamRs.fr", role = c("aut", "cre")),
person("Fabiola", "Aravena-Rojas", email = "fabiola.aravena-rojas@rte-france.com", role = c("aut")),
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export(create_clusters_edf)
export(create_clusters_nuclear)
export(create_clusters_other)
export(mean_thermal_ts)
export(mean_thermal_ts2)
export(msp_run_clusters)
export(pcn_stop_clusters)
export(read_calendar)
Expand Down
76 changes: 76 additions & 0 deletions R/mean_thermal_ts.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,79 @@ mean_thermal_ts <- function(first_weekday = 1, opts = simOptions()) {
}


#' Mean of thermal timeseries by weeks
#'
#' @param first_weekday The first day to use for starting a week, default to \code{1} (monday).
#' @param opts
#' List of simulation parameters returned by the function
#' \code{setSimulationPath}
#'
#' @return a \code{data.table}.
#' @export
#'
#' @importFrom antaresRead readClusterDesc
#' @importFrom lubridate wday hour isoweek
#' @importFrom data.table first := rbindlist
#' @importFrom anytime anydate
#' @importFrom progress progress_bar
#'
mean_thermal_ts2 <- function(first_weekday = 1, opts = simOptions()) {
clusters <- readClusterDesc(opts = opts)
clusters[, area := as.character(area)]
clusters[, cluster := as.character(cluster)]
clusters[, group := as.character(group)]
clusters <- clusters[area == "fr"]
pb <- progress_bar$new(
format = " Reading clusters time-series [:bar] :percent",
total = nrow(clusters), clear = FALSE
)
ts_clus <- mapply(
FUN = function(area, cluster) {
pb$tick()
path <- file.path(opts$inputPath, "thermal/series", area, cluster, "series.txt")
if (file.size(path) == 0) {
return(NULL)
}
ts <- fread(file = path)
ts[, time := seq.POSIXt(from = opts$start, by = "hour", length.out = 8760)]
ts[, date := anytime::anydate(time)]
ts[, WED19 := FALSE]
ts[lubridate::wday(time, week_start = 1) == 3 & lubridate::hour(time) == 19, WED19 := TRUE]
ts <- melt(
data = ts,
id.vars = c("time", "date", "WED19"),
variable.factor = FALSE,
variable.name = "tsId",
value.name = "ThermalAvailabilities"
)
ts <- ts[, list(
ThermalAvailabilities = mean(ThermalAvailabilities[WED19 == TRUE])
), by = date]
ts[, week := lubridate::wday(date, week_start = first_weekday)]
ts[week > 1, week := 0]
ts[, week := cumsum(week)]
ts[lubridate::wday(date, week_start = 1) == 1, nweek := lubridate::isoweek(date)]
ts[, nweek := nweek[!is.na(nweek)][1], by = week]
tsweek <- ts[, list(
ThermalAvailabilities = mean(ThermalAvailabilities, na.rm = TRUE),
date = first(date),
nweek = first(nweek),
n = .N
), by = list(week)]
tsweek <- tsweek[n == 7]
tsweek[, n := NULL]
tsweek[, area := area]
tsweek[, cluster := cluster]
},
area = clusters$area,
cluster = clusters$cluster,
SIMPLIFY = FALSE
)
ts_clus <- rbindlist(ts_clus)
ts_clus <- merge(
x = ts_clus,
y = clusters[, list(area, cluster, group)],
by = c("area", "cluster")
)
ts_clus[]
}
20 changes: 20 additions & 0 deletions man/mean_thermal_ts2.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8d3b449

Please sign in to comment.