-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathgenerate_models.py
More file actions
87 lines (68 loc) · 2.55 KB
/
generate_models.py
File metadata and controls
87 lines (68 loc) · 2.55 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import os
import shutil
from pathlib import Path
import pandas as pd
from tomlkit import dumps, parse
from muse import examples
from muse.wizard import add_timeslice, modify_toml
parent_path = Path(__file__).parent
def generate_model_1():
"""Generates first model for tutorial 4.
Adds two new timeslices to the model.
"""
model_name = "1-modify-timeslices"
model_path = parent_path / model_name
if model_path.exists():
shutil.rmtree(model_path)
# Starting point: copy default model
examples.copy_model(name="default", path=parent_path, overwrite=True)
os.rename(parent_path / "model", model_path)
# Add timeslices
add_timeslice(model_path, timeslice_name="early-morning", copy_from="evening")
add_timeslice(model_path, timeslice_name="late-afternoon", copy_from="evening")
# Modify timeslices
settings_file = model_path / "settings.toml"
settings = parse(settings_file.read_text())
timeslices = settings["timeslices"]["all-year"]["all-week"]
for key in timeslices:
timeslices[key] = 1095
settings["timeslices"]["all-year"]["all-week"] = {
key if key != "afternoon" else "mid-afternoon": value
for key, value in timeslices.items()
} # hacky way to preserve the order
settings_file.write_text(dumps(settings))
# Change consumption profile
consumption_values = [
0.7,
1.0,
0.7,
1.0,
2.1,
1.4,
1.4,
1.4,
]
for year, multiplier in zip([2020, 2050], [1, 3]):
file = model_path / f"technodata/preset/Residential{year}Consumption.csv"
df = pd.read_csv(file)
df["heat"] = [round(i * multiplier, 1) for i in consumption_values]
df.to_csv(file, index=False)
def generate_model_2():
"""Generates the second model for tutorial 4.
Modifies the time framework of the model to every two years.
"""
model_name = "2-modify-time-framework"
model_path = parent_path / model_name
if model_path.exists():
shutil.rmtree(model_path)
# Starting point: copy previous model
shutil.copytree(parent_path / "1-modify-timeslices", model_path)
if (model_path / "Results").exists():
shutil.rmtree(model_path / "Results")
# Modify time framework
settings_file = model_path / "settings.toml"
time_framework = [2020, 2022, 2024, 2026, 2028, 2030, 2032, 2034, 2036, 2038, 2040]
modify_toml(settings_file, lambda x: x.update({"time_framework": time_framework}))
if __name__ == "__main__":
generate_model_1()
generate_model_2()