-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmo_vis.py
199 lines (158 loc) · 10 KB
/
mo_vis.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
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
import pandas as pd
import mopy as mo
import matplotlib.pyplot as plt
import numpy as np
# bar_colour = ["b", "g", "k", "m", "c", "r", "pink", "orange", "yellow"]
#
# # heat
heat_in = ["heat_pump", "heat_boiler_oil", "heat_boiler_gas", "heat_discharging"]
heat_out = ["heat_demand", "heat_charging"]
#
#
# # only ch and di
# heat_in = ["heat_discharging"]
# heat_out = ["heat_charging"]
#
# heat_colour = ["b-", "g--", "k:", "m+", "c--", "r:"]
#
# # hydrogen
hydrogen_in = ["electrolyser", "steam_reforming", "hydrogen_discharging"]
hydrogen_out = ["hydrogen_demand", "hydrogen_charging", "hydrogen_fuel_cell"]
# only ch and di
# hydrogen_in = ["hydrogen_discharging"]
# hydrogen_out = ["hydrogen_charging"]
# hydrogen_colour = ["b-", "g--", "k:", "m-", "c--", "r:"]
#
# # electricity
electricity_out = ['heat_pump', 'electrolyser', "", "electricity_demand", "battery_charging", "hydro_charging"]
electricity_in = ['biomass', 'hydropower', 'solar', 'wind_offshore', 'wind_onshore', 'lignite_coal', 'hard_coal', 'natural_gas', "oil", "battery_discharging", "hydro_discharging", "hydrogen_fuel_cell"]
colour_list = ["black", "gray", "darkgrey", "silver","red", "green", "blue", "sienna", "orchid", "fuchsia", "salmon", "tomato", "peru", "khaki", "plum", "purple", "violet", "pink", "yellow"]
# only ch and di
# electricity_in = ["hydro_discharging"]
# electricity_out = ["hydro_charging"]
# electricity_in = ["battery_discharging"]
# electricity_out = ["battery_charging"]
# electricity_colour = ["b-", "g--", "k:", "+m", "--c", ":r"]
opt_file = ['solar', 'wind_offshore', 'wind_onshore', 'steam_reforming', 'support_gen_ele', 'electrolyser', 'heat_pump', 'battery_storage', 'hydro_storage', 'hydrogen_storage', 'heat_storage', 'battery_charging', 'battery_discharging', 'hydro_charging', 'hydro_discharging', 'hydrogen_charging', 'hydrogen_discharging', 'heat_charging', 'heat_discharging']
def cum_sum_file(df, e_list):
df_new = pd.DataFrame()
for m in e_list:
if m in df.columns:
df_new = mo.hor(df_new, df.loc[:, m])
df_new = df_new.cumsum(axis=1)
return df_new
def file_hourly(in_folder_path, energy_file, e_list_in, e_list_out, out_file_name, out_folder_path, ele=False, time_step=False, time_slot=pd.date_range("2030-06-01", freq="H", periods=24, tz='Europe/Berlin')):
c = 0
df = pd.read_csv(mo.path.join(in_folder_path, energy_file), index_col="name", parse_dates=True)
df_in = cum_sum_file(df, e_list_in)
df_out = cum_sum_file(df, e_list_out)
if time_step:
for i in df_in.columns:
if ele:
plt.plot(time_slot, df_in.loc[time_slot, i], label=i)
else:
plt.plot(time_slot, df_in.loc[time_slot, i], heat_colour[c], label=i)
c = c+1
for j in df_out.columns:
if ele:
plt.plot(time_slot, df_out.loc[time_slot, j], label=j)
else:
plt.plot(time_slot, df_out.loc[time_slot, j], heat_colour[c], label=j)
c = c+1
else:
for i in df_in.columns:
if ele:
plt.plot(df_in.index, df_in.loc[:, i], label=i)
else:
plt.plot(df_in.index, df_in.loc[:, i], heat_colour[c], label=i)
c = c+1
for j in df_out.columns:
if ele:
plt.plot(df_out.index, df_out.loc[:, j], label=j)
else:
plt.plot(df_out.index, df_out.loc[:, j], heat_colour[c], label=j)
c = c+1
plt.title(out_file_name)
plt.xlabel("time in hours")
plt.ylabel("energy in MWh")
plt.legend(fontsize="x-small")
plt.savefig(mo.path.join(out_folder_path, out_file_name + ".png"), dpi=600)
plt.clf()
# return
def cum_sum_file_total(df, e_list):
df_new = pd.DataFrame(index=df.columns)
for m in e_list:
if m in df.index:
df_new = mo.hor(df_new, df.loc[m, :])
return df_new
def file_total(in_folder_path, energy_file_name, e_list_in, e_list_out, out_file_name, out_folder_path, ele=False):
df = pd.read_csv(mo.path.join(in_folder_path, energy_file_name), index_col=0)
c = 0
df_in = cum_sum_file_total(df, e_list_in)
df_out = cum_sum_file_total(df, e_list_out)
X = np.arange(len(df_in.index))
# lab = [df_in.columns[0]]
plt.bar(X - 0.15, df_in.loc[:, df_in.columns[0]], width=.25, label=df_in.columns[0])
for i in range(1, len(df_in.columns)):
c = c+1
plt.bar(X - 0.15, df_in.loc[:, df_in.columns[i]], color=colour_list[c], width=.25, bottom=(df_in.loc[:, df_in.columns[:i]]).sum(axis=1), label=df_in.columns[i])
# lab.append(df_in.columns[i])
X = np.arange(len(df_out.index))
# lab = lab.append(df_out.columns[0])
c = c+1
plt.bar(X + 0.15, abs(df_out.loc[:, df_out.columns[0]]), width=.25, label=df_out.columns[0])
for i in range(1, len(df_out.columns)):
c = c+1
plt.bar(X + 0.15, abs(abs(df_out.loc[:, df_out.columns[i]])), width=.25, bottom=abs((df_out.loc[:, df_out.columns[:i]]).sum(axis=1)), label=df_out.columns[i])
# lab.append(df_out.columns[i])
plt.title(out_file_name)
plt.xlabel("CO2 limit in Mtons")
plt.ylabel("annual energy in MWh")
plt.xticks(np.arange(len(df_in.index)), df_in.index, rotation="vertical")
plt.legend(fontsize="xx-small")
plt.savefig(mo.path.join(out_folder_path, out_file_name + ".png"), dpi=600)
plt.clf()
# return
def vis(data_folder_name, line=False):
if line:
if mo.path.isdir(mo.path.join(mo.output_path, data_folder_name)):
if not mo.path.isdir(mo.path.join(mo.output_path, data_folder_name, "results", "electricity_bus")):
mo.mkdir(mo.path.join(mo.output_path, data_folder_name, "results", "electricity_bus"))
if not mo.path.isdir(mo.path.join(mo.output_path, data_folder_name, "results", "hydrogen_bus")):
mo.mkdir(mo.path.join(mo.output_path, data_folder_name, "results", "hydrogen_bus"))
if not mo.path.isdir(mo.path.join(mo.output_path, data_folder_name, "results", "heat_bus")):
mo.mkdir(mo.path.join(mo.output_path, data_folder_name, "results", "heat_bus"))
# Ch and Di
if mo.path.isdir(mo.path.join(mo.output_path, data_folder_name)):
if not mo.path.isdir(mo.path.join(mo.output_path, data_folder_name, "results", "electricity_hydro_store")):
mo.mkdir(mo.path.join(mo.output_path, data_folder_name, "results", "electricity_hydro_store"))
if not mo.path.isdir(mo.path.join(mo.output_path, data_folder_name, "results", "hydrogen_store")):
mo.mkdir(mo.path.join(mo.output_path, data_folder_name, "results", "hydrogen_store"))
if not mo.path.isdir(mo.path.join(mo.output_path, data_folder_name, "results", "heat_store")):
mo.mkdir(mo.path.join(mo.output_path, data_folder_name, "results", "heat_store"))
# if not mo.path.isdir(mo.path.join(mo.output_path, data_folder_name, "results", "electricity_one_day")):
# mo.mkdir(mo.path.join(mo.output_path, data_folder_name, "results", "electricity_one_day"))
# if not mo.path.isdir(mo.path.join(mo.output_path, data_folder_name, "results", "hydrogen_one_day")):
# mo.mkdir(mo.path.join(mo.output_path, data_folder_name, "results", "hydrogen_one_day"))
# if not mo.path.isdir(mo.path.join(mo.output_path, data_folder_name, "results", "heat_one_day")):
# mo.mkdir(mo.path.join(mo.output_path, data_folder_name, "results", "heat_one_day"))
folder_list = mo.listdir(mo.path.join(mo.output_path, data_folder_name))
folder_list.remove("results")
for folder in folder_list:
result_files_folder_path = mo.path.join(mo.path.join(mo.output_path, data_folder_name), folder, "results")
file_hourly(result_files_folder_path, "electricity.csv", electricity_in, electricity_out, folder + "_electricity_bus", mo.path.join(mo.output_path, data_folder_name, "results", "electricity_hydro_store"), ele=True)
file_hourly(result_files_folder_path, "heat.csv", heat_in, heat_out, folder + "_heat_bus", mo.path.join(mo.output_path, data_folder_name, "results", "hydrogen_store"))
file_hourly(result_files_folder_path, "hydrogen.csv", hydrogen_in, hydrogen_out, folder + "_hydrogen_bus", mo.path.join(mo.output_path, data_folder_name, "results", "heat_store"))
# entire year
# file_hourly(result_files_folder_path, "electricity.csv", electricity_in, electricity_out, folder + "_electricity_bus", mo.path.join(mo.output_path, data_folder_name, "results", "electricity_one_day"), ele=True)
# file_hourly(result_files_folder_path, "heat.csv", heat_in, heat_out, folder + "_heat_bus", mo.path.join(mo.output_path, data_folder_name, "results", "heat_one_day"))
# file_hourly(result_files_folder_path, "hydrogen.csv", hydrogen_in, hydrogen_out, folder + "_hydrogen_bus", mo.path.join(mo.output_path, data_folder_name, "results", "hydrogen_one_day"))
# one day
# file_hourly(result_files_folder_path, "electricity.csv", electricity_in, electricity_out, folder + "_electricity", mo.path.join(mo.output_path, data_folder_name, "results", "electricity_bus"), ele=True, time_step=True, time_slot=pd.date_range("2030-06-01", freq="H", periods=24, tz='Europe/Berlin'))
# file_hourly(result_files_folder_path, "heat.csv", heat_in, heat_out, folder + "_heat", mo.path.join(mo.output_path, data_folder_name, "results", "heat_bus"), time_step=True, time_slot=pd.date_range("2030-06-01", freq="H", periods=24, tz='Europe/Berlin'))
file_hourly(result_files_folder_path, "hydrogen.csv", hydrogen_in, hydrogen_out, folder + "_hydrogen", mo.path.join(mo.output_path, data_folder_name, "results", "hydrogen_bus"), time_step=True, time_slot=pd.date_range("2030-06-01", freq="H", periods=24, tz='Europe/Berlin'))
else:
print("Error!!! output folder path dose not exits")
return
if __name__ == "__main__":
# vis("fi_3.0", line=True)