edisgo.tools.spatial_complexity_reduction
¶
Module Contents¶
Functions¶

Return buses with load and voltage issues, determined doing a worstcase powerflow 

Rename virtual buses so that no virtual transformer bus is created. 

Method to remove end lines under 1 meter to reduce size of edisgo object. 

Remove the lines under one meter. Sometimes these line are causing convergence 

Making busmap for the cluster area 'grid'. 

Making busmap for the cluster area 'feeder'. 

Making busmap for the cluster area 'main_feeder'. 

Determines which busses are clustered. 

Function to reduce the EDisGo object with a previously generated busmap. 

Reduces the number of busses and lines by applying a spatial clustering. 

Compares the voltages per node between the unreduced and the reduced EDisGo object. 

Compares the apparent power over each line between the unreduced and the reduced 
 edisgo.tools.spatial_complexity_reduction.find_buses_of_interest(edisgo_root: edisgo.EDisGo) set [source]¶
Return buses with load and voltage issues, determined doing a worstcase powerflow analysis.
 edisgo.tools.spatial_complexity_reduction.rename_virtual_buses(partial_busmap_df: pandas.DataFrame, transformer_node: str) pandas.DataFrame [source]¶
Rename virtual buses so that no virtual transformer bus is created.
 Parameters
partial_busmap_df (pandas.DataFrame) – Busmap to work on.
transformer_node (str) – Transformer node name.
 Returns
Busmap with applied changes.
 Return type
 edisgo.tools.spatial_complexity_reduction.remove_short_end_lines(edisgo_obj: edisgo.EDisGo)[source]¶
Method to remove end lines under 1 meter to reduce size of edisgo object.
Short lines inside at the end are removed in this function, including the end node. Components that were originally connected to the end node are reconnected to the upstream node.
This function does currently not remove short lines that are no end lines.
 Parameters
edisgo (
EDisGo
) –
 edisgo.tools.spatial_complexity_reduction.remove_lines_under_one_meter(edisgo_obj: edisgo.EDisGo) edisgo.EDisGo [source]¶
Remove the lines under one meter. Sometimes these line are causing convergence problems of the power flow calculation or making problems with the clustering methods.
Function might be a bit overengineered, so that the station bus is never dropped.
 edisgo.tools.spatial_complexity_reduction.make_busmap_grid(edisgo_obj: edisgo.EDisGo, grid: None  str = None, mode: str = 'kmeansdijkstra', reduction_factor: float = 0.25, preserve_trafo_bus_coordinates: bool = True) pandas.DataFrame [source]¶
Making busmap for the cluster area ‘grid’.
Every grid is clustered individually.
 Parameters
edisgo_obj (
EDisGo
) – EDisGo object for which the busmap is created.grid (str or None) – If None, busmap is created for all grids, else only for the selected grid. Default: None.
mode (str) – “kmeans” or “kmeansdijkstra” as clustering method. See parameter mode in function
spatial_complexity_reduction
for more information. Default: “kmeansdijkstra”.reduction_factor (float) – Factor to reduce number of nodes by. Must be between 0 and 1. Default: 0.25.
preserve_trafo_bus_coordinates (True) – If True, transformers have the same coordinates after the clustering, else the transformer coordinates are changed by the clustering. Default: True.
 Returns
Busmap which maps the old bus names to the new bus names with new coordinates. See return value in function
make_busmap()
for more information. Return type
References
In parts based on PyPSA spatial complexity reduction.
 edisgo.tools.spatial_complexity_reduction.make_busmap_feeders(edisgo_obj: edisgo.EDisGo = None, grid: None  Grid = None, mode: str = 'kmeansdijkstra', reduction_factor: float = 0.25, reduction_factor_not_focused: bool  float = False) pandas.DataFrame [source]¶
Making busmap for the cluster area ‘feeder’.
Every feeder is clustered individually.
 Parameters
edisgo_obj (
EDisGo
) – EDisGo object for which the busmap is created.grid (str or None) – If None, busmap is created for all grids, else only for the selected grid. Default: None.
mode (str) – “kmeans” or “kmeansdijkstra” as clustering method. See parameter mode in function
spatial_complexity_reduction
for more information. Default: “kmeansdijkstra”.reduction_factor (float) – Factor to reduce number of nodes by. Must be between 0 and 1. Default: 0.25.
reduction_factor_not_focused (bool or float) – If False, the focus method is not used. If between 0 and 1, this sets the reduction factor for buses not of interest. See parameter reduction_factor_not_focused in function
make_busmap()
for more information. Default: False.
 Returns
Busmap which maps the old bus names to the new bus names with new coordinates. See return value in function
make_busmap()
for more information. Return type
References
In parts based on PyPSA spatial complexity reduction.
 edisgo.tools.spatial_complexity_reduction.make_busmap_main_feeders(edisgo_obj: edisgo.EDisGo = None, grid: None  Grid = None, mode: str = 'kmeansdijkstra', reduction_factor: float = 0.25, reduction_factor_not_focused: bool  float = False) pandas.DataFrame [source]¶
Making busmap for the cluster area ‘main_feeder’.
Every main feeder is clustered individually. The main feeder is selected as the longest path in the feeder. All nodes are aggregated to this main feeder and then the feeder is clustered.
 Parameters
edisgo_obj (
EDisGo
) – EDisGo object for which the busmap is created.grid (str or None) – If None, busmap is created for all grids, else only for the selected grid. Default: None.
mode (str) – “kmeans”, “kmeansdijkstra”, “aggregate_to_main_feeder” or “equidistant_nodes” as clustering method. See parameter mode in function
spatial_complexity_reduction
for more information. Default: “kmeansdijkstra”.reduction_factor (float) – Factor to reduce number of nodes by. Must be between 0 and 1. Default: 0.25.
reduction_factor_not_focused (bool or float) – If False, the focus method is not used. If between 0 and 1, this sets the reduction factor for buses not of interest. See parameter reduction_factor_not_focused in function
make_busmap()
for more information. Default: False.
 Returns
Busmap which maps the old bus names to the new bus names with new coordinates. See return value in function
make_busmap()
for more information. Return type
References
In parts based on PyPSA spatial complexity reduction.
 edisgo.tools.spatial_complexity_reduction.make_busmap(edisgo_obj: edisgo.EDisGo, mode: str = 'kmeansdijkstra', cluster_area: str = 'feeder', reduction_factor: float = 0.25, reduction_factor_not_focused: bool  float = False, grid: None  Grid = None) pandas.DataFrame [source]¶
Determines which busses are clustered.
The information on which original busses are clustered to which new busses is given in the socalled busmap dataframe. The busmap can be used with the function
apply_busmap()
to perform a spatial complexity reduction. Parameters
edisgo_obj (
EDisGo
) – EDisGo object for which the busmap is created.mode (str) – Clustering method to use. See parameter mode in function
spatial_complexity_reduction
for more information.cluster_area (str) – The cluster area is the area the different clustering methods are applied to. Possible options are ‘grid’, ‘feeder’ or ‘main_feeder’. Default: “feeder”.
reduction_factor (float) – Factor to reduce number of nodes by. Must be between 0 and 1. Default: 0.25.
reduction_factor_not_focused (bool or float) – If False, uses the same reduction factor for all cluster areas. If between 0 and 1, this sets the reduction factor for buses not of interest (these are buses without voltage or overloading issues, that are determined through a worst case power flow analysis). When selecting 0, the nodes of the clustering area are aggregated to the transformer bus. This parameter is only used when parameter cluster_area is set to ‘feeder’ or ‘main_feeder’. Default: False.
grid (str or None) – If None, busmap is created for all grids, else only for the selected grid.
 Returns
Busmap which maps the old bus names to the new bus names with new coordinates. Columns are “new_bus” with new bus name, “new_x” with new xcoordinate and “new_y” with new ycoordinate. Index of the dataframe holds bus names of original buses as in buses_df.
 Return type
References
In parts based on PyPSA spatial complexity reduction.
 edisgo.tools.spatial_complexity_reduction.apply_busmap(edisgo_obj: edisgo.EDisGo, busmap_df: pandas.DataFrame, line_naming_convention: str = 'standard_lines', aggregation_mode: bool = False, load_aggregation_mode: str = 'sector', generator_aggregation_mode: str = 'type') pandas.DataFrame [source]¶
Function to reduce the EDisGo object with a previously generated busmap.
Warning: After reduction, ‘in_building’ of all buses is set to False. Also, the method only works if all buses have x and y coordinates. If this is not the case, you can use the function
make_pseudo_coordinates()
to set coordinates for all buses. Parameters
edisgo_obj (
EDisGo
) – EDisGo object to reduce.busmap_df (pandas.DataFrame) – Busmap holding the information which nodes are merged together.
line_naming_convention (str) – Determines how to set “type_info” and “kind” in case two or more lines are aggregated. Possible options are “standard_lines” or “combined_name”. If “standard_lines” is selected, the values of the standard line of the respective voltage level are used to set “type_info” and “kind”. If “combined_name” is selected, “type_info” and “kind” contain the concatenated values of the merged lines. x and r of the lines are not influenced by this as they are always determined from the x and r values of the aggregated lines. Default: “standard_lines”.
aggregation_mode (bool) – Specifies, whether to aggregate loads and generators at the same bus or not. If True, loads and generators at the same bus are aggregated according to their selected modes (see parameters load_aggregation_mode and generator_aggregation_mode). Default: False.
load_aggregation_mode (str) – Specifies, how to aggregate loads at the same bus, in case parameter aggregation_mode is set to True. Possible options are “bus” or “sector”. If “bus” is chosen, loads are aggregated per bus. When “sector” is chosen, loads are aggregated by bus, type and sector. Default: “sector”.
generator_aggregation_mode (str) – Specifies, how to aggregate generators at the same bus, in case parameter aggregation_mode is set to True. Possible options are “bus” or “type”. If “bus” is chosen, generators are aggregated per bus. When “type” is chosen, generators are aggregated by bus and type.
 Returns
Linemap which maps the old line names (in the index of the dataframe) to the new line names (in column “new_line_name”).
 Return type
References
In parts based on PyPSA spatial complexity reduction.
 edisgo.tools.spatial_complexity_reduction.spatial_complexity_reduction(edisgo_obj: edisgo.EDisGo, mode: str = 'kmeansdijkstra', cluster_area: str = 'feeder', reduction_factor: float = 0.25, reduction_factor_not_focused: bool  float = False, apply_pseudo_coordinates: bool = True, **kwargs) tuple[pandas.DataFrame, pandas.DataFrame] [source]¶
Reduces the number of busses and lines by applying a spatial clustering.
See function
spatial_complexity_reduction
for more information. Parameters
edisgo_obj (
EDisGo
) – EDisGo object to apply spatial complexity reduction to.mode (str) – Clustering method to use. See parameter mode in function
spatial_complexity_reduction
for more information.cluster_area (str) – The cluster area is the area the different clustering methods are applied to. See parameter cluster_area in function
spatial_complexity_reduction
for more information.reduction_factor (float) – Factor to reduce number of nodes by. Must be between 0 and 1. Default: 0.25.
reduction_factor_not_focused (bool or float) – If False, uses the same reduction factor for all cluster areas. If between 0 and 1, this sets the reduction factor for buses not of interest. See parameter reduction_factor_not_focused in function
spatial_complexity_reduction
for more information.apply_pseudo_coordinates (bool) – If True pseudo coordinates are applied. The spatial complexity reduction method is only tested with pseudo coordinates. Default: True.
line_naming_convention (str) – Determines how to set “type_info” and “kind” in case two or more lines are aggregated. See parameter line_naming_convention in function
spatial_complexity_reduction
for more information.aggregation_mode (bool) – Specifies, whether to aggregate loads and generators at the same bus or not. See parameter aggregation_mode in function
spatial_complexity_reduction
for more information.load_aggregation_mode (str) – Specifies, how to aggregate loads at the same bus, in case parameter aggregation_mode is set to True. See parameter load_aggregation_mode in function
spatial_complexity_reduction
for more information.generator_aggregation_mode (str) – Specifies, how to aggregate generators at the same bus, in case parameter aggregation_mode is set to True. See parameter generator_aggregation_mode in function
spatial_complexity_reduction
for more information.mv_pseudo_coordinates (bool, optional) – If True pseudo coordinates are also generated for MV grid. Default: False.
 Returns
Returns busmap and linemap dataframes. The busmap maps the original busses to the new busses with new coordinates. Columns are “new_bus” with new bus name, “new_x” with new xcoordinate and “new_y” with new ycoordinate. Index of the dataframe holds bus names of original buses as in buses_df. The linemap maps the original line names (in the index of the dataframe) to the new line names (in column “new_line_name”).
 Return type
tuple(pandas.DataFrame, pandas.DataFrame)
 edisgo.tools.spatial_complexity_reduction.compare_voltage(edisgo_unreduced: edisgo.EDisGo, edisgo_reduced: edisgo.EDisGo, busmap_df: pandas.DataFrame, timestep: str  pd.Timestamp) tuple[pandas.DataFrame, float] [source]¶
Compares the voltages per node between the unreduced and the reduced EDisGo object.
The voltage difference for each node in p.u. as well as the rootmeansquare error is returned. For the mapping of nodes in the unreduced and reduced network the busmap is used. The calculation is performed for one timestep or the minimum or maximum values of the node voltages.
 Parameters
edisgo_unreduced (
EDisGo
) – Unreduced EDisGo object.edisgo_reduced (
EDisGo
) – Reduced EDisGo object.busmap_df (pandas.DataFrame) – Busmap for the mapping of nodes.
timestep (str or pandas.Timestamp) – Timestep for which to compare the bus voltage. Can either be a certain time step or ‘min’ or ‘max’.
 Returns
Returns a tuple with the first entry being a DataFrame containing the node voltages as well as voltage differences and the second entry being the rootmeansquare error. Columns of the DataFrame are “v_unreduced” with voltage in p.u. in unreduced EDisGo object, “v_reduced” with voltage in p.u. in reduced EDisGo object, and “v_diff” with voltage difference in p.u. between voltages in unreduced and reduced EDisGo object. Index of the DataFrame contains the bus names of buses in the unreduced EDisGo object.
 Return type
(pandas.DataFrame, rms)
 edisgo.tools.spatial_complexity_reduction.compare_apparent_power(edisgo_unreduced: edisgo.EDisGo, edisgo_reduced: edisgo.EDisGo, linemap_df: pandas.DataFrame, timestep: str) tuple[pandas.DataFrame, float] [source]¶
Compares the apparent power over each line between the unreduced and the reduced EDisGo object.
The difference of apparent power over each line in MVA as well as the rootmeansquare error is returned. For the mapping of lines in the unreduced and reduced network the linemap is used. The calculation is performed for one timestep or the minimum or maximum values of the node voltages.
 Parameters
edisgo_unreduced (
EDisGo
) – Unreduced EDisGo object.edisgo_reduced (
EDisGo
) – Reduced EDisGo object.linemap_df (pandas.DataFrame) – Linemap for the mapping.
timestep (str or pandas.Timestamp) – Timestep for which to compare the apparent power. Can either be a certain time step or ‘min’ or ‘max’.
 Returns
Returns a tuple with the first entry being a DataFrame containing the apparent power as well as difference of apparent power for each line and the second entry being the rootmeansquare error. Columns of the DataFrame are “s_unreduced” with apparent power in MVA in unreduced EDisGo object, “s_reduced” with apparent power in MVA in reduced EDisGo object, and “s_diff” with difference in apparent power in MVA between apparent power over line in unreduced and reduced EDisGo object. Index of the DataFrame contains the line names of lines in the unreduced EDisGo object.
 Return type
(pandas.DataFrame, rms)