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.
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Energy System Modelling - Tutorial I\n",
"\n",
"SS 2018, Karlsruhe Institute of Technology, Institute for Automation and Applied Informatics\n",
"***"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"# Imports"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd\n",
"import matplotlib.pyplot as plt\n",
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"***\n",
"# Introductory Comments"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Getting Help\n",
"\n",
"Executing cells with Shift-Enter and with `h` there is help.\n",
"\n",
"Help is available with `.<TAB>` or load.sort_values() <- cursor between brackets, `Shift-<TAB>`"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Using one-dimensional arrays (Numpy and Pandas)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Numpy**"
]
},
{
"cell_type": "code",
"execution_count": 43,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])"
]
},
"execution_count": 43,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a = np.arange(10)\n",
"a"
]
},
{
"cell_type": "code",
"execution_count": 44,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([1, 2])"
]
},
"execution_count": 44,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"a[1:3]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Pandas**"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"foo 0.748951\n",
"bar 0.286110\n",
"baz 0.274185\n",
"dtype: float64"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"s = pd.Series(np.random.random(3), index=['foo', 'bar', 'baz'])\n",
"s"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"foo 0.748951\n",
"bar 0.286110\n",
"dtype: float64"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"s[\"foo\":\"bar\"]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Using two-dimensional arrays (Numpy and Pandas)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Numpy** "
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {
"scrolled": false
},
"outputs": [
{
"data": {
"text/plain": [
"array([[0.28941884, 0.4004386 , 0.67028241, 0.40211146, 0.87918444],\n",
" [0.42221308, 0.13808648, 0.08780219, 0.96793469, 0.62714239],\n",
" [0.97390844, 0.83849364, 0.65386425, 0.15093854, 0.29176614]])"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.random.random((3,5))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Pandas**"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>0</th>\n",
" <th>1</th>\n",
" <th>2</th>\n",
" <th>3</th>\n",
" <th>4</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>foo</th>\n",
" <td>0.390126</td>\n",
" <td>0.502056</td>\n",
" <td>0.958872</td>\n",
" <td>0.186866</td>\n",
" <td>0.860330</td>\n",
" </tr>\n",
" <tr>\n",
" <th>bar</th>\n",
" <td>0.042661</td>\n",
" <td>0.636768</td>\n",
" <td>0.233535</td>\n",
" <td>0.577435</td>\n",
" <td>0.909700</td>\n",
" </tr>\n",
" <tr>\n",
" <th>baz</th>\n",
" <td>0.957205</td>\n",
" <td>0.313162</td>\n",
" <td>0.348274</td>\n",
" <td>0.542685</td>\n",
" <td>0.698854</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" 0 1 2 3 4\n",
"foo 0.390126 0.502056 0.958872 0.186866 0.860330\n",
"bar 0.042661 0.636768 0.233535 0.577435 0.909700\n",
"baz 0.957205 0.313162 0.348274 0.542685 0.698854"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"s = pd.DataFrame(np.random.random((3,5)), index=['foo', 'bar', 'baz'])\n",
"s"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0 0.463331\n",
"1 0.483995\n",
"2 0.513560\n",
"3 0.435662\n",
"4 0.822961\n",
"dtype: float64"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"s.mean()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"***\n",
"# Problem I.1\n",
"\n",
"The following data are made available to you on the __[coures homepage](https://nworbmot.org/courses/complex_renewable_energy_networks/)__:\n",
"\n",
"`de_data.csv`, `gb_data.csv`, `eu_data.csv`\n",
"and alternatively\n",
"`wind.csv`, `solar.csv`, `load.csv`\n",
"\n",
"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.\n",
"\n",
"> Remark: In this example notebook, we only look at Germany and the EU, Great Britain works in exactly the same way."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"***\n",
"**Read Data**"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
"de = pd.read_csv('tutorial_data/de_data.csv', parse_dates=True, index_col=0)\n",
"eu = pd.read_csv('tutorial_data/eu_data.csv', parse_dates=True, index_col=0)\n",
"gb = pd.read_csv('tutorial_data/gb_data.csv', parse_dates=True, index_col=0)"
]
},
{
"cell_type": "code",
"execution_count": 54,
"metadata": {},
"outputs": [],
"source": [
"wind = pd.read_csv('tutorial_data/wind.csv', parse_dates=True, index_col=0)\n",
"solar = pd.read_csv('tutorial_data/solar.csv', parse_dates=True, index_col=0)\n",
"load = pd.read_csv('tutorial_data/load.csv', parse_dates=True, index_col=0)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Extra: Show the first 5 lines (header) of the German data:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Extra: Check that wind, solar and load files are just differently organized datasets and it's the same data:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"***\n",
"**(a) Check that the wind and solar time series are normalized to ’per-unit of installed capacity’,\n",
"and that the load time series is normalized to MW.**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"***\n",
"**(b) Calculate the maximum, mean, and variance of the time series. **"
]
},