From ef9e64d457686b7cd01e15795276bd26635a6656 Mon Sep 17 00:00:00 2001 From: FabianHofmann Date: Mon, 3 Feb 2020 15:01:24 +0100 Subject: [PATCH] set bus to nan for powerplants not assigned in kdtree (#123) * solves #109 * fix substations_i for no-neighbours in kdtree --- scripts/build_powerplants.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) mode change 100644 => 100755 scripts/build_powerplants.py diff --git a/scripts/build_powerplants.py b/scripts/build_powerplants.py old mode 100644 new mode 100755 index abea3f9d..237c42b9 --- a/scripts/build_powerplants.py +++ b/scripts/build_powerplants.py @@ -76,6 +76,7 @@ from scipy.spatial import cKDTree as KDTree import pypsa import powerplantmatching as pm import pandas as pd +import numpy as np def add_custom_powerplants(ppl): custom_ppl_query = snakemake.config['electricity']['custom_powerplants'] @@ -122,8 +123,8 @@ if __name__ == "__main__": kdtree = KDTree(n.buses.loc[substation_i, ['x','y']].values) ppl_i = ppl.query('Country == @c').index - ppl.loc[ppl_i, 'bus'] = substation_i[kdtree.query(ppl.loc[ppl_i, - ['lon','lat']].values)[1]] + tree_i = kdtree.query(ppl.loc[ppl_i, ['lon','lat']].values)[1] + ppl.loc[ppl_i, 'bus'] = substation_i.append(pd.Index([np.nan]))[tree_i] if cntries_without_ppl: logging.warning(f"No powerplants known in: {', '.join(cntries_without_ppl)}")