From d57989c027058a95eec55a33035848ea8cfccdbb Mon Sep 17 00:00:00 2001 From: Fabian Neumann Date: Mon, 16 Mar 2020 15:55:01 +0100 Subject: [PATCH] scripts: mini code cleanup (#140) --- scripts/_helpers.py | 2 -- scripts/base_network.py | 2 +- scripts/cluster_network.py | 2 +- scripts/plot_network.py | 2 +- scripts/plot_p_nom_max.py | 1 - scripts/retrieve_natura_raster.py | 1 - scripts/solve_operations_network.py | 1 - 7 files changed, 3 insertions(+), 8 deletions(-) diff --git a/scripts/_helpers.py b/scripts/_helpers.py index 88f41c5d..1f3a9873 100644 --- a/scripts/_helpers.py +++ b/scripts/_helpers.py @@ -94,8 +94,6 @@ def load_network_for_plots(fn, tech_costs, config, combine_hydro_ps=True): import pypsa from add_electricity import update_transmission_costs, load_costs - opts = config['plotting'] - n = pypsa.Network(fn) n.loads["carrier"] = n.loads.bus.map(n.buses.carrier) + " load" diff --git a/scripts/base_network.py b/scripts/base_network.py index 9c73dd09..cbb195a1 100644 --- a/scripts/base_network.py +++ b/scripts/base_network.py @@ -66,7 +66,7 @@ import yaml import pandas as pd import geopandas as gpd import numpy as np -import scipy as sp, scipy.spatial +import scipy as sp from scipy.sparse import csgraph from six import iteritems from itertools import product diff --git a/scripts/cluster_network.py b/scripts/cluster_network.py index a3f0be9f..6e07ae4f 100644 --- a/scripts/cluster_network.py +++ b/scripts/cluster_network.py @@ -227,7 +227,7 @@ def busmap_for_n_clusters(n, n_clusters, solver_name, focus_weights=None, algori elif algorithm == "louvain": return prefix + busmap_by_louvain(reduce_network(n, x), n_clusters[x.name], **algorithm_kwds) else: - raise ArgumentError("`algorithm` must be one of 'kmeans', 'spectral' or 'louvain'") + raise ValueError(f"`algorithm` must be one of 'kmeans', 'spectral' or 'louvain'. Is {algorithm}.") return (n.buses.groupby(['country', 'sub_network'], group_keys=False, squeeze=True) .apply(busmap_for_country).rename('busmap')) diff --git a/scripts/plot_network.py b/scripts/plot_network.py index 7f3e6d6d..9facaac0 100755 --- a/scripts/plot_network.py +++ b/scripts/plot_network.py @@ -17,7 +17,7 @@ Description import logging logger = logging.getLogger(__name__) -from _helpers import (load_network, aggregate_p, aggregate_costs, +from _helpers import (load_network_for_plots, aggregate_p, aggregate_costs, configure_logging) import pandas as pd diff --git a/scripts/plot_p_nom_max.py b/scripts/plot_p_nom_max.py index d3d82906..ec1b5354 100644 --- a/scripts/plot_p_nom_max.py +++ b/scripts/plot_p_nom_max.py @@ -22,7 +22,6 @@ import pypsa import pandas as pd import matplotlib.pyplot as plt -import logging def cum_p_nom_max(net, tech, country=None): carrier_b = net.generators.carrier == tech diff --git a/scripts/retrieve_natura_raster.py b/scripts/retrieve_natura_raster.py index df5f1510..82ff4df8 100644 --- a/scripts/retrieve_natura_raster.py +++ b/scripts/retrieve_natura_raster.py @@ -29,7 +29,6 @@ This rule, as a substitute for :mod:`build_natura_raster`, downloads an already import logging logger = logging.getLogger(__name__) -from pathlib import Path from _helpers import progress_retrieve, configure_logging if __name__ == "__main__": diff --git a/scripts/solve_operations_network.py b/scripts/solve_operations_network.py index 99310d35..b8be0f30 100644 --- a/scripts/solve_operations_network.py +++ b/scripts/solve_operations_network.py @@ -47,7 +47,6 @@ from _helpers import configure_logging import pypsa import numpy as np -import re from pathlib import Path from vresutils.benchmark import memory_logger