-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlatex_tables.py
332 lines (322 loc) · 18.8 KB
/
latex_tables.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
import pandas as pd
import os
def create_column_format(number_of_columns, position='c', index_columns='l'):
r"""
Creates column format for pd.DataFrame.to_latex() function.
Parameters
----------
number_of_columns : Integer
Number of columns of the table to be created without index column.
position : String
Position of text in columns. For example: 'c', 'l', 'r'.
"""
column_format = index_columns
for i in range(number_of_columns):
column_format = column_format.__add__(position)
return column_format
def write_latex_output(latex_output, weather_data_list, approach_list,
restriction_list, val_obj_dict, annual_energy_dicts,
wind_farm_names, key_figures_print, output_methods,
path_latex_tables, filename_add_on, year):
if 'annual_energy_approaches' in latex_output:
for weather_data_name in weather_data_list:
latex_df = pd.DataFrame()
for outerKey, innerDict in annual_energy_dicts[
weather_data_name].items():
df_part = pd.DataFrame(
{(innerKey, innerstKey): [values] for
innerKey, innerstDict in innerDict.items() if (
innerKey != 'measured_annual_energy' and
innerKey not in restriction_list) for
innerstKey, values in innerstDict.items()},
index=[outerKey.replace('wf_', 'WF ')]).round(2)
df_part['measured', '[MWh]'] = round(
annual_energy_dicts[weather_data_name][outerKey][
'measured_annual_energy'], 2)
latex_df = pd.concat([latex_df, df_part], axis=0)
latex_df.sort_index(axis=1, ascending=False, inplace=True)
latex_df.sort_index(axis=0, inplace=True)
# Column order
order = ['measured']
order.extend([approach for approach in approach_list if
approach not in restriction_list])
latex_df = latex_df[order]
filename_table = os.path.join(
path_latex_tables,
'annual_energy_approach_{0}_{1}{2}.tex'.format(
year, weather_data_name, filename_add_on))
latex_df.to_latex(buf=filename_table,
column_format=create_column_format(
len(
latex_df.columns), 'c'),
multicolumn_format='c')
if 'annual_energy_weather' in latex_output:
for approach in approach_list:
if approach not in restriction_list:
latex_df = pd.DataFrame()
for weather_data_name in weather_data_list:
df_part_weather = pd.DataFrame()
for outerKey, innerDict in annual_energy_dicts[
weather_data_name].items():
df_part = pd.DataFrame(
{(weather_data_name, innerstKey): [values] for
innerKey, innerstDict in innerDict.items() if
(innerKey == approach and innerKey not in
restriction_list) for
innerstKey, values in innerstDict.items()},
index=[outerKey.replace('wf_', 'WF ')]).round(2)
if weather_data_name == weather_data_list[0]:
df_part['measured', '[MWh]'] = round(
annual_energy_dicts[weather_data_name][
outerKey]['measured_annual_energy'], 2)
df_part_weather = pd.concat([df_part_weather, df_part],
axis=0)
latex_df = pd.concat([latex_df, df_part_weather], axis=1)
# Sort columns and index
latex_df.sort_index(axis=1, ascending=True, inplace=True)
latex_df.sort_index(axis=0, inplace=True)
# Column order
order = ['measured']
order.extend(weather_data_list)
latex_df = latex_df[order]
filename_table = os.path.join(
path_latex_tables,
'annual_energy_weather_{0}_{1}{2}.tex'.format(
year, approach, filename_add_on))
latex_df.to_latex(
buf=filename_table, column_format=create_column_format(
len(latex_df.columns), 'c'), multicolumn_format='c')
if 'annual_energy_weather_approaches' in latex_output:
latex_df = pd.DataFrame()
for weather_data_name in weather_data_list:
df_part_weather = pd.DataFrame()
for outerKey, innerDict in annual_energy_dicts[
weather_data_name].items():
df_part = pd.DataFrame(
{(innerKey, weather_data_name): [values] for
innerKey, innerstDict in innerDict.items() if (
innerKey != 'measured_annual_energy' and
innerKey not in restriction_list) for
innerstKey, values in innerstDict.items() if
innerstKey == 'deviation [%]'},
index=[outerKey.replace('wf_', 'WF ')]).round(2)
df_part_weather = pd.concat([df_part_weather, df_part], axis=0)
latex_df = pd.concat([latex_df, df_part_weather], axis=1)
# Sort columns and index
latex_df.sort_index(axis=1, ascending=True, inplace=True)
latex_df.sort_index(axis=0, inplace=True)
# Column order
latex_df = latex_df[[approach for approach in approach_list if
approach not in restriction_list]]
filename_table = os.path.join(
path_latex_tables,
'annual_energy_weather_approaches_{0}{1}.tex'.format(
year, filename_add_on))
latex_df.to_latex(
buf=filename_table, column_format=create_column_format(
len(latex_df.columns), 'c'), multicolumn_format='c')
if 'key_figures_approaches' in latex_output: # TODO add units everywhere
for weather_data_name in weather_data_list:
latex_df = pd.DataFrame()
for outerKey, innerDict in val_obj_dict[
weather_data_name].items():
for wf_name in wind_farm_names:
if wf_name not in restriction_list:
df_wf_part = pd.DataFrame()
if 'rmse' in key_figures_print:
df_part = pd.DataFrame(
{('RMSE [MW]', innerKey.replace(
'ity_correction', '. corr.').replace(
'_wf', '').replace(
'efficiency', 'eff.').replace(
'_%', '').replace(
'constant', 'const.').replace('_', ' ')):
val_obj.rmse for
innerKey, innerstList in innerDict.items() if
innerKey not in restriction_list for
val_obj in innerstList if
val_obj.object_name == wf_name},
index=[[wf_name.replace('wf_', 'WF ')],
[outerKey]])
df_wf_part = pd.concat([df_wf_part, df_part],
axis=1)
if 'rmse_normalized' in key_figures_print:
df_part = pd.DataFrame(
{('RMSE [%]', innerKey.replace(
'ity_correction', '. corr.').replace(
'_wf', '').replace(
'efficiency', 'eff.').replace(
'_%', '').replace(
'constant', 'const.').replace('_', ' ')):
val_obj.rmse_normalized for
innerKey, innerstList in
innerDict.items() for
val_obj in innerstList if
val_obj.object_name == wf_name},
index=[[wf_name.replace('wf_', 'WF ')],
[outerKey]])
df_wf_part = pd.concat([df_wf_part, df_part],
axis=1)
if 'pearson' in key_figures_print:
df_part = pd.DataFrame(
{('Pearson coeff.', innerKey.replace(
'ity_correction', '. corr.').replace(
'_wf', '').replace(
'efficiency', 'eff.').replace(
'_%', '').replace(
'constant', 'const.').replace('_', ' ')):
val_obj.pearson_s_r for
innerKey, innerstList in innerDict.items() for
val_obj in innerstList if
val_obj.object_name == wf_name},
index=[[wf_name.replace('wf_', 'WF ')],
[outerKey]])
df_wf_part = pd.concat([df_wf_part, df_part],
axis=1)
if 'mean_bias' in key_figures_print:
df_part = pd.DataFrame(
{('mean bias [MW]', innerKey.replace(
'ity_correction', '. corr.').replace(
'_wf', '').replace(
'efficiency', 'eff.').replace(
'_%', '').replace(
'constant', 'const.').replace('_', ' ')):
val_obj.mean_bias for
innerKey, innerstList in innerDict.items() for
val_obj in innerstList if
val_obj.object_name == wf_name},
index=[[wf_name.replace('wf_', 'WF ')],
[outerKey]])
df_wf_part = pd.concat([df_wf_part, df_part],
axis=1)
if 'standard_deviation' in key_figures_print:
df_part = pd.DataFrame(
{('std deviation [MW]', innerKey.replace(
'ity_correction', '. corr.').replace(
'_wf', '').replace(
'efficiency', 'eff.').replace(
'_%', '').replace(
'constant', 'const.').replace('_', ' ')):
val_obj.standard_deviation for
innerKey, innerstList in innerDict.items() for
val_obj in innerstList if
val_obj.object_name == wf_name},
index=[[wf_name.replace('wf_', 'WF ')],
[outerKey]])
df_wf_part = pd.concat([df_wf_part, df_part],
axis=1)
latex_df = pd.concat([latex_df, df_wf_part]).round(2)
# Sort index
latex_df.sort_index(axis=0, inplace=True)
filename_table = os.path.join(
path_latex_tables,
'key_figures_approaches_{0}_{1}{2}.tex'.format(
year, weather_data_name, filename_add_on))
column_format = create_column_format(
number_of_columns=(
len(val_obj_dict[weather_data_name][
output_methods[1]]) * len(key_figures_print)),
index_columns='ll')
latex_df.to_latex(buf=filename_table, column_format=column_format,
multicolumn_format='c')
if 'key_figures_weather' in latex_output:
for approach in approach_list:
if approach not in restriction_list:
latex_df = pd.DataFrame()
for weather_data_name in weather_data_list:
df_part_weather = pd.DataFrame()
for outerKey, innerDict in val_obj_dict[
weather_data_name].items():
if outerKey != 'half_hourly':
for wf_name in wind_farm_names:
if wf_name not in restriction_list:
df_wf_part = pd.DataFrame()
if 'rmse' in key_figures_print:
df_part = pd.DataFrame(
{('RMSE [MW]',
weather_data_name):
val_obj.rmse for
innerKey, innerstList in
innerDict.items() for
val_obj in innerstList if
val_obj.object_name == wf_name},
index=[[
wf_name.replace('wf_', 'WF ')],
[outerKey]])
df_wf_part = pd.concat(
[df_wf_part, df_part], axis=1)
if 'rmse_normalized' in key_figures_print:
df_part = pd.DataFrame(
{('RMSE [%]',
weather_data_name):
val_obj.rmse_normalized for
innerKey, innerstList in
innerDict.items() for
val_obj in innerstList if
val_obj.object_name == wf_name},
index=[[
wf_name.replace('wf_', 'WF ')],
[outerKey]])
df_wf_part = pd.concat(
[df_wf_part, df_part], axis=1)
if 'pearson' in key_figures_print:
df_part = pd.DataFrame(
{('Pearson coeff.',
weather_data_name):
val_obj.pearson_s_r for
innerKey, innerstList in
innerDict.items() for
val_obj in innerstList if
val_obj.object_name == wf_name},
index=[[
wf_name.replace('wf_', 'WF ')],
[outerKey]])
df_wf_part = pd.concat(
[df_wf_part, df_part], axis=1)
if 'mean_bias' in key_figures_print:
df_part = pd.DataFrame(
{('mean bias [MW]',
weather_data_name):
val_obj.mean_bias for
innerKey, innerstList in
innerDict.items() for
val_obj in innerstList if
val_obj.object_name == wf_name},
index=[[
wf_name.replace('wf_', 'WF ')],
[outerKey]])
df_wf_part = pd.concat(
[df_wf_part, df_part], axis=1)
if ('standard_deviation' in
key_figures_print):
df_part = pd.DataFrame(
{('std deviation [MW]',
weather_data_name):
val_obj.standard_deviation for
innerKey, innerstList in
innerDict.items() for
val_obj in innerstList if
val_obj.object_name == wf_name},
index=[[
wf_name.replace('wf_', 'WF ')],
[outerKey]])
df_wf_part = pd.concat(
[df_wf_part, df_part], axis=1)
df_part_weather = pd.concat(
[df_part_weather, df_wf_part])
latex_df = pd.concat([latex_df, df_part_weather],
axis=1).round(2)
# Sort columns and index
latex_df.sort_index(axis=1, inplace=True)
latex_df.sort_index(axis=0, inplace=True)
filename_table = os.path.join(
path_latex_tables,
'Key_figures_weather_{0}_{1}{2}.tex'.format(
year, approach, filename_add_on))
column_format = create_column_format(
number_of_columns=(
len(val_obj_dict[weather_data_name][
output_methods[1]]) * len(key_figures_print)),
index_columns='ll')
latex_df.to_latex(buf=filename_table, column_format=column_format,
multicolumn_format='c')