From 448ba651a068831494b49739966374b8a31614e8 Mon Sep 17 00:00:00 2001 From: Jonas Hoersch Date: Tue, 11 Dec 2018 17:30:25 +0100 Subject: [PATCH] build_renewable_profiles: Compute underwater_fraction --- Snakefile | 1 + scripts/build_renewable_profiles.py | 26 +++++++++++++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/Snakefile b/Snakefile index a37f6b32..f479e923 100644 --- a/Snakefile +++ b/Snakefile @@ -107,6 +107,7 @@ rule build_renewable_profiles: natura="resources/natura.tiff", gebco="data/bundle/GEBCO_2014_2D.nc", country_shapes='resources/country_shapes.geojson', + offshore_shapes='resources/offshore_shapes.geojson', regions=lambda wildcards: ("resources/regions_onshore.geojson" if wildcards.technology in ('onwind', 'solar') else "resources/regions_offshore.geojson"), diff --git a/scripts/build_renewable_profiles.py b/scripts/build_renewable_profiles.py index 8860dd6f..6c906e13 100644 --- a/scripts/build_renewable_profiles.py +++ b/scripts/build_renewable_profiles.py @@ -99,7 +99,7 @@ if __name__ == '__main__': with Pool(initializer=init_globals, initargs=(bounds, dx, dy), maxtasksperchild=20, processes=snakemake.config['atlite'].get('nprocesses', 2)) as pool: - regions = gk.vector.extractFeatures(snakemake.input.regions, onlyAttr=True) #.iloc[:10] + regions = gk.vector.extractFeatures(snakemake.input.regions, onlyAttr=True).iloc[:10] buses = pd.Index(regions['name'], name="bus") widgets = [ pgb.widgets.Percentage(), @@ -163,12 +163,28 @@ if __name__ == '__main__': row = layoutmatrix[i] distances = haversine(regions.loc[i, ['x', 'y']], cell_coords[row.indices])[0] average_distance.append((distances * (row.data / row.data.sum())).sum()) + average_distance = xr.DataArray(average_distance, [buses]) ds = xr.merge([(correction_factor * profile).rename('profile'), - capacities.rename('weight'), - p_nom_max.rename('p_nom_max'), - layout.rename('potential'), - average_distance.rename('average_distance')]) + capacities.rename('weight'), + p_nom_max.rename('p_nom_max'), + layout.rename('potential'), + average_distance.rename('average_distance')]) + + if snakemake.wildcards.technology.startswith("offwind"): + import geopandas as gpd + from shapely.geometry import LineString + + offshore_shape = gpd.read_file(snakemake.input.offshore_shapes).set_index('id').unary_union + underwater_fraction = [] + for i in regions.index: + row = layoutmatrix[i] + centre_of_mass = (cell_coords[row.indices] * (row.data / row.data.sum())[:,np.newaxis]).sum(axis=0) + line = LineString([centre_of_mass, regions.loc[i, ['x', 'y']]]) + underwater_fraction.append(line.intersection(offshore_shape).length / line.length) + + ds['underwater_fraction'] = xr.DataArray(underwater_fraction, [buses]) + (ds.sel(bus=(ds['profile'].mean('time') > config.get('min_p_max_pu', 0.)) & (ds['p_nom_max'] > 0.)) .to_netcdf(snakemake.output.profile))