* Add logging to logfiles to all snakemake workflow scripts. * Fix missing quotation marks in Snakefile. * Apply suggestions from code review Co-Authored-By: Fabian Neumann <fabian.neumann@outlook.de> * Apply suggestions from code review Co-Authored-By: Fabian Neumann <fabian.neumann@outlook.de> * doc: fix _ec_ filenames in docs * Allow logging message format to be specified in config.yaml. * Add logging for Snakemake rule 'retrieve_databundle '. * Add limited logging to STDERR only for retrieve_*.py scripts. * Import progressbar module only on demand. * Fix logging to file and enable concurrent printing to STDERR for most scripts. * Add new 'logging_format' option to Travis CI test config.yaml. * Add missing parenthesis (bug fix) and cross-os compatible paths. * Fix typos in messages. * Use correct log files for logging (bug fix). * doc: fix line references * config: logging_format in all configs * doc: add doc for logging_format * environment: update to powerplantmatching 0.4.3 * doc: update line references for tutorial.rst * Change logging configuration scheme for config.yaml. * Add helper function for doing basic logging configuration. * Add logpath for prepare_links_p_nom rule. * Outsource basic logging configuration for all scripts to _helper submodule. * Update documentation for changed config.yaml structure. Instead of 'logging_level' and 'logging_format', now 'logging' with subcategories is used. * _helpers: Change configure_logging signature.
63 lines
1.7 KiB
Python
63 lines
1.7 KiB
Python
"""
|
|
Rasters the vector data of the `Natura 2000 <https://en.wikipedia.org/wiki/Natura_2000>`_ natural protection areas onto all cutout regions.
|
|
|
|
Relevant Settings
|
|
-----------------
|
|
|
|
.. code:: yaml
|
|
|
|
renewable:
|
|
{technology}:
|
|
cutout:
|
|
|
|
.. seealso::
|
|
Documentation of the configuration file ``config.yaml`` at
|
|
:ref:`renewable_cf`
|
|
|
|
Inputs
|
|
------
|
|
|
|
- ``data/bundle/natura/Natura2000_end2015.shp``: `Natura 2000 <https://en.wikipedia.org/wiki/Natura_2000>`_ natural protection areas.
|
|
|
|
.. image:: ../img/natura.png
|
|
:scale: 33 %
|
|
|
|
Outputs
|
|
-------
|
|
|
|
- ``resources/natura.tiff``: Rasterized version of `Natura 2000 <https://en.wikipedia.org/wiki/Natura_2000>`_ natural protection areas to reduce computation times.
|
|
|
|
.. image:: ../img/natura.png
|
|
:scale: 33 %
|
|
|
|
Description
|
|
-----------
|
|
|
|
"""
|
|
|
|
import logging
|
|
logger = logging.getLogger(__name__)
|
|
from _helpers import configure_logging
|
|
|
|
import numpy as np
|
|
import atlite
|
|
import geokit as gk
|
|
|
|
def determine_cutout_xXyY(cutout_name):
|
|
cutout = atlite.Cutout(cutout_name, cutout_dir="cutouts")
|
|
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.]
|
|
|
|
if __name__ == "__main__":
|
|
configure_logging(snakemake)
|
|
|
|
cutout_names = np.unique([res['cutout'] for res in snakemake.config['renewable'].values()])
|
|
xs, Xs, ys, Ys = zip(*(determine_cutout_xXyY(cutout) for cutout in cutout_names))
|
|
xXyY = min(xs), max(Xs), min(ys), max(Ys)
|
|
|
|
natura = gk.vector.loadVector(snakemake.input.natura)
|
|
extent = gk.Extent.from_xXyY(xXyY).castTo(3035).fit(100)
|
|
extent.rasterize(natura, pixelWidth=100, pixelHeight=100, output=snakemake.output[0])
|