-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoutput_processing2.py
123 lines (97 loc) · 4.64 KB
/
output_processing2.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
# Return EHF from multiple simulation results of Operative Temperature
import glob
from multiprocessing import Pool
import os
import pandas as pd
from dict_update import update
def set_delta_T(n):
if n < .25:
delta_T = 0
elif n < .5:
delta_T = 1.2
elif n < .75:
delta_T = 1.8
else:
delta_T = 2.2
return delta_T
def process_outputs(line, month_means, output_name,ach=True):
df_temp = {
'folder': [],
'file': [],
'zone': [],
'temp': [],
'temp_max': [],
'ach': [],
'ehf': []
}
print(line['file'],' ',line['folder']) # , end='\r')
csv_file = line['file'].split('.')[0]+'out.csv'
df = pd.read_csv(line['folder']+'/'+csv_file)
delta_T = set_delta_T(line['v_ar'])
if line['file'][0] == 'w':
n_zones = 6
for zn in range(n_zones):
df_temp['file'].append(line['file'].split('.')[0])
df_temp['folder'].append(line['folder'])
df_temp['zone'].append(zn)
df_temp['temp'].append((df['OFFICE_'+'{:02.0f}'.format(zn)+':Zone Operative Temperature [C](Hourly)'][df['SCH_OCUPACAO:Schedule Value [](Hourly)'] > 0]).mean())
df_temp['temp_max'].append((df['OFFICE_'+'{:02.0f}'.format(zn)+':Zone Operative Temperature [C](Hourly)'][df['SCH_OCUPACAO:Schedule Value [](Hourly)'] > 0]).max())
if ach:
df_temp['ach'].append((df['OFFICE_'+'{:02.0f}'.format(zn)+':AFN Zone Infiltration Air Change Rate [ach](Hourly)'][df['SCH_OCUPACAO:Schedule Value [](Hourly)'] > 0]).mean())
else:
df_temp['ach'].append(0)
df['E_hot'] = -1
df['sup_lim'] = month_means['mean_temp'] + 3.5 + delta_T
df.loc[df['OFFICE_'+'{:02.0f}'.format(zn)+':Zone Operative Temperature [C](Hourly)'] > df['sup_lim'], 'E_hot'] = 1
df.loc[df['OFFICE_'+'{:02.0f}'.format(zn)+':Zone Operative Temperature [C](Hourly)'] <= df['sup_lim'], 'E_hot'] = 0
df_temp['ehf'].append(df['E_hot'][df['SCH_OCUPACAO:Schedule Value [](Hourly)'] > 0].mean())
else:
df_temp['file'].append(line['file'].split('.')[0])
df_temp['folder'].append(line['folder'])
df_temp['zone'].append(line['file'].split('.')[0][-1])
df_temp['temp'].append((df['OFFICE:Zone Operative Temperature [C](Hourly)'][df['SCH_OCUPACAO:Schedule Value [](Hourly)'] > 0]).mean())
df_temp['temp_max'].append((df['OFFICE:Zone Operative Temperature [C](Hourly)'][df['SCH_OCUPACAO:Schedule Value [](Hourly)'] > 0]).max())
if ach:
df_temp['ach'].append((df['OFFICE:AFN Zone Infiltration Air Change Rate [ach](Hourly)'][df['SCH_OCUPACAO:Schedule Value [](Hourly)'] > 0]).mean())
else:
df_temp['ach'].append(0)
df['E_hot'] = -1
df['sup_lim'] = month_means['mean_temp'] + 3.5 + delta_T
df.loc[df['OFFICE:Zone Operative Temperature [C](Hourly)'] > df['sup_lim'], 'E_hot'] = 1
df.loc[df['OFFICE:Zone Operative Temperature [C](Hourly)'] <= df['sup_lim'], 'E_hot'] = 0
df_temp['ehf'].append(df['E_hot'][df['SCH_OCUPACAO:Schedule Value [](Hourly)'] > 0].mean())
return(df_temp)
def main(df_base, month_means, output_name, ach=True):
df_final = {
'folder': [],
'file': [],
'zone': [],
'temp': [],
'temp_max': [],
'ach': [],
'ehf': []
}
MONTH_MEANS = pd.read_csv(month_means)
num_cluster = len(df_base['folder'].unique())
p = Pool(num_cluster)
result_map = p.starmap(process_outputs, zip(
# [df_base.query('folder == "cluster'+str(i)+'"') for i in range(num_cluster)],
[df_base.iloc[i] for i in range(len(df_base))],
[MONTH_MEANS for _ in range(len(df_base))],
[output_name for _ in range(len(df_base))],
[ach for _ in range(len(df_base))]
))
p.close()
p.join()
for df_temp in result_map:
for key in df_final.keys():
for i in range(len(df_temp[key])):
df_final[key].append(df_temp[key][i])
# df_final = pd.DataFrame(df_final)
# df_final = pd.concat([df_base, df_final], axis=1, ignore_index=True)
df_output = pd.DataFrame(df_final)
df_output.to_csv(output_name+'.csv', index=False)
print('\tDone processing!')
# df_base = pd.read_csv('test.csv')
# os.chdir('test')
# main(df_base, '/media/marcelo/OS/LabEEE_1-2/idf-creator/month_means_8760.csv', 'teste')