scenarios
scenarios
Collection and bulk operations for scenarios.
Classes
ScenarioCreationParams
Bases: TypedDict
Type definition for create_many parameter dicts.
Note: template_id must be a Session ID (ETEngine), not a SavedScenario ID (MyETM).
Scenarios
Bases: Base
A collection of SavedScenario and/or Session objects.
Can hold both Scenario and Session objects to support mixed collections loaded from Excel or other sources.
Warnings from bulk operations are collected in the inherited _warning_collector.
Source code in src/pyetm/models/base.py
Attributes
combine
property
Helps users with quick access to a packer. The combine keyword makes sense when spelling out method calls to scenarios.
E.g. scenarios.combine.inputs.to_dataframe() or scenarios.combine.to_excel()
Functions
get_hourly_output_curves
Get hourly output curves for all scenarios by carrier type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
carrier_type
|
CarrierType
|
Carrier type alias (electricity, heat, hydrogen, methane) |
required |
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, DataFrame]]
|
Dictionary mapping curve names to scenario data |
Source code in src/pyetm/models/scenarios.py
get_annual_exports
Get annual exports for all scenarios, organized by export type.
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, DataFrame]]
|
Dict mapping export names to dicts of {scenario_title: DataFrame} |
Source code in src/pyetm/models/scenarios.py
load_all
classmethod
Load all saved scenarios belonging to the authenticated user.
Fetches all MyETM saved scenarios for the authenticated user in a single request. Returns all saved scenarios the user has access to (owned or shared).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Optional[BaseClient]
|
Optional BaseClient instance for API communication |
None
|
Returns:
| Type | Description |
|---|---|
'Scenarios'
|
Scenarios collection containing all user's saved scenarios |
Raises:
| Type | Description |
|---|---|
ValueError
|
If authentication fails or API request fails |
Source code in src/pyetm/models/scenarios.py
load_many
classmethod
Load multiple SavedScenario objects by their MyETM saved scenario IDs.
This is a bulk operation - individual failures are collected as warnings to allow partial success. Use PYETM_ERROR_MODE=safe to raise on first error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
saved_scenario_ids
|
Iterable[int]
|
Iterable of MyETM saved scenario IDs to load |
required |
client
|
Optional[BaseClient]
|
Optional BaseClient instance for API communication |
None
|
Returns:
| Type | Description |
|---|---|
'Scenarios'
|
SavedScenarios collection containing the loaded SavedScenario objects. |
'Scenarios'
|
Warnings from failures are collected in the warnings property. |
Source code in src/pyetm/models/scenarios.py
create_many
classmethod
Create multiple SavedScenario objects from parameter dicts.
If scenario_id is not provided in params, creates a new Session first.
This is a bulk operation - individual failures are collected as warnings to allow partial success. Use PYETM_ERROR_MODE=safe to raise on first error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scenario_params
|
Iterable[ScenarioCreationParams]
|
Iterable of ScenarioCreationParams dicts, each containing: - title: Title for the saved scenario (required) - scenario_id: (Optional) ETEngine scenario ID to save. If not provided, a new Session will be created using area_code and end_year - template_id: (Optional) Session ID to use as template. Inherits area_code and end_year from the template. - area_code: (Optional if using defaults or template_id) Area code for new session - end_year: (Optional if using defaults or template_id) End year for new session - user_values: (Optional) Dict of user input values to apply after creation - custom_curves: (Optional) Dict of custom curves to upload after creation - sortables: (Optional) Dict of sortables to apply after creation |
required |
area_code
|
str | None
|
Default area_code for all scenarios (if not in params) |
None
|
end_year
|
int | None
|
Default end_year for all scenarios (if not in params) |
None
|
client
|
BaseClient | None
|
Optional BaseClient instance (shared across all creates) |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Scenarios |
'Scenarios'
|
Collection of created scenarios. Warnings from individual failures are collected in the warnings property. |
Source code in src/pyetm/models/scenarios.py
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 | |
to_excel
Export all scenarios to Excel.
Note: This exports the underlying session data from each SavedScenario. The scenario_id column will contain Scenario IDs (MyETM).
Source code in src/pyetm/models/scenarios.py
from_excel
classmethod
Import all scenarios from Excel file.
Loads all scenarios from the Excel file, including both: - SavedScenarios (where 'session' column is False or missing) - Sessions (where 'session' column is True)
Returns:
| Type | Description |
|---|---|
'Scenarios'
|
Scenarios collection containing mixed Scenario and Session objects |
Source code in src/pyetm/models/scenarios.py
discard_many
classmethod
Discard multiple saved scenarios in bulk (soft-delete).
The scenarios are 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.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
saved_scenario_ids
|
List[int]
|
List of SavedScenario IDs to discard |
required |
client
|
Optional[BaseClient]
|
Optional BaseClient instance |
None
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dict with 'successful' and 'failed' keys containing lists of IDs |
Example
result = Scenarios.discard_many([1, 2, 3]) print(f"Discarded: {result['successful']}") print(f"Failed: {result['failed']}")