new spatial clustering method: modularity

This commit is contained in:
martacki 2022-07-13 14:51:48 +02:00
parent 44e8fbd5aa
commit 387271b03b
2 changed files with 5 additions and 2 deletions

View File

@ -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

View File

@ -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}.")