# Energy System Modelling - Tutorial II

**Imports**


```python
import numpy as np
import numpy.linalg
import pandas as pd
import matplotlib.pyplot as plt
plt.style.use('bmh')
%matplotlib inline
```

***
## Problem II.1

**(a) Compile the nodes list and the edge list.**
> **Remark:** While graph-theoretically both lists are unordered sets, let's agree on an ordering now which can serve as basis for the matrices in the following exercises: we sort everything in ascending numerical order, i.e. node 1 before node 2 and edge (1,2) before (1,4) before (2,3).


```python

```

***
**(b) Determine the order and the size of the network.**


```python

```

***
**(c) Compute the adjacency matrix $A$ and check that it is symmetric.**
> In graph theory and computer science, an adjacency matrix is a square matrix used to represent a finite graph. The elements of the matrix indicate whether pairs of vertices are adjacent or not in the graph.

Adjacency Matrix:


```python

```

Check for symmetry:


```python

```

***
**(d) Find the degree $k_n$ of each node $n$ and compute the average degree of the network.**
> In graph theory, the degree (or valency) of a vertex of a graph is the number of edges incident to the vertex, with loops counted twice.


```python

```

***
**(e) Determine the incidence matrix $K$ by assuming the links are always directed from smaller-numbered node to larger-numbered node, i.e.\ from node 2 to node 3, instead of from 3 to 2.**
> The unoriented incidence matrix (or simply incidence matrix) of an undirected graph is a $n \times m$ matrix $B$, where n and m are the numbers of vertices and edges respectively, such that $B_{i,j} = 1$ if the vertex $v_i$ and edge $e_j$ are incident and 0 otherwise.


```python

```

***
**(f) Compute the Laplacian $L$ of the network using $k_n$ and $A$. Remember that the Laplacian can also be computed as $L=KK^T$ and check that the two definitions agree.**
> The **Laplacian** (also: admittance matrix, Kirchhoff matrix, discrete Laplacian) is a matrix representation of a graph. It is defined as the difference of degree matrix and adjacency matrix. The **degree matrix** is a diagonal matrix which contains information about the degree of each vertex.


```python

```

***
**(g) Find the diameter of the network by looking at the graph.**
> The diameter of a network is the longest of all the calculated shortest paths in a network. It is the shortest distance between the two most distant nodes in the network. In other words, once the shortest path length from every node to all other nodes is calculated, the diameter is the longest of all the calculated path lengths. The diameter is representative of the linear size of a network. 


```python

```

***
## Problem II.2

If you map the nodes to `0=DK, 1=DE, 2=CH, 3=IT, 4=AT, 5=CZ` the network represents a small part of the European electricity network (albeit very simplified). In the repository, you can find the power imbalance time series for the six countries for January 2017 in hourly MW at `./data/imbalance.csv`. They have been derived from physical flows as published by [ENTSO-E](https://transparency.entsoe.eu/transmission-domain/physicalFlow/show)

The linear power flow is given by
$$p_i = \sum_j \tilde{L}_{i,j}\theta_j \qquad \text{and} \qquad f_l = \frac{1}{x_l} \sum_i K_{i,l}\theta_i, \qquad \text{where} \qquad \tilde{L}_{i,j}= \sum_l K_{i,l}\frac{1}{x_l} K_{j,l}$$
is the weighted Laplacian. For simplicity, we assume identity reactance on all links $x_l = 1$.

***
**Read data**


```python
imbalance = pd.read_csv('data/imbalance.csv', index_col=0, parse_dates=True)
imbalance.head()
```




<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>DK</th>
      <th>DE</th>
      <th>CH</th>
      <th>IT</th>
      <th>AT</th>
      <th>CZ</th>
    </tr>
    <tr>
      <th>DateTime</th>
      <th></th>
      <th></th>
      <th></th>
      <th></th>
      <th></th>
      <th></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>2017-01-01 00:00:00</th>
      <td>-79.73</td>
      <td>3486.25</td>
      <td>-3403.37</td>
      <td>-97.5</td>
      <td>-2867.33</td>
      <td>2961.68</td>
    </tr>
    <tr>
      <th>2017-01-01 01:00:00</th>
      <td>-109.14</td>
      <td>4248.17</td>
      <td>-3829.59</td>
      <td>-105.9</td>
      <td>-3149.98</td>
      <td>2946.44</td>
    </tr>
    <tr>
      <th>2017-01-01 02:00:00</th>
      <td>-101.49</td>
      <td>5314.56</td>
      <td>-4131.66</td>
      <td>-199.2</td>
      <td>-3646.87</td>
      <td>2764.66</td>
    </tr>
    <tr>
      <th>2017-01-01 03:00:00</th>
      <td>-197.96</td>
      <td>5450.71</td>
      <td>-4009.61</td>
      <td>-656.0</td>
      <td>-3345.56</td>
      <td>2758.42</td>
    </tr>
    <tr>
      <th>2017-01-01 04:00:00</th>
      <td>-526.15</td>
      <td>5695.72</td>
      <td>-3924.43</td>
      <td>-646.2</td>
      <td>-3393.12</td>
      <td>2794.18</td>
    </tr>
  </tbody>
</table>
</div>



\begin{equation}
p_u = \sum_v L_{u,v} \theta_v
\end{equation}

***
**(a) Compute the voltage angles $\theta_j$ and flows $f_l$ for the first hour in the dataset with the convention of $\theta_0 = 0$; i.e. the slack bus is at node 0.**
> **Remark:** Linear equation systems are solved efficiently using [`numpy.linalg.solve`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.solve.html).

Calculate the *voltage angles* first:


```python

```

Then, calculate the *flows*:


```python

```

***
**(b) Determine the average flow on each link for January 2017 and draw it as a directed network**

> **Hint:** You may want to make use of the function `np.vstack`.


```python

```

6c8624521f76e8867e42745af568065b51f2dc10
ipynb
Jupyter Notebook
Tutorials/02-tutorial-05.06.2020/notebooks/02-tutorial-task-1+2.ipynb
pitmonticone/EnergySystemModelling
4179cea3b55b295cf6de971b6444bb3d8c957d9f
CC-BY-4.0
2020-06-26T11:42:37.000Z
2022-03-30T20:16:55.000Z
Tutorials/02-tutorial-05.06.2020/notebooks/02-tutorial-task-1+2.ipynb
hmasrur/EnergySystemModelling
4179cea3b55b295cf6de971b6444bb3d8c957d9f
CC-BY-4.0
Tutorials/02-tutorial-05.06.2020/notebooks/02-tutorial-task-1+2.ipynb
hmasrur/EnergySystemModelling
4179cea3b55b295cf6de971b6444bb3d8c957d9f
CC-BY-4.0
2020-07-23T08:01:43.000Z
2021-04-25T07:16:29.000Z
Qwen/Qwen-72B
1. YES
2. YES