-
Notifications
You must be signed in to change notification settings - Fork 0
/
LoadSimGLD.py
358 lines (328 loc) · 11.7 KB
/
LoadSimGLD.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
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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
import os, csv
from matplotlib import pyplot as plt
import matplotlib.dates as mdates
import argparse
import sys
import pvlib
_parameters = ["GasHeat", "HeatPump", "Resistance", "AC_electric", "AC_HeatPump", "Waterheater", "EV", "Refrigerator", "Clotheswasher", "Dryer", "Freezer"]
_myDir = os.path.dirname(os.path.realpath(__file__))
def runGld(modelType):
# Run GridLAB-D on the GLM.
if modelType == 'GasHeat':
cooling_system_type = "ELECTRIC"
heating_system_type = 'GAS'
graphType = 'out_super_house_heat'
system_type_name = 'Gas Heating'
elif modelType == 'HeatPump':
cooling_system_type = "ELECTRIC"
heating_system_type = 'HEAT_PUMP'
graphType = 'out_super_house_heat'
system_type_name = 'Heat Pump'
elif modelType == 'Resistance':
cooling_system_type = "ELECTRIC"
heating_system_type = 'RESISTANCE'
graphType = 'out_super_house_heat'
system_type_name = 'Resistance'
elif modelType == 'AC_electric':
cooling_system_type = "ELECTRIC"
heating_system_type = ''
graphType = 'out_super_house_cool'
system_type_name = 'Electric'
elif modelType == 'AC_HeatPump':
cooling_system_type = "HEAT_PUMP"
heating_system_type = ''
graphType = 'out_super_house_cool'
system_type_name = 'Heat Pump'
elif modelType == 'Waterheater':
cooling_system_type = "ELECTRIC"
heating_system_type = 'RESISTANCE'
graphType = 'waterheater'
system_type_name = None
elif modelType == 'EV':
cooling_system_type = "ELECTRIC"
heating_system_type = 'RESISTANCE'
graphType = 'EV'
system_type_name = None
elif modelType =='Refrigerator':
cooling_system_type = "ELECTRIC"
heating_system_type = 'RESISTANCE'
graphType = 'Refrigerator'
system_type_name = None
elif modelType == 'Clotheswasher':
cooling_system_type= "ELECTRIC"
heating_system_type = "RESISTANCE"
graphType = 'clotheswasher'
system_type_name = None
elif modelType == 'Dryer':
cooling_system_type = "ELECTRIC"
heating_system_type = "RESISTANCE"
graphType = 'dryer'
system_type_name = None
elif modelType == 'Freezer':
cooling_system_type = "ELECTRIC"
heating_system_type = "RESISTANCE"
graphType = 'freezer'
system_type_name = None
with open('in_super_house.glm', 'r') as myfile:
data=myfile.read()
"""
SUPER HOUSE OBJECT BELOW
The following is the house model, it is inserted into the .glm that is run in any situation.
If you would like to edit the properties of the house, please edit the text below.
"""
data = data + ("""\nobject house {\n\tglass_type 2;\n\tcooling_COP 3.8;\n\thvac_breaker_rating 1000;\t
cooling_system_type """+cooling_system_type+""";\t
total_thermal_mass_per_floor_area 3.504;\t
cooling_setpoint cooling6*2.89+69.19;\t
air_temperature 71.22;\t
ceiling_height 8;\t
Rdoors 10.51;\t
heating_system_type """+heating_system_type+""";\t
glazing_layers 3;\t
glazing_treatment 2;\t
heating_setpoint heating6*0.19+59.01;\t
groupid Residential;\t
schedule_skew -57.2977315002;\t
window_frame 4;\t
parent R4-25-00-1_tm_1;\t
floor_area 8000.0;\t
number_of_stories 1;\t
mass_temperature 71.22;\t
name house0;\t
Rfloor 35.59;\t
airchange_per_hour 0.23;\t
Rroof 50.34;\t
Rwall 27.33;\t
breaker_amps 1000;\t
over_sizing_factor 0.1;
};""")
with open('temp_super_house.glm', 'w') as outFile:
outFile.write(data)
os.system('gridlabd '+'temp_super_house.glm')
print os.system('which gridlabd')
os.remove('temp_super_house.glm')
return graphHandler(graphType, heating_system_type, cooling_system_type, system_type_name)
def graphHandler(graphType, heating_system_type = None, cooling_system_type = None, system_type_name = None):
location = getCity()
if graphType == 'out_super_house_heat':
plotLoadHouseHeat(heating_system_type, system_type_name, location)
plotTemp(location)
if graphType == 'out_super_house_cool':
plotLoadHouseCool(cooling_system_type, system_type_name, location)
plotTemp(location)
elif graphType == 'waterheater':
plotLoadWaterheater(location)
elif graphType == 'EV':
plotLoadEV(location)
elif graphType == 'Refrigerator':
plotFridge(location)
elif graphType == 'clotheswasher':
plotClotheswasher(location)
elif graphType =='dryer':
plotDryer(location)
elif graphType == 'freezer':
plotFreezer(location)
def plotLoadHouseHeat(heating_system_type, system_type_name, location):
# Get the data
fileOb = open('out_super_house.csv')
for x in range(8):
# Burn the headers.
fileOb.readline()
data = list(csv.DictReader(fileOb))
# Plot Heat and AC load
# plt.switch_backend('MacOSX')
plt.figure()
formatter = mdates.DateFormatter('%Y-%m-%d')
dates = mdates.datestr2num([''.join(x.get('# timestamp')) for x in data])
plt.plot_date(dates, [float(x.get('heating_demand', 0.0)) for x in data], '-', label="Heating")
ax = plt.gcf().axes[0]
ax.xaxis.set_major_formatter(formatter)
plt.gcf().autofmt_xdate(rotation=45)
plt.suptitle(location +' ' + system_type_name +' Heating System')
plt.title('Path to raw data is in '+ _myDir, fontsize =10 )
plt.legend()
plt.xlabel('Time Stamp')
plt.ylabel('Demand (kW)')
plt.show()
def plotLoadHouseCool(cooling_system_type, system_type_name, location):
# Get the data
fileOb = open('out_super_house.csv')
for x in range(8):
# Burn the headers.
fileOb.readline()
data = list(csv.DictReader(fileOb))
# Plot Heat and AC load
# plt.switch_backend('MacOSX')
plt.figure()
formatter = mdates.DateFormatter('%Y-%m-%d')
dates = mdates.datestr2num([''.join(x.get('# timestamp')) for x in data])
plt.plot_date(dates, [float(x.get(' cooling_demand', 0.0)) for x in data], '-', label="Cooling")
ax = plt.gcf().axes[0]
ax.xaxis.set_major_formatter(formatter)
plt.gcf().autofmt_xdate(rotation=45)
plt.suptitle(location +' ' + system_type_name +' Cooling System')
plt.title('Path to raw data is in '+ _myDir, fontsize =10 )
plt.legend()
plt.xlabel('Time Stamp')
plt.ylabel('Demand (kW)')
plt.show()
def plotLoadWaterheater(location):
fileOb = open('out_super_house_waterheater.csv')
for x in range(8):
# Burn the headers.
fileOb.readline()
data = list(csv.DictReader(fileOb))
# plt.switch_backend('MacOSX')
plt.figure()
formatter = mdates.DateFormatter('%Y-%m-%d')
dates = mdates.datestr2num([''.join(x.get('# timestamp')) for x in data])
plt.plot_date(dates, [float(x.get('actual_load', 0.0)) for x in data], '-', label="Load")
ax = plt.gcf().axes[0]
ax.xaxis.set_major_formatter(formatter)
plt.gcf().autofmt_xdate(rotation=45)
plt.suptitle(location +' waterheater load in (kW)')
plt.title('Path to raw data is in '+ _myDir, fontsize =10 )
plt.legend()
plt.xlabel('Time Stamp')
plt.ylabel('Demand (kW)')
plt.show()
def plotLoadEV(location):
fileOb = open('out_super_house_EV.csv')
for x in range(8):
# Burn the headers.
fileOb.readline()
data = list(csv.DictReader(fileOb))
# plt.switch_backend('MacOSX')
plt.figure()
formatter = mdates.DateFormatter('%Y-%m-%d')
dates = mdates.datestr2num([''.join(x.get('# timestamp')) for x in data])
plt.plot_date(dates, [float(x.get('charge_rate', 0.0)) for x in data], '-', label="Load")
ax = plt.gcf().axes[0]
ax.xaxis.set_major_formatter(formatter)
plt.gcf().autofmt_xdate(rotation=45)
plt.suptitle(location +' EV load in (W)')
plt.title('Path to raw data is in '+ _myDir, fontsize =10 )
plt.legend()
plt.xlabel('Time Stamp')
plt.ylabel('Demand (W)')
plt.show()
def plotFridge(location):
fileOb = open('out_load_fridge.csv')
for x in range(8):
# Burn the headers.
fileOb.readline()
data = list(csv.DictReader(fileOb))
# plt.switch_backend('MacOSX')
plt.figure()
formatter = mdates.DateFormatter('%Y-%m-%d')
dates = mdates.datestr2num([''.join(x.get('# timestamp')) for x in data])
plt.plot_date(dates, [complex(x.get('base_power', 0.0)).real for x in data], '-', label="Load")
ax = plt.gcf().axes[0]
ax.xaxis.set_major_formatter(formatter)
plt.gcf().autofmt_xdate(rotation=45)
plt.suptitle(location + ' Fridge load in (kW)')
plt.title('Path to raw data is in '+ _myDir, fontsize =10 )
plt.legend()
plt.xlabel('Time Stamp')
plt.ylabel('Demand (kW)')
plt.show()
def plotFreezer(location):
fileOb = open('out_load_freezer.csv')
for x in range(8):
# Burn the headers.
fileOb.readline()
data = list(csv.DictReader(fileOb))
# plt.switch_backend('MacOSX')
plt.figure()
formatter = mdates.DateFormatter('%Y-%m-%d')
dates = mdates.datestr2num([''.join(x.get('# timestamp')) for x in data])
plt.plot_date(dates, [complex(x.get('base_power', 0.0)).real for x in data], '-', label="Load")
ax = plt.gcf().axes[0]
ax.xaxis.set_major_formatter(formatter)
plt.gcf().autofmt_xdate(rotation=45)
plt.suptitle(location + ' Freezer load in (kW)')
plt.title('Path to raw data is in '+ _myDir, fontsize =10 )
plt.legend()
plt.xlabel('Time Stamp')
plt.ylabel('Demand (kW)')
plt.show()
def plotClotheswasher(location):
fileOb = open('out_load_clotheswasher.csv')
for x in range(8):
# Burn the headers.
fileOb.readline()
data = list(csv.DictReader(fileOb))
# plt.switch_backend('MacOSX')
plt.figure()
formatter = mdates.DateFormatter('%Y-%m-%d')
dates = mdates.datestr2num([''.join(x.get('# timestamp')) for x in data])
plt.plot_date(dates, [complex(x.get('base_power', 0.0)).real for x in data], '-', label="Load")
ax = plt.gcf().axes[0]
ax.xaxis.set_major_formatter(formatter)
plt.gcf().autofmt_xdate(rotation=45)
plt.suptitle(location + ' Clotheswasher load in (kW)')
plt.title('Path to raw data is in '+ _myDir, fontsize =10 )
plt.legend()
plt.xlabel('Time Stamp')
plt.ylabel('Demand (kW)')
plt.show()
def plotDryer(location):
fileOb = open('out_load_dryer.csv')
for x in range(8):
# Burn the headers.
fileOb.readline()
data = list(csv.DictReader(fileOb))
# plt.switch_backend('MacOSX')
plt.figure()
formatter = mdates.DateFormatter('%Y-%m-%d')
dates = mdates.datestr2num([''.join(x.get('# timestamp')) for x in data])
plt.plot_date(dates, [complex(x.get('base_power', 0.0)).real for x in data], '-', label="Load")
ax = plt.gcf().axes[0]
ax.xaxis.set_major_formatter(formatter)
plt.gcf().autofmt_xdate(rotation=45)
plt.suptitle(location + ' Dryer load in (kW)')
plt.title('Path to raw data is in '+ _myDir, fontsize =10 )
plt.legend()
plt.xlabel('Time Stamp')
plt.ylabel('Demand (kW)')
plt.show()
def plotTemp(location):
# Get the data
fileOb = open('out_super_house.csv')
for x in range(8):
# Burn the headers.
fileOb.readline()
data = list(csv.DictReader(fileOb))
plt.title(location + ' Temperatures')
formatter = mdates.DateFormatter('%Y-%m-%d')
dates = mdates.datestr2num([''.join(x.get('# timestamp')) for x in data])
plt.plot_date(dates, [float(x.get(' air_temperature', 0.0)) for x in data], '-', label="Indoor")
plt.plot_date(dates, [float(x.get(' outdoor_temperature', 0.0)) for x in data], '-', label="Outdoors")
plt.plot_date(dates, [float(x.get(' heating_setpoint', 0.0)) for x in data], '-', label="heating_setpoint")
ax = plt.gcf().axes[0]
ax.xaxis.set_major_formatter(formatter)
plt.gcf().autofmt_xdate(rotation=45)
plt.legend()
plt.xlabel('Time Stamp')
plt.ylabel('Temperature (degF)')
plt.show()
def getCity():
df = pvlib.tmy.readtmy2('inc_climate.tmy2')
city = df[1]['City']
state = df[1]['State']
return (city + ", " + state)
if __name__ == '__main__':
#TODO: warning text 'Illegal input. Usage: "python LoadSimGLD <load_type>" where load_type is one of ...
#Parse Command Line
if len(sys.argv) == 1:
modelType = 'Waterheater'
else:
parser = argparse.ArgumentParser(description='Simulates heat/cool power use on a canonical .glm single house model')
parser.add_argument(
'model_type',
metavar = 'base',
type = str,
help = 'Please specify type of model :"GasHeat", "HeatPump", "Resistance", "AC_electric", "AC_HeatPump", "Waterheater", "EV", "Refrigerator", "Clotheswasher", "Dryer", "Freezer" ')
args = parser.parse_args()
modelType = args.model_type
runGld(modelType)