Contingency Analysis#
AC Loadflow Service#
toop_engine_contingency_analysis.ac_loadflow_service.ac_loadflow_service
#
Get the results of the AC Contingency Analysis for the given network
get_ac_loadflow_results
#
get_ac_loadflow_results(
net,
n_minus_1_definition,
timestep=0,
job_id="",
n_processes=1,
batch_size=None,
)
Get the results of the AC loadflow for the given network
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The network to run the contingency analysis on
TYPE:
|
n_minus_1_definition
|
The N-1 definition to use for the contingency analysis. Contains outages and monitored elements
TYPE:
|
timestep
|
The timestep of the results. Used to identify the results in the database
TYPE:
|
job_id
|
The job id of the current job
TYPE:
|
n_processes
|
The number of processes to use for the contingency analysis. If 1, the analysis is run sequentially. If > 1, the analysis is run in parallel Paralelization is done by splitting the contingencies into chunks and running each chunk in a separate process
TYPE:
|
batch_size
|
The size of the batches to use for the parallelization. This is ignored for Powsybl at the moment. If None, the batch size is computed based on the number of contingencies and the number of processes.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
LoadflowResultsPolars
|
The results of the Contingency analysis |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the network is not a PandapowerNetwork or PowsyblNetwork |
Source code in packages/contingency_analysis_pkg/src/toop_engine_contingency_analysis/ac_loadflow_service/ac_loadflow_service.py
toop_engine_contingency_analysis.ac_loadflow_service.compute_metrics
#
Provides functions to compute the metrics directly from the results dataframes.
This is similar to jax.aggregate_results.py but straight on the results dataframes.
compute_overload_column
#
Compute the overload column for further aggregation.
This is just a max operation
| PARAMETER | DESCRIPTION |
|---|---|
branch_results
|
The branch results dataframe containing the loading information.
TYPE:
|
field
|
The field to use for the overload calculation, either "p" for power or "i" for current, by default "i".
TYPE:
|
branch_results_with_overload : patpl.LazyFrame
1 | |
Source code in packages/contingency_analysis_pkg/src/toop_engine_contingency_analysis/ac_loadflow_service/compute_metrics.py
compute_max_load
#
Compute the highest loading of the branches in the results.
This is just a max operation
| PARAMETER | DESCRIPTION |
|---|---|
branch_results
|
The branch results dataframe containing the loading information.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
float
|
The maximum loading in factor of maximum rated current (percent / 100) of any branch in the results. |
Source code in packages/contingency_analysis_pkg/src/toop_engine_contingency_analysis/ac_loadflow_service/compute_metrics.py
compute_overload_energy
#
Compute the maximum overload current of the branches in the results.
This is just a max operation
| PARAMETER | DESCRIPTION |
|---|---|
branch_results
|
The branch results dataframe containing the loading information.
TYPE:
|
field
|
The field to use for the overload calculation, either "p" for power or "i" for current, by default "i".
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
float
|
The maximum overload total current or power |
Source code in packages/contingency_analysis_pkg/src/toop_engine_contingency_analysis/ac_loadflow_service/compute_metrics.py
count_critical_branches
#
Count how many branches are above 100% in any side/contingency
| PARAMETER | DESCRIPTION |
|---|---|
branch_results
|
The branch results dataframe containing the loading information.
TYPE:
|
critical_threshold
|
The loading threshold to consider a branch as critical, by default 1.0 (100%)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
int
|
The number of branches that are overloaded in any side/contingency. |
Source code in packages/contingency_analysis_pkg/src/toop_engine_contingency_analysis/ac_loadflow_service/compute_metrics.py
compute_max_va_diff
#
Compute the maximum voltage angle difference.
| PARAMETER | DESCRIPTION |
|---|---|
va_diff_results
|
The voltage angle difference results dataframe.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
float
|
The maximum voltage angle difference in degrees. |
Source code in packages/contingency_analysis_pkg/src/toop_engine_contingency_analysis/ac_loadflow_service/compute_metrics.py
get_worst_k_contingencies_ac
#
Get the worst k contingencies based on overload energy.
If k is greater than the number of contingencies, all contingencies will be returned.
| PARAMETER | DESCRIPTION |
|---|---|
branch_results
|
The branch results dataframe containing the loading information.
TYPE:
|
k
|
The number of worst contingencies to return, by default 10.
TYPE:
|
field
|
The field to use for the overload calculation, either "p" for power or "i" for current, by default "p".
TYPE:
|
base_case_id
|
The contingency ID for the base case (N-0), by default "BASECASE".
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[list[list[str]], list[float]]
|
A tuple containing: - A list of lists with the contingency IDs for each timestep. The length of the outer list is the number of timesteps while the inner lists contain the top k contingencies for that timestep. - A list of total overload energy for each timestep. The length matches the number of timesteps. |
Source code in packages/contingency_analysis_pkg/src/toop_engine_contingency_analysis/ac_loadflow_service/compute_metrics.py
compute_metrics
#
Compute the metrics from the loadflow results.
| PARAMETER | DESCRIPTION |
|---|---|
loadflow_results
|
The loadflow results containing the branch results.
TYPE:
|
base_case_id
|
The contingency ID for the base case (N-0). If not provided, no n-0 metrics will be computed.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[MetricType, float]
|
A dictionary with the computed metrics. |
Source code in packages/contingency_analysis_pkg/src/toop_engine_contingency_analysis/ac_loadflow_service/compute_metrics.py
toop_engine_contingency_analysis.ac_loadflow_service.kafka_client
#
Provides a wrapper around the confluent_kafka Consumer to allow long running processes.
There are fundamentally two ways how to deal with long running processes in kafka: - increase the max.poll.interval.ms to a very high value so the processing can happen in between. - pause the consumer while processing and resume it afterwards, regularly polling the paused consumer to reset the max.poll.interval.ms timeout. These polls will not consume any messages, but will reset the timeout.
The first method is not recommended as it inhibits rebalances during frozen time, does not detect frozen consumers and is generally not what kafka was designed for. However, kafka does not provide a way to pause and resume a topic, only a topic-partition. That means if a consumer is paused but then a rebalance happens, new topic-partitions will not be paused and the consumer may receive messages for it. However, the polls we are doing are happening in the processing loop and we are fundamentally unable to process anything there. Hence, this wrapper provides a way to pause and resume a consumer, listening to the assignment changes and pausing or resuming the new TPs accordingly. As a drawback, this consumer then looses the ability to consume multiple topics.
LongRunningKafkaConsumer
#
LongRunningKafkaConsumer(
topic,
group_id,
bootstrap_servers,
client_id,
max_poll_interval_ms=1800000,
kafka_auth_config=None,
)
A kafka consumer for long running processes that need to pause and resume the topic consumption.
Initialize the LongRunningKafkaConsumer.
| PARAMETER | DESCRIPTION |
|---|---|
topic
|
The topic to subscribe to. This can only be a single topic as the consumer will pause and resume it.
TYPE:
|
group_id
|
The consumer group id
TYPE:
|
bootstrap_servers
|
The bootstrap servers to connect to, e.g. "localhost:9092
TYPE:
|
client_id
|
The client id to use for the consumer. This is used for logging and debugging purposes.
TYPE:
|
max_poll_interval_ms
|
The maximum time in milliseconds between polls before the consumer is considered dead. Defaults to 1_800_000 (30 minutes). Set this long enough so the process fits in with confidence.
TYPE:
|
kafka_auth_config
|
Additional kafka authentication configuration to pass to the consumer. Defaults to None.
TYPE:
|
Source code in packages/contingency_analysis_pkg/src/toop_engine_contingency_analysis/ac_loadflow_service/kafka_client.py
consumer
instance-attribute
#
consume
#
Consume a batch of messages from the kafka topic at once.
This will commit all offsets directly after consuming the messages.
| PARAMETER | DESCRIPTION |
|---|---|
timeout
|
The maximum time to wait for messages in seconds. If no messages are available, returns an empty list.
TYPE:
|
num_messages
|
The maximum number of messages to consume. If more messages are available, they will not be consumed.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[Message]
|
The consumed messages, or an empty list if no messages are available within the timeout. |
Source code in packages/contingency_analysis_pkg/src/toop_engine_contingency_analysis/ac_loadflow_service/kafka_client.py
poll
#
Consume a single message from the Kafka topic.
This will not commit the offset to the broker
| PARAMETER | DESCRIPTION |
|---|---|
timeout
|
The maximum time to wait for a message in seconds. If no message is available, returns None.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional[Message]
|
The consumed message, or None if no message is available within the timeout. |
Source code in packages/contingency_analysis_pkg/src/toop_engine_contingency_analysis/ac_loadflow_service/kafka_client.py
commit
#
Commit the last consumed message.
Source code in packages/contingency_analysis_pkg/src/toop_engine_contingency_analysis/ac_loadflow_service/kafka_client.py
start_processing
#
Start a long running process to consume the message.
This will internally pause the consumer. To not exceed the poll timeout, call heartbeat() periodically while processing, e.g. every epoch
Source code in packages/contingency_analysis_pkg/src/toop_engine_contingency_analysis/ac_loadflow_service/kafka_client.py
heartbeat
#
Send a heartbeat to the kafka topic while processing to reset the max poll interval timeout.
Source code in packages/contingency_analysis_pkg/src/toop_engine_contingency_analysis/ac_loadflow_service/kafka_client.py
stop_processing
#
Stop the long running process and commit the last message
Source code in packages/contingency_analysis_pkg/src/toop_engine_contingency_analysis/ac_loadflow_service/kafka_client.py
close
#
Close the consumer and commit the last message if any.
Source code in packages/contingency_analysis_pkg/src/toop_engine_contingency_analysis/ac_loadflow_service/kafka_client.py
toop_engine_contingency_analysis.ac_loadflow_service.lf_worker
#
Module contains functions for the kafka communication of the ac loadflow worker.
General Idea: - The worker will listen for commands on the preprocessing kafka topic - Once the initial conversion is done, it runs an initial loadflow - Once the optimiuation is done, The command contains a path to the pandapower or powsybl grid file The command contains the N-1 Definition
- The worker will load the grid file and the N-1 definition
- The worker will run the N-1 analysis on the grid file with as many processes as possible
- The worker will send the results to a kafka topic - ErrorResult, if anything goes wrong - SuccessResult, if everything goes well even if loadflow fails - LoadflowStartedResult? # Use the LoadflowResultsClass as the result result
- The worker will send a heartbeat to a kafka topic every X seconds
Questions: - Does it make sense to return the results in batches? - Faster results, but dont really tell the full story - How to deal with grid updates? - Separate Service? (Load would be doubled) - Passing the grid file as path valid? - Otherwise large files need to be passed as bytes which kafka supports but is not really intended
File: worker.py Author: Leonard Hilfrich Created: 05/2024
LoadflowWorkerArgs
dataclass
#
LoadflowWorkerArgs(
kafka_broker="localhost:9092",
loadflow_command_topic="loadflow_commands",
loadflow_results_topic="loadflow_results",
loadflow_heartbeat_topic="loadflow_heartbeat",
heartbeat_interval_ms=1000,
instance_id="loadflow_worker",
processed_gridfile_folder=Path("processed_gridfiles"),
loadflow_result_folder=Path("loadflow_results"),
n_processes=1,
)
Holds arguments which must be provided at the launch of the worker.
Contains arguments that static for each loadflow run.
kafka_broker
class-attribute
instance-attribute
#
The Kafka broker to connect to.
loadflow_command_topic
class-attribute
instance-attribute
#
The Kafka topic to listen for commands on.
loadflow_results_topic
class-attribute
instance-attribute
#
The topic to push results to.
loadflow_heartbeat_topic
class-attribute
instance-attribute
#
The topic to push heartbeats to.
heartbeat_interval_ms
class-attribute
instance-attribute
#
The interval in milliseconds to send heartbeats.
instance_id
class-attribute
instance-attribute
#
The instance id of the worker, used to identify the worker in the logs.
processed_gridfile_folder
class-attribute
instance-attribute
#
A folder where pre-processed grid files are stored - this should be a NFS share together with the backend and optimizer.
loadflow_result_folder
class-attribute
instance-attribute
#
A folder where the loadflow results are stored - this should be a NFS share together with the backend and optimizer.
n_processes
class-attribute
instance-attribute
#
The number of processes to use for the loadflow calculation. If 1, the analysis is run sequentially. If > 1, the analysis is run in parallel
idle_loop
#
Start the idle loop of the worker.
This will be running when the worker is currently not preprocessing This will wait until a StartCalculationCommand is received and return it. In case a ShutdownCommand is received, the worker will exit with the exit code provided in the command.
| PARAMETER | DESCRIPTION |
|---|---|
consumer
|
The initialized Kafka consumer to listen for commands on.
TYPE:
|
send_heartbeat_fn
|
A function to call when there were no messages received for a while.
TYPE:
|
heartbeat_interval_ms
|
The time to wait for a new command in milliseconds. If no command has been received, a heartbeat will be sent and then the receiver will wait for commands again.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
StartOptimizationCommand
|
The start optimization command to start the optimization run with |
Source code in packages/contingency_analysis_pkg/src/toop_engine_contingency_analysis/ac_loadflow_service/lf_worker.py
solver_loop
#
solver_loop(
command,
producer,
processed_grid_path,
loadflow_solver_path,
heartbeat_fn,
instance_id,
n_processes,
results_topic,
)
Start the solver loop of the worker.
This will be running when the worker is currently solving the loadflow This will wait until a StartCalculationCommand is received and return it. In case a ShutdownCommand is received, the worker will exit with the exit code provided in the command.
| PARAMETER | DESCRIPTION |
|---|---|
command
|
The command to start the optimization run with.
TYPE:
|
producer
|
The initialized Kafka producer to send results to.
TYPE:
|
processed_grid_path
|
The path to the pre-processed grid files. This is used to load the grid files.
TYPE:
|
loadflow_solver_path
|
The path to the loadflow solver results. This is used to save the loadflow results.
TYPE:
|
heartbeat_fn
|
A function to call to send a heartbeat message to the kafka topic.
TYPE:
|
instance_id
|
The instance id of the worker, used to identify the worker in the logs.
TYPE:
|
n_processes
|
The number of processes to use for the optimization run. If 1, the analysis is run sequentially. If > 1, the analysis is run in parallel Paralelization is done by splitting the contingencies into chunks and running each chunk in a separate process
TYPE:
|
results_topic
|
The topic to push results to.
TYPE:
|
Source code in packages/contingency_analysis_pkg/src/toop_engine_contingency_analysis/ac_loadflow_service/lf_worker.py
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 | |
load_base_grid_fs
#
Load the base grid from the grid file.
Force loading pandapower if grid type is pandapower, otherwise load powsybl.
| PARAMETER | DESCRIPTION |
|---|---|
filesystem
|
The filesystem to load the grid from
TYPE:
|
grid_path
|
The grid to load
TYPE:
|
grid_type
|
The type of the grid, either "pandapower", "powsybl", "ucte" or "cgmes".
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
PandapowerNet | Network
|
The loaded grid |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the grid type is not supported. |
Source code in packages/contingency_analysis_pkg/src/toop_engine_contingency_analysis/ac_loadflow_service/lf_worker.py
load_base_grid
#
Load the base grid from the grid file.
| PARAMETER | DESCRIPTION |
|---|---|
grid_path
|
The grid to load
TYPE:
|
grid_type
|
The type of the grid, either "pandapower", "powsybl", "ucte" or "cgmes".
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
PandapowerNet | Network
|
The loaded grid |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the grid type is not supported. |
Source code in packages/contingency_analysis_pkg/src/toop_engine_contingency_analysis/ac_loadflow_service/lf_worker.py
main
#
Start main function of the worker.
Source code in packages/contingency_analysis_pkg/src/toop_engine_contingency_analysis/ac_loadflow_service/lf_worker.py
Contingency Analysis PandaPower#
toop_engine_contingency_analysis.pandapower.contingency_analysis_pandapower
#
Compute the N-1 AC/DC power flow for the pandapower network.
run_single_outage
#
run_single_outage(
net,
contingency,
monitored_elements,
timestep,
job_id,
method,
runpp_kwargs=None,
)
Compute a single outage for the given network
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The network to compute the outage for
TYPE:
|
contingency
|
The contingency to compute the outage for
TYPE:
|
monitored_elements
|
The elements to monitor during the outage
TYPE:
|
timestep
|
The timestep of the results
TYPE:
|
job_id
|
The job id of the current job
TYPE:
|
method
|
The method to use for the loadflow. Either "ac" or "dc"
TYPE:
|
runpp_kwargs
|
Additional keyword arguments to pass to runpp/rundcpp functions, by default None
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
LoadflowResults
|
The results of the ContingencyAnalysis computation |
Source code in packages/contingency_analysis_pkg/src/toop_engine_contingency_analysis/pandapower/contingency_analysis_pandapower.py
restore_elements_to_service
#
Restore the outaged elements to their original in_service status.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The pandapower network to restore the elements in
TYPE:
|
outaged_elements
|
The elements that were outaged
TYPE:
|
were_in_service
|
A list indicating whether each element was in service before being set out of service
TYPE:
|
Source code in packages/contingency_analysis_pkg/src/toop_engine_contingency_analysis/pandapower/contingency_analysis_pandapower.py
get_element_results_df
#
Get the element results dataframes for the given contingency and monitored elements.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The pandapower network to get the results from
TYPE:
|
contingency
|
The contingency to get the results for
TYPE:
|
monitored_elements
|
The monitored elements to get the results for
TYPE:
|
timestep
|
The timestep of the results
TYPE:
|
status
|
The convergence status of the loadflow computation
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[DataFrame, DataFrame, DataFrame]
|
The branch results dataframe, node results dataframe and va diff results dataframe |
Source code in packages/contingency_analysis_pkg/src/toop_engine_contingency_analysis/pandapower/contingency_analysis_pandapower.py
set_outaged_elements_out_of_service
#
Set the outaged elements in the network to out of service.
Returns info if the elements were in service before being set out of service.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The pandapower network to set the elements out of service in
TYPE:
|
outaged_elements
|
The elements to set out of service
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[bool]
|
A list indicating whether each element was in service before being set out of service |
Source code in packages/contingency_analysis_pkg/src/toop_engine_contingency_analysis/pandapower/contingency_analysis_pandapower.py
run_contingency_analysis_sequential
#
run_contingency_analysis_sequential(
net,
n_minus_1_definition,
job_id,
timestep,
slack_allocation_config,
method="dc",
runpp_kwargs=None,
)
Compute a full N-1 analysis for the given network, but a single timestep
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The network to compute the N-1 analysis for
TYPE:
|
n_minus_1_definition
|
The N-1 definition to use for the analysis
TYPE:
|
job_id
|
The job id of the current job
TYPE:
|
timestep
|
The timestep of the results
TYPE:
|
slack_allocation_config
|
Precomputed configuration for slack allocation per island.
TYPE:
|
method
|
The method to use for the loadflow, by default "dc"
TYPE:
|
runpp_kwargs
|
Additional keyword arguments to pass to runpp/rundcpp functions, by default None
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[LoadflowResults]
|
A list of the results per contingency |
Source code in packages/contingency_analysis_pkg/src/toop_engine_contingency_analysis/pandapower/contingency_analysis_pandapower.py
run_contingency_analysis_parallel
#
run_contingency_analysis_parallel(
net,
n_minus_1_definition,
job_id,
timestep,
slack_allocation_config,
method="dc",
n_processes=1,
batch_size=None,
runpp_kwargs=None,
)
Compute the N-1 AC/DC power flow for the network.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The pandapower network to compute the N-1 power flow for, with the topolgy already applied. You can either pass the network directly or a ray.ObjectRef to the network (wrapped in a list to avoid dereferencing the object).
TYPE:
|
n_minus_1_definition
|
The N-1 definition to use for the analysis. Contains outages and monitored elements
TYPE:
|
job_id
|
The job id of the current job
TYPE:
|
timestep
|
The timestep of the results
TYPE:
|
slack_allocation_config
|
Precomputed configuration for slack allocation per island.
TYPE:
|
method
|
The method to use for the loadflow, by default "dc"
TYPE:
|
n_processes
|
The number of processes to use for the contingency analysis. If 1, the analysis is run sequentially. If > 1, the analysis is run in parallel. Paralelization is done by splitting the contingencies into chunks and running each chunk in a separate process
TYPE:
|
batch_size
|
The size of the batches to use for the parallelization. If None, the batch size is set to the number of contingencies divided by the number of processes, rounded up. This is used to avoid too many handles in
TYPE:
|
runpp_kwargs
|
Additional keyword arguments to pass to runpp/rundcpp functions, by default None
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[LoadflowResults]
|
A list of the results per contingency |
Source code in packages/contingency_analysis_pkg/src/toop_engine_contingency_analysis/pandapower/contingency_analysis_pandapower.py
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 | |
run_contingency_analysis_pandapower
#
run_contingency_analysis_pandapower(
net,
n_minus_1_definition,
job_id,
timestep,
min_island_size=11,
method="ac",
n_processes=1,
batch_size=None,
runpp_kwargs=None,
polars=False,
)
Compute the N-1 AC/DC power flow for the network.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The pandapower network to compute the N-1 power flow for, with the topology already applied.
TYPE:
|
n_minus_1_definition
|
The N-1 definition to use for the analysis. Contains outages and monitored elements
TYPE:
|
job_id
|
The job id of the current job
TYPE:
|
timestep
|
The timestep of the results
TYPE:
|
min_island_size
|
The minimum island size to consider
TYPE:
|
method
|
The method to use for the loadflow, by default "ac"
TYPE:
|
n_processes
|
The number of processes to use for the contingency analysis. If 1, the analysis is run sequentially. If > 1, the analysis is run in parallel. Paralelization is done by splitting the contingencies into chunks and running each chunk in a separate process
TYPE:
|
batch_size
|
The size of the batches to use for the parallelization. If None, the batch size is set to the number of contingencies divided by the number of processes, rounded up.
TYPE:
|
runpp_kwargs
|
Additional keyword arguments to pass to runpp/rundcpp functions, by default None
TYPE:
|
polars
|
Whether to return the results as a LoadflowResultsPolars object. If False, returns a LoadflowResults object. Note that this only affects the type of the returned object, the computations are the same.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Union[LoadflowResults, LoadflowResultsPolars]
|
The results of the loadflow computation |
Source code in packages/contingency_analysis_pkg/src/toop_engine_contingency_analysis/pandapower/contingency_analysis_pandapower.py
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 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 | |
toop_engine_contingency_analysis.pandapower.pandapower_helpers
#
Contingency Analysis PyPowsybl#
toop_engine_contingency_analysis.pypowsybl.contingency_analysis_powsybl
#
Compute the N-1 AC/DC power flow for the network.
run_powsybl_analysis
#
Run the powsybl security analysis for the given network and N-1 definition.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The powsybl network to compute the Contingency Analysis for
TYPE:
|
n_minus_1_definition
|
The N-1 definition to use for the contingency analysis. Contains outages and monitored elements
TYPE:
|
method
|
The method to use for the contingency analysis. Either "ac" or "dc", by default "ac"
TYPE:
|
n_processes
|
The number of processes to use for the contingency analysis. If 1, the analysis is run sequentially.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
res
|
The security analysis result from powsybl containing the monitored elements and the results of the contingencies.
TYPE:
|
basecase_id
|
The name of the basecase contingency, if it is included in the run. Otherwise None.
TYPE:
|
Source code in packages/contingency_analysis_pkg/src/toop_engine_contingency_analysis/pypowsybl/contingency_analysis_powsybl.py
run_contingency_analysis_polars
#
run_contingency_analysis_polars(
net,
pow_n1_definition,
job_id,
timestep,
method="dc",
n_processes=1,
)
Compute the N-0 + N-1 power flow for the network.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The powsybl network to compute the Contingency Analysis for
TYPE:
|
pow_n1_definition
|
The N-1 definition to use for the contingency analysis. Contains outages and monitored elements
TYPE:
|
job_id
|
The job id of the current job
TYPE:
|
timestep
|
The timestep to use for the contingency analysis
TYPE:
|
method
|
Whether to compute the AC or DC power flow, by default "dc"
TYPE:
|
n_processes
|
The number of processes to use for the contingency analysis. If 1, the analysis is run sequentially. If > 1, the analysis is run in parallel Paralelization is done by splitting the contingencies into chunks and running each chunk in a separate process This is done via the openloadflow native threadCount parameter, which is set in the powsybl security analysis parameters.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
LoadflowResultsPolars
|
The results of the loadflow computation. Invalid or otherwise failed results will be set to NaN. |
Source code in packages/contingency_analysis_pkg/src/toop_engine_contingency_analysis/pypowsybl/contingency_analysis_powsybl.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 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 | |
run_contingency_analysis_powsybl
#
run_contingency_analysis_powsybl(
net,
n_minus_1_definition,
job_id,
timestep,
method="ac",
n_processes=1,
polars=False,
)
Compute the Contingency Analysis for the network.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The powsybl network to compute the Contingency Analysis for
TYPE:
|
n_minus_1_definition
|
The N-1 definition to use for the contingency analysis. Contains outages and monitored elements
TYPE:
|
job_id
|
The job id of the current job
TYPE:
|
timestep
|
The timestep to use for the contingency analysis
TYPE:
|
method
|
The method to use for the contingency analysis. Either "ac" or "dc", by default "dc"
TYPE:
|
n_processes
|
The number of processes to use for the contingency analysis. If 1, the analysis is run sequentially. If > 1, the analysis is run in parallel Paralelization is done by splitting the contingencies into chunks and running each chunk in a separate process
TYPE:
|
polars
|
Whether to use polars for the dataframe operations.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Union[LoadflowResults, LoadflowResultsPolars]
|
The results of the loadflow computation. |
Source code in packages/contingency_analysis_pkg/src/toop_engine_contingency_analysis/pypowsybl/contingency_analysis_powsybl.py
toop_engine_contingency_analysis.pypowsybl.powsybl_helpers_polars
#
Helper functions to translate the N-1 definition into a usable format for Powsybl.
This includes translating contingencies, monitored elements and collecting the necessary data from the network, so this only has to happen once.
POWSYBL_CONVERGENCE_MAP
module-attribute
#
get_node_results_polars
#
get_node_results_polars(
bus_results,
monitored_buses,
bus_map,
voltage_levels,
failed_outages,
timestep,
method,
)
Get the node results for the given outages and timestep.
TODO: This is currently faking the sum of p and q at the node
| PARAMETER | DESCRIPTION |
|---|---|
bus_results
|
The bus results from the powsybl security analysis
TYPE:
|
monitored_buses
|
The list of monitored buses to get the node results for
TYPE:
|
bus_map
|
A mapping from busbar sections or bus_breaker_buses to the electrical buses. This is used to map the buses from bus_results to electrical buses and back to the monitored buses.
TYPE:
|
voltage_levels
|
The voltage levels of the buses. This is used to determine voltage limits and nominal v in DC.
TYPE:
|
failed_outages
|
The list of failed outages to get nan-node results for
TYPE:
|
timestep
|
The timestep to get the node results for
TYPE:
|
method
|
The method to use for the node results. Either "ac" or "dc"
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame[NodeResultSchemaPolars]
|
The node results for the given outages and timestep |
Source code in packages/contingency_analysis_pkg/src/toop_engine_contingency_analysis/pypowsybl/powsybl_helpers_polars.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | |
get_branch_results_polars
#
get_branch_results_polars(
branch_results,
three_winding_results,
monitored_branches,
monitored_trafo3w,
failed_outages,
timestep,
branch_limits,
)
Get the branch results for the given outages and timestep.
| PARAMETER | DESCRIPTION |
|---|---|
branch_results
|
The branch results from the powsybl security analysis
TYPE:
|
three_winding_results
|
The three winding transformer results from the powsybl security analysis
TYPE:
|
monitored_branches
|
The list of monitored branches with 2 sides to get the branch results for
TYPE:
|
monitored_trafo3w
|
The list of monitored three winding transformers to get the branch results for
TYPE:
|
failed_outages
|
The list of failed outages to get nan-branch results for
TYPE:
|
timestep
|
The timestep to get the branch results for
TYPE:
|
branch_limits
|
The branch limits from the powsybl network
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame[BranchResultSchemaPolars]
|
The polars branch results for the given outages and timestep |
Source code in packages/contingency_analysis_pkg/src/toop_engine_contingency_analysis/pypowsybl/powsybl_helpers_polars.py
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 | |
get_va_diff_results_polars
#
Get the voltage angle difference results for the given outages and bus results.
| PARAMETER | DESCRIPTION |
|---|---|
bus_results
|
The dataframe containing the bus results of powsybl contingency analysis.
TYPE:
|
outages
|
The list of outages to be considered. These are the contingency ids that are outaged.
TYPE:
|
va_diff_with_buses
|
The dataframe containing the voltage angle difference results with the bus pairs that need checking.
TYPE:
|
bus_map
|
A mapping from busbar sections to bus breaker buses. This is used to convert the busbar sections to bus breaker buses in the Node Breaker model.
TYPE:
|
timestep
|
The timestep of the results.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
VADiffResultSchemaPolars
|
The dataframe containing the voltage angle difference results for the given outages. |
Source code in packages/contingency_analysis_pkg/src/toop_engine_contingency_analysis/pypowsybl/powsybl_helpers_polars.py
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 | |
update_basename_polars
#
Update the basecase name in the results dataframes.
This function updates the contingency index level of the results dataframes to reflect the basecase name. If the basecase is not included in the run, it will remove it from the results. Powsybl includes the basecase as an empty string by default.
The Dataframes are expected to have a multi-index with a "contingency" level. The Dataframes are updated inplace.
| PARAMETER | DESCRIPTION |
|---|---|
result_df
|
The dataframe containing the branch / node / VADiff results |
basecase_name
|
The name of the basecase contingency, if it is included in the run. Otherwise None, by default None
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
LoadflowResultTablePolars
|
The updated dataframes with the basecase name set or removed. |
Source code in packages/contingency_analysis_pkg/src/toop_engine_contingency_analysis/pypowsybl/powsybl_helpers_polars.py
add_name_column_polars
#
Translate the element ids in the results dataframes to the original names.
This function translates the element names in the results dataframes to the original names from the Powsybl network. This is useful for debugging and for displaying the results.
| PARAMETER | DESCRIPTION |
|---|---|
result_df
|
The dataframe containing the node / branch / VADiff results |
name_map
|
A mapping from the element ids to the original names. This is used to translate the element names in the results.
TYPE:
|
index_level
|
The index level storing the ids that should be mapped to the names. by default "element" for the monitored elements.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
LoadflowResultTablePolars
|
The updated dataframe with the ids translated to the original names. |
Source code in packages/contingency_analysis_pkg/src/toop_engine_contingency_analysis/pypowsybl/powsybl_helpers_polars.py
get_failed_node_results_polars
#
Get the failed node results for the given outages and timestep.
A wrapper around get_failed_node_results to convert the pandas dataframe to a polars dataframe.
| PARAMETER | DESCRIPTION |
|---|---|
timestep
|
The timestep to get the node results for
TYPE:
|
failed_outages
|
The list of failed outages to get nan-node results for
TYPE:
|
monitored_nodes
|
The list of monitored nodes to get the node results for
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame[NodeResultSchemaPolars]
|
The polars dataframe containing the failed node results for the given outages and timestep |
Source code in packages/contingency_analysis_pkg/src/toop_engine_contingency_analysis/pypowsybl/powsybl_helpers_polars.py
get_failed_branch_results_polars
#
get_failed_branch_results_polars(
timestep,
failed_outages,
monitored_branches,
monitored_trafo3w,
)
Get the failed branch results for the given outages and timestep.
A wrapper around get_failed_branch_results to convert the pandas dataframe to a polars dataframe.
| PARAMETER | DESCRIPTION |
|---|---|
timestep
|
The timestep to get the branch results for
TYPE:
|
failed_outages
|
The list of failed outages to get nan-branch results for
TYPE:
|
monitored_branches
|
The list of monitored branches with 2 sides to get the branch results for
TYPE:
|
monitored_trafo3w
|
The list of monitored three winding transformers to get the branch results for
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame[BranchResultSchemaPolars]
|
The polars dataframe containing the failed branch results for the given outages and timestep |
Source code in packages/contingency_analysis_pkg/src/toop_engine_contingency_analysis/pypowsybl/powsybl_helpers_polars.py
toop_engine_contingency_analysis.pypowsybl.powsybl_helpers
#
Helper functions to translate the N-1 definition into a usable format for Powsybl.
This includes translating contingencies, monitored elements and collecting the necessary data from the network, so this only has to happen once.
POWSYBL_CONVERGENCE_MAP
module-attribute
#
PowsyblContingency
#
Bases: BaseModel
A Powsybl contingency.
This is a simplified version of the PandapowerContingency that is used in Powsybl. It contains only the necessary information to run an N-1 analysis in Powsybl.
is_basecase
#
Check if the contingency is a basecase.
A basecase contingency has no outaged elements.
PowsyblMonitoredElements
#
Bases: TypedDict
A dictionary to hold the monitored element ids for the N-1 analysis.
This is used to store the monitored elements in a format that can be used in Powsybl.
PowsyblNMinus1Definition
#
Bases: BaseModel
A Powsybl N-1 definition.
This is a simplified version of the NMinus1Definition that is used in Powsybl. It contains only the necessary information to run an N-1 analysis in Powsybl.
contingencies
instance-attribute
#
The outages to be considered. Maps contingency id to outaged element ids.
monitored_elements
instance-attribute
#
The list of branches with two sides, to be monitored during the N-1 analysis.
missing_elements
class-attribute
instance-attribute
#
A list of monitored elements that are not present in the network.
missing_contingencies
class-attribute
instance-attribute
#
A list of contingencies whose elements are (partially) not present in the network.
branch_limits
instance-attribute
#
The branch limits to be used during the N-1 analysis. If None, the default limits will be used.
blank_va_diff
instance-attribute
#
The buses to be used during the N-1 analysis. This is used to determine the voltage levels of the monitored buses. Could be a busbar section or a bus_breaker_buse depending on the model type.
bus_map
instance-attribute
#
A mapping from busbar sections and bus breaker buses to bus breaker buses, electrical buses and voltage_levels. This help to always get the correct buses, even if the model type changes.
element_name_mapping
instance-attribute
#
A mapping from element ids to their names. This is used to convert the element ids to their names in the results.
contingency_name_mapping
instance-attribute
#
A mapping from contingency ids to their names. This is used to convert the contingency ids to their names in the results.
voltage_levels
instance-attribute
#
The voltage levels of the buses. This is used to determine voltage limits.
distributed_slack
class-attribute
instance-attribute
#
Whether to distribute the slack across the generators in the grid. Only relevant for powsybl grids.
contingency_propagation
class-attribute
instance-attribute
#
Whether to enable powsybl's contingency propagation in the N-1 analysis.
https://powsybl.readthedocs.io/projects/powsybl-open-loadflow/en/latest/security/parameters.html Security Analysis will determine by topological search the switches with type circuit breakers (i.e. capable of opening fault currents) that must be opened to isolate the fault. Depending on the network structure, this could lead to more equipments to be simulated as tripped, because disconnectors and load break switches (i.e., not capable of opening fault currents) are not considered.
__getitem__
#
Get a subset of the nminus1definition based on the contingencies.
If a string is given, the contingency id must be in the contingencies list. If an integer or slice is given, the case id will be indexed by the integer or slice.
Source code in packages/contingency_analysis_pkg/src/toop_engine_contingency_analysis/pypowsybl/powsybl_helpers.py
translate_contingency_to_powsybl
#
Translate the contingencies to a format that can be used in Powsybl.
| PARAMETER | DESCRIPTION |
|---|---|
contingencies
|
The list of contingencies to translate.
TYPE:
|
identifiables
|
A dataframe containing the identifiables of the network. This is used to check if the elements are present in the network.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
pow_contingency
|
A list of PowsyblContingency objects, each containing the id, name and elements.
TYPE:
|
missing_contingency
|
A list of all contingencies that are not fully present in the network.
TYPE:
|
Source code in packages/contingency_analysis_pkg/src/toop_engine_contingency_analysis/pypowsybl/powsybl_helpers.py
translate_monitored_elements_to_powsybl
#
Translate the monitored elements to a format that can be used in Powsybl.
Also adds busses that are not monitored per se, but are needed for the voltage angle difference calculation.
| PARAMETER | DESCRIPTION |
|---|---|
nminus1_definition
|
The original Nminus1Definition containing the monitored elements and outages.
TYPE:
|
branches
|
The dataframe containing the branches of the network and their voltage_id including 3w-trafos.
TYPE:
|
buses
|
The dataframe containing the buses of the network and their voltage_id. These include busbar sections and bus_breaker buses.
TYPE:
|
switches
|
The dataframe containing the switches of the network and their voltage_id.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
monitored_elements
|
A dictionary containing the monitored elements in a format that can be used in Powsybl.
TYPE:
|
element_name_mapping
|
A mapping from element ids to their names. This is used to convert the element ids to their names in the results.
TYPE:
|
missing_elements
|
A list of monitored elements that are not present in the network.
TYPE:
|
Source code in packages/contingency_analysis_pkg/src/toop_engine_contingency_analysis/pypowsybl/powsybl_helpers.py
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 | |
prepare_branch_limits
#
Prepare the branch limits for the N-1 analysis.
This is done here, to avoid having to do this in every process.
| PARAMETER | DESCRIPTION |
|---|---|
branch_limits
|
The dataframe containing the branch limits of the network.
TYPE:
|
chosen_limit
|
The name of the limit to be used for the N-1 analysis. This is usually "permanent_limit". TODO Decide if and how this could be extended to other limits.#
TYPE:
|
monitored_branches
|
The list of branches to be monitored during the N-1 analysis.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
branch_limits
|
The dataframe containing the branch limits for the N-1 analysis in the right format.
TYPE:
|
Source code in packages/contingency_analysis_pkg/src/toop_engine_contingency_analysis/pypowsybl/powsybl_helpers.py
get_blank_va_diff
#
Get a blank dataframe for the voltage angle difference results.
This already includes all possible contingencies and monitored switches. The buses of the switches and the outaged branches are added later.
| PARAMETER | DESCRIPTION |
|---|---|
all_outages
|
The list of all outages to be considered. For all of these cases, all switches need to be checked
TYPE:
|
single_branch_outages
|
A dictionary mapping contingency ids to single outaged element ids. For all of these cases, the specific outaged branch need to be checked.
TYPE:
|
monitored_switches
|
The list of monitored switches to be considered. These are only the switches that are open and retained.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
A blank dataframe with the correct index for the voltage angle difference results. The index is a MultiIndex with the following levels: - timestep: The timestep of the results - contingency: The contingency id (including an empty string for the base case) - element: The element id (the switch or outaged branch) |
Source code in packages/contingency_analysis_pkg/src/toop_engine_contingency_analysis/pypowsybl/powsybl_helpers.py
get_blank_va_diff_with_buses
#
Get a blank dataframe for the voltage angle difference results with the buspairs that need checking.
The buspairs are bus_breaker_buses (net.get_bus_breaker_view_buses)
| PARAMETER | DESCRIPTION |
|---|---|
branches
|
The dataframe containing the branches of the network and their bus_breaker_buses.
TYPE:
|
switches
|
The dataframe containing the switches of the network and their bus_breaker_buses.
TYPE:
|
pow_contingencies
|
The list of all contingencies to be considered. For all of these cases, all switches need to be checked. For single outages we also consider the outaged branches.
TYPE:
|
monitored_switches
|
The list of monitored switches to be considered. These are only the switches that are open and retained.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
A blank dataframe with the correct index for the voltage angle difference results. The index is a MultiIndex with the following levels: - contingency: The contingency id (including an empty string for the base case) - element: The element id (the switch or outaged branch) - bus_breaker_bus1_id: The first bus_breaker_bus_id of the element - bus_breaker_bus2_id: The second bus_breaker_bus_id of the element |
Source code in packages/contingency_analysis_pkg/src/toop_engine_contingency_analysis/pypowsybl/powsybl_helpers.py
get_va_diff_results
#
Get the voltage angle difference results for the given outages and bus results.
| PARAMETER | DESCRIPTION |
|---|---|
bus_results
|
The dataframe containing the bus results of powsybl contingency analysis.
TYPE:
|
outages
|
The list of outages to be considered. These are the contingency ids that are outaged.
TYPE:
|
va_diff_with_buses
|
The dataframe containing the voltage angle difference results with the bus pairs that need checking.
TYPE:
|
bus_map
|
A mapping from busbar sections to bus breaker buses. This is used to convert the busbar sections to bus breaker buses in the Node Breaker model.
TYPE:
|
timestep
|
The timestep of the results.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
The dataframe containing the voltage angle difference results for the given outages. |
Source code in packages/contingency_analysis_pkg/src/toop_engine_contingency_analysis/pypowsybl/powsybl_helpers.py
get_busbar_mapping
#
Get a map between the different kind of buses in the network.
Maps busbar sections and bus breaker buses to bus breaker buses and electrical buses. Maps the electrical buses to monitored buses (either bus breaker or busbar sections).
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The Powsybl network to use for the translation. This is used to get the busbar sections and bus breaker buses.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
A dataframe containing the busbar mapping from busbar sections to bus breaker buses. |
Source code in packages/contingency_analysis_pkg/src/toop_engine_contingency_analysis/pypowsybl/powsybl_helpers.py
translate_nminus1_for_powsybl
#
Translate the N-1 definition to a format that can be used in Powsybl.
| PARAMETER | DESCRIPTION |
|---|---|
n_minus_1_definition
|
The N-1 definition to translate.
TYPE:
|
net
|
The Powsybl network to use for the translation. This is used to get the busbarsections, buses, branches and switches.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
PowsyblNMinus1Definition
|
The translated N-1 definition that can be used in Powsybl. |
Source code in packages/contingency_analysis_pkg/src/toop_engine_contingency_analysis/pypowsybl/powsybl_helpers.py
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 | |
get_regulating_element_results
#
Get the regulating element results for the given outages and timestep.
TODO: This is a fake implementation, we need to get the real results from the powsybl security analysis
| PARAMETER | DESCRIPTION |
|---|---|
monitored_buses
|
The list of monitored buses to get the regulating element results for
TYPE:
|
timestep
|
The timestep to get the regulating element results for
TYPE:
|
basecase_name
|
The name of the basecase contingency, if it is included in the run. Otherwise None, by default None
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame[RegulatingElementResultSchema]
|
The regulating element results for the given outages and timestep |
Source code in packages/contingency_analysis_pkg/src/toop_engine_contingency_analysis/pypowsybl/powsybl_helpers.py
get_node_results
#
get_node_results(
bus_results,
monitored_buses,
bus_map,
voltage_levels,
failed_outages,
timestep,
method,
)
Get the node results for the given outages and timestep.
TODO: This is currently faking the sum of p and q at the node
| PARAMETER | DESCRIPTION |
|---|---|
bus_results
|
The bus results from the powsybl security analysis
TYPE:
|
monitored_buses
|
The list of monitored buses to get the node results for
TYPE:
|
bus_map
|
A mapping from busbar sections or bus_breaker_buses to the electrical buses. This is used to map the buses from bus_results to electrical buses and back to the monitored buses.
TYPE:
|
voltage_levels
|
The voltage levels of the buses. This is used to determine voltage limits and nominal v in DC.
TYPE:
|
failed_outages
|
The list of failed outages to get nan-node results for
TYPE:
|
timestep
|
The timestep to get the node results for
TYPE:
|
method
|
The method to use for the node results. Either "ac" or "dc"
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame[NodeResultSchema]
|
The node results for the given outages and timestep |
Source code in packages/contingency_analysis_pkg/src/toop_engine_contingency_analysis/pypowsybl/powsybl_helpers.py
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 | |
get_branch_results
#
get_branch_results(
branch_results,
three_winding_results,
monitored_branches,
monitored_trafo3w,
failed_outages,
timestep,
branch_limits,
)
Get the branch results for the given outages and timestep.
| PARAMETER | DESCRIPTION |
|---|---|
branch_results
|
The branch results from the powsybl security analysis
TYPE:
|
three_winding_results
|
The three winding transformer results from the powsybl security analysis
TYPE:
|
monitored_branches
|
The list of monitored branches with 2 sides to get the branch results for
TYPE:
|
monitored_trafo3w
|
The list of monitored three winding transformers to get the branch results for
TYPE:
|
failed_outages
|
The list of failed outages to get nan-branch results for
TYPE:
|
timestep
|
The timestep to get the branch results for
TYPE:
|
branch_limits
|
The branch limits from the powsybl network
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame[BranchResultSchema]
|
The branch results for the given outages and timestep |
Source code in packages/contingency_analysis_pkg/src/toop_engine_contingency_analysis/pypowsybl/powsybl_helpers.py
get_convergence_result_df
#
get_convergence_result_df(
post_contingency_results,
pre_contingency_result,
outages,
timestep,
basecase_name=None,
)
Get the convergence dataframe for the given outages and timestep.
| PARAMETER | DESCRIPTION |
|---|---|
post_contingency_results
|
The post contingency results from the powsybl security analysis. Maps contingency id to PostContingencyResult.
TYPE:
|
pre_contingency_result
|
The pre contingency result from the powsybl security analysis. Holds the Basecase.
TYPE:
|
outages
|
The list of outages to get the convergence results for
TYPE:
|
timestep
|
The timestep to get the convergence results for
TYPE:
|
basecase_name
|
The name of the basecase contingency, if it is included in the run. Otherwise None, by default None
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame[ConvergedSchema]
|
The convergence dataframe for the given outages and timestep |
list[str]
|
The list of failed outages |
Source code in packages/contingency_analysis_pkg/src/toop_engine_contingency_analysis/pypowsybl/powsybl_helpers.py
update_basename
#
Update the basecase name in the results dataframes.
This function updates the contingency index level of the results dataframes to reflect the basecase name. If the basecase is not included in the run, it will remove it from the results. Powsybl includes the basecase as an empty string by default.
The Dataframes are expected to have a multi-index with a "contingency" level. The Dataframes are updated inplace.
| PARAMETER | DESCRIPTION |
|---|---|
result_df
|
The dataframe containing the branch / node / VADiff results
TYPE:
|
basecase_name
|
The name of the basecase contingency, if it is included in the run. Otherwise None, by default None
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
LOADFLOW_RESULT_TABLE
|
The updated dataframes with the basecase name set or removed. |
Source code in packages/contingency_analysis_pkg/src/toop_engine_contingency_analysis/pypowsybl/powsybl_helpers.py
add_name_column
#
Translate the element ids in the results dataframes to the original names.
This function translates the element names in the results dataframes to the original names from the Powsybl network. This is useful for debugging and for displaying the results.
| PARAMETER | DESCRIPTION |
|---|---|
result_df
|
The dataframe containing the node / branch / VADiff results
TYPE:
|
name_map
|
A mapping from the element ids to the original names. This is used to translate the element names in the results.
TYPE:
|
index_level
|
The index level storing the ids that should be mapped to the names. by default "element" for the monitored elements.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
LoadflowResultTable
|
The updated dataframe with the ids translated to the original names. |
Source code in packages/contingency_analysis_pkg/src/toop_engine_contingency_analysis/pypowsybl/powsybl_helpers.py
set_target_values_to_lf_values_incl_distributed_slack
#
Update the target values of generators to include the distributed slack.
This is necessary if you want to run the security analysis for generators without distributed their outaged power across the whole network, but still want to mantain the original n0-flows.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The powsybl network to update
TYPE:
|
method
|
The method to use for the loadflow, either "ac" or "dc"
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Network
|
The updated network |
Source code in packages/contingency_analysis_pkg/src/toop_engine_contingency_analysis/pypowsybl/powsybl_helpers.py
get_full_nminus1_definition_powsybl
#
Get the full N-1 definition from a Powsybl network.
This function retrieves the N-1 definition from a Powsybl network, including: Monitored Elements all lines, trafos, buses and switches Contingencies all lines, trafos, generators and loads Basecase contingency with name "BASECASE"
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The Powsybl network to retrieve the N-1 definition from.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Nminus1Definition
|
The complete N-1 definition for the given Powsybl network. |
Source code in packages/contingency_analysis_pkg/src/toop_engine_contingency_analysis/pypowsybl/powsybl_helpers.py
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 | |