Update Clustering authored by Leonie Plaga's avatar Leonie Plaga
## Different number of nodes in countries
## Custom Clustering
This page was written and tested for the commit 03221fe539bf9f24806a96c0939aa34b05e5f4cc (21.10.2020) on the [custom_busmap_for_clustering](https://github.com/PyPSA/pypsa-eur/tree/custom_busmap_for_clustering) branch of the [PyPSA-eur repository](https://github.com/PyPSA/pypsa-eur).
It currently is still an [issue](https://github.com/PyPSA/pypsa-eur/issues/124) there.
**The goal***
The goal was to define a model with higher resolution for Germany ([nuts2](https://ec.europa.eu/eurostat/de/web/gisco/geodata/reference-data/administrative-units-statistical-units/nuts)) 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**
- enable clustering.custom_busmap in the PyPSA config file by setting it to `True`.
- modify `custom_clustering.py.ipynb` such that it meets your needs.
- execute it. It will create a `custom_busmap_elec_s_{clusters}.csv` file where `clusters` is analogous to its use in the PyPSA snakefile.
- copy the resulting file into your pypsa-eur\data directory. (might be automated in the future)
**The result**
Clustering as described above yields the following map. Note that colours only serve the purpose of visually separating clusters.
![sample_clustering](uploads/d150155028c473c35c34c613c6671453/sample_clustering.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:
| 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.|
| some error in a clustering routine yielding a list of country codes | Although you might not see it, the list contains different country codes but it shouldn't. Make sure that you don't create clusters that span across borders, as this causes issues. Use `n.buses` to see which bus should go into which country and check your result for differences. |