-
Notifications
You must be signed in to change notification settings - Fork 2
/
csv-mod.py
233 lines (216 loc) · 5.4 KB
/
csv-mod.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
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
# Script to compute TOU pricing for each time period in a dataset and return a modified dataset.
# Input: CSV file of daily consumption with time/date data as one column
# Output: CSV file of daily consumption with TOU pricing data added
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
# Tariff rate data for TOU-DR1
SUMMER_MONTHS = [6, 7, 8, 9, 10] # June 1 through Oct 31
WINTER_MONTHS = [1, 2, 3, 4, 5, 11, 12] # Nov 1 through May 31th
ON_PEAK = [16, 17, 18, 19, 20] # 4pm - 9pm, same for all days
SUMMER_OFF_PEAK = [
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
21,
22,
23,
] # 6am - 4pm, 9pm - midnight
SUPER_OFF_PEAK = [
0,
1,
2,
3,
4,
5,
] # midnight - 6am, same for all days except in March and April
WINTER_OFF_PEAK = [
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
21,
22,
23,
] # 6am - 4pm, 9pm - midnight
WINTER_OFF_PEAK_MAR_APR = [
6,
7,
8,
9,
14,
15,
21,
22,
23,
] # 6am - 4pm, 9pm - midnight, excluding 10:00 a.m. – 2:00 p.m
WINTER_SUPER_OFF_PEAK_MAR_APR = [
0,
1,
2,
3,
4,
5,
10,
11,
12,
13,
] # midnight - 6am; 10am = 2pm
OFF_PEAK_WEEKEND = [14, 15, 21, 22, 23] # 2pm - 4pm; 9pm - midnight
SUPER_OFF_PEAK_WEEKEND = [
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
] # midnight - 2pm
# since we have 15-minute periods, therefore $/kw-hour must be divided by (15/60) = 4
SUM_ON_PEAK_TOU = 0.50199 / 4
SUM_OFF_PEAK_TOU = 0.30462 / 4
SUM_SUP_OFF_PEAK_TOU = 0.25900 / 4
WIN_ON_PEAK_TOU = 0.35630 / 4
WIN_OFF_PEAK_TOU = 0.34747 / 4
WIN_SUP_OFF_PEAK_TOU = 0.3376 / 4
# df = pd.read_csv('9836.csv')
#
# # drop NaNs (0 in original CSV -- not metered load quantities)
# df.dropna(axis=1, how='all', inplace=True)
#
# # Remove unnecessary voltage data and dataid columns
# df.drop(['dataid', 'leg1v', 'leg2v'], axis=1, inplace=True)
#
# # Create column subtracting out PV output:
# df['gridnopv'] = df['grid'] - df['solar']
# Keep only grid and solar data:
df = pd.read_csv("9836.csv", usecols=["local_15min", "grid", "solar"])
# Create column subtracting out PV output:
df["gridnopv"] = df["grid"] + df["solar"]
# Convert first column to datetime:
df["dt"] = pd.to_datetime(df["local_15min"], format="%m/%d/%Y %H:%M")
# Plot!
fig = plt.figure(figsize=(8, 6), dpi=150)
ax = plt.gca()
# df.plot(kind='line', x='dt', y='grid', ax=ax, xlabel='Date', ylabel='Power, kW')
# df.plot(kind='line', x='dt', y='solar', color='red', ax=ax, xlabel='Date', ylabel='Power, kW')
df.plot(
kind="line",
x="dt",
y="gridnopv",
color="green",
ax=ax,
xlabel="Date",
ylabel="Power, kW",
)
fig.savefig("load_data.png")
df = df.assign(tariff="")
# Summer TOU pricing, weekdays:
df.loc[
df["dt"].dt.month.isin(SUMMER_MONTHS)
& df["dt"].dt.hour.isin(ON_PEAK)
& df["dt"].dt.weekday.isin([1, 2, 3, 4, 5]),
"tariff",
] = SUM_ON_PEAK_TOU
df.loc[
df["dt"].dt.month.isin(SUMMER_MONTHS)
& df["dt"].dt.hour.isin(SUMMER_OFF_PEAK)
& df["dt"].dt.weekday.isin([1, 2, 3, 4, 5]),
"tariff",
] = SUM_OFF_PEAK_TOU
df.loc[
df["dt"].dt.month.isin(SUMMER_MONTHS)
& df["dt"].dt.hour.isin(SUPER_OFF_PEAK)
& df["dt"].dt.weekday.isin([1, 2, 3, 4, 5]),
"tariff",
] = SUM_SUP_OFF_PEAK_TOU
# Winter TOU pricing, weekdays:
df.loc[
df["dt"].dt.month.isin(WINTER_MONTHS)
& df["dt"].dt.hour.isin(ON_PEAK)
& df["dt"].dt.weekday.isin([1, 2, 3, 4, 5]),
"tariff",
] = WIN_ON_PEAK_TOU
df.loc[
df["dt"].dt.month.isin(WINTER_MONTHS)
& df["dt"].dt.hour.isin(WINTER_OFF_PEAK)
& df["dt"].dt.weekday.isin([1, 2, 3, 4, 5]),
"tariff",
] = WIN_OFF_PEAK_TOU
df.loc[
df["dt"].dt.month.isin(WINTER_MONTHS)
& df["dt"].dt.hour.isin(SUPER_OFF_PEAK)
& df["dt"].dt.weekday.isin([1, 2, 3, 4, 5]),
"tariff",
] = WIN_SUP_OFF_PEAK_TOU
# Adjust March and April TOU periods:
df.loc[
df["dt"].dt.month.isin([3, 4])
& df["dt"].dt.hour.isin(WINTER_SUPER_OFF_PEAK_MAR_APR)
& df["dt"].dt.weekday.isin([1, 2, 3, 4, 5]),
"tariff",
] = WIN_SUP_OFF_PEAK_TOU
# Summer TOU pricing, weekends:
df.loc[
df["dt"].dt.month.isin(SUMMER_MONTHS)
& df["dt"].dt.hour.isin(ON_PEAK)
& df["dt"].dt.weekday.isin([0, 6]),
"tariff",
] = SUM_ON_PEAK_TOU
df.loc[
df["dt"].dt.month.isin(SUMMER_MONTHS)
& df["dt"].dt.hour.isin(OFF_PEAK_WEEKEND)
& df["dt"].dt.weekday.isin([0, 6]),
"tariff",
] = SUM_OFF_PEAK_TOU
df.loc[
df["dt"].dt.month.isin(SUMMER_MONTHS)
& df["dt"].dt.hour.isin(SUPER_OFF_PEAK_WEEKEND)
& df["dt"].dt.weekday.isin([0, 6]),
"tariff",
] = SUM_SUP_OFF_PEAK_TOU
# Winter TOU pricing, weekends:
df.loc[
df["dt"].dt.month.isin(WINTER_MONTHS)
& df["dt"].dt.hour.isin(ON_PEAK)
& df["dt"].dt.weekday.isin([0, 6]),
"tariff",
] = WIN_ON_PEAK_TOU
df.loc[
df["dt"].dt.month.isin(WINTER_MONTHS)
& df["dt"].dt.hour.isin(OFF_PEAK_WEEKEND)
& df["dt"].dt.weekday.isin([0, 6]),
"tariff",
] = WIN_OFF_PEAK_TOU
df.loc[
df["dt"].dt.month.isin(WINTER_MONTHS)
& df["dt"].dt.hour.isin(SUPER_OFF_PEAK_WEEKEND)
& df["dt"].dt.weekday.isin([0, 6]),
"tariff",
] = WIN_SUP_OFF_PEAK_TOU
# # Plot tariff rate!
# fig = plt.figure(figsize=(8, 6), dpi=150)
# ax = plt.gca()
# df.plot(kind='line', x='dt', y='tariff', color='black', ax=ax, xlabel='Date', ylabel='$/kWh')
# fig.savefig('tariff_data.png')
df.to_csv("load_tariff.csv")