forked from quintel/scenario-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scenario_from_csv.py
62 lines (44 loc) · 1.95 KB
/
scenario_from_csv.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# external modules
import sys
# project modules
from helpers.ETM_API import ETM_API, SessionWithUrlBase
from helpers.Scenario import ScenarioCollection
from helpers.Curves import load_curve_file_dict
from helpers.helpers import process_arguments, print_bold
from helpers.file_helpers import query_list, data_download_dict, write_csv
if __name__ == "__main__":
base_url, model_url, query_only_mode = process_arguments(sys.argv)
session = SessionWithUrlBase(base_url)
print("Opening CSV files:")
scenarios = ScenarioCollection.from_csv()
if query_only_mode:
scenarios.filter_query_only()
else:
curve_file_dict = load_curve_file_dict(scenarios)
scenarios.add_settings()
query_list = query_list()
data_download_dict = data_download_dict()
print(f"\nProcessing {len(scenarios)} scenarios..")
if query_only_mode:
print_bold("\n'Query-only' mode is enabled. Only scenario "
"outcomes will be collected, no changes to scenarios will "
"be made.")
for scenario in scenarios:
print(f"\nProcessing scenario {scenario.short_name}..")
API_scenario = ETM_API(session, scenario)
# Do this in the loop to save memory
if scenario.heat_demand: scenario.set_heat_demand_curves()
if not query_only_mode:
API_scenario.update(curve_file_dict)
if query_list:
print(' Getting queries')
API_scenario.query(query_list)
if data_download_dict:
print(' Getting downloads')
for name, download in API_scenario.get_data_downloads(data_download_dict):
write_csv(download, f'{scenario.short_name}_{name}', folder=scenario.short_name,
index=False, header=True)
scenarios.export_scenario_outcomes()
scenarios.export_ids()
print("\n\nAll done! Open the scenarios in the Energy Transition Model:")
scenarios.print_urls(model_url)