From 37d817c70f75387058b760e7ec93162c2fd5552f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20H=C3=B6rsch?= Date: Thu, 27 Sep 2018 18:27:33 +0200 Subject: [PATCH] base_network: Fix bug in _closest_links and fix SACOI capacity --- data/parameter_corrections.yaml | 1 + scripts/base_network.py | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/data/parameter_corrections.yaml b/data/parameter_corrections.yaml index 46cd64b9..43db5716 100644 --- a/data/parameter_corrections.yaml +++ b/data/parameter_corrections.yaml @@ -17,6 +17,7 @@ Link: "8106": 1000 # ALEGrO BE-DE "5241": 1000 # NEMO GB-BE "7719": 700 # Cobra DK-NL + "5362": 300 # SACOI (between Sardignia and Corse) index: "11384": 1000 # NO-DK (part 1) "11087": 1000 # NO-DK (part 2) diff --git a/scripts/base_network.py b/scripts/base_network.py index 57623c4a..ab9d0901 100644 --- a/scripts/base_network.py +++ b/scripts/base_network.py @@ -19,6 +19,9 @@ logger = logging.getLogger(__name__) import pypsa +def _get_oid(df): + return df.tags.str.extract('"oid"=>"(\d+)"', expand=False) + def _find_closest_links(links, new_links, distance_upper_bound=1.5): tree = sp.spatial.KDTree(np.vstack([ new_links[['x1', 'y1', 'x2', 'y2']], @@ -31,8 +34,11 @@ def _find_closest_links(links, new_links, distance_upper_bound=1.5): distance_upper_bound=distance_upper_bound ) + found_b = ind < 2 * len(new_links) return ( - pd.DataFrame(dict(D=dist, i=new_links.index[ind % len(new_links)]), index=links.index) + pd.DataFrame(dict(D=dist[found_b], + i=new_links.index[ind[found_b] % len(new_links)]), + index=links.index[found_b]) .groupby('i').D.idxmin() ) @@ -157,13 +163,13 @@ def _apply_parameter_corrections(n): if corrections is None: return for component, attrs in iteritems(corrections): df = n.df(component) + oid = _get_oid(df) if attrs is None: continue for attr, repls in iteritems(attrs): for i, r in iteritems(repls): if i == 'oid': - df["oid"] = df.tags.str.extract('"oid"=>"(\d+)"', expand=False) - r = df.oid.map(repls["oid"]).dropna() + r = oid.map(repls["oid"]).dropna() elif i == 'index': r = pd.Series(repls["index"]) else: