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 |
|---|---|
StartOptimizationCommand
|
The start optimization command to start the optimization 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 | |
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
#
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
#
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
#
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
#
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 |
|---|---|
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",
"SWITCH",
"TWO_WINDINGS_TRANSFORMER",
"THREE_WINDINGS_TRANSFORMER",
"GENERATOR",
"LOAD",
"SHUNT_COMPENSATOR",
"DANGLING_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
#
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
#
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
#
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
#
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 |
|---|---|
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 |
|---|---|
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 |
|---|---|
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 |
|---|---|
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 |
|---|---|
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_asset_topology_from_network",
"get_closed_switch",
"get_coupler_types_of_substation",
"get_indirect_connected_switch",
"get_relevant_subs",
"get_station_from_id",
"get_station_id_list",
"get_substation_buses_from_bus_id",
"get_type_b_nodes",
"make_pp_masks",
"move_elements_based_on_labels",
"preprocess_net_step1",
"preprocess_net_step2",
"remove_out_of_service",
"replace_zero_branches",
"select_connected_subnet",
"validate_asset_topology",
]
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
get_asset_topology_from_network
#
get_asset_topology_from_network(
network,
topology_id,
grid_model_file,
station_id_list,
foreign_key="equipment",
)
Get the asset topology from the network.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
pandapower network object
TYPE:
|
topology_id
|
Id of the topology.
TYPE:
|
grid_model_file
|
Name of the grid model file.
TYPE:
|
station_id_list
|
List of station ids for which the stations should be retrieved. Station ids are a list -> a list of busbars associated with the station.
TYPE:
|
foreign_key
|
Defines the column name that is used as the foreign_key/unique identifier.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
asset_topology
|
Topology class of the network.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/pandapower_import/asset_topology.py
get_station_from_id
#
Get the busses from a station_id.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
pandapower network object
TYPE:
|
station_id_list
|
List of station ids for which the stations should be retrieved.
TYPE:
|
foreign_key
|
Defines the column name that is used as the foreign_key/unique identifier.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
station
|
Station object.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/pandapower_import/asset_topology.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
478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 | |
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
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | |
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:
|
| 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
get_relevant_subs
#
get_relevant_subs(
network,
region="",
voltage_level=150,
min_branches_per_station=4,
exclude_stations=None,
substation_column="substat",
min_busbars_per_substation=2,
min_busbar_coupler_per_station=1,
)
Create the network masks for the pandapower network.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
The pandapower network.
TYPE:
|
region
|
The region of the network.
TYPE:
|
voltage_level
|
The voltage level of the network to be considered.
TYPE:
|
min_branches_per_station
|
The minimum number of busbars per station to be relevant.
TYPE:
|
exclude_stations
|
The substations to exclude.
TYPE:
|
substation_column
|
The column containing the substation.
TYPE:
|
min_busbars_per_substation
|
The minimum number of busbars per substation to be relevant. Note: you need a substation column in the bus dataframe. Note: if you merged the busbars, you need to set this to 1. Note: set to 0 and ignore busbars and branches
TYPE:
|
min_busbar_coupler_per_station
|
The minimum number of busbar coupler per station to be relevant. Note: you need a substation column in the bus dataframe. Note: if you merged the busbars, you need to set this to 0.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ndarray
|
The relevant substations. |
Source code in packages/importer_pkg/src/toop_engine_importer/pandapower_import/pp_masks.py
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 | |
make_pp_masks
#
make_pp_masks(
network,
region="",
voltage_level=150,
min_power=100.0,
trafo_weight=1.2,
cross_border_weight=1.2,
min_branches_per_station=4,
foreign_id_column="equipment",
exclude_stations=None,
substation_column="substat",
min_busbars_per_substation=2,
min_busbar_coupler_per_station=1,
)
Create the network masks for the pandapower network.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
The pandapower network.
TYPE:
|
region
|
The region of the network.
TYPE:
|
voltage_level
|
The voltage level of the network to be considered.
TYPE:
|
min_power
|
The minimum power of generators, loads and static generators to be considered, for the n-1 analysis and reassignable.
TYPE:
|
trafo_weight
|
The weight of the transformers for the overload.
TYPE:
|
cross_border_weight
|
The weight of the cross border lines for the overload.
TYPE:
|
min_branches_per_station
|
The minimum number of busbars per station to be relevant.
TYPE:
|
foreign_id_column
|
The column containing the foreign id.
TYPE:
|
exclude_stations
|
The substations to exclude.
TYPE:
|
substation_column
|
The column containing the substation.
TYPE:
|
min_busbars_per_substation
|
The minimum number of busbars per substation to be relevant. Note: you need a substation column in the bus dataframe. Note: if you merged the busbars, you need to set this to 1.
TYPE:
|
min_busbar_coupler_per_station
|
The minimum number of busbar coupler per station to be relevant. Note: you need a substation column in the bus dataframe. Note: if you merged the busbars, you need to set this to 0.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NetworkMasks
|
The network masks. |
Source code in packages/importer_pkg/src/toop_engine_importer/pandapower_import/pp_masks.py
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 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 | |
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
#
Step 2: after creation of the asset topology.
1 2 3 4 5 6 | |
| PARAMETER | DESCRIPTION |
|---|---|
network
|
pandapower network Note: the network is modified in place
TYPE:
|
topology_model
|
asset topology model
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
topology_model
|
modified asset topology model
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/pandapower_import/preprocessing.py
validate_asset_topology
#
Validate the asset topology with the network.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
pandapower network
TYPE:
|
topology_model
|
asset topology model
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
None
|
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
if the number of connections in the network does not match the number of assets in the station |
Source code in packages/importer_pkg/src/toop_engine_importer/pandapower_import/preprocessing.py
toop_engine_importer.pandapower_import.asset_topology
#
Module contains functions to translate the pandapower model to the asset topology model.
File: asset_topology.py Author: Benjamin Petrick Created: 2024-10-01
get_busses_from_station
#
get_busses_from_station(
network,
station_name=None,
station_col="substat",
station_bus_index=None,
foreign_key="equipment",
)
Get the busses from a station_name.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
pandapower network object
TYPE:
|
station_name
|
Station id for which the busses should be retrieved.
TYPE:
|
station_col
|
Column name in the bus DataFrame that contains the station_name.
TYPE:
|
station_bus_index
|
List of bus indices for which the busses should be retrieved.
TYPE:
|
foreign_key
|
Defines the column name that is used as the foreign_key.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
station_busses
|
DataFrame with the busses of the station_name. Note: The DataFrame columns are the same as in the pydantic model. Note: the index of the DataFrame is the internal id of the bus. Note: the function does not check for types e.g. 'n' (Node) or 'b' (Busbar).
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError:
|
If station_name and station_bus_index are None. |
Source code in packages/importer_pkg/src/toop_engine_importer/pandapower_import/asset_topology.py
get_coupler_from_station
#
Get the coupler elements from a station_name.
This function expects couplers between all busbars of type 'b' (Busbar). Merge cross couplers before using this function.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
pandapower network object
TYPE:
|
station_buses
|
DataFrame with the busses of the station_name. Note: The DataFrame columns are the same as in the pydantic model. Note: The index of the DataFrame is the internal id of the bus. Note: The function expects all nodes of the station, inlc. type 'n' (Node) and 'b' (Busbar).
TYPE:
|
foreign_key
|
Defines the column name that is used as the foreign_key.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
station_switches_CB
|
DataFrame with the coupler elements of the station_name. Note: The DataFrame columns are the same as in the pydantic model. Note: the index of the DataFrame is the internal id of the bus.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError:
|
If no busbar coupler is found between the busbars. If the station_busses are not of type 'b' (Busbar). If the coupler elements are not of type 'CB' (Circuit Breaker). |
Source code in packages/importer_pkg/src/toop_engine_importer/pandapower_import/asset_topology.py
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 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | |
get_branches_from_station
#
get_branches_from_station(
network,
station_buses,
branch_types=None,
bus_types=None,
foreign_key="equipment",
)
Get the branches from a station_buses index.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
pandapower network object
TYPE:
|
station_buses
|
DataFrame with one or multiple busses to get the bus id from. Note: The DataFrame columns are the same as in the pydantic model. Note: the index of the DataFrame is the internal id of the bus.
TYPE:
|
branch_types
|
List of branch types that should be retrieved. It needs to be an attribute of the pandapower network.
TYPE:
|
bus_types
|
List of the tuple(name_of_column, pydantic_type, postfix_gridmodel_id). This list is used to identify the bus columns in the branch types.
TYPE:
|
foreign_key
|
Defines the column name that is used as the foreign_key/unique identifier.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
station_branches
|
DataFrame with the branches of the station_name. Note: The DataFrame columns are the same as in the pydantic model. Note: the index of the DataFrame is the internal id of the bus.
TYPE:
|
switching_matrix
|
DataFrame with the switching matrix of the station_name. Note: The DataFrame columns are the same as in the pydantic model. Note: the index of the DataFrame is the internal id of the bus.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError:
|
If the branch type is not found in the pp.pandapowerNet. Note: trying to call an attribute with an empty DataFrame will not raise an error. e.g. pp.networks.case4gs()["impedance"].empty == True will not raise an error. But calling an "not_existing_attribute" will raise an error. If any bus name from bus_from_to_names is not found in the branch type. |
Source code in packages/importer_pkg/src/toop_engine_importer/pandapower_import/asset_topology.py
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 | |
get_parameter_from_station
#
get_parameter_from_station(
network,
station_name=None,
station_col="substat",
station_bus_index=None,
parameter="vn_kv",
)
Get the voltage level from a station_name.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
pandapower network object
TYPE:
|
station_name
|
Station id for which the busses should be retrieved.
TYPE:
|
station_col
|
Column name in the bus DataFrame that contains the station_name.
TYPE:
|
station_bus_index
|
List of bus indices for which the busses should be retrieved.
TYPE:
|
parameter
|
Parameter that should be retrieved.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
parameter
|
Parameter value.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError:
|
If station_name and station_bus_index are None. If the parameter is not found in the bus_df. If the voltage level is not unique for the station_name. |
Source code in packages/importer_pkg/src/toop_engine_importer/pandapower_import/asset_topology.py
get_station_from_id
#
Get the busses from a station_id.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
pandapower network object
TYPE:
|
station_id_list
|
List of station ids for which the stations should be retrieved.
TYPE:
|
foreign_key
|
Defines the column name that is used as the foreign_key/unique identifier.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
station
|
Station object.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/pandapower_import/asset_topology.py
get_list_of_stations_ids
#
Get the list of stations from the network.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
pandapower network object
TYPE:
|
station_list
|
List of station ids for which the stations should be retrieved. Station ids are a list -> a list of busbars associated with the station.
TYPE:
|
foreign_key
|
Defines the column name that is used as the foreign_key/unique identifier.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
station_list
|
List of station objects.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/pandapower_import/asset_topology.py
get_asset_topology_from_network
#
get_asset_topology_from_network(
network,
topology_id,
grid_model_file,
station_id_list,
foreign_key="equipment",
)
Get the asset topology from the network.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
pandapower network object
TYPE:
|
topology_id
|
Id of the topology.
TYPE:
|
grid_model_file
|
Name of the grid model file.
TYPE:
|
station_id_list
|
List of station ids for which the stations should be retrieved. Station ids are a list -> a list of busbars associated with the station.
TYPE:
|
foreign_key
|
Defines the column name that is used as the foreign_key/unique identifier.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
asset_topology
|
Topology class of the network.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/pandapower_import/asset_topology.py
get_station_bus_df
#
Get the bus df by either station_name or station_bus_index.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
pandapower network object
TYPE:
|
station_name
|
Station id for which the busses should be retrieved.
TYPE:
|
station_col
|
Column name in the bus DataFrame that contains the station_name. Note: Pandapower does not have a station column, so this is a custom column.
TYPE:
|
station_bus_index
|
List of bus indices for which the busses should be retrieved.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bus_df
|
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError:
|
If station_name and station_bus_index are None. |
Source code in packages/importer_pkg/src/toop_engine_importer/pandapower_import/asset_topology.py
get_asset_connection_path_to_busbars
#
get_asset_connection_path_to_busbars(
network,
asset_bus,
station_buses,
save_col_name="equipment",
)
Get the asset connection path to busbars.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
pandapower network object
TYPE:
|
asset_bus
|
Asset bus id for which the connection path should be retrieved.
TYPE:
|
station_buses
|
DataFrame with the busses of the station_name. Note: The DataFrame columns are the same as in the pydantic model.
TYPE:
|
save_col_name
|
Column name that is used as the foreign_key/unique identifier.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
asset_connection
|
AssetConnectionPath object.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/pandapower_import/asset_topology.py
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 | |
get_branch_from_bus_ids
#
Get the branches based on branch_type and bus_ids.
| PARAMETER | DESCRIPTION |
|---|---|
branch_df
|
DataFrame with one or multiple busses to get the bus id from. Note: The DataFrame columns are the same as in the pydantic model. Note: the index of the DataFrame is the internal id of the bus.
TYPE:
|
branch_type
|
Branch type that should be retrieved. It needs to be an attribute of the pandapower network.
TYPE:
|
bus_ids
|
List of bus indices for which the busses should be retrieved.
TYPE:
|
bus_types
|
List of the tuple(name_of_column, pydantic_type, postfix_gridmodel_id). This list is used to identify the bus columns in the branch types.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
branch_df_all_busses
|
DataFrame with the branches of the station_name. Note: The DataFrame columns NOT yet the same as in the pydantic model. Note: the index of the DataFrame is the internal id of the bus.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError:
|
If branch_type is not found in the pp.pandapowerNet. |
Source code in packages/importer_pkg/src/toop_engine_importer/pandapower_import/asset_topology.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_file",
"convert_low_impedance_lines",
"create_default_network_masks",
"get_branches_df_with_element_name",
"get_list_of_stations",
"get_topology",
"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, dangling_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.
NetworkMasks
dataclass
#
NetworkMasks(
relevant_subs,
line_for_nminus1,
line_for_reward,
line_overload_weight,
line_disconnectable,
line_blacklisted,
line_tso_border,
trafo_for_nminus1,
trafo_for_reward,
trafo_overload_weight,
trafo_disconnectable,
trafo_blacklisted,
trafo_n0_n1_max_diff_factor,
trafo_dso_border,
trafo_pst_controllable,
tie_line_for_reward,
tie_line_for_nminus1,
tie_line_overload_weight,
tie_line_disconnectable,
tie_line_tso_border,
dangling_line_for_nminus1,
generator_for_nminus1,
load_for_nminus1,
switch_for_nminus1,
switch_for_reward,
busbar_for_nminus1,
)
Class to hold the network masks.
See class PowsyblBackend(BackendInterface) in DCLoadflowsolver for more information.
relevant_subs
instance-attribute
#
relevant_subs.npy (a boolean mask of relevant nodes).
line_for_nminus1
instance-attribute
#
line_for_nminus1.npy (a boolean mask of lines that are relevant for n-1).
line_for_reward
instance-attribute
#
line_for_reward.npy (a boolean mask of lines that are relevant for the reward).
line_overload_weight
instance-attribute
#
line_overload_weight.npy (a float mask of weights for the overload).
line_disconnectable
instance-attribute
#
line_disconnectable.npy (a boolean mask of lines that can be disconnected)
line_blacklisted
instance-attribute
#
line_blacklisted.npy (a boolean mask of lines that are blacklisted) Currently only used during importing and not part of the PowsyblBackend
line_tso_border
instance-attribute
#
line_tso_border.npy (a boolean mask of lines that are leading to TSOs outside the reward area) Currently only used during importing and not part of the PowsyblBackend
trafo_for_nminus1
instance-attribute
#
trafo_for_nminus1.npy (a boolean mask of transformers that are relevant for n-1).
trafo_for_reward
instance-attribute
#
trafo_for_reward.npy (a boolean mask of transformers that are relevant for the reward).
trafo_overload_weight
instance-attribute
#
trafo_overload_weight.npy (a float mask of weights for the overload).
trafo_disconnectable
instance-attribute
#
trafo_disconnectable.npy (a boolean mask of transformers that can be disconnected)
trafo_blacklisted
instance-attribute
#
trafo_blacklisted.npy (a boolean mask of transformers that are blacklisted) Currently only used during importing and not part of the PowsyblBackend
trafo_n0_n1_max_diff_factor
instance-attribute
#
trafo_n0_n1_max_diff_factor.npy (if a trafo shall be limited in its N-0 to N-1 difference and by how much)
trafo_dso_border
instance-attribute
#
trafo_dso_border.npy (a boolean mask of transformers that border the DSO control area) Currently only used during importing and not part of the PowsyblBackend
trafo_pst_controllable
instance-attribute
#
Trafos which are a PST and can be controlled
tie_line_for_reward
instance-attribute
#
tie_line_for_reward.npy (a boolean mask of tie lines that are relevant for the reward).
tie_line_for_nminus1
instance-attribute
#
tie_line_for_nminus1.npy (a boolean mask of tie lines that are relevant for n-1).
tie_line_overload_weight
instance-attribute
#
tie_line_overload_weight.npy (a float mask of weights for the overload).
tie_line_disconnectable
instance-attribute
#
tie_line_disconnectable.npy (a boolean mask of tie lines that can be disconnected)
tie_line_tso_border
instance-attribute
#
tie_line_tso_border.npy (a boolean mask of tielines that are leading to TSOs outside the reward area) Currently only used during importing and not part of the PowsyblBackend
dangling_line_for_nminus1
instance-attribute
#
tie_line_disconnectable.npy (a boolean mask of tie lines that are relevant for n-1).
generator_for_nminus1
instance-attribute
#
generator_for_nminus1.npy (a boolean mask of generators that are relevant for n-1).
load_for_nminus1
instance-attribute
#
generator_for_nminus1.npy (a boolean mask of loads that are relevant for n-1).
switch_for_nminus1
instance-attribute
#
switches_nminus1.npy (a boolean mask of switches that are relevant for n-1).
switch_for_reward
instance-attribute
#
switches_reward.npy (a boolean mask of switches that are relevant for the reward).
busbar_for_nminus1
instance-attribute
#
busbar_for_nminus1.npy (a boolean mask of busbars/busbar_sections that are relevant for n-1).
get_list_of_stations
#
get_list_of_stations(
network,
buses_with_substation_and_voltage,
switches,
dangling_lines,
element_names,
)
Get the list of stations from the relevant buses.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
pypowsybl network object
TYPE:
|
buses_with_substation_and_voltage
|
DataFrame with the relevant buses, substation id and voltage level
TYPE:
|
switches
|
DataFrame with all the switches in the network. Includes the column "name"
TYPE:
|
dangling_lines
|
DataFrame with all the dangling lines in the network. Includes the column "tie_line_id"
TYPE:
|
element_names
|
Series with the names of all injections and branches in the network and their ids as index
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
station_list
|
List of all formatted stations of the relevant buses in the network
TYPE:
|
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/powsybl/powsybl_asset_topo.py
get_topology
#
Get the pydantic topology model from the network.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
pypowsybl network object
TYPE:
|
relevant_stations
|
The relevant stations to be included in the resulting topology. Either as a boolean mask over all buses in network.get_buses or as a list of bus ids in network.get_buses()
TYPE:
|
topology_id
|
Id of the topology to set in the asset topology
TYPE:
|
grid_model_file
|
Path to the grid model file to set in the asset topology
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
topology
|
Topology object, including all relevant stations
TYPE:
|
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/powsybl/powsybl_asset_topo.py
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
create_default_network_masks
#
Create a default NetworkMasks object with all masks set to False.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
The powsybl network to create the masks for.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
network_masks
|
The default NetworkMasks object.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/powsybl_masks.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:
|
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
convert_file
#
convert_file(
importer_parameters,
status_update_fn=empty_status_update_fn,
processed_gridfile_fs=None,
unprocessed_gridfile_fs=None,
)
Convert the UCTE file to a format that can be used by the RL agent.
Saves data and network to the output folder.
| PARAMETER | DESCRIPTION |
|---|---|
importer_parameters
|
Parameters that are required to import the data from a UCTE 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 and an optional message 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:
|
| RETURNS | DESCRIPTION |
|---|---|
UcteImportResult
|
The result of the import process. |
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/preprocessing.py
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 | |
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
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:
|
| RETURNS | DESCRIPTION |
|---|---|
Nminus1Definition
|
The created N-1 definition. |
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/preprocessing.py
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 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 | |
convert_file
#
convert_file(
importer_parameters,
status_update_fn=empty_status_update_fn,
processed_gridfile_fs=None,
unprocessed_gridfile_fs=None,
)
Convert the UCTE file to a format that can be used by the RL agent.
Saves data and network to the output folder.
| PARAMETER | DESCRIPTION |
|---|---|
importer_parameters
|
Parameters that are required to import the data from a UCTE 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 and an optional message 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:
|
| RETURNS | DESCRIPTION |
|---|---|
UcteImportResult
|
The result of the import process. |
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/preprocessing.py
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 | |
get_network_masks
#
Create network masks and save them.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
The network to create the asset topology for
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_topology_model
#
Get the initial asset topology.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
The network to create the asset topology for
TYPE:
|
network_masks
|
The network masks giving info which elements are relevant
TYPE:
|
importer_parameters
|
import parameters that include the datafolder
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
None
|
|
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_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
Network Graph#
toop_engine_importer.network_graph
#
Functions to get an AssetTopology from a Node-Breaker grid model.
BRANCH_TYPES
module-attribute
#
BRANCH_TYPES = Union[
BRANCH_TYPES_POWSYBL, BRANCH_TYPES_PANDAPOWER
]
BRANCH_TYPES_PANDAPOWER
module-attribute
#
BRANCH_TYPES_POWSYBL
module-attribute
#
BRANCH_TYPES_POWSYBL = Literal[
"LINE",
"TWO_WINDING_TRANSFORMER",
"PHASE_SHIFTER",
"TWO_WINDING_TRANSFORMER_WITH_TAP_CHANGER",
"THREE_WINDINGS_TRANSFORMER",
]
SWITCH_TYPES
module-attribute
#
__all__
module-attribute
#
__all__ = [
"BRANCH_TYPES",
"BRANCH_TYPES_PANDAPOWER",
"BRANCH_TYPES_POWSYBL",
"NODE_TYPES",
"SWITCH_TYPES",
"AssetSchema",
"BranchSchema",
"BusbarConnectionInfo",
"EdgeConnectionInfo",
"HelperBranchSchema",
"NetworkGraphData",
"NodeAssetSchema",
"NodeSchema",
"SubstationInformation",
"SwitchSchema",
"WeightValues",
"add_graph_specific_data",
"add_node_tuple_column",
"generate_graph",
"get_asset_bay",
"get_busbar_df",
"get_coupler_df",
"get_empty_dataframe_from_df_model",
"get_network_graph",
"get_network_graph_data",
"get_node_breaker_topology_graph",
"get_station_connection_tables",
"get_switchable_asset",
"node_breaker_topology_to_graph_data",
"remove_helper_branches",
"run_default_filter_strategy",
"set_all_busbar_coupling_switches",
"set_all_weights",
"set_asset_bay_edge_attr",
"set_bay_weights",
"set_connectable_busbars",
"set_empty_bay_weights",
"set_switch_busbar_connection_info",
"set_zero_impedance_connected",
"shortest_paths_to_target_ids",
]
AssetSchema
#
Bases: DataFrameModel
An AssetSchema is a DataFrameModel that represents an asset in a network graph.
This is the parent class for SwitchSchema and BranchSchema and should not be used directly.
foreign_id
class-attribute
instance-attribute
#
The unique ID of the node in the foreign model. This id is optional is only dragged along. Can for instance used for the DGS model.
int_id
class-attribute
instance-attribute
#
The int_id of the asset. This is the index of the dataframe and is expected to be unique for the asset DataFrame and of type int.
in_service
class-attribute
instance-attribute
#
The state of the asset. True: The asset is in service. Normally expected to be True or not included in the network graph.
BranchSchema
#
Bases: AssetSchema
A BranchSchema is an AssetSchema that represents a branch in a network graph.
A branch is a connection between two nodes in a network graph. It can be for instance a LINE, TWO_WINDING_TRANSFORMER, but not a THREE_WINDING_TRANSFORMER. A SwitchSchema is a special type of BranchSchema that represents a switch in a network graph.
foreign_id
class-attribute
instance-attribute
#
The unique ID of the node in the foreign model. This id is optional is only dragged along. Can for instance used for the DGS model.
int_id
class-attribute
instance-attribute
#
The int_id of the asset. This is the index of the dataframe and is expected to be unique for the asset DataFrame and of type int.
in_service
class-attribute
instance-attribute
#
The state of the asset. True: The asset is in service. Normally expected to be True or not included in the network graph.
asset_type
class-attribute
instance-attribute
#
asset_type = Field(
isin=[
branch_type
for branch_type_model in (__args__)
for branch_type in (__args__)
]
)
The type of the branch.
node_tuple
class-attribute
instance-attribute
#
The node tuple of the branch. The node tuple is a tuple of two nodes int_id that are connected by the branch.
BusbarConnectionInfo
#
Bases: BaseModel
BusbarConnectionInfo is a data class that contains information about the connections of a busbar.
The given connection information is always related to a specific busbar. A connection that is only possible when including another busbar in it's path is never included.
model_config
class-attribute
instance-attribute
#
The configuration for the model. The extra parameter is set to forbid, to raise an error if an unexpected field is passed to the model.
connectable_assets_node_ids
class-attribute
instance-attribute
#
The node_ids of the connectable assets. Connectable is referring to the assets that can be connected and disconnected with a circuit breaker switch. A connectable asset can be a single node or a tuple of two nodes, if the asset is a branch.
connectable_assets
class-attribute
instance-attribute
#
The connectable assets grid_model_id. Connectable is referring to the assets that can be connected and disconnected
connectable_busbars_node_ids
class-attribute
instance-attribute
#
The node_ids of the connectable busbars. Interconnectable is referring to the busbars that can be connected and disconnected with a circuit breaker switch.
connectable_busbars
class-attribute
instance-attribute
#
The connectable busbars grid_model_id. Interconnectable is referring to the busbars that can be connected and disconnected with a circuit breaker switch.
zero_impedance_connected_assets
class-attribute
instance-attribute
#
The asset grid_model_ids, connected by zero impedance. Zero impedance refers to assets that are currently connected to the busbar with a path where all switches are closed. Only the asset bays are considered.
zero_impedance_connected_assets_node_ids
class-attribute
instance-attribute
#
The asset node_ids, connected by zero impedance. Zero impedance refers to assets that are currently connected to the busbar with a path where all switches are closed. Only the asset bays are considered.
zero_impedance_connected_busbars
class-attribute
instance-attribute
#
The busbars grid_model_ids, connected by zero impedance. Zero impedance refers to busbars that are currently connected to the busbar with a path where all switches are closed. Only busbar/cross coupler are considered that directly connect the two busbars.
zero_impedance_connected_busbars_node_ids
class-attribute
instance-attribute
#
The busbars node_ids, connected by zero impedance Zero impedance refers to busbars that are currently connected to the busbar with a path where all switches are closed. Only busbar/cross coupler are considered that directly connect the two busbars.
node_assets
class-attribute
instance-attribute
#
The node assets grid_model_id. Node assets are assets that are connected to a node in the network graph. For instance, a transformer or line at the border of the network graph or a generator or load.
node_assets_ids
class-attribute
instance-attribute
#
The node assets node_id. Node assets are assets that are connected to a node in the network graph. For instance, a transformer or line at the border of the network graph or a generator or load. The node asset is for instance the index of the node_assets DataFrame or the node_tuple of the branch.
EdgeConnectionInfo
#
Bases: BaseModel
EdgeConnectionInfo is a data class that contains information about an edge in relation to busbars or bays.
Use this class to store information about the connection of an edge.
model_config
class-attribute
instance-attribute
#
The configuration for the model. The extra parameter is set to forbid, to raise an error if an unexpected field is passed to the model.
direct_busbar_grid_model_id
class-attribute
instance-attribute
#
The direct_busbar_grid_model_id is set only if the edge is directly connected to a busbar. Leave blank if there is any edge in between the busbar and the edge. Fill with the grid_model_id of the busbar if the edge is directly connected to the busbar.
bay_id
class-attribute
instance-attribute
#
The bay_id is set only if the edge is part of an asset/coupler bay. Leave blank if the edge is not part of an asset/coupler bay. Fill with the grid_model_id of the asset/coupler if the edge is part of an asset/coupler bay.
coupler_type
class-attribute
instance-attribute
#
The coupler_type is set only if the edge is part of a busbar coupler. Leave blank if the edge is not part of a busbar coupler. Fill with the type of the busbar coupler if the edge is part of a busbar coupler.
coupler_grid_model_id_list
class-attribute
instance-attribute
#
The coupler_grid_model_id_list is set only if the edge is part of a busbar coupler. Leave blank if the edge is not part of a busbar coupler. Fill with the grid_model_id of the busbar coupler if the edge is part of a busbar coupler. Reason for tuples: one coupler can connect only two busbars at once. Reason for list: one coupler can have multiple from and to busbars. Example: [("busbar1", "busbar2"), ("busbar1", "busbar3"), ("busbar2", "busbar3")]
from_busbar_grid_model_ids
class-attribute
instance-attribute
#
The from_busbar_grid_model_ids is set only if the edge is part of a busbar coupler. Leave blank if the edge is not part of a busbar coupler. Fill with the grid_model_id of the busbar if the edge is part of a busbar coupler. Reason for list: one coupler can have multiple from busbars. Example: ["busbar1", "busbar2", "busbar3"]
to_busbar_grid_model_ids
class-attribute
instance-attribute
#
The to_busbar_grid_model_ids is set only if the edge is part of a busbar coupler. Leave blank if the edge is not part of a busbar coupler. Fill with the grid_model_id of the busbar if the edge is part of a busbar coupler. Reason for list: one coupler can have multiple to busbars. Example: ["busbar1", "busbar2", "busbar3"]
from_coupler_ids
class-attribute
instance-attribute
#
The from_coupler_ids is set only if the edge is part of a busbar coupler. Leave blank if the edge is not part of a busbar coupler. Fill with the grid_model_id all edges that are part of the busbar coupler. Enables the correct identification an coupler bay.
to_coupler_ids
class-attribute
instance-attribute
#
The to_coupler_ids is set only if the edge is part of a busbar coupler. Leave blank if the edge is not part of a busbar coupler. Fill with the grid_model_id all edges that are part of the busbar coupler. Enables the correct identification an coupler bay.
HelperBranchSchema
#
Bases: DataFrameModel
A HelperBranchSchema is a BranchSchema that represents a helper branch in a network graph.
Helper branches no real branches, but are used to connect nodes in the network graph. These branches can occur for instance when there is an other abstraction level in the network graph e.g. a node for plotting svg. Note: The HelperBranch may contain all branches and switches in addition to the helper branches.
grid_model_id
class-attribute
instance-attribute
#
A helper branch does not have a grid_model_id. It is set to an empty string, creating all edges with a grid_model_id.
NetworkGraphData
#
Bases: BaseModel
A NetworkGraphData contains all data to create a nx.Graph from a grid model (e.g. from CGMES).
It contains nodes, switches, branches and node_assets. This network is used to find substations and categorize the elements of the substation into known categories. It can be used to create an AssetTopology model and an action_set for the substation.
branches
class-attribute
instance-attribute
#
branches = Field(
default_factory=lambda: get_empty_dataframe_from_df_model(
df_model=BranchSchema
)
)
A DataFrame containing the branches.
node_assets
class-attribute
instance-attribute
#
node_assets = Field(
default_factory=lambda: get_empty_dataframe_from_df_model(
df_model=NodeAssetSchema
)
)
A DataFrame containing the node assets
helper_branches
class-attribute
instance-attribute
#
helper_branches = Field(
default_factory=lambda: get_empty_dataframe_from_df_model(
df_model=HelperBranchSchema
)
)
A DataFrame containing the helper branches.
validate_network_graph_data
#
Validate the NetworkGraphData model.
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/data_classes.py
NodeAssetSchema
#
Bases: AssetSchema
A NodeAssetSchema is an AssetSchema that represents an asset in a network graph.
A NodeAssetSchema is an asset that is located at a node in the network graph. It can be for instance a transformer or line at the border of the network graph or a generator or load.
foreign_id
class-attribute
instance-attribute
#
The unique ID of the node in the foreign model. This id is optional is only dragged along. Can for instance used for the DGS model.
int_id
class-attribute
instance-attribute
#
The int_id of the asset. This is the index of the dataframe and is expected to be unique for the asset DataFrame and of type int.
in_service
class-attribute
instance-attribute
#
The state of the asset. True: The asset is in service. Normally expected to be True or not included in the network graph.
NodeSchema
#
Bases: DataFrameModel
A NodeSchema is a DataFrameModel that represents a node in a network graph.
int_id
class-attribute
instance-attribute
#
The int_id of the node, used to connect Assets by their node_id. This needs to be a unique int_id for the nodes DataFrame.
foreign_id
class-attribute
instance-attribute
#
The unique ID of the node in the foreign model. This id is optional is only dragged along. Can for instance used for the DGS model.
node_type
class-attribute
instance-attribute
#
The type of the node NODE_TYPES.
voltage_level
class-attribute
instance-attribute
#
The voltage level of the node.
bus_id
class-attribute
instance-attribute
#
The bus_id of the node. The bus_id is the refers to the id in the bus-branch topology.
system_operator
instance-attribute
#
The system operator of the node. Can be used to categorize the node. For instance to identify border lines.
substation_id
class-attribute
instance-attribute
#
The unique ID of the substation. This id is optional and can be used to identify the substation the node is part of. If set as an empty string, the node is not part of a relevant substation. If set as None, the node is part of an unknown substation.
helper_node
class-attribute
instance-attribute
#
A helper node is a node that is used to connect other nodes in the network graph. Helper nodes are not part of the network and do not contain any information.
in_service
class-attribute
instance-attribute
#
The state of the node. True: The node is in service. Normally expected to be True or not included in the network graph.
SubstationInformation
#
Bases: BaseModel
SubstationInformation contains information about a powsybl substation.
region
instance-attribute
#
The region of the substation. from net.get_substations(attributes=["country"])
voltage_level_id
instance-attribute
#
The voltage level of the substation. from net.get_voltage_levels()
nominal_v
instance-attribute
#
The nominal voltage of the substation. from net.get_voltage_levels()
SwitchSchema
#
Bases: AssetSchema
A SwitchSchema is a BranchSchema that represents a switch in a network graph.
foreign_id
class-attribute
instance-attribute
#
The unique ID of the node in the foreign model. This id is optional is only dragged along. Can for instance used for the DGS model.
int_id
class-attribute
instance-attribute
#
The int_id of the asset. This is the index of the dataframe and is expected to be unique for the asset DataFrame and of type int.
in_service
class-attribute
instance-attribute
#
The state of the asset. True: The asset is in service. Normally expected to be True or not included in the network graph.
asset_type
class-attribute
instance-attribute
#
The type of the switch SWITCH_TYPES.
open
instance-attribute
#
The state of the switch. True: The switch is open. False: The switch is closed.
node_tuple
class-attribute
instance-attribute
#
The node tuple of the branch. The node tuple is a tuple of two nodes int_id that are connected by the branch.
WeightValues
#
Bases: Enum
WeightValues is an Enum that contains the weight values for the edges in the NetworkGraphData model.
The weight values are used to map assets to categories in the network graph. high: A values used to cut off shortest paths. half: A value confidently ignore the steps, but still use a weight, where step or a few max_step are set. low: A value to ignore the edge in the shortest path. step: A value to count the steps in the shortest path. max_step: A value to set the cutoff in the shortest path. over_step: A value to set the cutoff in the shortest path. Used if this edge should not be part in the max_step cutoff, but may be part of a longer path max_coupler: A max value, counting switches in a busbar coupler path.
get_empty_dataframe_from_df_model
#
Get an empty DataFrame from a DataFrameModel.
This functions creates an empty DataFrame with the columns and correct dtype of the DataFrameModel. It does not initialize Optional columns.
| PARAMETER | DESCRIPTION |
|---|---|
df_model
|
The DataFrameModel to get an empty DataFrame from.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
An empty DataFrame with the columns and correct dtype of the DataFrameModel. |
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/data_classes.py
run_default_filter_strategy
#
Run the default strategy on the nx.Graph created by the NetworkGraphData model.
This is the main function for the default strategy. The default strategy fills - BusbarConnectionInfo of all busbars in the network graph. - EdgeConnectionInfo of all edges in the network graph.
| PARAMETER | DESCRIPTION |
|---|---|
graph
|
The network graph. Note: The graph is modified in place.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/default_filter_strategy.py
set_all_busbar_coupling_switches
#
Set all connection paths between busbars, be it BREAKER or DISCONNECTOR.
- Get all BREAKER, which have no bay_id (e.g. excludes Line/Load breaker)
- Loop over BREAKER one by one 2.1 Loop: Get all shortest paths from BREAKER to all BUSBARs (respect weights) 2.2 Set coupler sides 2.3 After loop: Set bay_id 2.4 Set coupler type
- Get all DISCONNECTOR (to find left over connections like B -> DS -> B)
- Repeat step 2. for DS
| PARAMETER | DESCRIPTION |
|---|---|
graph
|
The network graph.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/filter_strategy/switches.py
set_asset_bay_edge_attr
#
Set the bay information in the nx.Graph.
This function updates the initial edge weights and id related to the asset bay. Sets the bay_id, bay_weight, and coupler_weight for each edge in the shortest path to a busbar.
| PARAMETER | DESCRIPTION |
|---|---|
graph
|
The network graph. Note: The graph is modified in place.
TYPE:
|
asset_bay_update_dict
|
A dictionary containing the shortest path to a busbar for each busbar. key: bay_id (a str grid_model_id) value: dictionary from shortest_paths_to_target_ids key: busbar_id and value: list of node_ids from the asset_node the key (a busbars_helper_node)
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/filter_strategy/helper_functions.py
set_bay_weights
#
Set the bay weights in the NetworkGraphData model for asset_nodes and branches.
The bay weight is used to categorize paths in the network and assign a bay to an asset. Enables DGS export and switching into topology using a branch_id, by linking the branch_id to a switch.
| PARAMETER | DESCRIPTION |
|---|---|
graph
|
The network graph. Note: The graph is modified in place.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/default_filter_strategy.py
set_connectable_busbars
#
Set the connectable busbars in BusbarConnectionInfo for each node in connectable_busbars.
| PARAMETER | DESCRIPTION |
|---|---|
graph
|
The network graph. Note: The graph is modified in place.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/default_filter_strategy.py
set_empty_bay_weights
#
Set a bay weight for empty bays.
Due to data quality issues, some bays may be empty. Finding and categorizing couplers depends on all bays weights being set. This function sets a bay weight for empty bays.
| PARAMETER | DESCRIPTION |
|---|---|
graph
|
The network graph. Note: The graph is modified in place.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/filter_strategy/empty_bay.py
set_switch_busbar_connection_info
#
Set the switch busbar connection information in the network graph model.
why:
- cut off the shortest path at a busbar
- direct_busbar_grid_model_id in combination with bay_id for switching table
uses:
- graph.nodes[node_id]["node_type"] == "busbar"
sets:
- set the direct_busbar_grid_model_id in the switches
- set the busbar_weight to step for all edges around a busbar.
This enables to cut off a shortest path at a busbar.
| PARAMETER | DESCRIPTION |
|---|---|
graph
|
The network graph. Note: The graph is modified in place.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/default_filter_strategy.py
set_zero_impedance_connected
#
Set zero_impedance_connected in the graph model.
A shortest path to the connected assets respecting the switch open state is calculated.
| PARAMETER | DESCRIPTION |
|---|---|
graph
|
The network graph. Note: The graph is modified
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/default_filter_strategy.py
shortest_paths_to_target_ids
#
shortest_paths_to_target_ids(
graph,
target_node_ids,
start_node_id,
weight="station_weight",
cutoff=int(high.value),
)
Find the shortest paths from one busbar to a list of busbars in the NetworkX graph.
| PARAMETER | DESCRIPTION |
|---|---|
graph
|
The NetworkX graph.
TYPE:
|
target_node_ids
|
The list of busbar node ids, to which the shortest path is calculated.
TYPE:
|
start_node_id
|
The node id from which the shortest path is calculated.
TYPE:
|
weight
|
string or Callable
If this is a string, then edge weights will be accessed via the
edge attribute with this key (that is, the weight of the edge
joining If this is a function, the weight of an edge is the value returned by the function. The function must accept exactly three positional arguments: the two endpoints of an edge and the dictionary of edge attributes for that edge. The function must return a number or None to indicate a hidden edge.
TYPE:
|
cutoff
|
The cutoff value for the shortest path.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
shortest_path_dict dict[int, list[int]]
|
The shortest path to the busbar. key: target_node_ids value: list of node_ids from the start_node_id to the key (the target_node_id) Note: not all target_node_ids are in the dict, only the ones that are reachable from the start_node_id. Reachable means that the path is shorter than the cutoff value. |
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/network_graph.py
set_all_weights
#
Set all weights for the edges DataFrame in the NetworkGraphData model.
All weights are set in place in the DataFrames. This function sets the following weights for the edges: - station_weight - bay_weight - trafo_weight - coupler_weight - busbar_weight - switch_open_weight
| PARAMETER | DESCRIPTION |
|---|---|
branches_df
|
The BranchSchema DataFrame from the NetworkGraphData model. Note: The DataFrame is modified in place.
TYPE:
|
switches_df
|
The SwitchSchema DataFrame from the NetworkGraphData model. Note: The DataFrame is modified in place.
TYPE:
|
helper_branches_df
|
The HelperBranchSchema DataFrame from the NetworkGraphData model. Note: The DataFrame is modified in place.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/filter_weights.py
get_asset_bay
#
Get the asset bay for a asset_grid_model_id.
| PARAMETER | DESCRIPTION |
|---|---|
switches_df
|
Dataframe with all switches of the substation. expects NetworkGraphData.switches
TYPE:
|
asset_grid_model_id
|
Asset grid model id for which the asset bays should be retrieved.
TYPE:
|
busbar_df
|
Dataframe with all busbars of the substation. expects get_busbar_df
TYPE:
|
edge_connection_info
|
Dictionary with all edge connections of the substation. expects network_graph.get_edge_connection_info()
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
asset_bay
|
AssetBay of the specified asset. or None if no AssetBay is found.
TYPE:
|
logs
|
List of logs that are created during the process.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the switches found not match the number of switches in the asset bay. |
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/graph_to_asset_topo.py
get_busbar_df
#
Get the busbar from the NetworkGraphData nodes dataframe.
| PARAMETER | DESCRIPTION |
|---|---|
nodes_df
|
Dataframe with all nodes of the substation or whole network. expects NetworkGraphData.nodes
TYPE:
|
substation_id
|
Substation id for which the busbar should be retrieved.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
busbar_df
|
busbar_df of the specified substation.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/graph_to_asset_topo.py
get_coupler_df
#
Get the busbar couplers from the NetworkGraphData edges dataframe.
| PARAMETER | DESCRIPTION |
|---|---|
switches_df
|
Dataframe with all switches of the substation. expects NetworkGraphData.switches
TYPE:
|
busbar_df
|
Dataframe with all busbars of the substation. expects get_busbar_df
TYPE:
|
substation_id
|
Substation id for which the busbar couplers should be retrieved. looks for the "substation_id", "coupler_type" and "asset_type" column in the edges dataframe.
TYPE:
|
graph
|
The graph from the NetworkGraphData of the substation or whole network. Note: the default strategy functions must been executed before calling this function.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
coupler_df
|
coupler_df of the specified substation.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/graph_to_asset_topo.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | |
get_station_connection_tables
#
Get the switching table physically from the NetworkGraphData busbar_connection_info dict.
| PARAMETER | DESCRIPTION |
|---|---|
busbar_connection_info
|
Dictionary with all busbar connections of the substation. expects NetworkGraphData.busbar_connection_info
TYPE:
|
busbar_df
|
Dataframe with all busbars of the substation. expects get_busbar_df
TYPE:
|
switchable_assets_df
|
Dataframe with all switchable assets of the substation. expects get_switchable_asset
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
asset_connectivity
|
asset_connectivity of the specified substation. Holds the all possible layouts of the switching table, shape (n_bus n_asset). An entry is true if it is possible to connected an asset to the busbar.
TYPE:
|
asset_switching_table
|
Holds the switching of each asset to each busbar, shape (n_bus n_asset). An entry is true if the asset is connected to the busbar.
TYPE:
|
busbar_connectivity
|
Holds the all possible layouts of the switching table, shape (n_bus n_bus). An entry is true if it is possible to connected an busbar to the busbar.
TYPE:
|
busbar_switching_table
|
Holds the switching of each busbar to each busbar, shape (n_bus n_bus). An entry is true if a busbar is connected to the busbar.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/graph_to_asset_topo.py
get_switchable_asset
#
Get the switchable assets from the NetworkGraphData busbar_connection_info dict.
| PARAMETER | DESCRIPTION |
|---|---|
busbar_connection_info
|
Dictionary with all busbar connections of the substation. expects network_graph.get_busbar_connection_info()
TYPE:
|
node_assets_df
|
Dataframe with all nodes of the substation. expects get_node_assets_df
TYPE:
|
branches_df
|
Dataframe with all branches of the substation. expects get_branches_df
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
connected_asset_df
|
connected_asset_df of the specified substation.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/graph_to_asset_topo.py
generate_graph
#
Generate a NetworkX graph from the NetworkGraphData model.
| PARAMETER | DESCRIPTION |
|---|---|
network_graph_data
|
The NetworkGraphData model. Needs to be filled e.g. using pandapower_network_to_graph or powsybl_station_to_graph
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Graph
|
The NetworkX graph from the NetworkGraphData model. |
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/network_graph.py
add_graph_specific_data
#
Add graph specific data to the NetworkGraphData model.
This functions prepares the NetworkGraphData model for the network graph by setting general data. The network graph uses the node_tuple to identify nodes for switches and branches. The weight strategy is set for the branches and switches. The network graph data is validated.
| PARAMETER | DESCRIPTION |
|---|---|
network_graph_data
|
The NetworkGraphData model to prepare for the network graph Note: The NetworkGraphData is modified in place.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/network_graph_data.py
add_node_tuple_column
#
Add node tuple to the edges of the NetworkGraphData model.
This function adds the node tuple to the NetworkGraphData model. The node tuple is used to identify the nodes for the switches and branches.
| PARAMETER | DESCRIPTION |
|---|---|
network_graph_data
|
The NetworkGraphData model to add the node tuple. Note: The NetworkGraphData is modified in place.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/network_graph_data.py
remove_helper_branches
#
Remove helper branches from the network.
Helper branches are used to connect nodes in the network, but are not part of the grid model. They are an artifact of the network model creation and it is optional to remove them. This function removes the helper branches and the helper nodes from the network. It also removes some nodes that are not specified as helper nodes, if they hold not additional information.
This function is mainly used to test the functionality with the helper branches vs without helper branches.
| PARAMETER | DESCRIPTION |
|---|---|
nodes_df
|
The DataFrame containing the nodes. See the NodeSchema for more information. Note: The nodes_df is modified in place.
TYPE:
|
helper_branches_df
|
The DataFrame containing the helper branches. See the HelperBranchSchema for more information. Note: this DataFrame is obsolete after the function is called.
TYPE:
|
node_assets_df
|
The DataFrame containing the node assets. See the NodeAssetsSchema for more information.
TYPE:
|
switches_df
|
The DataFrame containing the switches. See the SwitchSchema for more information. Note: The switches_df is modified in place.
TYPE:
|
branches_df
|
The DataFrame containing the branches. See the BranchSchema for more information. Note: The branches_df is modified in place.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/network_graph_data.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_node_breaker_topology_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/powsybl_station_to_graph.py
node_breaker_topology_to_graph_data
#
Convert a node breaker topology to a NetworkGraph.
This function is WIP.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The network to convert.
TYPE:
|
substation_info
|
The substation information to retrieve the node breaker topology.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NetworkGraphData.
|
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/powsybl_station_to_graph.py
toop_engine_importer.network_graph.default_filter_strategy
#
The default filter strategy for the NetworkGraphData model.
The default strategy fills: - the BusbarConnectionInfo of all relevant nodes in the network graph. - the bay weights for asset nodes. - EdgeConnectionInfo
run_default_filter_strategy
#
Run the default strategy on the nx.Graph created by the NetworkGraphData model.
This is the main function for the default strategy. The default strategy fills - BusbarConnectionInfo of all busbars in the network graph. - EdgeConnectionInfo of all edges in the network graph.
| PARAMETER | DESCRIPTION |
|---|---|
graph
|
The network graph. Note: The graph is modified in place.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/default_filter_strategy.py
set_switch_busbar_connection_info
#
Set the switch busbar connection information in the network graph model.
why:
- cut off the shortest path at a busbar
- direct_busbar_grid_model_id in combination with bay_id for switching table
uses:
- graph.nodes[node_id]["node_type"] == "busbar"
sets:
- set the direct_busbar_grid_model_id in the switches
- set the busbar_weight to step for all edges around a busbar.
This enables to cut off a shortest path at a busbar.
| PARAMETER | DESCRIPTION |
|---|---|
graph
|
The network graph. Note: The graph is modified in place.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/default_filter_strategy.py
set_bay_weights
#
Set the bay weights in the NetworkGraphData model for asset_nodes and branches.
The bay weight is used to categorize paths in the network and assign a bay to an asset. Enables DGS export and switching into topology using a branch_id, by linking the branch_id to a switch.
| PARAMETER | DESCRIPTION |
|---|---|
graph
|
The network graph. Note: The graph is modified in place.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/default_filter_strategy.py
get_asset_bay_update_dict
#
Get the asset bay update dictionary for the nx.Graph (bases on NetworkGraphData model).
The asset bay update dictionary is used to categorize the asset nodes in the network graph.
| PARAMETER | DESCRIPTION |
|---|---|
graph
|
The network graph.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
update_node_dict
|
A dictionary containing the update information for each node. keys: BusbarConnectionInfo attributes values: list of values to update
TYPE:
|
update_bay_dict
|
A dictionary containing the update information for each bay. keys: bay_id values: dict key: busbar_id value: list of node_ids from the asset_node
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/default_filter_strategy.py
get_asset_bay_node_asset_dict
#
Get the asset bay node asset dictionary for the nx.Graph (based on NetworkGraphData model).
The asset bay node asset dictionary is used to categorize the asset nodes in the network graph.
| PARAMETER | DESCRIPTION |
|---|---|
graph
|
The network graph. Note: The graph is modified in place.
TYPE:
|
node_ids_with_node_assets
|
A list of node ids with a connected asset. This can be a node at the outer end of a Graph, e.g. a node where a line is incoming. Can also be a in the middle of a Graph, e.g. a BREAKER to be mapped.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
connectable_asset_node_to_busbar
|
A dictionary containing the connectable busbars for each node. Key: node_id Value: list of connectable busbar ids
TYPE:
|
asset_bay_update_dict
|
A dictionary containing the update information for each bay. keys: bay_id values: dict key: busbar_id value: list of node_ids from the asset_node
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/default_filter_strategy.py
get_connectable_busbars_update_dict
#
Get the node update dictionary for the BusbarConnectionInfo.
| PARAMETER | DESCRIPTION |
|---|---|
graph
|
The network graph from the NetworkGraphData.
TYPE:
|
shortest_path
|
A dictionary containing the shortest path to a busbar for each busbar. key: busbars_helper_nodes value: list of node_ids from the asset_node the key (a busbars_helper_node)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
update_nodes
|
A dictionary containing the update information for each node. keys: BusbarConnectionInfo attributes values: list of values to update
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/default_filter_strategy.py
get_connectable_assets_update_dict
#
Get the connectable assets update dictionary for the BusbarConnectionInfo.
Uses the reversed connectable_node_assets_to_busbars to update the connectable assets in the BusbarConnectionInfo.
| PARAMETER | DESCRIPTION |
|---|---|
connectable_node_assets_to_busbars
|
A dictionary containing the connectable busbars for each asset node. key: node_id value: list of connectable busbar ids
TYPE:
|
graph
|
The network graph from the NetworkGraphData.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
update_nodes
|
A dictionary containing the update information for each node. keys: BusbarConnectionInfo attributes values: list of values to update
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/default_filter_strategy.py
set_connectable_busbars
#
Set the connectable busbars in BusbarConnectionInfo for each node in connectable_busbars.
| PARAMETER | DESCRIPTION |
|---|---|
graph
|
The network graph. Note: The graph is modified in place.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/default_filter_strategy.py
calculate_connectable_busbars
#
Calculate the connectable busbars in the NetworkGraphData model.
The connectable busbars are the busbars that are reachable from a busbar.
| PARAMETER | DESCRIPTION |
|---|---|
graph
|
The network graph from the NetworkGraphData.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
(busbar_interconnectable, busbar_shortest_path) : tuple[dict[int, list[int]], dict[int, dict[int, list[int]]]]
|
the first dictionary contains the connectable busbars for each node. the second dictionary contains the shortest path to a busbar for each busbar. |
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/default_filter_strategy.py
calculate_zero_impedance_connected
#
Calculate the zero impedance connected assets and busbars for a busbar_id.
The zero impedance connections, are e.g. connections where open switches are filtered out.
| PARAMETER | DESCRIPTION |
|---|---|
graph
|
The network graph from the NetworkGraphData.
TYPE:
|
busbar_id
|
The node id of the busbar.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
connected_assets_dict
|
A dictionary containing the connected assets for each node. key: node_id (a node asset id or a different busbar id than the input busbar_id) value: BusbarConnectionInfo.node_assets
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/default_filter_strategy.py
set_zero_impedance_connected
#
Set zero_impedance_connected in the graph model.
A shortest path to the connected assets respecting the switch open state is calculated.
| PARAMETER | DESCRIPTION |
|---|---|
graph
|
The network graph. Note: The graph is modified
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/default_filter_strategy.py
toop_engine_importer.network_graph.powsybl_station_to_graph
#
Convert a pypowsybl network to a NetworkGraph.
node_breaker_topology_to_graph_data
#
Convert a node breaker topology to a NetworkGraph.
This function is WIP.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The network to convert.
TYPE:
|
substation_info
|
The substation information to retrieve the node breaker topology.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NetworkGraphData.
|
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/powsybl_station_to_graph.py
get_node_breaker_topology_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/powsybl_station_to_graph.py
get_switches
#
Get switches from a node breaker topology.
Get the switches from a node breaker topology, rename and retype for the NetworkGraph.
| PARAMETER | DESCRIPTION |
|---|---|
switches_df
|
The switches DataFrame from the node NodeBreakerTopology.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
switches_df
|
The switches as a DataFrame, with renamed columns for the NetworkGraph.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/powsybl_station_to_graph.py
get_nodes
#
Get nodes from a node breaker topology.
Get the nodes from a node breaker topology, rename and retype for the NetworkGraph. Adds additional information to the nodes.
| PARAMETER | DESCRIPTION |
|---|---|
busbar_sections_names_df
|
The busbar sections names. from get_busbar_sections_with_in_service(network=net, attributes=["name", "in_service"])
TYPE:
|
nodes_df
|
The nodes DataFrame from the net.get_node_breaker_topology(voltage_level_id).nodes
TYPE:
|
switches_df
|
The switches DataFrame from the node NodeBreakerTopology.
TYPE:
|
substation_info
|
The substation information to add as node information.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
nodes_df
|
The nodes as a DataFrame, with renamed columns for the NetworkGraph.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/powsybl_station_to_graph.py
get_helper_branches
#
Get helper branches from a node breaker topology.
Get the helper branches from a node breaker topology, rename and retype for the NetworkGraph.
| PARAMETER | DESCRIPTION |
|---|---|
internal_connections_df
|
The internal connections DataFrame from the node NodeBreakerTopology.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
helper_branches
|
The helper branches as a DataFrame, with renamed columns for the NetworkGraph.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/powsybl_station_to_graph.py
get_node_assets
#
Get node assets from a node breaker topology.
Get the node assets from a node breaker topology, rename and retype for the NetworkGraph.
| PARAMETER | DESCRIPTION |
|---|---|
nodes_df
|
The nodes DataFrame from the node NodeBreakerTopology.
TYPE:
|
all_names_df
|
The names of all elements in the network.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
node_assets_df
|
The node assets as a DataFrame, with renamed columns for the NetworkGraph
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/powsybl_station_to_graph.py
get_station
#
Get the station from a pypowsybl network.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
The powsybl network.
TYPE:
|
bus_id
|
bus id of the station. (the substation grid_model_id)
TYPE:
|
station_info
|
The substation information.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
station
|
The station as a AssetTopology.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/powsybl_station_to_graph.py
get_station_list
#
Get the station list from a pypowsybl network.
Note: include only wanted voltage levels and regions.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
The powsybl network.
TYPE:
|
relevant_voltage_level_with_region
|
DataFrame with the voltage level and region information.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
station_list
|
The station list as a AssetTopology.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/powsybl_station_to_graph.py
get_relevant_voltage_levels
#
Get all relevant voltage level from the network.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
pypowsybl network object
TYPE:
|
network_masks
|
NetworkMasks object with the relevant_subs mask
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
relevant_voltage_level_with_region_and_bus_id
|
DataFrame with the relevant voltage level and region information with bus_id as index.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/powsybl_station_to_graph.py
get_topology
#
Get the pydantic topology model from the network.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
pypowsybl network object
TYPE:
|
network_masks
|
NetworkMasks object with the relevant voltage levels.
TYPE:
|
importer_parameters
|
UCTE importer parameters
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
topology
|
Topology object, including all relevant stations
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/powsybl_station_to_graph.py
toop_engine_importer.network_graph.filter_strategy.empty_bay
#
Empty Bay Filter Strategy.
This module contains functions to identify and handle empty bays in a network graph. An empty bay is defined as a node in the graph that has no connected assets, but has still a bay.
These empty bays need to be identified, so couplers can be found and categorized correctly.
The main function is set_empty_bay_weights, which sets the bay weight for empty bays.
set_empty_bay_weights
#
Set a bay weight for empty bays.
Due to data quality issues, some bays may be empty. Finding and categorizing couplers depends on all bays weights being set. This function sets a bay weight for empty bays.
| PARAMETER | DESCRIPTION |
|---|---|
graph
|
The network graph. Note: The graph is modified in place.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/filter_strategy/empty_bay.py
get_empty_bay_list
#
Get a list of empty bays.
| PARAMETER | DESCRIPTION |
|---|---|
graph
|
The network graph.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
empty_asset_bay_lists
|
A list of empty bays. contains the node_ids of the empty bay path.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/filter_strategy/empty_bay.py
get_empty_bay_update_dict
#
Get the empty bay update dictionary for the nx.Graph.
The empty bay update dictionary is used set the bay weight.
| PARAMETER | DESCRIPTION |
|---|---|
empty_bay_lists
|
A list of empty bays. contains the node_ids of the empty bay path.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
update_edge_dict
|
A dictionary containing the update information for each edge. keys: edge_id (a tuple of node_ids) values: {"bay_weight": WeightValues.max_step.value}
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/filter_strategy/empty_bay.py
toop_engine_importer.network_graph.filter_strategy.switches
#
Filter strategy for switches.
The Issue: There are many paths between two busbars, list of all known connection paths. DISCONNECTOR -> DS CIRCUIT BREAKER -> CB BUSBAR -> B
Busbar to Busbar (single path with no additional parallel busbars): - B -> DS -> B - B -> CB -> B - B -> DS -> CB -> B - B -> CB -> DS -> B - B -> DS -> CB -> DS -> B - B -> DS -> CB -> CB -> DS -> B - B -> DS -> CB -> DS -> CB -> DS -> B
More complex paths, e.g. with multiple busbars, all paths above can be extended with additional busbars: only few examples. Two busbars on either/both sides of a busbar: - B1 -> DS1 -> CB -> DS3 -> B3 ^ - B2 -> DS2 |
Three busbars on either/both sides of a busbar: - B1 -> DS1 -> CB -> DS3 -> B3 ^ - B2 -> DS2 | | - B4 -> DS4 |
Solution: 1. Get all BREAKER, which have no bay_id (e.g. excludes Line/Load breaker) 2. Loop over BREAKER one by one 2.1 Loop: Get all shortest paths from BREAKER to all BUSBARs (respect weights) 2.2 Set coupler sides 2.3 Set bay_id 2.4 Set coupler type 3. Get all DISCONNECTOR (to find left over connections like B -> DS -> B) 4. Repeat step 2. for DS 5. assert all bay_id are set for all DS and CB in the graph
set_all_busbar_coupling_switches
#
Set all connection paths between busbars, be it BREAKER or DISCONNECTOR.
- Get all BREAKER, which have no bay_id (e.g. excludes Line/Load breaker)
- Loop over BREAKER one by one 2.1 Loop: Get all shortest paths from BREAKER to all BUSBARs (respect weights) 2.2 Set coupler sides 2.3 After loop: Set bay_id 2.4 Set coupler type
- Get all DISCONNECTOR (to find left over connections like B -> DS -> B)
- Repeat step 2. for DS
| PARAMETER | DESCRIPTION |
|---|---|
graph
|
The network graph.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/filter_strategy/switches.py
set_switch_bay_from_edge_ids
#
Set the bay for a switch.
Loops over the edge_ids and sets the bay for each edge_id. If there are multiple edges with the same bay_id, the first one is used. Note: if you provide all switches of one bay, the function will set the first edge as the bay_id, no matter the type of the edge. You may provide e.g. all BREAKER first, then all DISCONNECTOR with no bay_id. This way the bay id will be set for a BREAKER if there is one in the path.
| PARAMETER | DESCRIPTION |
|---|---|
graph
|
The network graph.
TYPE:
|
edge_ids
|
A list of edges to find the bay for. Note: only the first edge (regardless of type) in a path is used to set the bay_id.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/filter_strategy/switches.py
set_bay_attr_for_coupler_paths
#
Set the bay attributes for the coupler paths.
This function sets the bay attributes for the coupler paths. The coupler paths are the paths between the busbars and the coupler.
| PARAMETER | DESCRIPTION |
|---|---|
graph
|
The network graph. Note: The graph is modified in place.
TYPE:
|
coupler_update
|
A dictionary containing the found busbars. key: bay_edge_id value: dictionary with key: busbar_id and value: list of node_ids from the asset_node the key (a busbars_helper_node)
TYPE:
|
side1_update
|
A dictionary containing the found busbars. key: bay_edge_id value: dictionary with key: busbar_id and value: list of node_ids from the asset_node the key (a busbars_helper_node)
TYPE:
|
side2_update
|
A dictionary containing the found busbars. key: bay_edge_id value: dictionary with key: busbar_id and value: list of node_ids from the asset_node the key (a busbars_helper_node)
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/filter_strategy/switches.py
set_coupler_bay_ids
#
Set the from_coupler_ids and to_coupler_ids in the EdgeConnectionInfo of the coupler.
| PARAMETER | DESCRIPTION |
|---|---|
graph
|
The network graph. Note: The graph is modified in place.
TYPE:
|
side1_update
|
A dictionary containing the found busbars. key: bay_edge_id value: dictionary with key: busbar_id and value: list of node_ids from the asset_node the key (a busbars_helper_node)
TYPE:
|
side2_update
|
A dictionary containing the found busbars. key: bay_edge_id value: dictionary with key: busbar_id and value: list of node_ids from the asset_node the key (a busbars_helper_node)
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/filter_strategy/switches.py
get_coupler_bay_edge_ids
#
Get the coupler bay ids.
| PARAMETER | DESCRIPTION |
|---|---|
asset_bay_edge_id_update_dict
|
A dictionary containing the found busbars. key: coupler_edge_id value: dictionary with key: busbar_id and value: list of node_ids from the asset_node the key (a busbars_helper_node)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
coupler_bay_ids
|
A dictionary containing the coupler bay ids. key: coupler_edge_id value: list of edge_ids (a tuple of node_ids) that are part of the coupler leading to the busbar
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/filter_strategy/switches.py
set_coupler_type
#
Set the coupler type in the nx.Graph (based on NetworkGraphData model).
Warning: this assumes that all assets of horizontal connections are connected have an bay to all busbars.
| PARAMETER | DESCRIPTION |
|---|---|
graph
|
The network graph. Note: The graph is modified in place.
TYPE:
|
coupler_sides
|
A dictionary containing the sides of the coupler. key: edge_id (a tuple of node_ids) value: tuple of two lists of busbar ids which side is from and which side is to is not defined. The order of the busbar ids is not important.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/filter_strategy/switches.py
get_coupler_type
#
Categorize the coupler in the NetworkGraphData model.
A logic to categorize the coupler into busbar coupler and cross coupler. Uses the BusbarConnectionInfo of each node to find the coupler.
Note: this function is independent of any coupler information. Match the results with the couplers in the graph.
| PARAMETER | DESCRIPTION |
|---|---|
connectable_assets
|
A dictionary containing the connectable assets. Key: busbar_id Value: list of connectable asset ids
TYPE:
|
coupler_sides
|
A dictionary containing the sides of the coupler. key: edge_id (a tuple of node_ids) value: tuple of two lists of busbar ids which side is from and which side is to is not defined. The order of the busbar ids is not important.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
coupler_categories
|
A dictionary containing the coupler_categories. Key: busbar_coupler or cross_coupler Value: list of busbar id tuples
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/filter_strategy/switches.py
busbar_coupler_condition
#
Check if a busbar is a busbar coupler.
A busbar is a busbar coupler if a percentage of connected assets are connected to all other busbars.
| PARAMETER | DESCRIPTION |
|---|---|
busbar1
|
The busbar1 id.
TYPE:
|
busbar2
|
The busbar2 id.
TYPE:
|
connectable_assets
|
A dictionary containing the connectable assets. Key: busbar_id Value: list of connectable asset ids
TYPE:
|
threshold
|
The threshold of connected assets to all other busbars. The percentage above the threshold is considered a busbar coupler. example: connectable_assets[busbar] = [1,2,3,4] connectable_assets[connected_bus] = [1,2,3] threshold = 0.5 -> busbar is still a busbar coupler, even if only 3 out of 4 assets are connected to both busbars.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if the busbar is a busbar coupler. |
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/filter_strategy/switches.py
set_coupler_type_graph
#
Set the "coupler_type" in the NetworkX Graph EdgeConnectionInfo.
| PARAMETER | DESCRIPTION |
|---|---|
graph
|
The network graph. Note: The graph is modified in place.
TYPE:
|
coupler_categories
|
A dictionary containing the coupler_categories. Key: busbar_coupler or cross_coupler Value: list of busbar id tuples
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/filter_strategy/switches.py
get_switches_with_no_bay_id
#
Get all switches with no bay_id.
| PARAMETER | DESCRIPTION |
|---|---|
graph
|
The network graph.
TYPE:
|
asset_type
|
The asset type to find. Can be either "BREAKER" or "DISCONNECTOR".
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
switches
|
A list of all switches with no bay_id.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/filter_strategy/switches.py
get_switch_bay_dict
#
Get the bay for a switch.
Note: if there are two BREAKER in one connection path, this function will return only the first one.
Examples:
- B -> DS -> CB1 -> CB2 -> DS -> B
- B -> DS -> CB1 -> DS -> CB2 -> DS -> B Assuming CB1 is the first in the list, the function will return only CB1.
| PARAMETER | DESCRIPTION |
|---|---|
graph
|
The network graph.
TYPE:
|
switch_edge_list
|
A list of edges to find the bay for. This can be a list of edges with a BREAKER or DISCONNECTOR. The edges are used to find the bay for the asset.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
asset_bay_update_dict
|
A dictionary containing the found busbars. key: bay_edge_id value: tuple of dictionary with key: busbar_id and value: list of node_ids from the asset_node the key (a busbars_helper_node)
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/filter_strategy/switches.py
get_busbar_sides_of_coupler
#
Get the sides of the coupler.
A coupler has two sides, the from and to side. Both sides can connect to multiple busbars. This function gets the busbar ids for the busbar_helper_node ids.
| PARAMETER | DESCRIPTION |
|---|---|
graph
|
The network graph.
TYPE:
|
asset_bay_edge_id_update_dict
|
A dictionary containing the found busbars. key: EDGE_ID (a tuple of node_ids) value: list of busbar_helper_node ids.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
sides_of_coupler
|
A dictionary containing the sides of the coupler. key: edge_id (a tuple of node_ids) value: tuple of two lists of busbar ids Which side is from and which side is to is not defined. The order of the tuple is defined by the edge_id order. Note: the busbar_helper_node are transformed to busbar ids.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/filter_strategy/switches.py
set_coupler_busbar_sides
#
Set the coupler busbar side in the nx.Graph (based on NetworkGraphData model).
| PARAMETER | DESCRIPTION |
|---|---|
graph
|
The network graph. Note: The graph is modified in place.
TYPE:
|
busbar_sides_of_coupler
|
A dictionary containing the sides of the coupler. key: EDGE_ID (a tuple of node_ids) value: tuple of two lists of busbar ids
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/filter_strategy/switches.py
get_asset_bay_id_grid_model_update_dict
#
Get the asset bay id grid model update dict for set_asset_bay_edge_attr.
Replaces the edge ids with the grid model ids. Adds the coupler itself to the dict if missing.
| PARAMETER | DESCRIPTION |
|---|---|
asset_bay_edge_id_update_dict
|
A dictionary containing the found busbars. key: bay_edge_id value: tuple of dictionary with key: busbar_id and value: list of node_ids from the asset_node the key (a busbars_helper_node)
TYPE:
|
| RETURNS | DESCRIPTION | ||
|---|---|---|---|
asset_bay_id_grid_model_update_dict
|
A tuple (coupler, side1, side2) of dictionary containing the found busbars. key: bay_id (an EDGE_ID) value: dictionary with key: busbar_id and value: list of node_ids from the asset_node the key (a busbars_helper_node)
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/filter_strategy/switches.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(
asset_topology,
grid_model_file_output,
grid_model_file_input=None,
station_list=None,
)
Translate asset topology model to UCT and saves the model.
| PARAMETER | DESCRIPTION |
|---|---|
asset_topology
|
Asset topology model to be translated. Based on the pydantic model from interfaces.asset_topology
TYPE:
|
grid_model_file_output
|
Path to save the UCTE file.
TYPE:
|
grid_model_file_input
|
Path to the grid model file. If not provided, the Topology.grid_model_file will be used.
TYPE:
|
station_list
|
List of station grid_model_ids to be translated. If not provided, all stations in the asset_topology will be translated.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
NotImplementedError
|
If asset_topology.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 |