Importer#
Importer Worker#
toop_engine_importer.worker.worker
#
Module contains functions for the kafka communication in the importer repo.
File: worker.py Author: Nico Westerbeck Created: 2024
Args
#
Bases: BaseModel
Holds arguments which must be provided at the launch of the worker.
Contains arguments that static for each preprocessing run.
kafka_broker
class-attribute
instance-attribute
#
The Kafka broker to connect to.
importer_command_topic
class-attribute
instance-attribute
#
The Kafka topic to listen for commands on.
importer_results_topic
class-attribute
instance-attribute
#
The topic to push results to.
importer_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.
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 StartPreprocessingCommand 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 |
|---|---|
StartPreprocessingCommand
|
The start preprocessing command to start the preprocessing run with |
Source code in packages/importer_pkg/src/toop_engine_importer/worker/worker.py
main
#
main(
args,
producer,
consumer,
unprocessed_gridfile_fs,
processed_gridfile_fs,
loadflow_result_fs,
)
Start main function of the worker.
| PARAMETER | DESCRIPTION |
|---|---|
args
|
The arguments to start the worker with.
TYPE:
|
unprocessed_gridfile_fs
|
A filesystem where the unprocessed gridfiles are stored. The concrete folder to use is determined by the start command, which contains an import location relative to the root of the unprocessed_gridfile_fs.
TYPE:
|
processed_gridfile_fs
|
The target filesystem for the preprocessing worker. This contains all processed grid files. During the import job, a new folder import_results.data_folder was created which will be completed with the preprocess call to this function. Internally, only the data folder is passed around as a dirfs. Note that the unprocessed_gridfile_fs is not needed here anymore, as all preprocessing steps that need the unprocessed gridfiles were already done.
TYPE:
|
loadflow_result_fs
|
A filesystem where the loadflow results are stored. Loadflows will be stored here using the uuid generation process and passed as a StoredLoadflowReference which contains the subfolder in this filesystem.
TYPE:
|
producer
|
The Kafka producer to send results and heartbeats with.
TYPE:
|
consumer
|
The Kafka consumer to receive commands with.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/worker/worker.py
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 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 | |
toop_engine_importer.worker.preprocessor
#
Module contains functions holds preprocessor commands for kafka communication in the importer repo.
File: preprocessor.py Author: Nico Westerbeck Created: 2024
run_preprocessing
#
run_preprocessing(
start_command,
unprocessed_gridfile_fs,
processed_gridfile_fs,
loadflow_result_fs,
status_update_fn,
)
Run the whole preprocessing of a start command: import, initial loadflow and DC preprocessing.
The AC N-1 security analysis runs once, during the import. It sets the artificial limits and is stored as the initial loadflow, before the DC preprocessing reads the grid with these limits.
| PARAMETER | DESCRIPTION |
|---|---|
start_command
|
The command to start the preprocessing run with |
unprocessed_gridfile_fs
|
A filesystem where the unprocessed gridfiles are stored.
TYPE:
|
processed_gridfile_fs
|
The target filesystem for the preprocessing worker. This contains all processed grid files.
TYPE:
|
loadflow_result_fs
|
A filesystem where the loadflow results are stored - this should be a NFS share together with the backend and optimizer. The initial loadflow is stored here.
TYPE:
|
status_update_fn
|
A function to call to signal progress in the preprocessing pipeline. Takes a stage, an optional message as parameters and network size stats.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
PreprocessingSuccessResult | NoOptimizationRequiredResult
|
A result dataclass for the entire preprocessing, including paths to the ready static_information and network_data dataclasses. |
| RAISES | DESCRIPTION |
|---|---|
BaseCaseNotConvergedError
|
If the base case loadflow of the import did not converge. |
Exception
|
Any exception raised will be caught by the worker and sent back |
Source code in packages/importer_pkg/src/toop_engine_importer/worker/preprocessor.py
import_grid_model
#
import_grid_model(
start_command,
unprocessed_gridfile_fs,
processed_gridfile_fs,
status_update_fn,
)
Run the import procedure, including the AC security analysis that sets the artificial limits.
This only performs the import until there's a grid model, the preprocessing in the loadflow solver is run by preprocess
| PARAMETER | DESCRIPTION |
|---|---|
start_command
|
The command to start the preprocessing run with |
unprocessed_gridfile_fs
|
A filesystem where the unprocessed gridfiles are stored. The concrete folder to use is determined by the start command, which contains an import location relative to the root of the unprocessed_gridfile_fs.
TYPE:
|
processed_gridfile_fs
|
The target filesystem for the preprocessing worker. This contains all processed grid files. During the import job, a new folder import_results.data_folder is created.
TYPE:
|
status_update_fn
|
A function to call to signal progress in the preprocessing pipeline. Takes a stage, an optional message as parameters and network size stats.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ImportedGridModel
|
The import statistics, mainly including the grid folder, and the initial loadflow with its metrics. |
| RAISES | DESCRIPTION |
|---|---|
Exception
|
Any exception raised will be caught by the worker and sent back |
Source code in packages/importer_pkg/src/toop_engine_importer/worker/preprocessor.py
store_initial_ca_results
#
Store the AC N-1 results of the import as the initial loadflow.
| PARAMETER | DESCRIPTION |
|---|---|
start_command
|
The command that was sent to the worker |
initial_loadflow
|
The AC N-1 results of the import, with the permanent and the artificial branch limits.
TYPE:
|
loadflow_result_fs
|
A filesystem where the loadflow results are stored - this should be a NFS share together with the backend and optimizer.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
StoredLoadflowReference
|
A reference to the stored loadflow results |
Source code in packages/importer_pkg/src/toop_engine_importer/worker/preprocessor.py
preprocess
#
preprocess(
start_command,
import_results,
status_update_fn,
processed_gridfile_fs,
initial_loadflow,
initial_metrics,
)
Run the preprocessing pipeline that is independent of the data source.
This only performs the preprocessing in the loadflow solver
| PARAMETER | DESCRIPTION |
|---|---|
start_command
|
The command to start the preprocessing run with |
import_results
|
Results from the import procedure
TYPE:
|
status_update_fn
|
A function to call to signal progress in the preprocessing pipeline. Takes a stage and an optional message as parameters
TYPE:
|
processed_gridfile_fs
|
The target filesystem for the preprocessing worker. This contains all processed grid files. During the import job, a new folder import_results.data_folder was created which will be completed with the preprocess call to this function. Internally, only the data folder is passed around as a dirfs. Note that the unprocessed_gridfile_fs is not needed here anymore, as all preprocessing steps that need the unprocessed gridfiles were already done.
TYPE:
|
initial_loadflow
|
The reference to the stored initial loadflow of the import.
TYPE:
|
initial_metrics
|
The metrics of the initial loadflow.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
PreprocessingSuccessResult
|
The result of completed DC preprocessing. |
| RAISES | DESCRIPTION |
|---|---|
Exception
|
Any exception raised will be caught by the worker and sent back |
Source code in packages/importer_pkg/src/toop_engine_importer/worker/preprocessor.py
Contingency from PowerFactory#
toop_engine_importer.contingency_from_power_factory
#
Import contingency from PowerFactory.
__all__
module-attribute
#
__all__ = [
"AllGridElementsSchema",
"ContingencyImportSchemaPowerFactory",
"ContingencyMatchSchema",
"get_contingencies_from_file",
"match_contingencies",
"power_factory_data_class",
]
AllGridElementsSchema
#
Bases: DataFrameModel
A AllGridElementsSchema is a DataFrameModel for all grid elements in the grid model.
The grid model is loaded from the CGMES file in either PyPowsybl or Pandapower.
element_type
class-attribute
instance-attribute
#
element_type = pa.Field(
nullable=True, isin=list(GridElementType.__args__)
)
The grid model type of the contingency. e.g. LINE, SWITCH, BUS, etc.
grid_model_id
class-attribute
instance-attribute
#
The grid model id of the contingency. e.g. a CGMES id (cryptic number)
grid_model_name
class-attribute
instance-attribute
#
The grid model name of the contingency. e.g. a CGMES name (human readable name)
ContingencyImportSchemaPowerFactory
#
Bases: DataFrameModel
A ContingencyImportSchemaPowerFactory is a DataFrameModel defining the expected data of the contingency import.
From PowerFactory: You may find the list of contingencies in the PowerFactory GUI under "Calculation > Contingency Analysis > Show Contingencies...".
index
class-attribute
instance-attribute
#
The unique index of the DataFrame. This index is used as a unique id for the dataframe.
contingency_name
class-attribute
instance-attribute
#
The id of contingency found in the contingency table. Attribute: "loc_name" of contingency table May be a multi index to group the contingencies together.
contingency_id
class-attribute
instance-attribute
#
A id for the contingency. This id is used to group the contingencies together. Attribute: "number" of contingency table.
power_factory_grid_model_name
class-attribute
instance-attribute
#
The name of the grid model element Attribute: "loc_name" of grid model element
power_factory_grid_model_fid
class-attribute
instance-attribute
#
The foreign Key of the grid model element Attribute: "for_name" of grid model element Note: True spacing of FID must be kept in the string.
power_factory_grid_model_rdf_id
class-attribute
instance-attribute
#
The rdf id (CIM) of the grid model element Attribute: "cimRdfId" of grid model element
comment
class-attribute
instance-attribute
#
May contain information about the contingency. Leave empty if not needed. Fill if comments or descriptions exist in the contingency table.
power_factory_element_type
class-attribute
instance-attribute
#
power_factory_element_type = pa.Field(
nullable=True, isin=list(GridElementType.__args__)
)
The type of the contingency based on the PowerFactory type. Gives a hint where to look for the contingency.
ContingencyMatchSchema
#
Bases: ContingencyImportSchemaPowerFactory, AllGridElementsSchema
A ContingencyMatchSchema is a DataFrameModel for matching the ContingencyImportSchema with the grid model.
ContingencyMatchSchema is a merge of: ContingencyImportSchema.merge( AllGridElementsSchema, how="left", left_on="power_factory_grid_model_rdf_id", right_on="grid_model_id" ) Note: the power_factory_grid_model_rdf_id has a leading underscore and may need modification.
element_type
class-attribute
instance-attribute
#
element_type = pa.Field(
nullable=True, isin=list(GridElementType.__args__)
)
The grid model type of the contingency. e.g. LINE, SWITCH, BUS, etc.
grid_model_id
class-attribute
instance-attribute
#
The grid model id of the contingency. e.g. a CGMES id (cryptic number)
grid_model_name
class-attribute
instance-attribute
#
The grid model name of the contingency. e.g. a CGMES name (human readable name)
index
class-attribute
instance-attribute
#
The unique index of the DataFrame. This index is used as a unique id for the dataframe.
contingency_name
class-attribute
instance-attribute
#
The id of contingency found in the contingency table. Attribute: "loc_name" of contingency table May be a multi index to group the contingencies together.
contingency_id
class-attribute
instance-attribute
#
A id for the contingency. This id is used to group the contingencies together. Attribute: "number" of contingency table.
power_factory_grid_model_name
class-attribute
instance-attribute
#
The name of the grid model element Attribute: "loc_name" of grid model element
power_factory_grid_model_fid
class-attribute
instance-attribute
#
The foreign Key of the grid model element Attribute: "for_name" of grid model element Note: True spacing of FID must be kept in the string.
power_factory_grid_model_rdf_id
class-attribute
instance-attribute
#
The rdf id (CIM) of the grid model element Attribute: "cimRdfId" of grid model element
comment
class-attribute
instance-attribute
#
May contain information about the contingency. Leave empty if not needed. Fill if comments or descriptions exist in the contingency table.
power_factory_element_type
class-attribute
instance-attribute
#
power_factory_element_type = pa.Field(
nullable=True, isin=list(GridElementType.__args__)
)
The type of the contingency based on the PowerFactory type. Gives a hint where to look for the contingency.
get_contingencies_from_file
#
Get the contingencies from the file.
This function reads the contingencies from the file and returns a DataFrame in the ContingencyImportSchema format.
| PARAMETER | DESCRIPTION |
|---|---|
n1_file
|
The path to the file.
TYPE:
|
delimiter
|
The delimiter of the file. Default is ";".
TYPE:
|
filesystem
|
The filesystem to use to read the file. If None, the local filesystem is used.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ContingencyImportSchema
|
A DataFrame containing the contingencies. |
Source code in packages/importer_pkg/src/toop_engine_importer/contingency_from_power_factory/contingency_from_file.py
match_contingencies
#
Match the contingencies from the file with the elements in the grid model.
This function matches the contingencies from the file with the elements in the grid model. It first tries to match by index, then by name.
| PARAMETER | DESCRIPTION |
|---|---|
n1_definition
|
The contingencies from the file.
TYPE:
|
all_element_names
|
The elements in the grid model.
TYPE:
|
match_by_name
|
If True, match by name. Default is True. If False, only match by index.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame[ContingencyMatchSchema]
|
A DataFrame containing the matched contingencies. |
Source code in packages/importer_pkg/src/toop_engine_importer/contingency_from_power_factory/contingency_from_file.py
toop_engine_importer.contingency_from_power_factory.power_factory_data_class
#
Classes for the contingency list import from PowerFactory.
This importing has the focus on CIM bases grid models. UCTE has not been tested.
Author: Benjamin Petrick Created: 2025-05-13
GridModelTypePowerFactory
module-attribute
#
GridModelTypePowerFactory = Literal[
"ElmTr2",
"ElmLne",
"ElmGenstat",
"ElmLod",
"ElmSym",
"ElmNec",
"ElmZpu",
"ElmTr3",
"ElmSind",
"ElmTerm",
"ElmShnt",
"ElmVac",
]
GridElementType
module-attribute
#
GridElementType = Literal[
"BUS",
"BUSBAR_SECTION",
"LINE",
"HVDC_LINE",
"SWITCH",
"TWO_WINDINGS_TRANSFORMER",
"THREE_WINDINGS_TRANSFORMER",
"GENERATOR",
"LOAD",
"SHUNT_COMPENSATOR",
"BOUNDARY_LINE",
"TIE_LINE",
]
ContingencyImportSchemaPowerFactory
#
Bases: DataFrameModel
A ContingencyImportSchemaPowerFactory is a DataFrameModel defining the expected data of the contingency import.
From PowerFactory: You may find the list of contingencies in the PowerFactory GUI under "Calculation > Contingency Analysis > Show Contingencies...".
index
class-attribute
instance-attribute
#
The unique index of the DataFrame. This index is used as a unique id for the dataframe.
contingency_name
class-attribute
instance-attribute
#
The id of contingency found in the contingency table. Attribute: "loc_name" of contingency table May be a multi index to group the contingencies together.
contingency_id
class-attribute
instance-attribute
#
A id for the contingency. This id is used to group the contingencies together. Attribute: "number" of contingency table.
power_factory_grid_model_name
class-attribute
instance-attribute
#
The name of the grid model element Attribute: "loc_name" of grid model element
power_factory_grid_model_fid
class-attribute
instance-attribute
#
The foreign Key of the grid model element Attribute: "for_name" of grid model element Note: True spacing of FID must be kept in the string.
power_factory_grid_model_rdf_id
class-attribute
instance-attribute
#
The rdf id (CIM) of the grid model element Attribute: "cimRdfId" of grid model element
comment
class-attribute
instance-attribute
#
May contain information about the contingency. Leave empty if not needed. Fill if comments or descriptions exist in the contingency table.
power_factory_element_type
class-attribute
instance-attribute
#
power_factory_element_type = pa.Field(
nullable=True, isin=list(GridElementType.__args__)
)
The type of the contingency based on the PowerFactory type. Gives a hint where to look for the contingency.
AllGridElementsSchema
#
Bases: DataFrameModel
A AllGridElementsSchema is a DataFrameModel for all grid elements in the grid model.
The grid model is loaded from the CGMES file in either PyPowsybl or Pandapower.
element_type
class-attribute
instance-attribute
#
element_type = pa.Field(
nullable=True, isin=list(GridElementType.__args__)
)
The grid model type of the contingency. e.g. LINE, SWITCH, BUS, etc.
grid_model_id
class-attribute
instance-attribute
#
The grid model id of the contingency. e.g. a CGMES id (cryptic number)
grid_model_name
class-attribute
instance-attribute
#
The grid model name of the contingency. e.g. a CGMES name (human readable name)
ContingencyMatchSchema
#
Bases: ContingencyImportSchemaPowerFactory, AllGridElementsSchema
A ContingencyMatchSchema is a DataFrameModel for matching the ContingencyImportSchema with the grid model.
ContingencyMatchSchema is a merge of: ContingencyImportSchema.merge( AllGridElementsSchema, how="left", left_on="power_factory_grid_model_rdf_id", right_on="grid_model_id" ) Note: the power_factory_grid_model_rdf_id has a leading underscore and may need modification.
element_type
class-attribute
instance-attribute
#
element_type = pa.Field(
nullable=True, isin=list(GridElementType.__args__)
)
The grid model type of the contingency. e.g. LINE, SWITCH, BUS, etc.
grid_model_id
class-attribute
instance-attribute
#
The grid model id of the contingency. e.g. a CGMES id (cryptic number)
grid_model_name
class-attribute
instance-attribute
#
The grid model name of the contingency. e.g. a CGMES name (human readable name)
index
class-attribute
instance-attribute
#
The unique index of the DataFrame. This index is used as a unique id for the dataframe.
contingency_name
class-attribute
instance-attribute
#
The id of contingency found in the contingency table. Attribute: "loc_name" of contingency table May be a multi index to group the contingencies together.
contingency_id
class-attribute
instance-attribute
#
A id for the contingency. This id is used to group the contingencies together. Attribute: "number" of contingency table.
power_factory_grid_model_name
class-attribute
instance-attribute
#
The name of the grid model element Attribute: "loc_name" of grid model element
power_factory_grid_model_fid
class-attribute
instance-attribute
#
The foreign Key of the grid model element Attribute: "for_name" of grid model element Note: True spacing of FID must be kept in the string.
power_factory_grid_model_rdf_id
class-attribute
instance-attribute
#
The rdf id (CIM) of the grid model element Attribute: "cimRdfId" of grid model element
comment
class-attribute
instance-attribute
#
May contain information about the contingency. Leave empty if not needed. Fill if comments or descriptions exist in the contingency table.
power_factory_element_type
class-attribute
instance-attribute
#
power_factory_element_type = pa.Field(
nullable=True, isin=list(GridElementType.__args__)
)
The type of the contingency based on the PowerFactory type. Gives a hint where to look for the contingency.
toop_engine_importer.contingency_from_power_factory.contingency_from_file
#
Import contingencies from a file.
This module contains functions to import contingencies from a file and match them with the grid model.
Author: Benjamin Petrick Created: 2025-05-13
get_contingencies_from_file
#
Get the contingencies from the file.
This function reads the contingencies from the file and returns a DataFrame in the ContingencyImportSchema format.
| PARAMETER | DESCRIPTION |
|---|---|
n1_file
|
The path to the file.
TYPE:
|
delimiter
|
The delimiter of the file. Default is ";".
TYPE:
|
filesystem
|
The filesystem to use to read the file. If None, the local filesystem is used.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ContingencyImportSchema
|
A DataFrame containing the contingencies. |
Source code in packages/importer_pkg/src/toop_engine_importer/contingency_from_power_factory/contingency_from_file.py
match_contingencies
#
Match the contingencies from the file with the elements in the grid model.
This function matches the contingencies from the file with the elements in the grid model. It first tries to match by index, then by name.
| PARAMETER | DESCRIPTION |
|---|---|
n1_definition
|
The contingencies from the file.
TYPE:
|
all_element_names
|
The elements in the grid model.
TYPE:
|
match_by_name
|
If True, match by name. Default is True. If False, only match by index.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame[ContingencyMatchSchema]
|
A DataFrame containing the matched contingencies. |
Source code in packages/importer_pkg/src/toop_engine_importer/contingency_from_power_factory/contingency_from_file.py
match_contingencies_by_index
#
Match the contingencies from the file with the elements in the grid model.
| PARAMETER | DESCRIPTION |
|---|---|
n1_definition
|
The contingencies from the file.
TYPE:
|
all_element_names
|
The elements in the grid model.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame[ContingencyMatchSchema]
|
A DataFrame containing the matched contingencies. |
Source code in packages/importer_pkg/src/toop_engine_importer/contingency_from_power_factory/contingency_from_file.py
match_contingencies_by_name
#
Match the contingencies from the file with the elements in the grid model by name.
Matches by name and replaces the grid_model_name, element_type and grid_model_id. First tries to match 100% of the name. Second tries to match by removing spaces and replacing "+" with "##_##".
| PARAMETER | DESCRIPTION |
|---|---|
processed_n1_definition
|
The contingencies from the file.
TYPE:
|
all_element_names
|
The elements in the grid model.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame[ContingencyMatchSchema]
|
A DataFrame containing the matched contingencies. |
Source code in packages/importer_pkg/src/toop_engine_importer/contingency_from_power_factory/contingency_from_file.py
match_contingencies_with_suffix
#
Match the contingencies from the file with the elements in the grid model by name.
Matches by name and replaces the grid_model_name with power_factory_grid_model_name. Removes suffix from the grid_model_name.
| PARAMETER | DESCRIPTION |
|---|---|
processed_n1_definition
|
The contingencies from the file.
TYPE:
|
all_element_names
|
The elements in the grid model.
TYPE:
|
grid_model_suffix
|
The suffixes to match the grid model names.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame[ContingencyMatchSchema]
|
A DataFrame containing the matched contingencies. |
Source code in packages/importer_pkg/src/toop_engine_importer/contingency_from_power_factory/contingency_from_file.py
match_contingencies_column
#
match_contingencies_column(
processed_n1_definition,
all_element_names,
n1_column,
element_column,
)
Match a column processed_n1_definition with a column from all_element_names.
This functions matches based on 100% name match and replaces the grid_model_name, element_type and grid_model_id
| PARAMETER | DESCRIPTION |
|---|---|
processed_n1_definition
|
The contingencies from the file.
TYPE:
|
all_element_names
|
The elements in the grid model.
TYPE:
|
n1_column
|
The column name in processed_n1_definition.
TYPE:
|
element_column
|
The column name in all_element_names.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame[ContingencyMatchSchema]
|
A DataFrame containing the matched contingencies. |
Source code in packages/importer_pkg/src/toop_engine_importer/contingency_from_power_factory/contingency_from_file.py
UCTE Toolset#
toop_engine_importer.ucte_toolset
#
A collection of tools to work with UCTE data.
ucte_toolset.py: Functions load, manipulate, and save UCTE data using pd.DataFrame.
Importer Pandapower#
toop_engine_importer.pandapower_import
#
Contains functions to import data from pandapower networks to the Topology Optimizer.
__all__
module-attribute
#
__all__ = [
"add_substation_column_to_bus",
"create_virtual_slack",
"drop_elements_connected_to_one_bus",
"drop_unsupplied_buses",
"fuse_closed_switches_by_bus_ids",
"fuse_closed_switches_fast",
"get_all_switches_from_bus_ids",
"get_closed_switch",
"get_coupler_types_of_substation",
"get_indirect_connected_switch",
"get_master_asset_topology_from_network",
"get_station_id_list",
"get_substation_buses_from_bus_id",
"get_type_b_nodes",
"move_elements_based_on_labels",
"preprocess_net_step1",
"preprocess_net_step2_master_asset_topology",
"remove_out_of_service",
"replace_zero_branches",
"select_connected_subnet",
"validate_asset_topology_stations",
]
get_master_asset_topology_from_network
#
get_master_asset_topology_from_network(
network,
topology_id,
grid_model_file,
station_id_list,
foreign_key="equipment",
)
Return canonical asset-topology master data derived from a pandapower network.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
Source pandapower network.
TYPE:
|
topology_id
|
Identifier to store on the resulting master data.
TYPE:
|
grid_model_file
|
Source grid-model file name stored in the master data.
TYPE:
|
station_id_list
|
Station definitions as lists of pandapower bus indices.
TYPE:
|
foreign_key
|
Column name used as the preferred human-readable identifier.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
MasterAssetTopology
|
Canonical master data split into structural station groups. |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/pandapower/asset_topology.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
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
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
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
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
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
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
add_substation_column_to_bus
#
add_substation_column_to_bus(
network,
substation_col="substat",
get_name_col="name",
only_closed_switches=False,
)
Add a substation column to the bus DataFrame.
This function will go through all busbars of type 'b' and add the substation name to all buses connected to the busbar.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
The pandapower network to add the substation column to. Note: the network will be modified in-place.
TYPE:
|
substation_col
|
The name of the new substation column where the value from the get_name_col is added.
TYPE:
|
get_name_col
|
The name of the column to get the substation name from.
TYPE:
|
only_closed_switches
|
If True, only closed switches are considered. The result will lead substation naming after the the electrical voltage level.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/pandapower_import/pandapower_toolset_node_breaker.py
fuse_closed_switches_by_bus_ids
#
Fuse a series of closed switches in the network by merging busbars (type b).
| PARAMETER | DESCRIPTION |
|---|---|
network
|
The pandapower network to fuse closed switches in, will be modified in-place.
TYPE:
|
switch_bus_ids
|
The bus ids of the switches to fuse. Note: this must include the bus_id that is expected to be the final busbar.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bus_labels
|
An with the length of the highest bus id in the network representing the busbar index. At the index of the array(old busbar index), the new busbar index is stored.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/pandapower_import/pandapower_toolset_node_breaker.py
get_all_switches_from_bus_ids
#
Get all switches connected to a list of buses.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
The pandapower network to get the switches from.
TYPE:
|
bus_ids
|
The buses to get the switches from.
TYPE:
|
only_closed_switches
|
If True, only closed switches are considered.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
A DataFrame with all switches connected to the buses in bus_ids. |
Source code in packages/importer_pkg/src/toop_engine_importer/pandapower_import/pandapower_toolset_node_breaker.py
get_closed_switch
#
Get the closed switch based on the column and column_ids.
| PARAMETER | DESCRIPTION |
|---|---|
switches
|
The switches df to filter the closed switch from.
TYPE:
|
column
|
The column to filter the column_ids. e.g. foreign_id
TYPE:
|
column_ids
|
The column ids to filter the closed switch from.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
The closed switch filtered by the column_ids. |
Source code in packages/importer_pkg/src/toop_engine_importer/pandapower_import/pandapower_toolset_node_breaker.py
get_coupler_types_of_substation
#
Get the cross coupler (German: Querkuppler), busbar coupler and a cross connector of a substation.
A busbar coupler is a connection between two busbars, where assets can be connected to both busbars. A cross coupler is a connection between two busbars B1 and B2, where assets A1 can not be connected to both busbars directly. Asset A1 can only be connected directly to B1 and is connected indirectly to B2 by the cross coupler. A coupler is always a disconnector (DS), a power switch (CB) and a DS in series. In unique cases, there can be two CB switches in series. A cross connector is a single disconnector between two busbars.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
The pandapower network to get the Cross coupler/quercoupler from.
TYPE:
|
substation_bus_list
|
The bus list of the substation. All buses in the list represent a substation.
TYPE:
|
only_closed_switches
|
If True, only closed switches are considered.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
coupler
|
a dictionary with 4 keys: - 1. key: "busbar_coupler_bus_ids" - 2. key: "cross_coupler_bus_ids" - 3. key: "busbar_coupler_switch_ids" - 4. key: "cross_coupler_switch_ids" bus_ids: list of bus ids representing the busbar coupler and cross coupler switch_ids: list of switch ids representing the busbar coupler and cross coupler switch_ids = [CB, DS1, DS2] Note: the switches are not filtered by open/closed. Note: if there is only one switch or two switches: switch_ids_1sw = [CB, CB, CB] switch_ids_2sw = [CB, CB, DS2]
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/pandapower_import/pandapower_toolset_node_breaker.py
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 | |
get_indirect_connected_switch
#
get_indirect_connected_switch(
net,
bus_1,
bus_2,
only_closed_switches=True,
consider_three_buses=False,
exclude_buses=None,
)
Get a switch, that is indirectly connected by two buses and only by two buses.
This function will only return the indirect connection between two buses. e.g. switchB or any switch that is parallel to switchB.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The pandapower network to get the indirect connections from.
TYPE:
|
bus_1
|
The bus to get the indirect connections from.
TYPE:
|
bus_2
|
The bus to get the indirect connections to.
TYPE:
|
only_closed_switches
|
If True, only closed switches are considered.
TYPE:
|
consider_three_buses
|
If True, the function will also consider three buses in between. Bus1---switch1---bus2---switch2---bus3---switch3---bus4---switch4---bus5
TYPE:
|
exclude_buses
|
The buses to exclude from the indirect connection. e.g. give all other busbars (type b) in the substation.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, list[int]]
|
A dictionary with the indirect connections from bus_1 to bus_2 |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the indirect connection contains more than one switch. e.g. a parallel line to the switch. |
Source code in packages/importer_pkg/src/toop_engine_importer/pandapower_import/pandapower_toolset_node_breaker.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | |
get_station_id_list
#
Get all station ids from the network.
This function will return all unique station ids from the network.
| PARAMETER | DESCRIPTION |
|---|---|
bus_df
|
The bus DataFrame to get the station ids from. e.g. pre filtered bus DataFrame with only busbars of type 'b'.
TYPE:
|
substation_col
|
The column name of the substation
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[int]
|
A list of station ids in the order of the stations in the substation_col. |
Source code in packages/importer_pkg/src/toop_engine_importer/pandapower_import/pandapower_toolset_node_breaker.py
get_substation_buses_from_bus_id
#
Get all buses of a substation from a start bus id.
This function will return all buses that are connected to the start bus id via switches. Note: The input expects a bus ids only containing the busbars you want to get the connection for. See diagram for references. e.g:: input [BB1, BB2] -> get BC½ input [BB1, BB2, BB3, BB4] -> get BC½, BC¾, CC⅓, CC2/4
| PARAMETER | DESCRIPTION |
|---|---|
network
|
The pandapower network to get the substation buses from.
TYPE:
|
start_bus_id
|
The bus id to start the search from.
TYPE:
|
only_closed_switches
|
If True, only closed switches are considered.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
set[int]
|
A set of bus ids that are connected to the start bus id. |
| RAISES | DESCRIPTION |
|---|---|
RuntimeError
|
If the function detects an infinite loop. |
Source code in packages/importer_pkg/src/toop_engine_importer/pandapower_import/pandapower_toolset_node_breaker.py
get_type_b_nodes
#
Get all nodes of type 'b' (busbar) in a network or substation.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
The pandapower network to get the busbars from.
TYPE:
|
substation_bus_list
|
The bus ids of the substation.
TYPE:
|
substation_column
|
The column containing the substation.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
A DataFrame with all busbars of type 'b' in the substation. |
Source code in packages/importer_pkg/src/toop_engine_importer/pandapower_import/pandapower_toolset_node_breaker.py
preprocess_net_step1
#
General preprocessing - e.g. a PowerFactory network may converge in AC -> change elements.
Step 1: General preprocessing - select connected subnet - Remove zero branches - remove out of service elements - handle_constant_z_load - drop elements connected to one bus - replace xward by internal elements - replace ward by internal elements - drop controler
| PARAMETER | DESCRIPTION |
|---|---|
net
|
pandapower network Note: the network is modified in place
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
net
|
modified pandapower network
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/pandapower_import/preprocessing.py
preprocess_net_step2_master_asset_topology
#
Run pandapower preprocessing step 2 on canonical master data.
Source code in packages/importer_pkg/src/toop_engine_importer/pandapower_import/preprocessing.py
validate_asset_topology_stations
#
Validate canonical station connection counts directly against the pandapower network.
Source code in packages/importer_pkg/src/toop_engine_importer/pandapower_import/preprocessing.py
Importer Pypowsybl#
toop_engine_importer.pypowsybl_import
#
Import data from PyPowSyBl networks to the Topology Optimizer.
__all__
module-attribute
#
__all__ = [
"NetworkMasks",
"PowsyblSecurityAnalysisParam",
"PreProcessingStatistics",
"apply_cb_lists",
"apply_preprocessing_changes_to_network",
"apply_white_list_to_operational_limits",
"assign_element_id_to_cb_df",
"convert_low_impedance_lines",
"create_default_network_masks",
"get_branches_df_with_element_name",
"get_bus_breaker_master_asset_topology",
"import_grid_with_security_analysis",
"load_preprocessing_statistics_filesystem",
"make_masks",
"remove_branches_across_switch",
"save_masks_to_files",
"save_preprocessing_statistics_filesystem",
"validate_network_masks",
]
PowsyblSecurityAnalysisParam
#
Bases: BaseModel
Contains all the parameter for a Security Analysis with pypowsybl.
single_element_contingencies_ids
instance-attribute
#
The ids of the single element contingencies for the different element types.
The keys are the element types and the values are the ids of the elements. keys example: "dangling", "generator", "line", "switch", "tie", "transformer", "load", "custom"
current_limit_factor
instance-attribute
#
The factor to reduce the current limit on the lines.
This factor needs to be applied before the security analysis in for current limit and after in the violation dataframe.
monitored_branches
instance-attribute
#
The branches that are monitored during the security analysis.
monitored_buses
instance-attribute
#
The buses that are monitored during the security analysis.
ac_run
class-attribute
instance-attribute
#
Define load flow type.
True: run AC N-1 Analysis. False: run DC N-1 Analysis.
PreProcessingStatistics
#
Bases: BaseModel
Contains all the statistics of the postprocessing.
id_lists
class-attribute
instance-attribute
#
Contains the ids of the N-1 analysis, border line currents and CB lists. keys: relevant_subs, line_for_nminus1, trafo_for_nminus1, tie_line_for_nminus1, boundary_line_for_nminus1, generator_for_nminus1, load_for_nminus1, switches_for_nminus1 white_list, black_list
border_current
class-attribute
instance-attribute
#
Contains the statistics of the current limit for the lines that leave the tso area.
network_changes
class-attribute
instance-attribute
#
Contains the statistics of the changes made to the network. keys: black_list, white_list, low_impedance_lines, branches_across_switch
import_parameter
class-attribute
instance-attribute
#
Contains the statistics of the post processing.
get_bus_breaker_master_asset_topology
#
get_bus_breaker_master_asset_topology(
network,
relevant_stations,
topology_id,
grid_model_file=None,
)
Return canonical topology master data derived from the current bus-breaker structure.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
Source powsybl network.
TYPE:
|
relevant_stations
|
Relevant stations as bus ids or as a boolean mask over
TYPE:
|
topology_id
|
Identifier to store on the resulting master data.
TYPE:
|
grid_model_file
|
Source grid-model file name stored in the master data.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
MasterAssetTopology
|
Canonical master data grouped by structural bus-breaker station views. |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/powsybl/powsybl_asset_topo.py
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 | |
apply_white_list_to_operational_limits
#
Apply the white list to the operational limits of the network.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
The network to modify. Note: The network is modified in place.
TYPE:
|
white_list_df
|
DataFrame with the columns "element_id", "Anfangsknoten", "Endknoten", "Auslastungsgrenze_n_0", "Auslastungsgrenze_n_1"
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/dacf_whitelists.py
assign_element_id_to_cb_df
#
Get the element_id for the elements in the cb_df based on the power network model.
| PARAMETER | DESCRIPTION |
|---|---|
branches_with_elementname
|
powsybl branches DataFrame with the columns "elementName", "bus_breaker_bus1_id", "bus_breaker_bus2_id", "voltage_level1_id", "voltage_level2_id", "pairing_key"
TYPE:
|
cb_df
|
DataFrame with the columns "Elementname", "Anfangsknoten", "Endknoten" Note: The element_id column is added to the DataFrame in place
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
None
|
|
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/dacf_whitelists.py
apply_cb_lists
#
Run the black or white list to the powsybl network.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
The network to modify. Note: The network is modified in place.
TYPE:
|
statistics
|
The statistics to fill with the id lists of the black and white list Note: The statistics are modified in place.
TYPE:
|
white_list_file
|
The path to the white list file, if None, no white list is applied.
TYPE:
|
black_list_file
|
The path to the black list file, if None, no black list is applied.
TYPE:
|
fs
|
The filesystem to use to read the files.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
statistics
|
The statistics with the id lists of the black and white list
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/network_analysis.py
convert_low_impedance_lines
#
Convert all lines in the same voltage level with very low impedance to breakers.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The network to modify. Note: This function modifies the network in place.
TYPE:
|
voltage_level_prefix
|
The prefix of the voltage level to consider.
TYPE:
|
x_threshold_line
|
The threshold for x, everything below will be converted.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
low_impedance_lines
|
The lines that were converted to breakers.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/network_analysis.py
get_branches_df_with_element_name
#
Get the branches with the element name.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
The network object
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
The branches with the element name |
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/network_analysis.py
remove_branches_across_switch
#
Remove all branches that span across a closed switch, i.e. have the same from+to bus.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The network to modify. Note: This function modifies the network in place.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
to_remove
|
The branches that were removed.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/network_analysis.py
make_masks
#
Create all masks for the network, depending on the import parameters.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
The network to get the masks for.
TYPE:
|
slack_id
|
The id of the slack bus in the network. This is needed to exclude the slack bus from the relevant_subs mask.
TYPE:
|
importer_parameters
|
The import parameters including control_area, nminus1_area, cutoff_voltage Optional: border_line_factors, border_line_weight, dso_trafo_factors, dso_trafo_weight
TYPE:
|
filesystem
|
The filesystem to use for loading the contingency lists from. If not provided, the local filesystem is used.
TYPE:
|
blacklisted_ids
|
The ids of the branche that are blacklisted.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
network_masks
|
The masks for the network.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/powsybl_masks.py
save_masks_to_files
#
Save the network masks to files.
| PARAMETER | DESCRIPTION |
|---|---|
network_masks
|
The network masks to save.
TYPE:
|
data_folder
|
The folder to save the masks to.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/powsybl_masks.py
validate_network_masks
#
Validate if the network masks are created correctly.
| PARAMETER | DESCRIPTION |
|---|---|
network_masks
|
The network masks to validate.
TYPE:
|
default_mask
|
The default network masks to validate against.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if the network masks are created correctly, False otherwise. |
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/powsybl_masks.py
apply_preprocessing_changes_to_network
#
Apply the default changes to the network.
These changes include: - removing low impedance lines - removing branches across switches
| PARAMETER | DESCRIPTION |
|---|---|
network
|
The network to apply the changes to. Note: This function modifies the network in place.
TYPE:
|
statistics
|
The statistics of the preprocessing. Note: This function modifies the statistics in place.
TYPE:
|
status_update_fn
|
A function to call to signal progress in the preprocessing pipeline. Takes a stage and an optional message as parameters
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/preprocessing.py
import_grid_with_security_analysis
#
import_grid_with_security_analysis(
importer_parameters,
status_update_fn=empty_status_update_fn,
processed_gridfile_fs=None,
unprocessed_gridfile_fs=None,
*,
job_id="",
)
Import the grid file and run its AC security analysis, which sets the artificial limits.
Saves data and network to the output folder. The security analysis runs once. Its results, with the artificial limits attached, are returned as the initial loadflow, so no second analysis is needed.
| PARAMETER | DESCRIPTION |
|---|---|
importer_parameters
|
Parameters that are required to import the data from a UCTE or CGMES file. This will utilize powsybl and the powsybl backend to the loadflow solver
TYPE:
|
status_update_fn
|
A function to call to signal progress in the preprocessing pipeline. Takes a stage, an optional message and network stats as parameters
TYPE:
|
processed_gridfile_fs
|
A filesystem where the processed gridfiles are stored. If None, the local filesystem is used
TYPE:
|
unprocessed_gridfile_fs
|
A filesystem where the unprocessed gridfiles are stored. If None, the local filesystem is used.
TYPE:
|
job_id
|
The job id stored with the initial loadflow.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ImportedGridModel
|
The statistics of the import, the initial loadflow and its metrics. |
| RAISES | DESCRIPTION |
|---|---|
BaseCaseNotConvergedError
|
If the base case loadflow does not converge, before or after the preprocessing changes to the network. |
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/preprocessing.py
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 | |
load_preprocessing_statistics_filesystem
#
Load the preprocessing statistics from the file.
| PARAMETER | DESCRIPTION |
|---|---|
file_path
|
The file to load the preprocessing statistics from.
TYPE:
|
filesystem
|
The filesystem to load the file from.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
statistics
|
The loaded statistics.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/preprocessing.py
save_preprocessing_statistics_filesystem
#
Save the preprocessing statistics to the filesystem.
| PARAMETER | DESCRIPTION |
|---|---|
statistics
|
The statistics to save.
TYPE:
|
file_path
|
The file to save the preprocessing statistics to.
TYPE:
|
filesystem
|
The filesystem to save the file to.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/preprocessing.py
toop_engine_importer.pypowsybl_import.preprocessing
#
Module contains functions for the pypowsybl preprocessing for the grid export into the loadflow solver.
File: preprocessing.py Author: Benjamin Petrick Created: 2024-09-04
BaseCaseNotConvergedError
#
Bases: RuntimeError
The base case loadflow of the import did not converge, so the import cannot continue.
ImportedGridModel
dataclass
#
The outcome of an import, including its AC security analysis.
save_preprocessing_statistics_filesystem
#
Save the preprocessing statistics to the filesystem.
| PARAMETER | DESCRIPTION |
|---|---|
statistics
|
The statistics to save.
TYPE:
|
file_path
|
The file to save the preprocessing statistics to.
TYPE:
|
filesystem
|
The filesystem to save the file to.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/preprocessing.py
load_preprocessing_statistics_filesystem
#
Load the preprocessing statistics from the file.
| PARAMETER | DESCRIPTION |
|---|---|
file_path
|
The file to load the preprocessing statistics from.
TYPE:
|
filesystem
|
The filesystem to load the file from.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
statistics
|
The loaded statistics.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/preprocessing.py
create_nminus1_definition_from_masks
#
Create the N-1 definition from the network masks.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
The network to create the N-1 definition for.
TYPE:
|
network_masks
|
The network masks to create the N-1 definition from.
TYPE:
|
master_topology
|
The asset-topology master data providing the busbars and couplers of the relevant stations.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Nminus1Definition
|
The created N-1 definition. |
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/preprocessing.py
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 368 369 370 | |
create_nminus1_definition
#
create_nminus1_definition(
network,
network_masks,
master_topology,
input_nminus1_definition=None,
)
Create the N-1 definition that is saved next to the processed grid.
The input N-1 definition is authoritative and not filtered by the area settings; without one, the definition is
derived from the network masks. Three-winding transformers are then replaced by their two-winding legs, and an
input definition is checked against network again, dropping elements that preprocessing removed.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
The processed grid, after the three-winding transformer conversion.
TYPE:
|
network_masks
|
The network masks, used when no input N-1 definition is given.
TYPE:
|
master_topology
|
The asset-topology master data, used when no input N-1 definition is given.
TYPE:
|
input_nminus1_definition
|
The grid-validated input N-1 definition, if any.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Nminus1Definition
|
The N-1 definition referencing only elements of the processed grid. |
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/preprocessing.py
get_input_nminus1_definition_voltage_level_ids
#
Get the voltage levels of all input N-1 elements, including the star voltage levels of converted 3W trafos.
Network reduction keeps them, because the input N-1 definition takes precedence over the area settings.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
The grid after the three-winding transformer conversion and before the reduction.
TYPE:
|
input_nminus1_definition
|
The grid-validated input N-1 definition, if any.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[str]
|
The voltage level ids to keep, empty if no input N-1 definition is given. |
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/preprocessing.py
load_and_prepare_network
#
load_and_prepare_network(
importer_parameters,
processed_gridfile_fs,
unprocessed_gridfile_fs,
status_update_fn,
)
Copy, load, and normalize the input network before preprocessing.
An input N-1 definition is validated before the three-winding transformer conversion, as it uses their original ids.
| PARAMETER | DESCRIPTION |
|---|---|
importer_parameters
|
Parameters describing the input grid file and output folder.
TYPE:
|
processed_gridfile_fs
|
Filesystem where the original input grid is archived.
TYPE:
|
unprocessed_gridfile_fs
|
Filesystem from which the input grid is loaded.
TYPE:
|
status_update_fn
|
Callback used to report preprocessing progress.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Network
|
The loaded and normalized network. |
Optional[Nminus1Definition]
|
The grid-validated input N-1 definition, or None if |
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/preprocessing.py
import_grid_with_security_analysis
#
import_grid_with_security_analysis(
importer_parameters,
status_update_fn=empty_status_update_fn,
processed_gridfile_fs=None,
unprocessed_gridfile_fs=None,
*,
job_id="",
)
Import the grid file and run its AC security analysis, which sets the artificial limits.
Saves data and network to the output folder. The security analysis runs once. Its results, with the artificial limits attached, are returned as the initial loadflow, so no second analysis is needed.
| PARAMETER | DESCRIPTION |
|---|---|
importer_parameters
|
Parameters that are required to import the data from a UCTE or CGMES file. This will utilize powsybl and the powsybl backend to the loadflow solver
TYPE:
|
status_update_fn
|
A function to call to signal progress in the preprocessing pipeline. Takes a stage, an optional message and network stats as parameters
TYPE:
|
processed_gridfile_fs
|
A filesystem where the processed gridfiles are stored. If None, the local filesystem is used
TYPE:
|
unprocessed_gridfile_fs
|
A filesystem where the unprocessed gridfiles are stored. If None, the local filesystem is used.
TYPE:
|
job_id
|
The job id stored with the initial loadflow.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ImportedGridModel
|
The statistics of the import, the initial loadflow and its metrics. |
| RAISES | DESCRIPTION |
|---|---|
BaseCaseNotConvergedError
|
If the base case loadflow does not converge, before or after the preprocessing changes to the network. |
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/preprocessing.py
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 | |
compute_network_masks
#
compute_network_masks(
importer_parameters,
processed_gridfile_fs,
unprocessed_gridfile_fs,
network,
statistics,
)
Create, persist, and return network masks.
| PARAMETER | DESCRIPTION |
|---|---|
importer_parameters
|
Import configuration providing the data folder and mask generation settings.
TYPE:
|
processed_gridfile_fs
|
Filesystem used to persist the generated masks.
TYPE:
|
unprocessed_gridfile_fs
|
Filesystem used to resolve auxiliary inputs required during mask creation.
TYPE:
|
network
|
Powsybl network for which masks are computed.
TYPE:
|
statistics
|
Statistics object updated while generating masks.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NetworkMasks
|
Generated network masks after saving them. |
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/preprocessing.py
get_slack_ids
#
Get the slack bus ids from the network.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
The network to get the slack bus ids from.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[str] | None
|
The list of slack bus ids. |
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/preprocessing.py
find_converging_loadflow_params
#
Iterate over Loadflow parameters and voltage initialization methods to find a converging loadflow.
This is necessary because some grid files do not converge with the default loadflow parameters and voltage initialization method.
| PARAMETER | DESCRIPTION |
|---|---|
importer_parameters
|
The importer parameters to use for the loadflow parameters.
TYPE:
|
network
|
The network to run the loadflow on.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tuple[Parameters, ComponentResult]
|
The loadflow parameters that converged and the result of the loadflow with those parameters. |
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/preprocessing.py
get_network_masks
#
Create network masks and save them.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
The network to create the asset topology for
TYPE:
|
slack_id
|
The id of the slack bus
TYPE:
|
importer_parameters
|
import parameters that include the datafolder
TYPE:
|
statistics
|
preprocessing statistics to fill with information
TYPE:
|
filesystem
|
The filesystem to load the mask files from.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NetworkMasks
|
The created network masks |
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/preprocessing.py
get_master_asset_topology_artifact
#
Return canonical asset-topology master data for preprocessing persistence.
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/preprocessing.py
apply_preprocessing_changes_to_network
#
Apply the default changes to the network.
These changes include: - removing low impedance lines - removing branches across switches
| PARAMETER | DESCRIPTION |
|---|---|
network
|
The network to apply the changes to. Note: This function modifies the network in place.
TYPE:
|
statistics
|
The statistics of the preprocessing. Note: This function modifies the statistics in place.
TYPE:
|
status_update_fn
|
A function to call to signal progress in the preprocessing pipeline. Takes a stage and an optional message as parameters
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/preprocessing.py
fill_statistics_for_overload_energy
#
Fill the statistics with the overload energy against the permanent, the artificial and the artificial DC limits.
| PARAMETER | DESCRIPTION |
|---|---|
statistics
|
The statistics to fill. Note: This function modifies the statistics in place.
TYPE:
|
metrics
|
The AC metrics of the unsplit grid, see compute_initial_metrics. A missing metric is stored as None.
TYPE:
|
dc_metrics
|
The DC metrics of the unsplit grid against the artificial DC limits, named like the artificial limit metrics. A missing metric is stored as None.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/preprocessing.py
fill_statistics_for_nminus1_definition
#
Fill the statistics with the monitored branches of the N-1 definition.
| PARAMETER | DESCRIPTION |
|---|---|
statistics
|
The statistics to fill. Note: This function modifies the statistics in place.
TYPE:
|
nminus1_definition
|
The N-1 definition, generated from the masks or given as input.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/preprocessing.py
fill_statistics_for_network_masks
#
Fill the statistics with the network masks.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
The network to get the id lists from.
TYPE:
|
statistics
|
The statistics to fill. Note: This function modifies the statistics in place.
TYPE:
|
network_masks
|
The masks for the network.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/preprocessing.py
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 | |
toop_engine_importer.pypowsybl_import.artificial_limits
#
Create the artificial optimization limits of the monitored branches and measure the unsplit grid against them.
The limits are derived from the worst currents of a security analysis, the branch role (optimized or non-worsening) and the double limits. See docs/importer/pypowsybl/artificial_limits.md.
ARTIFICIAL_LIMITS
module-attribute
#
ARTIFICIAL_LIMITS = (
OperationalLimit.ARTIFICIAL_N_0,
OperationalLimit.ARTIFICIAL_N_1,
)
ARTIFICIAL_DC_LIMITS
module-attribute
#
ARTIFICIAL_DC_LIMITS = (
OperationalLimit.ARTIFICIAL_DC_N_0,
OperationalLimit.ARTIFICIAL_DC_N_1,
)
compute_artificial_limits
#
Compute the optimization limit of every branch and side from its worst flow.
- Branches that are optimized and non-worsening ignore the lower and upper limit.
They get the physical limit if overloaded, otherwise their flow plus
non_worsening_margin(capped at the physical limit), at leastminimum_lower_physical_non_worsening_limittimes the physical limit. - Optimized branches above the upper limit get the upper limit.
- Non-worsening branches get their flow plus
non_worsening_margin, at leastminimum_lower_physical_non_worsening_limittimes the physical limit. - Other optimized branches get the larger of the lower limit and their flow.
| PARAMETER | DESCRIPTION |
|---|---|
flow
|
The worst absolute flow of the case.
TYPE:
|
limit
|
The physical limit of the case, in the unit of the flow.
TYPE:
|
optimized
|
Whether the branch is optimized.
TYPE:
|
non_worsening
|
Whether the branch is non-worsening.
TYPE:
|
double_limits
|
The lower and upper limit and the minimum non-worsening limit, relative to the physical limit.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Series
|
The optimization limits. NaN for branches that are neither optimized nor non-worsening and for branches without a flow or a physical limit. |
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/artificial_limits.py
get_artificial_limits_for_case
#
Get the optimization limits of the monitored branches for one limit.
| PARAMETER | DESCRIPTION |
|---|---|
branches_df
|
The branches dataframe with the columns type, i1, i2, optimized, non_worsening, the limits and group names of the case and the boundary lines of the tie lines.
TYPE:
|
worst_case
|
The worst absolute currents with the columns element, side, n0 and n1.
TYPE:
|
double_limits
|
The lower and upper limit, relative to the physical limit.
TYPE:
|
limit
|
The limit to create, e.g. ARTIFICIAL_N_0 or ARTIFICIAL_DC_N_1. It defines the case, name and acceptable duration.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[DataFrame]
|
A list of dataframes in the required format for create_operational_limits. |
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/artificial_limits.py
add_default_permanent_limits
#
Add a permanent limit to the monitored branches that have None on a branch SIDE.
The limits of tie lines are set on their boundary lines.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
The network to add the limits to. It is modified in place.
TYPE:
|
monitored_branch_ids
|
The ids of the monitored branches.
TYPE:
|
default_permanent
|
The permanent limit in A of the added limits.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/artificial_limits.py
create_artificial_limits
#
create_artificial_limits(
network,
nminus1_definition,
worst_case_currents,
double_limits,
limits=ARTIFICIAL_LIMITS,
)
Create the optimization limits of the monitored branches in the network.
The limits replace the limits of the same element, side and name, see compute_artificial_limits.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
The network to create the limits for. The loadflow calculation needs to have happened
TYPE:
|
nminus1_definition
|
The N-1 definition with the optimized and non-worsening monitored branches
TYPE:
|
worst_case_currents
|
The worst absolute currents with the columns element, side, n0 and n1, see extract_worst_case_branch_results_polars
TYPE:
|
double_limits
|
The lower and upper limit, relative to the physical limit.
TYPE:
|
limits
|
The limits to create, ARTIFICIAL_LIMITS by default. Use ARTIFICIAL_DC_LIMITS for DC results.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
The new limits for the network including the already existing ones |
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/artificial_limits.py
attach_artificial_limits_to_results
#
attach_artificial_limits_to_results(
network,
nminus1_definition,
security_analysis_results,
double_limits,
limits=ARTIFICIAL_LIMITS,
)
Create the artificial limits from the worst currents and attach the new limits to the results.
Works for AC and DC results alike, the limits tell them apart.
Currents do not depend on limits, so the returned results equal those of an analysis run after the limits were created, without running one.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
The network to create the artificial limits on. It is modified in place.
TYPE:
|
nminus1_definition
|
The N-1 definition with the optimized and non-worsening monitored branches.
TYPE:
|
security_analysis_results
|
The results of the AC security analysis of the network.
TYPE:
|
double_limits
|
The lower and upper limit, relative to the physical limit.
TYPE:
|
limits
|
The limits to create. Use ARTIFICIAL_DC_LIMITS for DC results.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
LoadflowResultsPolars
|
The security analysis results with the branch limits of the monitored branches, including the artificial ones. |
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/artificial_limits.py
compute_initial_metrics
#
Compute the metrics of the unsplit grid.
| PARAMETER | DESCRIPTION |
|---|---|
loadflow_results
|
The AC N-1 results of the unsplit grid, with the branch limits to measure against.
TYPE:
|
nminus1_definition
|
The N-1 definition, which holds the base case.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[MetricType, float]
|
The metrics. Metrics of limits that no branch has are left out. |
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/artificial_limits.py
compute_dc_artificial_limit_metrics
#
compute_dc_artificial_limit_metrics(
network,
nminus1_definition,
double_limits,
lf_params,
job_id,
n_processes,
batch_size,
)
Run a DC security analysis, create the artificial DC limits from it and measure the unsplit grid against them.
The DC solver reads these limits instead of the AC based ones, as they match its DC flows.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
The network to create the artificial DC limits on. Only its limits are modified.
TYPE:
|
nminus1_definition
|
The N-1 definition with the optimized and non-worsening monitored branches.
TYPE:
|
double_limits
|
The lower and upper limit, relative to the physical limit.
TYPE:
|
lf_params
|
The loadflow parameters of the import.
TYPE:
|
job_id
|
The job id stored with the results.
TYPE:
|
n_processes
|
The number of threads of the security analysis.
TYPE:
|
batch_size
|
Maximum number of outage contingencies per sequential analysis.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[MetricType, float]
|
The DC metrics of the unsplit grid against the artificial DC limits, named like the artificial limit metrics. Metrics of limits that no branch has are left out. |
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/artificial_limits.py
toop_engine_importer.pypowsybl_import.contingency_from_file.nminus1_definition_input
#
Grid-file stage of the input N-1 definition: validate a Pydantic dump of Nminus1Definition against a grid.
KIND_BY_ELEMENT_TYPE
module-attribute
#
KIND_BY_ELEMENT_TYPE = {
"LINE": "branch",
"TWO_WINDINGS_TRANSFORMER": "branch",
"THREE_WINDINGS_TRANSFORMER": "branch",
"HVDC_LINE": "branch",
"TIE_LINE": "branch",
"GENERATOR": "injection",
"LOAD": "injection",
"BOUNDARY_LINE": "injection",
"SHUNT_COMPENSATOR": "injection",
"BUS": "bus",
"BUSBAR_SECTION": "bus",
"SWITCH": "switch",
}
filter_nminus1_definition_to_network
#
Validate an input N-1 definition against the grid, dropping what the grid does not contain.
The network must be the grid before the three-winding transformer conversion, because three-winding transformers are referenced by their original id.
| PARAMETER | DESCRIPTION |
|---|---|
definition
|
The input N-1 definition with Powsybl element ids.
TYPE:
|
network
|
The unconverted grid to validate against.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Nminus1Definition
|
The definition restricted to the grid. Every change is logged as a warning:
|
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/contingency_from_file/nminus1_definition_input.py
load_nminus1_definition_for_network
#
Load an input N-1 definition JSON and validate it against the grid.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
The unconverted grid to validate against, see :func:
TYPE:
|
file_path
|
Path to the Pydantic JSON of an
TYPE:
|
filesystem
|
Filesystem from which to read
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Nminus1Definition
|
The grid-validated N-1 definition. |
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/contingency_from_file/nminus1_definition_input.py
toop_engine_importer.pypowsybl_import.contingency_from_file.nminus1_definition_conversion
#
Convert three-winding transformers in an N-1 definition to their two-winding legs <id>-Leg1/2/3.
This is the last stage of the N-1 definition pipeline before the definition is saved next to the converted grid.
convert_three_winding_transformers_in_nminus1_definition
#
Convert every three-winding transformer reference in an N-1 definition to its two-winding legs.
Contingency and monitored elements on a converted three-winding transformer are replaced by its three legs.
SPPS conditions and actions on it are copied once per leg, regardless of the rule's condition_logic, so an
ANY rule triggers as soon as a single leg meets the condition. The conversion is idempotent.
| PARAMETER | DESCRIPTION |
|---|---|
definition
|
The N-1 definition, referencing three-winding transformers by their original id.
TYPE:
|
network
|
The grid after
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Nminus1Definition
|
The converted definition. A three-winding transformer whose legs are not in the grid is kept and warned about. |
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/contingency_from_file/nminus1_definition_conversion.py
get_nminus1_definition_element_ids
#
Collect the ids of all contingency, monitored, SPPS condition and SPPS action elements of an N-1 definition.
| PARAMETER | DESCRIPTION |
|---|---|
definition
|
The N-1 definition.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
set[str]
|
The referenced element ids. |
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/contingency_from_file/nminus1_definition_conversion.py
toop_engine_importer.pypowsybl_import.network_reduction
#
Reduce the network based on voltage levels and a depth range.
get_voltage_level_ids_of_elements
#
Get the sorted, unique voltage levels the given elements are connected to.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The network containing the elements.
TYPE:
|
element_ids
|
Ids of branches (both sides), injections (including busbar sections), HVDC lines (both converter stations), switches, bus-breaker buses or voltage levels. Ids not found in the network are ignored.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[str]
|
The voltage level ids. |
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/network_reduction.py
reduce_network_based_on_area_settings
#
Reduce the network based on area settings and range.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The network to be reduced. Note: The network is modified in place.
TYPE:
|
importer_parameters
|
The importer parameters containing the area settings and range.
TYPE:
|
extra_voltage_level_ids
|
Additional voltage levels to keep, regardless of the area settings, e.g. the voltage levels of the elements of an input N-1 definition. They are reduced with the same range as the area voltage levels.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/network_reduction.py
Importer Network Graph Pandapower#
toop_engine_importer.network_graph
#
Importer-specific network-graph helpers.
__all__
module-attribute
#
__all__ = [
"get_branch_df",
"get_network_graph",
"get_network_graph_data",
"get_nodes",
"get_switches_df",
]
get_branch_df
#
Get the branches data from the pandapower network and return a df ready to use for the BranchSchema.
Note: A star equivalent transformation for three winding trafos is not needed before calling this module. The the graph module only needs the connection and does no calculation.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The pandapower network.
TYPE:
|
only_relevant_col
|
Whether to return only the relevant columns, by default True relevant is determined by the default BranchSchema columns
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
branch_df
|
The DataFrame containing the branches in the format of the BranchSchema.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/pandapower_network_to_graph.py
get_network_graph
#
Get the network graph from the NetworkGraphData and run default filter.
| PARAMETER | DESCRIPTION |
|---|---|
network_graph_data
|
The NetworkGraphData containing the nodes, switches, branches and node_assets.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Graph
|
The network graph. |
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/pandapower_network_to_graph.py
get_network_graph_data
#
Get the network graph from the pandapower network.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The pandapower network.
TYPE:
|
only_relevant_col
|
Whether to return only the relevant columns, by default True relevant is determined by the default BranchSchema columns
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
net_graph
|
The network graph in the format of the NetworkGraph class. Contains the full network with all substations.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/pandapower_network_to_graph.py
get_nodes
#
Get the nodes data from the pandapower network and return a df ready to use for the NodeSchema.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The pandapower network.
TYPE:
|
only_relevant_col
|
Whether to return only the relevant columns, by default True relevant is determined by the default NodeSchema columns
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
nodes_df
|
The DataFrame containing the nodes in the format of the NodeSchema.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/pandapower_network_to_graph.py
get_switches_df
#
Get the switches data from the pandapower network and return a df ready to use for the SwitchSchema.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The pandapower network.
TYPE:
|
only_relevant_col
|
Whether to return only the relevant columns, by default True relevant is determined by the default SwitchSchema columns
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
switches_df
|
The DataFrame containing the switches in the format of the SwitchSchema.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/pandapower_network_to_graph.py
toop_engine_importer.network_graph.pandapower_network_to_graph
#
Convert a pandapower network to a network graph.
get_network_graph_data
#
Get the network graph from the pandapower network.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The pandapower network.
TYPE:
|
only_relevant_col
|
Whether to return only the relevant columns, by default True relevant is determined by the default BranchSchema columns
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
net_graph
|
The network graph in the format of the NetworkGraph class. Contains the full network with all substations.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/pandapower_network_to_graph.py
get_network_graph
#
Get the network graph from the NetworkGraphData and run default filter.
| PARAMETER | DESCRIPTION |
|---|---|
network_graph_data
|
The NetworkGraphData containing the nodes, switches, branches and node_assets.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Graph
|
The network graph. |
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/pandapower_network_to_graph.py
get_edges_data
#
Get the edges data from the dataframe and return a df ready to use for the BranchSchema.
Can be used for switches, trafos and other branches.
| PARAMETER | DESCRIPTION |
|---|---|
dataframe
|
The DataFrame containing the edges.
TYPE:
|
asset_type
|
The type of the asset.
TYPE:
|
only_relevant_col
|
Whether to return only the relevant columns, by default True relevant is determined by the default BranchSchema columns
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
The DataFrame containing the edges in the format of the |
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/pandapower_network_to_graph.py
get_nodes
#
Get the nodes data from the pandapower network and return a df ready to use for the NodeSchema.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The pandapower network.
TYPE:
|
only_relevant_col
|
Whether to return only the relevant columns, by default True relevant is determined by the default NodeSchema columns
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
nodes_df
|
The DataFrame containing the nodes in the format of the NodeSchema.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/pandapower_network_to_graph.py
get_switches_df
#
Get the switches data from the pandapower network and return a df ready to use for the SwitchSchema.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The pandapower network.
TYPE:
|
only_relevant_col
|
Whether to return only the relevant columns, by default True relevant is determined by the default SwitchSchema columns
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
switches_df
|
The DataFrame containing the switches in the format of the SwitchSchema.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/pandapower_network_to_graph.py
get_branch_df
#
Get the branches data from the pandapower network and return a df ready to use for the BranchSchema.
Note: A star equivalent transformation for three winding trafos is not needed before calling this module. The the graph module only needs the connection and does no calculation.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The pandapower network.
TYPE:
|
only_relevant_col
|
Whether to return only the relevant columns, by default True relevant is determined by the default BranchSchema columns
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
branch_df
|
The DataFrame containing the branches in the format of the BranchSchema.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/pandapower_network_to_graph.py
Exporter#
toop_engine_importer.exporter
#
Export data from the AICoE_HPC_RL_Optimizer back to the original format.
asset_topology_to_dgs.py: Translate asset topology model to a DGS file (PowerFactory).asset_topology_to_ucte.py: Translate asset topology model to a UCTE file.uct_exporter.py: Translate a RealizedTopology json file to a UCTE file.
__all__
module-attribute
#
asset_topo_to_uct
#
asset_topo_to_uct(
master_data,
grid_model_file_output,
starting_stations=None,
grid_model_file_input=None,
station_list=None,
)
Translate asset topology model to UCT and saves the model.
| PARAMETER | DESCRIPTION |
|---|---|
master_data
|
Canonical master data describing the exported topology.
TYPE:
|
grid_model_file_output
|
Path to save the UCTE file.
TYPE:
|
starting_stations
|
Optional runtime-aware station snapshots to export directly. If not provided,
they are materialized from
TYPE:
|
grid_model_file_input
|
Path to the grid model file. If not provided,
TYPE:
|
station_list
|
List of station ids to be translated. If not provided, all stations in the asset_topology will be translated.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
NotImplementedError
|
If master_data.asset_setpoints is not None. |
Source code in packages/importer_pkg/src/toop_engine_importer/exporter/asset_topology_to_ucte.py
load_ucte
#
Load UCTE file and return its contents as separate dataframes.
| PARAMETER | DESCRIPTION |
|---|---|
input_uct
|
Path to the UCTE file.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
preamble
|
Preamble of the UCTE file.
TYPE:
|
nodes
|
Nodes of the UCTE file.
TYPE:
|
lines
|
Lines of the UCTE file.
TYPE:
|
trafos
|
Transformers of the UCTE file.
TYPE:
|
trafo_reg
|
Transformer regulation of the UCTE file.
TYPE:
|
postamble
|
Postamble of the UCTE file.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/exporter/asset_topology_to_ucte.py
process_file
#
process_file(
input_uct,
input_json,
output_uct,
topo_id=0,
reassign_branches=True,
reassign_injections=False,
)
Process a UCTE file and a preprocessed json file to include split substations.
| PARAMETER | DESCRIPTION |
|---|---|
input_uct
|
The path to the input UCTE file, the original UCTE
TYPE:
|
input_json
|
The preprocessed json holding the split substations and information, use the loadflowsolver's preprocessing notebook to generate this
TYPE:
|
output_uct
|
The path to the output UCTE file, will be overwritten
TYPE:
|
topo_id
|
The id of the topology to use in the json file
TYPE:
|
reassign_branches
|
If True, reassign branches to the new busbars
TYPE:
|
reassign_injections
|
If True, reassign injections to the new busbars Note: not implemented yet
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[str]
|
The codes of the fake busbars that were inserted |
Source code in packages/importer_pkg/src/toop_engine_importer/exporter/uct_exporter.py
validate_ucte_changes
#
Validate the changes made to the UCTE file.
| PARAMETER | DESCRIPTION |
|---|---|
ucte_contents
|
The original UCTE file
TYPE:
|
ucte_contents_out
|
The modified UCTE file
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
RuntimeError
|
If the changes are not as expected |
Source code in packages/importer_pkg/src/toop_engine_importer/exporter/uct_exporter.py
toop_engine_importer.exporter.asset_topology_to_ucte
#
Module containing functions to translate asset topology model to UCT model.
File: asset_topology_to_uct.py Author: Benjamin Petrick Created: 2024-10-22
Note: this module currently ignores the asset_setpoints. Note: this module currently ignores generator and load reassignments.
UCTE_STATUS_CODES
module-attribute
#
UCTE_STATUS_CODES = {
0: {"name": "in_service", "opposite": 8},
1: {"name": "in_service", "opposite": 9},
2: {"name": "in_service", "opposite": 7},
7: {"name": "out_of_service", "opposite": 2},
8: {"name": "out_of_service", "opposite": 0},
9: {"name": "out_of_service", "opposite": 1},
}
load_ucte
#
Load UCTE file and return its contents as separate dataframes.
| PARAMETER | DESCRIPTION |
|---|---|
input_uct
|
Path to the UCTE file.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
preamble
|
Preamble of the UCTE file.
TYPE:
|
nodes
|
Nodes of the UCTE file.
TYPE:
|
lines
|
Lines of the UCTE file.
TYPE:
|
trafos
|
Transformers of the UCTE file.
TYPE:
|
trafo_reg
|
Transformer regulation of the UCTE file.
TYPE:
|
postamble
|
Postamble of the UCTE file.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/exporter/asset_topology_to_ucte.py
asset_topo_to_uct
#
asset_topo_to_uct(
master_data,
grid_model_file_output,
starting_stations=None,
grid_model_file_input=None,
station_list=None,
)
Translate asset topology model to UCT and saves the model.
| PARAMETER | DESCRIPTION |
|---|---|
master_data
|
Canonical master data describing the exported topology.
TYPE:
|
grid_model_file_output
|
Path to save the UCTE file.
TYPE:
|
starting_stations
|
Optional runtime-aware station snapshots to export directly. If not provided,
they are materialized from
TYPE:
|
grid_model_file_input
|
Path to the grid model file. If not provided,
TYPE:
|
station_list
|
List of station ids to be translated. If not provided, all stations in the asset_topology will be translated.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
NotImplementedError
|
If master_data.asset_setpoints is not None. |
Source code in packages/importer_pkg/src/toop_engine_importer/exporter/asset_topology_to_ucte.py
change_trafos_lines_in_ucte
#
Change the 'from' and 'to' columns of the trafos or line DataFrame based on the change_df.
| PARAMETER | DESCRIPTION |
|---|---|
ucte_df
|
The ucte trafos or line DataFrame Note: The DataFrame should have 'from', 'to', 'order' columns Note: The DataFrame is modified in place
TYPE:
|
change_df
|
The change_df, containing the 'grid_model_id', 'initial_busbar' and 'final_busbar' columns
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
None
|
|
Source code in packages/importer_pkg/src/toop_engine_importer/exporter/asset_topology_to_ucte.py
update_busbar_name
#
Update 'from' and 'to' columns based on 'initial_busbar' and 'final_busbar'.
| PARAMETER | DESCRIPTION |
|---|---|
row
|
A row of the DataFrame
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Series
|
The updated row |
Source code in packages/importer_pkg/src/toop_engine_importer/exporter/asset_topology_to_ucte.py
disconnect_line_from_ucte
#
Disconnect a line from UCTE.
Note: a switch is modeled as a line in UCTE. To differentiate between a switch and a line, different status codes are used.
| PARAMETER | DESCRIPTION |
|---|---|
line_row
|
A row of the line DataFrame from the parse_ucte() function
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Series
|
The updated row can be used to update the line DataFrame |
Source code in packages/importer_pkg/src/toop_engine_importer/exporter/asset_topology_to_ucte.py
change_busbar_coupler_state
#
Change the 'status' columns of the lines DataFrame based on the change_df.
| PARAMETER | DESCRIPTION |
|---|---|
lines_df
|
The lines DataFrame Note: The DataFrame should have 'from', 'to', 'status' columns Note: The DataFrame is modified in place
TYPE:
|
change_df
|
The change_df, containing the 'grid_model_id' and 'coupler_state_ucte' columns
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/exporter/asset_topology_to_ucte.py
update_coupler_state
#
Update 'status' column based on 'coupler_state_ucte'.
| PARAMETER | DESCRIPTION |
|---|---|
row
|
A row of the DataFrame
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Series
|
The updated row |
Source code in packages/importer_pkg/src/toop_engine_importer/exporter/asset_topology_to_ucte.py
get_coupler_state_ucte
#
Get coupler ucte state of from a BusbarCoupler.
| PARAMETER | DESCRIPTION |
|---|---|
couplers
|
BusbarCoupler object from the asset topology model
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[dict[str, Union[str, int]]]
|
List of dictionaries containing the coupler_name and the state of the coupler in UCTE format 2: busbar coupler in operation (definition: R=0, X=0, B=0) 7: busbar coupler out of operation (definition: R=0, X=0, B=0) |
Source code in packages/importer_pkg/src/toop_engine_importer/exporter/asset_topology_to_ucte.py
get_changes_from_switching_table
#
Get changes from switching table.
| PARAMETER | DESCRIPTION |
|---|---|
station
|
Station object with switching table, busbars and assets
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[dict[str, Union[str, None]]]
|
List of tuples with asset name, initial_busbar and final_busbar Note: initial_busbar and final_busbar can both be None if asset is disconnected |
Source code in packages/importer_pkg/src/toop_engine_importer/exporter/asset_topology_to_ucte.py
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 | |
handle_duplicated_grid_ids
#
Handle duplicated grid ids in the ucte file.
The function will increment the order of the duplicated grid ids by 1.
| PARAMETER | DESCRIPTION |
|---|---|
ucte_df
|
The ucte DataFrame to be updated Note: The DataFrame should have 'from', 'to', 'order' columns Note: The DataFrame is modified in place
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/exporter/asset_topology_to_ucte.py
toop_engine_importer.exporter.uct_exporter
#
Module containing functions to translate a RealizedTopology json file to a UCTE file.
DeprecationWarning: This module is deprecated and will be removed in the future, due to deprecation of RealizedTopology. Use Topology (AssetTopology) instead.
File: ucte_exporter.py Author: Benjamin Petrick Created: 2024
Note: this module ignores generator and load reassignments.
process_file
#
process_file(
input_uct,
input_json,
output_uct,
topo_id=0,
reassign_branches=True,
reassign_injections=False,
)
Process a UCTE file and a preprocessed json file to include split substations.
| PARAMETER | DESCRIPTION |
|---|---|
input_uct
|
The path to the input UCTE file, the original UCTE
TYPE:
|
input_json
|
The preprocessed json holding the split substations and information, use the loadflowsolver's preprocessing notebook to generate this
TYPE:
|
output_uct
|
The path to the output UCTE file, will be overwritten
TYPE:
|
topo_id
|
The id of the topology to use in the json file
TYPE:
|
reassign_branches
|
If True, reassign branches to the new busbars
TYPE:
|
reassign_injections
|
If True, reassign injections to the new busbars Note: not implemented yet
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[str]
|
The codes of the fake busbars that were inserted |
Source code in packages/importer_pkg/src/toop_engine_importer/exporter/uct_exporter.py
validate_ucte_changes
#
Validate the changes made to the UCTE file.
| PARAMETER | DESCRIPTION |
|---|---|
ucte_contents
|
The original UCTE file
TYPE:
|
ucte_contents_out
|
The modified UCTE file
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
RuntimeError
|
If the changes are not as expected |
Source code in packages/importer_pkg/src/toop_engine_importer/exporter/uct_exporter.py
is_split
#
get_switch_group_number
#
Decide which switch group to open. Selects the group with the fewest unique busbars.
| PARAMETER | DESCRIPTION |
|---|---|
grouped_switches
|
The grouped switches data-frame from group_switches(). Each key contains all switches necessary to isolate a busbar
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
reassignment_key
|
The dict key of the switch group to open
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/exporter/uct_exporter.py
find_switches
#
Find the all switches on the input node.
| PARAMETER | DESCRIPTION |
|---|---|
lines
|
The lines data-frame from UCTE file
TYPE:
|
node_id
|
The node id(s) to search for switches. Note: expects switches to be closed -> status = 2 (closed) Note: this is the first 7 characters of the id (Node), not the full id of busbar that has one additional character
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
switches
|
All switches found on the input node, with status = 2 (closed)
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/exporter/uct_exporter.py
get_unique_busbars
#
Get the unique busbars from the switches.
| PARAMETER | DESCRIPTION |
|---|---|
switches
|
The switches data-frame from find_switches()
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
unique_busbars
|
A list of unique busbars found in the switches
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/exporter/uct_exporter.py
group_switches
#
Group the switches by the busbar id.
There can be multiple switches between the same busbars. This function groups them together. One list element is one group of switches to isolate the bus completely.
| PARAMETER | DESCRIPTION |
|---|---|
switches
|
All switches data-frame from UCTE file from a specific node
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
switches_sort
|
A dict of switches data-frames sorted by the busbar id
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/exporter/uct_exporter.py
get_bus_a_b
#
Get the bus A and B from the switches.
| PARAMETER | DESCRIPTION |
|---|---|
switches
|
The switches data-frame from find_switches()
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bus_a
|
The bus A of the substation
TYPE:
|
bus_b
|
The bus B of the substation
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the switches contain switches from multiple nodes. |
Source code in packages/importer_pkg/src/toop_engine_importer/exporter/uct_exporter.py
open_switches
#
Open switches in the UCTE data by changing the status code value.
| PARAMETER | DESCRIPTION |
|---|---|
lines
|
The lines data-frame from UCTE file Note: modifies the data-frames in place
TYPE:
|
switches
|
The switches data-frame from find_switches() Note: modifies the data-frames in place
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
stats
|
A dictionary containing the bus A and B of the substation, the number of switches and the from and to busbar of the switches
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/exporter/uct_exporter.py
handle_order_of_branch
#
Get a unique order number of the branch for new id.
| PARAMETER | DESCRIPTION |
|---|---|
branch_df
|
The branch data-frame from UCTE file. e.g. lines or trafos or trafo_reg
TYPE:
|
replacement_id
|
The replacement ID of the branch
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
order
|
The order of the branch
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/exporter/uct_exporter.py
find_branch_index
#
Find the index of the branch in the UCTE data.
| PARAMETER | DESCRIPTION |
|---|---|
branch_df
|
The branch data-frame from UCTE file. e.g. lines or trafos or trafo_reg
TYPE:
|
id
|
The ID of the branch
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
branch_df_idx
|
The index of the branch in the data-frame
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/exporter/uct_exporter.py
execute_branch_assignment
#
Apply branch assignment to the UCTE data.
| PARAMETER | DESCRIPTION |
|---|---|
branch_df
|
The branch data-frame from UCTE file. e.g. lines or trafos or trafo_reg Note: modifies the data-frames in place
TYPE:
|
id
|
The original ID of the branch
TYPE:
|
replacement_id
|
The replacement ID of the branch
TYPE:
|
statistics_all_stations
|
The statistics dictionary from process_file() expects as input the statistics["changed_ids"] dictionary
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
replaced
|
True if the branch was replaced, False if the branch was not found in the data-frame
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/exporter/uct_exporter.py
get_replacement_id
#
Get the replacement ID of the branch.
Decides if the element is on bus A or B and replaces the ID accordingly. Bus A is a logical bus and can be electrically connected to other buses e.g. bus C. Bus B is the new Bus that will be split off.
| PARAMETER | DESCRIPTION |
|---|---|
element
|
The element to replace imported from the json
TYPE:
|
code
|
The code of the substation
TYPE:
|
bus_a
|
The bus A of the substation
TYPE:
|
bus_b
|
The bus B of the substation
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
replacement_id
|
The replacement ID of the branch
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/exporter/uct_exporter.py
update_id_if_has_been_replaced
#
Update the ID if it has been replaced in the statistics.
Each branch has a "from" and "to" bus. It can oocur that e.g. the "from" bus has been already replaced, but the "to" bus not. This function checks if the ID has been replaced and returns the new ID if it has been replaced.
| PARAMETER | DESCRIPTION |
|---|---|
id
|
The ID of the branch, which might have been replaced
TYPE:
|
statistics
|
The statistics dictionary from process_file() expects as input the statistics["changed_ids"] dictionary
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/exporter/uct_exporter.py
apply_branch_assignment
#
apply_branch_assignment(
topology_optimizer_results,
lines,
trafos,
trafo_reg,
bus_a,
bus_b,
statistics_all_stations,
)
Apply branch assignment to the UCTE data.
Uses the method to split a busbar into two busbars A and B
| PARAMETER | DESCRIPTION |
|---|---|
topology_optimizer_results
|
The substation split to apply from the postprocessed json
TYPE:
|
lines
|
The lines data-frame from UCTE file Note: modifies the data-frames in place
TYPE:
|
trafos
|
The transformers data-frame from UCTE file Note: modifies the data-frames in place
TYPE:
|
trafo_reg
|
The transformer regulation data-frame from UCTE file Note: modifies the data-frames in place
TYPE:
|
bus_a
|
The bus A of the substation
TYPE:
|
bus_b
|
The bus B of the substation
TYPE:
|
statistics_all_stations
|
The statistics dictionary from process_file()
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
statistics
|
A list of dictionaries containing the original and replacement IDs of the branches that were modified
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
|
Source code in packages/importer_pkg/src/toop_engine_importer/exporter/uct_exporter.py
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 | |