From cdd063d3b050851a7621dca10851375fb16e3382 Mon Sep 17 00:00:00 2001 From: Fabian Neumann Date: Wed, 27 Jul 2022 09:02:34 +0200 Subject: [PATCH] scripts: remove deprecated clustering methods, remove unused imports --- scripts/_helpers.py | 1 - scripts/build_powerplants.py | 2 -- scripts/build_shapes.py | 1 - scripts/cluster_network.py | 17 ++--------------- scripts/simplify_network.py | 2 +- 5 files changed, 3 insertions(+), 20 deletions(-) diff --git a/scripts/_helpers.py b/scripts/_helpers.py index 8dd2acd5..0871f622 100644 --- a/scripts/_helpers.py +++ b/scripts/_helpers.py @@ -4,7 +4,6 @@ import pandas as pd from pathlib import Path -from collections import OrderedDict REGION_COLS = ['geometry', 'name', 'x', 'y', 'country'] diff --git a/scripts/build_powerplants.py b/scripts/build_powerplants.py index 1c3990af..056c2649 100755 --- a/scripts/build_powerplants.py +++ b/scripts/build_powerplants.py @@ -77,10 +77,8 @@ from _helpers import configure_logging import pypsa import powerplantmatching as pm import pandas as pd -import numpy as np from powerplantmatching.export import map_country_bus -from scipy.spatial import cKDTree as KDTree logger = logging.getLogger(__name__) diff --git a/scripts/build_shapes.py b/scripts/build_shapes.py index 35d564b3..c2c081b4 100644 --- a/scripts/build_shapes.py +++ b/scripts/build_shapes.py @@ -70,7 +70,6 @@ Description import logging from _helpers import configure_logging -import os import numpy as np from operator import attrgetter from functools import reduce diff --git a/scripts/cluster_network.py b/scripts/cluster_network.py index b76b703f..76fc8398 100644 --- a/scripts/cluster_network.py +++ b/scripts/cluster_network.py @@ -125,8 +125,6 @@ import logging from _helpers import configure_logging, update_p_nom_max, get_aggregation_strategies import pypsa -import os -import shapely import pandas as pd import numpy as np @@ -137,8 +135,7 @@ 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) +from pypsa.networkclustering import (busmap_by_kmeans, busmap_by_hac, get_clustering_from_busmap) import warnings warnings.filterwarnings(action='ignore', category=UserWarning) @@ -305,12 +302,6 @@ def busmap_for_n_clusters(n, n_clusters, solver_name, focus_weights=None, algori n_clusters = distribute_clusters(n, n_clusters, focus_weights=focus_weights, solver_name=solver_name) - def reduce_network(n, buses): - nr = pypsa.Network() - nr.import_components_from_dataframe(buses, "Bus") - nr.import_components_from_dataframe(n.lines.loc[n.lines.bus0.isin(buses.index) & n.lines.bus1.isin(buses.index)], "Line") - return nr - def busmap_for_country(x): prefix = x.name[0] + x.name[1] + ' ' logger.debug(f"Determining busmap for country {prefix[:-1]}") @@ -320,14 +311,10 @@ def busmap_for_n_clusters(n, n_clusters, solver_name, focus_weights=None, algori if algorithm == "kmeans": return prefix + busmap_by_kmeans(n, weight, n_clusters[x.name], buses_i=x.index, **algorithm_kwds) - elif algorithm == "spectral": - return prefix + busmap_by_spectral_clustering(reduce_network(n, x), n_clusters[x.name], **algorithm_kwds) - elif algorithm == "louvain": - 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]) else: - raise ValueError(f"`algorithm` must be one of 'kmeans', 'hac', 'spectral' or 'louvain'. Is {algorithm}.") + raise ValueError(f"`algorithm` must be one of 'kmeans' or 'hac'. Is {algorithm}.") return (n.buses.groupby(['country', 'sub_network'], group_keys=False) .apply(busmap_for_country).squeeze().rename('busmap')) diff --git a/scripts/simplify_network.py b/scripts/simplify_network.py index 2bba1077..bbd8c2cf 100644 --- a/scripts/simplify_network.py +++ b/scripts/simplify_network.py @@ -99,7 +99,7 @@ from functools import reduce import pypsa from pypsa.io import import_components_from_dataframe, import_series_from_dataframe -from pypsa.networkclustering import busmap_by_stubs, aggregategenerators, aggregateoneport, get_clustering_from_busmap, _make_consense +from pypsa.networkclustering import busmap_by_stubs, aggregategenerators, aggregateoneport, get_clustering_from_busmap logger = logging.getLogger(__name__)