Tutorial
=====

After finishing the installation process in :ref:`installation` you can follow the following steps to create your first energy system input data from climate data:

#. Copy the :file:`config_default.yaml` to the same folder and rename it :file:`config.yaml`.
#. Open the :file:`config.yaml`.

.. image:: images/configOverview.png

3. You can adjust the config to your needs.
   
   0. Choose your desired energy system model e.g. ``desired_ESM: Backbone``
   1. You need to change the data_dir. This is the folder, where the downloaded climate data is saved. Be careful: climate data files can be very large, choose a large enough partition.
   2. You can choose which technologies shall be calculated. You can choose from:
  
      * csp (concentrated solar power)
      * pv (photovoltaics)
      * wind (onshore wind)
      * wind_offshore (offshore wind)
      * tpp{CoolingType}_p{plant} (availability of thermal power plants, choose cooling type from CL (closed loop) and OT (once through) and plant from Nuclear, Coal and CCGT, replace {CoolingType} and {plant} with your desired technologies)
      * hydro (water inflow for hydro power plants, given in MWh)

   3. Choose the climate model to be downloaded. With the models MPI-M-MPI-ESM-LR and NCC-NorESM1-M, the download works automatically. For other models, it might be necessary to change further parameters below in the config (row 30 and below, *cordex parameters*). Which combinations exist can be found in the cordex data store: https://esgf-data.dkrz.de/search/cordex-dkrz/
   4. Choose the representative concentration pathway. Give them without decimal separator (e.g. *26* for RCP 2.6)
   5. Choose the years you want time series for.
   6. Choose the domain - cordex data is prepared for different domains and you have to choose which one to look at.

After adapting the config, you can run the tool by opening the console and navigating to the repository folder.

.. code:: python
   
   pixi run snakemake -j7 --resources mem_mb=10000 api_slots_cds=2 api_slots_esgf=2
   
to execute the tool.

* The number behind -j is the amount of cores to be used by snakemake, adapt it to your machine.
* The number behind mem_mb limits the parallel execution of memory intensive jobs. If you have a lot of memory, enlarge it, if you see problems with memory allocation, diminish it.
* With ``api_slots_cds``, the number of parallel downloads for ERA5 datasets is limited, while ``api_slots_esgf`` applies to CORDEX.

Snakemake will then show you, which rules it plans to execute:

.. image:: images/snakemakeOverview.png

If all rules complete successfully, you will find the results in the folder ``results/{domain}`` in the format ``{technology}_m{model}rcp{rcp}{year}.csv``.