Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
pvictor committed Mar 29, 2019
0 parents commit d5ae3f7
Show file tree
Hide file tree
Showing 38 changed files with 1,689 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
^\.travis\.yml$
^appveyor\.yml$
^antaresThermalTS\.Rproj$
^\.Rproj\.user$
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.Rhistory
.RData
.Rproj.user
*.Rproj
23 changes: 23 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Package: antaresThermalTS
Title: Extended Shutdown Simulation with 'Antares' for Power Groups
Version: 0.0.0.9310
Authors@R: c(
person("Victor", "Perrier", email = "[email protected]", role = c("aut", "cre")),
person("Fabiola", "Aravena-Rojas", email = "[email protected]", role = c("aut")),
person("RTE", role = c("cph", "fnd"))
)
Description: Setup an 'Antares' study to simulate shutdown of power groups.
License: GPL (>= 2) | file LICENSE
Encoding: UTF-8
LazyData: true
Imports:
antaresEditObject,
antaresRead,
readxl (>= 1.2.0),
janitor,
data.table,
lubridate,
stringr,
stringi,
zoo
RoxygenNote: 6.1.1
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
COPYRIGHT HOLDER: RTE Réseau de transport d’électricité
47 changes: 47 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Generated by roxygen2: do not edit by hand

export(build_weekcal)
export(compute_kd_coefs)
export(compute_kipr)
export(compute_kivt)
export(create_clusters_edf)
export(create_clusters_nuclear)
export(create_clusters_other)
export(read_calendar)
export(read_cluster_desc)
export(read_info)
export(read_kd_cho)
export(read_kd_cho_macro)
export(read_planning)
export(read_planning_rte)
export(setup_study)
importFrom(antaresEditObject,createArea)
importFrom(antaresEditObject,createCluster)
importFrom(antaresEditObject,createStudy)
importFrom(antaresEditObject,updateGeneralSettings)
importFrom(antaresRead,setSimulationPath)
importFrom(antaresRead,simOptions)
importFrom(data.table,"%chin%")
importFrom(data.table,":=")
importFrom(data.table,.SD)
importFrom(data.table,copy)
importFrom(data.table,data.table)
importFrom(data.table,melt)
importFrom(data.table,rbindlist)
importFrom(data.table,setDT)
importFrom(data.table,setnames)
importFrom(data.table,setorder)
importFrom(data.table,uniqueN)
importFrom(janitor,clean_names)
importFrom(lubridate,as_datetime)
importFrom(lubridate,days)
importFrom(lubridate,hours)
importFrom(lubridate,years)
importFrom(readxl,anchored)
importFrom(readxl,cell_limits)
importFrom(readxl,read_excel)
importFrom(stats,setNames)
importFrom(stringi,stri_replace_all_charclass)
importFrom(stringr,str_replace_all)
importFrom(utils,packageVersion)
importFrom(zoo,na.locf)
39 changes: 39 additions & 0 deletions R/build_weekcal.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

#' Build Week calendar
#'
#' @param start Starting year
#' @param end Ending year
#'
#' @return a \code{data.table}
#' @export
#'
#' @importFrom data.table data.table :=
#' @importFrom zoo na.locf
#'
#' @examples
#'
#' build_weekcal()
#'
build_weekcal <- function(start = 2018, end = 2020) {
weekcal <- data.table(
dates = seq(
from = as.Date(paste0(start, "-01-01")) - 7,
to = as.Date(paste0(end, "-12-31")) + 7,
by = "days"
)
)
weekcal[, saturdays := format(dates, format = "%u") %in% "6"]
weekcal[, year := format(dates + 7, format = "%Y")]
weekcal[saturdays == TRUE, week := sprintf("S%02d - %s", seq_along(saturdays), year), by = year]
weekcal[, week := zoo::na.locf(week, na.rm = FALSE)]
weekcal <- weekcal[!is.na(week)]

weekcal <- weekcal[, list(
week_start = min(dates),
week_end = max(dates),
n = .N
), by = week]
weekcal <- weekcal[n == 7]
weekcal[, n := NULL]
weekcal[]
}
39 changes: 39 additions & 0 deletions R/compute_kd_coefs.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

#' Compute Kd coefficients
#'
#' @param kipr Kipr coefficient from \code{\link{compute_kipr}}.
#' @param kivt Kivt coefficient from \code{\link{compute_kivt}}.
#' @param kd_cho Kd coefficients read with \code{\link{read_kd_cho}}.
#'
#' @return a \code{data.table}
#' @export
#'
#' @importFrom data.table copy := setorder data.table
compute_kd_coefs <- function(kipr, kivt, kd_cho) {
kipr <- copy(kipr)
kivt <- copy(kivt)
kd_cho <- copy(kd_cho)
code_palier_dic <- data.table(
type_groupe = c("Nucl\u00e9aire 1300", "Nucl\u00e9aire 900", "Nucl\u00e9aire N4"),
code_palier = c("p4", "cp0_cp_cp2", "n4")
)
kipr <- merge(
x = kipr[, .SD, .SDcols = c("week", "week_start", "week_end", "type_groupe", "kipr")],
y = code_palier_dic, by = "type_groupe"
)
kipr_kivt <- merge(
x = kipr,
y = kivt[, .SD, .SDcols = c("week", "type_groupe", "kivt")],
by = c("week", "type_groupe")
)
kipr_kivt[, type_groupe := NULL]

kd_coefs <- merge(
x = kipr_kivt,
y = kd_cho[, list(week = n_sem_annee, kif, kistretch, kienv, kihiver, kibouclage, code_palier, palier)],
by = c("week", "code_palier")
)
setorder(kd_coefs, week_start, code_palier)
kd_coefs[]
}

71 changes: 71 additions & 0 deletions R/compute_kipr.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@

#' Compute Kipr coefficient
#'
#' @param calendar Calendar data read with \code{\link{read_calendar}}.
#' @param clusters_desc Clusters / groups description read with \code{\link{read_cluster_desc}}.
#' @param years Years to consider, if \code{NULL} (default), year range from \code{calendar} will be used.
#'
#' @return a \code{data.table}
#' @export
#'
#' @importFrom data.table copy setorder := uniqueN
#'
#' @examples
#' \dontrun{
#' # Calendar data
#' calendar <- read_calendar(path = "REF_Planning_5_ans_mars_2018.xlsx")
#'
#' # Clusters description
#' clusters <- read_cluster_desc("HypothesesRTE_CHO-4145.xlsx")
#'
#'
#' # Kipr computation
#' kipr <- compute_kipr(calendar, clusters)
#' kipr
#' }
compute_kipr <- function(calendar, clusters_desc, years = NULL) {

calendar <- copy(calendar)
clusters_desc <- copy(clusters_desc)

if (is.null(years)) {
years <- range(calendar$date_debut, na.rm = TRUE)
years <- format(years, format = "%Y")
}

weekcal <- build_weekcal(start = years[1], end = years[2])

weekcal[, .id := 1]
calendar[, .id := 1]

week_groups <- weekcal[calendar[, list(
.id,
group = tranche,
shutdown_start = as.Date(date_de_fin_sans_prolongation),
shutdown_end = as.Date(date_de_fin_avec_prolongation)
)], on = ".id", allow.cartesian = TRUE]

week_groups[, n_overlaps := n_overlaps(week_start, week_end, shutdown_start, shutdown_end)]

clusters_desc <- clusters_desc[, list(group = corresp_groupes, type_groupe, pcn_mw)]
clusters_desc[, pcn_mw := as.numeric(pcn_mw)]
clusters_desc[, group_power := sum(pcn_mw), by = type_groupe]

weekclus <- merge(
x = week_groups,
y = clusters_desc,
by = "group", all.x = TRUE, all.y = FALSE
)
weekclus <- weekclus[!is.na(type_groupe)]

setorder(weekclus, week, group, -n_overlaps)
weekclus <- unique(weekclus, by = c("week", "group"))

coef_kipr <- weekclus[, list(
kipr = sum(pcn_mw * n_overlaps / 7) / group_power * 100,
n_days = sum(n_overlaps),
n = .N, n_group = uniqueN(group)
), by = list(week, week_start, week_end, type_groupe, group_power)]
setorder(coef_kipr, week_start, type_groupe)
coef_kipr[]
}
71 changes: 71 additions & 0 deletions R/compute_kivt.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@

#' Compute Kivt coefficient
#'
#' @param calendar Calendar data read with \code{\link{read_calendar}}.
#' @param clusters_desc Clusters / groups description read with \code{\link{read_cluster_desc}}.
#' @param years Years to consider, if \code{NULL} (default), year range from \code{calendar} will be used.
#'
#' @return a \code{data.table}
#' @export
#'
#' @importFrom data.table copy setorder := uniqueN
#'
#' @examples
#' \dontrun{
#' # Calendar data
#' calendar <- read_calendar(path = "REF_Planning_5_ans_mars_2018.xlsx")
#'
#' # Clusters description
#' clusters <- read_cluster_desc("HypothesesRTE_CHO-4145.xlsx")
#'
#'
#' # Kivt computation
#' kivt <- compute_kivt(calendar, clusters)
#' kivt
#' }
compute_kivt <- function(calendar, clusters_desc, years = NULL) {

calendar <- copy(calendar)
clusters_desc <- copy(clusters_desc)

if (is.null(years)) {
years <- range(calendar$date_debut, na.rm = TRUE)
years <- format(years, format = "%Y")
}

weekcal <- build_weekcal(start = years[1], end = years[2])

weekcal[, .id := 1]
calendar[, .id := 1]

week_groups <- weekcal[calendar[, list(
.id,
group = tranche,
shutdown_start = as.Date(date_debut),
shutdown_end = as.Date(date_de_fin_sans_prolongation) - 1
)], on = ".id", allow.cartesian = TRUE]

week_groups[, n_overlaps := n_overlaps(week_start, week_end, shutdown_start, shutdown_end)]

clusters_desc <- clusters_desc[, list(group = corresp_groupes, type_groupe, pcn_mw)]
clusters_desc[, pcn_mw := as.numeric(pcn_mw)]
clusters_desc[, group_power := sum(pcn_mw), by = type_groupe]

weekclus <- merge(
x = week_groups,
y = clusters_desc,
by = "group", all.x = TRUE, all.y = FALSE
)
weekclus <- weekclus[!is.na(type_groupe)]

setorder(weekclus, week, group, -n_overlaps)
weekclus <- unique(weekclus, by = c("week", "group"))

coef_kivt <- weekclus[, list(
kivt = sum(pcn_mw * n_overlaps / 7) / group_power * 100,
n_days = sum(n_overlaps),
n = .N, n_group = uniqueN(group)
), by = list(week, week_start, week_end, type_groupe, group_power)]
setorder(coef_kivt, week_start, type_groupe)
coef_kivt[]
}
86 changes: 86 additions & 0 deletions R/corresp_gps.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@



corresp_gps <- function() {
data.table(
groupe = c("BELLEVILLE 1", "BELLEVILLE 2", "BLAYAIS 1", "BLAYAIS 2",
"BLAYAIS 3", "BLAYAIS 4", "BUGEY 2", "BUGEY 3", "BUGEY 4",
"BUGEY 5", "CATTENOM 1", "CATTENOM 2", "CATTENOM 3", "CATTENOM 4",
"CHINON 1", "CHINON 2", "CHINON 3", "CHINON 4", "CHOOZ 1",
"CHOOZ 2", "CIVAUX 1", "CIVAUX 2", "CRUAS 1", "CRUAS 2", "CRUAS 3",
"CRUAS 4", "DAMPIERRE 1", "DAMPIERRE 2", "DAMPIERRE 3",
"DAMPIERRE 4", "FESSENHEIM 1", "FESSENHEIM 2", "FLAMANVILLE 1",
"FLAMANVILLE 2", "GOLFECH 1", "GOLFECH 2", "GRAVELINES 1",
"GRAVELINES 2", "GRAVELINES 3", "GRAVELINES 4", "GRAVELINES 5",
"GRAVELINES 6", "NOGENT 1", "NOGENT 2", "PALUEL 1", "PALUEL 2", "PALUEL 3",
"PALUEL 4", "PENLY 1", "PENLY 2", "ST ALBAN 1", "ST ALBAN 2",
"ST LAURENT 1", "ST LAURENT 2", "TRICASTIN 1", "TRICASTIN 2",
"TRICASTIN 3", "TRICASTIN 4", "CORDEMAIS 4", "CORDEMAIS 5", "HAVRE 4",
"PROVENCE 5", "EMILE HUCHET 6", "DK6 - Braek 1",
"DK6 - Braek 2", "BOUCHAIN 7", "MARTIGUES PONTEAU 5", "MARTIGUES PONTEAU 6",
"SPEM", "SPEM Pointe", "Grand-Riviere (SPEM)", "CYCOFOS",
"BLENOD 5", "COMBIGOLFE", "EMILE HUCHET 7", "EMILE HUCHET 8",
"Croix-de-Metz", "Pont-sur-Sambre", "FR-GA-MORANT1", "GENNEVILLIERS 1",
"AMFARD14", "AMFARD15", "CORDEMAIS 2", "CORDEMAIS 3",
"PORCHEVILLE 1", "PORCHEVILLE 2", "PORCHEVILLE 3", "PORCHEVILLE 4",
"ARAMON 1", "ARAMON 2", "MONTEREAU FIOUL 6", "MONTEREAU FIOUL 5",
"MONTEREAU GAZ 6", "MONTEREAU GAZ 5", "VAIRES 1", "VAIRES 2",
"VAIRES 3", "ARRIGHI 1", "ARRIGHI 2", "DIRINON 1", "DIRINON 2",
"BRENNILIS 1", "BRENNILIS 2", "BRENNILIS 3", "BILHOT01", "FOSCHT 2",
"Calais Tioxide", "DD HOA 1", "DD HOA 2", "DD HOA DALKIA",
"DD OA - ELD RESTE France", "DD OA - ERDF RESTE France", "DDBZHT 1",
"DK6 TV1", "DK6 TV2"),
code_gp = c("BVIL7T 1", "BVIL7T 2", "BLAYAT 1", "BLAYAT 2", "BLAYAT 3",
"BLAYAT 4", "BUGEYT 2", "BUGEYT 3", "BUGEYT 4", "BUGEYT 5",
"CATTET 1", "CATTET 2", "CATTET 3", "CATTET 4", "CHIN2T 1",
"CHIN2T 2", "CHIN2T 3", "CHIN2T 4", "CHOO2T 1", "CHOO2T 2",
"CIVAUT 1", "CIVAUT 2", "CRUA5T 1", "CRUA5T 2", "CRUA5T 3", "CRUA5T 4",
"D.BURT 1", "D.BURT 2", "D.BURT 3", "D.BURT 4", "FESS5T 1",
"FESS5T 2", "FLAMAT 1", "FLAMAT 2", "GOLF5T 1", "GOLF5T 2",
"GRAV5T 1", "GRAV5T 2", "GRAV5T 3", "GRAV5T 4", "GRAV5T 5", "GRAV5T 6",
"N.SE5T 1", "N.SE5T 2", "PALUET 1", "PALUET 2", "PALUET 3",
"PALUET 4", "PENLYT 1", "PENLYT 2", "SSAL7T 1", "SSAL7T 2",
"SSEA2T 1", "SSEA2T 2", "TRICAT 1", "TRICAT 2", "TRICAT 3", "TRICAT 4",
"CORD5T 4", "CORD5T 5", "HAVRET 4", "PROVET 5", "E.HUCT 6", NA,
NA, "BOUCHT 7", "M.PONT 5", "M.PONT 6", NA, NA, NA, NA,
"BLENOT 5", NA, "E.HUCT 7", "E.HUCT 8", "C.ME5T01", "SAMBRT1", "MORANT 1",
"GENN3T 1", "AMFART14", "AMFART15", "CORD5T 2", "CORD5T 3",
"PORC2T 1", "PORC2T 2", "PORC2T 3", "PORC2T 4", NA, NA, "MTERFT 6",
"MTERFT 5", "MTERGT 6", "MTERGT 5", "VAIR6T 1", "VAIR6T 2",
"VAIR6T 3", "ARRI5T 1", "ARRI5T 2", "DIRINT 1", "DIRINT 2",
"BRENNT 1", "BRENNT 2", "BRENNT 3", NA, NA, "CALAIT1", "DFDC1T 1",
"DFDC2T 1", "DFDCOT 1", "DFELDT 1", "DFEGST 1", "DDBZHT 1", NA, NA),
name_desc = c("nuclear_p4", "nuclear_p4", "nuclear_cp0_cp_cp2",
"nuclear_cp0_cp_cp2", "nuclear_cp0_cp_cp2",
"nuclear_cp0_cp_cp2", "nuclear_cp0_cp_cp2", "nuclear_cp0_cp_cp2",
"nuclear_cp0_cp_cp2", "nuclear_cp0_cp_cp2", "nuclear_p4", "nuclear_p4",
"nuclear_p4", "nuclear_p4", "nuclear_cp0_cp_cp2", "nuclear_cp0_cp_cp2",
"nuclear_cp0_cp_cp2", "nuclear_cp0_cp_cp2", "nuclear_n4",
"nuclear_n4", "nuclear_n4", "nuclear_n4", "nuclear_cp0_cp_cp2",
"nuclear_cp0_cp_cp2", "nuclear_cp0_cp_cp2", "nuclear_cp0_cp_cp2",
"nuclear_cp0_cp_cp2", "nuclear_cp0_cp_cp2", "nuclear_cp0_cp_cp2",
"nuclear_cp0_cp_cp2", "nuclear_cp0_cp_cp2", "nuclear_cp0_cp_cp2",
"nuclear_p4", "nuclear_p4", "nuclear_p4", "nuclear_p4",
"nuclear_cp0_cp_cp2", "nuclear_cp0_cp_cp2", "nuclear_cp0_cp_cp2",
"nuclear_cp0_cp_cp2", "nuclear_cp0_cp_cp2", "nuclear_cp0_cp_cp2",
"nuclear_p4", "nuclear_p4", "nuclear_p4", "nuclear_p4",
"nuclear_p4", "nuclear_p4", "nuclear_p4", "nuclear_p4", "nuclear_p4",
"nuclear_p4", "nuclear_cp0_cp_cp2", "nuclear_cp0_cp_cp2",
"nuclear_cp0_cp_cp2", "nuclear_cp0_cp_cp2", "nuclear_cp0_cp_cp2",
"nuclear_cp0_cp_cp2", "hard_coal_old_1", "hard_coal_old_1",
"hard_coal_old_1", "hard_coal_old_1", "hard_coal_old_1", "gas_ccgt_new",
"gas_ccgt_new", "gas_ccgt_new", "gas_ccgt_new", "gas_ccgt_new",
"gas_ccgt_new", "gas_ccgt_new", "gas_ccgt_new", "gas_ccgt_new",
"gas_ccgt_new", "gas_ccgt_new", "gas_ccgt_new", "gas_ccgt_new",
"gas_ccgt_new", "gas_ccgt_new", "gas_ccgt_new", "gas_ocgt_old",
"gas_cogen_market", "gas_cogen_market", "heavy_oil_old_1",
"heavy_oil_old_1", "heavy_oil_old_1", "heavy_oil_old_1",
"heavy_oil_old_1", "heavy_oil_old_1", "heavy_oil_old_1", "heavy_oil_old_1",
"light_oil", "light_oil", "gas_ocgt_new", "gas_ocgt_new",
"light_oil", "light_oil", "light_oil", "light_oil", "light_oil",
"light_oil", "light_oil", "light_oil", "light_oil", "light_oil",
"gas_cogen_market", "gas_cogen_market", "gas_cogen_market", "light_oil",
"light_oil", "light_oil", "light_oil", "light_oil", "light_oil",
"gas_ccgt_new", "gas_ccgt_new")
)
}
Loading

0 comments on commit d5ae3f7

Please sign in to comment.