Commit 379abd90 authored by Fabian Neumann's avatar Fabian Neumann
Browse files

update sheets

parent b9ddcf9e
No preview for this file type
......@@ -67,18 +67,29 @@
%=====================================================================
\begin{document}
\begin{flushright}
\textbf{Energy System Modelling }\\
{\small Karlsruhe Institute of Technology}\\
{\small Institute for Automation and Applied Informatics}\\
{\small Summer Term 2019}\\
\end{flushright}
\vspace{-0.5em}
\hrulefill
\vspace{0.3em}
\begin{center}
\textbf{\Large Energy System Modelling }\\
{SS 2018, Karlsruhe Institute of Technology}\\
{Institute for Automation and Applied Informatics}\\ [1em]
\textbf{\textsc{\Large Tutorial I: Time Series Analysis}}\\
\small Will be worked on in the exercise session on Wednesday, 11 July 2018.\\[1.5em]
\small Will be worked on in the exercise session on Thursday, 6 June 2019.\\[1.5em]
\end{center}
\vspace{1em}
\vspace{-0.8em}
\hrulefill
\vspace{0.8em}
%=============== ======================================================
\paragraph{Problem I.1 \normalsize (data analysis).}~\\
\paragraph{Problem I.1 (programming) -- Data Analysis}~\\
%=====================================================================
The following data are made available to you on the course home
......@@ -94,16 +105,17 @@ They describe (quasi-real) time series for wind power generation \(W(t)\), solar
\item For all three regions, plot the time series \(W(t)\),
\(S(t)\),
\(L(t)\) for a winter month (January) and a summer month (July).
\item Resample the time series to daily, weekly and monthly data points and visualise them in plots. Can you identify some recurring patterns?
\item For all three regions, plot the duration curve for \(W(t)\), \(S(t)\), \(L(t)\).
\item For all three regions, plot the probability density function of \(W(t)\), \(S(t)\), \(L(t)\).
\item Apply a (Fast) Fourier Transform to the the three time series $X \in W(t), S(t), L(t)$:
\item Recurring patterns of time series can also be visualised more rigorously by applying a Fourier Transform. Apply a (Fast) Fourier Transform to the the three time series $X \in W(t), S(t), L(t)$:
\begin{equation*}
\tilde{X}(\omega) = \int_0^T X(t) e^{\i \omega t} \,\ud t \, .
\end{equation*}
For all three regions, plot the energy spectrum
$\left| \tilde{X}(\omega) \right|^2$ as a function of
$\omega$. Discuss the relationship of these results with the
findings obtained in (b)-(e).
findings obtained in (b)-(f).
\item Normalize the time series to one, so that \(\expect{W} = \expect{S} = \expect{L} = 1\).
Now, for all three regions, plot the mismatch time series
\begin{equation*}
......@@ -112,12 +124,15 @@ They describe (quasi-real) time series for wind power generation \(W(t)\), solar
for the same winter and summer months as in (c). Choose
\(\alpha \in \{0.0, 0.5, 0.75, 1.0\}\) with \(\gamma = 1\),
and $\gamma \in \{0.5, 0.75, 1.0, 1.25, 1.5\} $ with $\alpha = 0.75$.
\item For all three regions, repeat (b)-(f) for the mismatch time series.
Which configuration entails the lowest mismatch on average and in extremes?
\item For all three regions, repeat (b)-(g) for the mismatch time series.
\end{enumerate}
\pagebreak
%=====================================================================
\paragraph{Problem I.2 \normalsize (analytical).}~\\
\paragraph{Problem I.2 (analytical) -- Effect of Seasonality}~\\
%=====================================================================
\begin{wrapfigure}[11]{r}{0pt}
......@@ -181,10 +196,12 @@ The time series are normalized to
\pagebreak
%=============== ======================================================
\paragraph{Remarks (Python pointers or where to start).}~\\
\paragraph{Remarks -- Introductions to Python}~\\
%=====================================================================
I found the python notebook based notes of Robert Johansson to be a
In the tutorials we will repeatedly work with the programming language Python. If you are unfamiliar with the language, you might find the following tutorials useful.\\
The Python notebook based notes of Robert Johansson are a
comprehensive kick starter\footnote{\url{http://nbviewer.jupyter.org/github/jrjohansson/scientific-python-lectures/tree/master/}}.
\begin{itemize}
\item
......@@ -195,14 +212,9 @@ comprehensive kick starter\footnote{\url{http://nbviewer.jupyter.org/github/jrjo
brush over it and stop reading early, i.e. if you read the word
\verb+classes+ you already know too much).
\item \href{http://nbviewer.jupyter.org/github/jrjohansson/scientific-python-lectures/blob/master/Lecture-2-Numpy.ipynb}{Lecture~2} is the most important and closely connected to the exercises.
\item You might as well stop now, but if you \emph{are} hooked, I recommend \href{http://nbviewer.jupyter.org/github/jrjohansson/scientific-python-lectures/blob/master/Lecture-3-Scipy.ipynb}{Lecture~3} for more physics and \href{http://nbviewer.jupyter.org/github/jrjohansson/scientific-python-lectures/blob/master/Lecture-4-Matplotlib.ipynb}{Lecture~4} for prettier graphs.
\end{itemize}
Further reference material of help is:
\begin{itemize}
\item The website-books \url{http://python-course.eu/} (english), \url{http://python-kurs.eu/} (german); especially if you only \emph{very} quickly skim over the \href{https://www.python-course.eu/python3_course.php}{python3 tutorial} and switch over to the \href{http://www.python-course.eu/numerical_programming.php}{numerical python} stuff early; especially of interest might be the \href{http://www.python-course.eu/pandas.php}{pandas} bit in the end, which will make the exercises a breeze at the expense of yet another package to learn.
\item the exhaustive (overly so) official python tutorial\footnote{\url{https://docs.python.org/3.6/tutorial/}} available in \href{https://docs.python.org/3.6/tutorial/}{english} and \href{https://py-tutorial-de.readthedocs.org/}{german}; which will NOT introduce you to numpy or scipy.
\item You might as well stop now, but if you \emph{are} hooked, have a look at \href{http://nbviewer.jupyter.org/github/jrjohansson/scientific-python-lectures/blob/master/Lecture-3-Scipy.ipynb}{Lecture~3} for more physics and \href{http://nbviewer.jupyter.org/github/jrjohansson/scientific-python-lectures/blob/master/Lecture-4-Matplotlib.ipynb}{Lecture~4} for prettier graphs.
\end{itemize}
Further reference material of help is are the website-books \url{http://python-course.eu/} (english), \url{http://python-kurs.eu/} (german); especially of interest might be the \href{http://www.python-course.eu/pandas.php}{pandas} bit in the end, which will make the exercises a breeze at the expense of yet another package to learn.
\end{document}
This diff is collapsed.
This diff is collapsed.
%% 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
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
plt.style.use('bmh')
%matplotlib inline
```
%% 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() <- cursor between brackets, `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: execute_result
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
%% Cell type:code id: tags:
``` python
a[1:3]
```
%%%% Output: execute_result
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: execute_result
foo 0.748951
bar 0.286110
baz 0.274185
dtype: float64
%% Cell type:code id: tags:
``` python
s["foo":"bar"]
```
%%%% Output: execute_result
foo 0.748951
bar 0.286110
dtype: float64
%% Cell type:markdown id: tags:
## Using two-dimensional arrays (Numpy and Pandas)
%% Cell type:markdown id: tags:
**Numpy**
%% Cell type:code id: tags:
``` python
np.random.random((3,5))
```
%%%% Output: execute_result
array([[0.28941884, 0.4004386 , 0.67028241, 0.40211146, 0.87918444],
[0.42221308, 0.13808648, 0.08780219, 0.96793469, 0.62714239],
[0.97390844, 0.83849364, 0.65386425, 0.15093854, 0.29176614]])
%% Cell type:markdown id: tags:
**Pandas**
%% Cell type:code id: tags:
``` python
s = pd.DataFrame(np.random.random((3,5)), index=['foo', 'bar', 'baz'])
s
```
%%%% Output: execute_result
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: execute_result
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)
gb = pd.read_csv('tutorial_data/gb_data.csv', parse_dates=True, index_col=0)
```
%% Cell type:code id: tags:
``` python
wind = pd.read_csv('tutorial_data/wind.csv', parse_dates=True, index_col=0)
solar = pd.read_csv('tutorial_data/solar.csv', parse_dates=True, index_col=0)
load = pd.read_csv('tutorial_data/load.csv', parse_dates=True, index_col=0)
```
%% Cell type:markdown id: tags:
Extra: Show the first 5 lines (header) of the German data:
%% Cell type:code id: tags:
``` python
de.head()
```
%%%% Output: execute_result
wind solar load
time
2011-01-01 00:00:00 0.535144 0.0 46209.0
2011-01-01 01:00:00 0.580456 0.0 44236.0
2011-01-01 02:00:00 0.603605 0.0 42502.0
2011-01-01 03:00:00 0.614114 0.0 41479.0
2011-01-01 04:00:00 0.627257 0.0 39923.0
%% 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
(wind['DE'] == de['wind']).all()
```
%%%% Output: execute_result
True
%% 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
wind.max()
```
%%%% Output: execute_result
DE 0.994588
GB 0.999998
EU 0.719222
dtype: float64
%% 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)$:**
$$\tilde{X}(\omega) = \int_0^T X(t) \;e^{i\omega t} \;\mathrm{d}t.$$
**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:
> **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**
$$\Delta(t) = \gamma \alpha W(t) + \gamma (1 - \alpha) S(t) - L(t) $$
**for the same winter and summer months as in (c). Choose**
1. $\alpha \in \{0.0, 0.5, 0.75, 1.0\}$ with $\gamma = 1$, and
2. $\gamma \in \{0.5, 0.75, 1.0, 1.25, 1.5\}$ with $\alpha = 0.75$.
**What is the interpretation of $\gamma$ and $\alpha$?**
%% Cell type:markdown id: tags:
Choose the country and alpha, gamma values and re-run:
%% Cell type:code id: tags:
``` python
d = de
gamma = 1.0
alpha = 0
```
%% Cell type:markdown id: tags:
Normalize the time series and calculate mismatch time series:
%% Cell type:code id: tags:
``` python
```
%% Cell type:markdown id: tags:
Plot the mismatch time series for the winter and summer months:
%% Cell type:code id: tags:
``` python
```
%% Cell type:markdown id: tags:
***
**(h) For all three regions, repeat (b)-(f) for the mismatch time series. What changed?**
%% Cell type:markdown id: tags:
**Data check**
%% Cell type:code id: tags:
``` python
```
%% Cell type:markdown id: tags:
**Time series plot**
%% Cell type:code id: tags:
``` python
```
%% Cell type:markdown id: tags:
**Duration curve**
%% Cell type:code id: tags:
``` python
```
%% Cell type:markdown id: tags:
**Probability density function**
%% Cell type:code id: tags:
``` python
```
%% Cell type:markdown id: tags:
**Fast Fourier Transform**
%% Cell type:code id: tags:
``` python
```
......
No preview for this file type
......@@ -70,19 +70,29 @@
%=====================================================================
\begin{document}
\begin{flushright}
\textbf{Energy System Modelling }\\
{\small Karlsruhe Institute of Technology}\\
{\small Institute for Automation and Applied Informatics}\\
{\small Summer Term 2019}\\
\end{flushright}
\vspace{-0.5em}
\hrulefill
\vspace{0.3em}
\begin{center}
\textbf{\Large Energy System Modelling }\\
{SS 2018, Karlsruhe Institute of Technology}\\
{Institute for Automation and Applied Informatics}\\ [1em]
\textbf{\textsc{\Large Tutorial II: Network Theory and Power Flow}}\\
\small Will be worked on in the exercise session on Friday, 13 July 2018.\\[1.5em]
\small Will be worked on in the exercise session on Friday, 7 June 2019.\\[1.5em]
\end{center}
\vspace{1em}
\vspace{-0.5em}
\hrulefill
\vspace{0.8em}
%=====================================================================
\paragraph{Problem II.1 \normalsize (network theory basics).}~\\
\paragraph{Problem II.1 (programming) -- network theory basics}~\\
%=====================================================================
\begin{wrapfigure}[10]{r}{0pt}
......@@ -119,7 +129,7 @@ Consider the simple network shown ins Figure \ref{fig:network}. Calculate in Pyt
\pagebreak
%=====================================================================
\paragraph{Problem II.2 \normalsize (linear power flow).}~\\
\paragraph{Problem II.2 (programming) -- linear power flow}~\\
%=====================================================================
......
%% Cell type:markdown id: tags:
# Energy System Modelling - Solutions to Tutorial II
%% Cell type:markdown id: tags:
**Imports**
%% Cell type:code id: tags:
``` python
import numpy as np
import numpy.linalg
import pandas as pd
import matplotlib.pyplot as plt
plt.style.use('bmh')
%matplotlib inline
```
%% Cell type:markdown id: tags:
***
## Problem II.1
%% Cell type:markdown id: tags:
***
**(a) Compile the nodes list and the edge list.**
> **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).
%% Cell type:code id: tags:
``` python
nodes = [0, 1, 2, 3, 4, 5]
edges = [(0, 1), (1, 2), (1, 4),
(1, 5), (2, 3), (2, 4),
(3, 4), (4, 5)]
```
%% Cell type:markdown id: tags:
***
**(b) Determine the order and the size of the network.**