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
|
|
|
Create cutouts with `atlite <https://atlite.readthedocs.io/en/latest/>`_.
|
2019-08-11 09:40:47 +00:00
|
|
|
|
2019-10-03 10:38:59 +00:00
|
|
|
For this rule to work you must have
|
|
|
|
|
|
|
|
- installed the `Copernicus Climate Data Store <https://cds.climate.copernicus.eu>`_ ``cdsapi`` package (`install with `pip``) and
|
|
|
|
- registered and setup your CDS API key as described `on their website <https://cds.climate.copernicus.eu/api-how-to>`_.
|
|
|
|
|
|
|
|
.. seealso::
|
|
|
|
For details on the weather data read the `atlite documentation <https://atlite.readthedocs.io/en/latest/>`_.
|
|
|
|
If you need help specifically for creating cutouts `the corresponding section in the atlite documentation <https://atlite.readthedocs.io/en/latest/examples/create_cutout.html>`_ should be helpful.
|
|
|
|
|
2019-08-11 09:40:47 +00:00
|
|
|
Relevant Settings
|
|
|
|
-----------------
|
|
|
|
|
2019-08-11 11:17:36 +00:00
|
|
|
.. code:: yaml
|
|
|
|
|
|
|
|
atlite:
|
|
|
|
nprocesses:
|
|
|
|
cutouts:
|
|
|
|
{cutout}:
|
|
|
|
|
2019-12-09 20:29:15 +00:00
|
|
|
.. seealso::
|
2019-08-13 08:03:46 +00:00
|
|
|
Documentation of the configuration file ``config.yaml`` at
|
|
|
|
:ref:`atlite_cf`
|
|
|
|
|
2019-08-11 09:40:47 +00:00
|
|
|
Inputs
|
|
|
|
------
|
|
|
|
|
2019-08-11 20:34:18 +00:00
|
|
|
*None*
|
|
|
|
|
2019-08-11 09:40:47 +00:00
|
|
|
Outputs
|
|
|
|
-------
|
|
|
|
|
2019-08-13 13:48:21 +00:00
|
|
|
- ``cutouts/{cutout}``: weather data from either the `ERA5 <https://www.ecmwf.int/en/forecasts/datasets/reanalysis-datasets/era5>`_
|
|
|
|
reanalysis weather dataset or `SARAH-2 <https://wui.cmsaf.eu/safira/action/viewProduktSearch>`_
|
|
|
|
satellite-based historic weather data with the following structure:
|
|
|
|
|
|
|
|
**ERA5 cutout:**
|
|
|
|
|
|
|
|
=================== ========== ========== =========================================================
|
|
|
|
Field Dimensions Unit Description
|
|
|
|
=================== ========== ========== =========================================================
|
|
|
|
pressure time, y, x Pa Surface pressure
|
|
|
|
------------------- ---------- ---------- ---------------------------------------------------------
|
|
|
|
temperature time, y, x K Air temperature 2 meters above the surface.
|
|
|
|
------------------- ---------- ---------- ---------------------------------------------------------
|
|
|
|
soil temperature time, y, x K Soil temperature between 1 meters and 3 meters
|
|
|
|
depth (layer 4).
|
|
|
|
------------------- ---------- ---------- ---------------------------------------------------------
|
|
|
|
influx_toa time, y, x Wm**-2 Top of Earth's atmosphere TOA incident solar radiation
|
|
|
|
------------------- ---------- ---------- ---------------------------------------------------------
|
|
|
|
influx_direct time, y, x Wm**-2 Total sky direct solar radiation at surface
|
|
|
|
------------------- ---------- ---------- ---------------------------------------------------------
|
|
|
|
runoff time, y, x m `Runoff <https://en.wikipedia.org/wiki/Surface_runoff>`_
|
|
|
|
(volume per area)
|
|
|
|
------------------- ---------- ---------- ---------------------------------------------------------
|
|
|
|
roughness y, x m Forecast surface roughness
|
|
|
|
(`roughness length <https://en.wikipedia.org/wiki/Roughness_length>`_)
|
|
|
|
------------------- ---------- ---------- ---------------------------------------------------------
|
|
|
|
height y, x m Surface elevation above sea level
|
|
|
|
------------------- ---------- ---------- ---------------------------------------------------------
|
|
|
|
albedo time, y, x -- `Albedo <https://en.wikipedia.org/wiki/Albedo>`_
|
|
|
|
measure of diffuse reflection of solar radiation.
|
|
|
|
Calculated from relation between surface solar radiation
|
|
|
|
downwards (Jm**-2) and surface net solar radiation
|
|
|
|
(Jm**-2). Takes values between 0 and 1.
|
|
|
|
------------------- ---------- ---------- ---------------------------------------------------------
|
|
|
|
influx_diffuse time, y, x Wm**-2 Diffuse solar radiation at surface.
|
|
|
|
Surface solar radiation downwards minus
|
|
|
|
direct solar radiation.
|
|
|
|
------------------- ---------- ---------- ---------------------------------------------------------
|
|
|
|
wnd100m time, y, x ms**-1 Wind speeds at 100 meters (regardless of direction)
|
|
|
|
=================== ========== ========== =========================================================
|
|
|
|
|
2019-08-14 13:36:46 +00:00
|
|
|
.. image:: ../img/era5.png
|
2019-12-09 20:29:15 +00:00
|
|
|
:scale: 40 %
|
|
|
|
|
2019-08-13 13:48:21 +00:00
|
|
|
A **SARAH-2 cutout** can be used to amend the fields ``temperature``, ``influx_toa``, ``influx_direct``, ``albedo``,
|
|
|
|
``influx_diffuse`` of ERA5 using satellite-based radiation observations.
|
2019-12-09 20:29:15 +00:00
|
|
|
|
2019-08-14 13:36:46 +00:00
|
|
|
.. image:: ../img/sarah.png
|
2019-08-13 13:48:21 +00:00
|
|
|
:scale: 40 %
|
|
|
|
|
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
|
|
|
|
2018-08-03 09:54:28 +00:00
|
|
|
import logging
|
2019-11-28 07:22:52 +00:00
|
|
|
from _helpers import configure_logging
|
|
|
|
|
|
|
|
import os
|
|
|
|
import atlite
|
2018-08-03 09:54:28 +00:00
|
|
|
|
2020-12-03 18:50:53 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
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
|
|
|
|
snakemake = mock_snakemake('build_cutout', cutout='europe-2013-era5')
|
2019-11-28 07:22:52 +00:00
|
|
|
configure_logging(snakemake)
|
2018-08-03 09:54:28 +00:00
|
|
|
|
2019-08-08 13:02:28 +00:00
|
|
|
cutout_params = snakemake.config['atlite']['cutouts'][snakemake.wildcards.cutout]
|
|
|
|
for p in ('xs', 'ys', 'years', 'months'):
|
|
|
|
if p in cutout_params:
|
|
|
|
cutout_params[p] = slice(*cutout_params[p])
|
2018-08-03 10:46:42 +00:00
|
|
|
|
2019-08-08 13:02:28 +00:00
|
|
|
cutout = atlite.Cutout(snakemake.wildcards.cutout,
|
|
|
|
cutout_dir=os.path.dirname(snakemake.output[0]),
|
|
|
|
**cutout_params)
|
2018-08-03 09:54:28 +00:00
|
|
|
|
2020-12-03 18:50:53 +00:00
|
|
|
nprocesses = snakemake.config['atlite'].get('nprocesses', 4)
|
|
|
|
|
|
|
|
cutout.prepare(nprocesses=nprocesses)
|