From 3c1c604c7e6424b657d5970eff012432bd0fbfb0 Mon Sep 17 00:00:00 2001 From: Fabian Neumann Date: Sun, 29 Mar 2020 11:39:18 +0200 Subject: [PATCH] cluster: skip recalculation of link parameters if empty (#149) --- scripts/cluster_network.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/scripts/cluster_network.py b/scripts/cluster_network.py index 6e07ae4f..cc1ac54a 100644 --- a/scripts/cluster_network.py +++ b/scripts/cluster_network.py @@ -262,13 +262,15 @@ def clustering_for_n_clusters(n, n_clusters, aggregate_carriers=None, generator_strategies={'p_nom_max': p_nom_max_strategy}, scale_link_capital_costs=False) - nc = clustering.network - nc.links['underwater_fraction'] = (n.links.eval('underwater_fraction * length') - .div(nc.links.length).dropna()) - nc.links['capital_cost'] = (nc.links['capital_cost'] - .add((nc.links.length - n.links.length) - .clip(lower=0).mul(extended_link_costs), - fill_value=0)) + if not n.links.empty: + nc = clustering.network + nc.links['underwater_fraction'] = (n.links.eval('underwater_fraction * length') + .div(nc.links.length).dropna()) + nc.links['capital_cost'] = (nc.links['capital_cost'] + .add((nc.links.length - n.links.length) + .clip(lower=0).mul(extended_link_costs), + fill_value=0)) + return clustering def save_to_geojson(s, fn):