Working with Scenarios
Scenarios in PLEXOS allow you to model different conditions or assumptions. PlexosDB provides methods to manage these scenarios.
Creating Scenarios
Section titled “Creating Scenarios”Scenarios can be added manually to the database by calling add_scenario:
from plexosdb import PlexosDB
# Initialize databasedb = PlexosDB()db.create_schema(version=10)
db.add_scenario("TestScenario")Creating Scenario Properties
Section titled “Creating Scenario Properties”Scenarios are automatically created when adding properties with a scenario name:
from plexosdb import PlexosDBfrom plexosdb.enums import ClassEnum
# Initialize databasedb = PlexosDB()db.create_schema(version=10)
# Create a generatordb.add_object(ClassEnum.Generator, "Generator1")
# Add a property with a scenario - this automatically creates the scenariodb.add_property( ClassEnum.Generator, "Generator1", "Max Capacity", 100.0, scenario="Base Case")
# Add another property with a different scenariodb.add_property( ClassEnum.Generator, "Generator1", "Max Capacity", 120.0, scenario="High Demand")Listing Available Scenarios
Section titled “Listing Available Scenarios”You can list all scenarios in your model:
# List all scenariosscenarios = db.list_scenarios()print(f"Available scenarios: {scenarios}")Checking if a Scenario Exists
Section titled “Checking if a Scenario Exists”# Check if a scenario existsif db.check_scenario_exists("Base Case"): print("Base Case scenario exists")else: print("Base Case scenario does not exist")Creating Object-Specific Scenarios
Section titled “Creating Object-Specific Scenarios”You can create scenarios with specific property values for an object:
# Create a new scenario with specific property valuesdb.create_object_scenario( "Generator1", "New Scenario", { "Max Capacity": 130.0, "Min Stable Level": 25.0, "Heat Rate": 9.5 }, object_class=ClassEnum.Generator, description="New scenario for testing", base_scenario="Base Case" # Inherits other properties from Base Case)Getting Properties for a Specific Scenario
Section titled “Getting Properties for a Specific Scenario”# Get all properties for an object in a specific scenariofrom plexosdb.enums import CollectionEnum
# Get the scenario IDscenario_id = db.get_scenario_id("High Demand")
# Query properties with this scenarioproperties = db.query(""" SELECT o.name, p.name as property, d.value FROM t_data d JOIN t_property p ON d.property_id = p.property_id JOIN t_membership m ON d.membership_id = m.membership_id JOIN t_object o ON m.child_object_id = o.object_id JOIN t_tag t ON t.data_id = d.data_id WHERE t.object_id = ?""", (scenario_id,))
for row in properties: print(f"{row[0]}: {row[1]} = {row[2]}")Updating Scenarios
Section titled “Updating Scenarios”# Update scenario name or descriptiondb.update_scenario( "High Demand", new_name="Peak Demand", new_description="Updated scenario for peak demand periods")