From f49682c61d8205d39f4e474b6b6e1100b9b074c8 Mon Sep 17 00:00:00 2001 From: Jonas Hoersch Date: Fri, 15 Feb 2019 11:11:41 +0100 Subject: [PATCH] build_renewable_profiles: Extend `calculate_potential` to optionally save the exclusion map --- scripts/build_renewable_profiles.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/scripts/build_renewable_profiles.py b/scripts/build_renewable_profiles.py index 8e64e229..9f8068f8 100644 --- a/scripts/build_renewable_profiles.py +++ b/scripts/build_renewable_profiles.py @@ -1,5 +1,7 @@ #!/usr/bin/env python +import matplotlib.pyplot as plt + import os import atlite import numpy as np @@ -50,7 +52,7 @@ def downsample_to_coarse_grid(bounds, dx, dy, mask, data): assert gdal.Warp(average, padded, resampleAlg='average') == 1, "gdal warp failed: %s" % gdal.GetLastErrorMsg() return average -def calculate_potential(gid): +def calculate_potential(gid, save_map=None): feature = gk.vector.extractFeature(paths["regions"], where=gid) ec = gl.ExclusionCalculator(feature.geom) @@ -73,6 +75,11 @@ def calculate_potential(gid): if 'min_shore_distance' in config: ec.excludeVectorType(paths["country_shapes"], buffer=config['min_shore_distance']) + if save_map is not None: + ec.draw() + plt.savefig(save_map, transparent=True) + plt.close() + availability = downsample_to_coarse_grid(bounds, dx, dy, ec.region, np.where(ec.region.mask, ec._availability, 0)) return csr_matrix(gk.raster.extractMatrix(availability).flatten() / 100.)