2020-05-29 07:50:55 +00:00
|
|
|
# SPDX-FileCopyrightText: : 2017-2020 The PyPSA-Eur Authors
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2019-08-08 13:02:28 +00:00
|
|
|
"""
|
2019-08-11 20:34:18 +00:00
|
|
|
Rasters the vector data of the `Natura 2000 <https://en.wikipedia.org/wiki/Natura_2000>`_ natural protection areas onto all cutout regions.
|
2019-08-11 09:40:47 +00:00
|
|
|
|
|
|
|
Relevant Settings
|
|
|
|
-----------------
|
|
|
|
|
2019-08-11 11:17:36 +00:00
|
|
|
.. code:: yaml
|
|
|
|
|
|
|
|
renewable:
|
|
|
|
{technology}:
|
|
|
|
cutout:
|
|
|
|
|
2019-11-14 16:50:24 +00:00
|
|
|
.. seealso::
|
2019-08-13 08:03:46 +00:00
|
|
|
Documentation of the configuration file ``config.yaml`` at
|
|
|
|
:ref:`renewable_cf`
|
|
|
|
|
2019-08-11 09:40:47 +00:00
|
|
|
Inputs
|
|
|
|
------
|
|
|
|
|
2019-08-12 17:01:53 +00:00
|
|
|
- ``data/bundle/natura/Natura2000_end2015.shp``: `Natura 2000 <https://en.wikipedia.org/wiki/Natura_2000>`_ natural protection areas.
|
2019-08-11 20:34:18 +00:00
|
|
|
|
2019-08-14 13:36:46 +00:00
|
|
|
.. image:: ../img/natura.png
|
2019-08-11 20:34:18 +00:00
|
|
|
:scale: 33 %
|
|
|
|
|
2019-08-11 09:40:47 +00:00
|
|
|
Outputs
|
|
|
|
-------
|
|
|
|
|
2019-08-12 17:01:53 +00:00
|
|
|
- ``resources/natura.tiff``: Rasterized version of `Natura 2000 <https://en.wikipedia.org/wiki/Natura_2000>`_ natural protection areas to reduce computation times.
|
2019-08-11 20:34:18 +00:00
|
|
|
|
2019-08-14 13:36:46 +00:00
|
|
|
.. image:: ../img/natura.png
|
2019-08-11 20:34:18 +00:00
|
|
|
:scale: 33 %
|
|
|
|
|
2019-08-11 09:40:47 +00:00
|
|
|
Description
|
|
|
|
-----------
|
|
|
|
|
2019-08-08 13:02:28 +00:00
|
|
|
"""
|
|
|
|
|
2019-11-28 07:22:52 +00:00
|
|
|
import logging
|
|
|
|
from _helpers import configure_logging
|
2020-09-11 10:40:53 +00:00
|
|
|
|
2018-12-10 17:40:54 +00:00
|
|
|
import atlite
|
|
|
|
import geokit as gk
|
2019-12-09 20:29:15 +00:00
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
2018-12-10 17:40:54 +00:00
|
|
|
|
|
|
|
def determine_cutout_xXyY(cutout_name):
|
2019-12-09 20:29:15 +00:00
|
|
|
cutout = atlite.Cutout(cutout_name, cutout_dir=cutout_dir)
|
2018-12-10 17:40:54 +00:00
|
|
|
x, X, y, Y = cutout.extent
|
|
|
|
dx = (X - x) / (cutout.shape[1] - 1)
|
|
|
|
dy = (Y - y) / (cutout.shape[0] - 1)
|
|
|
|
return [x - dx/2., X + dx/2., y - dy/2., Y + dy/2.]
|
|
|
|
|
2019-12-09 20:29:15 +00:00
|
|
|
|
2019-08-08 13:02:28 +00:00
|
|
|
if __name__ == "__main__":
|
2019-12-09 20:29:15 +00:00
|
|
|
if 'snakemake' not in globals():
|
|
|
|
from _helpers import mock_snakemake
|
2020-09-11 10:40:53 +00:00
|
|
|
snakemake = mock_snakemake('build_natura_raster')
|
2019-11-28 07:22:52 +00:00
|
|
|
configure_logging(snakemake)
|
|
|
|
|
2019-12-09 20:29:15 +00:00
|
|
|
cutout_dir = Path(snakemake.input.cutouts[0]).parent.resolve()
|
|
|
|
cutout_names = {res['cutout'] for res in snakemake.config['renewable'].values()}
|
2019-08-08 13:02:28 +00:00
|
|
|
xs, Xs, ys, Ys = zip(*(determine_cutout_xXyY(cutout) for cutout in cutout_names))
|
|
|
|
xXyY = min(xs), max(Xs), min(ys), max(Ys)
|
2018-12-10 17:40:54 +00:00
|
|
|
|
2019-11-11 15:29:27 +00:00
|
|
|
natura = gk.vector.loadVector(snakemake.input.natura)
|
2019-08-08 13:02:28 +00:00
|
|
|
extent = gk.Extent.from_xXyY(xXyY).castTo(3035).fit(100)
|
|
|
|
extent.rasterize(natura, pixelWidth=100, pixelHeight=100, output=snakemake.output[0])
|