PowerSystemModeler
explain here what the PowerSystemModeler is and why
Supported Modelers
- PSS®E35: Industry-standard commercial power system analysis
- PyPSA: Open-source Python-based optimization framework
API Reference
PowerSystemModeler
Bases: ABC
Abstract base class for power system modeling backends.
Defines standardized interface for PSS®E, PyPSA, and other power system tools in WEC-GRID framework. Provides grid analysis, WEC integration, and time-series simulation capabilities through common API.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
engine
|
Any
|
WEC-GRID Engine with case_file, time, and wec_farms attributes. |
required |
Attributes:
Name | Type | Description |
---|---|---|
engine |
Reference to simulation engine. |
|
grid |
GridState
|
Time-series data for buses, generators, lines, loads. |
sbase |
float
|
System base power [MVA]. |
Example
from wecgrid.modelers import PSSEModeler, PyPSAModeler psse_model = PSSEModeler(engine) pypsa_model = PyPSAModeler(engine)
Notes
- Abstract class - use concrete implementations (PSSEModeler, PyPSAModeler)
- Grid state data follows standardized schema for cross-platform comparison
- All abstract methods must be implemented by subclasses
Source code in src/wecgrid/modelers/power_system/base.py
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 |
|
bus
property
Current bus state with columns: bus, bus_name, type, p, q, v_mag, angle_deg, base.
Returns:
Type | Description |
---|---|
Optional[DataFrame]
|
pd.DataFrame: Bus state data [p.u. on system MVA base] or None if no snapshots. |
bus_t
property
Time-series bus data for all snapshots.
Returns:
Type | Description |
---|---|
Dict[str, DataFrame]
|
Dict[str, pd.DataFrame]: Keys: timestamp strings, Values: bus state DataFrames. |
gen
property
Current generator state with columns: gen, bus, p, q, base, status.
Returns:
Type | Description |
---|---|
Optional[DataFrame]
|
pd.DataFrame: Generator state data [p.u. on generator MVA base] or None if no snapshots. |
gen_t
property
Time-series generator data for all snapshots.
Returns:
Type | Description |
---|---|
Dict[str, DataFrame]
|
Dict[str, pd.DataFrame]: Keys: timestamp strings, Values: generator state DataFrames. |
line
property
Current line state with columns: line, ibus, jbus, line_pct, status.
Returns:
Type | Description |
---|---|
Optional[DataFrame]
|
pd.DataFrame: Line state data [line_pct as % of thermal rating] or None if no snapshots. |
line_t
property
Time-series line data for all snapshots.
Returns:
Type | Description |
---|---|
Dict[str, DataFrame]
|
Dict[str, pd.DataFrame]: Keys: timestamp strings, Values: line state DataFrames. |
load
property
Current load state with columns: load, bus, p, q, base, status.
Returns:
Type | Description |
---|---|
Optional[DataFrame]
|
pd.DataFrame: Load state data [p.u. on system MVA base] or None if no snapshots. |
load_t
property
Time-series load data for all snapshots.
Returns:
Type | Description |
---|---|
Dict[str, DataFrame]
|
Dict[str, pd.DataFrame]: Keys: timestamp strings, Values: load state DataFrames. |
add_wec_farm(farm)
abstractmethod
Add WEC farm to power system model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
farm
|
WECFarm
|
WEC farm with connection details and power characteristics. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if farm added successfully, False otherwise. |
Raises:
Type | Description |
---|---|
ValueError
|
If WEC farm parameters invalid. |
Notes
Implementation should:
- Create new bus for WEC connection
- Add WEC generator with power characteristics
- Create transmission line to existing grid
- Update grid state after modifications
- Solve power flow to validate changes
Example
if modeler.add_wec_farm(wec_farm): ... print("WEC farm added successfully")
Source code in src/wecgrid/modelers/power_system/base.py
605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 |
|
init_api()
abstractmethod
Initialize backend power system tool and load case file.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if initialization successful, False otherwise. |
Raises:
Type | Description |
---|---|
ImportError
|
If backend tool not found or configured. |
ValueError
|
If case file invalid or cannot be loaded. |
Notes
Implementation should:
- Initialize backend API/environment
- Load case file (.sav, .raw, etc.)
- Set system base MVA (self.sbase)
- Perform initial power flow solution
- Take initial grid state snapshot
Example
if modeler.init_api(): ... print("Backend initialized successfully")
Source code in src/wecgrid/modelers/power_system/base.py
558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 |
|
simulate(load_curve=None)
abstractmethod
Run time-series simulation with WEC and load updates.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
load_curve
|
DataFrame
|
Load values for each bus at each snapshot. Index: snapshots, columns: bus IDs. If None, loads remain constant. |
None
|
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if simulation completes successfully, False otherwise. |
Raises:
Type | Description |
---|---|
Exception
|
If error updating components or solving power flow. |
Notes
Implementation should:
- Iterate through all time snapshots from engine.time
- Update WEC generator power outputs [MW] from farm data
- Update bus loads [MW] if load_curve provided
- Solve power flow at each time step
- Capture grid state snapshots for analysis
- Handle convergence failures gracefully
Example
Constant loads
modeler.simulate()
Time-varying loads
modeler.simulate(load_curve=load_df)
Source code in src/wecgrid/modelers/power_system/base.py
633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 |
|
solve_powerflow()
abstractmethod
Run power flow solution using backend solver.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if power flow converged, False otherwise. |
Notes
Implementation should:
- Call backend's power flow solver
- Check convergence status
- Handle solver-specific parameters
- Suppress verbose output if needed
Example
if modeler.solve_powerflow(): ... print("Power flow converged")
Source code in src/wecgrid/modelers/power_system/base.py
584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 |
|
take_snapshot(timestamp)
abstractmethod
Capture current grid state at specified timestamp.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
timestamp
|
datetime
|
Timestamp for the snapshot. |
required |
Notes
Implementation should:
- Extract bus data: voltages [p.u.], [degrees], power [MW], [MVAr]
- Extract generator data: power outputs [MW], [MVAr], status
- Extract line data: power flows [MW], [MVAr], loading [%]
- Extract load data: power consumption [MW], [MVAr]
- Convert to standardized WEC-GRID schema
- Store in self.grid with timestamp indexing
Example
modeler.take_snapshot(datetime.now())
Source code in src/wecgrid/modelers/power_system/base.py
666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 |
|