"> **Hint:** You can use the function [`scipy.optimize.minimize`](https://docs.scipy.org/doc/scipy-1.0.0/reference/generated/scipy.optimize.minimize.html) and use e.g. [`method='nelder-mead'`](https://en.wikipedia.org/wiki/Nelder%E2%80%93Mead_method)."
]
},
{
...
...
@@ -435,7 +458,10 @@
"***\n",
"**(c) Now assume that there is a seasonal shift in the wind signal\n",
"Express the optimal mix $\\alpha$ as a function of $\\phi$.**"
"Express the optimal mix $\\alpha$ as a function of $\\phi$.**\n",
"> **Remark:** Note, that $\\alpha\\in [0,1]$ and you need to add this as bounds.\n",
"\n",
"> **Hint:** If you encounter problems (why?), try another optimisation algorithm [`method='TNC'`](https://en.wikipedia.org/wiki/Truncated_Newton_method)"
]
},
{
...
...
%% Cell type:markdown id: tags:
# Energy System Modelling - Solutions to Tutorial II.1
# Energy System Modelling - Solutions to Tutorial I.2
%% Cell type:markdown id: tags:
We use approximations to seasonal variations of wind and solar power generation $W(t)$
and $S(t)$ and load $L(t)$:
$$W(t) = 1 + A_W \cos \omega t$$
$$S(t) = 1 - A_S \cos \omega t$$
$$L(t) = 1 + A_L \cos \omega t$$
The time series are normalized to $\langle{W}\rangle = \langle{S}\rangle = \langle{L}\rangle := \frac{1}{T} \int_0^T L(t)
> **Hint:** You can use the function [`scipy.optimize.minimize`](https://docs.scipy.org/doc/scipy-1.0.0/reference/generated/scipy.optimize.minimize.html) and use e.g. [`method='nelder-mead'`](https://en.wikipedia.org/wiki/Nelder%E2%80%93Mead_method).
Express the optimal mix $\alpha$ as a function of $\phi$.**
> **Remark:** Note, that $\alpha\in [0,1]$ and you need to add this as bounds.
> **Hint:** If you encounter problems (why?), try another optimisation algorithm [`method='TNC'`](https://en.wikipedia.org/wiki/Truncated_Newton_method)
"**(d) For all three regions, plot the duration curve for $W(t)$, $S(t)$, $L(t)$.** "
"**(d) For all three regions, plot the duration curve for $W(t)$, $S(t)$, $L(t)$.** \n",
"> **Hint:** You might want to make use of the functions [`.sort_values`](https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.sort_values.html) and [`.reset_index`](https://pandas.pydata.org/pandas-docs/version/0.23/generated/pandas.DataFrame.reset_index.html)\n",
"\n",
"> **Tip:** Go through the line `de['wind'].sort_values(ascending=False).reset_index(drop=True).plot()` dot by dot and note what happens to the output."
"**For all three regions, plot the energy spectrum $\\|\\tilde{\\Delta}(\\omega)\\|^2$ as a function of $\\omega$. Discuss the relationship of these results with the findings obtained in (b)-(f).**"
"**For all three regions, plot the energy spectrum $\\|\\tilde{X}(\\omega)\\|^2$ as a function of $\\omega$. Discuss the relationship of these results with the findings obtained in (b)-(f).**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"> **Hint:** To determine the frequencies `rfffreq` can be used, the argument `d` indicates the distance between two data points, `1h` hour, which we specify as $\\frac{1}{8760} a$, so that the frequencies come out in the unit $\\frac{1}{a}$."
"> **Remark:** Use the function [`numpy.fft.rfft`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.fft.rfft.html) and make sure you subtract the mean.\n",
"\n",
"> **Remark:** To determine the frequencies [`numpy.fft.rfffreq`](https://docs.scipy.org/doc/numpy-1.12.0/reference/generated/numpy.fft.rfftfreq.html) is used, the argument `d` indicates the distance between two data points, `1h` hour, which we specify as $\\frac{1}{8760} a$, so that the frequencies come out in the unit $\\frac{1}{a}$."
]
},
{
...
...
%% Cell type:markdown id: tags:
# Energy System Modelling - Tutorial I
SS 2018, Karlsruhe Institute of Technology, Institute for Automation and Applied Informatics
***
%% Cell type:markdown id: tags:
# Imports
%% Cell type:code id: tags:
``` python
importnumpyasnp
importpandasaspd
importmatplotlib.pyplotasplt
%matplotlibinline
```
%% Cell type:markdown id: tags:
***
# Introductory Comments
%% Cell type:markdown id: tags:
## Getting Help
Executing cells with Shift-Enter and with `h` there is help.
Help is available with `.<TAB>` or load.sort_values() <-cursorbetweenbrackets,`Shift-<TAB>`
%% Cell type:markdown id: tags:
## Using one-dimensional arrays (Numpy and Pandas)
%% Cell type:markdown id: tags:
**Numpy**
%% Cell type:code id: tags:
``` python
a = np.arange(10)
a
```
%% Output
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
%% Cell type:code id: tags:
``` python
a[1:3]
```
%% Output
array([1, 2])
%% Cell type:markdown id: tags:
**Pandas**
%% Cell type:code id: tags:
``` python
s = pd.Series(np.random.random(3), index=['foo', 'bar', 'baz'])
s
```
%% Output
foo 0.748951
bar 0.286110
baz 0.274185
dtype: float64
%% Cell type:code id: tags:
``` python
s["foo":"bar"]
```
%% Output
foo 0.748951
bar 0.286110
dtype: float64
%% Cell type:markdown id: tags:
## Using two-dimensional arrays (Numpy and Pandas)
s = pd.DataFrame(np.random.random((3,5)), index=['foo', 'bar', 'baz'])
s
```
%% Output
0 1 2 3 4
foo 0.390126 0.502056 0.958872 0.186866 0.860330
bar 0.042661 0.636768 0.233535 0.577435 0.909700
baz 0.957205 0.313162 0.348274 0.542685 0.698854
%% Cell type:code id: tags:
``` python
s.mean()
```
%% Output
0 0.463331
1 0.483995
2 0.513560
3 0.435662
4 0.822961
dtype: float64
%% Cell type:markdown id: tags:
***
# Problem I.1
The following data are made available to you on the __[coures homepage](https://nworbmot.org/courses/complex_renewable_energy_networks/)__:
`de_data.csv`, `gb_data.csv`, `eu_data.csv`
and alternatively
`wind.csv`, `solar.csv`, `load.csv`
They describe (quasi-real) time series for wind power generation $W(t)$, solar power generation $S(t)$ and load $L(t)$ in Great Britain (GB), Germany (DE) and Europe (EU). The time step is 1 h and the time series are several years long.
> Remark: In this example notebook, we only look at Germany and the EU, Great Britain works in exactly the same way.
%% Cell type:markdown id: tags:
***
**Read Data**
%% Cell type:code id: tags:
``` python
de = pd.read_csv('tutorial_data/de_data.csv', parse_dates=True, index_col=0)
eu = pd.read_csv('tutorial_data/eu_data.csv', parse_dates=True, index_col=0)
Extra: Show the first 5 lines (header) of the German data:
%% Cell type:code id: tags:
``` python
```
%% Cell type:markdown id: tags:
Extra: Check that wind, solar and load files are just differently organized datasets and it's the same data:
%% Cell type:code id: tags:
``` python
```
%% Cell type:markdown id: tags:
***
**(a) Check that the wind and solar time series are normalized to ’per-unit of installed capacity’,
and that the load time series is normalized to MW.**
%% Cell type:code id: tags:
``` python
```
%% Cell type:markdown id: tags:
***
**(b) Calculate the maximum, mean, and variance of the time series. **
%% Cell type:code id: tags:
``` python
```
%% Cell type:markdown id: tags:
***
** (c) For all three regions, plot the time series $W (t)$, $S(t)$, $L(t)$ for a winter month (January) and a summer month (July). **
%% Cell type:code id: tags:
``` python
```
%% Cell type:markdown id: tags:
Extra: Also compare the wind between the different regions
%% Cell type:code id: tags:
``` python
```
%% Cell type:markdown id: tags:
***
**(d) For all three regions, plot the duration curve for $W(t)$, $S(t)$, $L(t)$.**
> **Hint:** You might want to make use of the functions [`.sort_values`](https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.sort_values.html) and [`.reset_index`](https://pandas.pydata.org/pandas-docs/version/0.23/generated/pandas.DataFrame.reset_index.html)
> **Tip:** Go through the line `de['wind'].sort_values(ascending=False).reset_index(drop=True).plot()` dot by dot and note what happens to the output.
%% Cell type:code id: tags:
``` python
```
%% Cell type:markdown id: tags:
***
**(e) For all three regions, plot the probability density function of $W(t)$, $S(t)$, $L(t)$.**
%% Cell type:markdown id: tags:
There are two different methods:
1. [Histograms](https://en.wikipedia.org/wiki/Histogram) and
2. [Kernel density estimation (KDE)](https://en.wikipedia.org/wiki/Kernel_density_estimation).
This [image](https://en.wikipedia.org/wiki/Kernel_density_estimation#/media/File:Comparison_of_1D_histogram_and_KDE.png) on the KDE page provides a good summary of the differences. You can do both with Panda!
%% Cell type:markdown id: tags:
First, let's look at the wind data:
%% Cell type:code id: tags:
``` python
```
%% Cell type:markdown id: tags:
Now, let's look at the solar data:
%% Cell type:code id: tags:
``` python
```
%% Cell type:markdown id: tags:
The solar data might be hard to see. Look at this in detail by limiting the y-axis to (0,2):
%% Cell type:code id: tags:
``` python
```
%% Cell type:markdown id: tags:
Finally, let's look at the load profile:
%% Cell type:code id: tags:
``` python
```
%% Cell type:markdown id: tags:
***
**(f) Apply a [(Fast) Fourier Transform](https://en.wikipedia.org/wiki/Fast_Fourier_transform) to the the three time series $X \in W(t), S(t), L(t)$:**
**For all three regions, plot the energy spectrum $\|\tilde{\Delta}(\omega)\|^2$ as a function of $\omega$. Discuss the relationship of these results with the findings obtained in (b)-(f).**
%% Cell type:code id: tags:
``` python
```
**For all three regions, plot the energy spectrum $\|\tilde{X}(\omega)\|^2$ as a function of $\omega$. Discuss the relationship of these results with the findings obtained in (b)-(f).**
%% Cell type:markdown id: tags:
> **Hint:** To determine the frequencies `rfffreq` can be used, the argument `d` indicates the distance between two data points, `1h` hour, which we specify as $\frac{1}{8760} a$, so that the frequencies come out in the unit $\frac{1}{a}$.
> **Remark:** Use the function [`numpy.fft.rfft`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.fft.rfft.html) and make sure you subtract the mean.
> **Remark:** To determine the frequencies [`numpy.fft.rfffreq`](https://docs.scipy.org/doc/numpy-1.12.0/reference/generated/numpy.fft.rfftfreq.html) is used, the argument `d` indicates the distance between two data points, `1h` hour, which we specify as $\frac{1}{8760} a$, so that the frequencies come out in the unit $\frac{1}{a}$.
%% Cell type:code id: tags:
``` python
```
%% Cell type:markdown id: tags:
***
**(g) Normalize the time series to one, so that $\langle{W}\rangle = \langle{S}\rangle = \langle{L}\rangle = 1$.**
**Now, for all three regions, plot the mismatch time series**
"> **Hint:** You can use the function [`scipy.optimize.minimize`](https://docs.scipy.org/doc/scipy-1.0.0/reference/generated/scipy.optimize.minimize.html) and use e.g. [`method='nelder-mead'`](https://en.wikipedia.org/wiki/Nelder%E2%80%93Mead_method)."
]
},
{
...
...
@@ -224,7 +225,10 @@
"***\n",
"**(c) Now assume that there is a seasonal shift in the wind signal\n",
"Express the optimal mix $\\alpha$ as a function of $\\phi$.**"
"Express the optimal mix $\\alpha$ as a function of $\\phi$.**\n",
"> **Remark:** Note, that $\\alpha\\in [0,1]$ and you need to add this as bounds.\n",
"\n",
"> **Hint:** If you encounter problems (why?), try another optimisation algorithm [`method='TNC'`](https://en.wikipedia.org/wiki/Truncated_Newton_method)"
]
},
{
...
...
%% Cell type:markdown id: tags:
# Energy System Modelling - Tutorial II.1
# Energy System Modelling - Tutorial I.2
%% Cell type:markdown id: tags:
We use approximations to seasonal variations of wind and solar power generation $W(t)$
and $S(t)$ and load $L(t)$:
$$W(t) = 1 + A_W \cos \omega t$$
$$S(t) = 1 - A_S \cos \omega t$$
$$L(t) = 1 + A_L \cos \omega t$$
The time series are normalized to $\langle{W}\rangle = \langle{S}\rangle = \langle{L}\rangle := \frac{1}{T} \int_0^T L(t)
> **Hint:** You can use the function [`scipy.optimize.minimize`](https://docs.scipy.org/doc/scipy-1.0.0/reference/generated/scipy.optimize.minimize.html) and use e.g. [`method='nelder-mead'`](https://en.wikipedia.org/wiki/Nelder%E2%80%93Mead_method).
Express the optimal mix $\alpha$ as a function of $\phi$.**
> **Remark:** Note, that $\alpha\in [0,1]$ and you need to add this as bounds.
> **Hint:** If you encounter problems (why?), try another optimisation algorithm [`method='TNC'`](https://en.wikipedia.org/wiki/Truncated_Newton_method)
%% Cell type:code id: tags:
``` python
```
%% Cell type:markdown id: tags:
***
**(d) A constant conventional power source $C(t) = 1 - \gamma$ is now introduced. The mismatch then becomes
"**(a) Compile the nodes list and the edge list.**\n",
"> **Remark:** While graph-theoretically both lists are unordered sets, let's agree on an ordering now which can serve as basis for the matrices in the following exercises: we sort everything in ascending numerical order, i.e.\\ node 1 before node 2 and edge (1,2) before (1,4) before (2,3)."
"> **Remark:** While graph-theoretically both lists are unordered sets, let's agree on an ordering now which can serve as basis for the matrices in the following exercises: we sort everything in ascending numerical order, i.e. node 1 before node 2 and edge (1,2) before (1,4) before (2,3)."
]
},
{
...
...
@@ -137,7 +137,8 @@
},
"source": [
"***\n",
"**(c) Compute the adjacency matrix $A$ and check that it is symmetric.**"
"**(c) Compute the adjacency matrix $A$ and check that it is symmetric.**\n",
"> In graph theory and computer science, an adjacency matrix is a square matrix used to represent a finite graph. The elements of the matrix indicate whether pairs of vertices are adjacent or not in the graph."
]
},
{
...
...
@@ -208,7 +209,8 @@
},
"source": [
"***\n",
"**(d) Find the $k_n$ of each node $n$ and compute the average degree of the network.**"
"**(d) Find the degree $k_n$ of each node $n$ and compute the average degree of the network.**\n",
"> In graph theory, the degree (or valency) of a vertex of a graph is the number of edges incident to the vertex, with loops counted twice."
]
},
{
...
...
@@ -269,7 +271,8 @@
},
"source": [
"***\n",
"**(e) Determine the incidence matrix $K$ by assuming the links are always directed from smaller-numbered node to larger-numbered node, i.e.\\ from node 2 to node 3, instead of from 3 to 2.**"
"**(e) Determine the incidence matrix $K$ by assuming the links are always directed from smaller-numbered node to larger-numbered node, i.e. from node 2 to node 3, instead of from 3 to 2.**\n",
"> The unoriented incidence matrix (or simply incidence matrix) of an undirected graph is a $n \\times m$ matrix $B$, where n and m are the numbers of vertices and edges respectively, such that $B_{i,j} = 1$ if the vertex $v_i$ and edge $e_j$ are incident and 0 otherwise."
]
},
{
...
...
@@ -316,7 +319,8 @@
},
"source": [
"***\n",
"**(f) Compute the Laplacian $L$ of the network using $k_n$ and $A$. Remember that the Laplacian can also be computed as $L=KK^T$ and check that the two definitions agree.**"
"**(f) Compute the Laplacian $L$ of the network using $k_n$ and $A$. Remember that the Laplacian can also be computed as $L=KK^T$ and check that the two definitions agree.**\n",
"> The **Laplacian** (also: admittance matrix, Kirchhoff matrix, discrete Laplacian) is a matrix representation of a graph. It is defined as the difference of degree matrix and adjacency matrix. The **degree matrix** is a diagonal matrix which contains information about the degree of each vertex."
]
},
{
...
...
@@ -395,7 +399,8 @@
},
"source": [
"***\n",
"**(g) Find the diameter of the network by looking at the graph.**"
"**(g) Find the diameter of the network by looking at the graph.**\n",
"> The diameter of a network is the longest of all the calculated shortest paths in a network. It is the shortest distance between the two most distant nodes in the network. In other words, once the shortest path length from every node to all other nodes is calculated, the diameter is the longest of all the calculated path lengths. The diameter is representative of the linear size of a network. "
]
},
{
...
...
@@ -418,9 +423,9 @@
},
"source": [
"***\n",
"## Problem II.3\n",
"## Problem II.2\n",
"\n",
"If you map the nodes to `0=DK, 1=DE, 2=CH, 3=IT, 4=AT,5=CZ` the network represents a small part of the European electricity network (albeit very simplified). On the [course homepage](https://nworbmot.org/courses/complex_renewable_energy_networks/), you can find the power imbalance time series for the six countries for January 2017 in hourly MW in the file `imbalance.csv`. They have been derived from physical flows as published by [ENTSO-E](https://transparency.entsoe.eu/transmission-domain/physicalFlow/show)"
"If you map the nodes to `0=DK, 1=DE, 2=CH, 3=IT, 4=AT,5=CZ` the network represents a small part of the European electricity network (albeit very simplified). In the repository, you can find the power imbalance time series for the six countries for January 2017 in hourly MW in the file `imbalance.csv`. They have been derived from physical flows as published by [ENTSO-E](https://transparency.entsoe.eu/transmission-domain/physicalFlow/show)"
"is the weighted Laplacian. For simplicity, we assume identity reactance on all links $x_l = 1$."
]
},
...
...
@@ -588,7 +593,7 @@
"source": [
"***\n",
"**(a) Compute the voltage angles $\\theta_j$ and flows $f_l$ for the first hour in the dataset with the convention of $\\theta_0 = 0$; i.e. the slack bus is at node 0.**\n",
"> **Remark:** Linear equation systems are solved efficiently using `numpy.linalg.solve`."
"> **Remark:** Linear equation systems are solved efficiently using [`numpy.linalg.solve`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.solve.html)."