edisgo.tools.spatial_complexity_reduction ========================================= .. py:module:: edisgo.tools.spatial_complexity_reduction Functions --------- .. autoapisummary:: edisgo.tools.spatial_complexity_reduction.find_buses_of_interest edisgo.tools.spatial_complexity_reduction.rename_virtual_buses edisgo.tools.spatial_complexity_reduction.remove_short_end_lines edisgo.tools.spatial_complexity_reduction.remove_lines_under_one_meter edisgo.tools.spatial_complexity_reduction.make_busmap_grid edisgo.tools.spatial_complexity_reduction.make_busmap_feeders edisgo.tools.spatial_complexity_reduction.make_busmap_main_feeders edisgo.tools.spatial_complexity_reduction.make_busmap edisgo.tools.spatial_complexity_reduction.apply_busmap edisgo.tools.spatial_complexity_reduction.spatial_complexity_reduction edisgo.tools.spatial_complexity_reduction.compare_voltage edisgo.tools.spatial_complexity_reduction.compare_apparent_power Module Contents --------------- .. py:function:: find_buses_of_interest(edisgo_root) Return buses with load and voltage issues, determined doing a worst-case powerflow analysis. :param edisgo_root: The investigated EDisGo object. :type edisgo_root: :class:`~.EDisGo` :returns: Set with the names of the buses with load and voltage issues. :rtype: set(str) .. py:function:: rename_virtual_buses(partial_busmap_df, transformer_node) Rename virtual buses so that no virtual transformer bus is created. :param partial_busmap_df: Busmap to work on. :type partial_busmap_df: :pandas:`pandas.DataFrame` :param transformer_node: Transformer node name. :type transformer_node: str :returns: Busmap with applied changes. :rtype: :pandas:`pandas.DataFrame` .. py:function:: remove_short_end_lines(edisgo_obj) 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. :param edisgo: :type edisgo: :class:`~.EDisGo` .. py:function:: remove_lines_under_one_meter(edisgo_obj) 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. .. py:function:: make_busmap_grid(edisgo_obj, grid = None, mode = 'kmeansdijkstra', reduction_factor = 0.25, preserve_trafo_bus_coordinates = True) Making busmap for the cluster area 'grid'. Every grid is clustered individually. :param edisgo_obj: EDisGo object for which the busmap is created. :type edisgo_obj: :class:`~.EDisGo` :param grid: If None, busmap is created for all grids, else only for the selected grid. Default: None. :type grid: str or None :param mode: "kmeans" or "kmeansdijkstra" as clustering method. See parameter `mode` in function :attr:`~.EDisGo.spatial_complexity_reduction` for more information. Default: "kmeansdijkstra". :type mode: str :param reduction_factor: Factor to reduce number of nodes by. Must be between 0 and 1. Default: 0.25. :type reduction_factor: float :param preserve_trafo_bus_coordinates: If True, transformers have the same coordinates after the clustering, else the transformer coordinates are changed by the clustering. Default: True. :type preserve_trafo_bus_coordinates: True :returns: Busmap which maps the old bus names to the new bus names with new coordinates. See return value in function :func:`~make_busmap` for more information. :rtype: :pandas:`pandas.DataFrame` .. rubric:: References In parts based on `PyPSA spatial complexity reduction `_. .. py:function:: make_busmap_feeders(edisgo_obj = None, grid = None, mode = 'kmeansdijkstra', reduction_factor = 0.25, reduction_factor_not_focused = False) Making busmap for the cluster area 'feeder'. Every feeder is clustered individually. :param edisgo_obj: EDisGo object for which the busmap is created. :type edisgo_obj: :class:`~.EDisGo` :param grid: If None, busmap is created for all grids, else only for the selected grid. Default: None. :type grid: str or None :param mode: "kmeans" or "kmeansdijkstra" as clustering method. See parameter `mode` in function :attr:`~.EDisGo.spatial_complexity_reduction` for more information. Default: "kmeansdijkstra". :type mode: str :param reduction_factor: Factor to reduce number of nodes by. Must be between 0 and 1. Default: 0.25. :type reduction_factor: float :param reduction_factor_not_focused: 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 :func:`~make_busmap` for more information. Default: False. :type reduction_factor_not_focused: bool or float :returns: Busmap which maps the old bus names to the new bus names with new coordinates. See return value in function :func:`~make_busmap` for more information. :rtype: :pandas:`pandas.DataFrame` .. rubric:: References In parts based on `PyPSA spatial complexity reduction `_. .. py:function:: make_busmap_main_feeders(edisgo_obj = None, grid = None, mode = 'kmeansdijkstra', reduction_factor = 0.25, reduction_factor_not_focused = False) 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. :param edisgo_obj: EDisGo object for which the busmap is created. :type edisgo_obj: :class:`~.EDisGo` :param grid: If None, busmap is created for all grids, else only for the selected grid. Default: None. :type grid: str or None :param mode: "kmeans", "kmeansdijkstra", "aggregate_to_main_feeder" or "equidistant_nodes" as clustering method. See parameter `mode` in function :attr:`~.EDisGo.spatial_complexity_reduction` for more information. Default: "kmeansdijkstra". :type mode: str :param reduction_factor: Factor to reduce number of nodes by. Must be between 0 and 1. Default: 0.25. :type reduction_factor: float :param reduction_factor_not_focused: 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 :func:`~make_busmap` for more information. Default: False. :type reduction_factor_not_focused: bool or float :returns: Busmap which maps the old bus names to the new bus names with new coordinates. See return value in function :func:`~make_busmap` for more information. :rtype: :pandas:`pandas.DataFrame` .. rubric:: References In parts based on `PyPSA spatial complexity reduction `_. .. py:function:: make_busmap(edisgo_obj, mode = 'kmeansdijkstra', cluster_area = 'feeder', reduction_factor = 0.25, reduction_factor_not_focused = False, grid = None) Determines which busses are clustered. The information on which original busses are clustered to which new busses is given in the so-called busmap dataframe. The busmap can be used with the function :func:`~apply_busmap` to perform a spatial complexity reduction. :param edisgo_obj: EDisGo object for which the busmap is created. :type edisgo_obj: :class:`~.EDisGo` :param mode: Clustering method to use. See parameter `mode` in function :attr:`~.EDisGo.spatial_complexity_reduction` for more information. :type mode: str :param cluster_area: The cluster area is the area the different clustering methods are applied to. Possible options are 'grid', 'feeder' or 'main_feeder'. Default: "feeder". :type cluster_area: str :param reduction_factor: Factor to reduce number of nodes by. Must be between 0 and 1. Default: 0.25. :type reduction_factor: float :param reduction_factor_not_focused: 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. :type reduction_factor_not_focused: bool or float :param grid: If None, busmap is created for all grids, else only for the selected grid. :type grid: str or None :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 x-coordinate and "new_y" with new y-coordinate. Index of the dataframe holds bus names of original buses as in buses_df. :rtype: :pandas:`pandas.DataFrame` .. rubric:: References In parts based on `PyPSA spatial complexity reduction `_. .. py:function:: apply_busmap(edisgo_obj, busmap_df, line_naming_convention = 'standard_lines', aggregation_mode = False, load_aggregation_mode = 'sector', generator_aggregation_mode = 'type') 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 :func:`~.tools.pseudo_coordinates.make_pseudo_coordinates` to set coordinates for all buses. :param edisgo_obj: EDisGo object to reduce. :type edisgo_obj: :class:`~.EDisGo` :param busmap_df: Busmap holding the information which nodes are merged together. :type busmap_df: :pandas:`pandas.DataFrame` :param line_naming_convention: 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". :type line_naming_convention: str :param aggregation_mode: 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. :type aggregation_mode: bool :param load_aggregation_mode: 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". :type load_aggregation_mode: str :param generator_aggregation_mode: 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. :type generator_aggregation_mode: str :returns: Linemap which maps the old line names (in the index of the dataframe) to the new line names (in column "new_line_name"). :rtype: :pandas:`pandas.DataFrame` .. rubric:: References In parts based on `PyPSA spatial complexity reduction `_. .. py:function:: spatial_complexity_reduction(edisgo_obj, mode = 'kmeansdijkstra', cluster_area = 'feeder', reduction_factor = 0.25, reduction_factor_not_focused = False, apply_pseudo_coordinates = True, **kwargs) Reduces the number of busses and lines by applying a spatial clustering. See function :attr:`~.EDisGo.spatial_complexity_reduction` for more information. :param edisgo_obj: EDisGo object to apply spatial complexity reduction to. :type edisgo_obj: :class:`~.EDisGo` :param mode: Clustering method to use. See parameter `mode` in function :attr:`~.EDisGo.spatial_complexity_reduction` for more information. :type mode: str :param cluster_area: The cluster area is the area the different clustering methods are applied to. See parameter `cluster_area` in function :attr:`~.EDisGo.spatial_complexity_reduction` for more information. :type cluster_area: str :param reduction_factor: Factor to reduce number of nodes by. Must be between 0 and 1. Default: 0.25. :type reduction_factor: float :param reduction_factor_not_focused: 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 :attr:`~.EDisGo.spatial_complexity_reduction` for more information. :type reduction_factor_not_focused: bool or float :param apply_pseudo_coordinates: If True pseudo coordinates are applied. The spatial complexity reduction method is only tested with pseudo coordinates. Default: True. :type apply_pseudo_coordinates: bool :param line_naming_convention: Determines how to set "type_info" and "kind" in case two or more lines are aggregated. See parameter `line_naming_convention` in function :attr:`~.EDisGo.spatial_complexity_reduction` for more information. :type line_naming_convention: str :param aggregation_mode: Specifies, whether to aggregate loads and generators at the same bus or not. See parameter `aggregation_mode` in function :attr:`~.EDisGo.spatial_complexity_reduction` for more information. :type aggregation_mode: bool :param load_aggregation_mode: 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 :attr:`~.EDisGo.spatial_complexity_reduction` for more information. :type load_aggregation_mode: str :param generator_aggregation_mode: 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 :attr:`~.EDisGo.spatial_complexity_reduction` for more information. :type generator_aggregation_mode: str :param mv_pseudo_coordinates: If True pseudo coordinates are also generated for MV grid. Default: False. :type mv_pseudo_coordinates: bool, optional :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 x-coordinate and "new_y" with new y-coordinate. 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"). :rtype: tuple(:pandas:`pandas.DataFrame`, :pandas:`pandas.DataFrame`) .. py:function:: compare_voltage(edisgo_unreduced, edisgo_reduced, busmap_df, timestep) 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 root-mean-square 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. :param edisgo_unreduced: Unreduced EDisGo object. :type edisgo_unreduced: :class:`~.EDisGo` :param edisgo_reduced: Reduced EDisGo object. :type edisgo_reduced: :class:`~.EDisGo` :param busmap_df: Busmap for the mapping of nodes. :type busmap_df: :pandas:`pandas.DataFrame` :param timestep: Timestep for which to compare the bus voltage. Can either be a certain time step or 'min' or 'max'. :type timestep: str or :pandas:`pandas.Timestamp` :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 root-mean-square 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. :rtype: (:pandas:`pandas.DataFrame`, rms) .. py:function:: compare_apparent_power(edisgo_unreduced, edisgo_reduced, linemap_df, timestep) 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 root-mean-square 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. :param edisgo_unreduced: Unreduced EDisGo object. :type edisgo_unreduced: :class:`~.EDisGo` :param edisgo_reduced: Reduced EDisGo object. :type edisgo_reduced: :class:`~.EDisGo` :param linemap_df: Linemap for the mapping. :type linemap_df: :pandas:`pandas.DataFrame` :param timestep: Timestep for which to compare the apparent power. Can either be a certain time step or 'min' or 'max'. :type timestep: str or :pandas:`pandas.Timestamp` :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 root-mean-square 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. :rtype: (:pandas:`pandas.DataFrame`, rms)