Importer#
Importer Worker#
toop_engine_importer.worker.worker
#
Module contains functions for the kafka communication in the importer repo.
File: worker.py Author: Nico Westerbeck Created: 2024
Args
#
Bases: BaseModel
Holds arguments which must be provided at the launch of the worker.
Contains arguments that static for each preprocessing run.
kafka_broker
class-attribute
instance-attribute
#
The Kafka broker to connect to.
importer_command_topic
class-attribute
instance-attribute
#
The Kafka topic to listen for commands on.
importer_results_topic
class-attribute
instance-attribute
#
The topic to push results to.
importer_heartbeat_topic
class-attribute
instance-attribute
#
The topic to push heartbeats to.
heartbeat_interval_ms
class-attribute
instance-attribute
#
The interval in milliseconds to send heartbeats.
idle_loop
#
Start the idle loop of the worker.
This will be running when the worker is currently not preprocessing This will wait until a StartPreprocessingCommand is received and return it. In case a ShutdownCommand is received, the worker will exit with the exit code provided in the command.
| PARAMETER | DESCRIPTION |
|---|---|
consumer
|
The initialized Kafka consumer to listen for commands on.
TYPE:
|
send_heartbeat_fn
|
A function to call when there were no messages received for a while.
TYPE:
|
heartbeat_interval_ms
|
The time to wait for a new command in milliseconds. If no command has been received, a heartbeat will be sent and then the receiver will wait for commands again.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
StartPreprocessingCommand
|
The start preprocessing command to start the preprocessing run with |
Source code in packages/importer_pkg/src/toop_engine_importer/worker/worker.py
main
#
main(
args,
producer,
consumer,
unprocessed_gridfile_fs,
processed_gridfile_fs,
loadflow_result_fs,
)
Start main function of the worker.
| PARAMETER | DESCRIPTION |
|---|---|
args
|
The arguments to start the worker with.
TYPE:
|
unprocessed_gridfile_fs
|
A filesystem where the unprocessed gridfiles are stored. The concrete folder to use is determined by the start command, which contains an import location relative to the root of the unprocessed_gridfile_fs.
TYPE:
|
processed_gridfile_fs
|
The target filesystem for the preprocessing worker. This contains all processed grid files. During the import job, a new folder import_results.data_folder was created which will be completed with the preprocess call to this function. Internally, only the data folder is passed around as a dirfs. Note that the unprocessed_gridfile_fs is not needed here anymore, as all preprocessing steps that need the unprocessed gridfiles were already done.
TYPE:
|
loadflow_result_fs
|
A filesystem where the loadflow results are stored. Loadflows will be stored here using the uuid generation process and passed as a StoredLoadflowReference which contains the subfolder in this filesystem.
TYPE:
|
producer
|
The Kafka producer to send results and heartbeats with.
TYPE:
|
consumer
|
The Kafka consumer to receive commands with.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/worker/worker.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 | |
toop_engine_importer.worker.preprocessor
#
Module contains functions holds preprocessor commands for kafka communication in the importer repo.
File: preprocessor.py Author: Nico Westerbeck Created: 2024
import_grid_model
#
import_grid_model(
start_command,
unprocessed_gridfile_fs,
processed_gridfile_fs,
status_update_fn,
)
Run the import procedure.
This only performs the import until there's a grid model, the preprocessing in the loadflow solver is run by preprocess
| PARAMETER | DESCRIPTION |
|---|---|
start_command
|
The command to start the preprocessing run with |
unprocessed_gridfile_fs
|
A filesystem where the unprocessed gridfiles are stored. The concrete folder to use is determined by the start command, which contains an import location relative to the root of the unprocessed_gridfile_fs.
TYPE:
|
processed_gridfile_fs
|
The target filesystem for the preprocessing worker. This contains all processed grid files. During the import job, a new folder import_results.data_folder 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:
|
status_update_fn
|
A function to call to signal progress in the preprocessing pipeline. Takes a stage, an optional message as parameters and network size stats.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ImportResult
|
A result dataclass from the importer, mainly including the grid folder and some stats |
| RAISES | DESCRIPTION |
|---|---|
Exception
|
Any exception raised will be caught by the worker and sent back |
Source code in packages/importer_pkg/src/toop_engine_importer/worker/preprocessor.py
run_initial_loadflow
#
run_initial_loadflow(
start_command,
processed_gridfile_dirfs,
status_update_fn,
loadflow_result_fs,
lf_params=None,
)
Run the initial AC contingency analysis
| PARAMETER | DESCRIPTION |
|---|---|
start_command
|
The command that was sent to the worker |
processed_gridfile_dirfs
|
A filesystem where the processed gridfiles are stored. This is assumed to be a dirfs pointing to the data folder for this import job, where the preprocessed gridfiles are stored
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:
|
loadflow_result_fs
|
A filesystem where the loadflow results are stored - this should be a NFS share together with the backend and optimizer. The importer needs this to store the initial loadflows
TYPE:
|
lf_params
|
The loadflow parameters to use for the runner, if any. This is passed in the preprocessing results and can be used to run the loadflows with the same parameters as the initial loadflow in the preprocessing step. If None, the runner will use default parameters.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
StoredLoadflowReference
|
A reference to the stored loadflow results |
dict[MetricType, float]
|
A dictionary containing the computed metrics |
Source code in packages/importer_pkg/src/toop_engine_importer/worker/preprocessor.py
preprocess
#
preprocess(
start_command,
import_results,
status_update_fn,
loadflow_result_fs,
processed_gridfile_fs,
)
Run the preprocessing pipeline that is independent of the data source.
This only performs the preprocessing in the loadflow solver
| PARAMETER | DESCRIPTION |
|---|---|
start_command
|
The command to start the preprocessing run with |
import_results
|
Results from the import procedure
TYPE:
|
status_update_fn
|
A function to call to signal progress in the preprocessing pipeline. Takes a stage and an optional message as parameters
TYPE:
|
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:
|
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:
|
| RETURNS | DESCRIPTION |
|---|---|
PreprocessingSuccessResult
|
A result dataclass for the entire preprocessing, including paths to the ready static_information and network_data dataclasses. |
| RAISES | DESCRIPTION |
|---|---|
Exception
|
Any exception raised will be caught by the worker and sent back |
Source code in packages/importer_pkg/src/toop_engine_importer/worker/preprocessor.py
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 | |
Contingency from PowerFactory#
toop_engine_importer.contingency_from_power_factory
#
Import contingency from PowerFactory.
__all__
module-attribute
#
__all__ = [
"AllGridElementsSchema",
"ContingencyImportSchemaPowerFactory",
"ContingencyMatchSchema",
"get_contingencies_from_file",
"match_contingencies",
"power_factory_data_class",
]
AllGridElementsSchema
#
Bases: DataFrameModel
A AllGridElementsSchema is a DataFrameModel for all grid elements in the grid model.
The grid model is loaded from the CGMES file in either PyPowsybl or Pandapower.
element_type
class-attribute
instance-attribute
#
element_type = pa.Field(
nullable=True, isin=GridElementType.__args__
)
The grid model type of the contingency. e.g. LINE, SWITCH, BUS, etc.
grid_model_id
class-attribute
instance-attribute
#
The grid model id of the contingency. e.g. a CGMES id (cryptic number)
grid_model_name
class-attribute
instance-attribute
#
The grid model name of the contingency. e.g. a CGMES name (human readable name)
ContingencyImportSchemaPowerFactory
#
Bases: DataFrameModel
A ContingencyImportSchemaPowerFactory is a DataFrameModel defining the expected data of the contingency import.
From PowerFactory: You may find the list of contingencies in the PowerFactory GUI under "Calculation > Contingency Analysis > Show Contingencies...".
index
class-attribute
instance-attribute
#
The unique index of the DataFrame. This index is used as a unique id for the dataframe.
contingency_name
class-attribute
instance-attribute
#
The id of contingency found in the contingency table. Attribute: "loc_name" of contingency table May be a multi index to group the contingencies together.
contingency_id
class-attribute
instance-attribute
#
A id for the contingency. This id is used to group the contingencies together. Attribute: "number" of contingency table.
power_factory_grid_model_name
class-attribute
instance-attribute
#
The name of the grid model element Attribute: "loc_name" of grid model element
power_factory_grid_model_fid
class-attribute
instance-attribute
#
The foreign Key of the grid model element Attribute: "for_name" of grid model element Note: True spacing of FID must be kept in the string.
power_factory_grid_model_rdf_id
class-attribute
instance-attribute
#
The rdf id (CIM) of the grid model element Attribute: "cimRdfId" of grid model element
comment
class-attribute
instance-attribute
#
May contain information about the contingency. Leave empty if not needed. Fill if comments or descriptions exist in the contingency table.
power_factory_element_type
class-attribute
instance-attribute
#
power_factory_element_type = pa.Field(
nullable=True, isin=GridElementType.__args__
)
The type of the contingency based on the PowerFactory type. Gives a hint where to look for the contingency.
ContingencyMatchSchema
#
Bases: ContingencyImportSchemaPowerFactory, AllGridElementsSchema
A ContingencyMatchSchema is a DataFrameModel for matching the ContingencyImportSchema with the grid model.
ContingencyMatchSchema is a merge of: ContingencyImportSchema.merge( AllGridElementsSchema, how="left", left_on="power_factory_grid_model_rdf_id", right_on="grid_model_id" ) Note: the power_factory_grid_model_rdf_id has a leading underscore and may need modification.
element_type
class-attribute
instance-attribute
#
element_type = pa.Field(
nullable=True, isin=GridElementType.__args__
)
The grid model type of the contingency. e.g. LINE, SWITCH, BUS, etc.
grid_model_id
class-attribute
instance-attribute
#
The grid model id of the contingency. e.g. a CGMES id (cryptic number)
grid_model_name
class-attribute
instance-attribute
#
The grid model name of the contingency. e.g. a CGMES name (human readable name)
index
class-attribute
instance-attribute
#
The unique index of the DataFrame. This index is used as a unique id for the dataframe.
contingency_name
class-attribute
instance-attribute
#
The id of contingency found in the contingency table. Attribute: "loc_name" of contingency table May be a multi index to group the contingencies together.
contingency_id
class-attribute
instance-attribute
#
A id for the contingency. This id is used to group the contingencies together. Attribute: "number" of contingency table.
power_factory_grid_model_name
class-attribute
instance-attribute
#
The name of the grid model element Attribute: "loc_name" of grid model element
power_factory_grid_model_fid
class-attribute
instance-attribute
#
The foreign Key of the grid model element Attribute: "for_name" of grid model element Note: True spacing of FID must be kept in the string.
power_factory_grid_model_rdf_id
class-attribute
instance-attribute
#
The rdf id (CIM) of the grid model element Attribute: "cimRdfId" of grid model element
comment
class-attribute
instance-attribute
#
May contain information about the contingency. Leave empty if not needed. Fill if comments or descriptions exist in the contingency table.
power_factory_element_type
class-attribute
instance-attribute
#
power_factory_element_type = pa.Field(
nullable=True, isin=GridElementType.__args__
)
The type of the contingency based on the PowerFactory type. Gives a hint where to look for the contingency.
get_contingencies_from_file
#
Get the contingencies from the file.
This function reads the contingencies from the file and returns a DataFrame in the ContingencyImportSchema format.
| PARAMETER | DESCRIPTION |
|---|---|
n1_file
|
The path to the file.
TYPE:
|
delimiter
|
The delimiter of the file. Default is ";".
TYPE:
|
filesystem
|
The filesystem to use to read the file. If None, the local filesystem is used.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ContingencyImportSchema
|
A DataFrame containing the contingencies. |
Source code in packages/importer_pkg/src/toop_engine_importer/contingency_from_power_factory/contingency_from_file.py
match_contingencies
#
Match the contingencies from the file with the elements in the grid model.
This function matches the contingencies from the file with the elements in the grid model. It first tries to match by index, then by name.
| PARAMETER | DESCRIPTION |
|---|---|
n1_definition
|
The contingencies from the file.
TYPE:
|
all_element_names
|
The elements in the grid model.
TYPE:
|
match_by_name
|
If True, match by name. Default is True. If False, only match by index.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame[ContingencyMatchSchema]
|
A DataFrame containing the matched contingencies. |
Source code in packages/importer_pkg/src/toop_engine_importer/contingency_from_power_factory/contingency_from_file.py
toop_engine_importer.contingency_from_power_factory.power_factory_data_class
#
Classes for the contingency list import from PowerFactory.
This importing has the focus on CIM bases grid models. UCTE has not been tested.
Author: Benjamin Petrick Created: 2025-05-13
GridModelTypePowerFactory
module-attribute
#
GridModelTypePowerFactory = Literal[
"ElmTr2",
"ElmLne",
"ElmGenstat",
"ElmLod",
"ElmSym",
"ElmNec",
"ElmZpu",
"ElmTr3",
"ElmSind",
"ElmTerm",
"ElmShnt",
"ElmVac",
]
GridElementType
module-attribute
#
GridElementType = Literal[
"BUS",
"BUSBAR_SECTION",
"LINE",
"SWITCH",
"TWO_WINDINGS_TRANSFORMER",
"THREE_WINDINGS_TRANSFORMER",
"GENERATOR",
"LOAD",
"SHUNT_COMPENSATOR",
"BOUNDARY_LINE",
"TIE_LINE",
]
ContingencyImportSchemaPowerFactory
#
Bases: DataFrameModel
A ContingencyImportSchemaPowerFactory is a DataFrameModel defining the expected data of the contingency import.
From PowerFactory: You may find the list of contingencies in the PowerFactory GUI under "Calculation > Contingency Analysis > Show Contingencies...".
index
class-attribute
instance-attribute
#
The unique index of the DataFrame. This index is used as a unique id for the dataframe.
contingency_name
class-attribute
instance-attribute
#
The id of contingency found in the contingency table. Attribute: "loc_name" of contingency table May be a multi index to group the contingencies together.
contingency_id
class-attribute
instance-attribute
#
A id for the contingency. This id is used to group the contingencies together. Attribute: "number" of contingency table.
power_factory_grid_model_name
class-attribute
instance-attribute
#
The name of the grid model element Attribute: "loc_name" of grid model element
power_factory_grid_model_fid
class-attribute
instance-attribute
#
The foreign Key of the grid model element Attribute: "for_name" of grid model element Note: True spacing of FID must be kept in the string.
power_factory_grid_model_rdf_id
class-attribute
instance-attribute
#
The rdf id (CIM) of the grid model element Attribute: "cimRdfId" of grid model element
comment
class-attribute
instance-attribute
#
May contain information about the contingency. Leave empty if not needed. Fill if comments or descriptions exist in the contingency table.
power_factory_element_type
class-attribute
instance-attribute
#
power_factory_element_type = pa.Field(
nullable=True, isin=GridElementType.__args__
)
The type of the contingency based on the PowerFactory type. Gives a hint where to look for the contingency.
AllGridElementsSchema
#
Bases: DataFrameModel
A AllGridElementsSchema is a DataFrameModel for all grid elements in the grid model.
The grid model is loaded from the CGMES file in either PyPowsybl or Pandapower.
element_type
class-attribute
instance-attribute
#
element_type = pa.Field(
nullable=True, isin=GridElementType.__args__
)
The grid model type of the contingency. e.g. LINE, SWITCH, BUS, etc.
grid_model_id
class-attribute
instance-attribute
#
The grid model id of the contingency. e.g. a CGMES id (cryptic number)
grid_model_name
class-attribute
instance-attribute
#
The grid model name of the contingency. e.g. a CGMES name (human readable name)
ContingencyMatchSchema
#
Bases: ContingencyImportSchemaPowerFactory, AllGridElementsSchema
A ContingencyMatchSchema is a DataFrameModel for matching the ContingencyImportSchema with the grid model.
ContingencyMatchSchema is a merge of: ContingencyImportSchema.merge( AllGridElementsSchema, how="left", left_on="power_factory_grid_model_rdf_id", right_on="grid_model_id" ) Note: the power_factory_grid_model_rdf_id has a leading underscore and may need modification.
element_type
class-attribute
instance-attribute
#
element_type = pa.Field(
nullable=True, isin=GridElementType.__args__
)
The grid model type of the contingency. e.g. LINE, SWITCH, BUS, etc.
grid_model_id
class-attribute
instance-attribute
#
The grid model id of the contingency. e.g. a CGMES id (cryptic number)
grid_model_name
class-attribute
instance-attribute
#
The grid model name of the contingency. e.g. a CGMES name (human readable name)
index
class-attribute
instance-attribute
#
The unique index of the DataFrame. This index is used as a unique id for the dataframe.
contingency_name
class-attribute
instance-attribute
#
The id of contingency found in the contingency table. Attribute: "loc_name" of contingency table May be a multi index to group the contingencies together.
contingency_id
class-attribute
instance-attribute
#
A id for the contingency. This id is used to group the contingencies together. Attribute: "number" of contingency table.
power_factory_grid_model_name
class-attribute
instance-attribute
#
The name of the grid model element Attribute: "loc_name" of grid model element
power_factory_grid_model_fid
class-attribute
instance-attribute
#
The foreign Key of the grid model element Attribute: "for_name" of grid model element Note: True spacing of FID must be kept in the string.
power_factory_grid_model_rdf_id
class-attribute
instance-attribute
#
The rdf id (CIM) of the grid model element Attribute: "cimRdfId" of grid model element
comment
class-attribute
instance-attribute
#
May contain information about the contingency. Leave empty if not needed. Fill if comments or descriptions exist in the contingency table.
power_factory_element_type
class-attribute
instance-attribute
#
power_factory_element_type = pa.Field(
nullable=True, isin=GridElementType.__args__
)
The type of the contingency based on the PowerFactory type. Gives a hint where to look for the contingency.
toop_engine_importer.contingency_from_power_factory.contingency_from_file
#
Import contingencies from a file.
This module contains functions to import contingencies from a file and match them with the grid model.
Author: Benjamin Petrick Created: 2025-05-13
get_contingencies_from_file
#
Get the contingencies from the file.
This function reads the contingencies from the file and returns a DataFrame in the ContingencyImportSchema format.
| PARAMETER | DESCRIPTION |
|---|---|
n1_file
|
The path to the file.
TYPE:
|
delimiter
|
The delimiter of the file. Default is ";".
TYPE:
|
filesystem
|
The filesystem to use to read the file. If None, the local filesystem is used.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ContingencyImportSchema
|
A DataFrame containing the contingencies. |
Source code in packages/importer_pkg/src/toop_engine_importer/contingency_from_power_factory/contingency_from_file.py
match_contingencies
#
Match the contingencies from the file with the elements in the grid model.
This function matches the contingencies from the file with the elements in the grid model. It first tries to match by index, then by name.
| PARAMETER | DESCRIPTION |
|---|---|
n1_definition
|
The contingencies from the file.
TYPE:
|
all_element_names
|
The elements in the grid model.
TYPE:
|
match_by_name
|
If True, match by name. Default is True. If False, only match by index.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame[ContingencyMatchSchema]
|
A DataFrame containing the matched contingencies. |
Source code in packages/importer_pkg/src/toop_engine_importer/contingency_from_power_factory/contingency_from_file.py
match_contingencies_by_index
#
Match the contingencies from the file with the elements in the grid model.
| PARAMETER | DESCRIPTION |
|---|---|
n1_definition
|
The contingencies from the file.
TYPE:
|
all_element_names
|
The elements in the grid model.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame[ContingencyMatchSchema]
|
A DataFrame containing the matched contingencies. |
Source code in packages/importer_pkg/src/toop_engine_importer/contingency_from_power_factory/contingency_from_file.py
match_contingencies_by_name
#
Match the contingencies from the file with the elements in the grid model by name.
Matches by name and replaces the grid_model_name, element_type and grid_model_id. First tries to match 100% of the name. Second tries to match by removing spaces and replacing "+" with "##_##".
| PARAMETER | DESCRIPTION |
|---|---|
processed_n1_definition
|
The contingencies from the file.
TYPE:
|
all_element_names
|
The elements in the grid model.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame[ContingencyMatchSchema]
|
A DataFrame containing the matched contingencies. |
Source code in packages/importer_pkg/src/toop_engine_importer/contingency_from_power_factory/contingency_from_file.py
match_contingencies_with_suffix
#
Match the contingencies from the file with the elements in the grid model by name.
Matches by name and replaces the grid_model_name with power_factory_grid_model_name. Removes suffix from the grid_model_name.
| PARAMETER | DESCRIPTION |
|---|---|
processed_n1_definition
|
The contingencies from the file.
TYPE:
|
all_element_names
|
The elements in the grid model.
TYPE:
|
grid_model_suffix
|
The suffixes to match the grid model names.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame[ContingencyMatchSchema]
|
A DataFrame containing the matched contingencies. |
Source code in packages/importer_pkg/src/toop_engine_importer/contingency_from_power_factory/contingency_from_file.py
match_contingencies_column
#
match_contingencies_column(
processed_n1_definition,
all_element_names,
n1_column,
element_column,
)
Match a column processed_n1_definition with a column from all_element_names.
This functions matches based on 100% name match and replaces the grid_model_name, element_type and grid_model_id
| PARAMETER | DESCRIPTION |
|---|---|
processed_n1_definition
|
The contingencies from the file.
TYPE:
|
all_element_names
|
The elements in the grid model.
TYPE:
|
n1_column
|
The column name in processed_n1_definition.
TYPE:
|
element_column
|
The column name in all_element_names.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame[ContingencyMatchSchema]
|
A DataFrame containing the matched contingencies. |
Source code in packages/importer_pkg/src/toop_engine_importer/contingency_from_power_factory/contingency_from_file.py
UCTE Toolset#
toop_engine_importer.ucte_toolset
#
A collection of tools to work with UCTE data.
ucte_toolset.py: Functions load, manipulate, and save UCTE data using pd.DataFrame.
Importer Pandapower#
toop_engine_importer.pandapower_import
#
Contains functions to import data from pandapower networks to the Topology Optimizer.
__all__
module-attribute
#
__all__ = [
"add_substation_column_to_bus",
"create_virtual_slack",
"drop_elements_connected_to_one_bus",
"drop_unsupplied_buses",
"fuse_closed_switches_by_bus_ids",
"fuse_closed_switches_fast",
"get_all_switches_from_bus_ids",
"get_closed_switch",
"get_coupler_types_of_substation",
"get_indirect_connected_switch",
"get_master_asset_topology_from_network",
"get_station_id_list",
"get_substation_buses_from_bus_id",
"get_type_b_nodes",
"move_elements_based_on_labels",
"preprocess_net_step1",
"preprocess_net_step2_master_asset_topology",
"remove_out_of_service",
"replace_zero_branches",
"select_connected_subnet",
"validate_asset_topology_stations",
]
get_master_asset_topology_from_network
#
get_master_asset_topology_from_network(
network,
topology_id,
grid_model_file,
station_id_list,
foreign_key="equipment",
)
Return canonical asset-topology master data derived from a pandapower network.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
Source pandapower network.
TYPE:
|
topology_id
|
Identifier to store on the resulting master data.
TYPE:
|
grid_model_file
|
Source grid-model file name stored in the master data.
TYPE:
|
station_id_list
|
Station definitions as lists of pandapower bus indices.
TYPE:
|
foreign_key
|
Column name used as the preferred human-readable identifier.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
MasterAssetTopology
|
Canonical master data split into structural station groups. |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/pandapower/asset_topology.py
create_virtual_slack
#
Create a virtual slack bus for all ext_grids in the network.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The pandapower network to create a virtual slack for, will be modified in-place. Note: network is modified in-place.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
pandapowerNet
|
The network with a virtual slack. |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/pandapower/pandapower_import_helpers.py
drop_elements_connected_to_one_bus
#
Drop elements connected to one bus.
- impedance -> Capacitor will end up on the same bus
- trafo3w -> edgecase: trafo3w that goes from one hv to the same level but two different busbars will end up on the same bus
| PARAMETER | DESCRIPTION |
|---|---|
net
|
pandapower network Note: the network is modified in place
TYPE:
|
branch_types
|
list of branch types to drop elements connected to one bus
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
None
|
|
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/pandapower/pandapower_import_helpers.py
drop_unsupplied_buses
#
Drop all unsupplied buses from the network.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The pandapower network to drop unsupplied buses from, will be modified in-place.
TYPE:
|
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/pandapower/pandapower_import_helpers.py
fuse_closed_switches_fast
#
Fuse closed switches in the network by merging busbars.
This routine uses an algorithm to number each busbar and then find the lowest connected busbar iteratively. If a busbar is connected to a lower-numbered busbar, it will be re-labeled to the lower-numbered busbar. This algorithm needs as many iterations as the maximum number of hops between the lowest and highest busbar in any of the substations.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The pandapower network to fuse closed switches in, will be modified in-place.
TYPE:
|
switch_ids
|
The switch ids to fuse. If None, all closed switches are fused.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
The closed switches that were fused. |
DataFrame
|
The buses that were dropped because they were relabeled to a lower-numbered busbar. |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/pandapower/pandapower_import_helpers.py
move_elements_based_on_labels
#
Move all elements in the network to the lowest labeled busbar.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The pandapower network to move elements in, will be modified in-place.
TYPE:
|
labels
|
The labels of the busbars to move the elements to.
TYPE:
|
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/pandapower/pandapower_import_helpers.py
remove_out_of_service
#
Remove all out-of-service elements from the network.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The pandapower network to remove out-of-service elements from, will be modified in-place.
TYPE:
|
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/pandapower/pandapower_import_helpers.py
replace_zero_branches
#
Replace zero-impedance branches with switches in the network.
Some leftover lines and xwards will be bumped to a higher impedance to avoid numerical issues.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The pandapower network to replace zero branches in, will be modified in-place.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
pandapowerNet
|
The network with zero branches replaced. |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/pandapower/pandapower_import_helpers.py
select_connected_subnet
#
Select the connected subnet of the grid that has a slack and return it.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The pandapower network to select the connected subnet from.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
pandapowerNet
|
The connected subnet of the grid that has a slack. |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/pandapower/pandapower_import_helpers.py
add_substation_column_to_bus
#
add_substation_column_to_bus(
network,
substation_col="substat",
get_name_col="name",
only_closed_switches=False,
)
Add a substation column to the bus DataFrame.
This function will go through all busbars of type 'b' and add the substation name to all buses connected to the busbar.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
The pandapower network to add the substation column to. Note: the network will be modified in-place.
TYPE:
|
substation_col
|
The name of the new substation column where the value from the get_name_col is added.
TYPE:
|
get_name_col
|
The name of the column to get the substation name from.
TYPE:
|
only_closed_switches
|
If True, only closed switches are considered. The result will lead substation naming after the the electrical voltage level.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/pandapower_import/pandapower_toolset_node_breaker.py
fuse_closed_switches_by_bus_ids
#
Fuse a series of closed switches in the network by merging busbars (type b).
| PARAMETER | DESCRIPTION |
|---|---|
network
|
The pandapower network to fuse closed switches in, will be modified in-place.
TYPE:
|
switch_bus_ids
|
The bus ids of the switches to fuse. Note: this must include the bus_id that is expected to be the final busbar.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bus_labels
|
An with the length of the highest bus id in the network representing the busbar index. At the index of the array(old busbar index), the new busbar index is stored.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/pandapower_import/pandapower_toolset_node_breaker.py
get_all_switches_from_bus_ids
#
Get all switches connected to a list of buses.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
The pandapower network to get the switches from.
TYPE:
|
bus_ids
|
The buses to get the switches from.
TYPE:
|
only_closed_switches
|
If True, only closed switches are considered.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
A DataFrame with all switches connected to the buses in bus_ids. |
Source code in packages/importer_pkg/src/toop_engine_importer/pandapower_import/pandapower_toolset_node_breaker.py
get_closed_switch
#
Get the closed switch based on the column and column_ids.
| PARAMETER | DESCRIPTION |
|---|---|
switches
|
The switches df to filter the closed switch from.
TYPE:
|
column
|
The column to filter the column_ids. e.g. foreign_id
TYPE:
|
column_ids
|
The column ids to filter the closed switch from.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
The closed switch filtered by the column_ids. |
Source code in packages/importer_pkg/src/toop_engine_importer/pandapower_import/pandapower_toolset_node_breaker.py
get_coupler_types_of_substation
#
Get the cross coupler (German: Querkuppler), busbar coupler and a cross connector of a substation.
A busbar coupler is a connection between two busbars, where assets can be connected to both busbars. A cross coupler is a connection between two busbars B1 and B2, where assets A1 can not be connected to both busbars directly. Asset A1 can only be connected directly to B1 and is connected indirectly to B2 by the cross coupler. A coupler is always a disconnector (DS), a power switch (CB) and a DS in series. In unique cases, there can be two CB switches in series. A cross connector is a single disconnector between two busbars.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
The pandapower network to get the Cross coupler/quercoupler from.
TYPE:
|
substation_bus_list
|
The bus list of the substation. All buses in the list represent a substation.
TYPE:
|
only_closed_switches
|
If True, only closed switches are considered.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
coupler
|
a dictionary with 4 keys: - 1. key: "busbar_coupler_bus_ids" - 2. key: "cross_coupler_bus_ids" - 3. key: "busbar_coupler_switch_ids" - 4. key: "cross_coupler_switch_ids" bus_ids: list of bus ids representing the busbar coupler and cross coupler switch_ids: list of switch ids representing the busbar coupler and cross coupler switch_ids = [CB, DS1, DS2] Note: the switches are not filtered by open/closed. Note: if there is only one switch or two switches: switch_ids_1sw = [CB, CB, CB] switch_ids_2sw = [CB, CB, DS2]
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/pandapower_import/pandapower_toolset_node_breaker.py
489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 | |
get_indirect_connected_switch
#
get_indirect_connected_switch(
net,
bus_1,
bus_2,
only_closed_switches=True,
consider_three_buses=False,
exclude_buses=None,
)
Get a switch, that is indirectly connected by two buses and only by two buses.
This function will only return the indirect connection between two buses. e.g. switchB or any switch that is parallel to switchB.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The pandapower network to get the indirect connections from.
TYPE:
|
bus_1
|
The bus to get the indirect connections from.
TYPE:
|
bus_2
|
The bus to get the indirect connections to.
TYPE:
|
only_closed_switches
|
If True, only closed switches are considered.
TYPE:
|
consider_three_buses
|
If True, the function will also consider three buses in between. Bus1---switch1---bus2---switch2---bus3---switch3---bus4---switch4---bus5
TYPE:
|
exclude_buses
|
The buses to exclude from the indirect connection. e.g. give all other busbars (type b) in the substation.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, list[int]]
|
A dictionary with the indirect connections from bus_1 to bus_2 |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the indirect connection contains more than one switch. e.g. a parallel line to the switch. |
Source code in packages/importer_pkg/src/toop_engine_importer/pandapower_import/pandapower_toolset_node_breaker.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | |
get_station_id_list
#
Get all station ids from the network.
This function will return all unique station ids from the network.
| PARAMETER | DESCRIPTION |
|---|---|
bus_df
|
The bus DataFrame to get the station ids from. e.g. pre filtered bus DataFrame with only busbars of type 'b'.
TYPE:
|
substation_col
|
The column name of the substation
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[int]
|
A list of station ids in the order of the stations in the substation_col. |
Source code in packages/importer_pkg/src/toop_engine_importer/pandapower_import/pandapower_toolset_node_breaker.py
get_substation_buses_from_bus_id
#
Get all buses of a substation from a start bus id.
This function will return all buses that are connected to the start bus id via switches. Note: The input expects a bus ids only containing the busbars you want to get the connection for. See diagram for references. e.g:: input [BB1, BB2] -> get BC½ input [BB1, BB2, BB3, BB4] -> get BC½, BC¾, CC⅓, CC2/4
| PARAMETER | DESCRIPTION |
|---|---|
network
|
The pandapower network to get the substation buses from.
TYPE:
|
start_bus_id
|
The bus id to start the search from.
TYPE:
|
only_closed_switches
|
If True, only closed switches are considered.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
set[int]
|
A set of bus ids that are connected to the start bus id. |
| RAISES | DESCRIPTION |
|---|---|
RuntimeError
|
If the function detects an infinite loop. |
Source code in packages/importer_pkg/src/toop_engine_importer/pandapower_import/pandapower_toolset_node_breaker.py
get_type_b_nodes
#
Get all nodes of type 'b' (busbar) in a network or substation.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
The pandapower network to get the busbars from.
TYPE:
|
substation_bus_list
|
The bus ids of the substation.
TYPE:
|
substation_column
|
The column containing the substation.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
A DataFrame with all busbars of type 'b' in the substation. |
Source code in packages/importer_pkg/src/toop_engine_importer/pandapower_import/pandapower_toolset_node_breaker.py
preprocess_net_step1
#
General preprocessing - e.g. a PowerFactory network may converge in AC -> change elements.
Step 1: General preprocessing - select connected subnet - Remove zero branches - remove out of service elements - handle_constant_z_load - drop elements connected to one bus - replace xward by internal elements - replace ward by internal elements - drop controler
| PARAMETER | DESCRIPTION |
|---|---|
net
|
pandapower network Note: the network is modified in place
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
net
|
modified pandapower network
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/pandapower_import/preprocessing.py
preprocess_net_step2_master_asset_topology
#
Run pandapower preprocessing step 2 on canonical master data.
Source code in packages/importer_pkg/src/toop_engine_importer/pandapower_import/preprocessing.py
validate_asset_topology_stations
#
Validate canonical station connection counts directly against the pandapower network.
Source code in packages/importer_pkg/src/toop_engine_importer/pandapower_import/preprocessing.py
Importer Pypowsybl#
toop_engine_importer.pypowsybl_import
#
Import data from PyPowSyBl networks to the Topology Optimizer.
__all__
module-attribute
#
__all__ = [
"NetworkMasks",
"PowsyblSecurityAnalysisParam",
"PreProcessingStatistics",
"apply_cb_lists",
"apply_preprocessing_changes_to_network",
"apply_white_list_to_operational_limits",
"assign_element_id_to_cb_df",
"convert_file",
"convert_low_impedance_lines",
"create_default_network_masks",
"get_branches_df_with_element_name",
"get_bus_breaker_master_asset_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, boundary_line_for_nminus1, generator_for_nminus1, load_for_nminus1, switches_for_nminus1 white_list, black_list
border_current
class-attribute
instance-attribute
#
Contains the statistics of the current limit for the lines that leave the tso area.
network_changes
class-attribute
instance-attribute
#
Contains the statistics of the changes made to the network. keys: black_list, white_list, low_impedance_lines, branches_across_switch
import_parameter
class-attribute
instance-attribute
#
Contains the statistics of the post processing.
get_bus_breaker_master_asset_topology
#
get_bus_breaker_master_asset_topology(
network,
relevant_stations,
topology_id,
grid_model_file=None,
)
Return canonical topology master data derived from the current bus-breaker structure.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
Source powsybl network.
TYPE:
|
relevant_stations
|
Relevant stations as bus ids or as a boolean mask over
TYPE:
|
topology_id
|
Identifier to store on the resulting master data.
TYPE:
|
grid_model_file
|
Source grid-model file name stored in the master data.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
MasterAssetTopology
|
Canonical master data grouped by structural bus-breaker station views. |
Source code in packages/grid_helpers_pkg/src/toop_engine_grid_helpers/powsybl/powsybl_asset_topo.py
837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 | |
apply_white_list_to_operational_limits
#
Apply the white list to the operational limits of the network.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
The network to modify. Note: The network is modified in place.
TYPE:
|
white_list_df
|
DataFrame with the columns "element_id", "Anfangsknoten", "Endknoten", "Auslastungsgrenze_n_0", "Auslastungsgrenze_n_1"
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/dacf_whitelists.py
assign_element_id_to_cb_df
#
Get the element_id for the elements in the cb_df based on the power network model.
| PARAMETER | DESCRIPTION |
|---|---|
branches_with_elementname
|
powsybl branches DataFrame with the columns "elementName", "bus_breaker_bus1_id", "bus_breaker_bus2_id", "voltage_level1_id", "voltage_level2_id", "pairing_key"
TYPE:
|
cb_df
|
DataFrame with the columns "Elementname", "Anfangsknoten", "Endknoten" Note: The element_id column is added to the DataFrame in place
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
None
|
|
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/dacf_whitelists.py
apply_cb_lists
#
Run the black or white list to the powsybl network.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
The network to modify. Note: The network is modified in place.
TYPE:
|
statistics
|
The statistics to fill with the id lists of the black and white list Note: The statistics are modified in place.
TYPE:
|
white_list_file
|
The path to the white list file, if None, no white list is applied.
TYPE:
|
black_list_file
|
The path to the black list file, if None, no black list is applied.
TYPE:
|
fs
|
The filesystem to use to read the files.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
statistics
|
The statistics with the id lists of the black and white list
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/network_analysis.py
convert_low_impedance_lines
#
Convert all lines in the same voltage level with very low impedance to breakers.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The network to modify. Note: This function modifies the network in place.
TYPE:
|
voltage_level_prefix
|
The prefix of the voltage level to consider.
TYPE:
|
x_threshold_line
|
The threshold for x, everything below will be converted.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
low_impedance_lines
|
The lines that were converted to breakers.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/network_analysis.py
get_branches_df_with_element_name
#
Get the branches with the element name.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
The network object
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
The branches with the element name |
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/network_analysis.py
remove_branches_across_switch
#
Remove all branches that span across a closed switch, i.e. have the same from+to bus.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The network to modify. Note: This function modifies the network in place.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
to_remove
|
The branches that were removed.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/network_analysis.py
make_masks
#
Create all masks for the network, depending on the import parameters.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
The network to get the masks for.
TYPE:
|
slack_id
|
The id of the slack bus in the network. This is needed to exclude the slack bus from the relevant_subs mask.
TYPE:
|
importer_parameters
|
The import parameters including control_area, nminus1_area, cutoff_voltage Optional: border_line_factors, border_line_weight, dso_trafo_factors, dso_trafo_weight
TYPE:
|
filesystem
|
The filesystem to use for loading the contingency lists from. If not provided, the local filesystem is used.
TYPE:
|
blacklisted_ids
|
The ids of the branche that are blacklisted.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
network_masks
|
The masks for the network.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/powsybl_masks.py
save_masks_to_files
#
Save the network masks to files.
| PARAMETER | DESCRIPTION |
|---|---|
network_masks
|
The network masks to save.
TYPE:
|
data_folder
|
The folder to save the masks to.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/powsybl_masks.py
validate_network_masks
#
Validate if the network masks are created correctly.
| PARAMETER | DESCRIPTION |
|---|---|
network_masks
|
The network masks to validate.
TYPE:
|
default_mask
|
The default network masks to validate against.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if the network masks are created correctly, False otherwise. |
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/powsybl_masks.py
apply_preprocessing_changes_to_network
#
Apply the default changes to the network.
These changes include: - removing low impedance lines - removing branches across switches
| PARAMETER | DESCRIPTION |
|---|---|
network
|
The network to apply the changes to. Note: This function modifies the network in place.
TYPE:
|
statistics
|
The statistics of the preprocessing. Note: This function modifies the statistics in place.
TYPE:
|
status_update_fn
|
A function to call to signal progress in the preprocessing pipeline. Takes a stage and an optional message as parameters
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/preprocessing.py
convert_file
#
convert_file(
importer_parameters,
status_update_fn=empty_status_update_fn,
processed_gridfile_fs=None,
unprocessed_gridfile_fs=None,
)
Convert the grid file to a format that can be used by the preprocessing.
Saves data and network to the output folder.
| PARAMETER | DESCRIPTION |
|---|---|
importer_parameters
|
Parameters that are required to import the data from a UCTE or CGMES file. This will utilize powsybl and the powsybl backend to the loadflow solver
TYPE:
|
status_update_fn
|
A function to call to signal progress in the preprocessing pipeline. Takes a stage, an optional message and network stats as parameters
TYPE:
|
processed_gridfile_fs
|
A filesystem where the processed gridfiles are stored. If None, the local filesystem is used
TYPE:
|
unprocessed_gridfile_fs
|
A filesystem where the unprocessed gridfiles are stored. If None, the local filesystem is used.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ImportResult
|
The result of the import process. |
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/preprocessing.py
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 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 | |
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
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 | |
load_and_prepare_network
#
load_and_prepare_network(
importer_parameters,
processed_gridfile_fs,
unprocessed_gridfile_fs,
status_update_fn,
)
Copy, load, and normalize the input network before preprocessing.
| PARAMETER | DESCRIPTION |
|---|---|
importer_parameters
|
Parameters describing the input grid file and output folder.
TYPE:
|
processed_gridfile_fs
|
Filesystem where the original input grid is archived.
TYPE:
|
unprocessed_gridfile_fs
|
Filesystem from which the input grid is loaded.
TYPE:
|
status_update_fn
|
Callback used to report preprocessing progress.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Network
|
The loaded and normalized network. |
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 grid file to a format that can be used by the preprocessing.
Saves data and network to the output folder.
| PARAMETER | DESCRIPTION |
|---|---|
importer_parameters
|
Parameters that are required to import the data from a UCTE or CGMES file. This will utilize powsybl and the powsybl backend to the loadflow solver
TYPE:
|
status_update_fn
|
A function to call to signal progress in the preprocessing pipeline. Takes a stage, an optional message and network stats as parameters
TYPE:
|
processed_gridfile_fs
|
A filesystem where the processed gridfiles are stored. If None, the local filesystem is used
TYPE:
|
unprocessed_gridfile_fs
|
A filesystem where the unprocessed gridfiles are stored. If None, the local filesystem is used.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ImportResult
|
The result of the import process. |
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/preprocessing.py
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 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 | |
compute_network_masks_and_n_1_definition
#
compute_network_masks_and_n_1_definition(
importer_parameters,
processed_gridfile_fs,
unprocessed_gridfile_fs,
network,
statistics,
)
Create, persist, and return network masks plus the derived N-1 definition.
| PARAMETER | DESCRIPTION |
|---|---|
importer_parameters
|
Import configuration providing the data folder and mask generation settings.
TYPE:
|
processed_gridfile_fs
|
Filesystem used to persist the generated masks and N-1 definition.
TYPE:
|
unprocessed_gridfile_fs
|
Filesystem used to resolve auxiliary inputs required during mask creation.
TYPE:
|
network
|
Powsybl network for which masks and contingencies are computed.
TYPE:
|
statistics
|
Statistics object updated while generating masks.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NetworkMasks
|
Generated network masks after saving them and the derived N-1 definition. |
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/preprocessing.py
get_slack_ids
#
Get the slack bus ids from the network.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
The network to get the slack bus ids from.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[str] | None
|
The list of slack bus ids. |
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/preprocessing.py
find_converging_loadflow_params
#
Iterate over Loadflow parameters and voltage initialization methods to find a converging loadflow.
This is necessary because some grid files do not converge with the default loadflow parameters and voltage initialization method.
| PARAMETER | DESCRIPTION |
|---|---|
importer_parameters
|
The importer parameters to use for the loadflow parameters.
TYPE:
|
network
|
The network to run the loadflow on.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tuple[Parameters, ComponentResult]
|
The loadflow parameters that converged and the result of the loadflow with those parameters. |
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/preprocessing.py
get_network_masks
#
Create network masks and save them.
| PARAMETER | DESCRIPTION |
|---|---|
network
|
The network to create the asset topology for
TYPE:
|
slack_id
|
The id of the slack bus
TYPE:
|
importer_parameters
|
import parameters that include the datafolder
TYPE:
|
statistics
|
preprocessing statistics to fill with information
TYPE:
|
filesystem
|
The filesystem to load the mask files from.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
NetworkMasks
|
The created network masks |
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/preprocessing.py
get_master_asset_topology_artifact
#
Return canonical asset-topology master data for preprocessing persistence.
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/preprocessing.py
apply_preprocessing_changes_to_network
#
Apply the default changes to the network.
These changes include: - removing low impedance lines - removing branches across switches
| PARAMETER | DESCRIPTION |
|---|---|
network
|
The network to apply the changes to. Note: This function modifies the network in place.
TYPE:
|
statistics
|
The statistics of the preprocessing. Note: This function modifies the statistics in place.
TYPE:
|
status_update_fn
|
A function to call to signal progress in the preprocessing pipeline. Takes a stage and an optional message as parameters
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/pypowsybl_import/preprocessing.py
fill_statistics_for_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
Importer Network Graph Pandapower#
toop_engine_importer.network_graph
#
Importer-specific network-graph helpers.
__all__
module-attribute
#
__all__ = [
"get_branch_df",
"get_network_graph",
"get_network_graph_data",
"get_nodes",
"get_switches_df",
]
get_branch_df
#
Get the branches data from the pandapower network and return a df ready to use for the BranchSchema.
Note: A star equivalent transformation for three winding trafos is not needed before calling this module. The the graph module only needs the connection and does no calculation.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The pandapower network.
TYPE:
|
only_relevant_col
|
Whether to return only the relevant columns, by default True relevant is determined by the default BranchSchema columns
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
branch_df
|
The DataFrame containing the branches in the format of the BranchSchema.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/pandapower_network_to_graph.py
get_network_graph
#
Get the network graph from the NetworkGraphData and run default filter.
| PARAMETER | DESCRIPTION |
|---|---|
network_graph_data
|
The NetworkGraphData containing the nodes, switches, branches and node_assets.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Graph
|
The network graph. |
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/pandapower_network_to_graph.py
get_network_graph_data
#
Get the network graph from the pandapower network.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The pandapower network.
TYPE:
|
only_relevant_col
|
Whether to return only the relevant columns, by default True relevant is determined by the default BranchSchema columns
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
net_graph
|
The network graph in the format of the NetworkGraph class. Contains the full network with all substations.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/pandapower_network_to_graph.py
get_nodes
#
Get the nodes data from the pandapower network and return a df ready to use for the NodeSchema.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The pandapower network.
TYPE:
|
only_relevant_col
|
Whether to return only the relevant columns, by default True relevant is determined by the default NodeSchema columns
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
nodes_df
|
The DataFrame containing the nodes in the format of the NodeSchema.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/pandapower_network_to_graph.py
get_switches_df
#
Get the switches data from the pandapower network and return a df ready to use for the SwitchSchema.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The pandapower network.
TYPE:
|
only_relevant_col
|
Whether to return only the relevant columns, by default True relevant is determined by the default SwitchSchema columns
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
switches_df
|
The DataFrame containing the switches in the format of the SwitchSchema.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/pandapower_network_to_graph.py
toop_engine_importer.network_graph.pandapower_network_to_graph
#
Convert a pandapower network to a network graph.
get_network_graph_data
#
Get the network graph from the pandapower network.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The pandapower network.
TYPE:
|
only_relevant_col
|
Whether to return only the relevant columns, by default True relevant is determined by the default BranchSchema columns
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
net_graph
|
The network graph in the format of the NetworkGraph class. Contains the full network with all substations.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/pandapower_network_to_graph.py
get_network_graph
#
Get the network graph from the NetworkGraphData and run default filter.
| PARAMETER | DESCRIPTION |
|---|---|
network_graph_data
|
The NetworkGraphData containing the nodes, switches, branches and node_assets.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Graph
|
The network graph. |
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/pandapower_network_to_graph.py
get_edges_data
#
Get the edges data from the dataframe and return a df ready to use for the BranchSchema.
Can be used for switches, trafos and other branches.
| PARAMETER | DESCRIPTION |
|---|---|
dataframe
|
The DataFrame containing the edges.
TYPE:
|
asset_type
|
The type of the asset.
TYPE:
|
only_relevant_col
|
Whether to return only the relevant columns, by default True relevant is determined by the default BranchSchema columns
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
The DataFrame containing the edges in the format of the |
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/pandapower_network_to_graph.py
get_nodes
#
Get the nodes data from the pandapower network and return a df ready to use for the NodeSchema.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The pandapower network.
TYPE:
|
only_relevant_col
|
Whether to return only the relevant columns, by default True relevant is determined by the default NodeSchema columns
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
nodes_df
|
The DataFrame containing the nodes in the format of the NodeSchema.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/pandapower_network_to_graph.py
get_switches_df
#
Get the switches data from the pandapower network and return a df ready to use for the SwitchSchema.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The pandapower network.
TYPE:
|
only_relevant_col
|
Whether to return only the relevant columns, by default True relevant is determined by the default SwitchSchema columns
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
switches_df
|
The DataFrame containing the switches in the format of the SwitchSchema.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/pandapower_network_to_graph.py
get_branch_df
#
Get the branches data from the pandapower network and return a df ready to use for the BranchSchema.
Note: A star equivalent transformation for three winding trafos is not needed before calling this module. The the graph module only needs the connection and does no calculation.
| PARAMETER | DESCRIPTION |
|---|---|
net
|
The pandapower network.
TYPE:
|
only_relevant_col
|
Whether to return only the relevant columns, by default True relevant is determined by the default BranchSchema columns
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
branch_df
|
The DataFrame containing the branches in the format of the BranchSchema.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/network_graph/pandapower_network_to_graph.py
Exporter#
toop_engine_importer.exporter
#
Export data from the AICoE_HPC_RL_Optimizer back to the original format.
asset_topology_to_dgs.py: Translate asset topology model to a DGS file (PowerFactory).asset_topology_to_ucte.py: Translate asset topology model to a UCTE file.uct_exporter.py: Translate a RealizedTopology json file to a UCTE file.
__all__
module-attribute
#
asset_topo_to_uct
#
asset_topo_to_uct(
master_data,
grid_model_file_output,
starting_stations=None,
grid_model_file_input=None,
station_list=None,
)
Translate asset topology model to UCT and saves the model.
| PARAMETER | DESCRIPTION |
|---|---|
master_data
|
Canonical master data describing the exported topology.
TYPE:
|
grid_model_file_output
|
Path to save the UCTE file.
TYPE:
|
starting_stations
|
Optional runtime-aware station snapshots to export directly. If not provided,
they are materialized from
TYPE:
|
grid_model_file_input
|
Path to the grid model file. If not provided,
TYPE:
|
station_list
|
List of station ids to be translated. If not provided, all stations in the asset_topology will be translated.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
NotImplementedError
|
If master_data.asset_setpoints is not None. |
Source code in packages/importer_pkg/src/toop_engine_importer/exporter/asset_topology_to_ucte.py
load_ucte
#
Load UCTE file and return its contents as separate dataframes.
| PARAMETER | DESCRIPTION |
|---|---|
input_uct
|
Path to the UCTE file.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
preamble
|
Preamble of the UCTE file.
TYPE:
|
nodes
|
Nodes of the UCTE file.
TYPE:
|
lines
|
Lines of the UCTE file.
TYPE:
|
trafos
|
Transformers of the UCTE file.
TYPE:
|
trafo_reg
|
Transformer regulation of the UCTE file.
TYPE:
|
postamble
|
Postamble of the UCTE file.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/exporter/asset_topology_to_ucte.py
process_file
#
process_file(
input_uct,
input_json,
output_uct,
topo_id=0,
reassign_branches=True,
reassign_injections=False,
)
Process a UCTE file and a preprocessed json file to include split substations.
| PARAMETER | DESCRIPTION |
|---|---|
input_uct
|
The path to the input UCTE file, the original UCTE
TYPE:
|
input_json
|
The preprocessed json holding the split substations and information, use the loadflowsolver's preprocessing notebook to generate this
TYPE:
|
output_uct
|
The path to the output UCTE file, will be overwritten
TYPE:
|
topo_id
|
The id of the topology to use in the json file
TYPE:
|
reassign_branches
|
If True, reassign branches to the new busbars
TYPE:
|
reassign_injections
|
If True, reassign injections to the new busbars Note: not implemented yet
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[str]
|
The codes of the fake busbars that were inserted |
Source code in packages/importer_pkg/src/toop_engine_importer/exporter/uct_exporter.py
validate_ucte_changes
#
Validate the changes made to the UCTE file.
| PARAMETER | DESCRIPTION |
|---|---|
ucte_contents
|
The original UCTE file
TYPE:
|
ucte_contents_out
|
The modified UCTE file
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
RuntimeError
|
If the changes are not as expected |
Source code in packages/importer_pkg/src/toop_engine_importer/exporter/uct_exporter.py
toop_engine_importer.exporter.asset_topology_to_ucte
#
Module containing functions to translate asset topology model to UCT model.
File: asset_topology_to_uct.py Author: Benjamin Petrick Created: 2024-10-22
Note: this module currently ignores the asset_setpoints. Note: this module currently ignores generator and load reassignments.
UCTE_STATUS_CODES
module-attribute
#
UCTE_STATUS_CODES = {
0: {"name": "in_service", "opposite": 8},
1: {"name": "in_service", "opposite": 9},
2: {"name": "in_service", "opposite": 7},
7: {"name": "out_of_service", "opposite": 2},
8: {"name": "out_of_service", "opposite": 0},
9: {"name": "out_of_service", "opposite": 1},
}
load_ucte
#
Load UCTE file and return its contents as separate dataframes.
| PARAMETER | DESCRIPTION |
|---|---|
input_uct
|
Path to the UCTE file.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
preamble
|
Preamble of the UCTE file.
TYPE:
|
nodes
|
Nodes of the UCTE file.
TYPE:
|
lines
|
Lines of the UCTE file.
TYPE:
|
trafos
|
Transformers of the UCTE file.
TYPE:
|
trafo_reg
|
Transformer regulation of the UCTE file.
TYPE:
|
postamble
|
Postamble of the UCTE file.
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/exporter/asset_topology_to_ucte.py
asset_topo_to_uct
#
asset_topo_to_uct(
master_data,
grid_model_file_output,
starting_stations=None,
grid_model_file_input=None,
station_list=None,
)
Translate asset topology model to UCT and saves the model.
| PARAMETER | DESCRIPTION |
|---|---|
master_data
|
Canonical master data describing the exported topology.
TYPE:
|
grid_model_file_output
|
Path to save the UCTE file.
TYPE:
|
starting_stations
|
Optional runtime-aware station snapshots to export directly. If not provided,
they are materialized from
TYPE:
|
grid_model_file_input
|
Path to the grid model file. If not provided,
TYPE:
|
station_list
|
List of station ids to be translated. If not provided, all stations in the asset_topology will be translated.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
NotImplementedError
|
If master_data.asset_setpoints is not None. |
Source code in packages/importer_pkg/src/toop_engine_importer/exporter/asset_topology_to_ucte.py
change_trafos_lines_in_ucte
#
Change the 'from' and 'to' columns of the trafos or line DataFrame based on the change_df.
| PARAMETER | DESCRIPTION |
|---|---|
ucte_df
|
The ucte trafos or line DataFrame Note: The DataFrame should have 'from', 'to', 'order' columns Note: The DataFrame is modified in place
TYPE:
|
change_df
|
The change_df, containing the 'grid_model_id', 'initial_busbar' and 'final_busbar' columns
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
None
|
|
Source code in packages/importer_pkg/src/toop_engine_importer/exporter/asset_topology_to_ucte.py
update_busbar_name
#
Update 'from' and 'to' columns based on 'initial_busbar' and 'final_busbar'.
| PARAMETER | DESCRIPTION |
|---|---|
row
|
A row of the DataFrame
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Series
|
The updated row |
Source code in packages/importer_pkg/src/toop_engine_importer/exporter/asset_topology_to_ucte.py
disconnect_line_from_ucte
#
Disconnect a line from UCTE.
Note: a switch is modeled as a line in UCTE. To differentiate between a switch and a line, different status codes are used.
| PARAMETER | DESCRIPTION |
|---|---|
line_row
|
A row of the line DataFrame from the parse_ucte() function
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Series
|
The updated row can be used to update the line DataFrame |
Source code in packages/importer_pkg/src/toop_engine_importer/exporter/asset_topology_to_ucte.py
change_busbar_coupler_state
#
Change the 'status' columns of the lines DataFrame based on the change_df.
| PARAMETER | DESCRIPTION |
|---|---|
lines_df
|
The lines DataFrame Note: The DataFrame should have 'from', 'to', 'status' columns Note: The DataFrame is modified in place
TYPE:
|
change_df
|
The change_df, containing the 'grid_model_id' and 'coupler_state_ucte' columns
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/exporter/asset_topology_to_ucte.py
update_coupler_state
#
Update 'status' column based on 'coupler_state_ucte'.
| PARAMETER | DESCRIPTION |
|---|---|
row
|
A row of the DataFrame
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Series
|
The updated row |
Source code in packages/importer_pkg/src/toop_engine_importer/exporter/asset_topology_to_ucte.py
get_coupler_state_ucte
#
Get coupler ucte state of from a BusbarCoupler.
| PARAMETER | DESCRIPTION |
|---|---|
couplers
|
BusbarCoupler object from the asset topology model
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[dict[str, Union[str, int]]]
|
List of dictionaries containing the coupler_name and the state of the coupler in UCTE format 2: busbar coupler in operation (definition: R=0, X=0, B=0) 7: busbar coupler out of operation (definition: R=0, X=0, B=0) |
Source code in packages/importer_pkg/src/toop_engine_importer/exporter/asset_topology_to_ucte.py
get_changes_from_switching_table
#
Get changes from switching table.
| PARAMETER | DESCRIPTION |
|---|---|
station
|
Station object with switching table, busbars and assets
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[dict[str, Union[str, None]]]
|
List of tuples with asset name, initial_busbar and final_busbar Note: initial_busbar and final_busbar can both be None if asset is disconnected |
Source code in packages/importer_pkg/src/toop_engine_importer/exporter/asset_topology_to_ucte.py
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 | |
handle_duplicated_grid_ids
#
Handle duplicated grid ids in the ucte file.
The function will increment the order of the duplicated grid ids by 1.
| PARAMETER | DESCRIPTION |
|---|---|
ucte_df
|
The ucte DataFrame to be updated Note: The DataFrame should have 'from', 'to', 'order' columns Note: The DataFrame is modified in place
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/exporter/asset_topology_to_ucte.py
toop_engine_importer.exporter.uct_exporter
#
Module containing functions to translate a RealizedTopology json file to a UCTE file.
DeprecationWarning: This module is deprecated and will be removed in the future, due to deprecation of RealizedTopology. Use Topology (AssetTopology) instead.
File: ucte_exporter.py Author: Benjamin Petrick Created: 2024
Note: this module ignores generator and load reassignments.
process_file
#
process_file(
input_uct,
input_json,
output_uct,
topo_id=0,
reassign_branches=True,
reassign_injections=False,
)
Process a UCTE file and a preprocessed json file to include split substations.
| PARAMETER | DESCRIPTION |
|---|---|
input_uct
|
The path to the input UCTE file, the original UCTE
TYPE:
|
input_json
|
The preprocessed json holding the split substations and information, use the loadflowsolver's preprocessing notebook to generate this
TYPE:
|
output_uct
|
The path to the output UCTE file, will be overwritten
TYPE:
|
topo_id
|
The id of the topology to use in the json file
TYPE:
|
reassign_branches
|
If True, reassign branches to the new busbars
TYPE:
|
reassign_injections
|
If True, reassign injections to the new busbars Note: not implemented yet
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[str]
|
The codes of the fake busbars that were inserted |
Source code in packages/importer_pkg/src/toop_engine_importer/exporter/uct_exporter.py
validate_ucte_changes
#
Validate the changes made to the UCTE file.
| PARAMETER | DESCRIPTION |
|---|---|
ucte_contents
|
The original UCTE file
TYPE:
|
ucte_contents_out
|
The modified UCTE file
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
RuntimeError
|
If the changes are not as expected |
Source code in packages/importer_pkg/src/toop_engine_importer/exporter/uct_exporter.py
is_split
#
get_switch_group_number
#
Decide which switch group to open. Selects the group with the fewest unique busbars.
| PARAMETER | DESCRIPTION |
|---|---|
grouped_switches
|
The grouped switches data-frame from group_switches(). Each key contains all switches necessary to isolate a busbar
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
reassignment_key
|
The dict key of the switch group to open
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/exporter/uct_exporter.py
find_switches
#
Find the all switches on the input node.
| PARAMETER | DESCRIPTION |
|---|---|
lines
|
The lines data-frame from UCTE file
TYPE:
|
node_id
|
The node id(s) to search for switches. Note: expects switches to be closed -> status = 2 (closed) Note: this is the first 7 characters of the id (Node), not the full id of busbar that has one additional character
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
switches
|
All switches found on the input node, with status = 2 (closed)
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/exporter/uct_exporter.py
get_unique_busbars
#
Get the unique busbars from the switches.
| PARAMETER | DESCRIPTION |
|---|---|
switches
|
The switches data-frame from find_switches()
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
unique_busbars
|
A list of unique busbars found in the switches
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/exporter/uct_exporter.py
group_switches
#
Group the switches by the busbar id.
There can be multiple switches between the same busbars. This function groups them together. One list element is one group of switches to isolate the bus completely.
| PARAMETER | DESCRIPTION |
|---|---|
switches
|
All switches data-frame from UCTE file from a specific node
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
switches_sort
|
A dict of switches data-frames sorted by the busbar id
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/exporter/uct_exporter.py
get_bus_a_b
#
Get the bus A and B from the switches.
| PARAMETER | DESCRIPTION |
|---|---|
switches
|
The switches data-frame from find_switches()
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bus_a
|
The bus A of the substation
TYPE:
|
bus_b
|
The bus B of the substation
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the switches contain switches from multiple nodes. |
Source code in packages/importer_pkg/src/toop_engine_importer/exporter/uct_exporter.py
open_switches
#
Open switches in the UCTE data by changing the status code value.
| PARAMETER | DESCRIPTION |
|---|---|
lines
|
The lines data-frame from UCTE file Note: modifies the data-frames in place
TYPE:
|
switches
|
The switches data-frame from find_switches() Note: modifies the data-frames in place
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
stats
|
A dictionary containing the bus A and B of the substation, the number of switches and the from and to busbar of the switches
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/exporter/uct_exporter.py
handle_order_of_branch
#
Get a unique order number of the branch for new id.
| PARAMETER | DESCRIPTION |
|---|---|
branch_df
|
The branch data-frame from UCTE file. e.g. lines or trafos or trafo_reg
TYPE:
|
replacement_id
|
The replacement ID of the branch
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
order
|
The order of the branch
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/exporter/uct_exporter.py
find_branch_index
#
Find the index of the branch in the UCTE data.
| PARAMETER | DESCRIPTION |
|---|---|
branch_df
|
The branch data-frame from UCTE file. e.g. lines or trafos or trafo_reg
TYPE:
|
id
|
The ID of the branch
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
branch_df_idx
|
The index of the branch in the data-frame
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/exporter/uct_exporter.py
execute_branch_assignment
#
Apply branch assignment to the UCTE data.
| PARAMETER | DESCRIPTION |
|---|---|
branch_df
|
The branch data-frame from UCTE file. e.g. lines or trafos or trafo_reg Note: modifies the data-frames in place
TYPE:
|
id
|
The original ID of the branch
TYPE:
|
replacement_id
|
The replacement ID of the branch
TYPE:
|
statistics_all_stations
|
The statistics dictionary from process_file() expects as input the statistics["changed_ids"] dictionary
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
replaced
|
True if the branch was replaced, False if the branch was not found in the data-frame
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/exporter/uct_exporter.py
get_replacement_id
#
Get the replacement ID of the branch.
Decides if the element is on bus A or B and replaces the ID accordingly. Bus A is a logical bus and can be electrically connected to other buses e.g. bus C. Bus B is the new Bus that will be split off.
| PARAMETER | DESCRIPTION |
|---|---|
element
|
The element to replace imported from the json
TYPE:
|
code
|
The code of the substation
TYPE:
|
bus_a
|
The bus A of the substation
TYPE:
|
bus_b
|
The bus B of the substation
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
replacement_id
|
The replacement ID of the branch
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/exporter/uct_exporter.py
update_id_if_has_been_replaced
#
Update the ID if it has been replaced in the statistics.
Each branch has a "from" and "to" bus. It can oocur that e.g. the "from" bus has been already replaced, but the "to" bus not. This function checks if the ID has been replaced and returns the new ID if it has been replaced.
| PARAMETER | DESCRIPTION |
|---|---|
id
|
The ID of the branch, which might have been replaced
TYPE:
|
statistics
|
The statistics dictionary from process_file() expects as input the statistics["changed_ids"] dictionary
TYPE:
|
Source code in packages/importer_pkg/src/toop_engine_importer/exporter/uct_exporter.py
apply_branch_assignment
#
apply_branch_assignment(
topology_optimizer_results,
lines,
trafos,
trafo_reg,
bus_a,
bus_b,
statistics_all_stations,
)
Apply branch assignment to the UCTE data.
Uses the method to split a busbar into two busbars A and B
| PARAMETER | DESCRIPTION |
|---|---|
topology_optimizer_results
|
The substation split to apply from the postprocessed json
TYPE:
|
lines
|
The lines data-frame from UCTE file Note: modifies the data-frames in place
TYPE:
|
trafos
|
The transformers data-frame from UCTE file Note: modifies the data-frames in place
TYPE:
|
trafo_reg
|
The transformer regulation data-frame from UCTE file Note: modifies the data-frames in place
TYPE:
|
bus_a
|
The bus A of the substation
TYPE:
|
bus_b
|
The bus B of the substation
TYPE:
|
statistics_all_stations
|
The statistics dictionary from process_file()
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
statistics
|
A list of dictionaries containing the original and replacement IDs of the branches that were modified
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
|
Source code in packages/importer_pkg/src/toop_engine_importer/exporter/uct_exporter.py
497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 | |