Commit 27b4a8b7 authored by Fabian Neumann's avatar Fabian Neumann

update for summer term 2019 session

parent 379abd90
# Download
# Python Tutorials
You can download the tutorials with `git` with the following command (it should
be public):
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](http://nbviewer.jupyter.org/github/jrjohansson/scientific-python-lectures/tree/master/) are a
comprehensive kick starter.
* [Lecture 0](http://nbviewer.jupyter.org/github/jrjohansson/scientific-python-lectures/blob/master/Lecture-0-Scientific-Computing-with-Python.ipynb) covers installation and getting ready.
* [Lecture 1](http://nbviewer.jupyter.org/github/jrjohansson/scientific-python-lectures/blob/master/Lecture-1-Introduction-to-Python-Programming.ipynb)
zooms through most basic general python control structures (only
brush over it and stop reading early, i.e. if you read the word
`classes` you already know too much).
* [Lecture 2](http://nbviewer.jupyter.org/github/jrjohansson/scientific-python-lectures/blob/master/Lecture-2-Numpy.ipynb) is the most important and closely connected to the exercises.
* You might as well stop now, but if you are hooked, have a look at [Lecture 3](http://nbviewer.jupyter.org/github/jrjohansson/scientific-python-lectures/blob/master/Lecture-3-Scipy.ipynb) for more physics and [Lecture 4](http://nbviewer.jupyter.org/github/jrjohansson/scientific-python-lectures/blob/master/Lecture-4-Matplotlib.ipynb) for prettier graphs.
Further reference material of help is are the website-books http://python-course.eu/ (English), http://python-kurs.eu/ (German); especially of interest might be the [pandas](http://www.python-course.eu/pandas.php) bit in the end, which will make the exercises a breeze at the expense of yet another package to learn.
# Downloading Tutorial Material
You can download the tutorials with `git` with the following command:
```bash
cd /path/where/your/tutorial/folder/should/be
git clone https://git.scc.kit.edu/sp2668/esm_tutorials.git
```
or
```
```bash
cd /path/where/your/tutorial/folder/should/be
git clone git@git.scc.kit.edu:sp2668/esm_tutorials.git
```
if you have `ssh` setup at `git.scc.kit.edu`.
Alternatively, you can download the tutorials as compressed zip-file from
Alternatively, (not as nice as description above) you can download the tutorials as compressed zip-file from
https://git.scc.kit.edu/sp2668/esm_tutorials/-/archive/master/esm_tutorials-master.zip
# Installation Guide
**Make sure to follow these steps BEFORE the first tutorial (The wireless WILL
be spotty with so many heavy users and we'll loose precious tutorial time)!**
**If you happen to come across this before the tutorials start,
you may already want to follow the installation instructions already to get started right away.**
We'll be using `Python` in the tutorials. If you are unfamiliar with `Python`, [this](http://introtopython.org/) is a great start, but a quick Google search on `Python` tutorials will give you millions of great alternatives.
Install `miniconda` (or Anaconda). For instructions for your operating system
see https://conda.io/docs/user-guide/install/index.html
We recommend using the package manager and environment management system `conda` to install the packages we need.
Now create a new environment from the provided `requirements.yml` file. For
detailed instructions see
https://conda.io/docs/user-guide/tasks/manage-environments.html#creating-an-environment-from-an-environment-yml-file
Install [`miniconda`](https://conda.io/docs/user-guide/install/index.html) (or Anaconda). For instructions for your operating system
see https://conda.io/docs/user-guide/install/index.html.
Open a terminal. Creating the environment requires the following set of
commands. They take time and have to download several packages!
Create a new `conda` environment from the provided `environment.yaml` file with the following set of commands:
Windows:
```
```bash
conda env create -f requirements.yml
activate esm-tutorials
```
macOS and Linux:
```
```bash
conda env create -f requirements.yml
conda activate esm-tutorials
```
On some older Linux installations the last command can be instead
```bash
source activate esm-tutorials
```
Open a jupyter notebook with the following command in the tutorial folder (where your notebooks are):
For detailed instructions see
https://conda.io/docs/user-guide/tasks/manage-environments.html#creating-an-environment-from-an-environment-yml-file.
It will take some time!
With the `conda` environment installed and activated, open a jupyter notebook/lab with the following command in the tutorial folder (where your notebooks are):
```bash
cd /path/where/your/tutorial/folder/should/be
cd esm-tutorials
jupyter lab
```
or
```bash
cd /path/where/your/tutorial/folder/should/be
cd esm-tutorials
jupyter notebook
```
......
......@@ -3,20 +3,29 @@ channels:
- conda-forge
- defaults
dependencies:
- python
# notebooks
- jupyter
- matplotlib
- basemap
- jupyterlab
- nb_conda
# utilities
- numpy
- scipy
- networkx
- pandas
- python
- scikit-learn
- pyomo
- xarray
- netcdf4
- bottleneck
- networkx
- matplotlib
- yaml
# optimisation
- pyomo
- scikit-learn
- glpk
- pip:
- pypsa
- ipopt
# power system analysis
- pypsa
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -4,9 +4,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Energy System Modelling - Tutorial I\n",
"# Energy System Modelling - Tutorial I.1\n",
"\n",
"SS 2018, Karlsruhe Institute of Technology, Institute for Automation and Applied Informatics\n",
"Karlsruhe Institute of Technology, Institute for Automation and Applied Informatics\n",
"***"
]
},
......@@ -20,7 +20,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
......@@ -47,7 +47,7 @@
"\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>`"
"Help is available with `.<TAB>` or `load.sort_values()` <- cursor between brackets, `Shift-<TAB>`"
]
},
{
......@@ -66,7 +66,7 @@
},
{
"cell_type": "code",
"execution_count": 43,
"execution_count": 12,
"metadata": {},
"outputs": [
{
......@@ -75,7 +75,7 @@
"array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])"
]
},
"execution_count": 43,
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
......@@ -87,7 +87,7 @@
},
{
"cell_type": "code",
"execution_count": 44,
"execution_count": 13,
"metadata": {},
"outputs": [
{
......@@ -96,7 +96,7 @@
"array([1, 2])"
]
},
"execution_count": 44,
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
......@@ -114,19 +114,19 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"foo 0.748951\n",
"bar 0.286110\n",
"baz 0.274185\n",
"foo 0.411967\n",
"bar 0.517359\n",
"baz 0.161198\n",
"dtype: float64"
]
},
"execution_count": 13,
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
......@@ -138,18 +138,18 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"foo 0.748951\n",
"bar 0.286110\n",
"foo 0.411967\n",
"bar 0.517359\n",
"dtype: float64"
]
},
"execution_count": 14,
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
......@@ -174,7 +174,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 16,
"metadata": {
"scrolled": false
},
......@@ -182,12 +182,12 @@
{
"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]])"
"array([[0.88874586, 0.65931364, 0.0737824 , 0.75068366, 0.83953661],\n",
" [0.89467727, 0.2886438 , 0.05467341, 0.63164326, 0.39284222],\n",
" [0.62764859, 0.00685673, 0.08956703, 0.48831881, 0.36779429]])"
]
},
"execution_count": 15,
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
......@@ -205,7 +205,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 17,
"metadata": {},
"outputs": [
{
......@@ -229,76 +229,78 @@
" <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",
" <th>colA</th>\n",
" <th>colB</th>\n",
" <th>colC</th>\n",
" <th>colD</th>\n",
" <th>colE</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",
" <td>0.654135</td>\n",
" <td>0.430461</td>\n",
" <td>0.391214</td>\n",
" <td>0.936756</td>\n",
" <td>0.197864</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",
" <td>0.234510</td>\n",
" <td>0.750636</td>\n",
" <td>0.645157</td>\n",
" <td>0.838452</td>\n",
" <td>0.485820</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",
" <td>0.474954</td>\n",
" <td>0.384302</td>\n",
" <td>0.613151</td>\n",
" <td>0.496617</td>\n",
" <td>0.870843</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"
" colA colB colC colD colE\n",
"foo 0.654135 0.430461 0.391214 0.936756 0.197864\n",
"bar 0.234510 0.750636 0.645157 0.838452 0.485820\n",
"baz 0.474954 0.384302 0.613151 0.496617 0.870843"
]
},
"execution_count": 16,
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"s = pd.DataFrame(np.random.random((3,5)), index=['foo', 'bar', 'baz'])\n",
"s = pd.DataFrame(np.random.random((3,5)),\n",
" index=['foo', 'bar', 'baz'],\n",
" columns=['colA', 'colB', 'colC', 'colD', 'colE'])\n",
"s"
]
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 18,
"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",
"colA 0.454533\n",
"colB 0.521799\n",
"colC 0.549841\n",
"colD 0.757275\n",
"colE 0.518176\n",
"dtype: float64"
]
},
"execution_count": 17,
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
......@@ -307,6 +309,29 @@
"s.mean()"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"foo 0.522086\n",
"bar 0.590915\n",
"baz 0.567974\n",
"dtype: float64"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"s.mean(axis=1)"
]
},
{
"cell_type": "markdown",
"metadata": {},
......@@ -314,7 +339,7 @@
"***\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",
"The following data are made available to you on the repository in the `./data` directory:\n",
"\n",
"`de_data.csv`, `gb_data.csv`, `eu_data.csv`\n",
"and alternatively\n",
......@@ -335,36 +360,36 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 20,
"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)"
"de = pd.read_csv('data/de_data.csv', parse_dates=True, index_col=0)\n",
"eu = pd.read_csv('data/eu_data.csv', parse_dates=True, index_col=0)\n",
"gb = pd.read_csv('data/gb_data.csv', parse_dates=True, index_col=0)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 21,
"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)"
"wind = pd.read_csv('data/wind.csv', parse_dates=True, index_col=0)\n",
"solar = pd.read_csv('data/solar.csv', parse_dates=True, index_col=0)\n",
"load = pd.read_csv('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:"
"Extra: Show the first and last 5 lines (header) of the German data:"
]
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 27,
"metadata": {},
"outputs": [
{
......@@ -444,7 +469,7 @@
"2011-01-01 04:00:00 0.627257 0.0 39923.0"
]
},
"execution_count": 4,
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
......@@ -453,6 +478,97 @@
"de.head()"
]
},
{
"cell_type": "code",
"execution_count": 28,
"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>wind</th>\n",
" <th>solar</th>\n",
" <th>load</th>\n",
" </tr>\n",
" <tr>\n",
" <th>time</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>2014-12-31 19:00:00</th>\n",
" <td>0.191347</td>\n",
" <td>0.0</td>\n",
" <td>50365.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2014-12-31 20:00:00</th>\n",
" <td>0.220209</td>\n",
" <td>0.0</td>\n",
" <td>48725.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2014-12-31 21:00:00</th>\n",
" <td>0.247598</td>\n",
" <td>0.0</td>\n",
" <td>49074.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2014-12-31 22:00:00</th>\n",
" <td>0.273812</td>\n",
" <td>0.0</td>\n",
" <td>47667.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2014-12-31 23:00:00</th>\n",
" <td>0.295076</td>\n",
" <td>0.0</td>\n",
" <td>47667.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" wind solar load\n",
"time \n",
"2014-12-31 19:00:00 0.191347 0.0 50365.0\n",
"2014-12-31 20:00:00 0.220209 0.0 48725.0\n",
"2014-12-31 21:00:00 0.247598 0.0 49074.0\n",
"2014-12-31 22:00:00 0.273812 0.0 47667.0\n",
"2014-12-31 23:00:00 0.295076 0.0 47667.0"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"de.tail()"
]
},
{
"cell_type": "markdown",
"metadata": {},
......@@ -462,7 +578,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 23,
"metadata": {},
"outputs": [
{
......@@ -471,7 +587,7 @@
"True"
]
},
"execution_count": 7,
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
......@@ -480,6 +596,63 @@
"(wind['DE'] == de['wind']).all()"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"Extra: How many years does the dataset comprise?"
]
},
{
"cell_type": "code",
"execution_count": 44,
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"data": {
"text/plain": [
"DatetimeIndex(['2011-01-01 00:00:00', '2011-01-01 01:00:00',\n",
" '2011-01-01 02:00:00', '2011-01-01 03:00:00',\n",
" '2011-01-01 04:00:00', '2011-01-01 05:00:00',\n",
" '2011-01-01 06:00:00', '2011-01-01 07:00:00',\n",
" '2011-01-01 08:00:00', '2011-01-01 09:00:00',\n",
" ...\n",
" '2014-12-31 14:00:00', '2014-12-31 15:00:00',\n",
" '2014-12-31 16:00:00', '2014-12-31 17:00:00',\n",
" '2014-12-31 18:00:00', '2014-12-31 19:00:00',\n",
" '2014-12-31 20:00:00', '2014-12-31 21:00:00',\n",
" '2014-12-31 22:00:00', '2014-12-31 23:00:00'],\n",
" dtype='datetime64[ns]', name='time', length=35064, freq=None)"
]
},
"execution_count": 44,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"de.index"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"Data set includes four years ranging from `2011-01-01` until `2014-12-31`."
]
},
{
"cell_type": "markdown",
"metadata": {},
......@@ -491,7 +664,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 24,
"metadata": {},
"outputs": [
{
......@@ -503,21 +676,19 @@
"dtype: float64"
]
},
"execution_count": 8,
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"wind.max()"
]
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"***\n",
"**(b) Calculate the maximum, mean, and variance of the time series. **"
"**(b) For all three regions, calculate the maximum, mean, and variance of the time series.**"
]
},
{
......@@ -532,7 +703,7 @@
"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). **"
"**(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).**"
]
},
{
......@@ -556,12 +727,158 @@
"outputs": [],
"source": []
},
{