Commit 4992e412 authored by sp2668's avatar sp2668
Browse files

Change nomenclature q/Q -> d/D for demand + g/G for generation

parent 4a0e0cb9
%% 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
 
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
 
%% Cell type:code id: tags:
 
``` python
a[1:3]
```
 
%% Output
 
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
 
foo 0.191527
bar 0.866264
baz 0.338317
foo 0.268016
bar 0.969528
baz 0.171212
dtype: float64
 
%% Cell type:code id: tags:
 
``` python
s["foo":"bar"]
```
 
%% Output
 
foo 0.191527
bar 0.866264
foo 0.268016
bar 0.969528
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
 
array([[ 0.23005626, 0.85227057, 0.83846306, 0.89066314, 0.71151271],
[ 0.07761223, 0.97980108, 0.34868122, 0.75078926, 0.96252371],
[ 0.92787399, 0.62272409, 0.58763381, 0.71937543, 0.19855054]])
array([[ 0.63346698, 0.22021609, 0.42064879, 0.47521256, 0.82246114],
[ 0.91677278, 0.33011203, 0.38242317, 0.73180186, 0.19080544],
[ 0.14882987, 0.74586303, 0.97671972, 0.21033794, 0.3308271 ]])
 
%% 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
 
0 1 2 3 4
foo 0.903758 0.597699 0.105770 0.708391 0.833426
bar 0.218514 0.784634 0.626200 0.797509 0.501407
baz 0.907245 0.841323 0.027155 0.133918 0.689129
foo 0.970723 0.416728 0.120606 0.296505 0.898589
bar 0.323891 0.369041 0.533998 0.705619 0.670083
baz 0.665230 0.203579 0.451946 0.994433 0.131078
 
%% Cell type:code id: tags:
 
``` python
s.mean()
```
 
%% Output
 
0 0.676506
1 0.741219
2 0.253041
3 0.546606
4 0.674654
0 0.653281
1 0.329783
2 0.368850
3 0.665519
4 0.566583
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:
 
Show the first 5 lines (header) of the German data:
 
%% Cell type:code id: tags:
 
``` python
de.head()
```
 
%% Output
 
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:
 
The wind, solar and load files are just differently organized datasets, its the same data:
 
%% Cell type:code id: tags:
 
``` python
(wind['DE'] == de['wind']).all()
```
 
%% Output
 
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.**
**(b) Calculate the maximum, mean, and variance of the time series. **
 
%% Cell type:code id: tags:
 
``` python
de.index
```
 
%% Output
 
DatetimeIndex(['2011-01-01 00:00:00', '2011-01-01 01:00:00',
'2011-01-01 02:00:00', '2011-01-01 03:00:00',
'2011-01-01 04:00:00', '2011-01-01 05:00:00',
'2011-01-01 06:00:00', '2011-01-01 07:00:00',
'2011-01-01 08:00:00', '2011-01-01 09:00:00',
...
'2014-12-31 14:00:00', '2014-12-31 15:00:00',
'2014-12-31 16:00:00', '2014-12-31 17:00:00',
'2014-12-31 18:00:00', '2014-12-31 19:00:00',
'2014-12-31 20:00:00', '2014-12-31 21:00:00',
'2014-12-31 22:00:00', '2014-12-31 23:00:00'],
dtype='datetime64[ns]', name='time', length=35064, freq=None)
 
%% Cell type:markdown id: tags:
 
Data set includes four years ranging from `2011-01-01` until `2014-12-31`.
 
%% Cell type:code id: tags:
 
``` python
de.describe()
```
 
%% Output
 
wind solar load
count 35064.000000 35064.000000 35064.000000
mean 0.265785 0.149262 54877.199806
std 0.239194 0.221564 10354.693128
min 0.000577 0.000000 29201.000000
25% 0.078827 0.000000 46321.750000
50% 0.181354 0.000000 54594.000000
75% 0.394514 0.268505 63953.250000
max 0.994588 0.913781 79286.000000
 
%% Cell type:code id: tags:
 
``` python
de.var()
```
 
%% Output
 
wind 5.721393e-02
solar 4.909081e-02
load 1.072197e+08
dtype: float64
 
%% Cell type:markdown id: tags:
 
There are 35064 time slots: 8760h*4 + 24 (2012 was a leap year!)
 
The wind and solar time series have a maximum slightly below 1, thus we can conclude that per-unit values are given.
 
The load time series has a unit of MW, with the mean of 55 GW, which is typical for Germany.
 
Max, mean and variance as shown above in per-unit/MW.
 
%% 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
fig, axes = plt.subplots(2, 1, figsize=(12, 8))
de.loc["2012-07", ['wind', 'solar']].plot(ax=axes[0])
axes[0].set_title("Summer month")
 
de.loc["2012-01", ['wind', 'solar']].plot(ax=axes[1])
axes[1].set_title("Winter month")
 
fig.tight_layout()
```
 
%% Output