This Gitlab instance will be briefly unavailable today from 19:15 CET onwards for maintenance reasons.
Diese Gitlab-Instanz wird heute ab 19:15 Uhr kurzzeitig nicht verfügbar sein aufgrund von Wartungsarbeiten.
1. For example, you want all countries with one node except for Germany, here you want 10 nodes.
2. Pypsa-eur usually looks at 33 countries. So in total, you want 43 nodes.
3. Germany gets a focus weight of 10/43.
4. All other countries get a focus weight of 1/43.
* add focus weights in the form of:
`focus weights:`
`focus weights:`
` 'DE': 0.2326`
`'DE': 0.2326`
` 'IT': 0.02326 `
`...`
`'IT': 0.02326``...`
* all countries must have a focus weight
* the total number of nodes for this case is **47**, because there are four countries, who always have two nodes: Great Britain (Northern Ireland and the rest), Italy (mainland Italy and Sardinia), Denmark (the part, which borders Germany, and the part, which borders Sweden) and Spain (mainland Spain and balearic islands). Therefore, the minmum number of nodes possible is 37 and not 33 (= number of countries). For the calulation of focus weights, those extra nodes must not be paid attention to.
* the total number of nodes for this case is **47**, because there are four countries, who always have two nodes: Great Britain (Northern Ireland and the rest), Italy (mainland Italy and Sardinia), Denmark (the part, which borders Germany, and the part, which borders Sweden) and Spain (mainland Spain and balearic islands). Therefore, the minmum number of nodes possible is 37 and not 33 (= number of countries). For the calulation of focus weights, those extra nodes must not be paid attention to.
* When you want to have a higher nodal resolution of one of these four countries, maybe some adjustments must be made
## Custom Clustering
This chapter was written and tested for the commit cfb979a0d0f037a24b9d916b726805108386049b (03.12.2020) on the master branch of the [PyPSA-eur repository](https://github.com/PyPSA/pypsa-eur).
It was an [issue](https://github.com/PyPSA/pypsa-eur/issues/124) there. The functionality has been last checked on 12.02.2021 on the PyPSA-eur master branch (commit df2425d4a04648e948d8291421cab7d2ca36529f, 14.01.2021).
**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.
This chapter was written and tested for the commit cfb979a0d0f037a24b9d916b726805108386049b (03.12.2020) on the master branch of the [PyPSA-eur repository](https://github.com/PyPSA/pypsa-eur). It was an [issue](https://github.com/PyPSA/pypsa-eur/issues/124) there. The functionality has been last checked on 12.02.2021 on the PyPSA-eur master branch (commit df2425d4a04648e948d8291421cab7d2ca36529f, 14.01.2021).
**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**
- 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.
- Execute it. It will create a `custom_busmap_elec_s_{clusters}.csv` file where `clusters` is analogous to its use in the PyPSA-eur snakefile. It will be written to the PyPSA-eur-folder "data".
...
...
@@ -33,25 +35,21 @@ The goal was to define a model with higher resolution for Germany ([NUTS 2](http
- 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)| |
| DE (NUTS 2 level), AT (NUTS 0) & IT (NUTS 0) with buses | |
| DE (NUTS 2 level), AT (NUTS 0) & IT (NUTS 0) with buses |  |
**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.\* |
**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:
\*E.g. the thrown error can look like this:
| 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.*|
E.g. the thrown error can look like this:
```
```plaintext
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,8 +67,9 @@ AssertionError: In Bus cluster country the values of attribute country do not ag
Name: country, Length: 137, dtype: object
```
Gain insight by altering the following code in ´C:\ProgramData\Miniconda3\envs\pypsa-eur\Lib\site-packages\pypsa\networkclustering.py´:
```
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: