R/setSimulationPath.R
, R/setSimulationPathAPI.R
setSimulationPath.Rd
This function has to be used before the read
functions. It sets the path to
the Antares simulation to work on and other useful options (list of areas,
links, areas with clusters, variables, etc.). On local disk with setSimulationPath
or
on an AntaREST API with setSimulationPathAPI
setSimulationPath(path, simulation = NULL)
setSimulationPathAPI(
host,
study_id,
token,
simulation = NULL,
timeout = 60,
httr_config = list()
)
(optional)
Path to the simulation. It can either be the path to a directory containing
an antares project or directly to the directory containing the output of a
simulation. If missing, a window opens and lets the user choose the
directory of the simulation interactively. Can also choose .h5 file, if rhdf5
is installed.
(optional) Only used if "path" represents the path of a study and not of the
output of a simulation. It can be either the name of the simulation or a
number indicating which simulation to use. It is possible to use negative
values to select a simulation from the last one: for instance -1 will
select the most recent simulation, -2 will the penultimate one, etc. There
are two special values 0 and "input" that tells the function that the user
is not interested by the results of any simulation, but only by the inputs.
In such a case, the function readAntares
is unavailable.
character
host of AntaREST server API
character
id of the target study on the API
character
API personnal access token
numeric
API timeout (seconds). Default to 60. See also setTimeoutAPI
API httr configuration. See config
A list containing various information about the simulation, in particular:
path of the Antares study
path of the simulation
path of the input folder of the study
Name of the study
path of the folder containing the data of the simulation
name of the simulation
type of simulation: economy, adequacy, draft or input
Are synthetic results available ?
Are the results for each Monte Carlo simulation available ?
Are the Monte-Carlo scenarii stored in output ? This is important to reconstruct some input time series that have been used in each Monte-Carlo simulation.
Vector containing the number of the exported Monte-Carlo scenarios
Version of Antares used to run the simulation.
Vector of the available areas.
Vector of the available districts.
Vector of the available links.
Vector of areas containing clusters.
Vector of areas containing clusters renewable.
Vector of areas containing clusters storage (>=v8.6.0).
Available variables for areas, districts and links.
Other parameters of the simulation.
Table of time series dimensions for each group (>=v8.7.0).
Minimum time id of the simulation. It is generally equal to one but can be higher if working on a subperiod.
maximum time id of the simulation.
Date of the first day of the year in the simulation. This date corresponds to timeId = 1.
First day of the week.
data.table containing the specification of the districts.
list containing the cost of spilled and unsupplied energy.
timer for api commande execute
The simulation chosen with setSimulationPath
or setSimulationPathAPI
becomes the default
simulation for all functions of the package. This behavior is fine when
working on only one simulation, but it may become problematic when working
on multiple simulations at same time.
In such case, you can store the object returned by the function in a variable and pass this variable to the functions of the package (see examples).
if (FALSE) { # \dontrun{
# Select interactively a study. It only works on windows.
setSimulationPath()
# Specify path of the study. Note: if there are more than one simulation
# output in the study, the function will asks the user to interactively choose
# one simulation.
setSimulationPath("path_of_the_folder_of_the_study")
# Select the first simulation of a study
setSimulationPath("path_of_the_folder_of_the_study", 1)
# Select the last simulation of a study
setSimulationPath("path_of_the_folder_of_the_study", -1)
# Select a simulation by name
setSimulationPath("path_of_the_folder_of_the_study", "name of the simulation")
# Just need to read input data
setSimulationPath("path_of_the_folder_of_the_study", "input")
# or
setSimulationPath("path_of_the_folder_of_the_study", 0)
# Working with API
#--------------------------
setSimulationPathAPI(
host = "http://antares_api_adress",
study_id = "study_id_on_api",
token = "token"
)
## Custom httr options ?
# global using httr package
require(httr)
set_config(verbose())
setSimulationPathAPI(
host = "http://antares_api_adress",
study_id = "study_id_on_api",
token = "token"
)
reset_config()
# or in setSimulationPathAPI
setSimulationPathAPI(
host = "http://antares_api_adress",
study_id = "study_id_on_api",
token = "token",
httr_config = config(verbose = TRUE)
)
# disable ssl certificate checking ?
setSimulationPathAPI(
host = "http://antares_api_adress",
study_id = "study_id_on_api",
token = "token",
httr_config = config(ssl_verifypeer = FALSE)
)
# WORKING WITH MULTIPLE SIMULATIONS
#----------------------------------
# Let us assume ten simulations have been run and we want to collect the
# variable "LOAD" for each area. We can create a list containing options
# for each simulation and iterate through this list.
opts <- lapply(1:10, function(i) {
setSimulationPath("path_of_the_folder_of_the_study", i)
})
output <- lapply(opts, function(o) {
res <- readAntares(areas = "all", select = "LOAD", timeStep = "monthly", opts = o)
# Add a column "simulation" containing the name of the simulation
res$simulation <- o$name
res
})
# Concatenate all the tables in one super table
output <- rbindlist(output)
# Reshape output for easier comparisons: one line per timeId and one column
# per simulation
output <- dcast(output, timeId + areaId ~ simulation, value.var = "LOAD")
output
# Quick visualization
matplot(output[area == area[1], !c("area", "timeId"), with = FALSE],
type = "l")
} # }