etrago.cluster package¶
Submodules¶
etrago.cluster.networkclustering module¶
Networkclustering.py defines the methods to cluster power grid networks spatially for applications within the tool eTraGo.
-
etrago.cluster.networkclustering.
cluster_on_extra_high_voltage
(network, busmap, with_time=True)[source]¶ Main function of the EHV-Clustering approach. Creates a new clustered pypsa.Network given a busmap mapping all bus_ids to other bus_ids of the same network.
Parameters: Returns: network – Container for all network components of the clustered network.
Return type: pypsa.Network
-
etrago.cluster.networkclustering.
graph_from_edges
(edges)[source]¶ Constructs an undirected multigraph from a list containing data on weighted edges.
Parameters: edges (list) – List of tuples each containing first node, second node, weight, key. Returns: M Return type: :class:`networkx.classes.multigraph.MultiGraph
-
etrago.cluster.networkclustering.
gen
(nodes, n, graph)[source]¶ Generator for applying multiprocessing.
Parameters: Returns: Return type:
-
etrago.cluster.networkclustering.
shortest_path
(paths, graph)[source]¶ Finds the minimum path lengths between node pairs defined in paths.
Parameters: Returns: df – DataFrame holding source and target node and the minimum path length.
Return type: pd.DataFrame
-
etrago.cluster.networkclustering.
busmap_by_shortest_path
(network, session, scn_name, version, fromlvl, tolvl, cpu_cores=4)[source]¶ Creates a busmap for the EHV-Clustering between voltage levels based on dijkstra shortest path. The result is automatically written to the model_draft on the <OpenEnergyPlatform>[www.openenergy-platform.org] database with the name ego_grid_pf_hv_busmap and the attributes scn_name (scenario name), bus0 (node before clustering), bus1 (node after clustering) and path_length (path length). An AssertionError occurs if buses with a voltage level are not covered by the input lists ‘fromlvl’ or ‘tolvl’.
Parameters: - network (pypsa.Network object) – Container for all network components.
- session (sqlalchemy.orm.session.Session object) – Establishes interactions with the database.
- scn_name (str) – Name of the scenario.
- fromlvl (list) – List of voltage-levels to cluster.
- tolvl (list) – List of voltage-levels to remain.
- cpu_cores (int) – Number of CPU-cores.
Returns: Return type:
-
etrago.cluster.networkclustering.
busmap_from_psql
(network, session, scn_name, version)[source]¶ Retrieves busmap from model_draft.ego_grid_pf_hv_busmap on the <OpenEnergyPlatform>[www.openenergy-platform.org] by a given scenario name. If this busmap does not exist, it is created with default values.
Parameters: - network (pypsa.Network object) – Container for all network components.
- session (sqlalchemy.orm.session.Session object) – Establishes interactions with the database.
- scn_name (str) – Name of the scenario.
Returns: busmap – Maps old bus_ids to new bus_ids.
Return type:
-
etrago.cluster.networkclustering.
kmean_clustering
(network, n_clusters=10, load_cluster=False, line_length_factor=1.25, remove_stubs=False, use_reduced_coordinates=False, bus_weight_tocsv=None, bus_weight_fromcsv=None, n_init=10, max_iter=300, tol=0.0001, n_jobs=1)[source]¶ Main function of the k-mean clustering approach. Maps an original network to a new one with adjustable number of nodes and new coordinates.
Parameters: - network (:class:`pypsa.Network) – Container for all network components.
- n_clusters (int) – Desired number of clusters.
- load_cluster (boolean) – Loads cluster coordinates from a former calculation.
- line_length_factor (float) – Factor to multiply the crow-flies distance between new buses in order to get new line lengths.
- remove_stubs (boolean) – Removes stubs and stubby trees (i.e. sequentially reducing dead-ends).
- use_reduced_coordinates (boolean) – If True, do not average cluster coordinates, but take from busmap.
- bus_weight_tocsv (str) – Creates a bus weighting based on conventional generation and load and save it to a csv file.
- bus_weight_fromcsv (str) – Loads a bus weighting from a csv file to apply it to the clustering algorithm.
Returns: network – Container for all network components.
Return type: pypsa.Network object
etrago.cluster.snapshot module¶
This module contains functions for calculating representative days/weeks based on a pyPSA network object. It is designed to be used for the lopf method. Essentially the tsam package ( https://github.com/FZJ-IEK3-VSA/tsam ), which is developed by Leander Kotzur is used.
Remaining questions/tasks:
- Does it makes sense to cluster normed values?
- Include scaling method for yearly sums
-
etrago.cluster.snapshot.
tsam_cluster
(timeseries_df, typical_periods=10, how='daily', extremePeriodMethod='None')[source]¶ Parameters: - df (pd.DataFrame) – DataFrame with timeseries to cluster
- extremePeriodMethod ({'None','append','new_cluster_center',) –
‘replace_cluster_center’}, default: ‘None’ Method how to integrate extreme Periods into to the typical period profiles. None: No integration at all. ‘append’: append typical Periods to cluster centers ‘new_cluster_center’: add the extreme period as additional cluster
center. It is checked then for all Periods if they fit better to the this new center or their original cluster center.- ’replace_cluster_center’: replaces the cluster center of the
- cluster where the extreme period belongs to with the periodly profile of the extreme period. (Worst case system design)
Returns: timeseries – Clustered timeseries
Return type: pd.DataFrame
-
etrago.cluster.snapshot.
update_data_frames
(network, cluster_weights, dates, hours)[source]¶ Updates the snapshots, snapshots weights and the dataframes based on the original data in the network and the medoids created by clustering these original data.
Parameters: - network (pyPSA network object) –
- cluster_weights (dictionary) –
- dates (Datetimeindex) –
Returns: Return type: network