-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotting_utils.py
More file actions
102 lines (85 loc) · 3.66 KB
/
plotting_utils.py
File metadata and controls
102 lines (85 loc) · 3.66 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
"""
Plotting utilities for OpenDSS analysis
"""
import os
import numpy as np
import pandas as pd
import matplotlib
from config import MATPLOTLIB_BACKEND, PLOTTING_DAYS, TICK_INCREMENT, VOLTAGE_BINS, HISTOGRAM_COLOR, HISTOGRAM_ALPHA, HISTOGRAM_WIDTH, PERCENTILE_BAR_WIDTH
matplotlib.use(MATPLOTLIB_BACKEND)
import matplotlib.pyplot as plt
def do_plotting(total, res, com, region, substation, feeder, day, output_folder):
"""
Sequential function to plot the com/res/total profiles for each day
over each other
"""
num_days = PLOTTING_DAYS
times = (day*24*4, (day+1)*24*4*num_days) # Now one day - was 1 week
tick_inc = TICK_INCREMENT
if not isinstance(res, pd.core.series.Series):
res = pd.Series([0 for i in range(len(total))])
if not isinstance(com, pd.core.series.Series):
com = pd.Series([0 for i in range(len(total))])
subset = total[times[0]:times[1]]
subset_res = res[times[0]:times[1]]
subset_com = com[times[0]:times[1]]
max_value = max(total)
inc = int(len(subset)/tick_inc)
ticks_pos = [times[0] + inc*i for i in range(tick_inc)]
ticks = [ticks_pos[i]/4 for i in range(tick_inc)]
plt.clf()
## Overlayed load plot ##
f, axarr = plt.subplots(1, sharex=True)
axarr.plot(subset, color='k', label='Total')
axarr.plot(subset_res, color='r', label='Residential')
axarr.plot(subset_com, color='b', label='Commercial')
axarr.set_xticks(ticks_pos)
axarr.set_xticklabels(ticks, rotation=70)
axarr.set_ylabel('kW total')
axarr.set_ylim(0, max_value*1.05)
axarr.set_xlabel('Hour of Year')
plt.title('Timeseries Load for '+ region + ' '+substation+' '+feeder+ ' Day '+str(day+1))
plt.legend()
plt.tight_layout()
plt.savefig(os.path.join(output_folder, f'total_load_{day+1}.png'))
plt.clf()
plt.close(f)
def create_voltage_histogram(dss_vals_avg, global_min, global_max, region, substation, feeder, output_folder):
"""Create voltage histogram plot"""
comparison_ticks = []
comparison_cnt = 0.01
while comparison_cnt < 1.5:
comparison_cnt += 0.005
if comparison_cnt >= global_min-0.01 and comparison_cnt <= global_max + 0.01:
comparison_ticks.append(round(comparison_cnt, 3))
f, axarr = plt.subplots(1, sharex=True)
bins = np.linspace(VOLTAGE_BINS[0], VOLTAGE_BINS[1], VOLTAGE_BINS[2])
axarr.set_title(region+' '+substation+' '+feeder+' OpenDSS p.u. Voltages')
axarr.hist(x=dss_vals_avg, bins=bins, color=HISTOGRAM_COLOR,
alpha=HISTOGRAM_ALPHA, rwidth=HISTOGRAM_WIDTH)
axarr.set_xlim(global_min-0.01, global_max+0.01)
axarr.set_xticks(comparison_ticks)
axarr.set_xticklabels(comparison_ticks, rotation=70)
axarr.set_ylabel('Frequency')
axarr.set_xlabel('p.u. Voltage')
plt.tight_layout()
plt.savefig(os.path.join(output_folder, 'pu_voltages_histogram.png'))
plt.clf()
plt.close(f)
def create_voltage_percentiles(dss_vals_avg, region, substation, feeder, output_folder):
"""Create voltage percentiles plot"""
percentiles = []
for i in range(100):
percentiles.append(np.percentile(dss_vals_avg, i))
plt.bar(range(len(percentiles)), percentiles, width=PERCENTILE_BAR_WIDTH)
max_pct = max(percentiles)
min_pct = min(percentiles)
plt.ylim(min_pct - (max_pct-min_pct)/20, max_pct + (max_pct-min_pct)/20)
plt.grid()
plt.xlabel('Percentile')
plt.ylabel('Value')
plt.title(region+' '+substation+' '+feeder+' All Percentiles')
plt.tight_layout()
plt.savefig(os.path.join(output_folder, "pu_voltages_percentiles.png"))
plt.clf()
plt.close()