scenario
scenario
Scenario model for ETM scenario management.
Classes
SavedScenarioError
Bases: Exception
Base saved scenario error
Scenario
Bases: Base
Pydantic model for a MyETM SavedScenario.
A SavedScenario wraps an ETEngine session scenario and persists it in MyETM. The response includes both SavedScenario metadata and the full nested Scenario.
Source code in src/pyetm/models/base.py
Attributes
session
property
Get the current underlying ETEngine Scenario for this SavedScenario.
Returns:
| Name | Type | Description |
|---|---|---|
Scenario |
'Session'
|
The current ETEngine scenario session (cached after first access) |
Functions
new
classmethod
new(title, session_id=None, area_code=None, end_year=None, client=None, user_values=None, custom_curves=None, sortables=None, private=False, **kwargs)
Create a SavedScenario in MyETM - either from an existing session or by creating a new one.
Provide EITHER session_id OR (area_code + end_year), not both.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
title
|
str
|
Title for the saved scenario (required) |
required |
session_id
|
Optional[int]
|
ID of existing Session to save (optional) |
None
|
area_code
|
Optional[str]
|
Region code for new session, e.g., "nl2023", "de" (optional) |
None
|
end_year
|
Optional[int]
|
End year for new session (optional) |
None
|
client
|
Optional[BaseClient]
|
Optional BaseClient instance |
None
|
user_values
|
Optional[Dict[str, Any]]
|
Optional dict of user input values to apply after creation |
None
|
custom_curves
|
Optional[Dict[str, Any]]
|
Optional dict of custom curves to upload after creation |
None
|
sortables
|
Optional[Dict[str, Any]]
|
Optional dict of sortables to apply after creation |
None
|
private
|
bool
|
Whether the scenario should be private (default: False) |
False
|
**kwargs
|
Any
|
Additional parameters (e.g., description) |
{}
|
Returns:
| Type | Description |
|---|---|
'Scenario'
|
SavedScenario instance |
Raises:
| Type | Description |
|---|---|
SavedScenarioError
|
If creation fails |
ValueError
|
If parameter combination is invalid |
Example
Create new scenario (creates new session + saves it)
scenario = Scenario.new( ... title="High Solar 2050", ... area_code="nl2023", ... end_year=2050 ... )
Save existing session
scenario = Scenario.new( ... title="My Scenario", ... session_id=existing_session.id ... )
Source code in src/pyetm/models/scenario.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | |
load
classmethod
Load an existing SavedScenario from MyETM by its ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
saved_scenario_id
|
int
|
The ID of the saved scenario to load |
required |
client
|
Optional[BaseClient]
|
Optional BaseClient instance |
None
|
Returns:
| Type | Description |
|---|---|
'Scenario'
|
SavedScenario instance |
Raises:
| Type | Description |
|---|---|
SavedScenarioError
|
If loading fails |
Source code in src/pyetm/models/scenario.py
update
Update this SavedScenario
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Optional[BaseClient]
|
Optional BaseClient instance |
None
|
**kwargs
|
Any
|
Fields to update (title, private, discarded) |
{}
|
Source code in src/pyetm/models/scenario.py
discard
Discard this SavedScenario from MyETM (soft-delete, recoverable).
The scenario is marked as discarded and hidden from listings, but can be recovered through the MyETM web interface within 60 days. After 60 days, MyETM automatically removes discarded scenarios permanently.
This is the safe, recoverable deletion method. Use delete() for permanent deletion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Optional[BaseClient]
|
Optional BaseClient instance |
None
|
Raises:
| Type | Description |
|---|---|
SavedScenarioError
|
If discard fails |
Example
scenario = Scenario.load(123) scenario.discard() # Soft-delete, recoverable for 60 days
Source code in src/pyetm/models/scenario.py
delete
Permanently delete this SavedScenario AND its underlying Session (hard delete with cascade).
WARNING: This is a PERMANENT deletion and CANNOT be undone. This will: 1. Permanently delete the SavedScenario from MyETM 2. Permanently delete the underlying Session from ETEngine
All scenario data will be irreversibly lost. For recoverable deletion, use discard() instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Optional[BaseClient]
|
Optional BaseClient instance |
None
|
Raises:
| Type | Description |
|---|---|
SavedScenarioError
|
If deletion fails |
Example
scenario = Scenario.load(123) scenario.delete() # PERMANENT deletion - cannot be recovered
Source code in src/pyetm/models/scenario.py
user_values
update_user_values
Update user values on the underlying session.
remove_user_values
set_user_values_from_dataframe
Set user values from dataframe on the underlying session.
update_sortables
remove_sortables
set_sortables_from_dataframe
Set sortables from dataframe on the underlying session.
Source code in src/pyetm/models/scenario.py
update_custom_curves
Update custom curves on the underlying session.
remove_custom_curves
custom_curve_series
custom_curves_series
get_hourly_curve
Get a single hourly output curve by name or carrier type alias.
Carrier types ('electricity', 'heat', 'hydrogen', 'methane') are treated as convenient aliases for their primary curves.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
identifier
|
str
|
Curve name (e.g., 'merit_order') or carrier type alias |
required |
Returns:
| Type | Description |
|---|---|
Optional[DataFrame]
|
DataFrame with hourly data, or None if not found |
Source code in src/pyetm/models/scenario.py
get_hourly_curves
Get multiple hourly output curves by names or carrier type aliases.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
identifiers
|
list[str]
|
List of curve names and/or carrier type aliases |
required |
Returns:
| Type | Description |
|---|---|
dict[str, DataFrame]
|
Dictionary mapping curve names to DataFrames |
Source code in src/pyetm/models/scenario.py
all_hourly_output_curves
clear_hourly_curves_cache
Clear all hourly output curves cache files and LRU cache.
Returns:
| Type | Description |
|---|---|
int
|
Number of files successfully removed |
clear_custom_curves_cache
Clear all custom curves cache files.
Returns:
| Type | Description |
|---|---|
int
|
Number of files successfully removed |
clear_all_curve_caches
Clear all curve caches (hourly output curves and custom curves).
Returns:
| Type | Description |
|---|---|
tuple[int, int]
|
Tuple of (hourly_curves_removed, custom_curves_removed) |
Source code in src/pyetm/models/scenario.py
clear_session_cache
Clear entire session temp directory (all cached files).
This removes all cached files for this session and clears all associated in-memory caches.
get_annual_export
Get a single annual export by name from the underlying session.
get_annual_exports
Get multiple annual exports from the underlying session.
update_couplings
Update couplings on the underlying session.
add_queries
execute_queries
results
queries_requested
set_export_config
get_export_config
show_all_warnings
identifier
Get identifier in priority order: saved title, short_name, session title, saved id, session id.
Source code in src/pyetm/models/scenario.py
set_short_name
update_metadata
copy_with_preset
Create a copy of the underlying session with a linked preset and save it to MyETM.
Source code in src/pyetm/models/scenario.py
copy
Create a copy with no template link to the original scenario and save it to MyETM.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_values
|
Optional[Dict[str, Any]]
|
Optional dict of user input values to apply after copying |
None
|
custom_curves
|
Optional[Dict[str, Any]]
|
Optional dict of custom curves to upload after copying |
None
|
sortables
|
Optional[Dict[str, Any]]
|
Optional dict of sortables to apply after copying |
None
|
**overrides
|
Any
|
Additional parameters to override (title, private, etc.) |
{}
|
Returns:
| Type | Description |
|---|---|
'Scenario'
|
Copied SavedScenario instance |
Source code in src/pyetm/models/scenario.py
interpolate
classmethod
Interpolate one or more saved scenarios to target years and save to MyETM.
Source code in src/pyetm/models/scenario.py
to_excel
collect_export_data
Returns ExportDataCollection containing pandas DataFrames and dictionaries that can be exported to any file format (Parquet, CSV, JSON, etc.).
Source code in src/pyetm/models/scenario.py
list_users
Fetch all users with access to this saved scenario.
Source code in src/pyetm/models/scenario.py
update_users
Add, update, or remove a user's access to this saved scenario. - skip_upload: If True, store data locally without uploading (can be applied later)
Source code in src/pyetm/models/scenario.py
apply_pending_users
Apply all pending user updates that were loaded with skip_upload=True.