add example for snakemake and configuration
This commit is contained in:
parent
485b66c2c9
commit
9ab516ff39
@ -33,7 +33,7 @@ electricity:
|
||||
battery: 6
|
||||
H2: 168
|
||||
|
||||
conventional_carriers: [] # [nuclear, oil, OCGT, CCGT, coal, lignite, geothermal, biomass]
|
||||
conventional_carriers: [coal, CCGT] # [nuclear, oil, OCGT, CCGT, coal, lignite, geothermal, biomass]
|
||||
|
||||
atlite:
|
||||
nprocesses: 4
|
||||
@ -72,7 +72,6 @@ renewable:
|
||||
# correction_factor: 0.93
|
||||
corine: [44, 255]
|
||||
natura: true
|
||||
#max_depth: 50
|
||||
max_shore_distance: 30000
|
||||
potential: simple # or conservative
|
||||
clip_p_max_pu: 1.e-2
|
||||
@ -86,7 +85,6 @@ renewable:
|
||||
# correction_factor: 0.93
|
||||
corine: [44, 255]
|
||||
natura: true
|
||||
#max_depth: 50
|
||||
min_shore_distance: 30000
|
||||
potential: simple # or conservative
|
||||
clip_p_max_pu: 1.e-2
|
||||
@ -156,7 +154,7 @@ solving:
|
||||
clip_p_max_pu: 0.01
|
||||
#nhours: 10
|
||||
solver:
|
||||
name: cbc
|
||||
name: ipopt
|
||||
# solver:
|
||||
# name: gurobi
|
||||
# threads: 4
|
||||
|
@ -4,14 +4,14 @@
|
||||
Configuration
|
||||
##########################################
|
||||
|
||||
PyPSA-Eur has several configuration options which are documented in this section and are collected in a ``config.yaml`` file located in the root directory. Users can amend their own modifications and assumptions by changing the default configuration provided in the configuration file (``config.yaml``).
|
||||
PyPSA-Eur has several configuration options which are documented in this section and are collected in a ``config.yaml`` file located in the root directory. Users should copy the provided default configuration (``config.default.yaml``) and amend their own modifications and assumptions in the user-specific configuration file (``config.yaml``); confer installation instructions at :ref:`defaultconfig`.
|
||||
|
||||
.. _toplevel_cf:
|
||||
|
||||
Top-level configuration
|
||||
=======================
|
||||
|
||||
.. literalinclude:: ../config.yaml
|
||||
.. literalinclude:: ../config.default.yaml
|
||||
:language: yaml
|
||||
:lines: 1-5,13
|
||||
|
||||
@ -43,7 +43,7 @@ An exemplary dependency graph (starting from the simplification rules) then look
|
||||
|
||||
.. image:: img/scenarios.png
|
||||
|
||||
.. literalinclude:: ../config.yaml
|
||||
.. literalinclude:: ../config.default.yaml
|
||||
:language: yaml
|
||||
:lines: 6-11
|
||||
|
||||
@ -59,7 +59,7 @@ An exemplary dependency graph (starting from the simplification rules) then look
|
||||
|
||||
Specifies the temporal range to build an energy system model for as arguments to `pandas.date_range <https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.date_range.html>`_
|
||||
|
||||
.. literalinclude:: ../config.yaml
|
||||
.. literalinclude:: ../config.default.yaml
|
||||
:language: yaml
|
||||
:lines: 15-18
|
||||
|
||||
@ -73,7 +73,7 @@ Specifies the temporal range to build an energy system model for as arguments to
|
||||
``electricity``
|
||||
===============
|
||||
|
||||
.. literalinclude:: ../config.yaml
|
||||
.. literalinclude:: ../config.default.yaml
|
||||
:language: yaml
|
||||
:lines: 24-36
|
||||
|
||||
@ -90,7 +90,7 @@ Specifies the temporal range to build an energy system model for as arguments to
|
||||
``atlite``
|
||||
=============
|
||||
|
||||
.. literalinclude:: ../config.yaml
|
||||
.. literalinclude:: ../config.default.yaml
|
||||
:language: yaml
|
||||
:lines: 38-51
|
||||
|
||||
@ -107,7 +107,7 @@ Specifies the temporal range to build an energy system model for as arguments to
|
||||
``onwind``
|
||||
----------
|
||||
|
||||
.. literalinclude:: ../config.yaml
|
||||
.. literalinclude:: ../config.default.yaml
|
||||
:language: yaml
|
||||
:lines: 53-70
|
||||
|
||||
@ -119,7 +119,7 @@ Specifies the temporal range to build an energy system model for as arguments to
|
||||
``offwind-ac``
|
||||
--------------
|
||||
|
||||
.. literalinclude:: ../config.yaml
|
||||
.. literalinclude:: ../config.default.yaml
|
||||
:language: yaml
|
||||
:lines: 53,71-83
|
||||
|
||||
@ -131,7 +131,7 @@ Specifies the temporal range to build an energy system model for as arguments to
|
||||
``offwind-dc``
|
||||
---------------
|
||||
|
||||
.. literalinclude:: ../config.yaml
|
||||
.. literalinclude:: ../config.default.yaml
|
||||
:language: yaml
|
||||
:lines: 53,84-97
|
||||
|
||||
@ -143,7 +143,7 @@ Specifies the temporal range to build an energy system model for as arguments to
|
||||
``solar``
|
||||
---------------
|
||||
|
||||
.. literalinclude:: ../config.yaml
|
||||
.. literalinclude:: ../config.default.yaml
|
||||
:language: yaml
|
||||
:lines: 53,98-117
|
||||
|
||||
@ -155,7 +155,7 @@ Specifies the temporal range to build an energy system model for as arguments to
|
||||
``hydro``
|
||||
---------------
|
||||
|
||||
.. literalinclude:: ../config.yaml
|
||||
.. literalinclude:: ../config.default.yaml
|
||||
:language: yaml
|
||||
:lines: 53,118-124
|
||||
|
||||
@ -169,7 +169,7 @@ Specifies the temporal range to build an energy system model for as arguments to
|
||||
``lines``
|
||||
=============
|
||||
|
||||
.. literalinclude:: ../config.yaml
|
||||
.. literalinclude:: ../config.default.yaml
|
||||
:language: yaml
|
||||
:lines: 126-133
|
||||
|
||||
@ -183,7 +183,7 @@ Specifies the temporal range to build an energy system model for as arguments to
|
||||
``links``
|
||||
=============
|
||||
|
||||
.. literalinclude:: ../config.yaml
|
||||
.. literalinclude:: ../config.default.yaml
|
||||
:language: yaml
|
||||
:lines: 135-138
|
||||
|
||||
@ -197,7 +197,7 @@ Specifies the temporal range to build an energy system model for as arguments to
|
||||
``transformers``
|
||||
================
|
||||
|
||||
.. literalinclude:: ../config.yaml
|
||||
.. literalinclude:: ../config.default.yaml
|
||||
:language: yaml
|
||||
:lines: 140-143
|
||||
|
||||
@ -211,7 +211,7 @@ Specifies the temporal range to build an energy system model for as arguments to
|
||||
``load``
|
||||
=============
|
||||
|
||||
.. literalinclude:: ../config.yaml
|
||||
.. literalinclude:: ../config.default.yaml
|
||||
:language: yaml
|
||||
:lines: 145-146
|
||||
|
||||
@ -225,7 +225,7 @@ Specifies the temporal range to build an energy system model for as arguments to
|
||||
``costs``
|
||||
=============
|
||||
|
||||
.. literalinclude:: ../config.yaml
|
||||
.. literalinclude:: ../config.default.yaml
|
||||
:language: yaml
|
||||
:lines: 148-160
|
||||
|
||||
@ -247,7 +247,7 @@ Specifies the temporal range to build an energy system model for as arguments to
|
||||
``options``
|
||||
-----------
|
||||
|
||||
.. literalinclude:: ../config.yaml
|
||||
.. literalinclude:: ../config.default.yaml
|
||||
:language: yaml
|
||||
:lines: 162-170
|
||||
|
||||
@ -259,7 +259,7 @@ Specifies the temporal range to build an energy system model for as arguments to
|
||||
``solver``
|
||||
----------
|
||||
|
||||
.. literalinclude:: ../config.yaml
|
||||
.. literalinclude:: ../config.default.yaml
|
||||
:language: yaml
|
||||
:lines: 162,171-187
|
||||
|
||||
@ -273,7 +273,7 @@ Specifies the temporal range to build an energy system model for as arguments to
|
||||
``plotting``
|
||||
=============
|
||||
|
||||
.. literalinclude:: ../config.yaml
|
||||
.. literalinclude:: ../config.default.yaml
|
||||
:language: yaml
|
||||
:lines: 189-323
|
||||
|
||||
|
150
doc/example.rst
150
doc/example.rst
@ -1,150 +0,0 @@
|
||||
#####################
|
||||
Examples
|
||||
#####################
|
||||
|
||||
.. todo:: some of this is duplicated in other sections in the documentation. Consense!
|
||||
|
||||
As PyPSA-EUR has mostly the same features as PyPSA in general, this provided example will guide the reader through running a simplified model:
|
||||
|
||||
#. how to configure a (PyPSA-EUR) network model
|
||||
|
||||
#. how to run snakemake (step by step) from network creation to the fully solved network
|
||||
|
||||
#. short analysis of the solved network (provided jupyter notebook)
|
||||
|
||||
|
||||
All of the data can be found in ``/pypsa-eur/example/``.
|
||||
|
||||
.. note::
|
||||
If you were to re-run the example, make sure to take care of the following two arrangement-changes:
|
||||
|
||||
#. exchange the ``pypsa-eur/cutouts/europe-2013-era5`` folder by the provided one in ``pypsa-eur/example/europe-2013-era5``
|
||||
|
||||
#. exchange the ``pypsa-eur/config.yaml`` file by the provided ``pypsa-eur/example/config.yaml``
|
||||
|
||||
You can also rename the original files before pasting the examplary cutout and configuration which will make it easier to switch back after the example.
|
||||
|
||||
Configuration
|
||||
=============
|
||||
All references in this section relate to the ``config.yaml`` provided for this example unless mentioned otherwise. We discuss only major changes to the provided default configuration or point out important settings, as the full discussion of configuration would be too extensive.
|
||||
|
||||
Our model example considers only Germany (from all the european countries)
|
||||
|
||||
.. code-block:: yaml
|
||||
:emphasize-lines: 0
|
||||
|
||||
countries: ['DE']
|
||||
|
||||
for the duration of only a single month (03.2013):
|
||||
|
||||
.. code-block:: yaml
|
||||
:emphasize-lines: 0
|
||||
|
||||
snapshots:
|
||||
start: "2013-03-01"
|
||||
end: "2013-04-01"
|
||||
closed: 'left' #end is not inclusive
|
||||
|
||||
As we consider a huge cutout (in comparison to whole europe), we should also adapt the CO2-Limit:
|
||||
|
||||
.. code-block:: yaml
|
||||
:emphasize-lines: 0
|
||||
|
||||
electricity:
|
||||
[...]
|
||||
co2limit: 110.6e+6 #(1/12 DE)
|
||||
|
||||
We consider all the available conventional generators
|
||||
|
||||
.. code-block:: yaml
|
||||
:emphasize-lines: 0
|
||||
|
||||
conventional_carriers: [nuclear, oil, CCGT, coal, lignite, geothermal, biomass]
|
||||
|
||||
with fixed capacity (data provided by pypsa-eur in ``/pypsa-eur/resources/powerplants.csv``), while an additional expandable carrier steps in whenever there is unmet demand that cannot be covered by included Storage Units:
|
||||
|
||||
.. code-block:: yaml
|
||||
:emphasize-lines: 0
|
||||
|
||||
electricity:
|
||||
[...]
|
||||
extendable_carriers:
|
||||
Generator: [OCGT]
|
||||
StorageUnit: [battery, H2]
|
||||
max_hours:
|
||||
battery: 6
|
||||
H2: 168
|
||||
|
||||
To include profiles (availability curves) for the variable renewable we restrict to the ERA5 dataset in ``/pypsa-eur/cutouts/europe-2013-era5/`` for the same month (03.2013) as well as the approximate latitude and longitude of Germany:
|
||||
|
||||
.. code-block:: yaml
|
||||
:emphasize-lines: 0
|
||||
|
||||
atlite:
|
||||
cutouts:
|
||||
europe-2013-era5:
|
||||
xs: [4.,15.]
|
||||
ys: [56., 46.]
|
||||
months: [3, 3]
|
||||
years: [2013, 2013]
|
||||
|
||||
.. code-block:: yaml
|
||||
:emphasize-lines: 0
|
||||
|
||||
renewable:
|
||||
[...]
|
||||
solar:
|
||||
cutout: europe-2013-era5
|
||||
|
||||
|
||||
This last step is insignificant (should not be carried out when running any snakerule) as this example provides the necessary cutout.
|
||||
|
||||
Finally, the solver is adapted to ``cbc``, as gurobi might not be free of charge:
|
||||
|
||||
.. code-block:: yaml
|
||||
:emphasize-lines: 0
|
||||
|
||||
solving:
|
||||
[...]
|
||||
solver:
|
||||
name: cbc
|
||||
|
||||
.. note::
|
||||
For this configuration it might be necessary to install the package ``ipopt``:
|
||||
|
||||
``conda install -c conda-forge ipopt``
|
||||
|
||||
All the other configuration parameters remain default.
|
||||
|
||||
Snakemake
|
||||
=========
|
||||
In order to obtain the resulting network (which also is provided, but try to recunstruct it yourself), open a ``terminal`` (or use the shell in EMACS), activate the pypsa-eur environment (``activate pypsa-eur``) and run:
|
||||
|
||||
``snakemake results/networks/elec_s_10_lvopt_Co2L-3H.nc``
|
||||
|
||||
where the final solved network can be now found in ``pypsa-eur/results/networks`` with the name ``elec_s_10_lvopt_Co2L-3H.nc``. Each of the intermediate stages is also saved (which we will not discuss here in detail - for more information, see [reference Section] Rules Overview) in ``pypsa-eur/networks``:
|
||||
|
||||
#. ``base.nc``:
|
||||
|
||||
Contains the basic network with buses, links and lines.
|
||||
|
||||
#. ``elec.nc``:
|
||||
|
||||
Adds electricity to the network, such as generators (individual carriers with their respective capacities), loads and availability profiles for each individual carrier (all of the previous located at the corresponding buses)
|
||||
|
||||
#. ``elec_s.nc``:
|
||||
|
||||
Simplifies the previous network (e.g. aggregates generators of same type within one bus)
|
||||
|
||||
#. ``elec_s_10.nc``:
|
||||
|
||||
Clusters the previous network to a smaller one with only 10 buses. The previous contained 333 buses.
|
||||
|
||||
#. ``elec_s_10_lvopt_Co2L-3H.nc``:
|
||||
|
||||
Reduces the time resulution of the network from hourly to every 3 hours and includes the option to optimive line volumes (lvopt) for the solver.
|
||||
|
||||
Short Analysis of the German Network (Jupyter)
|
||||
==============================================
|
||||
|
||||
Open the jupyter notebook ``pypsa-eur_example.ipynb`` and consider buses as well as the timeseries for dispatch.
|
@ -43,7 +43,7 @@ Documentation
|
||||
|
||||
* :doc:`introduction`
|
||||
* :doc:`installation`
|
||||
* :doc:`example`
|
||||
* :doc:`tutorial`
|
||||
|
||||
.. toctree::
|
||||
:hidden:
|
||||
@ -52,7 +52,7 @@ Documentation
|
||||
|
||||
introduction
|
||||
installation
|
||||
example
|
||||
tutorial
|
||||
|
||||
**Configuration**
|
||||
|
||||
|
@ -61,10 +61,10 @@ extracting them manually in the locations outlined below.
|
||||
The :ref:`tutorial` uses smaller data bundles than required for the full model.
|
||||
To start with the tutorial, substitute with the links below using the following alternatives:
|
||||
|
||||
- **Data Bundle:** ``https://vfs.fias.science/d/0a0ca1e2fb/files/?dl=1&p=/pypsa-eur-data-bundle.tar.xz``
|
||||
- **Cutouts:** ``https://vfs.fias.science/d/0a0ca1e2fb/files/?p=/pypsa-eur-cutouts.tar.xz``
|
||||
- **Data Bundle:** ``https://vfs.fias.science/d/0a0ca1e2fb/files/?dl=1&p=/pypsa-eur-data-bundle.tar.xz`` (197 MB)
|
||||
- **Cutouts:** ``https://vfs.fias.science/d/0a0ca1e2fb/files/?p=/pypsa-eur-cutouts.tar.xz`` (19 MB)
|
||||
|
||||
1. **Data Bundle:** `pypsa-eur-data-bundle.tar.xz <https://vfs.fias.science/d/0a0ca1e2fb/files/?p=/pypsa-eur-data-bundle.tar.xz>`_ contains common GIS datasets like NUTS3 shapes, EEZ shapes, CORINE Landcover, Natura 2000 and also electricity specific summary statistics like historic per country yearly totals of hydro generation, GDP and POP on NUTS3 levels and per-country load time-series. It should be extracted in the ``data`` sub-directory, such that all files of the bundle are stored in the ``data/bundle`` subdirectory)
|
||||
1. **Data Bundle:** `pypsa-eur-data-bundle.tar.xz <https://vfs.fias.science/d/0a0ca1e2fb/files/?p=/pypsa-eur-data-bundle.tar.xz>`_ (1.3 GB) contains common GIS datasets like NUTS3 shapes, EEZ shapes, CORINE Landcover, Natura 2000 and also electricity specific summary statistics like historic per country yearly totals of hydro generation, GDP and POP on NUTS3 levels and per-country load time-series. It should be extracted in the ``data`` sub-directory, such that all files of the bundle are stored in the ``data/bundle`` subdirectory)
|
||||
|
||||
.. code:: bash
|
||||
|
||||
@ -73,7 +73,7 @@ extracting them manually in the locations outlined below.
|
||||
.../pypsa-eur/data % tar xJf pypsa-eur-data-bundle.tar.xz
|
||||
|
||||
|
||||
2. **Cutouts:** `pypsa-eur-cutouts.tar.xz <https://vfs.fias.science/d/0a0ca1e2fb/files/?p=/pypsa-eur-cutouts.tar.xz>`_ are spatiotemporal subsets of the European weather data from the `ECMWF ERA5 <https://software.ecmwf.int/wiki/display/CKB/ERA5+data+documentation>`_ reanalysis dataset and the `CMSAF SARAH-2 <https://wui.cmsaf.eu/safira/action/viewDoiDetails?acronym=SARAH_V002>`_ solar surface radiation dataset for the year 2013. They have been prepared by and are for use with the `atlite <https://github.com/PyPSA/atlite>`_ tool. You can either generate them yourself using the ``build_cutouts`` rule or extract them directly into the ``pypsa-eur`` directory. To download cutouts yourself you need to `set up the CDS API <https://cds.climate.copernicus.eu/api-how-to>`_. For more details read the `atlite documentation <https://atlite.readthedocs.io>`_. For beginners, extracting the bundle is recommended:
|
||||
2. **Cutouts:** `pypsa-eur-cutouts.tar.xz <https://vfs.fias.science/d/0a0ca1e2fb/files/?p=/pypsa-eur-cutouts.tar.xz>`_ (3.9 GB) are spatiotemporal subsets of the European weather data from the `ECMWF ERA5 <https://software.ecmwf.int/wiki/display/CKB/ERA5+data+documentation>`_ reanalysis dataset and the `CMSAF SARAH-2 <https://wui.cmsaf.eu/safira/action/viewDoiDetails?acronym=SARAH_V002>`_ solar surface radiation dataset for the year 2013. They have been prepared by and are for use with the `atlite <https://github.com/PyPSA/atlite>`_ tool. You can either generate them yourself using the ``build_cutouts`` rule or extract them directly into the ``pypsa-eur`` directory. To download cutouts yourself you need to `set up the CDS API <https://cds.climate.copernicus.eu/api-how-to>`_. For more details read the `atlite documentation <https://atlite.readthedocs.io>`_. For beginners, extracting the bundle is recommended:
|
||||
|
||||
.. code:: bash
|
||||
|
||||
@ -100,6 +100,7 @@ Install a Solver
|
||||
PyPSA passes the PyPSA-Eur network model to an external solver for performing a total annual system cost minimization with optimal power flow.
|
||||
PyPSA is known to work with the free software
|
||||
|
||||
- `Ipopt <https://coin-or.github.io/Ipopt/INSTALL.html>`_
|
||||
- `Cbc <https://projects.coin-or.org/Cbc#DownloadandInstall>`_
|
||||
- `GLPK <https://www.gnu.org/software/glpk/>`_ (`WinGLKP <http://winglpk.sourceforge.net/>`_)
|
||||
|
||||
@ -134,3 +135,14 @@ Before first use, create a ``config.yaml`` by copying the example.
|
||||
|
||||
Users are advised to regularly check their own ``config.yaml`` against changes in the ``config.default.yaml``
|
||||
when pulling a new version from the remote repository.
|
||||
|
||||
Using PyPSA-Eur with Docker Images
|
||||
==================================
|
||||
|
||||
If docker. Optional.
|
||||
|
||||
To run on cloud computing.
|
||||
|
||||
Gurobi license - floating token server - license must not be tied to a particular machine
|
||||
|
||||
Provide ``Dockerfile``.
|
||||
|
265
doc/tutorial.rst
Normal file
265
doc/tutorial.rst
Normal file
@ -0,0 +1,265 @@
|
||||
.. _tutorial:
|
||||
|
||||
#####################
|
||||
Tutorial
|
||||
#####################
|
||||
|
||||
Before getting started with **PyPSA-Eur** it makes sense to be familiar
|
||||
with its general modelling framework `PyPSA <https://pypsa.readthedocs.io>`_.
|
||||
|
||||
Running the tutorial requires limited computational resources compared to the full model,
|
||||
which allows the user to explore most of its functionalities on a local machine.
|
||||
It takes approximately five minutes to complete and
|
||||
requires 3 GB of memory along with 1 GB free disk space.
|
||||
|
||||
The tutorial will cover examples on how to
|
||||
|
||||
- configure and customise the PyPSA-Eur model and
|
||||
- run the ``snakemake`` workflow step by step from network creation to the solved network.
|
||||
|
||||
If not yet completed, follow the :ref:`installation` steps but
|
||||
substitute the links for the **data bundle** and the **cutouts** with the following lightweight alternatives:
|
||||
|
||||
- **Data Bundle:** ``https://vfs.fias.science/d/0a0ca1e2fb/files/?dl=1&p=/pypsa-eur-data-bundle.tar.xz`` (197 MB)
|
||||
- **Cutouts:** ``https://vfs.fias.science/d/0a0ca1e2fb/files/?p=/pypsa-eur-cutouts.tar.xz`` (19 MB)
|
||||
|
||||
The configuration of the tutorial is included in the ``config.tutorial.yaml``.
|
||||
To run the tutorial, use this as your configuration file ``config.yaml``.
|
||||
|
||||
.. code:: bash
|
||||
|
||||
.../pypsa-eur % cp config.default.yaml config.yaml
|
||||
|
||||
How to customise PyPSA-Eur?
|
||||
===========================
|
||||
|
||||
The model can be adapted to only include selected countries (e.g. Germany) instead of all European countries to limit the spatial scope.
|
||||
|
||||
.. literalinclude:: ../config.tutorial.yaml
|
||||
:language: yaml
|
||||
:lines: 13
|
||||
|
||||
Likewise, the example's temporal scope can be restricted (e.g. to a single month).
|
||||
|
||||
.. literalinclude:: ../config.tutorial.yaml
|
||||
:language: yaml
|
||||
:lines: 15-18
|
||||
|
||||
It is also possible to allow less or more carbon-dioxide emissions. Here, we limit the emissions of Germany 100 Megatonnes per year.
|
||||
|
||||
.. literalinclude:: ../config.tutorial.yaml
|
||||
:language: yaml
|
||||
:lines: 26
|
||||
|
||||
PyPSA-Eur also includes a database of existing conventional powerplants.
|
||||
We can select which types of powerplants we like to be included with fixed capacities:
|
||||
|
||||
.. literalinclude:: ../config.tutorial.yaml
|
||||
:language: yaml
|
||||
:lines: 36
|
||||
|
||||
To accurately model the temporal and spatial availability of renewables such as wind and solar energy, we rely on historical weather data.
|
||||
It is advisable to adapt the required range of coordinates to the selection of countries.
|
||||
|
||||
.. literalinclude:: ../config.tutorial.yaml
|
||||
:language: yaml
|
||||
:lines: 38-47
|
||||
|
||||
We can also decide which weather data source should be used to calculate potentials and capacity factor time-series for each carrier.
|
||||
For example, we may want to use the ERA-5 dataset for solar and not the default SARAH-2 dataset.
|
||||
|
||||
.. literalinclude:: ../config.tutorial.yaml
|
||||
:language: yaml
|
||||
:lines: 48,91-92
|
||||
|
||||
Finally, it is possible to pick a solver. For instance, this tutorial uses the open-source solver Ipopt and does not rely
|
||||
on the commercial solvers Gurobi or CPLEX (for which free academic licenses are available).
|
||||
|
||||
.. literalinclude:: ../config.tutorial.yaml
|
||||
:language: yaml
|
||||
:lines: 156-157
|
||||
|
||||
Note, that we only note major changes to the provided default configuration that is comprehensibly documented in :ref:`config`.
|
||||
There are many more configuration options beyond what is adapted for the tutorial!
|
||||
|
||||
How to use the ``snakemake`` rules?
|
||||
===================================
|
||||
|
||||
Open a terminal, go into the PyPSA-Eur directory, and activate the ``pypsa-eur`` environment with
|
||||
|
||||
.. code:: bash
|
||||
|
||||
.../pypsa-eur % conda activate pypsa-eur
|
||||
|
||||
Let's say based on the modifications above we would like to solve a very simplified model
|
||||
clustered down to 6 buses and every 24 hours aggregated to one snapshot. The command
|
||||
|
||||
.. code:: bash
|
||||
|
||||
.../pypsa-eur % snakemake results/networks/elec_s_6_lcopt_Co2L-24H.
|
||||
|
||||
orders ``snakemake`` to run the script ``solve_network`` that produces the solved network and stores it in ``.../pypsa-eur/results/networks`` with the name ``elec_s_6_lcopt_Co2L-24H.nc``:
|
||||
|
||||
.. code::
|
||||
|
||||
rule solve_network:
|
||||
input: "networks/{network}_s{simpl}_{clusters}_l{ll}_{opts}.nc"
|
||||
output: "results/networks/{network}_s{simpl}_{clusters}_l{ll}_{opts}.nc"
|
||||
[...]
|
||||
script: "scripts/solve_network.py"
|
||||
|
||||
This triggers a workflow of multiple preceding jobs that depend on each rule's inputs and outputs:
|
||||
|
||||
.. graphviz::
|
||||
:align: center
|
||||
|
||||
digraph snakemake_dag {
|
||||
graph[bgcolor=white, margin=0];
|
||||
node[shape=box, style=rounded, fontname=sans, fontsize=10, penwidth=2];
|
||||
edge[penwidth=2, color=grey];
|
||||
0[label = "solve_network", color = "0.10 0.6 0.85", style="rounded"];
|
||||
1[label = "prepare_network\nll: copt\nopts: Co2L-24H", color = "0.13 0.6 0.85", style="rounded"];
|
||||
2[label = "cluster_network\nclusters: 6", color = "0.51 0.6 0.85", style="rounded"];
|
||||
3[label = "simplify_network\nnetwork: elec\nsimpl: ", color = "0.00 0.6 0.85", style="rounded"];
|
||||
4[label = "add_electricity", color = "0.60 0.6 0.85", style="rounded"];
|
||||
5[label = "build_bus_regions", color = "0.19 0.6 0.85", style="rounded"];
|
||||
6[label = "base_network", color = "0.38 0.6 0.85", style="rounded"];
|
||||
7[label = "build_shapes", color = "0.03 0.6 0.85", style="rounded"];
|
||||
8[label = "build_renewable_profiles\ntechnology: onwind", color = "0.48 0.6 0.85", style="rounded"];
|
||||
9[label = "build_renewable_profiles\ntechnology: offwind-ac", color = "0.48 0.6 0.85", style="rounded"];
|
||||
10[label = "build_renewable_profiles\ntechnology: offwind-dc", color = "0.48 0.6 0.85", style="rounded"];
|
||||
11[label = "build_renewable_profiles\ntechnology: solar", color = "0.48 0.6 0.85", style="rounded"];
|
||||
12[label = "build_cutout\ncutout: europe-2013-era5", color = "0.35 0.6 0.85", style="rounded,dashed"];
|
||||
1 -> 0
|
||||
2 -> 1
|
||||
3 -> 2
|
||||
4 -> 3
|
||||
5 -> 3
|
||||
6 -> 4
|
||||
5 -> 4
|
||||
7 -> 4
|
||||
8 -> 4
|
||||
9 -> 4
|
||||
10 -> 4
|
||||
11 -> 4
|
||||
7 -> 5
|
||||
6 -> 5
|
||||
7 -> 6
|
||||
6 -> 8
|
||||
7 -> 8
|
||||
5 -> 8
|
||||
12 -> 8
|
||||
6 -> 9
|
||||
7 -> 9
|
||||
5 -> 9
|
||||
12 -> 9
|
||||
6 -> 10
|
||||
7 -> 10
|
||||
5 -> 10
|
||||
12 -> 10
|
||||
6 -> 11
|
||||
7 -> 11
|
||||
5 -> 11
|
||||
12 -> 11
|
||||
}
|
||||
|
||||
|
|
||||
|
||||
In the terminal, this will show up as a list of jobs to be run:
|
||||
|
||||
.. code:: bash
|
||||
|
||||
Building DAG of jobs...
|
||||
Using shell: /bin/bash
|
||||
Provided cores: 1
|
||||
Rules claiming more threads will be scaled down.
|
||||
Unlimited resources: mem
|
||||
Job counts:
|
||||
count jobs
|
||||
1 add_electricity
|
||||
1 base_network
|
||||
1 build_bus_regions
|
||||
4 build_renewable_profiles
|
||||
1 build_shapes
|
||||
1 cluster_network
|
||||
1 prepare_network
|
||||
1 simplify_network
|
||||
1 solve_network
|
||||
12
|
||||
|
||||
``snakemake`` then runs these jobs in the correct order.
|
||||
|
||||
A job (here ``simplify_network``) will display its attributes and normally some logs in the terminal:
|
||||
|
||||
.. code:: bash
|
||||
|
||||
[<DATETIME>]
|
||||
rule simplify_network:
|
||||
input: networks/elec.nc, data/costs.csv, resources/regions_onshore.geojson, resources/regions_offshore.geojson
|
||||
output: networks/elec_s.nc, resources/regions_onshore_elec_s.geojson, resources/regions_offshore_elec_s.geojson, resources/clustermaps_elec_s.h5
|
||||
jobid: 3
|
||||
benchmark: benchmarks/simplify_network/elec_s
|
||||
wildcards: network=elec, simpl=
|
||||
resources: mem=4000
|
||||
|
||||
INFO:pypsa.io:Imported network elec.nc has buses, carriers, generators, lines, links, loads, storage_units, transformers
|
||||
INFO:__main__:Mapping all network lines onto a single 380kV layer
|
||||
INFO:__main__:Simplifying connected link components
|
||||
INFO:__main__:Removing stubs
|
||||
INFO:__main__:Displacing offwind-ac generator(s) and adding connection costs to capital_costs: 20128 Eur/MW/a for `5718 offwind-ac`
|
||||
INFO:__main__:Displacing offwind-dc generator(s) and adding connection costs to capital_costs: 14994 Eur/MW/a for `5718 offwind-dc`, 26939 Eur/MW/a for `5724 offwind-dc`, 29621 Eur/MW/a for `5725 offwind-dc`
|
||||
INFO:pypsa.io:Exported network elec_s.nc has lines, carriers, links, storage_units, loads, buses, generators
|
||||
[<DATETIME>]
|
||||
Finished job 3.
|
||||
9 of 12 steps (75%) done
|
||||
|
||||
Once the whole worktree is finished, it should show state so in the terminal:
|
||||
|
||||
.. code:: bash
|
||||
|
||||
Finished job 0.
|
||||
12 of 12 steps (100%) done
|
||||
Complete log: /home/XXXX/pypsa-eur/.snakemake/log/20XX-XX-XXTXX.snakemake.log
|
||||
snakemake results/networks/elec_s_6_lcopt_Co2L-24H.nc 519,84s user 34,26s system 242% cpu 3:48,83 total
|
||||
|
||||
You will notice that many intermediate stages are saved, namely the outputs of each individual ``snakemake`` rule.
|
||||
|
||||
You can produce any output file occuring in the ``Snakefile`` by running
|
||||
|
||||
.. code:: bash
|
||||
|
||||
.../pypsa-eur % snakemake <output file>
|
||||
|
||||
For example, you can explore the evolution of the PyPSA networks by running
|
||||
|
||||
#. ``.../pypsa-eur % snakemake networks/base.nc``
|
||||
#. ``.../pypsa-eur % snakemake networks/elec.nc``
|
||||
#. ``.../pypsa-eur % snakemake networks/elec_s.nc``
|
||||
#. ``.../pypsa-eur % snakemake networks/elec_s_6.nc``
|
||||
#. ``.../pypsa-eur % snakemake networks/elec_s_6_lcopt_Co2L-24H.nc``
|
||||
|
||||
There's a special rule: If you simply run
|
||||
|
||||
.. code:: bash
|
||||
|
||||
.../pypsa-eur % snakemake
|
||||
|
||||
the wildcards given in ``scenario`` in the configuration file ``config.yaml`` are used:
|
||||
|
||||
.. literalinclude:: ../config.tutorial.yaml
|
||||
:language: yaml
|
||||
:lines: 6-11
|
||||
|
||||
In this example we would not only solve a 6-node model of Germany but also a 2-node model.
|
||||
|
||||
The solved networks can be analysed just like any other PyPSA network (e.g. in Jupyter Notebooks).
|
||||
|
||||
.. code:: python
|
||||
|
||||
import pypsa
|
||||
|
||||
network = pypsa.Network("results/networks/elec_s_6_lcopt_Co2L-24H.nc")
|
||||
|
||||
...
|
||||
|
||||
For inspiration, read the `examples section in the PyPSA documentation <https://pypsa.readthedocs.io/en/latest/examples.html>`_.
|
Loading…
Reference in New Issue
Block a user