From f7159de47f66a7bd0e2eae04e36c0f2a51fb52b4 Mon Sep 17 00:00:00 2001 From: Fabian Neumann Date: Sun, 11 Aug 2019 16:59:56 +0200 Subject: [PATCH] base_network: return zero underwater fraction if no link geometry given (closes #53) fixes #53 --- scripts/base_network.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/scripts/base_network.py b/scripts/base_network.py index b23fa0c1..f2eab220 100644 --- a/scripts/base_network.py +++ b/scripts/base_network.py @@ -411,10 +411,13 @@ def _replace_b2b_converter_at_country_border_by_link(n): def _set_links_underwater_fraction(n): if n.links.empty: return - - offshore_shape = gpd.read_file(snakemake.input.offshore_shapes).unary_union - links = gpd.GeoSeries(n.links.geometry.dropna().map(shapely.wkt.loads)) - n.links['underwater_fraction'] = links.intersection(offshore_shape).length / links.length + + if not hasattr(n.links, 'geometry'): + n.links['underwater_fraction'] = 0. + else: + offshore_shape = gpd.read_file(snakemake.input.offshore_shapes).unary_union + links = gpd.GeoSeries(n.links.geometry.dropna().map(shapely.wkt.loads)) + n.links['underwater_fraction'] = links.intersection(offshore_shape).length / links.length def _adjust_capacities_of_under_construction_branches(n): lines_mode = snakemake.config['lines'].get('under_construction', 'undef')