-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmake_load_charts.py
More file actions
322 lines (231 loc) · 12.3 KB
/
Copy pathmake_load_charts.py
File metadata and controls
322 lines (231 loc) · 12.3 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
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
import plotly
import plotly.graph_objs as go
import pandas as pd
import json
import numpy as np
from time import time
from datetime import datetime, timedelta
def get_average_annual_profile(load, load_filtered, series_name):
Xaxis = "Time"
Yaxis = "Average Load (kW)"
layout = go.Layout(xaxis=dict(showgrid=False, title=Xaxis,title_font=dict(size=12),tickfont=dict(size=12)),
yaxis=dict(showgrid=False, title=Yaxis,rangemode='tozero',title_font=dict(size=12),tickfont=dict(size=12)),
showlegend=True)
if len(series_name) == 1:
### load mean
load2 = load.copy()
load_mean = load2.mean(axis=1)
trace1 = go.Scattergl(x=load_mean.index, y=load_mean.values, name=series_name[0])
### no load_filtered data
data = {'data':[trace1],'layout':layout}
return data
else:
if load_filtered.shape[1] < 1:
data = {'data':[],'layout':layout}
return data
else:
### load mean
load2 = load.copy()
load_mean = load2.mean(axis=1)
trace1 = go.Scattergl(x=load_mean.index, y=load_mean.values, name=series_name[0])
load_filtered2 = load_filtered.copy()
load_filtered_mean = load_filtered2.mean(axis=1)
trace2 = go.Scattergl(x=load_filtered_mean.index, y=load_filtered_mean.values, name=series_name[1])
data = {'data': [trace1, trace2], 'layout': layout}
return data
def get_daily_kWh_hist(load, load_filtered, series_name):
Xaxis = "Daily Electricity (kWh)"
Yaxis = "Percentage"
layout = go.Layout(xaxis=dict(showgrid=False, title=Xaxis,title_font=dict(size=12),tickfont=dict(size=12)),
yaxis=dict(showgrid=False, title=Yaxis,rangemode='tozero',title_font=dict(size=12),tickfont=dict(size=12)),
showlegend=True)
if len(series_name)==1:
load2 = load.copy()
load_sum = load2.sum(axis=0)/2/365
# no filtered data
trace1 = go.Histogram(x=list(load_sum),histnorm='probability',name=series_name[0], xbins=dict(
start=min(load_sum),
end=max(load_sum),
size=(max(load_sum)-min(load_sum))/50))
data ={'data': [trace1], 'layout':layout}
return data
else:
if load_filtered.shape[1] < 1:
data ={'data': [], 'layout':layout}
return data
else:
load2 = load.copy()
load_sum = load2.sum(axis=0)/2/365
load_filtered2 = load_filtered.copy()
load_filtered_sum = load_filtered2.sum(axis=0)/2/365
trace1 = go.Histogram(x=list(load_sum),histnorm='probability',name=series_name[0])
trace2 = go.Histogram(x=list(load_filtered_sum),histnorm='probability',name=series_name[1])
data ={'data': [trace1, trace2], 'layout':layout}
return data
def get_daily_average_profile(x):
x_array = np.array(x).reshape((-1,48))
return np.nanmean(x_array,axis=0)
def get_daily_profiles(load):
Xaxis = "Time"
Yaxis = "Average Load (kW)"
layout = go.Layout(xaxis=dict(showgrid=False, title=Xaxis,title_font=dict(size=12),tickfont=dict(size=12),
tickmode = 'array',
tickvals = [2, 6, 10, 14, 18, 22, 26, 30, 34, 38, 42, 46],
ticktext = ['01:00', '03:00', '05:00', '07:00', '09:00', '11:00','13:00','15:00','17:00','19:00','21:00','23:00']),
yaxis=dict(showgrid=False, title=Yaxis,rangemode='tozero',title_font=dict(size=12),tickfont=dict(size=12)),
showlegend=True)
if load.shape[1] < 1:
data ={'data': [], 'layout':layout}
return data
else:
load2=load.copy()
load_daily_average = load2.apply(get_daily_average_profile)
trace_list = []
for i in range(load_daily_average.shape[1]):
trace = go.Scatter(x=list(range(0,48)), y=list(load_daily_average.iloc[:,i]), name = load_daily_average.columns[i])
trace_list.append(trace)
data ={'data': trace_list, 'layout':layout}
return data
def get_daily_profile_interquartile(load):
Xaxis = "Time"
Yaxis = "Load (kW)"
layout = go.Layout(xaxis=dict(showgrid=False, title=Xaxis,title_font=dict(size=12),tickfont=dict(size=12),
tickmode = 'array',
tickvals = [2, 6, 10, 14, 18, 22, 26, 30, 34, 38, 42, 46],
ticktext = ['01:00', '03:00', '05:00', '07:00', '09:00', '11:00','13:00','15:00','17:00','19:00','21:00','23:00']),
yaxis=dict(showgrid=False, title=Yaxis,rangemode='tozero',title_font=dict(size=12),tickfont=dict(size=12)),
showlegend=True)
if load.shape[1] < 1:
data ={'data': [], 'layout':layout}
return data
else:
load2=load.copy()
load_daily_average = load2.apply(get_daily_average_profile)
qr1 = np.nanpercentile(np.array(load_daily_average), 75, interpolation='midpoint',axis=1)
qr2 = np.nanpercentile(np.array(load_daily_average), 50, interpolation='midpoint',axis=1)
qr3 = np.nanpercentile(np.array(load_daily_average), 25, interpolation='midpoint',axis=1)
trace1 = go.Scatter(x=list(range(0,48)),y=list(qr3),fill=None, name = '25%')
trace2 = go.Scatter(x=list(range(0,48)),y=list(qr2),fill='tonexty', name = '50%')
trace3 = go.Scatter(x=list(range(0,48)),y=list(qr1),fill='tonexty', name = '75%')
data ={'data': [trace1, trace2, trace3], 'layout':layout}
return data
def get_average_load_duration_curve(load):
Xaxis = "Time"
Yaxis = "Load (kW)"
layout = go.Layout(xaxis=dict(showgrid=False, title=Xaxis,title_font=dict(size=12),tickfont=dict(size=12)),
yaxis=dict(showgrid=False, title=Yaxis,rangemode='tozero',title_font=dict(size=12),tickfont=dict(size=12)),
showlegend=False)
if load.shape[1] < 1:
data = {'data': [], 'layout':layout}
return data
else:
load2=load.copy()
load_average = load2.mean(axis=1)
load_average_sort = load_average.sort_values(ascending = False, inplace = False, na_position ='last')
load_average_sort = load_average_sort.reset_index(drop = True)
trace = go.Scatter(x=load_average_sort.index,y=load_average_sort.values)
data = {'data': [trace], 'layout':layout}
return data
def get_average_peak_day_profile(load):
Xaxis = "Time"
Yaxis = "Load (kW)"
layout = go.Layout(xaxis=dict(showgrid=False, title=Xaxis,title_font=dict(size=12),tickfont=dict(size=12)),
yaxis=dict(showgrid=False, title=Yaxis,rangemode='tozero',title_font=dict(size=12),tickfont=dict(size=12)),
showlegend=False)
if load.shape[1] < 1:
data = {'data': [], 'layout':layout}
return data
else:
load2=load.copy()
load_average = load2.mean(axis=1)
# organise data
load_average = pd.DataFrame(load_average)
load_average.columns = ['power']
# find the max day
peak_day_index = load_average['power'].idxmax()
peak_day = pd.to_datetime(peak_day_index, format='%Y-%m-%d')
peak_day_string = peak_day.strftime("%Y-%m-%d")
# filter for the peak day
load_average_peak_day = load_average.loc[peak_day_string]
trace = go.Scatter(x=load_average_peak_day.index,y=list(load_average_peak_day['power']))
data = {'data': [trace], 'layout':layout}
return data
def get_monthly_average_kWh(load):
Xaxis = "Month"
Yaxis = "Average Daily Consumption (kWh)"
layout = go.Layout(xaxis=dict(showgrid=False, title=Xaxis,title_font=dict(size=12),tickfont=dict(size=12)),
yaxis=dict(showgrid=False, title=Yaxis,rangemode='tozero',title_font=dict(size=12),tickfont=dict(size=12)),
showlegend=False)
if load.shape[1] < 1:
data = {'data': [], 'layout':layout}
return data
else:
load2=load.copy()
load_average = load2.mean(axis=1)
# find mean for each month
monthly_mean = load_average.resample('M').mean()
monthly_mean = monthly_mean * 48
month_name = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']
trace = go.Bar(x=month_name,y=monthly_mean.values)
data = {'data': [trace], 'layout':layout}
return data
def get_seasonal_daily_pattern(load):
Xaxis = "Time"
Yaxis = "Load (kW)"
layout = go.Layout(xaxis=dict(showgrid=False, title=Xaxis,title_font=dict(size=12),tickfont=dict(size=12),
tickmode = 'array',
tickvals = [2, 6, 10, 14, 18, 22, 26, 30, 34, 38, 42, 46],
ticktext = ['01:00', '03:00', '05:00', '07:00', '09:00', '11:00','13:00','15:00','17:00','19:00','21:00','23:00']),
yaxis=dict(showgrid=False, title=Yaxis,rangemode='tozero',title_font=dict(size=12),tickfont=dict(size=12)),
showlegend=True)
if load.shape[1] < 1:
data = {'data': [], 'layout':layout}
return data
else:
load2=load.copy()
load_average = load2.mean(axis=1)
# organise data
load_average = pd.DataFrame(load_average)
load_average.columns = ['power']
load_average['Date'] = load_average.index
load_average['Month_Number'] = load_average['Date'].dt.month
# summer
#load_summer = load_average[load_average['Month_Number'] == 1 or load_average['Month_Number'] == 11 or load_average['Month_Number'] == 12]
load_summer = load_average[load_average['Month_Number'].isin([1,11,12])]
load_summer_reshape = np.array(load_summer['power']).reshape(-1,48)
load_summer_daily = np.nanmean(load_summer_reshape,axis=0)
trace1 = go.Scatter(x=list(range(0,48)), y=load_summer_daily, name= 'Summer', mode='lines')
# winter
load_winter = load_average[load_average['Month_Number'].isin([6,7,8])]
load_winter_reshape = np.array(load_winter['power']).reshape(-1,48)
load_winter_daily = np.nanmean(load_winter_reshape,axis=0)
trace2 = go.Scatter(x=list(range(0,48)), y=load_winter_daily, name= 'Winter', mode='lines')
data = {'data': [trace1, trace2], 'layout':layout}
return data
def get_annual_average_energy_flow_profile(energy_profiles):
load_profiles = energy_profiles['load_profiles'].mean(axis=1)
solar_profiles = energy_profiles['solar_profiles'].mean(axis=1)
dr_profiles = energy_profiles['dr_profiles'].mean(axis=1)
battery_profiles = energy_profiles['battery_profiles'].mean(axis=1)
final_net_profiles = energy_profiles['final_net_profiles'].mean(axis=1)
Xaxis = "Time"
Yaxis = "Average Load (kW)"
layout = go.Layout(xaxis=dict(title=Xaxis, title_font=dict(size=12), tickfont=dict(size=12)),
yaxis=dict(title=Yaxis, title_font=dict(size=12), tickfont=dict(size=12)),
showlegend=True)
trace1 = go.Scatter(x=load_profiles.index, y=load_profiles.values , name='load profile', fill='tozeroy')
trace2 = go.Scatter(x=solar_profiles.index, y=solar_profiles.values, name='solar profile', fill='tozeroy')
trace3 = go.Scatter(x=dr_profiles.index, y=dr_profiles.values, name='demand response profile', fill='tozeroy')
trace4 = go.Scatter(x=battery_profiles.index, y=battery_profiles.values, name='battery profile', fill='tozeroy')
trace5 = go.Scatter(x=final_net_profiles.index, y=final_net_profiles.values, name='net profile')
data = {'data': [trace1, trace2, trace3, trace4, trace5], 'layout': layout}
return data
chart_methods = {'Annual Average Profile': get_average_annual_profile,
'Daily kWh Histogram': get_daily_kWh_hist,
'Daily Profiles': get_daily_profiles,
'Daily Profile Interquartile Range': get_daily_profile_interquartile,
'Average Load Duration Curve': get_average_load_duration_curve,
'Average Peak Day Profile': get_average_peak_day_profile,
'Monthly Average kWh': get_monthly_average_kWh,
'Seasonal Daily Pattern': get_seasonal_daily_pattern,
'Annual Average Energy Flow Profile': get_annual_average_energy_flow_profile}