-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added GUI for defining Balmorel geography (#13)
* Added eel dashboard * Made copy button * Added environments file * Updated environments * Upgraded to 0.3.5 * Added geofilemaker GUI and new GUI class * Made a small example of the geographic file maker GUI * Corrected versions * Removed .yml file because we made a .yaml
- Loading branch information
1 parent
d07cd32
commit eb8ded0
Showing
17 changed files
with
506 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,5 @@ src/* | |
examples/files/DE.inc | ||
__pycache__ | ||
output | ||
config | ||
config | ||
build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,13 @@ | ||
|
||
## Examples | ||
# Examples | ||
The following notebooks provide examples on how to use pybalmorel for pre-processing, post-processing and for executing Balmorel scenarios: | ||
- [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) | ||
|
||
The next pages also include some code snippets on how to use various functions. | ||
|
||
```{toctree} | ||
:maxdepth: 1 | ||
examples/geofilemaker.md | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Defining Geography | ||
|
||
pybalmorel includes a GUI to interactively define nodes in Balmorel's hierarchical geographic structure comprising countries, regions and areas. | ||
```python | ||
from pybalmorel import GUI | ||
GUI.geofilemaker() | ||
``` | ||
|
||
The video below illustrates how it works. | ||
:::{figure} ../img/geoset_generator_example.gif | ||
:name: geofilemaker | ||
:alt: How to use the 'geofilemaker' GUI. | ||
:width: 100% | ||
:align: center | ||
How to use the 'geofilemaker' GUI. | ||
::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
# Get Started | ||
|
||
An installation instruction. | ||
|
||
```{toctree} | ||
:maxdepth: 1 | ||
get_started/installation.md | ||
get_started/examples.md | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ Get started [here](get_started.md). | |
:hidden: | ||
get_started | ||
examples | ||
``` | ||
|
||
```{toctree} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
name: pybalmorel | ||
channels: | ||
- conda-forge | ||
dependencies: | ||
- python >= 3.9 | ||
- pandas>=2.1.4 | ||
- matplotlib>=3.9.0 | ||
- geopandas>=1.0.1 | ||
- ipywidgets>=8.1.3 | ||
- pip | ||
- pip: | ||
- gamsapi[transfer]>=45.0.0 | ||
- eel>=0.17.0 | ||
- pybalmorel==0.3.6 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[project] | ||
name = "pybalmorel" | ||
version = "0.3.5" | ||
version = "0.3.6" | ||
maintainers = [ | ||
{ name="Mathias Berg Rosendal", email="[email protected]"}, | ||
{ name="Théodore Le Nalinec"}, | ||
|
@@ -17,7 +17,7 @@ classifiers = [ | |
"Operating System :: OS Independent", | ||
] | ||
dependencies = ['pandas>=2.1.4', 'matplotlib>=3.9.0', 'geopandas>=0.14.4', | ||
'gamsapi[transfer]>=45.0.0', 'ipywidgets>=8.1.3'] | ||
'gamsapi[transfer]>=45.0.0', 'ipywidgets>=8.1.3', 'eel>=0.17.0'] | ||
|
||
[project.urls] | ||
Repository = "https://github.com/Mathias157/pybalmorel" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from . import formatting, utils | ||
from .classes import IncFile, MainResults, Balmorel | ||
from .classes import IncFile, MainResults, Balmorel, GUI | ||
|
||
__all__ = [IncFile, MainResults, Balmorel] | ||
__all__ = [IncFile, MainResults, Balmorel, GUI] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
#%% | ||
import eel | ||
import ast | ||
from pybalmorel import IncFile | ||
import pkg_resources | ||
import os | ||
|
||
# 1.0 Other functions | ||
def get_wkdir(): | ||
return os.path.abspath('.') | ||
|
||
# 1.1 Create .inc Files | ||
def create_incfile(unique_processing): | ||
"""The general wrapper for creating and saving .inc files, | ||
because the creating of the IncFile class and saving it is the same everytime. | ||
The unique processing of the .body content differs, however. | ||
Args: | ||
unique_processing (func): The unique processing per case | ||
**incfile_kwargs: Keyword arguments to pass to IncFile | ||
""" | ||
def wrapper(**kwargs): | ||
inc_file = IncFile(name=kwargs['name'], prefix=kwargs['prefix'], | ||
suffix=kwargs['suffix'], path=kwargs['path']) | ||
unique_processing(inc_file, kwargs['geo_nodes']) | ||
inc_file.save() | ||
return wrapper | ||
|
||
## 1.1.1 CCC, RRR or AAA | ||
@create_incfile | ||
def create_sets(inc_file: IncFile, geo_nodes_layer2: dict): | ||
inc_file.body += '\n'.join(list(geo_nodes_layer2.keys())) | ||
|
||
## 1.1.2 CCCRRRAAA | ||
@create_incfile | ||
def create_CCCRRRAAA(inc_file: IncFile, geo_nodes: dict): | ||
for key in geo_nodes.keys(): | ||
inc_file.body += '\n* %s:\n' % key.capitalize() | ||
inc_file.body += '\n'.join(geo_nodes[key].keys()) | ||
|
||
## 1.1.3 CCCRRR or RRRAAA | ||
@create_incfile | ||
def create_setconnection(inc_file: IncFile, geo_nodes_layer1: dict): | ||
for node in geo_nodes_layer1.keys(): | ||
if len(geo_nodes_layer1[node]) != 0: | ||
inc_file.body += f'\n{node} . ' | ||
inc_file.body += f'\n{node} . '.join(geo_nodes_layer1[node]) | ||
|
||
|
||
# 1.2 Create .inc Files | ||
def create_incfiles(output: str, path: str): | ||
geo_nodes = ast.literal_eval(output) # Convert output to dict | ||
prefix = """SET CCC(CCCRRRAAA) 'All countries' | ||
/\n""" | ||
create_sets(geo_nodes=geo_nodes['countries'], name='CCC', prefix=prefix, suffix="\n/;", path=path) | ||
|
||
prefix = """SET RRR(CCCRRRAAA) 'All regions' | ||
/\n""" | ||
create_sets(geo_nodes=geo_nodes['regions'], name='RRR', prefix=prefix, suffix="\n/;", path=path) | ||
|
||
prefix = """SET AAA(CCCRRRAAA) 'All areas' | ||
/\n""" | ||
create_sets(geo_nodes=geo_nodes['areas'], name='AAA', prefix=prefix, suffix="\n/;", path=path) | ||
|
||
prefix = """* All sets that are related to Geographical resolution | ||
SET CCCRRRAAA 'All geographical entities (CCC + RRR + AAA)' | ||
/""" | ||
create_CCCRRRAAA(geo_nodes=geo_nodes, name='CCCRRRAAA', prefix=prefix, suffix="\n/;", path=path) | ||
|
||
prefix="""SET CCCRRR(CCC,RRR) "Regions in countries" | ||
/""" | ||
create_setconnection(geo_nodes=geo_nodes['countries'], name='CCCRRR', prefix=prefix, suffix="\n/;", path=path) | ||
|
||
prefix="""SET RRRAAA(RRR,AAA) "Areas in regions" | ||
/""" | ||
create_setconnection(geo_nodes=geo_nodes['regions'], name='RRRAAA', prefix=prefix, suffix="\n/;", path=path) | ||
|
||
def interactive_geofilemaker(): | ||
|
||
# Get working directory and package directory | ||
static_path = pkg_resources.resource_filename(__name__, 'static') | ||
index_path = pkg_resources.resource_filename(__name__, 'static/index.html') | ||
|
||
eel.init(static_path) | ||
eel.expose(get_wkdir) | ||
eel.expose(create_incfiles) | ||
eel.start(index_path) |
Oops, something went wrong.