{ "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 . or load.sort_values() <- cursor between brackets, Shift-" ] }, { "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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
01234
foo0.3901260.5020560.9588720.1868660.860330
bar0.0426610.6367680.2335350.5774350.909700
baz0.9572050.3131620.3482740.5426850.698854
\n", "
" ], "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. **" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "***\n", "** (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", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Extra: Also compare the wind between the different regions" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "***\n", "**(d) For all three regions, plot the duration curve for $W(t)$, $S(t)$, $L(t)$.** " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "***\n", "**(e) For all three regions, plot the probability density function of $W(t)$, $S(t)$, $L(t)$.**" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "There are two different methods:\n", "1. [Histograms](https://en.wikipedia.org/wiki/Histogram) and \n", "2. [Kernel density estimation (KDE)](https://en.wikipedia.org/wiki/Kernel_density_estimation).\n", "\n", "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", "metadata": {}, "source": [ "First, let's look at the wind data:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": true }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": { "scrolled": true }, "source": [ "Now, let's look at the solar data:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": true }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The solar data might be hard to see. Look at this in detail by limiting the y-axis to (0,2):" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": { "scrolled": true }, "source": [ "Finally, let's look at the load profile:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": true }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "***\n", "**(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)$:**\n", "\n", "$$\\tilde{X}(\\omega) = \\int_0^T X(t) \\;e^{i\\omega t} \\;\\mathrm{d}t.$$\n", "\n", "**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", "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}$." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "***\n", "**(g) Normalize the time series to one, so that $\\langle{W}\\rangle = \\langle{S}\\rangle = \\langle{L}\\rangle = 1$.**\n", "\n", "**Now, for all three regions, plot the mismatch time series**\n", " \n", " $$\\Delta(t) = \\gamma \\alpha W(t) + \\gamma (1 - \\alpha) S(t) - L(t)$$\n", " \n", "**for the same winter and summer months as in (c). Choose** \n", "1. $\\alpha \\in \\{0.0, 0.5, 0.75, 1.0\\}$ with $\\gamma = 1$, and \n", "2. $\\gamma \\in \\{0.5, 0.75, 1.0, 1.25, 1.5\\}$ with $\\alpha = 0.75$.\n", "\n", "**What is the interpretation of $\\gamma$ and $\\alpha$?**" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Choose the country and alpha, gamma values and re-run:" ] }, { "cell_type": "code", "execution_count": 112, "metadata": {}, "outputs": [], "source": [ "d = de\n", "gamma = 1.0\n", "alpha = 0" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "Normalize the time series and calculate mismatch time series:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Plot the mismatch time series for the winter and summer months:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "***\n", "**(h) For all three regions, repeat (b)-(f) for the mismatch time series. What changed?**" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Data check**" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Time series plot**" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Duration curve**" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Probability density function**" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": true }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Fast Fourier Transform**" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.4" }, "nav_menu": {}, "toc": { "navigate_menu": true, "number_sections": true, "sideBar": false, "threshold": 6, "toc_cell": false, "toc_section_display": "block", "toc_window_display": true }, "varInspector": { "cols": { "lenName": 16, "lenType": 16, "lenVar": 40 }, "kernels_config": { "python": { "delete_cmd_postfix": "", "delete_cmd_prefix": "del ", "library": "var_list.py", "varRefreshCmd": "print(var_dic_list())" }, "r": { "delete_cmd_postfix": ") ", "delete_cmd_prefix": "rm(", "library": "var_list.r", "varRefreshCmd": "cat(var_dic_list()) " } }, "types_to_exclude": [ "module", "function", "builtin_function_or_method", "instance", "_Feature" ], "window_display": false } }, "nbformat": 4, "nbformat_minor": 1 }