Scenario Builder

library(antaresEditObject)
#> Le chargement a nécessité le package : antaresRead

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)

# Check what we have created
getAreas()
#> [1] "earth" "moon"
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]
#> earth "1"  "2"  "3"  "1"  "2"  "3"  "1"  "2"  "3"  "1"  
#> moon  "2"  "3"  "1"  "2"  "3"  "1"  "2"  "3"  "1"  "2"
scenarioBuilder(n_scenario = 5)
#>       [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
#> earth "1"  "2"  "3"  "4"  "5"  "1"  "2"  "3"  "4"  "5"  
#> moon  "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] 
#> earth "rand" "rand" "rand" "rand" "rand" "rand" "rand" "rand" "rand" "rand"
#> moon  "2"    "3"    "1"    "2"    "3"    "1"    "2"    "3"    "1"    "2"

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]
#> earth    1    2    3    4    1    2    3    4    1     2
#> moon     3    4    1    2    3    4    1    2    3     4
#> 
#> $l
#>       [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
#> earth    1    2    3    1    2    3    1    2    3     1
#> moon     2    3    1    2    3    1    2    3    1     2

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
#>                  [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
#> earth_africa        1    2    3    1    2    3    1    2    3     1
#> earth_america       1    2    3    1    2    3    1    2    3     1
#> earth_europe        1    2    3    1    2    3    1    2    3     1
#> moon_serenety       2    3    1    2    3    1    2    3    1     2
#> moon_tranquility    2    3    1    2    3    1    2    3    1     2

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
#>                  [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
#> earth_africa        1    2    3    1    2    3    1    2    3     1
#> earth_america      NA   NA   NA   NA   NA   NA   NA   NA   NA    NA
#> earth_europe        1    2    3    1    2    3    1    2    3     1
#> moon_serenety      NA   NA   NA   NA   NA   NA   NA   NA   NA    NA
#> moon_tranquility   NA   NA   NA   NA   NA   NA   NA   NA   NA    NA

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

clearScenarioBuilder()