Skip to content

Commit

Permalink
Map balmorel plotting tool (#27)
Browse files Browse the repository at this point in the history
* First draft of the map plot tool

* Updates :
- fix line width problem
- add background colormap

* Adjust scales for pie plotting

* Fixing the legend

* Code clearing

* code clearing

* Ioannis map function deleted

* Put possibility to have a personalized geofile again

* Fix some coordinates issues

* Fix generation_show option issue

* Fix savefig issue

* Documentation

* cartopy

* Added option to color countries

* Added bioconda

* Trying pip instead

* Uploading pybalmorel 0.5.0 to PyPI

* Added gams system directory to function

* New upload

---------

Co-authored-by: mathias157 <mathiasros@gmail.com>
  • Loading branch information
theodoreln and Mathias157 authored Jan 20, 2025
1 parent 435eae7 commit 7af371f
Show file tree
Hide file tree
Showing 92 changed files with 3,700 additions and 763 deletions.
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
project = "pybalmorel"
copyright = "2024, Mathias Berg Rosendal, Théodore Le Nalinec"
author = "Mathias Berg Rosendal, Théodore Le Nalinec"
release = "0.4.5"
release = "0.5.1"

exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", ".testenv", ".testenv/**"]

Expand Down
1 change: 1 addition & 0 deletions docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ The following notebooks can also be downloaded:
- [Pre-Processing](https://github.com/Mathias157/pybalmorel/blob/master/examples/PreProcessing.ipynb)
- [Execution](https://github.com/Mathias157/pybalmorel/blob/master/examples/Execution.ipynb)
- [Post-Processing](https://github.com/Mathias157/pybalmorel/blob/master/examples/PostProcessing.ipynb)
- [Post_Processing Map]((https://github.com/Mathias157/pybalmorel/blob/master/examples/PostProcessing_map.ipynb))


```{toctree}
Expand Down
9 changes: 9 additions & 0 deletions docs/examples/postprocessing.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ model.results.plot_map(model.results.sc[0], 'electricity', 2050)
model.results.plot_profile('heat', 2050, model.results.sc[1])
```

For more information about the map plotting please look here :

```{toctree}
:maxdepth: 1
:hidden:
postprocessing_map.md
```

## Getting Specific Results
The `model.results` is actually a `MainResults` class. The example below illustrates how to get specific results using that class.

Expand Down
161 changes: 161 additions & 0 deletions docs/examples/postprocessing_map.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
# Pybalmorel for map plotting

This notebook provide examples on how to use the pybalmorel post processing map plotting tool.

```python
### Loading scenarios
res = MainResults(files=['MainResults_Example1.gdx', 'MainResults_Example2.gdx', 'MainResults_Example3.gdx'], paths='files', scenario_names=['SC1', 'SC2', 'SC3'])
```

## Basic map plotting

The map plotting tool only needs 3 arguments to work. One has to select the **scenario** (see scenarios importation in [this section](postprocessing.md)), the **year** and the **commodity** shown on both the lines and the generation capacity. \
For now, electricity and hydrogen can be selected as commodities. If the information are available in the gdx results file, it should work.


```python
fig, ax = res.plot_map(scenario='SC3', year=2050, commodity='Electricity')
```

![png](../img/PostProcessing_map_files/PostProcessing_map_4_3.png)


```python
fig, ax = res.plot_map(scenario='SC3', year=2050, commodity='Hydrogen')
```

![png](../img/PostProcessing_map_files/PostProcessing_map_5_2.png)


## Selecting a different transmission information

The option **lines** allows to plot different transmission line information amongst *Capacity*, *FlowYear*, *FlowTime*, *UtilizationYear*, *UtilizationTime*. \
Please note that for *FlowTime* and *UtilizationTime*, it is possible to select a specific **S** and **T** to select a specific simulation time. \
It is also possible to select with **generation** the generation information plotted amongst *Capacity* and *Production*. It is also possible to desactivate pie charts with *generation_show* option.


```python
fig, ax = res.plot_map(scenario='SC3', year=2050, commodity='Electricity', lines='Capacity', generation='Capacity')
```

![png](../img/PostProcessing_map_files/PostProcessing_map_7_2.png)


```python
fig, ax = res.plot_map(scenario='SC3', year=2050, commodity='Electricity', lines='FlowTime', generation='Production', S='S08', T='T076')
```

![png](../img/PostProcessing_map_files/PostProcessing_map_8_2.png)


```python
fig, ax = res.plot_map(scenario='SC3', year=2050, commodity='Electricity', lines='FlowYear', generation='Production', generation_show=False)
```

![png](../img/PostProcessing_map_files/PostProcessing_map_9_2.png)


```python
fig, ax = res.plot_map(scenario='SC3', year=2050, commodity='Electricity', lines='UtilizationTime', generation='Production')
```

![png](../img/PostProcessing_map_files/PostProcessing_map_10_2.png)


```python
fig, ax = res.plot_map(scenario='SC3', year=2050, commodity='Electricity', lines='UtilizationYear', generation='Production')
```

![png](../img/PostProcessing_map_files/PostProcessing_map_11_2.png)



## Background information and legend selection

Using the option **background**, it is possible to plot an additional information that colors the countries. For now *H2 Storage* and *Elec Storage* have been implemented. \
It is also possible to change the legend of the pie charts and to select either *TECH_TYPE* or *FFF* to be plotted.


```python
fig, ax = res.plot_map(scenario='SC3', year=2050, commodity='Electricity', lines='FlowYear', generation='Capacity', background="Elec Storage", generation_var='TECH_TYPE')
```

![png](../img/PostProcessing_map_files/PostProcessing_map_13_2.png)


```python
fig, ax = res.plot_map(scenario='SC3', year=2050, commodity='Electricity', lines='FlowYear', generation='Capacity', background="H2 Storage", generation_var='FFF')
```

![png](../img/PostProcessing_map_files/PostProcessing_map_14_2.png)


## Geofile input and coordinates issues

Using the option **path_to_geofile**, it is possible to use a personalized map file with a specific column (option *geo_file_region_column*) with the name of the regions in your Balmorel file. \
When using this option, the coordinates are set automatically as the border of the map plus an offset that can be modified with the option *coordinates_geofile_offset*. \
It is also possible to choose to plot only Denmark by setting *choosen_map_coordinates* as "DK" (if you only have data for denmark, please use it) or to select specific coordinates with *map_coordinates*. \
Please note that when modifying all of this, you will have trouble with the size of the pie charts that are defined in data values. You will need to modify those to have something that you like. \
**For now, the legend is only working for the EU coordinates (in the case of having data for all EU) !!**


```python
fig, ax = res.plot_map(scenario='SC3', year=2050, commodity='Electricity', path_to_geofile="../../../examples/files/Geofile_Example.geojson")
```

![png](../img/PostProcessing_map_files/PostProcessing_map_16_4.png)


```python
fig, ax = res.plot_map(scenario='SC1', year=2050, commodity='Electricity', lines='Capacity')
```

![png](../img/PostProcessing_map_files/PostProcessing_map_17_2.png)


```python
fig, ax = res.plot_map(scenario='SC1', year=2050, commodity='Electricity', lines='Capacity', choosen_map_coordinates="DK")
```

![png](../img/PostProcessing_map_files/PostProcessing_map_18_2.png)



## Additional options

There is a large number of additional options available and the detailed can be found in the function's help below :


```python
help(res.plot_map)
```

Let's review some examnples :

```python
# If you want to show the value of the lines and not the arrows
fig, ax = res.plot_map(scenario='SC3', year=2050, commodity='Electricity', lines='UtilizationYear', generation='Capacity',
line_label_show=True, line_flow_show=False)
```

![png](../img/PostProcessing_map_files/PostProcessing_map_21_3.png)


```python
# If you want to clusterize the pie charts and/or the lines and not plot the smaller ones
fig, ax = res.plot_map(scenario='SC3', year=2050, commodity='Electricity', lines='FlowYear', generation='Capacity',
line_width_cat='cluster', pie_radius_cat='cluster', line_show_min=1)
```

![png](../img/PostProcessing_map_files/PostProcessing_map_22_2.png)


```python
# If you want to specified the colors of things
fig, ax = res.plot_map(scenario='SC3', year=2050, commodity='Electricity', lines='FlowYear', generation='Capacity',
background_color='blue', regions_model_color='green', regions_ext_color='red', line_color='black')
```

![png](../img/PostProcessing_map_files/PostProcessing_map_23_2.png)


4 changes: 3 additions & 1 deletion docs/get_started/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ dependencies:
- geopandas>=1.0.1
- ipywidgets>=8.1.3
- ipykernel>=6.29.5
- cartopy>=0.24.1
- pip
- pip:
- pybalmorel==0.4.5
- pybalmorel==0.5.1
- cartopy>=0.24.1
```
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ dependencies:
- pytest=8.3.3
- pip
- pip:
- pybalmorel==0.4.5
- pybalmorel==0.5.1
- cartopy>=0.24.1
Loading

0 comments on commit 7af371f

Please sign in to comment.