Skip to content

Commit 8e02ed2

Browse files
merge TrustParetoFront to master.
Changed the technology definition to be closer to HSLU database; Now also able to generate calliope config file from settings.yml and excel.
1 parent c5956d9 commit 8e02ed2

16 files changed

+1736
-131
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,4 @@ dmypy.json
132132
# Pyre type checker
133133
.pyre/
134134
*.iml
135+
.vscode/

.vscode/settings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@
3232
{
3333
"name": "fastapi",
3434
"depth": 2
35-
}
35+
},
3636
{
3737
"name": "cea",
3838
"depth": 4
39-
}
39+
},
4040
{
4141
"name": "pandas",
4242
"depth": 4

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ Currently, this line of code will automatically downgrade pandas to 1.5.3, along
4343

4444
Then, one need to register this plugin in cea-config. In the CEA console, enter the following command to enable the plugin in CEA:
4545
```python
46-
cea-config write --general:plugins cea_energy_hub_optimizer.energy_hub_optimizer.EnergyHubOptimizer
46+
cea-config write --general:plugins cea_energy_hub_optimizer.energy_hub_optimizer.EnergyHubOptimizer --general:plugins cea_energy_hub_optimizer.calliope_config_constructor.CalliopeConfigConstructor
4747
```
4848
Note that this line will overwrite other existing plugins. If you have other plugins installed, you can add them to the list by separating them with commas. For example:
4949
```python
50-
cea-config write --general:plugins cea_energy_hub_optimizer.energy_hub_optimizer.EnergyHubOptimizer, --general:plugins other_plugin, --general:plugins another_plugin
50+
cea-config write --general:plugins cea_energy_hub_optimizer.energy_hub_optimizer.EnergyHubOptimizer --general:plugins cea_energy_hub_optimizer.calliope_config_constructor.CalliopeConfigConstructor --general:plugins other_plugin --general:plugins another_plugin
5151
```
5252
You should include **ALL the plugins** in that command, otherwise you may lose already installed plugins.
5353

@@ -80,6 +80,13 @@ In the techs_energy_hub.yml file, one can see that there are three different kin
8080

8181
Therefore, three different hypothetical linear DH technologies are set, as shown in the image above. The small one has `energy_cap_min=50` and `energy_cap_max=100`, middle `energy_cap_min=100` and `energy_cap_max=700` and large `energy_cap_min=700` and `energy_cap_max=2000`. The slope of this line is set as `energy_cap` in CHF/kW, and the intercept is set as `purchase` in CHF. Note that each technology must have the same CAPEX on their interceptions (100, 700 and 2000kW) to make sure that both technologies are indifferent to this capacity.
8282

83+
## Uninstall
84+
To uninstall **all** plugins, simply paste the following command:
85+
```
86+
cea-config write --general:plugins ""
87+
```
88+
This will overwrite the plugins in cea config file.
89+
8390
## Development
8491
To enable auto-completion for both CEA's native methods and the venv that CEA uses, one need to do two things in VSCode:
8592
1. Add the following lines to the settings.json file (change the path to the path of your CEA **repository**):
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
"""
2+
construct the calliope config yaml file from the settings.yml file and the technology definition excel file.
3+
"""
4+
5+
from __future__ import division
6+
from __future__ import print_function
7+
import cea.config
8+
import cea.inputlocator
9+
import cea.plugin
10+
import os
11+
import yaml
12+
from cea_energy_hub_optimizer.tech_from_excel import *
13+
14+
15+
__author__ = "Yiqiao Wang"
16+
__copyright__ = "Copyright 2024, Yiqiao Wang"
17+
__credits__ = ["Yiqiao Wang"]
18+
__license__ = "MIT"
19+
__version__ = "1.0.0"
20+
__maintainer__ = "Yiqiao Wang"
21+
22+
__status__ = "Production"
23+
24+
25+
class CalliopeConfigConstructor(cea.plugin.CeaPlugin):
26+
"""
27+
Define the plugin class - unless you want to customize the behavior, you only really need to declare the class. The
28+
rest of the information will be picked up from ``default.config``, ``schemas.yml`` and ``scripts.yml`` by default.
29+
"""
30+
31+
pass
32+
33+
34+
def main(config: cea.config.Configuration) -> None:
35+
# read yaml file from /data/settings.yml and create a nested dictionary
36+
# my_config = MyConfig(config)
37+
with open(
38+
os.path.join(os.path.dirname(__file__), "data", "settings.yml"), "r"
39+
) as file:
40+
calliope_config: dict = yaml.safe_load(file)
41+
if config.calliope_config_constructor.technology_excel_file == "":
42+
tech_excel_path = os.path.join(
43+
os.path.dirname(__file__), "data", "example_techDefinition.xlsx"
44+
)
45+
else:
46+
# check if the path belongs to a .xlsx file
47+
if config.calliope_config_constructor.technology_excel_file[-5:] != ".xlsx":
48+
raise ValueError(
49+
"The technology definition file must be a .xlsx file. Please provide a valid .xlsx file."
50+
)
51+
tech_excel_path = config.calliope_config_constructor.technology_excel_file
52+
techs_subdict = read_tech_definition(filepath=tech_excel_path)
53+
calliope_config["techs"].update(techs_subdict)
54+
55+
store_path = config.calliope_config_constructor.yaml_storage_path
56+
if store_path == "":
57+
store_path = os.path.join(os.path.dirname(__file__), "data")
58+
if not os.path.isdir(store_path):
59+
raise ValueError("Please provide a valid folder path.")
60+
yaml_file_name = config.calliope_config_constructor.yaml_file_name
61+
if yaml_file_name == "":
62+
yaml_file_name = "energy_hub_config"
63+
yaml_file_name += ".yml"
64+
yaml_file_path = os.path.join(store_path, yaml_file_name)
65+
with open(yaml_file_path, "w") as file:
66+
yaml.dump(calliope_config, file)
67+
68+
print(f"Yaml file is saved at {yaml_file_path}.")
69+
70+
71+
if __name__ == "__main__":
72+
main(cea.config.Configuration())

0 commit comments

Comments
 (0)