Scenario Builder

 # CRAN limite CPU usage
data.table::setDTthreads(2)
library(antaresEditObject)

First let’s create a new study with some areas and clusters:

path <- tempdir()
createStudy(path = path, study_name = "my-study")
#> Warning: Parameter 'horizon' is missing or inconsistent with 'january.1st' and 'leapyear'. Assume correct year is 2018.
#> To avoid this warning message in future simulations, open the study with Antares and go to the simulation tab, put a valid year number in the cell 'horizon' and use consistent values for parameters 'Leap year' and '1st january'.

# Set number of Monte-Carlo scenarios
updateGeneralSettings(nbyears = 10)

# First area
createArea("earth")
createCluster(area = "earth", cluster_name = "america", add_prefix = FALSE)
createCluster(area = "earth", cluster_name = "africa", add_prefix = FALSE)
createCluster(area = "earth", cluster_name = "europe", add_prefix = FALSE)

# Second one
createArea("moon")
createCluster(area = "moon", cluster_name = "tranquility", add_prefix = FALSE)
createCluster(area = "moon", cluster_name = "serenety", add_prefix = FALSE)

# More areas
createArea("titan")
createArea("ceres")

# Some links
createLink("earth", "moon")
createLink("moon", "titan")
createLink("moon", "ceres")

# Check what we have created
getAreas()
#> [1] "ceres" "earth" "moon"  "titan"
readClusterDesc()
#>     area group     cluster
#> 1: earth Other     america
#> 2: earth Other      africa
#> 3: earth Other      europe
#> 4:  moon Other tranquility
#> 5:  moon Other    serenety

We can read scenario builder data with:

readScenarioBuilder()
#> list()

Currently it’s empty. We need to create rules before updating data:

# All areas
scenarioBuilder(n_scenario = 3)
#>       [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
#> ceres "1"  "2"  "3"  "1"  "2"  "3"  "1"  "2"  "3"  "1"  
#> earth "2"  "3"  "1"  "2"  "3"  "1"  "2"  "3"  "1"  "2"  
#> moon  "3"  "1"  "2"  "3"  "1"  "2"  "3"  "1"  "2"  "3"  
#> titan "1"  "2"  "3"  "1"  "2"  "3"  "1"  "2"  "3"  "1"
scenarioBuilder(n_scenario = 5)
#>       [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
#> ceres "1"  "2"  "3"  "4"  "5"  "1"  "2"  "3"  "4"  "5"  
#> earth "1"  "2"  "3"  "4"  "5"  "1"  "2"  "3"  "4"  "5"  
#> moon  "1"  "2"  "3"  "4"  "5"  "1"  "2"  "3"  "4"  "5"  
#> titan "1"  "2"  "3"  "4"  "5"  "1"  "2"  "3"  "4"  "5"
# Specific area
scenarioBuilder(n_scenario = 3, areas = "earth")
#>       [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
#> earth "1"  "2"  "3"  "1"  "2"  "3"  "1"  "2"  "3"  "1"
# Specify an area for which to use random values
scenarioBuilder(n_scenario = 3, areas_rand = "earth")
#>       [,1]   [,2]   [,3]   [,4]   [,5]   [,6]   [,7]   [,8]   [,9]   [,10] 
#> ceres "1"    "2"    "3"    "1"    "2"    "3"    "1"    "2"    "3"    "1"   
#> earth "rand" "rand" "rand" "rand" "rand" "rand" "rand" "rand" "rand" "rand"
#> moon  "3"    "1"    "2"    "3"    "1"    "2"    "3"    "1"    "2"    "3"   
#> titan "1"    "2"    "3"    "1"    "2"    "3"    "1"    "2"    "3"    "1"

Now we can update the scenario builder data:

my_scenario <- scenarioBuilder(n_scenario = 3)

# for load serie
updateScenarioBuilder(ldata = my_scenario, series = "load")

# equivalent as
updateScenarioBuilder(ldata = list(l = my_scenario))

Here we update data for serie load only. To update several series at once you can do:

my_scenario <- scenarioBuilder(n_scenario = 3)

updateScenarioBuilder(
  ldata = my_scenario, 
  series = c("load", "hydro", "solar")
)
load_scenario <- scenarioBuilder(n_scenario = 3)
hydro_scenario <- scenarioBuilder(n_scenario = 4)
solar_scenario <- scenarioBuilder(n_scenario = 5)

updateScenarioBuilder(ldata = list(
  l = load_scenario,
  h = hydro_scenario,
  s = solar_scenario
))

If you read scenario builder now, wet got:

readScenarioBuilder()
#> $h
#>       [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
#> ceres    1    2    3    4    1    2    3    4    1     2
#> earth    3    4    1    2    3    4    1    2    3     4
#> moon     1    2    3    4    1    2    3    4    1     2
#> titan    3    4    1    2    3    4    1    2    3     4
#> 
#> $l
#>       [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
#> ceres    1    2    3    1    2    3    1    2    3     1
#> earth    2    3    1    2    3    1    2    3    1     2
#> moon     3    1    2    3    1    2    3    1    2     3
#> titan    1    2    3    1    2    3    1    2    3     1

For thermal and renewables series, default behavior is to set rules to each clusters in the area :

my_scenario <- scenarioBuilder(n_scenario = 3)

updateScenarioBuilder(
  ldata = my_scenario, 
  series = "thermal"
)

readScenarioBuilder()$t
#> NULL

We can specify specific clusters with:

updateScenarioBuilder(
  ldata = my_scenario, 
  series = "thermal",
  clusters_areas = data.table::data.table(
    area = c("earth", "earth"),
    cluster = c("africa", "europe")
  )
)
readScenarioBuilder()$t
#> NULL

For NTC serie (Antares >= 8.2.0), it writes the scenario for all links :

updateScenarioBuilder(
  ldata = my_scenario, 
  series = "ntc"
)
readScenarioBuilder()$ntc
#>            [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
#> ceres%moon    1    2    3    1    2    3    1    2    3     1
#> earth%moon    2    3    1    2    3    1    2    3    1     2
#> moon%titan    3    1    2    3    1    2    3    1    2     3

For writing scenario for a specific link you can do:

updateScenarioBuilder(
  ldata = my_scenario, 
  series = "ntc",
  links = "moon%ceres"
)
readScenarioBuilder()$ntc
#>            [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
#> ceres%moon    1    2    3    1    2    3    1    2    3     1

Finally, you can remove all scenarios from a ruleset with:

clearScenarioBuilder()