diff --git a/doc/configtables/clustering.csv b/doc/configtables/clustering.csv index cf004dad..02a7b1fc 100644 --- a/doc/configtables/clustering.csv +++ b/doc/configtables/clustering.csv @@ -1,7 +1,7 @@ ,Unit,Values,Description simplify_network,,, -- to_substations,bool,"{'true','false'}","Aggregates all nodes without power injection (positive or negative, i.e. demand or generation) to electrically closest ones" --- algorithm,str,"One of {‘kmeans’, ‘hac’}", +-- algorithm,str,"One of {‘kmeans’, ‘hac’, ‘modularity‘}", -- feature,str,"Str in the format ‘carrier1+carrier2+...+carrierN-X’, where CarrierI can be from {‘solar’, ‘onwind’, ‘offwind’, ‘ror’} and X is one of {‘cap’, ‘time’}.", cluster_network -- algorithm,str,"One of {‘kmeans’, ‘hac’}", diff --git a/doc/release_notes.rst b/doc/release_notes.rst index cf53d5dd..1b48ff89 100644 --- a/doc/release_notes.rst +++ b/doc/release_notes.rst @@ -62,6 +62,8 @@ PyPSA-Eur 0.5.0 (26th July 2022) * Hierarchical clustering was introduced. Distance metric is calculated from renewable potentials on hourly (feature entry ends with `-time`) or annual (feature entry in config end with `-cap`) values. + +* Greedy modularity clustering was introduced. Distance metric is based on electrical distance taking into account the impedance of all transmission lines of the network. * Techno-economic parameters of technologies (e.g. costs and efficiencies) will now be retrieved from a separate repository `PyPSA/technology-data diff --git a/envs/environment.yaml b/envs/environment.yaml index cffb2754..3330a698 100644 --- a/envs/environment.yaml +++ b/envs/environment.yaml @@ -10,7 +10,7 @@ dependencies: - python>=3.8 - pip - - pypsa>=0.19.1 + - pypsa>=0.20 - atlite>=0.2.6 - dask diff --git a/scripts/cluster_network.py b/scripts/cluster_network.py index 76fc8398..d00624fa 100644 --- a/scripts/cluster_network.py +++ b/scripts/cluster_network.py @@ -135,7 +135,8 @@ import seaborn as sns from functools import reduce -from pypsa.networkclustering import (busmap_by_kmeans, busmap_by_hac, get_clustering_from_busmap) +from pypsa.networkclustering import (busmap_by_kmeans, busmap_by_hac, + busmap_by_greedy_modularity, get_clustering_from_busmap) import warnings warnings.filterwarnings(action='ignore', category=UserWarning) @@ -313,6 +314,8 @@ def busmap_for_n_clusters(n, n_clusters, solver_name, focus_weights=None, algori return prefix + busmap_by_kmeans(n, weight, n_clusters[x.name], buses_i=x.index, **algorithm_kwds) elif algorithm == "hac": return prefix + busmap_by_hac(n, n_clusters[x.name], buses_i=x.index, feature=feature.loc[x.index]) + elif algorithm == "modularity": + return prefix + busmap_by_greedy_modularity(n, n_clusters[x.name], buses_i=x.index) else: raise ValueError(f"`algorithm` must be one of 'kmeans' or 'hac'. Is {algorithm}.")