-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot_today.py
114 lines (75 loc) · 2.93 KB
/
plot_today.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
## Copyright 2024 Tom Brown
## This program is free software; you can redistribute it and/or
## modify it under the terms of the GNU Affero General Public License as
## published by the Free Software Foundation; either version 3 of the
## License, or (at your option) any later version.
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU Affero General Public License for more details.
## License and more information at:
## https://github.com/PyPSA/nowcast
import pandas as pd, yaml, os
from helpers import get_last_days
from plot_networks import rename
import matplotlib.pyplot as plt
plt.style.use('ggplot')
def concatenate_data(date_strings, ct):
for i,date_string in enumerate(date_strings):
weather_fn = f"{config['weather_dir']}/{ct}-day-{date_string}-corrected.csv"
df = pd.read_csv(weather_fn,
parse_dates=True,
index_col=0)
if i == 0:
full = df
else:
full = pd.concat([full,df])
return full
#modelled on plot_networks.plot_supply()
def plot(config):
date_strings = get_last_days(config).astype(str)
ct = config["countries"][0]
df = concatenate_data(date_strings, ct)
fig, ax = plt.subplots()
fig.set_size_inches((10, 2))
tz = config["time_zone"][ct]
color = config["color"]
supply = df/1e3
supply.columns = supply.columns.str[3:]
supply.rename(rename,
axis=1,
inplace=True)
print(supply)
supply.index = supply.index.tz_convert(tz)
supply["other"] = supply["today's demand"] - supply[map(rename,config["vre_techs"])].sum(axis=1)
load = supply["today's demand"]
supply.drop(["today's demand"],axis=1,inplace=True)
supply = supply.where(supply >= 0, 0)
supply.plot.area(stacked=True,linewidth=0,color=color,ax=ax)
load.plot(linewidth=2, color="k")
ax.set_ylabel("power [GW]")
ax.set_ylim([0,120])
ax.set_xlabel("")
ax.set_title("")
handles, labels = ax.get_legend_handles_labels()
ax.legend(reversed(handles),
reversed(labels),
loc="upper left",
fontsize=7)
graphic_fn = f"{config['results_dir']}/today/{ct}-days-{date_strings[0]}-{date_strings[-1]}-today"
supply.to_csv(f"{graphic_fn}.csv")
fig.savefig(f"{graphic_fn}.pdf",
transparent=True,
bbox_inches='tight')
fig.savefig(f"{graphic_fn}.png",
dpi=200,
transparent=True,
bbox_inches='tight')
plt.close(fig)
if __name__ == "__main__":
with open('config.yaml', 'r') as file:
config = yaml.safe_load(file)
results_dir = f"{config['results_dir']}/today"
if not os.path.isdir(results_dir):
os.mkdir(results_dir)
df = plot(config)