Update Clustering authored by David Huckebrink's avatar David Huckebrink
......@@ -26,7 +26,7 @@ This chapter was written and tested for the commit cfb979a0d0f037a24b9d916b72680
**The goal**\* The goal was to define a model with higher resolution for Germany ([NUTS 2](https://ec.europa.eu/eurostat/de/web/gisco/geodata/reference-data/administrative-units-statistical-units/nuts), also see explanation of [NUTS](https://de.wikipedia.org/wiki/NUTS) and [NUTS:DE](https://de.wikipedia.org/wiki/NUTS:DE)) and limit modelling of neighbouring countries to a minimum. While the current solution is specific to Germany, it can easily be adapted to other countries.
**The way**
## The way
- Create a PyPSA-eur-network with desired config-settings (clustering.custom_busmap in the PyPSA-eur config file must be set to `false` at this step).
- Modify `custom_clustering.py.ipynb` (in backbone_tools) such that it meets your needs.
......@@ -35,13 +35,15 @@ This chapter was written and tested for the commit cfb979a0d0f037a24b9d916b72680
- Enable clustering.custom_busmap in the PyPSA-eur config file by setting it to `true`.
- Create the final PyPSA-eur-network with desired settings (remember to match the wildcard `{clusters}` to `custom_busmap_elec_s_{clusters}.csv`).
**The result** Clustering as described above yields the following map. Note that colours only serve the purpose of visually separating clusters.
## The result
Clustering as described above yields the following map. Note that colours only serve the purpose of visually separating clusters.
| explanation | figure |
|-------------|--------|
| Germany (NUTS 2 level) with neighbours (NUTS 0) | ![sample_clustering](uploads/d150155028c473c35c34c613c6671453/sample_clustering.png) |
| DE (NUTS 2 level), AT (NUTS 0) & IT (NUTS 0) with buses | ![custom_cluster_de_at_it](uploads/36175c205aac99db03c8b5aabb5e6cf3/custom_cluster_de_at_it.png) |
**The errors** Several errors were encountered, when developing/using this tool. The following list serves as a short quick-fix guide reconstructed from the top of my head:
## The errors
Several errors were encountered, when developing/using this tool. The following list serves as a short quick-fix guide reconstructed from the top of my head:
| description | what caused it/what to do |
|-------------|---------------------------|
| 'some number does not match expected number' | One of the mentioned number is twice the amount of buses in your \`networks/elec_s.nc". Somewhere along the way some buses were lost and are missing in the output. |
......@@ -49,7 +51,7 @@ This chapter was written and tested for the commit cfb979a0d0f037a24b9d916b72680
\*E.g. the thrown error can look like this:
```plaintext
```python
File "C:\ProgramData\Miniconda3\envs\pypsa-eur\lib\site-packages\pypsa\networkclustering.py", line 60, in consense
assert ((x == v).all() or x.isnull().all()), (
AssertionError: In Bus cluster country the values of attribute country do not agree:
......@@ -69,7 +71,7 @@ Name: country, Length: 137, dtype: object
Gain further insight by altering the following code snippet in ´C:\\ProgramData\\Miniconda3\\envs\\pypsa-eur\\Lib\\site-packages\\pypsa\\networkclustering.py´ to something like this:
```plaintext
```python
def _make_consense(component, attr):
def consense(x):
v = x.iat[0]
......
......