Scenario Object¶
Scenarios should be accessed through the GetScenarios() API call.
This function first tries to get scenarios from the current Study.
If no scenarios were specified, it looks locally for a scenario
in the input/scenarios directory. Returned scenarios is an array
or list of scenarios.
For GoLang the u.GetScenarios()
function returns
two arguments - three-dimensional
structure (scen) and an error value:
import sdk
var scenarios []*sdk.VORScen
var err error
scenarios, err = u.GetScenarios()
The first dimension of scenarios
is the scenario.
The second dimension is the dates/horizons of the specific scenario.
The third is a map of values for the scenario and date.
for _, scen:= range scenarios {
scenarioName := scen.Name
for _, d := range scen.Dates {
log.Println(d.Date)
for name, value := range d.Scen {
log.Println(name, value)
}
}
}
If you don't have equal numbers of horizons in each scenario, it is the user's responsibility to check for values at each horizon.
Usage for Python follows the same pattern as scenarios for Golang with the following differences:
- Multiple copies of scenarios are loaded for Python threads. See Python Threads for more explanation.
- In Python, you call the routine
scenario.get_scenarios(runID, scenarioSetName)
. get_scenarios()
returns a dictionary of scenarios. Each scenario is a list of dictionaries, one for each date. The dictionary at each date is a name-value pair of the and values of the scenario.
An example of processing a scenario in Python is the following:
from sdk import scenario
import logging
try :
scenarioSetName = handle.options["JobOptions"]["system"]["scenario"]
except KeyError :
scenarioSetName = ""
try :
runID = handle.options["RunID"]
except (TypeError,KeyError) :
runID = 0
scen = scenario.get_scenarios(runID, scenarioSetName)
logging.info("There are %d scenarios", len(scen))
## loop over scenarios
for scenarioName, s in scen.items():
# loop over horizons
logging.info(scenarioName)
for horizonNumber, horiz in enumerate(s):
for name, value in horiz.items():
logging.info("%s = %s", name, value)