build_renewable_profiles: Extend calculate_potential
to optionally save the exclusion map
This commit is contained in:
parent
c858ed0b0d
commit
f49682c61d
@ -1,5 +1,7 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import atlite
|
import atlite
|
||||||
import numpy as np
|
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()
|
assert gdal.Warp(average, padded, resampleAlg='average') == 1, "gdal warp failed: %s" % gdal.GetLastErrorMsg()
|
||||||
return average
|
return average
|
||||||
|
|
||||||
def calculate_potential(gid):
|
def calculate_potential(gid, save_map=None):
|
||||||
feature = gk.vector.extractFeature(paths["regions"], where=gid)
|
feature = gk.vector.extractFeature(paths["regions"], where=gid)
|
||||||
ec = gl.ExclusionCalculator(feature.geom)
|
ec = gl.ExclusionCalculator(feature.geom)
|
||||||
|
|
||||||
@ -73,6 +75,11 @@ def calculate_potential(gid):
|
|||||||
if 'min_shore_distance' in config:
|
if 'min_shore_distance' in config:
|
||||||
ec.excludeVectorType(paths["country_shapes"], buffer=config['min_shore_distance'])
|
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))
|
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.)
|
return csr_matrix(gk.raster.extractMatrix(availability).flatten() / 100.)
|
||||||
|
Loading…
Reference in New Issue
Block a user