Commit 5b02f941 authored by sp2668's avatar sp2668
Browse files

Initial commit

parents
\documentclass[11pt,a4paper,fleqn]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[colorlinks=true, citecolor=blue, linkcolor=blue, filecolor=blue,urlcolor=blue]{hyperref}
\hypersetup{
colorlinks = true,
citecolor = gray
}
\usepackage{wrapfig}
\usepackage{caption}
\captionsetup{format=plain, indent=5pt, font=footnotesize, labelfont=bf}
\setkomafont{disposition}{\scshape\bfseries}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{bbm}
\usepackage{mathtools}
% \usepackage{epsfig}
% \usepackage{grffile}
%\usepackage{times}
\usepackage{palatino}
\usepackage{mathpazo}
\setlength\parindent{0pt}
%\usepackage{babel}
\usepackage{tikz}
\usepackage{paralist}
\usepackage{color}
\usepackage[top=3cm, bottom=2.5cm, left=2.5cm, right=3cm]{geometry}
%\setlength{\mathindent}{1ex}
% PGF
\usepackage{pgfplots}
\pgfplotsset{
compat=newest,
every axis/.append style={small, minor tick num=3}
}
%\usepackage[backend=biber,style=alphabetic,url=false,doi=false]{biblatex}
%\addbibresource{sheet01_biber.bib}
% \addbibresource{/home/coroa/papers/refs.bib}
\newcommand{\id}{\mathbbm{1}}
\newcommand{\NN}{{\mathbbm{N}}}
\newcommand{\ZZ}{{\mathbbm{Z}}}
\newcommand{\RR}{{\mathbbm{R}}}
\newcommand{\CC}{{\mathbbm{C}}}
\renewcommand{\vec}[1]{{\boldsymbol{#1}}}
\renewcommand{\i}{\mathrm{i}}
\newcommand{\expect}[1]{\langle\,#1\,\rangle}
\newcommand{\e}[1]{\ensuremath{\,\mathrm{#1}}}
\renewcommand{\O}{\mc{O}}
\newcommand{\veps}{\varepsilon}
\newcommand{\ud}[1]{\textup{d}#1\,}
\newcommand{\unclear}[1]{\color{green}#1}
\newcommand{\problem}[1]{\color{red}#1}
%=====================================================================
%=====================================================================
\begin{document}
\begin{center}
\textbf{\Large Energy System Modelling }\\
{SS 2018, Karlsruhe Institute of Technology}\\
{Institute of 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]
\end{center}
\vspace{1em}
%=============== ======================================================
\paragraph{Problem I.1 \normalsize (data analysis).}~\\
%=====================================================================
The following data are made available to you on the course home
page\footnote{\url{https://nworbmot.org/courses/complex_renewable_energy_networks/}}:
\begin{verbatim}
de_data.csv, gb_data.csv, eu_data.csv, (wind.csv, solar.csv, load.csv).
\end{verbatim}
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\e{h}\) and the time series are several years long.
\begin{enumerate}[(a)]
\item Check that the wind and solar time series are normalized to 'per-unit of installed \mbox{capacity}', and that the load time series is normalized to MW.
\item For all three regions, calculate the maximum, mean, and variance of the time series.
\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 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)$:
\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{\Delta}(\omega) \right|^2$ as a function of
$\omega$. Discuss the relationship of these results with the
findings obtained in (b)-(e).
\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*}
\Delta(t) = \gamma \alpha W(t) + \gamma (1 - \alpha) S(t) - L(t)
\end{equation*}
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.
\end{enumerate}
\pagebreak
%=====================================================================
\paragraph{Problem I.2 \normalsize (analytical).}~\\
%=====================================================================
\begin{wrapfigure}[11]{r}{0pt}
\begin{tikzpicture}
\begin{axis}[
domain=0:1, no markers, samples=200
% xlabel = $x$, ylabel = $f(x)$
]
\addplot+[dashed] {1 + 0.4 * cos(deg(2*pi*x))}; \label{figref:w}
\addplot+[densely dotted] {1 - 0.75 * cos(deg(2*pi*x))}; \label{figref:s}
\addplot+[solid] {1 + 0.1 * cos(deg(2*pi*x))}; \label{figref:l}
\addplot+[dotted] {1}; \label{figref:1}
\end{axis}
\end{tikzpicture}
\caption{Seasonal variations of wind and solar power generation
\(W(t)\)
\autoref{figref:w} and \(S(t)\)
\autoref{figref:s}, and load \(L(t)\)
\autoref{figref:l} around the mean \(1\) \ref{figref:1}.}
\label{fig:seasonalvariations}
\end{wrapfigure}
Figure \ref{fig:seasonalvariations} shows approximations to the
seasonal variations of wind and solar power generation \(W(t)\)
and \(S(t)\) and load \(L(t)\):
\begin{align*}
W(t) & = 1 + A_W \cos \omega t \\
S(t) & = 1 - A_S \cos \omega t \\
L(t) & = 1 + A_L \cos \omega t
\end{align*}
The time series are normalized to
\(\expect{W} = \expect{S} = \expect{L} := \frac{1}{T} \int_0^T L(t)
\ud t = 1\), and the constants have the values
\begin{align*}
\omega & = \frac{2\pi}{T} & T & = 1 \e{year} \\
A_W & = 0.4 & A_S & = 0.75 & A_L & = 0.1
\end{align*}
~\\
\begin{enumerate}[(a)]
\item What is the seasonal optimal mix \(\alpha\), which minimizes
\begin{equation*}
\expect{\left[ \alpha W(\cdot) + (1-\alpha) S(\cdot) - L(\cdot) \right]^2} = \frac1T \int_0^T \left[ \alpha W(t) + (1-\alpha) S(t) - L(t) \right]^2 \,\mathrm d t
,
\end{equation*}
\item How does the optimal mix change if we replace \(A_L \to -A_L\)?
\item Now assume that there is a seasonal shift in the wind signal
\begin{equation*}
W(t) = 1 + A_W \cos \left( \omega t - \phi \right)
.
\end{equation*}
Express the optimal mix \(\alpha\) as a function of \(\phi\).
\item A constant conventional power source \(C(t) = 1 - \gamma\) is now introduced. The mismatch then becomes
\begin{equation}
\Delta(t) = \gamma \left[ \alpha W(t) + (1-\alpha) S(t) \right] + C(t) - L(t)
.
\end{equation}
Analogously to (a), find the optimal mix \(\alpha\) as a function of \(0 \leq \gamma \leq 1\), which minimizes \(\expect{\Delta^2}\).
\end{enumerate}
\pagebreak
%=============== ======================================================
\paragraph{Remarks (Python pointers or where to start).}~\\
%=====================================================================
I found the python notebook based notes of Robert Johansson to be a
comprehensive kick starter\footnote{\url{http://nbviewer.jupyter.org/github/jrjohansson/scientific-python-lectures/tree/master/}}.
\begin{itemize}
\item
\href{http://nbviewer.jupyter.org/github/jrjohansson/scientific-python-lectures/blob/master/Lecture-0-Scientific-Computing-with-Python.ipynb}{Lecture~0} covers installation and getting ready.
\item
\href{http://nbviewer.jupyter.org/github/jrjohansson/scientific-python-lectures/blob/master/Lecture-1-Introduction-to-Python-Programming.ipynb}{Lecture~1}
zooms through most basic general python control structures (only
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{http://www.python-course.eu/course.php}{python2 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/2/tutorial/}} available in \href{https://docs.python.org/2/tutorial/}{english} and \href{https://py-tutorial-de.readthedocs.org/de/python-3.3/index.html}{german}; which will NOT introduce you to numpy or scipy.
\end{itemize}
%\printbibliography
\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
%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
```
%% 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)$.**
%% 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{\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
```
%% 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}$.
%% 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