# Scenario Builder

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)
#> Warning in createCluster(area = "earth", cluster_name = "america", add_prefix =
#> FALSE): Group: 'Other' is not a valid name recognized by Antares, you should be
#> using one of: Gas, Hard coal, Lignite, Mixed fuel, Nuclear, Oil, Other, Other 2,
#> Other 3, Other 4
createCluster(area = "earth", cluster_name = "africa", add_prefix = FALSE)
#> Warning in createCluster(area = "earth", cluster_name = "africa", add_prefix =
#> FALSE): Group: 'Other' is not a valid name recognized by Antares, you should be
#> using one of: Gas, Hard coal, Lignite, Mixed fuel, Nuclear, Oil, Other, Other 2,
#> Other 3, Other 4
createCluster(area = "earth", cluster_name = "europe", add_prefix = FALSE)
#> Warning in createCluster(area = "earth", cluster_name = "europe", add_prefix =
#> FALSE): Group: 'Other' is not a valid name recognized by Antares, you should be
#> using one of: Gas, Hard coal, Lignite, Mixed fuel, Nuclear, Oil, Other, Other 2,
#> Other 3, Other 4

# Second one
createArea("moon")
createCluster(area = "moon", cluster_name = "tranquility", add_prefix = FALSE)
#> Warning in createCluster(area = "moon", cluster_name = "tranquility", add_prefix
#> = FALSE): Group: 'Other' is not a valid name recognized by Antares, you should
#> be using one of: Gas, Hard coal, Lignite, Mixed fuel, Nuclear, Oil, Other, Other
#> 2, Other 3, Other 4
createCluster(area = "moon", cluster_name = "serenety", add_prefix = FALSE)
#> Warning in createCluster(area = "moon", cluster_name = "serenety", add_prefix =
#> FALSE): Group: 'Other' is not a valid name recognized by Antares, you should be
#> using one of: Gas, Hard coal, Lignite, Mixed fuel, Nuclear, Oil, Other, Other 2,
#> Other 3, Other 4

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

# Check what we have created
getAreas()
#> [1] "ceres" "earth" "moon"  "titan"
#>     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

# 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:

• with same scenario data:
my_scenario <- scenarioBuilder(n_scenario = 3)

ldata = my_scenario,
series = c("load", "hydro", "solar")
)
• with differents scenario:
load_scenario <- scenarioBuilder(n_scenario = 3)
hydro_scenario <- scenarioBuilder(n_scenario = 4)
solar_scenario <- scenarioBuilder(n_scenario = 5)

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)

ldata = my_scenario,
series = "thermal"
)

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

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()