Methods
=====

In this chapter, the mathematical methods for the conversion process from climate data to energy system input data are explained.
A more detailed explanation with literature backup can be found in :cite:`Plaga.2023`.

.. _wind:

Wind power
------------
Basic method
~~~~~~~
The wind speed in cordex and era5 data sets is reported at 10 m height (= :math:`h_0`). 
Following :cite:`Abdin.2019`, the wind speeds :math:`v` at turbine height :math:`h` can be calculated with the following:

.. math:: v(h) = v(h_0)\left(\frac{h}{h_0}\right)^{\frac{1}{7}}.

With the wind speeds the capacity factor :math:`c_\text{f}` for wind turbines is calculated using standardized production functions :cite:`vanderWiel.2019`:

.. math::

    cf_\text{wind, single}(v) = 
    \begin{cases}
    0, & v < v_{\text{in}}, \\
    \frac{v^3- v_{\text{in}}^3}{v_{\text{r}}^3- v_{\text{in}}^3}, & v_{\text{in}} \leq v <  v_{\text{r}}, \\
    1, &  v_{\text{r}} \leq v <  v_{\text{out}}, \\
    0, & v \geq v_{\text{out}},\\
    \end{cases}


with the cut-in velocity :math:`v_{\text{in}}`, the rated velocity :math:`v_{\text{r}}` and the cut-out velocity :math:`v_{\text{out}}`.
Following :cite:`Staffell.2016`, we smooth the single turbine output curve with a Gaussian Filter :math:`\Gamma` to account for multiple turbines:

.. math::
   \Gamma(n, \sigma) = \frac{1}{\sqrt{2\pi\sigma}}\exp\left(\frac{n^2}{2\sigma^2}\right)

We use a standard deviation of :math:`\sigma = 0.6 + 0.2 v`.
The resulting power curve at wind speed :math:`v` is then calculated via:

.. math::
   cf_\text{wind}(v, \sigma) = \sum^{4\sigma}_{n = -4\sigma} \left(cf_\text{wind, single}(v-n) \cdot \Gamma(n, \sigma) \right) \cdot \left(\sum^{4\sigma}_{n = -4\sigma} \Gamma(n, \sigma) \right)^{-1}

For :math:`v_{\text{in}} = 2.5 \text{m/s}` :math:`v_{\text{r}} = 12.5 \text{m/s}` and the cut-out velocity :math:`v_{\text{out}} = 25.5 \text{m/s}`, the following power curve results:

.. image:: images/turbineCurveExample.png

Choice of turbine parameters
~~~~~~~
The choice of the cut-in wind speed, the rated wind speed and the cut-out wind speed is very relevant for the resulting wind profiles.
You can change the wind speed parameters in the config under ``onwind`` or ``offwind``.
Furthermore, when spatially aggregating data, the tool *cd2es* allows to set a parameter (``choose_only_x_percent_of_country``) which then only considers the x % best values within each node to aggregate, accommodating for the fact that wind turbines are more likely to be build at places with high capacity factors.
To determine an which wind speed parameters are most suitable to represent the wind conditions in Europe, we compared the output of the *cd2es* tool with the results from :cite:`Staffell.2016` (long term future for onshore wind, near term future for offshore wind).
Testing different cut-in wind speed, rated wind speeds and the cut-out wind speeds we found that the results from :cite:`Staffell.2016` could be approximated best by using the following parameter:

+-------------------------+---------+----------+
|Parameter                | Onshore | Offshore |
+=========================+=========+==========+
| cut-in wind speed (m/s) | 2       | 0        |
+-------------------------+---------+----------+
| rated wind speed (m/s)  | 9.5     | 13       |
+-------------------------+---------+----------+
| cut-out wind speed (m/s)| 12      | 15       |
+-------------------------+---------+----------+
| percentage of land      | 0.05    | 0.05     |
+-------------------------+---------+----------+

The following two figures show the average yearly full load hours calculated with the *cd2es* tool based on historical era 5 data for the years 2011-2015 compared to the full load hours from :cite:`Staffell.2016`. 
The data calculated by the *cd2es* tools shows a deviation of 14.1% (12.4%) for onshore wind (offshore wind) from the data from :cite:`Staffell.2016`.
This is due to the fact that :cite:`Staffell.2016` use different historical datasets (MERRA-2 instead of era5) and apply bias correction factors to correct the reanalysis data.
As calculating bias adaption factors requires real historical production data, we do not apply them in the standard version of the *cd2es* tool to keep the tool applicable to various geographical scopes.

.. image:: images/vin2_vr9.5_vout12_per0.05_windOnshore_compareNinja.png

.. image:: images/vin0_vr13_vout15_per0.05_windOffshore_compareNinja.png

.. _pv:

Photovoltaics
------------

Photovoltaic cells are influenced by climate variables in two ways: 
the solar irradiance :math:`G` influences the available incoming energy, while the outdoor temperature :math:`T` influences the cell's efficiency.
The *cd2es* tools is able to use three different models for calculating photovoltaic time series.
They are all given in :cite:`Jerez.2015`.
The type of model can be chosen in the config under ``pv``.

Option 1
~~~~~~~

The cells output is independent from the temperature and only based on the solar irradiation :math:`G` and the irradiation under Standard Testing Conditions :math:`G_{\text{STC}}`:

.. math::
    cf_\text{solar} = 0.75 \cdot \frac{G}{G_{\text{STC}}}.

The factor 0.75 is also taken from :cite:`Jerez.2015`, they average values found in other literature.

Option 2
~~~~~~~

With option 2, the capacity factor of a photovoltaic cell :math:`cf_\text{solar}` is calculated via:

.. math::
    cf_\text{solar} = (1-\beta(T_{\text{cell}}- T_{\text{STC}}) + \gamma \log_{10} G)\frac{G}{G_{\text{STC}}},

where :math:`T` is the temperature, :math:`G` the solar irradiation and :math:`\beta` and :math:`\gamma` are temperature and irradiance constants depending on the cell's material. 
The index STC refers to values at Standard Testing Conditions.
The temperature of a photovoltaic cell :math:`T_{\text{cell}}` can be calculated via:

.. math::
    T_{cell} = c_1 + c_2 \cdot T + c_3 \cdot G,

with :math:`c_1` :math:`c_2` and :math:`c_3` being constants depending on the cell's setup.

Option 3
~~~~~~~

With option 3, the capacity factor of a photovoltaic cell :math:`cf_\text{solar}` is calculated via:

.. math::
    cf_\text{solar} = \left(1+\gamma(T_{\text{cell}}- T_{\text{STC}})\right)\frac{G}{G_{\text{STC}}}.

The temperature of a photovoltaic cell :math:`T_{\text{cell}}` can be calculated via:

.. math::
    T_{cell} = c_1 + c_2 \cdot T + c_3 \cdot G + c_4 v

with :math:`c_1` :math:`c_2`, :math:`c_3` and :math:`c_4` being constants depending on the cell's setup and :math:`v` is the wind speed.

Choice of option
~~~~~~~

You can choose the computational method as well as the parameters in the config under ``solar``.
We compared the output from the *cd2es* tool for historic era5 data to output from renewables ninja :cite:`Pfenninger.2016`.
We found that the deviations were smallest with 13.7% when using option 3 (compared to 15.4% for option 3 and 33.3% for option 1) .

.. image:: images/all_compare_pv_compareNinja.png

When spatially aggregating data, the tool *cd2es* allows to set a parameter (``choose_only_x_percent_of_country``) which then only considers the x % best values within each node to aggregate, accomondating for the fact that pv farms are more likely to be build at places with high capacity factors.
Here, we found, that a value of 30% yields the best result, reducing the deviations to 9.9%.

.. image:: images/option3per0.3_compare_pv_compareNinja.png

.. _tpp:

Availability of thermal power plants
------------
As thermal power plants need cooling water, their availability decreases if temperatures exceed a certain threshold.
The effects of rising temperatures differ depending on the cooling type of the power plant. 
Once-through (OT) cooling is more vulnerable to rising temperatures than closed-loop (CL) cooling as it relies directly on river water temperatures :cite:`Abdin.2019`.
The availability :math:`\alpha` (ratio of available power to maximum power) of a thermal power plant with OT cooling is influenced by the stream temperature :math:`T_{\text{in}}` and the water availability :math:`A` in the following:

.. math::
    \alpha = \begin{cases}
        A, & T \leq T_{\text{health}}, \\
        A(1-\rho(T_{\text{in}}-T_{\text{health}})), & T_{\text{health}} < T_{\text{in}} \leq T_{\text{risk}}, \\
        A \cdot\delta\frac{T_{\text{out}}-T_{\text{in}}}{\Delta T_{\text{max}}}, & T_{\text{risk}} < T_{\text{in}} \leq T_{\text{down}},\\
        0, &  T_{\text{in}} > T_{\text{down}}.
    \end{cases}

Thereby, there a two threshold temperatures: 
Above :math:`T_{\text{health}}` availability degrading starts with the efficiency degrading coefficient :math:`\rho`.
At :math:`T_{\text{risk}}`, the waste heat discharge is equal to the maximal design value, therefore the water body is warmed beyond the designated amount.
The availability degradation is here depending on the coefficient :math:`\delta`, the maximum allowed stream temperature :math:`T_{\text{out}}` and the increase in temperature in the cooling water :math:`\Delta T`.
Above :math:`T_{\text{down}}`, the power plant is shut down :cite:`Abdin.2019`.
The water availability :math:`A` is 1 if the runoff is above the 10th percentile of historic data. Below the 10th percentile, it is gradually reduced to 0, following the approach in :cite:`Byers.2020`.

The availability :math:`\alpha` of a thermal power plant with CL cooling is almost independent of the stream water, but depending on the outside temperature :math:`T` in the following :cite:`Abdin.2019`:

.. math::
    \alpha = \begin{cases}
        1, & T \leq T_{\text{health}}, \\
        (1-\rho(T-T_{\text{health}})), & T > T_{\text{health}}.
    \end{cases}

You can change the parameters for the different cooling types and power plants in the config under ``tpp``.

.. _hydropower:

Hydropower
------------

The calculation of future hydro power output is challenging due to the very site specific conditions.
In this work, we use the JRC power plant data base (http://data.europa.eu/89h/9810feeb-f062-49cd-8e76-8d8cfd488a05) to determine the positions of hydro power plants in Europe (due to the data availability, this feature is also only available for Europe).
We then calculate average water runoff :math:`\bar{Q}_{\text{hist}}` at the power plants locations by looking at historic data (the historic years to be looked at can be specified in the config).
We then assume that installed capacity of a power plant :math:`P_0` as given in the data base is correlated to the average historic runoff :math:`\bar{Q}_{\text{hist}}`.
We assume that a power plant can utilize its full installed capacity at the average historic runoff :math:`\bar{Q}_{\text{hist}}` multiplied by a scaling factor :math:`a`.
For the future output :math:`P(t)`, we assume that the the output of the power plant at a time :math:`t` is proportional to the current runoff :math:`Q(t)`.
This leads to the following equation:

.. math::
    P(t) = Q(t) \cdot \frac{P_0}{a \cdot \bar{Q}_{\text{hist}}}

To test our method, we compared the output of the *cd2es* tool with the output from Secures-Met :cite:`Formayer.2023` who used a far more complicated method to predict hydro power changes under climate influence.
We used the same climate model (ICHEC-EC-EARTH) and the same RCP (4.5) and compared the years 2045-2055.
In the following figure we compare the available hydro power in the ten years for the two methods, whereby we show the *cd2es* tool with a scaling factor of :math:`a=1` (meaning a power plant reaches its installed capacity at the average historic runoff) and :math:`a=1.9` (meaning a power plant reaches its installed capacity at 190% of the average historic runoff).
The value :math:`a = 1.9` showed the smallest deviation from :cite:`Formayer.2023` in testing.

.. image:: images/hydro_factor1.0_sum_hydro_compareSecuresMet.png

It can be seen that the results of the two tools are similar.
However, available hydro power is overestimated in many countries when using a scaling factor :math:`a=1`.
Using :math:`a=1.9` improves the results, leaving only Norway and Italy with an larger underestimation of hydro power.
The deviations from :cite:`Formayer.2023` are 48% in the :math:`a=1` case and 25% in the :math:`a=1.9` case.
The deviations are explainable as the *cd2es* tool uses a simple method which requires only the power plants locations and their installed capacities while the calculations in :cite:`Formayer.2023` are based on large hydrological data sets from the hydrological model E-HYPE, which models the behavior of rivers much more detailedly.
However, the E-HYPE data used in :cite:`Formayer.2023` is not freely available.
Thus the *cd2es* tool allows for the calculation of future hydro power output using only the location and installed capacity of hydro power plants while showing relatively small deviations from far more complex methods.
Due to its simplicity, the *cd2es* method can also easily be implemented for other continents.

.. _demand:

Demand
------------
The demand is influenced by temperature changes as these changes influence heating and cooling demand. 
As a detailed description of changes in heating demand and consumer's behavior exceeds the scope of this software, we will use regression techniques as in :cite:`Handayani.2020, vanderWiel.2019, Zhang.2020`.
Therefore, we perform a quadratic regression on daily historical temperature and demand data for each country in the study area as in :cite:`Zhang.2020`.
The historic years to perform the regression on can be chosen in the :file:`config.yaml`.
Note, that due to data availability this feature is currently only available for Europe.
Below you can see two examples for Albania and Belgium for the climate model CNRM-CERFACS-CNRM-CM5 and an RCP of 2.6:

.. image:: images/demand_regression_ALB_mCNRM-CERFACS-CNRM-CM5_rcp26.png

.. image:: images/demand_regression_BEL_mCNRM-CERFACS-CNRM-CM5_rcp26.png

.. _biasAdaption:

Bias adaption
------------

Due to the complexity of atmospheric processes, climate models are often found to be biased when compared to observed data. 
The *cd2es* tool allows for the correction of biases by using the quantile delta mapping algorithm as described in :cite:`Cannon.2015`.
The bias adaption is performed using the ERA-5 reanalysis data which is is downloaded within the *cd2es* tool, if the ``download_era5`` flag is activated in the config file.
To enable bias adaption, the flag ``use_bias_adaption`` in the config must be activated.

Bibliography
------------

.. bibliography:: leoniePromo.bib