From 387271b03bb24d5ae4975f19df065aa19fbd6a56 Mon Sep 17 00:00:00 2001 From: martacki Date: Wed, 13 Jul 2022 14:51:48 +0200 Subject: [PATCH 1/3] new spatial clustering method: modularity --- envs/environment.yaml | 2 +- scripts/cluster_network.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/envs/environment.yaml b/envs/environment.yaml index 4aefcb9a..90b710c9 100644 --- a/envs/environment.yaml +++ b/envs/environment.yaml @@ -10,7 +10,6 @@ dependencies: - python>=3.8 - pip - - pypsa>=0.19.1 - atlite>=0.2.6 - dask @@ -55,5 +54,6 @@ dependencies: - tabula-py - pip: + - git+https://github.com/pypsa/pypsa.git#egg=pypsa - vresutils>=0.3.1 - tsam>=1.1.0 diff --git a/scripts/cluster_network.py b/scripts/cluster_network.py index bd412b7f..bb35decb 100644 --- a/scripts/cluster_network.py +++ b/scripts/cluster_network.py @@ -138,7 +138,8 @@ import seaborn as sns from functools import reduce from pypsa.networkclustering import (busmap_by_kmeans, busmap_by_spectral_clustering, - busmap_by_hac, _make_consense, get_clustering_from_busmap) + busmap_by_hac, busmap_by_greedy_modularity, + _make_consense, get_clustering_from_busmap) import warnings warnings.filterwarnings(action='ignore', category=UserWarning) @@ -326,6 +327,8 @@ def busmap_for_n_clusters(n, n_clusters, solver_name, focus_weights=None, algori return prefix + busmap_by_louvain(reduce_network(n, x), n_clusters[x.name], **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', 'hac', 'spectral' or 'louvain'. Is {algorithm}.") From 90ffc35f05a06536aeaa7297384ba67ce0a7aa41 Mon Sep 17 00:00:00 2001 From: martacki Date: Wed, 13 Jul 2022 15:39:46 +0200 Subject: [PATCH 2/3] documentation --- doc/configtables/clustering.csv | 2 +- doc/release_notes.rst | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) 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 7aee0e32..5d96be07 100644 --- a/doc/release_notes.rst +++ b/doc/release_notes.rst @@ -92,6 +92,8 @@ Upcoming Release * 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. + Synchronisation Release - Ukraine and Moldova (17th March 2022) =============================================================== From e3555523d80d4ccd2f912ef772e0e5fd0f7a268d Mon Sep 17 00:00:00 2001 From: Fabian Neumann Date: Tue, 26 Jul 2022 14:04:06 +0200 Subject: [PATCH 3/3] env: use new pypsa 0.20 --- envs/environment.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/envs/environment.yaml b/envs/environment.yaml index 90b710c9..77c4db4c 100644 --- a/envs/environment.yaml +++ b/envs/environment.yaml @@ -10,6 +10,7 @@ dependencies: - python>=3.8 - pip + - pypsa>=0.20 - atlite>=0.2.6 - dask @@ -54,6 +55,5 @@ dependencies: - tabula-py - pip: - - git+https://github.com/pypsa/pypsa.git#egg=pypsa - vresutils>=0.3.1 - tsam>=1.1.0