-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProcessThermalDynamics.py
438 lines (401 loc) · 12.7 KB
/
ProcessThermalDynamics.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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
import logging
import pandas as pd
# flake8: noqa
logger = logging.getLogger(__name__)
dic_zones = {
"Large_House_zones_conditioned": [
"Family/Kitchen",
"Laundry",
"Bed 5",
"Lounge",
"Bed 3",
"Bed 2",
"Upper Hall",
"Bathroom",
"Bed 4",
"Bed 1",
"WIR",
"Ensuite",
],
"Large_House_zones_all": [
"Garage",
"Family/Kitchen",
"Powder",
"Laundry",
"Bed 5",
"Lounge",
"Bed 3",
"WC",
"Bed 2",
"Upper Hall",
"Bathroom",
"Bed 4",
"Bed 1",
"WIR",
"Ensuite",
"Roofspace",
],
"Large_House_conditioned_area": { # fixed
"Family/Kitchen": 80,
"Laundry": 5,
"Bed 5": 15,
"Lounge": 20,
"Bed 3": 13,
"Bed 2": 15,
"Upper Hall": 15,
"Bathroom": 10,
"Bed 4": 15,
"Bed 1": 15,
"WIR": 10,
"Ensuite": 10,
},
"Small_House_zones_conditioned": [
"BED 1",
"ENTRY",
"FAMILY/KITCHEN",
"GALLERY",
"BED 2",
"ENS",
"BED 3",
],
"Small_House_zones_all": [
"BED 1",
"ENTRY",
"WC",
"FAMILY/KITCHEN",
"GALLERY",
"BED 2",
"ENS",
"BATH",
"BED 3",
],
"Small_House_conditioned_area": { # fixed
"BED 1": 10,
"ENTRY": 10,
"FAMILY/KITCHEN": 35,
"GALLERY": 5,
"BED 2": 15,
"ENS": 5,
"BED 3": 15,
},
"Small_Apartment_zones_conditioned": ["Kitchen/Living", "Bed 1", "Entrance"],
"Small_Apartment_zones_all": ["Kitchen/Living", "Bed 1", "Entrance", "Bath"],
"Small_Apartment_conditioned_area": { # fixed
"Kitchen/Living": 30,
"Bed 1": 10,
"Entrance": 7,
},
"Medium_Apartment_zones_conditioned": [
"Living/Kitchen",
"Laundry",
"Bath",
"Bed1",
"Ensuite",
"Bed2",
"Study",
],
"Medium_Apartment_zones_all": [
"Living/Kitchen",
"Laundry",
"Bath",
"Bed1",
"Ensuite",
"Bed2",
"Study",
],
"Medium_Apartment_conditioned_area": { # fixed
"Living/Kitchen": 45,
"Laundry": 5,
"Bath": 5,
"Bed1": 15,
"Ensuite": 5,
"Bed2": 15,
"Study": 5,
},
"Large_Apartment_zones_conditioned": [
"Kitchen/Living",
"Master Bed",
"Ens (Master)",
"Bed 2",
"Bed 3",
"Hall",
],
"Large_Apartment_zones_all": [
"Kitchen/Living",
"Master Bed",
"Bath",
"Ens (Master)",
"Bed 2",
"Bed 3",
"Hall",
],
"Large_Apartment_conditioned_area": { # fixed
"Kitchen/Living": 45,
"Master Bed": 25,
"Ens (Master)": 5,
"Bed 2": 15,
"Bed 3": 15,
"Hall": 15,
},
}
def read_TMY_weather_files(city, all_fields=False):
climate_zones_list = {"Melbourne": 62, "Brisbane": 10, "Adelaide": 16, "Sydney": 56}
weather = pd.read_fwf(
"Data/TMY/climat{}.txt".format(climate_zones_list[city]),
widths=[
2,
2,
2,
2,
2,
4,
3,
4,
3,
2,
1,
1,
1,
1,
1,
1,
1,
4,
3,
4,
2,
3,
1,
1,
5,
5,
20,
],
header=None,
)
if all_fields == False:
# print("Hi")
weather = weather.iloc[:, 17:18]
weather.columns = ["SR"]
return weather
elif all_fields == True:
# weather = weather.iloc[:, 17:22]
weather = weather.iloc[
:,
[1, 2, 3, 4, 5, 8, 17, 18, 19, 20, 21],
]
weather.columns = [
"year",
"month",
"day",
"hour",
"DBT",
"Wspd",
"GHI",
"DHI",
"DNI",
"Altitude",
"Azimuth",
]
weather[["DBT", "Wspd"]] = weather[["DBT", "Wspd"]] / 10
# weather["year"] = 2020
weather.loc[weather["year"] > 30, "year"] = weather["year"] + 1900
weather.loc[weather["year"] <= 30, "year"] = weather["year"] + 2000
weather["DateTime"] = pd.to_datetime(weather[["year", "month", "day", "hour"]])
weather.set_index("DateTime", inplace=True, drop=True)
return weather
def convert_raw_to_csv():
"""This function converts raw data to processed aggregated data files (csv)
This funciton reads .ene and .tem files for all buildings from /Data
and aggregates the indoor temperature, then writes .csv files
in /Data/Processed_thermal_dynamics"""
for city in ["Adelaide", "Melbourne", "Brisbane", "Sydney"]:
for size in ["Medium"]:
for type in ["Apartment"]:
for star in ["2star", "6star", "8star"]:
for weight in ["Light", "Medium", "Heavy"]:
print(city, size, type, star, weight)
ene_string = "Data/{}{}/{}{}_{}___{}-{}.ene".format(
size, type, type, size, city, weight, star
)
tmp_string = "Data/{}{}/{}{}_{}___{}-{}.tem".format(
size, type, type, size, city, weight, star
)
# "Data/LargeHouse/HouseLarge_Adelaide___Heavy-2star.ene"
load_df = pd.read_csv(
ene_string,
skiprows=[0, 1, 2, 3, 4],
header=None,
delim_whitespace=True,
)
load_df.drop(columns=[0, 1, 2], axis=1, inplace=True)
header = pd.MultiIndex.from_product(
[
dic_zones["{}_{}_zones_conditioned".format(size, type)],
["Heat", "CoolS", "CoolL"],
],
names=["Zone", "loadType"],
)
load_df = pd.DataFrame(load_df.to_numpy(), columns=header)
level_0 = load_df.columns.get_level_values(level=0).unique()
for i in level_0:
load_df.loc[:, (i, ["CoolL", "CoolS"])] *= -1
load_df = load_df.groupby(level=0, axis=1).sum() #
load_df["agg_AC"] = load_df.sum(axis=1)
load_df = load_df.loc[:, ["agg_AC"]]
temp_df = pd.read_csv(
tmp_string,
skiprows=[0, 1, 2, 3],
delim_whitespace=True,
header=None,
)
outdoor_temp = temp_df[3]
datetime = temp_df.iloc[:, :3]
datetime.columns = ["Month", "Day", "Hour"]
time = temp_df[[0, 1, 2]].copy(deep=True)
# print(time.head(3))
temp_df.drop(columns=[0, 1, 2, 3], axis=1, inplace=True)
# flake8: noqa
try: # noqa: E722
temp_df.columns = dic_zones[
"{}_{}_zones_all".format(size, type)
]
except Exception as ve: # noqa: E722
temp_df = temp_df.iloc[:, :-1]
temp_df.columns = dic_zones[
"{}_{}_zones_all".format(size, type)
]
# logger.exception(ve)
temp_df = temp_df.loc[
:, dic_zones["{}_{}_zones_conditioned".format(size, type)]
]
total_conditioned_area = sum(
dic_zones[
"{}_{}_conditioned_area".format(size, type)
].values()
)
for key, value in dic_zones[
"{}_{}_conditioned_area".format(size, type)
].items():
temp_df[key] = temp_df[key] * value / total_conditioned_area
temp_df["agg_temp"] = temp_df.sum(axis=1)
temp_df["outdoor"] = outdoor_temp
temp_df = temp_df.loc[:, ["agg_temp", "outdoor"]]
weather = read_TMY_weather_files(city)
processed_df = pd.concat(
[time, temp_df, load_df, weather], axis=1
)
processed_df.rename(
columns={0: "month", 1: "day", 2: "hour"}, inplace=True
)
print(processed_df.head(3))
processed_df.to_csv(
"Data/Processed_thermal_dynamics/{}_{}_{}_{}_{}.csv".format(
size, type, star, weight, city
)
)
def process_medium_houses(city, starRating, weight):
"""Create datetime format from the data"""
Areas = {
"kitchen": 40.37,
"lounge": 29.66,
"entry": 7.54,
"bed_1": 14.08,
"ensuite_1": 3.96,
"bed_2": 11.53,
"bed_3": 11.99,
"bed_4": 11.97,
"wir_1": 4.42,
"hall": 11.36,
"wc": 1.65,
}
total_area = 148.5
climate_zones_list = {"Melbourne": 62, "Brisbane": 10, "Adelaide": 16, "Sydney": 56}
climateZone = climate_zones_list[city]
main_df = pd.read_csv(
"Data/MediumHouse/{}_wc_{}_{}.csv".format(
city.lower(), weight.lower(), starRating
)
)
main_df["year"] = 2020
main_df["Date"] = pd.to_datetime(main_df[["year", "month", "day", "hour"]])
main_df.drop("year", axis="columns", inplace=True) # Drop year columns
main_df.set_index("Date", inplace=True) # Set index
""" Average cooling/heating and temperature columns for all the zones """
main_df["Cooling_m"] = main_df[
[x for x in main_df.columns if x.endswith("_c")]
].sum(axis=1)
main_df["Heating_m"] = main_df[
[x for x in main_df.columns if x.endswith("_h")]
].sum(axis=1)
# Area-averaged################################################################################################################
dd = main_df[[x for x in main_df.columns if "ac_" in x]]
dd.columns = [x.replace("ac_", "") for x in dd.columns]
dd = dd[
[
"kitchen",
"lounge",
"entry",
"bed_1",
"ensuite_1",
"bed_2",
"bed_3",
"bed_4",
"wir_1",
"hall",
"wc",
]
]
for key, value in Areas.items():
dd[key] = dd[key] * value / total_area
main_df["T_m"] = dd.sum(axis=1)
###############################################################################################################################
main_df["agg_AC"] = main_df["Heating_m"] - main_df["Cooling_m"]
main_df = main_df[["month", "day", "hour", "T_m", "outdoor", "agg_AC"]]
weather = pd.read_fwf(
"Data/TMY/climat{}.txt".format(climateZone),
widths=[
2,
2,
2,
2,
2,
4,
3,
4,
3,
2,
1,
1,
1,
1,
1,
1,
1,
4,
3,
4,
2,
3,
1,
1,
5,
5,
20,
],
header=None,
)
main_df["SR"] = weather[17].values
main_df.rename(columns={"T_m": "agg_temp"}, inplace=True)
main_df.reset_index(drop=True, inplace=True)
# print(main_df.head(25))
main_df.to_csv(
"Data/Processed_thermal_dynamics/Medium_House_{}_{}_{}.csv".format(
starRating, weight, city
)
)
if __name__ == "__main__":
for city in ["Adelaide", "Melbourne", "Brisbane", "Sydney"]:
for star in ["2star", "6star", "8star"]:
for weight in ["Light", "Medium", "Heavy"]:
process_medium_houses(city=city, starRating=star, weight=weight)