Grid Helpers#
Grid Helpers Pandapower#
toop_engine_grid_helpers.pandapower
#
toop_engine_grid_helpers.pandapower.example_grids
#
add_phaseshift_transformer_to_line
#
add_phaseshift_transformer_to_line(
net,
line_idx,
at_from_bus=True,
tap_min=-30,
tap_max=30,
tap_step_degree=2.0,
)
Inserts a phase-shifting transformer into the pandapower network on the given line.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The pandapower network.
TYPE:
|
line_idx
|
Index of the line in net.line on which to insert the phase-shifting transformer.
TYPE:
|
at_from_bus
|
If True, the phase-shifting transformer is inserted at the from-bus of the line. If False, it is inserted at the to-bus (default is True
TYPE:
|
tap_min
|
Minimum tap position of the phase-shifting transformer (default is -30).
TYPE:
|
tap_max
|
Maximum tap position of the phase-shifting transformer (default is 30).
TYPE:
|
tap_step_degree
|
Step size in degrees for the tap position of the phase-shifting transformer (default is 2.0).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
trafo_idx
|
The index of the newly created transformer in net.trafo.
TYPE:
|
helper_bus
|
The index of the newly created helper bus.
TYPE:
|
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/pandapower/example_grids.py
pandapower_case30_with_psts
#
Create a pandapower IEEE 30 bus grid with phase-shifting transformers.
| RETURNS | DESCRIPTION |
|---|---|
pandapowerNet
|
The pandapower IEEE 30 bus network with phase-shifting transformers. |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/pandapower/example_grids.py
pandapower_case30_with_psts_and_weak_branches
#
Create a pandapower IEEE 30 bus grid with phase-shifting transformers and overloaded branches.
| RETURNS | DESCRIPTION |
|---|---|
pandapowerNet
|
The pandapower IEEE 30 bus network with phase-shifting transformers and weak branches. |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/pandapower/example_grids.py
replace_bus_index
#
Replaces the bus index in a pandapower network
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The pandapower network to modify.
TYPE:
|
new_index
|
The new bus index
TYPE:
|
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/pandapower/example_grids.py
pandapower_extended_oberrhein
#
Creates a pandapower extended version of the oberrhein grid.
| RETURNS | DESCRIPTION |
|---|---|
pandapowerNet
|
A pandapower grid with additional elements. |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/pandapower/example_grids.py
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 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 | |
pandapower_non_converging_case57
#
Creates a ac-non-converging pandapower case57 grid.
Still converges in DC.
| RETURNS | DESCRIPTION |
|---|---|
pandapowerNet
|
A pandapower grid that does not converge in AC load flow. |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/pandapower/example_grids.py
pandapower_extended_case57
#
Creates a pandapower case57 grid with additional elements.
| RETURNS | DESCRIPTION |
|---|---|
pandapowerNet
|
A pandapower grid with additional elements |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/pandapower/example_grids.py
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 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 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 | |
example_multivoltage_cross_coupler
#
Expands the single busbar coupler to a double busbar with a busbar coupler and a cross coupler See also: https://github.com/e2nIEE/pandapower/blob/develop/tutorials/create_advanced.ipynb
DS- Disconnector (type CB) BB- Busbar (type b) BC- Busbar coupler (two nodes and three switches) CC- Cross coupler (two nodes and three switches) PS- Power switch / Branch switch Branch 1 Branch 2 | | / DS / DS | | | | / CB / CB | | ____| ____| | | | | | / DS | / DS | | CC ⅓ | | BB 1----------------|----------- _______/______ --------|-------------- BB 3 | | | | DS / DS / DS / DS / | | CC 2/4 | | BB 2----|-----------/--------- _______/________ -------------------|--------BB 4 | | | | DS / | | / DS | | | | |/| |/| BC ½ BC ¾
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/pandapower/example_grids.py
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 | |
toop_engine_grid_helpers.pandapower.loadflow_parameters
#
A Collection of Pandapower parameters used in the Loadflow Solver.
PANDAPOWER_LOADFLOW_PARAM_RUNPP
module-attribute
#
PANDAPOWER_LOADFLOW_PARAM_RUNPP = {
"distributed_slack": False,
"voltage_depend_loads": False,
"trafo_model": "t",
"numba": True,
"max_iteration": 20,
}
PANDAPOWER_LOADFLOW_PARAM_PPCI
module-attribute
#
PANDAPOWER_LOADFLOW_PARAM_PPCI = {
"calculate_voltage_angles": True,
"trafo_model": "t",
"check_connectivity": True,
"mode": "pf",
"switch_rx_ratio": 2,
"enforce_q_lims": False,
"voltage_depend_loads": False,
"consider_line_temperature": False,
"tdpf": False,
"tdpf_update_r_theta": True,
"tdpf_delay_s": None,
"distributed_slack": False,
"delta": 0,
"trafo3w_losses": "hv",
"init_results": True,
"p_lim_default": 1000000000.0,
"q_lim_default": 1000000000.0,
"neglect_open_switch_branches": False,
"tolerance_mva": 1e-08,
"trafo_loading": "current",
"numba": True,
"algorithm": "nr",
"max_iteration": 25,
"v_debug": False,
"only_v_results": False,
"use_umfpack": True,
"permc_spec": None,
"lightsim2grid": False,
"recycle": False,
}
PANDAPOWER_LOADFLOW_PARAM_PPCI_AC
module-attribute
#
PANDAPOWER_LOADFLOW_PARAM_PPCI_AC = {
None: PANDAPOWER_LOADFLOW_PARAM_PPCI,
"ac": True,
"init_vm_pu": "dc",
"init_va_degree": "dc",
}
PANDAPOWER_LOADFLOW_PARAM_PPCI_DC
module-attribute
#
PANDAPOWER_LOADFLOW_PARAM_PPCI_DC = {
None: PANDAPOWER_LOADFLOW_PARAM_PPCI,
"ac": False,
"init_vm_pu": "none",
"init_va_degree": "none",
}
toop_engine_grid_helpers.pandapower.pandapower_helpers
#
Holds functions that help with all sorts of pandapower conversions, that are not specific to a single task.
power_key_lookup_table
module-attribute
#
power_key_lookup_table = {
"def_active": {
"gen": "p_mw",
"sgen": "p_mw",
"load": "p_mw",
"shunt": "p_mw",
"dcline_from": "p_mw",
"dcline_to": "dcline",
"ward_load": "ps_mw",
"ward_shunt": "pz_mw",
"xward_load": "ps_mw",
"xward_shunt": "pz_mw",
},
"def_reactive": {
"sgen": "q_mvar",
"load": "q_mvar",
"shunt": "q_mvar",
"ward_load": "qs_mvar",
"ward_shunt": "qz_mvar",
"xward_load": "qs_mvar",
"xward_shunt": "qz_mvar",
},
"res_active": {
"gen": "p_mw",
"sgen": "p_mw",
"load": "p_mw",
"shunt": "p_mw",
"dcline_from": "p_from_mw",
"dcline_to": "p_to_mw",
"ward_load": "p_mw",
"xward_load": "p_mw",
},
"res_reactive": {
"gen": "q_mvar",
"sgen": "q_mvar",
"load": "q_mvar",
"shunt": "q_mvar",
"dcline_from": "q_from_mvar",
"dcline_to": "q_to_mvar",
"ward_load": "q_mvar",
"xward_load": "q_mvar",
},
}
type_mapper
module-attribute
#
type_mapper = {
"line": "res_line",
"trafo": "res_trafo",
"trafo3w_lv": "res_trafo3w",
"trafo3w_mv": "res_trafo3w",
"trafo3w_hv": "res_trafo3w",
"impedance": "res_impedance",
"xward": "res_xward",
}
sign_mapper
module-attribute
#
sign_mapper = {
"line": -1,
"trafo": -1,
"trafo3w_lv": 1,
"trafo3w_mv": 1,
"trafo3w_hv": -1,
"impedance": -1,
"xward": -1,
}
column_mapper
module-attribute
#
column_mapper = {
"active_from": {
"line": "p_from_mw",
"trafo": "p_hv_mw",
"trafo3w_lv": "p_lv_mw",
"trafo3w_mv": "p_mv_mw",
"trafo3w_hv": "p_hv_mw",
"impedance": "p_from_mw",
"xward": "p_mw",
},
"reactive_from": {
"line": "q_from_mvar",
"trafo": "q_hv_mvar",
"trafo3w_lv": "q_lv_mvar",
"trafo3w_mv": "q_mv_mvar",
"trafo3w_hv": "q_hv_mvar",
"impedance": "q_from_mvar",
"xward": "q_mvar",
},
"current_from": {
"line": "i_from_ka",
"trafo": "i_hv_ka",
"trafo3w_lv": "i_lv_ka",
"trafo3w_mv": "i_mv_ka",
"trafo3w_hv": "i_hv_ka",
"impedance": "i_from_ka",
"xward": "no_column",
},
"active_to": {
"line": "p_to_mw",
"trafo": "p_lv_mw",
"trafo3w_lv": "p_lv_mw",
"trafo3w_mv": "p_mv_mw",
"trafo3w_hv": "p_hv_mw",
"impedance": "p_to_mw",
"xward": "p_mw",
},
"reactive_to": {
"line": "q_to_mvar",
"trafo": "q_lv_mvar",
"trafo3w_lv": "q_lv_mvar",
"trafo3w_mv": "q_mv_mvar",
"trafo3w_hv": "q_hv_mvar",
"impedance": "q_to_mvar",
"xward": "q_mvar",
},
"current_to": {
"line": "i_to_ka",
"trafo": "i_lv_ka",
"trafo3w_lv": "i_lv_ka",
"trafo3w_mv": "i_mv_ka",
"trafo3w_hv": "i_hv_ka",
"impedance": "i_to_ka",
"xward": "no_column",
},
}
isnan_column_mapper
module-attribute
#
isnan_column_mapper = {
"line": "i_from_ka",
"trafo": "i_hv_ka",
"trafo3w_lv": "i_lv_ka",
"trafo3w_mv": "i_mv_ka",
"trafo3w_hv": "i_hv_ka",
"impedance": "i_from_ka",
}
get_phaseshift_key
#
Get the key of the shift_degree in the trafo
| PARAMETER | DESCRIPTION |
|---|---|
trafo_type
|
The type of trafo
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The key of the phaseshift attribute in the trafo(3w)dataframe |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/pandapower/pandapower_helpers.py
get_phaseshift_mask
#
Return the mask over phaseshifters in the ppci and the minimum and maximum setpoints for these PSTs
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The pandapower network to extract the data from
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
pst_mask
|
The mask over phaseshifters in the ppci, true if it is a trafo with a phase shift in the ppci
TYPE:
|
controllable_mask
|
The mask over controllable phase shifters in the ppci. True if a trafo has a tap that can change the phase shift Note that this won't catch trafos with a fixed shift_degree, only those which have a tap changer that can change the angle shift.
TYPE:
|
shift_taps
|
A list of arrays with the tap positions for each controllable phase shifter. The outer list has length sum(controllable_mask), the inner arrays have length equal to the number of taps of each PST (varying)
TYPE:
|
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/pandapower/pandapower_helpers.py
get_bus_key
#
Get the key of the bus in the branch name
| PARAMETER | DESCRIPTION |
|---|---|
branch_name
|
The name of the branch
TYPE:
|
branch_from_end
|
Whether to get the from or to bus, True for from, False for to
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The key of the bus in the branch name |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/pandapower/pandapower_helpers.py
get_bus_key_injection
#
Get the key of the bus in the injection type
| PARAMETER | DESCRIPTION |
|---|---|
injection_type
|
The type of the injection
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The key of the bus in the injection type |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/pandapower/pandapower_helpers.py
get_element_table
#
Get the element table for the injection or branch type or bus
| PARAMETER | DESCRIPTION |
|---|---|
element_type
|
The type description of the branch/injection/bus
TYPE:
|
res_table
|
Whether to get the res table. Defaults to False
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The element table for the branch/injection/bus type |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/pandapower/pandapower_helpers.py
get_power_key
#
Get the power key for the injection type in the res/non-res tables
| PARAMETER | DESCRIPTION |
|---|---|
element_type
|
The type description of the injection
TYPE:
|
res_table
|
Whether to get the key for the res table. Defaults to False
TYPE:
|
reactive
|
Whether to get the reactive power instead of the active power. Defaults to False
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The power key for the injection type in pandapowers |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/pandapower/pandapower_helpers.py
get_pandapower_loadflow_results_in_ppc
#
Get the loadflow result for all pandapower branches that are included in ppc (= even if not in service)
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The pandapower network with loadflows already computed
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Float[ndarray, ' n_branches_ppc']
|
|
An array of all loadflows of branches that are in ppci in the correct order
|
|
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/pandapower/pandapower_helpers.py
get_pandapower_loadflow_results_injection
#
Use a list of injection types and ids to get the loadflow results
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The pandapower network with loadflows already computed
TYPE:
|
types
|
The types of the injections, length n_injections
TYPE:
|
ids
|
The ids of the injections, length n_injections
TYPE:
|
reactive
|
Whether to get the reactive power instead of the active power. Defaults to False
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Float[ndarray, ' n_injections']
|
The loadflow results of the injections in the correct order |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/pandapower/pandapower_helpers.py
get_pandapower_branch_loadflow_results_sequence
#
get_pandapower_branch_loadflow_results_sequence(
net,
types,
ids,
measurement,
from_end=True,
fill_na=None,
adjust_signs=True,
)
Use a list of branch types and ids to get the loadflow results
This can also applied in case the network is slightly different than the net in the backend, e.g. to use a non-preprocessed net
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The pandapower network with loadflows already computed
TYPE:
|
types
|
The types of the branches, length n_branches
TYPE:
|
ids
|
The ids of the branches, length n_branches
TYPE:
|
measurement
|
The type of the measurement to get. Can be "active", "reactive" or "current"
TYPE:
|
from_end
|
Whether to get the results from the end of the branch. Defaults to True
TYPE:
|
fill_na
|
Whether to replace NaN values with a constant
TYPE:
|
adjust_signs
|
Whether to adjust the signs of the results according to the type of branch. Defaults to True
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Float[ndarray, ' n_branches']
|
The loadflow results of the branches in the correct order |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/pandapower/pandapower_helpers.py
get_pandapower_bus_loadflow_results_sequence
#
Use a list of bus ids to get the loadflow results
This can also applied in case the network is slightly different than the net in the backend, e.g. to use a non-preprocessed net
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The pandapower network with loadflows already computed
TYPE:
|
monitored_bus_ids
|
The ids of the buses, length n_buses
TYPE:
|
voltage_magnitude
|
Whether to get the voltage magnitude instead of the angle. Defaults to False
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Float[ndarray, ' n_buses']
|
The loadflow results of the buses in the correct order |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/pandapower/pandapower_helpers.py
check_for_splits
#
Check for splits by checking for NaN values
Unfortunately, p_xx values are zero on split in pandapower
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The pandapower network with loadflows already computed
TYPE:
|
monitored_branch_types
|
The types of the monitored branches, length N_branches
TYPE:
|
monitored_branch_ids
|
The ids of the monitored branches, length N_branches
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
Whether a split is present, i.e. any monitored branch has a NaN value |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/pandapower/pandapower_helpers.py
get_dc_bus_voltage
#
Get the bus voltage of all buses in the network under DC conditions
This is usually bus.vn_kv, except a generator is connected in which case the voltage is the generator voltage
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The pandapower network
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Series
|
The bus voltage of all buses in the network, indexed by bus id |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/pandapower/pandapower_helpers.py
get_shunt_real_power
#
Get the real power of all shunts in the network
| PARAMETER | DESCRIPTION |
|---|---|
bus_voltage
|
The voltage level of the buses the shunts are connected to
TYPE:
|
shunt_power
|
The power of the shunts
TYPE:
|
shunt_voltage
|
The voltage level of the shunts. Defaults to bus_voltage
TYPE:
|
shunt_step
|
The step of the shunts. Defaults to np.ones(shunt_power.shape[0], dtype=int)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Float[ndarray, ' n_shunts']
|
The real power of all shunts in the network |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/pandapower/pandapower_helpers.py
get_remotely_connected_buses
#
get_remotely_connected_buses(
net,
buses,
consider=("l", "s", "t", "t3", "i"),
respect_switches=True,
respect_in_service=False,
max_num_iterations=100,
)
Get the remotely connected buses, calls pp.toolbox.get_connected_buses until no more buses are found
This is useful for finding grid islands or stations and uses the same function interface as get_connected_buses
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The pandapower network
TYPE:
|
buses
|
The buses to get the remotely connected buses for
TYPE:
|
consider
|
The types of elements to consider. Defaults to all. Use ("s",) to only consider switches, which will limit the search to a station. According to the pandapower docs: - l: lines - s: switches - t: trafos - t3: trafo3ws - i: impedances
TYPE:
|
respect_switches
|
Whether to respect switches. If true, will not hop over open switches. Defaults to True
TYPE:
|
respect_in_service
|
Whether to respect the in_service flag of the elements. Will not hop over out-of-service elements. Defaults to False
TYPE:
|
max_num_iterations
|
After how many iterations to stop searching for new buses. Defaults to 100
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
set[int]
|
The remotely connected buses, indexed by bus id. In contrast to the pandapower function, this will include the set of buses passed in as a parameter except for those that are not in the network. |
| RAISES | DESCRIPTION |
|---|---|
RuntimeError
|
If the maximum number of iterations is reached without finding all connected buses |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/pandapower/pandapower_helpers.py
load_pandapower_from_fs
#
Load any pandapower network from a filesystem.
Supported formats are pandapower native (.json), Matpower (.mat), CGMES (.zip) and UCTE (.uct).
| PARAMETER | DESCRIPTION |
|---|---|
filesystem
|
The filesystem to load the pandapower network from.
TYPE:
|
file_path
|
The path to the pandapower network file.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
pandapowerNet
|
The loaded pandapower network. |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/pandapower/pandapower_helpers.py
save_pandapower_to_fs
#
Save pandapower network to a filesystem in pandapower native format (.json) or Matpower (.mat).
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The pandapower network to save.
TYPE:
|
filesystem
|
The filesystem to save the pandapower network to.
TYPE:
|
file_path
|
The path to save the pandapower network file to.
TYPE:
|
format
|
The format to save the pandapower network in. Can be "JSON" or "MATPOWER". Defaults to "JSON".
TYPE:
|
make_dir
|
create parent folder if not exists.
TYPE:
|
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/pandapower/pandapower_helpers.py
toop_engine_grid_helpers.pandapower.pandapower_id_helpers
#
Functions to handle pandapower ids
Pandapower indices are usually not globally unique, so we provide some helper functions to make them globally unique.
get_globally_unique_id
#
Get a globally unique id for an element
Unfortunately, pandapowers ids are only unique within their type, so we need to add the type to the id to make it globally unique.
| PARAMETER | DESCRIPTION |
|---|---|
elem_id
|
The id of the element
TYPE:
|
elem_type
|
The type of the element
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The globally unique id of the element |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/pandapower/pandapower_id_helpers.py
parse_globally_unique_id
#
Parse a globally unique id into its components
| PARAMETER | DESCRIPTION |
|---|---|
globally_unique_id
|
The globally unique id
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
int
|
The id of the element |
str
|
The type of the element |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/pandapower/pandapower_id_helpers.py
get_globally_unique_id_from_index
#
Parse a series of globally unique ids into a dataframe
| PARAMETER | DESCRIPTION |
|---|---|
element_idx
|
The index of the element table
TYPE:
|
element_type
|
The type of the element table (e.g. "bus", "line", etc.)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Index
|
The index with added table name as prefix to make it globally unique |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/pandapower/pandapower_id_helpers.py
parse_globally_unique_id_series
#
Parse a series of globally unique ids into a dataframe
| PARAMETER | DESCRIPTION |
|---|---|
globally_unique_ids
|
The series of globally unique ids
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
A dataframe with the id, type and name of the elements |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/pandapower/pandapower_id_helpers.py
table_id
#
Get the id in the pandapower table from a globally unique id
| PARAMETER | DESCRIPTION |
|---|---|
globally_unique_id
|
The globally unique id
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Union[int, str]
|
The id in the pandapower table |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/pandapower/pandapower_id_helpers.py
table_ids
#
Get the ids in the pandapower table from a list of globally unique ids
| PARAMETER | DESCRIPTION |
|---|---|
list_of_globally_unique_ids
|
The list of globally unique ids
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[int]
|
The ids in the pandapower table |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/pandapower/pandapower_id_helpers.py
toop_engine_grid_helpers.pandapower.pandapower_import_helpers
#
Module contains additional functions to process pandapower network.
File: pandapower_toolset.py Author: Created:
fuse_closed_switches_fast
#
Fuse closed switches in the network by merging busbars.
This routine uses an algorithm to number each busbar and then find the lowest connected busbar iteratively. If a busbar is connected to a lower-numbered busbar, it will be re-labeled to the lower-numbered busbar. This algorithm needs as many iterations as the maximum number of hops between the lowest and highest busbar in any of the substations.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The pandapower network to fuse closed switches in, will be modified in-place.
TYPE:
|
switch_ids
|
The switch ids to fuse. If None, all closed switches are fused.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
The closed switches that were fused. |
DataFrame
|
The buses that were dropped because they were relabeled to a lower-numbered busbar. |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/pandapower/pandapower_import_helpers.py
move_elements_based_on_labels
#
Move all elements in the network to the lowest labeled busbar.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The pandapower network to move elements in, will be modified in-place.
TYPE:
|
labels
|
The labels of the busbars to move the elements to.
TYPE:
|
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/pandapower/pandapower_import_helpers.py
select_connected_subnet
#
Select the connected subnet of the grid that has a slack and return it.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The pandapower network to select the connected subnet from.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
pandapowerNet
|
The connected subnet of the grid that has a slack. |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/pandapower/pandapower_import_helpers.py
replace_zero_branches
#
Replace zero-impedance branches with switches in the network.
Some leftover lines and xwards will be bumped to a higher impedance to avoid numerical issues.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The pandapower network to replace zero branches in, will be modified in-place.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
pandapowerNet
|
The network with zero branches replaced. |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/pandapower/pandapower_import_helpers.py
drop_unsupplied_buses
#
Drop all unsupplied buses from the network.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The pandapower network to drop unsupplied buses from, will be modified in-place.
TYPE:
|
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/pandapower/pandapower_import_helpers.py
create_virtual_slack
#
Create a virtual slack bus for all ext_grids in the network.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The pandapower network to create a virtual slack for, will be modified in-place. Note: network is modified in-place.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
pandapowerNet
|
The network with a virtual slack. |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/pandapower/pandapower_import_helpers.py
remove_out_of_service
#
Remove all out-of-service elements from the network.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The pandapower network to remove out-of-service elements from, will be modified in-place.
TYPE:
|
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/pandapower/pandapower_import_helpers.py
drop_elements_connected_to_one_bus
#
Drop elements connected to one bus.
- impedance -> Capacitor will end up on the same bus
- trafo3w -> edgecase: trafo3w that goes from one hv to the same level but two different busbars will end up on the same bus
| PARAMETER | DESCRIPTION |
|---|---|
net
|
pandapower network Note: the network is modified in place
TYPE:
|
branch_types
|
list of branch types to drop elements connected to one bus
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
None
|
|
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/pandapower/pandapower_import_helpers.py
handle_elements_connected_to_one_bus
#
Drop elements of a specific branch type connected to one bus.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
pandapower network Note: the network is modified in place
TYPE:
|
branch_type
|
branch type to drop elements connected to one bus
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the branch type is not recognized. |
AssertionError
|
If a two-winding transformer with same hv and lv bus is found. If a three-winding transformer with same hv == lv or hv == mv bus is found |
| RETURNS | DESCRIPTION |
|---|---|
None
|
|
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/pandapower/pandapower_import_helpers.py
toop_engine_grid_helpers.pandapower.pandapower_tasks
#
Holds functions helping with some pandapower related tasks
get_max_line_flow
#
Get the rated power for each line in the network
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The pandapower network containing the line
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Float[ndarray, ' n_pp_lines']
|
The rated power of each line branch in the network |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/pandapower/pandapower_tasks.py
get_max_trafo_flow
#
Get the rated power for each trafo in the network.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The pandapower network containing the trafos
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Float[ndarray, ' n_pp_trafos']
|
The rated power of each trafo branch in the network |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/pandapower/pandapower_tasks.py
get_max_trafo3w_flow
#
Get the rated power of the different voltage levels of all trafo3ws in the network
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The pandapower network containing the trafo3ws
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Float[ndarray, ' n_pp_trafo3ws*3']
|
The rated power of each trafo3w branch in the network |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/pandapower/pandapower_tasks.py
get_trafo3w_ppc_branch_idx
#
Get the corresponding branch ids of the trafo3w pandapower ids.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The pandapower network containing the trafo3ws
TYPE:
|
trafo3w_pp_idx
|
An array of trafo3w indices from pandapower
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Int[ndarray, ' 3 rel_trafo3ws']
|
Return a 3xnum_trafo3w_pp_idx array containing the hv, mv and lv ppci_branch_idx of the trafo3w |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/pandapower/pandapower_tasks.py
get_trafo3w_ppc_node_idx
#
Get the corresponding node indices of the trafo3w pandapower ids
| PARAMETER | DESCRIPTION |
|---|---|
ppci
|
The ppci dict from pandapower
TYPE:
|
trafo3w_branch_idx
|
An array of trafo3w indices as obtained from get_trafo3w_ppc_branch_idx
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Int[ndarray, ' rel_trafo3ws']
|
Return a num_trafo3w_pp_idx array containing the ppci node indices of the trafo3w |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/pandapower/pandapower_tasks.py
Grid Helpers Powsybl#
toop_engine_grid_helpers.powsybl
#
toop_engine_grid_helpers.powsybl.example_grids
#
add_phaseshift_transformer_to_line_powsybl
#
add_phaseshift_transformer_to_line_powsybl(
net,
line_idx,
tap_min=-30,
tap_max=30,
tap_step_degree=2.0,
)
Add a phaseshift transformer to the from side of a line
Inserts a helper bus and a transformer with a tap changer to the given line.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The powsybl network, will be modified in place.
TYPE:
|
line_idx
|
The index of the line in net.line on which to insert the phase-shifting transformer.
TYPE:
|
tap_min
|
The minimum tap position, by default -30
TYPE:
|
tap_max
|
The maximum tap position, by default 30
TYPE:
|
tap_step_degree
|
The step size in degrees for each tap position, by default 2.0
TYPE:
|
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/powsybl/example_grids.py
powsybl_case30_with_psts
#
Create a Powsybl IEEE 30 bus grid with phase-shifting transformers.
| RETURNS | DESCRIPTION |
|---|---|
Network
|
The Powsybl IEEE 30 bus network with phase-shifting transformers. |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/powsybl/example_grids.py
powsybl_extended_case57
#
Create an extended version of the Powsybl IEEE 57 bus grid with additional elements.
| RETURNS | DESCRIPTION |
|---|---|
Network
|
The extended Powsybl IEEE 57 bus network. |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/powsybl/example_grids.py
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 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | |
basic_node_breaker_network_powsybl
#
Create a basic node breaker network with 5 substations, 5 voltage levels, and 10 buses.
| RETURNS | DESCRIPTION |
|---|---|
Network
|
The created Powsybl network. |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/powsybl/example_grids.py
234 235 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 | |
powsybl_case9241
#
Load the Powsybl case9241 grid.
| RETURNS | DESCRIPTION |
|---|---|
Network
|
The loaded Powsybl pegase case9241 network. |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/powsybl/example_grids.py
create_busbar_b_in_ieee
#
Create busbar B in the IEEE grid
This is needed to create a busbar B for each bus in the IEEE grid. The busbar A is already there, so we just need to create the busbar B and connect it to the busbar A with a coupler.
The bus B will have an id similar to bus A but with '_b' suffixed.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The network to create the busbar Bs in, will be modified in place
TYPE:
|
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/powsybl/example_grids.py
extract_station_info_powsybl
#
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/powsybl/example_grids.py
case14_matching_asset_topo_powsybl
#
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/powsybl/example_grids.py
create_complex_grid_battery_hvdc_svc_3w_trafo
#
Create a complex grid with batteries, HVDC, SVC, and 3-winding transformers using Powsybl.
This grid includes various components to test different functionalities. It is not aimed to be a realistic representation of an actual power grid but rather a comprehensive test case. The Basecase should converge in about 10 iterations with a tolerance of 1e-6.
TODO: add sensable operational limits, maybe some ratio/phase tap changers, etc. Ideally it should have some overloads that can be solved by ToOp
| RETURNS | DESCRIPTION |
|---|---|
Network
|
The created complex grid network. |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/powsybl/example_grids.py
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 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 | |
create_complex_substation_layout_grid
#
Create a simplified complex substation-layout network using bay helpers.
This version uses create_voltage_level_topology, create_line_bays,
create_2_windings_transformer_bays and create_coupling_device to build
the same conceptual layout (two aligned busbars with three sections and
three couplers) in a lot fewer lines of code.
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/powsybl/example_grids.py
1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 | |
three_node_pst_example
#
Creates a 3 node example grid with 2 PSTs in it
If all N-1 branch cases are computed, there is a limit violation on the BC lines in the default setting (tap 0). However, by changing the tap to -12 (AC) or -10 (DC), the violations can be healed.
This grid can be used to test tap optimization algorithms, which ideally should find a tap that can resolve the problem.
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/powsybl/example_grids.py
1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 | |
toop_engine_grid_helpers.powsybl.loadflow_parameters
#
A collection of Powsybl parameters used in the Loadflow Solver.
OPENLOADFLOW_PARAM_PF
module-attribute
#
OPENLOADFLOW_PARAM_PF = {
"voltageInitModeOverride": "VOLTAGE_MAGNITUDE",
"reactiveLimitsMaxPpvSwitch": "0",
"svcVoltageMonitoring": "false",
"maxActivePowerMismatch": "0.0001",
"maxReactivePowerMismatch": "0.00001",
"maxNewtonRaphsonIterations": "25",
"newtonRaphsonStoppingCriteriaType": "PER_EQUATION_TYPE_CRITERIA",
"generatorReactivePowerRemoteControl": "true",
"plausibleActivePowerLimit": "300",
"useActiveLimits": "false",
"minPlausibleTargetVoltage": "0.893",
"maxPlausibleTargetVoltage": "1.105",
}
POWSYBL_LOADFLOW_PARAM_PF
module-attribute
#
POWSYBL_LOADFLOW_PARAM_PF = Parameters(
balance_type=PROPORTIONAL_TO_GENERATION_P_MAX,
connected_component_mode=MAIN,
countries_to_balance=None,
dc_power_factor=1.0,
dc_use_transformer_ratio=True,
distributed_slack=True,
phase_shifter_regulation_on=False,
provider_parameters=OPENLOADFLOW_PARAM_PF,
read_slack_bus=True,
shunt_compensator_voltage_control_on=False,
transformer_voltage_control_on=False,
use_reactive_limits=True,
twt_split_shunt_admittance=False,
voltage_init_mode=PREVIOUS_VALUES,
write_slack_bus=True,
)
SDL_PARAM
module-attribute
#
SDL_PARAM = SldParameters(
use_name=True,
component_library="Convergence",
nodes_infos=True,
display_current_feeder_info=True,
)
NAD_PARAM
module-attribute
#
DISTRIBUTED_SLACK
module-attribute
#
DISTRIBUTED_SLACK = Parameters(
distributed_slack=True,
balance_type=PROPORTIONAL_TO_GENERATION_P,
voltage_init_mode=DC_VALUES,
provider_parameters={
"slackDistributionFailureBehavior": "LEAVE_ON_SLACK_BUS"
},
dc_use_transformer_ratio=True,
)
SINGLE_SLACK
module-attribute
#
toop_engine_grid_helpers.powsybl.powsybl_asset_topo
#
Module contains functions to translate the powsybl model to the asset topology model.
File: asset_topology.py Author: Benjamin Petrick Created: 2024-09-18
get_all_element_names
#
Get the names of all injections and branches in the network.
For trafo and line -> elementName For the rest -> name
| PARAMETER | DESCRIPTION |
|---|---|
network
|
pypowsybl network object
TYPE:
|
line_trafo_name_col
|
Column name for the element names of lines and trafos
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
all_names
|
Series with the names of all injections and branches in the network and their ids as index
TYPE:
|
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/powsybl/powsybl_asset_topo.py
get_asset_switching_table
#
Get the asset switching table, which holds the switching of each asset to each busbar.
| PARAMETER | DESCRIPTION |
|---|---|
station_buses
|
DataFrame with the station busbars Note: The DataFrame is expected be sorted by its "int_id".
TYPE:
|
station_elements
|
DataFrame with the injections and branches at the station Note: The DataFrame is expected to have a column "bus_int_id" which holds the busbar id for each asset.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
switching_matrix
|
Switching matrix with the shape (n_bus, n_asset) where n_bus is the number of busbars and n_asset is the number of assets.
TYPE:
|
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/powsybl/powsybl_asset_topo.py
get_list_of_coupler_from_df
#
Get the list of coupler elements from the DataFrame.
| PARAMETER | DESCRIPTION |
|---|---|
coupler_elements
|
DataFrame with the coupler elements Note: datatype of columns is expected to be the same as in the pydantic model.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
coupler_list
|
List of coupler elements.
TYPE:
|
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/powsybl/powsybl_asset_topo.py
get_list_of_switchable_assets_from_df
#
get_list_of_switchable_assets_from_df(
station_branches,
asset_bay_list=None,
asset_bay_dict=None,
)
Get the list of switchable assets from the DataFrame.
| PARAMETER | DESCRIPTION |
|---|---|
station_branches
|
DataFrame with the switchable assets Note: datatype of columns is expected to be the same as in the pydantic model.
TYPE:
|
asset_bay_list
|
List of asset bays. Note: The list is expected to have the same length as the station_branches.
TYPE:
|
asset_bay_dict
|
Dictionary of asset bays with the asset grid_model_id as key.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
switchable_assets_list
|
List of switchable assets.
TYPE:
|
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/powsybl/powsybl_asset_topo.py
get_list_of_busbars_from_df
#
Get the list of busbars from the DataFrame.
| PARAMETER | DESCRIPTION |
|---|---|
station_buses
|
DataFrame with the busbars Note: datatype of columns is expected to be the same as in the pydantic model.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
busbar_list
|
List of busbars.
TYPE:
|
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/powsybl/powsybl_asset_topo.py
get_bus_info_from_topology
#
Get the info for all busbars that are part of the bus.
| PARAMETER | DESCRIPTION |
|---|---|
station_buses
|
Dataframe with all busbars of the station and which bus they are connected to. Comes from BusBreakerTopology.buses
TYPE:
|
bus_id
|
Bus id for which the buses should be retrieved.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
station_buses
|
DataFrame with the busbars of the specified bus. Note: The DataFrame columns are the same as in the pydantic model.
TYPE:
|
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/powsybl/powsybl_asset_topo.py
get_coupler_info_from_topology
#
Get the coupler elements that are connected to the busbars of the station.
| PARAMETER | DESCRIPTION |
|---|---|
station_switches
|
Dataframe of all switches at the station and which busbars they connect Comes from BusBreakerTopology.switches
TYPE:
|
switches_df
|
DataFrame of all switches in the network
TYPE:
|
station_buses
|
Formatted dataframe of all busbars at the station.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
coupler_elements
|
DataFrame with the coupler elements of the station. Note: The DataFrame columns are the same as in the pydantic model.
TYPE:
|
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/powsybl/powsybl_asset_topo.py
get_name_of_station_elements
#
Attach the name of the elements to the station elements.
| PARAMETER | DESCRIPTION |
|---|---|
station_elements
|
DataFrame with the station elements Comes from BusBreakerTopology.elements
TYPE:
|
element_names
|
Series with the names of all injections and branches in the network and their ids as index
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
station_elements
|
DataFrame with the names of the elements attached
TYPE:
|
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/powsybl/powsybl_asset_topo.py
get_asset_info_from_topology
#
Get the asset information of all elements at the station.
| PARAMETER | DESCRIPTION |
|---|---|
station_elements
|
DataFrame with the station elements Comes from BusBreakerTopology.elements
TYPE:
|
station_buses
|
DataFrame with the busbars of the station
TYPE:
|
dangling_lines
|
DataFrame of all dangling lines in the network with column "tie_line_id"
TYPE:
|
element_names
|
Series with the names of all injections and branches in the network and their ids as index
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
station_elements
|
DataFrame with the asset information
TYPE:
|
switching_matrix
|
Switching matrix with the shape (n_bus, n_asset) where n_bus is the number of busbars and n_asset is the number of assets. True, where the asset is connected to the busbar.
TYPE:
|
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/powsybl/powsybl_asset_topo.py
get_relevant_network_data
#
Get the relevant data from the network that is required for all stations.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
pypowsybl network object
TYPE:
|
relevant_stations
|
The relevant stations to be included in the resulting topology. Either as a boolean mask over all buses in network.get_buses or as a list of bus ids in network.get_buses()
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
buses_with_substation_and_voltage
|
DataFrame with the relevant buses, substation id and voltage level
TYPE:
|
switches
|
DataFrame with all the switches in the network. Includes the column "name"
TYPE:
|
dangling_lines
|
DataFrame with all the dangling lines in the network. Includes the column "tie_line_id"
TYPE:
|
element_names
|
Series with the names of all injections and branches in the network and their ids as index
TYPE:
|
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/powsybl/powsybl_asset_topo.py
get_relevant_stations
#
Get all relevant stations from the network.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
pypowsybl network object
TYPE:
|
relevant_stations
|
The relevant stations to be included in the resulting topology. Either as a boolean mask over all buses in network.get_buses or as a list of bus ids in network.get_buses()
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
station
|
List of all formatted stations of the relevant buses in the network
TYPE:
|
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/powsybl/powsybl_asset_topo.py
get_list_of_stations
#
get_list_of_stations(
network,
buses_with_substation_and_voltage,
switches,
dangling_lines,
element_names,
)
Get the list of stations from the relevant buses.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
pypowsybl network object
TYPE:
|
buses_with_substation_and_voltage
|
DataFrame with the relevant buses, substation id and voltage level
TYPE:
|
switches
|
DataFrame with all the switches in the network. Includes the column "name"
TYPE:
|
dangling_lines
|
DataFrame with all the dangling lines in the network. Includes the column "tie_line_id"
TYPE:
|
element_names
|
Series with the names of all injections and branches in the network and their ids as index
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
station_list
|
List of all formatted stations of the relevant buses in the network
TYPE:
|
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/powsybl/powsybl_asset_topo.py
get_topology
#
Get the pydantic topology model from the network.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
pypowsybl network object
TYPE:
|
relevant_stations
|
The relevant stations to be included in the resulting topology. Either as a boolean mask over all buses in network.get_buses or as a list of bus ids in network.get_buses()
TYPE:
|
topology_id
|
Id of the topology to set in the asset topology
TYPE:
|
grid_model_file
|
Path to the grid model file to set in the asset topology
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
topology
|
Topology object, including all relevant stations
TYPE:
|
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/powsybl/powsybl_asset_topo.py
get_stations_bus_breaker
#
Convert all stations in a bus-breaker topology grid to the asset topology format.
This is very similar to get_topology but only works for bus-breaker grids. This is mainly used for the test grids. TODO find out why get_topology didn't work and remove either of the two.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The bus/breaker powsybl network to convert
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
stations
|
List of all stations in the network
TYPE:
|
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/powsybl/powsybl_asset_topo.py
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 | |
assert_station_in_network
#
assert_station_in_network(
net,
station,
couplers_strict=True,
assets_strict=True,
busbars_strict=True,
)
Check if an asset topology station and all assets/busbars are actually in the station in the grid
This only checks subsets, i.e. if all asset in the asset topology are also in the grid. If there are more assets in the grid, this will not raise by default. You can enable strict equality checking by setting ..._strict to True.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The powsybl network to check the station in
TYPE:
|
station
|
The asset topology station to check
TYPE:
|
couplers_strict
|
If you opt out of strict coupler checking, it will only be checked if all couplers in the station are present in the grid, not vice versa.
TYPE:
|
assets_strict
|
If you opt out of strict asset checking, it will only be checked if all assets in the station are present in the grid, not vice versa.
TYPE:
|
busbars_strict
|
If you opt out of strict busbar checking, it will only be checked if all busbars in the station are present in the grid, not vice versa.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the station or any of the assets/busbars are not in the network |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/powsybl/powsybl_asset_topo.py
toop_engine_grid_helpers.powsybl.powsybl_helpers
#
Provides general helper functions for pypowsybl networks.
These functions are used to extract and manipulate data from pypowsybl networks, such as loadflow results, branch limits, and monitored elements.
extract_single_injection_loadflow_result
#
Extract the loadflow results for a single injection.
| PARAMETER | DESCRIPTION |
|---|---|
injections
|
The injections dataframe with the loadflow results
TYPE:
|
injection_id
|
The id of the injection to extract
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[float, float]
|
The active and reactive power of the injection |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/powsybl/powsybl_helpers.py
extract_single_branch_loadflow_result
#
Extract the loadflow results for a single branch
| PARAMETER | DESCRIPTION |
|---|---|
branches
|
The branches dataframe with the loadflow results
TYPE:
|
branch_id
|
The id of the branch to extract
TYPE:
|
from_side
|
If True, the from side is used, by default True If False, the to side is used
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[float, float]
|
The active and reactive power of the branch |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/powsybl/powsybl_helpers.py
get_branches_with_i
#
Get the get_branches results with the i values filled
In DC, they are Nan and will be computed through p = i * v, in AC they are already computed
| PARAMETER | DESCRIPTION |
|---|---|
branches
|
The result of net.get_branches() with or without i values
TYPE:
|
net
|
The powsybl network to load voltage information from
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
The result of net.get_branches(), but with the i values filled |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/powsybl/powsybl_helpers.py
get_injections_with_i
#
Get the get_injections results with the i values filled
In DC, they are Nan and will be computed through p = i * v, in AC they are already computed
| PARAMETER | DESCRIPTION |
|---|---|
injections
|
The result of net.get_injections() with or without i values
TYPE:
|
net
|
The powsybl network to load voltage information from
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
The result of net.get_injections(), but with the i values filled |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/powsybl/powsybl_helpers.py
get_branches_with_i_max
#
Get the get_branches results with the i_max values
These will be pulled from the current limits table. If one side is missing, the other side will be taken. If both sides are missing, the value will be NaN
| PARAMETER | DESCRIPTION |
|---|---|
branches
|
The result of net.get_branches() without i_max values
TYPE:
|
net
|
The powsybl network with current limits
TYPE:
|
limit_name
|
The name of the limit to pull, by default "permanent_limit"
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
The result of net.get_branches(), but with i1_max and i2_max columns |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/powsybl/powsybl_helpers.py
get_voltage_level_with_region
#
Get the region for each voltage level in the network.
This function is an extension to the network.get_voltage_levels() function. It retrieves the region for each voltage level using the substation region.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
The network for which the regions should be retrieved.
TYPE:
|
attributes
|
The attributes that should be retrieved for the voltage levels. Behaves like the attributes parameter in network.get_voltage_levels().
TYPE:
|
all_attributes
|
If True, all attributes are retrieved for the voltage levels. Behaves like the all_attributes parameter in network.get_voltage_levels().
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
A DataFrame with the voltage levels and their regions. |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/powsybl/powsybl_helpers.py
change_dangling_to_tie
#
Change the type of the dangling lines to TIE_LINE.
Changes dangling lines if a tie line is present. Keep Dangling lines if no tie line is present.
| PARAMETER | DESCRIPTION |
|---|---|
dangling_lines
|
Dataframe of all dangling lines in the network with column "tie_line_id"
TYPE:
|
station_elements
|
DataFrame with the injections and branches of the bus
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
A copy of the station_elements dataframe with all dangling lines that are actually part of a tie line set to TIE_LINE. |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/powsybl/powsybl_helpers.py
load_powsybl_from_fs
#
load_powsybl_from_fs(
filesystem,
file_path,
parameters=None,
post_processors=None,
report_node=None,
allow_variant_multi_thread_access=False,
)
Load any supported Powsybl network format from a filesystem.
Supported standard Powsybl formats like CGMES (.zip), powsybl nativa (.xiddm), UCTE (.uct), Matpower (.mat).
For all supported formats, see pypowsybl documentation for pypowsybl.network.load:
https://powsybl.readthedocs.io/projects/powsybl-core/en/stable/grid_exchange_formats/index.html
| PARAMETER | DESCRIPTION |
|---|---|
filesystem
|
The filesystem to load the Powsybl network from.
TYPE:
|
file_path
|
The path to the Powsybl network in the filesystem.
TYPE:
|
parameters
|
Additional parameters to pass to the pypowsybl.network.load function, by default None
TYPE:
|
post_processors
|
a list of import post processors (will be added to the ones defined by the platform config), by default None
TYPE:
|
report_node
|
the reporter to be used to create an execution report
TYPE:
|
allow_variant_multi_thread_access
|
allow multi-thread access to variant, by default False
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Network
|
The loaded Powsybl network. |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/powsybl/powsybl_helpers.py
save_powsybl_to_fs
#
Save any supported Powsybl network format to a filesystem.
Supported standard Powsybl formats like CGMES (.zip), powsybl nativa (.xiddm), UCTE (.uct), Matpower (.mat).
For all supported formats, see pypowsybl documentation for pypowsybl.network.save:
https://powsybl.readthedocs.io/projects/powsybl-core/en/stable/grid_exchange_formats/index.html
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The Powsybl network to save.
TYPE:
|
filesystem
|
The filesystem to save the Powsybl network to.
TYPE:
|
file_path
|
The path to save the Powsybl network in the filesystem.
TYPE:
|
format
|
The format to save the Powsybl network in, by default "CGMES".
TYPE:
|
make_dir
|
create parent folder if not exists.
TYPE:
|
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/powsybl/powsybl_helpers.py
select_a_generator_as_slack_and_run_loadflow
#
Select a generator as slack and run loadflow.
Powsybl tends to set the reference bus and slack as two different buses. Additionally, in some cases the slack is not a generator bus. This function selects a generator as slack bus and runs the loadflow again.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
The Powsybl network to modify and run loadflow on.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the loadflow does not converge after setting the slack. If the slack bus is not a generator. |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/powsybl/powsybl_helpers.py
load_pandapower_net_for_powsybl
#
Load a pandapower network and convert it to a pypowsybl network.
Known pandapower test grids that fail to convert: (This list is a logical AND of convert_from_pandapower and grid2opt conversion methods + the logical OR of check_powsybl_import errors) 'example_multivoltage' -> Generator minimum reactive power is not set 'simple_four_bus_system' -> Generator minimum reactive power is not set 'simple_mv_open_ring_net' -> 2 windings transformer '0_1_6': b is invalid 'create_cigre_network_hv' -> Generator minimum reactive power is not set 'create_cigre_network_lv' -> No Slack Generator found 'case145' -> Transformer with negative resistance 'case_illinois200' -> No Slack Generator found 'case300' -> No Slack Generator found
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The pandapower network to convert.
TYPE:
|
check_trafo_resistance
|
If True, check for negative transformer resistance after conversion, by default True
TYPE:
|
set_slack_generator
|
If True, select a generator as slack and run loadflow after conversion, by default True
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Network
|
The converted pypowsybl network. |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/powsybl/powsybl_helpers.py
load_pandapower_net_for_powsybl_with_convert_from_pandapower
#
Load a pandapower network and convert it to a pypowsybl network using convert_from_pandapower.
Known pandapower test grids that fail to convert: 'example_simple' -> Generator minimum reactive power is not set 'example_multivoltage' -> Generator minimum reactive power is not set 'simple_four_bus_system' -> Generator minimum reactive power is not set 'simple_mv_open_ring_net' -> 2 windings transformer '0_1_6': b is invalid 'create_cigre_network_hv' -> Generator minimum reactive power is not set
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The pandapower network to convert.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Network
|
The converted pypowsybl network. |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/powsybl/powsybl_helpers.py
load_pandapower_net_via_grid2opt_for_powsybl
#
Load a pandapower network and convert it to a pypowsybl network using grid2opt.
Known pandapower test grids that fail to convert: 'example_multivoltage' -> Transformer with negative resistance 'create_cigre_network_hv' -> Line with different voltage levels -> failed transformer conversion 'case14' -> Line with different voltage levels -> failed transformer conversion 'case_ieee30' -> Line with different voltage levels -> failed transformer conversion 'case57' -> Line with different voltage levels -> failed transformer conversion 'case89pegase' -> Line with different voltage levels -> failed transformer conversion 'case118' -> Line with different voltage levels -> failed transformer conversion 'case145' -> Transformer with negative resistance 'case_illinois200' -> Line with different voltage levels -> failed transformer conversion 'case300' -> Line with different voltage levels -> failed transformer conversion
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The pandapower network to convert.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Network
|
The converted pypowsybl network. |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/powsybl/powsybl_helpers.py
check_powsybl_import
#
Check the import of a pypowsybl network.
| PARAMETER | DESCRIPTION |
|---|---|
pypowsybl_network
|
The pypowsybl network to test.
TYPE:
|
check_trafo_resistance
|
If True, check for negative transformer resistance, by default True
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If a transformer with negative resistance is found in the converted network. If a line with different voltage levels is found in the converted network. If the load flow does not converge. |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/powsybl/powsybl_helpers.py
Grid Helpers Single Line Diagram#
toop_engine_grid_helpers.powsybl.single_line_diagram.constants
#
Defines constants used in the SLD (Single Line Diagram) importer module.
Style guide: Colors for Voltage Levels Voltage level >=400kV (220, 255, 220) | #DCFFDC | NEW Voltage level 380kV (160, 255, 166) | #A0FFA6 Voltage level 220kV (60, 163, 40) | #3CA328 Voltage level 150.sld-bus-170kV (44, 122, 30) | #2C7A1E | NEW Voltage level 110kV (15, 90, 0) | #0F5A00 Voltage level 66kV (80, 255, 90) | #50FF5A | NEW Voltage level <=33kV (12, 244, 30) | #0CF41E Grounded (182, 132, 18) | #B68412 No voltage (255, 0, 0) | #FF0000 Data invalid (200, 10, 200) | #C80AC8 Blocked (0, 120, 230) | #0078E6 Bypass busbar (255, 255, 25) | #E1E119 Manual entry (255, 255, 25) | #E1E119
Line thickness: 3px Switches: Open: Square 18x18, Outline 2px inside in the color of the voltage level, Background color: color/base/levels/04 Closed: Square 18x18, Color of the voltage level Disconnector: Open: Square 16.97x16.97 rotated by 45 degrees, outline 2px inside in the color of the voltage level, background color: color/base/levels/04 Closed: Square 16.97x16.97 rotated by 45 degrees, color of the voltage level
SLD_CSS
module-attribute
#
SLD_CSS = "<![CDATA[\n/* ----------------------------------------------------------------------- */\n/* File: tautologies.css ------------------------------------------------- */\n.sld-out .sld-arrow-in {visibility: hidden}\n.sld-in .sld-arrow-out {visibility: hidden}\n.sld-closed .sld-sw-open {visibility: hidden}\n.sld-open .sld-sw-closed {visibility: hidden}\n.sld-hidden-node {visibility: hidden}\n.sld-top-feeder .sld-label {dominant-baseline: auto}\n.sld-bottom-feeder .sld-label {dominant-baseline: hanging}\n.sld-active-power .sld-label {dominant-baseline: mathematical}\n.sld-reactive-power .sld-label {dominant-baseline: mathematical}\n.sld-current .sld-label {dominant-baseline: mathematical}\n/* ----------------------------------------------------------------------- */\n/* File: topologicalBaseVoltages.css ------------------------------------- */\n.sld-disconnected {--sld-vl-color: #FF0000}\n.sld-vl300to500.sld-bus-0 {--sld-vl-color: #A0FFA6}\n.sld-vl300to500.sld-bus-1 {--sld-vl-color: #D56701}\n.sld-vl300to500.sld-bus-2 {--sld-vl-color: #3E8AD0}\n.sld-vl300to500.sld-bus-3 {--sld-vl-color: #A0FFA6}\n.sld-vl300to500.sld-bus-4 {--sld-vl-color: #A0FFA6}\n.sld-vl300to500.sld-bus-5 {--sld-vl-color: #A0FFA6}\n.sld-vl300to500.sld-bus-6 {--sld-vl-color: #A0FFA6}\n.sld-vl300to500.sld-bus-7 {--sld-vl-color: #A0FFA6}\n.sld-vl300to500.sld-bus-8 {--sld-vl-color: #A0FFA6}\n.sld-vl300to500.sld-bus-9 {--sld-vl-color: #A0FFA6}\n.sld-vl300to500.highlight {--sld-vl-color: #0050fcff}\n.sld-vl180to300.sld-bus-0 {--sld-vl-color: #3CA328}\n.sld-vl180to300.sld-bus-1 {--sld-vl-color: #7C5CC3}\n.sld-vl180to300.sld-bus-2 {--sld-vl-color: #A67D00}\n.sld-vl180to300.sld-bus-3 {--sld-vl-color: #3CA328}\n.sld-vl180to300.sld-bus-4 {--sld-vl-color: #3CA328}\n.sld-vl180to300.sld-bus-5 {--sld-vl-color: #3CA328}\n.sld-vl180to300.sld-bus-6 {--sld-vl-color: #3CA328}\n.sld-vl180to300.sld-bus-7 {--sld-vl-color: #3CA328}\n.sld-vl180to300.sld-bus-8 {--sld-vl-color: #3CA328}\n.sld-vl180to300.sld-bus-9 {--sld-vl-color: #3CA328}\n.sld-vl180to300.highlight {--sld-vl-color: #0050fcff}\n.sld-vl120to180.sld-bus-0 {--sld-vl-color: #2C7A1E}\n.sld-vl120to180.sld-bus-1 {--sld-vl-color: #72858C}\n.sld-vl120to180.sld-bus-2 {--sld-vl-color: #D94814}\n.sld-vl120to180.sld-bus-3 {--sld-vl-color: #2C7A1E}\n.sld-vl120to180.sld-bus-4 {--sld-vl-color: #2C7A1E}\n.sld-vl120to180.sld-bus-5 {--sld-vl-color: #2C7A1E}\n.sld-vl120to180.sld-bus-6 {--sld-vl-color: #2C7A1E}\n.sld-vl120to180.sld-bus-7 {--sld-vl-color: #2C7A1E}\n.sld-vl120to180.sld-bus-8 {--sld-vl-color: #2C7A1E}\n.sld-vl120to180.sld-bus-9 {--sld-vl-color: #2C7A1E}\n.sld-vl120to180.highlight {--sld-vl-color: #0050fcff}\n.sld-vl70to120.sld-bus-0 {--sld-vl-color: #0F5A00}\n.sld-vl70to120.sld-bus-1 {--sld-vl-color: #699720}\n.sld-vl70to120.sld-bus-2 {--sld-vl-color: #CB2D64}\n.sld-vl70to120.sld-bus-3 {--sld-vl-color: #0F5A00}\n.sld-vl70to120.sld-bus-4 {--sld-vl-color: #0F5A00}\n.sld-vl70to120.sld-bus-5 {--sld-vl-color: #0F5A00}\n.sld-vl70to120.sld-bus-6 {--sld-vl-color: #0F5A00}\n.sld-vl70to120.sld-bus-7 {--sld-vl-color: #0F5A00}\n.sld-vl70to120.sld-bus-8 {--sld-vl-color: #0F5A00}\n.sld-vl70to120.sld-bus-9 {--sld-vl-color: #0F5A00}\n.sld-vl70to120.highlight {--sld-vl-color: #0050fcff}\n.sld-vl50to70.sld-bus-0 {--sld-vl-color: #50FF5A}\n.sld-vl50to70.sld-bus-1 {--sld-vl-color: #50FF5A}\n.sld-vl50to70.sld-bus-2 {--sld-vl-color: #50FF5A}\n.sld-vl50to70.sld-bus-3 {--sld-vl-color: #50FF5A}\n.sld-vl50to70.sld-bus-4 {--sld-vl-color: #50FF5A}\n.sld-vl50to70.sld-bus-5 {--sld-vl-color: #50FF5A}\n.sld-vl50to70.sld-bus-6 {--sld-vl-color: #50FF5A}\n.sld-vl50to70.sld-bus-7 {--sld-vl-color: #50FF5A}\n.sld-vl50to70.sld-bus-8 {--sld-vl-color: #50FF5A}\n.sld-vl50to70.sld-bus-9 {--sld-vl-color: #50FF5A}\n.sld-vl50to70.highlight {--sld-vl-color: #0050fcff}\n.sld-vl30to50.sld-bus-0 {--sld-vl-color: #0CF41E}\n.sld-vl30to50.sld-bus-1 {--sld-vl-color: #0CF41E}\n.sld-vl30to50.sld-bus-2 {--sld-vl-color: #0CF41E}\n.sld-vl30to50.sld-bus-3 {--sld-vl-color: #0CF41E}\n.sld-vl30to50.sld-bus-4 {--sld-vl-color: #0CF41E}\n.sld-vl30to50.sld-bus-5 {--sld-vl-color: #0CF41E}\n.sld-vl30to50.sld-bus-6 {--sld-vl-color: #0CF41E}\n.sld-vl30to50.sld-bus-7 {--sld-vl-color: #0CF41E}\n.sld-vl30to50.sld-bus-8 {--sld-vl-color: #0CF41E}\n.sld-vl30to50.sld-bus-9 {--sld-vl-color: #0CF41E}\n.sld-vl30to50.highlight {--sld-vl-color: #0050fcff}\n.sld-vl0to30.sld-bus-0 {--sld-vl-color: #0CF41E}\n.sld-vl0to30.sld-bus-1 {--sld-vl-color: #0CF41E}\n.sld-vl0to30.sld-bus-2 {--sld-vl-color: #0CF41E}\n.sld-vl0to30.sld-bus-3 {--sld-vl-color: #0CF41E}\n.sld-vl0to30.sld-bus-4 {--sld-vl-color: #0CF41E}\n.sld-vl0to30.sld-bus-5 {--sld-vl-color: #0CF41E}\n.sld-vl0to30.sld-bus-6 {--sld-vl-color: #0CF41E}\n.sld-vl0to30.sld-bus-7 {--sld-vl-color: #0CF41E}\n.sld-vl0to30.sld-bus-8 {--sld-vl-color: #0CF41E}\n.sld-vl0to30.sld-bus-9 {--sld-vl-color: #0CF41E}\n.sld-vl0to30.highlight {--sld-vl-color: #0050fcff}\n\n\n/* ----------------------------------------------------------------------- */\n/* File : highlightLineStates.css ---------------------------------------- */\n.sld-wire.sld-feeder-disconnected {stroke: #FF0000; stroke-width: 1.5px}\n.sld-wire.sld-feeder-disconnected-connected {stroke: #FF0000; stroke-width: 1.5px}\n/* File : components.css ------------------------------------------------- */\n.sld-disconnector.sld-open {stroke-width: 1.5; stroke: var(--sld-vl-color, black); fill: black}\n.sld-disconnector.sld-closed {fill: var(--sld-vl-color, black)}\n.sld-breaker, .sld-load-break-switch {fill: var(--sld-vl-color, blue)}\n.sld-breaker {stroke: var(--sld-vl-color, blue); stroke-width: 1.5}\n.sld-bus-connection {fill: var(--sld-vl-color, black)}\n.sld-cell-shape-flat .sld-bus-connection {visibility: hidden}\n.sld-busbar-section {stroke: var(--sld-vl-color, black); stroke-width: 3; fill: none}\n.sld-wire {stroke: var(--sld-vl-color, #c80000); fill: none; stroke-width: 1.5px}\n.sld-wire.sld-dangling-line {stroke-width: 2px}\n.sld-wire.sld-tie-line {stroke-width: 2px}\n\n/* Stroke --sld-vl-color with fallback #C80AC8 */\n.sld-load {stroke: var(--sld-vl-color, #C80AC8); fill: none; stroke-width: 1.5px}\n.sld-battery {stroke: var(--sld-vl-color, #C80AC8); fill: none; stroke-width: 1.5px}\n.sld-generator {stroke: var(--sld-vl-color, #C80AC8); fill: none; stroke-width: 1.5px}\n.sld-two-wt {stroke: var(--sld-vl-color, #C80AC8); fill: none; stroke-width: 1.5px}\n.sld-three-wt {stroke: var(--sld-vl-color, #C80AC8); fill: none; stroke-width: 1.5px}\n.sld-winding {stroke: var(--sld-vl-color, #C80AC8); fill: none; stroke-width: 1.5px}\n.sld-capacitor {stroke: var(--sld-vl-color, #C80AC8); fill: none; stroke-width: 1.5px}\n.sld-inductor {stroke: var(--sld-vl-color, #C80AC8); fill: none; stroke-width: 1.5px}\n.sld-pst {stroke: var(--sld-vl-color, #C80AC8); fill: none; stroke-width: 1.5px}\n.sld-pst-arrow {stroke: #C80AC8; fill: none; stroke-width: 1.5px}\n.sld-svc {stroke: var(--sld-vl-color, #C80AC8); fill: none; stroke-width: 1.5px}\n.sld-vsc {stroke: var(--sld-vl-color, #C80AC8); font-size: 7.43px; fill: none; stroke-width: 1.5px}\n.sld-lcc {stroke: var(--sld-vl-color, #C80AC8); font-size: 7.43px; fill: none; stroke-width: 1.5px}\n.sld-ground {stroke: var(--sld-vl-color, #C80AC8); fill: none; stroke-width: 1.5px}\n\n.sld-node-infos {stroke: none; fill: var(--sld-vl-color, black)}\n.sld-node {stroke: none; fill: black}\n.sld-flash {stroke: none; fill: black}\n.sld-lock {stroke: none; fill: black}\n.sld-unknown {stroke: none; fill: #C80AC8}\n/* Fonts */\n.sld-label {stroke: none; fill: white; font: 8px serif}\n.sld-bus-legend-info {font: 10px serif; fill: white}\n.sld-graph-label {font: 12px serif}\n/* Specific */\n.sld-grid {stroke: #003700; stroke-dasharray: 1,10}\n.sld-feeder-info.sld-active-power {fill: #fff}\n.sld-feeder-info.sld-reactive-power {fill: #fff}\n.sld-feeder-info.sld-current {fill:#fff}\n.sld-frame {fill: var(--sld-background-color, #000)}\n/* fictitious switches and busbar */\n.sld-breaker.sld-fictitious {stroke: var(--sld-vl-color, #C80AC8); stroke-width: 1.5}\n.sld-disconnector.sld-fictitious {stroke: maroon}\n.sld-load-break-switch.sld-fictitious {stroke: maroon}\n.sld-busbar-section.sld-fictitious {stroke: var(--sld-vl-color, #c80000); stroke-width: 1}\n/* ground disconnector specific */\n.sld-ground-disconnection-attach {stroke: var(--sld-vl-color, #c80000); fill: none}\n.sld-open.sld-ground-disconnection-ground {stroke: black; fill: none}\n.sld-closed.sld-ground-disconnection-ground {stroke: var(--sld-vl-color, #c80000); fill: none}\n.sld-open.sld-ground-disconnection {stroke: var(--sld-vl-color, black); fill: none}\n.sld-closed.sld-ground-disconnection {fill: var(--sld-vl-color, black)}\n.sld-breaker.sld-open {fill: transparent}\n]]>\n"
DARK_MODE_STYLE
module-attribute
#
DARK_MODE_STYLE = {
"background": ".sld-frame {fill: var(--sld-background-color, #000)}",
"active_power": ".sld-feeder-info.sld-active-power {fill: #fff}",
"reactive_power": ".sld-feeder-info.sld-reactive-power {fill: #fff}",
"current": ".sld-feeder-info.sld-current {fill:#fff}",
"label": ".sld-label {stroke: none; fill: white; font: 8px serif}",
"bus-legend-info": ".sld-bus-legend-info {font: 10px serif; fill: white}",
"sld-open": ".sld-disconnector.sld-open {stroke-width: 1.5; stroke: var(--sld-vl-color, black); fill: black}",
}
BRIGHT_MODE_STYLE
module-attribute
#
BRIGHT_MODE_STYLE = {
"background": ".sld-frame {fill: var(--sld-background-color, #fff)}",
"active_power": ".sld-feeder-info.sld-active-power {fill: #000}",
"reactive_power": ".sld-feeder-info.sld-reactive-power {fill: #000}",
"current": ".sld-feeder-info.sld-current {fill:#000}",
"label": ".sld-label {stroke: none; fill: black; font: 8px serif}",
"bus-legend-info": ".sld-bus-legend-info {font: 10px serif; fill: black}",
"sld-open": ".sld-disconnector.sld-open {stroke-width: 1.5; stroke: var(--sld-vl-color, black); fill: white}",
}
DISCONNECTOR_STYLE
module-attribute
#
DISCONNECTOR_STYLE = {
"height": "8",
"width": "8",
"x": "0",
"y": "0",
"transform": "rotate(45.0,4.0,4.0)",
}
BUSBAR_SECTION_LABEL_POSITION
module-attribute
#
toop_engine_grid_helpers.powsybl.single_line_diagram.get_single_line_diagram_custom
#
A replacement for the powsybl get_single_line_diagram function.
get_single_line_diagram_custom
#
get_single_line_diagram_custom(
net,
container_id,
parameters=None,
custom_style="dark_mode",
highlight_grid_model_ids=None,
highlight_color="#0050fcff",
)
Get a single line diagram with custom styles.
A replacement for the powsybl get_single_line_diagram function that allows for custom styles to be applied, specifically dark mode or bright mode.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The network for which to get the single line diagram. Hint: If you want the SLD for including loadflow results, run the loadflow first.
TYPE:
|
container_id
|
The ID of Voltage level for which to get the single line diagram.
TYPE:
|
parameters
|
Parameters for the single line diagram, by default None.
TYPE:
|
custom_style
|
The custom style to apply, either "dark_mode" or "bright_mode". If None, the original style will be used, by default "dark_mode".
TYPE:
|
highlight_grid_model_ids
|
The IDs of the grid model elements to highlight, by default None. E.g. get all switches that changed their state from closed to open -> show the difference between the original and new states.
TYPE:
|
highlight_color
|
The color to use for highlighting, by default "#0050fcff".
TYPE:
|
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/powsybl/single_line_diagram/get_single_line_diagram_custom.py
toop_engine_grid_helpers.powsybl.single_line_diagram.replace_convergence_style
#
Functions to replace powsybl Convergence styles in SVG files.
Author: Benjamin Petrick Date: 2025-07-15
replace_sld_disconnected
#
Replace sld-disconnected with the most common vl tag in the SVG tree.
| PARAMETER | DESCRIPTION |
|---|---|
element
|
The element to search for sld-intern-cell and sld-extern-cell
TYPE:
|
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/powsybl/single_line_diagram/replace_convergence_style.py
move_transform
#
Move the transform attribute of a child element by a given value.
| PARAMETER | DESCRIPTION |
|---|---|
child
|
The child element to modify.
TYPE:
|
move_by_item
|
The value to move the transform by.
TYPE:
|
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/powsybl/single_line_diagram/replace_convergence_style.py
move_labels_p_q_i
#
Move labels for active power, reactive power, and current.
Avoids overlapping labels of the three-wt, moves all labels for consistent positioning.
| PARAMETER | DESCRIPTION |
|---|---|
element
|
The element to search for sld-intern-cell and sld-extern-cell.
TYPE:
|
move_by
|
The distance to move the labels, by default 0.0.
TYPE:
|
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/powsybl/single_line_diagram/replace_convergence_style.py
replace_disconnector
#
Replace the powsybl Convergence disconnector with the given style.
Parameter
element: StdETree.Element The element to search for sld-disconnector disconnector_style: dict[str, str] The disconnector style used as the replacement, expects a dict for a rect like:
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/powsybl/single_line_diagram/replace_convergence_style.py
replace_breaker
#
Replace the powsybl Convergence breaker with the given style.
Parameter
element: StdETree.Element The element to search for sld-breaker breaker_style: dict[str, str] The breaker style, expects a dict for a path like: "d": "M1,1 V19 H19 V1z"
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/powsybl/single_line_diagram/replace_convergence_style.py
move_busbar_section_label
#
Move the busbar section label up, to avoid overlapping.
Parameter
element: StdETree.Element The element to search for sld-busbar-section busbar_section_label_position: dict[str, str] expects values for x and y like: {"x":3, "y":4}
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/powsybl/single_line_diagram/replace_convergence_style.py
switch_dark_to_bright_mode
#
switch_dark_to_bright_mode(
xmlstring,
dark_mode=DARK_MODE_STYLE,
bright_mode=BRIGHT_MODE_STYLE,
)
Switches the dark mode to bright mode in the SVG XML string.
| PARAMETER | DESCRIPTION |
|---|---|
xmlstring
|
The SVG XML string to modify.
TYPE:
|
dark_mode
|
The dark mode styles, a dict with keys that must match the bright_mode and values of default dark mode style to be replaced with the bright_mode style.
TYPE:
|
bright_mode
|
The bright mode styles, a dict with keys that mus match the dark_mode and values to replace the dark mode values.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The modified SVG XML string with dark mode styles replaced by bright mode styles. |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/powsybl/single_line_diagram/replace_convergence_style.py
replace_svg_styles
#
replace_svg_styles(
xmlstring,
style="dark_mode",
sld_css=SLD_CSS,
move_p_q_i_labels_by=10.0,
highlight_color="#0050fcff",
highlight_grid_model_ids=None,
)
Replace powsybl Convergence with dark or bright mode.
Parameter
xmlstring: str The svg xmls string to load and replace the style style: Literal["dark_mode", "bright_mode"] Choose the style dark_mode: dict[str, str] The dark mode styles, a dict with keys that must match the bright_mode and values of default dark mode style to be replaced with the bright_mode style. bright_mode: dict[str, str] The bright mode styles, a dict with keys that mus match the dark_mode and values to replace the dark mode values. sld_css: str The SLD CSS to be added to the SVG. move_p_q_i_labels_by: float The distance to move the labels for active power, reactive power, and current. Default is 10.0. highlight_color: Optional[str] The color to use for highlighting elements in the SVG. highlight_grid_model_ids: Optional[list[str]] The list of grid model IDs to highlight in the SVG.
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/powsybl/single_line_diagram/replace_convergence_style.py
set_highlight_color_for_ids
#
Replace the SVG style given an id.
Parameter
xmlstring: str The svg xmls string to load and replace the style grid_model_ids: list[str] The list of grid model IDs to replace in the SVG. sld_css: str The SLD CSS to be added to the SVG.
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/powsybl/single_line_diagram/replace_convergence_style.py
set_highlight_color
#
Set the color for the highlight color
| PARAMETER | DESCRIPTION |
|---|---|
xmlstring
|
The SVG XML string to modify.
TYPE:
|
highlight_color
|
The color to set for the highlight elements, by default "#0050fcff".
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
|
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/powsybl/single_line_diagram/replace_convergence_style.py
remove_defuse_artifacts
#
Remove defuse_et artifacts from the SVG XML string.
xmlstring: str The svg xmls string to load and replace the style
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/powsybl/single_line_diagram/replace_convergence_style.py
toop_engine_grid_helpers.powsybl.single_line_diagram.sld_helper_functions
#
Helper functions for SLD (Single Line Diagram) processing.
extract_sld_bus_numbers
#
Extract all 'sld-bus' tags with their numbers from a list of strings.
Extracts all css classes e.g. sld-bus-0, sld-bus-1, etc. from a list of strings.
| PARAMETER | DESCRIPTION |
|---|---|
tags
|
List of strings containing 'sld-bus' tags.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[str]
|
List of extracted 'sld-bus' tags with their numbers. |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/powsybl/single_line_diagram/sld_helper_functions.py
get_most_common_bus
#
Get the most common Value of a list.
| PARAMETER | DESCRIPTION |
|---|---|
tags
|
List of tags to analyze
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
most_common_tag
|
The most common Value from the list
TYPE:
|