lines_clustering_functions.py

lib.lines_clustering_functions.clip_transmission_shapefile(paths, param)

This function clips the shapefile of the transmission lines using the shapefile of the scope. MULTILINESTRING instances are formed as a result of clipping. Hence, the script cleans the clipped transmission file by replacing the MULTILINESTRING instances with LINESTRING instances.

Parameters
  • paths (dict) – Dictionary of paths including the path to the shapefile of the transmission network after connecting islands, grid_connected, and to the output grid_clipped.

  • param – Dictionary of parameters including CRS_grid.

Returns

The shapefile of clipped transmission lines is saved directly in the desired path grid_clipped.

Return type

None

lib.lines_clustering_functions.cluster_transmission_shapefile(paths, param)

This function clusters the transmission network into a specified number of clusters. It first reads the shapefile of voronoi polygons, and initializes its attributes elec_neighbors, trans_lines, Area, Cap, and Ratio. Starting with the polygon with the highest ratio, it merges it with its electric neighbors with the highest ratio as well. It then updates the values and repeats the algorithm, until the target number of clusters is reached.

Parameters
  • paths (dict) – Dictionary of paths pointing to grid_clipped, grid_debugging, grid_voronoi, and to the outputs grid_intermediate and grid_regions.

  • param (dict) – Dictionary containing the parameter CRS_grid and the user preferences number_clusters and intermediate_number.

Returns

The intermediate and final outputs are saved directly in the desired shapefiles.

Return type

None

lib.lines_clustering_functions.connect_islands(paths, param)

This script takes a shapefile of a transmission network and uses graph theory to identify its components (electric islands). After the identification of islands, it creates connections between them using additional transmission lines with low capacities. This correction assumes that there are actually no electric islands, and that multiple graph components only exist because some transmission lines are missing in the data. The output is a shapefile of transmission lines with no electric islands.

Parameters
  • paths (dict) – Dictionary of paths including the path to the input shapefile of the transmission network, grid_input.

  • param – Dictionary of parameters including CRS_grid, default_cap_MVA, and default_line_type.

Returns

The shapefile with connections between islands is saved directly in the desired path grid_connected.

Return type

None

lib.lines_clustering_functions.create_voronoi_polygons(paths, param)

This function creates a shapefile of voronoi polygons based on the points at the start/end of the lines.

Parameters
  • paths (dict) – Dictionary of paths including the path to the shapefile of the transmission network after clipping, grid_clipped, to the scope spatial_scope, and to the output grid_voronoi.

  • param – Dictionary of parameters including CRS_grid.

Returns

The shapefile of voronoi polygons is saved directly in the desired path grid_voronoi.

Return type

None

lib.lines_clustering_functions.lines_clustering(paths, param)

This function applies the hierarchical clustering algorithm to the shapefile of transmission lines. It first ensures that the whole grid is one component (no electric islands), by eventually adding fake lines with low capacity. Then it clips the grid to the scope, and creates a shapefile of voronoi polygons based on the points at the start/end of the lines. Regions with a small area and high connectivity to their neighbors are aggregated together, until the target number of regions is reached.

Parameters
  • paths (dict) – Dictionary of paths pointing to input files and output locations.

  • param (dict) – Dictionary of parameters including transmission-line-related parameters.

Returns

The called functions connect_islands, clip_transmission_shapefile, create_voronoi_polygons, and cluster_transmission_shapefile generate outputs.

Return type

None

lib.lines_clustering_functions.update_values_in_geodataframes(gdf_trans, gdf_voronoi, poly1, poly2, cluster_no)

This function updates the values in the geodataframes gdf_trans and gdf_voronoi after dissolving the polygons and is called in the loops in cluster_transmission_shapefile.

Parameters
  • gdf_trans (geopandas GeoDataFrame) – Geodataframe of transmission lines, containing the columns Start_poly and End_poly.

  • gdf_voronoi (geopandas GeoDataFrame) – Geodataframe of polygons, containing the columns trans_lines, elec_neighbors, Cluster, Cap, Area, and Ratio.

  • poly1 (geopandas GeoDataFrame) – First polygon to be dissolved, containing the same columns as gdf_voronoi.

  • poly2 (geopandas GeoDataFrame) – Second polygon to be dissolved, containing the same columns as gdf_voronoi.

  • cluster_no (integer) – Cluster number to be used for the dissolved polygons.

Return (gdf_trans, gdf_voronoi)

Updated geodataframes after dissolving poly1 and poly2.

Return type

tuple of geodataframes