-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmod_plot.py
More file actions
166 lines (124 loc) · 5.06 KB
/
mod_plot.py
File metadata and controls
166 lines (124 loc) · 5.06 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
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
import matplotlib.pyplot as plt
import os
import pandas as pd
import numpy as np
class RAPlotTools:
'''Provides plotting tools for visualizing simulation results.'''
def __init__(self, results_subdir):
"""
Initializes the RAPlotTools class and creates a directory for storing results.
"""
self.results_subdir = results_subdir
pass
def PlotSolarGen(self, solar_rec, bus_name, s):
"""
Plots solar power generation over time.
Parameters:
solar_rec (numpy.ndarray): Solar power generation records.
bus_name (list): List of bus names.
"""
plt.title("Solar Power Generation")
plt.xlabel("Hours")
plt.ylabel("Output (MW)")
plt.plot(solar_rec.T, label = bus_name)
plt.legend()
pdf_path = os.path.join(self.results_subdir, f'solar_generation_sample_{s+1}.pdf')
plt.savefig(pdf_path)
plt.close()
def PlotWindGen(self, wind_rec, bus_name, s):
"""
Plots wind power generation over time.
Parameters:
wind_rec (numpy.ndarray): Wind power generation records.
bus_name (list): List of bus names.
"""
plt.title("Wind Power Generation")
plt.xlabel("Hours")
plt.ylabel("Output (MW)")
plt.plot(wind_rec.T, label = bus_name)
plt.legend()
pdf_path = os.path.join(self.results_subdir, f'wind_generation_sample_{s+1}.pdf')
plt.savefig(pdf_path)
plt.close()
def PlotSOC(self, SOC_rec, essname, s):
"""
Plots state of charge (SOC) of energy storage systems (ESS) over time.
Parameters:
SOC_rec (numpy.ndarray): SOC records.
essname (list): List of ESS names.
"""
plt.title("ESS SOC")
plt.xlabel("Hours")
plt.ylabel("SOC (MWh)")
plt.plot(SOC_rec.T, label = essname)
plt.legend(loc = 'upper right')
pdf_path = os.path.join(self.results_subdir, f'SOC_sample_{s+1}.pdf')
plt.savefig(pdf_path)
plt.close()
def PlotLoadCurt(self, curt_rec, s):
"""
Plots load curtailment over time.
Parameters:
curt_rec (numpy.ndarray): Load curtailment records.
"""
plt.title("Load Curtailment")
plt.xlabel("Hours")
plt.ylabel("MW")
plt.plot(curt_rec)
pdf_path = os.path.join(self.results_subdir, f'loadcurt_sample_{s+1}.pdf')
plt.savefig(pdf_path)
plt.close()
def OutageMap(self, outage_data):
"""
Plots a heatmap of outage data.
Parameters:
outage_data (str): Path to the Excel file containing outage data.
"""
outage_data = pd.read_csv(outage_data, header=0, index_col=0).values
y_label = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
x_label = np.arange(1, 25, 1)
heatmap = plt.imshow(outage_data, cmap='Reds', interpolation='nearest')
plt.xticks(range(len(x_label)), x_label, fontsize = 5)
plt.yticks(range(len(y_label)), y_label, fontsize = 6)
plt.xlabel('Hour', fontsize = 8)
plt.title('Outage Heat Map')
for i in range(outage_data.shape[0]):
for j in range(outage_data.shape[1]):
value = outage_data[i, j]
if value > 0.1:
plt.text(j, i, f'{value:.2f}', ha = 'center', va = 'center', color = 'black', fontsize = 3)
cbar = plt.colorbar(heatmap, shrink=0.6)
cbar.set_label('Outage %', rotation=270, labelpad=15, fontsize = 8)
cbar.ax.tick_params(labelsize=5)
pdf_path = os.path.join(self.results_subdir, 'heatmap.pdf')
plt.savefig(pdf_path)
plt.close()
def PlotLOLP(self, mLOLP_rec, samples, size):
plt.plot(np.arange(1, samples+1), mLOLP_rec)
plt.xticks(np.arange(1, samples+1, 1), size*np.arange(1, samples+1, 1))
plt.xlabel('Samples')
plt.ylabel('LOLP')
pdf_path = os.path.join(self.results_subdir, 'LOLP_track.pdf')
plt.savefig(pdf_path)
plt.close()
def PlotCOV(self, COV_rec, samples, size):
plt.plot(np.arange(1, samples+1), COV_rec)
plt.xticks(np.arange(1, samples+1, 1), size*np.arange(1, samples+1, 1))
plt.xlabel('Samples')
plt.ylabel('Coefficient of Variation')
pdf_path = os.path.join(self.results_subdir, 'COV_track.pdf')
plt.savefig(pdf_path)
plt.close()
############ EXTRA VISUALIZATION CODE ######################
# outage_day = var_s["outage_day"]
# month_names = [calendar.month_abbr[i] for i in range(1, 13)]
# tick_positions = np.arange(15, 365, 30)
# plt.bar(np.arange(365), outage_day)
# plt.xticks(tick_positions, month_names, rotation = 45)
# plt.ylabel('Outage Duration (Hours)')
# plt.savefig('outages.pdf')
# N = len(out_durations)
# colors = np.random.rand(N)
# plt.scatter(np.arange(N), out_durations, c = colors, alpha = 0.5)
# plt.savefig('outages.pdf')
# print(out_durations)