knitr::opts_chunk$set(echo = TRUE)

antaresFlowbased allows to model flow-based domains into adequacy studies using the software Antares, with the following main functionalities:

1. Preparation of the input of an Antares study to include a modelling a flow-based in the CWE area

2. Post-processing and visualisation of Antares’ results

This vignette describes the second set of functionnalities : the post-processing of the simulation results.

1 - Summary

# Set Antares study path and read the simulation results
study <- "MyStuDy"
opts <- antaresRead::setSimulationPath(study, 2)
dta <- antaresRead::readAntares(areas = c("fr", "be", "de", "nl"),
                                links = c("be - de","be - fr","be - nl",
                                "de - fr","de - nl"), mcYears = 1:10,
                                select = c("LOLD", "UNSP. ENRG",
                                "DTG MRG", "UNSP. ENRG", "BALANCE", "FLOW LIN."),
                                opts = opts)


# Add to the results the time series of typical flow-based days
dta <- addTypicalDayId(dta)


# Apply the adequacy patch on the results
dta_adq <- adqPatch(mcYears = "all", pre_filter = FALSE, strategic_reserve_be = NULL,
                    strategic_reserve_de = NULL, opts = antaresRead::simOptions(),
                    fb_opts = opts, select = NULL, keepOldColumns = TRUE)


# Visualise the flow-based exchanges (position in the flow-based domains) before or after the adequacy patch
    # Plot a domain and the matching output positions
    plotNetPositionFB(fb_opts = opts,
                      data = dta_adq, drawPositionsAdqP = FALSE,
                      dayType = 1, hour = c(0, 19),
                      country1 = "BE", country2 = "FR")

    # Run a shiny application to visualise the domains and matching output positions
    runAppPosition(dta_adq)


# Add to the results a calculation of the net position of the countries within an area (by default, position in CWE)
dta <- addNetPosition(data, opts = antaresRead::simOptions(), 
                      inAreas = c("be",  "de", "fr", "nl"), adq = FALSE, newName = "_CWE")


# h5 file: apply the adequacy patch to an output in h5 format
adqH5(opts, fb_opts = setFlowbasedPath(path = "D:/model1"))

2 - Post-processing : addition of typical days time series

 antaresRead::setSimulationPath("MyStuDy", 1)
 dta <- readAntares(areas = "all", links = "all", clusters = "all" ,mcYears = 1:10)
 dta <- addTypicalDayId(data = dta)

The function addTypicalDayId() adds to an Antares output table a column indicating the id of the used flow-based typical days at each timestep. It uses the following parameters :

3 - Application of the adequacy patch

3.1 - Why the adequacy patch?

Although it is applied as a post-processing for Antares, the adequacy patch is in reality an integral part of the market coupling algorithm.

This patch intervenes in case of unsupplied energy : the optimal situation will be the one reducing the maximum amount of unsupplied energy in the whole interconnected areas and this may lead to increasing the unsupplied energy in some areas (countries exporting while in loss of load situation for example). The aim of the patch is to move from the optimal situation at CWE perimeter to a solution splitting the effort in a « fair » way.

This function is a post-processing of Antares results (optimisation algorithm), its aim is to re-compute the net positions (exports - imports) in the CWE area while :

Example : Area "fr" is exporting while having unsupplied energy. After the post-processing, it is exporting only the volume it can to reduce area "be" 's unsupplied energy without endangering its own safety.

Drawing

3.2 - Application of the adequacy patch

 opts <- antaresRead::setSimulationPath("MyStuDy", 2)
 dta <- adqPatch(mcYears = "all", pre_filter = FALSE, strategic_reserve_be = NULL,
                    strategic_reserve_de = NULL, opts = antaresRead::simOptions(),
                    fb_opts = opts, select = NULL, keepOldColumns = TRUE)
 ## or
 dta <- adqPatch(fb_opts = opts)

The adqPatch() function applies a post-processing on an Antares study output. It loads the results of the study indicated by antaresRead::setSimulationPath() and selects the times with unsupplied energy to apply the patch optimisation algorithm described above. By default, the function returns the results for all the MC years :

It uses the following parameters :

4 - Visualisation of the flow-based exchanges positions

Preliminary step: load the simulation results.

 opts <- antaresRead::setSimulationPath("MyStuDy", 2)
 dta <- antaresRead::readAntares(areas = c("fr", "be", "de", "nl"),
                                 links = c("be - de","be - fr","be - nl","de - fr","de - nl"), 
                                 mcYears = 1:10,
                                 select = c("LOLD", "UNSP. ENRG",
                                 "DTG MRG", "UNSP. ENRG", "BALANCE", "FLOW LIN."))

4.1 - Plot the net positions in CWE calculated by Antares and the used flow-based domains

The function plotNetPositionFB() is used after running an Antares simulation to visualize how the domains have been used by the optimizer to fix the exchanges in the CWE area.

The parameters used by the function are the following (example on how to use them are described below):

Plot a domain and the matching net positions

The user chooses the typical day(s) and hour(s), the function will plot the required domain(s) and search the Antares results to calculate the net positions whenever these domains were used by the optimiser.

 ## Plot the typical day 1 at hours 0 and 19 and the matching net positions on a Belgium-France graph
 plotNetPositionFB(fb_opts = opts,
          data = dta,
          dayType = 1, hour = c(0, 19),
          country1 = "BE", country2 = "FR")

Drawing

 ## Plot the three typical days of summer at hour 19 and the matching net positions
 plotNetPositionFB(fb_opts = opts,
          data = dta,
          dayType = c(1,2,3), hour = c(19),
          country1 = "BE", country2 = "FR")

Drawing

Select a date (or mcYear...) and plot the matching domains

By default, the function draws all the times matching the domains in the entire results table. It is then possible to filter the input table. If so, the parameter filteringEmptyDomains can be set to TRUE and the parameters dayType and hour to ALL. The function will then try and print all the domains, but actually keep only the ones used in the table.

 ## Plot only one time, without knowing the used flow-based domain
 dta$areas <- dta$areas[timeId == 5659,]
 plotNetPositionFB(fb_opts = opts,
          data = dta,
          dayType = "all", hour = "all",
          filteringEmptyDomains = TRUE,
          country1 = "FR", country2 = "DE")

Drawing

Filtering example : plot the net positions of situations of unsupplied energy

Because of the format of the Antares data table, some caution must be observed when filtering it. For example, to keep only the situations where there is unsupplied energy, one must keep all the rows representing this specific time. Example :

## An exemple of authorized filter :
idC <- c(antaresRead::getIdCols(dta$areas))
idC <- idC[idC!="area"]
LOLD <- dta$areas[,lapply(.SD, sum), by = idC, .SDcols = "LOLD"]
LOLD <- LOLD[LOLD!=0]
LOLD[,LOLD := NULL]

# Merge to filter data
dta$areas <- merge(dta$areas, LOLD, by =  idC)
## End filter


## plot domains
 plotNetPositionFB(fb_opts = opts,
          data = dta,
          dayType = "all", hour = c(19),
          country1 = "BE", country2 = "FR", filteringEmptyDomains = TRUE)

Drawing

Visualise the results of the adequacy patch

Provided that the data are in the table given in input of the function, it is possible to plot the net positions before or after adequacy patch or even the two at the same time. To do so, the parameters drawPositionsBeforeAdqP and/or drawPositionsAdqP must be set to TRUE (default value).

 ## Apply the adequacy patch
 opts <- antaresRead::setSimulationPath("MyStuDy", 2)
 data_withAdq <- adqPatch(keepOldColumns = TRUE)

 ## Plot the hours 0 and 19 of typical day 1
  plotNetPositionFB(fb_opts = opts,
          data = data_withAdq,
          dayType = 1, hour = c(0, 19),
          country1 = "BE", country2 = "FR",
          drawPositionsBeforeAdqP = TRUE, drawPositionsAdqP = TRUE)

Drawing

It is also possible to apply the filter presented above to keep only situations in which the adequacy patch has really been applied (with unsupplied energy in the area)

 ## Filter on LOLD :
 idC <- c(antaresRead::getIdCols(data_withAdq$areas))
 idC <- idC[idC!="area"]
 LOLD <- data_withAdq$areas[,lapply(.SD, sum), by = idC, .SDcols = "LOLD"]
 LOLD <- LOLD[LOLD!=0]
 LOLD[,LOLD := NULL]
 data_withAdq$areas <- merge(data_withAdq$areas, LOLD, by =  idC)


 ## plot
 plotNetPositionFB(fb_opts = opts,
          data = data_withAdq,
          dayType = c(5,6,7), hour = c(19),
          country1 = "BE", country2 = "FR",
          drawPositionsBeforeAdqP = TRUE, drawPositionsAdqP = TRUE)

Drawing

4.2 - Run a shiny application to visualise the net positions calculated by Antares and the flow-based domains

One can also visualise the net positions graphs in a shiny application launched with runAppPosition. Two parameters only are used (data and fb_opts), the others are available directly in the app.

runAppPosition(dta)

Drawing

The same filters can also be applied beforehand to select only timesteps with unsupplied energy.

5 - Post-processing : addition of the exchange position

opts <- antaresRead::setSimulationPath("MyStuDy", 2)
data <- readAntares(area = "all", links = "all", mcYears = 1)

##Add net position for CWE
data <- addNetPosition(data, opts, adq = FALSE)

##Add net position for CWE+AT
data <- addNetPosition(data, opts, adq = FALSE,
 inAreas = c("be", "de", "fr", "nl", "at"), newName = "_CWEAt")

The function addNetPosition() adds to an Antares output table a column calculating the net position of areas within an interconnected group of areas, based on the exchanged flows. This can be used for flow-based calculation (to get net positions in the CWE perimeter). It uses the following parameters :

6 - Post-processing : adequacy patch in h5 format

The funtion adqH5() enables to apply the adequacy patch on a simulation in h5 format and returns the results in the same format. The plot functions and application can be used on an h5 file.

## Select the Antares simulation
# Select the output in a classic format
opts <- antaresRead::setSimulationPath("MyStuDy",2)
# Write the study in h5 format
antaresRead::writeAntaresH5()
# Select the simulation now in an h5 file
opts <- antaresRead::setSimulationPath("MyNewStudy",1)


## Select the flow-based model to use. The function setFlowbasedPath can also be used
fb_opts = antaresRead::setSimulationPath("MyOldStudy", 2)


## Apply the adequacy patch
adqH5(opts = opts, fb_opts = fb_opts,
      strategic_reserve_be = NULL, strategic_reserve_de = NULL)


## Set alias for an easy read of the file afterwards
setAlias("adqPatch", "Alias for adqPatch", c("LOLD_ADQPatch",
                                             "UNSP. ENRG_ADQPatch", "DTG MRG_ADQPatch",
                                             "UNSP. ENRG_ADQPatch", "BALANCE_ADQPatch",
                                             "FLOW LIN._ADQPatch",
                                             "areas", "links"))
## Read the results of the patch with alias
readAntares(select = "adqPatch", opts = opts, mcYears = 1)

The function has only a few parameters :

In the h5 file, all the columns are automatically kept, including the columns of results before adequacy patch (parameter keepOldColumn in the function adqPatch() to TRUE). It is furthermost impossible to select only a few MC years to apply the patch on, or to use the pre-filter parameter.



rte-antares-rpackage/antaresFlowbased documentation built on Oct. 19, 2020, 11:23 a.m.