-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlotter.py
817 lines (622 loc) · 37.4 KB
/
Plotter.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
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
import re
import sys
import pandas as pd
import numpy as np
import plotly.graph_objects as plygo
import plotly.io as pio
from plotly.subplots import make_subplots
def PlotterSelective (srcFig= dict, srcPlt= list, visibleLegend= bool, visibleTitle= bool):
### loop the plots and return a unique list of positions in grid
i = 0
posList = []
for i in range(len(srcPlt)):
if srcPlt[i]['pos'] in posList:
pass
else:
posList.append(srcPlt[i]['pos'])
posList.sort()
### group plots into dictionaries by pos and trace type
i, j = 0, 0
srcPltGrouped = []
pltGroupDict = {'pos': '', 'trace': [], 'plts': []}
for i in range(len(posList)):
pltGroupDict['pos'] = posList[i]
for j in range(len(srcPlt)):
if srcPlt[j]['pos'] == posList[i]:
pltGroupDict['plts'].append(srcPlt[j])
if srcPlt[j]['tracetype'] in pltGroupDict['trace']:
pass
else:
pltGroupDict['trace'].append(srcPlt[j]['tracetype'])
srcPltGrouped.append(pltGroupDict)
pltGroupDict = {'pos': '', 'trace': [], 'plts': []}
### check for pie charts (plotly limitation)
i = 0
if len(srcPltGrouped) == 1:
if len(srcPltGrouped[0]['trace']) > 1 and 'Pie Chart' in srcPltGrouped[0]['trace']:
print('Error 1: Can\'t plot Pie chart with other chart types in the same plot, Plotly Lib limitation')
sys.exit()
elif len(srcPltGrouped[i]['plts']) > 1 and 'Pie Chart' in srcPltGrouped[i]['trace']:
print('Error 2: Can\'t plot multiple Pie charts in the same plot, Plotly Lib limitation')
sys.exit()
else:
for i in range(len(srcPltGrouped)):
if 'Pie Chart' in srcPltGrouped[i]['trace']:
print('Error 3: Can\'t plot multiple Pie charts in the same figure, Plotly Lib limitation')
sys.exit()
### build figure subplots
figure = make_subplots(rows= srcFig['rows'], cols= srcFig['cols'], horizontal_spacing= 0.1, vertical_spacing= 0.23)
### build data frames
i, j = 0, 0
tempDF = pd.read_csv(srcPlt[0]['datasrc']['path'], delimiter= ',', low_memory= False, index_col= 'Index')
tempDF[:] = np.NaN
tempDF.insert(0,'temp0',np.NaN)
tempDF.drop(tempDF.columns[1:], axis= 1, inplace= True)
tempDF.drop(tempDF.index[tempDF.index.get_loc('EnergyplanModel'):tempDF.index.get_loc('Calc.EconomyAndFuel')], axis=0, inplace= True)
pltInfoList = ['pltid', 'stdid', 'stdname', 'datatype', 'tracetype', 'tracestyle', 'tracefill', 'xstart', 'xend', 'xtitle', 'ytitle', 'xtick', 'xstep', 'ytick', 'ystep']
sumDF = pd.DataFrame(0, pltInfoList, ['temp0'])
sumDF = pd.concat([sumDF,tempDF])
for i in range(len(srcPltGrouped)):
sumDF.reset_index(inplace= True)
sumDF['indNum'] = sumDF.index
sumDF.set_index('index', inplace= True, drop= True)
sumDF = sumDF[['indNum']]
statMean, statMedian, statOnly, stackLines = False, False, False, False
posRow = int(str(srcPltGrouped[i]['pos'])[:1])
posCol = int(str(srcPltGrouped[i]['pos'])[-1:])
for j in range(len(srcPltGrouped[i]['plts'])):
plot = srcPltGrouped[i]['plts'][j]
### check and set statistics switches
if 'Pie Chart' in srcPltGrouped[i]['trace'] or 'Box Plot' in srcPltGrouped[i]['trace']:
pass
else:
statMean = statMean or plot['mean']
statMedian = statMedian or plot['median']
statOnly = statOnly or plot['statonly']
stackLines = stackLines or plot['stack']
### get data source
srcStd = plot['datasrc']
stdDF = pd.read_csv(srcStd['path'], delimiter= ',', low_memory= False, index_col= 'Index')
### drop text values
stdDF = stdDF.drop(stdDF.index[stdDF.index.get_loc('EnergyplanModel'):stdDF.index.get_loc('Calc.EconomyAndFuel')], axis=0)
### cast cells data type
try:
stdDF = stdDF.astype(float)
except:
pass
### convert Annual values from TWh -> MWh
stdDF.loc['AnnualAverage':'AnnualMinimum'] /= 1000
### calc X series
if plot['datatype'] == 'hourly':
### set X start
if re.fullmatch(r'\d{1,4}', plot['xstart']):
xStart = 'h' + plot['xstart']
elif re.fullmatch(r'h\d{1,4}', plot['xstart']):
xStart = plot['xstart']
elif re.fullmatch(r'd\d{1,3}', plot['xstart']):
xStart = int(plot['xstart'][1:])
xStart = (xStart * 24) - 24 + 1
xStart = 'h' + str(xStart)
elif re.fullmatch(r'w\d{1,2}', plot['xstart']):
xStart = int(plot['xstart'][1:])
xStart = ((xStart -1) * 24 * 7) + 1
xStart = 'h' + str(xStart)
else:
xStart = 'h1'
### set X end
if re.fullmatch(r'\d{1,4}', plot['xend']):
xEnd = 'h' + plot['xend']
elif re.fullmatch(r'h\d{1,4}', plot['xend']):
xEnd = plot['xend']
elif re.fullmatch(r'd\d{1,3}', plot['xend']):
xEnd = int(plot['xend'][1:])
xEnd = xEnd * 24
xEnd = 'h' + str(xEnd)
elif re.fullmatch(r'w\d{1,2}', plot['xend']):
xEnd = int(plot['xend'][1:])
xEnd = xEnd * 24 * 7
xEnd = 'h' + str(xEnd)
else:
xEnd = 'h8784'
### Get X Data (by type: time based or data based) and set X axes title
if plot['xtype'] == 'time':
xData = stdDF.loc[xStart:xEnd].index.values.tolist()
xTitle = 'Time Range'
elif plot['xtype'] == 'data':
xDataOffset = ''
xTitle = plot['xtitle'] + ' (MW)'
for xData_i, headers in enumerate(list(stdDF.columns.values)):
if plot['xdata'][:2] == '00':
if plot['xdata'] == headers[:4]:
xDataOffset = headers
xData = stdDF.loc[xStart:xEnd, xDataOffset].tolist()
break
else:
xData = stdDF.loc[xStart:xEnd].index.values.tolist()
### Set Y axes title
yTitle = plot['ytitle'] + ' (MW)'
elif plot['datatype'] == 'monthly':
### set X start and end
xStart = plot['xstart']
xEnd = plot['xend']
### Get X Data (by type: time based or data based) and set X axes title
xData = stdDF.loc[xStart:xEnd].index.values.tolist()
if plot['xtype'] == 'time':
xTitle = 'Time Range'
elif plot['xtype'] == 'data':
xTitle = plot['xtitle'] + ' (MW)'
### Set Y axes title
yTitle = plot['ytitle'] + ' (MW)'
elif plot['datatype'] == 'annual':
yTitle = plot['ytitle'] + ' (TWh\Year)'
if plot['xdata'] == 'Power Values - Totals':
xStart = xEnd = 'Annual'
elif plot['xdata'] == 'Power Values - Annual Average':
xStart = xEnd = 'AnnualAverage'
elif plot['xdata'] == 'Power Values - Annual Maximum':
xStart = xEnd = 'AnnualMaximum'
elif plot['xdata'] == 'Power Values - Annual Minimum':
xStart = xEnd = 'AnnualMinimum'
elif plot['xdata'] == 'Annual CO2 Emissions':
xStart = 'Co2-Emission(Total)'
xEnd = 'Co2-Emission(Corrected)'
labelsData = xData = stdDF.loc[xStart:xEnd].index.values.tolist()
valuesData = stdDF.loc[xStart:xEnd, 'g0-Data1'].tolist()
templateFormat = '%{label}<br>%{value} (MT)<br>%{percent}'
elif plot['xdata'] == 'Annual Fuel Consumptions':
xStart = 'FuelConsumption(Total)'
xEnd = 'V2GPreLoadHours'
labelsData = xData = stdDF.loc[xStart:xEnd].index.values.tolist()
valuesData = stdDF.loc[xStart:xEnd, 'g0-Data1'].tolist()
templateFormat = '%{label}<br>%{value} (TWh/year)<br>%{percent}'
elif plot['xdata'] == 'Share of RES':
xStart = 'ResShareOfPes'
xEnd = 'ResShareOfElec.Prod.'
labelsData = xData = stdDF.loc[xStart:xEnd].index.values.tolist()
valuesData = stdDF.loc[xStart:xEnd, 'g0-Data1'].tolist()
templateFormat = '%{label}<br>%{value}'
elif plot['xdata'] == 'Total Elect. Demand':
xStart = xEnd = 'Annual'
labelsData = ['Elect. Demand', 'Elect. Demand Cooling', 'Fixed Exp/Imp', 'Flexible Electr, ', 'HH-HP Elect.', 'HH-EB Elect.']
valuesData = stdDF.loc['Annual', ['0001_ElectrDemand', '0002_ElecdemCooling', '0003_FixedExp/Imp', '0020_FlexibleElectr', '1802_HH-HPElectr', '1804_HH-EBElectr']].tolist()
templateFormat = '%{label}<br>%{value} (TWh/year)<br>%{percent}'
elif plot['xdata'] == 'Total Heat Demand':
xStart = xEnd = 'Annual'
labelsData = ['DH Demand', 'HH Demand Heat']
valuesData = stdDF.loc['Annual', ['0004_DHDemand', '1701_HHDemHeat']].tolist()
templateFormat = '%{label}<br>%{value} (TWh/year)<br>%{percent}'
elif plot['xdata'] == 'VRES (Renewable Fuel Balance)':
xStart = xEnd = 'Annual'
labelsData = ['Wind Electr', 'Offshore Electr', 'PV Electr', 'River Electr', 'Tidal Electr', 'Wave Electr', 'CSP Electr', 'CSP2 Electr']
valuesData = stdDF.loc['Annual', ['0101_WindElectr', '0102_OffshoreElectr', '0103_PVElectr', '0105_RiverElectr', '0107_TidalElectr', '0106_WaveElectr', '0104_CSPElectr', '0108_CSP2Electr']].tolist()
templateFormat = '%{label}<br>%{value} (TWh/year)<br>%{percent}'
elif plot['xdata'] == 'Electricity Consumption':
xStart = xEnd = 'Annual'
labelsData = ['Electr Demand', 'Fixed Exp/Imp', 'Flexible Electr', 'Elec. Dem Cooling', 'H2 Electr', 'V2G Charge', 'HP Electr', 'HH-EB Electr', 'Pump Electr', 'Pump2 Electr', 'Hydro Pump', 'EH3 Heat']
valuesData = stdDF.loc['Annual', ['0001_ElectrDemand', '0003_FixedExp/Imp', '0020_FlexibleElectr', '0002_ElecdemCooling', '2001_H2Electr', '1302_V2GCharge', '0021_HPElectr', '1804_HH-EBElectr', '0801_PumpElectr', '0802_Pump2Electr', '0202_Hydropump', '0016_EH3Heat']].tolist()
templateFormat = '%{label}<br>%{value} (TWh/year)<br>%{percent}'
elif plot['xdata'] == 'Electricity Production':
xStart = xEnd = 'Annual'
labelsData = ['Wind Electr', 'Offshore Electr', 'PV Electr', 'River Electr', 'Tidal Electr', 'Wave Electr', 'CSP Electr', 'CSP2 Electr', 'HH-CHP Electr', 'Hydro Electr', 'Nuclear Electr', 'Geother. Electr', 'V2G Discharge', 'CSHP Electr', 'CHP Electr', 'Turbine Electr', 'Turbine2 Electr', 'PP Electr', 'PP2 Electr']
valuesData = stdDF.loc['Annual', ['0101_WindElectr', '0102_OffshoreElectr', '0103_PVElectr', '0105_RiverElectr', '0107_TidalElectr', '0106_WaveElectr', '0104_CSPElectr', '0108_CSP2Electr', '1801_HH-CHPElectr', '0201_HydroElectr', '0701_NuclearElectr', '0702_GeotherElectr', '1303_V2GDischa', '0022_CSHPElectr', '0023_CHPElectr', '0901_TurbineElectr', '0902_Turbine2Electr', '0601_PPElectr', '0602_PP2Electr']].tolist()
templateFormat = '%{label}<br>%{value} (TWh/year)<br>%{percent}'
elif plot['xdata'] == 'Electricity Balance':
xStart = xEnd = 'Annual'
labelsData = ['Import Electr', 'CEEP Electr', 'EEEP Electr']
valuesData = stdDF.loc['Annual', ['0025_ImportElectr', '0027_CEEPElectr', '0028_EEEPElectr']].tolist()
templateFormat = '%{label}<br>%{value} (TWh/year)<br>%{percent}'
elif plot['xdata'] == 'District Heat Production':
xStart = xEnd = 'Annual'
labelsData = ['CSHP 1 Heat', 'Waste 1 Heat', 'Boiler 1 Heat', 'Solar 1 Heat', 'CSHP 2 Heat', 'Waste 2 Heat', 'Geoth 2 Heat', 'CHP 2 Heat', 'HP 2 Heat', 'Boiler 2 Heat', 'EH 2 Heat', 'ELT 2 Heat', 'Solar 2 Heat', 'CSHP 3 Heat', 'Waste 3 Heat', 'Geoth 3 Heat', 'CHP 3 Heat', 'HP 3 Heat', 'Boiler 3 Heat', 'EH 3 Heat', 'ELT 3 Heat', 'Solar 3 Heat']
valuesData = stdDF.loc['Annual', ['0401_CSHP1Heat', '0402_Waste1Heat', '0005_Boiler1Heat', '0302_Solar1Heat', '0403_CSHP2Heat', '0404_Waste2Heat', '0501_Geoth2Heat', '0006_CHP2Heat', '0007_HP2Heat', '0008_Boiler2Heat', '0009_EH2Heat', '0010_ELT2Heat', '0304_Solar2Heat', '0405_CSHP3Heat', '0406_Waste3Heat', '0504_Geoth3Heat', '0013_CHP3Heat', '0014_HP3Heat', '0015_Boiler3Heat', '0016_EH3Heat', '0017_ELT3Heat', '0306_Solar3Heat']].tolist()
templateFormat = '%{label}<br>%{value} (TWh/year)<br>%{percent}'
elif plot['xdata'] == 'District Heat Gr.1':
xStart = xEnd = 'Annual'
labelsData = ['CSHP 1 Heat', 'Waste 1 Heat', 'Boiler 1 Heat', 'Solar 1 Heat']
valuesData = stdDF.loc['Annual', ['0401_CSHP1Heat', '0402_Waste1Heat', '0005_Boiler1Heat', '0302_Solar1Heat']].tolist()
templateFormat = '%{label}<br>%{value} (TWh/year)<br>%{percent}'
elif plot['xdata'] == 'District Heat Gr.2':
xStart = xEnd = 'Annual'
labelsData = ['CSHP 2 Heat', 'Waste 2 Heat', 'Geoth 2 Heat', 'CHP 2 Heat', 'HP 2 Heat', 'Boiler 2 Heat', 'EH 2 Heat', 'ELT 2 Heat', 'Solar 2 Heat']
valuesData = stdDF.loc['Annual', ['0403_CSHP2Heat', '0404_Waste2Heat', '0501_Geoth2Heat', '0006_CHP2Heat', '0007_HP2Heat', '0008_Boiler2Heat', '0009_EH2Heat', '0010_ELT2Heat', '0304_Solar2Heat']].tolist()
templateFormat = '%{label}<br>%{value} (TWh/year)<br>%{percent}'
elif plot['xdata'] == 'District Heat Gr.3':
xStart = xEnd = 'Annual'
labelsData = ['CSHP 3 Heat', 'Waste 3 Heat', 'Geoth 3 Heat', 'CHP 3 Heat', 'HP 3 Heat', 'Boiler 3 Heat', 'EH 3 Heat', 'ELT 3 Heat', 'Solar 3 Heat']
valuesData = stdDF.loc['Annual', ['0405_CSHP3Heat', '0406_Waste3Heat', '0504_Geoth3Heat', '0013_CHP3Heat', '0014_HP3Heat', '0015_Boiler3Heat', '0016_EH3Heat', '0017_ELT3Heat', '0306_Solar3Heat']].tolist()
templateFormat = '%{label}<br>%{value} (TWh/year)<br>%{percent}'
elif plot['xdata'] == 'Individual (HH) Heating Production':
xStart = xEnd = 'Annual'
labelsData = ['HH-EB Electr', 'HH CHP+HP Heat', 'HH Boil. Heat', 'HH Solar Heat']
valuesData = stdDF.loc['Annual', ['1804_HH-EBElectr', '1702_HHCHP+HPHeat', '1703_HHBoilHeat', '1704_HHSolarHeat']].tolist()
templateFormat = '%{label}<br>%{value} (TWh/year)<br>%{percent}'
elif plot['xdata'] == 'Heat Balance':
xStart = xEnd = 'Annual'
labelsData = ['HH Balan Heat', 'Boiler1 Heat', 'Balance2 Heat', 'Balance3 Heat']
valuesData = stdDF.loc['Annual', ['1706_HHBalanHeat', '0005_Boiler1Heat', '0012_Balance2Heat', '0019_Balance3Heat']].tolist()
templateFormat = '%{label}<br>%{value} (TWh/year)<br>%{percent}'
elif plot['xdata'][0:16] == 'Investment Costs':
rangeStart = stdDF.index.get_loc('TotalAnnualCosts')
rangeStart += 1
rangeEnd = stdDF.iloc[rangeStart:rangeStart+100].index.get_loc('Coal')
rangeEnd = rangeEnd + rangeStart
xStart = stdDF.iloc[rangeStart:rangeEnd].index[0]
xEnd = stdDF.iloc[rangeStart:rangeEnd].index[-1]
if plot['xdata'] == 'Investment Costs - Total':
yData = ['g0-Data1']
elif plot['xdata'] == 'Investment Costs - Annual':
yData = ['g0-Data2']
elif plot['xdata'] == 'Investment Costs - O & M':
yData = ['g0-Data3']
yTitle = plot['xdata'] + ' (M Euro)'
elif plot['xdata'][:14] == 'Energy Balance':
rangeStart = stdDF.index.get_loc('TotalAnnualCosts')
rangeStart = rangeStart + stdDF.iloc[rangeStart:rangeStart+100].index.get_loc('Coal')
rangeEnd = stdDF.iloc[rangeStart:rangeStart+100].index.get_loc('Renewable')
rangeEnd = rangeEnd + rangeStart +1
xData = stdDF.iloc[rangeStart:rangeEnd].index.values.tolist()
xStart = stdDF.iloc[rangeStart:rangeEnd].index[0]
xEnd = stdDF.iloc[rangeStart:rangeEnd].index[-1]
yTitle = ''
elif plot['xdata'] == 'Installed Capacities':
break
if plot['xdata'][:14] != 'Energy Balance':
xData = stdDF.loc[xStart:xEnd].index.values.tolist()
xTitle = ''
### calc Y series
yData = []
if plot['xdata'][:14] == 'Energy Balance':
for yData_i, headers in enumerate(list(stdDF.columns.values)):
if headers[:2] == 'g1':
yData.append(headers)
yData.pop()
yTitle = plot['xdata']
elif plot['xdata'][0:16] == 'Investment Costs':
if plot['xdata'] == 'Investment Costs - Total':
yData = ['g0-Data1']
yTitle = plot['xdata'] + ' (M Euro)'
elif plot['xdata'] == 'Investment Costs - Annual':
yData = ['g0-Data2']
yTitle = plot['xdata'] + ' (M Euro)'
elif plot['xdata'] == 'Investment Costs - O & M':
yData = ['g0-Data3']
yTitle = plot['xdata'] + ' (M Euro)'
elif plot['xdata'] == 'Total Elect. Demand':
yData = ['0001_ElectrDemand', '0002_ElecdemCooling', '0003_FixedExp/Imp', '0020_FlexibleElectr', '1802_HH-HPElectr', '1804_HH-EBElectr']
yTitle = plot['xdata'] + ' (TWh/year)'
elif plot['xdata'] == 'Total Heat Demand':
yData = ['0004_DHDemand', '1701_HHDemHeat']
yTitle = plot['xdata'] + ' (TWh/year)'
elif plot['xdata'] == 'VRES (Renewable Fuel Balance)':
yData = ['0101_WindElectr', '0102_OffshoreElectr', '0103_PVElectr', '0105_RiverElectr', '0107_TidalElectr', '0106_WaveElectr', '0104_CSPElectr', '0108_CSP2Electr']
yTitle = plot['xdata'] + ' (TWh/year)'
elif plot['xdata'] == 'Electricity Consumption':
yData = ['0001_ElectrDemand', '0003_FixedExp/Imp', '0020_FlexibleElectr', '0002_ElecdemCooling', '2001_H2Electr', '1302_V2GCharge', '0021_HPElectr', '1804_HH-EBElectr', '0801_PumpElectr', '0802_Pump2Electr', '0202_Hydropump', '0016_EH3Heat']
yTitle = plot['xdata'] + ' (TWh/year)'
elif plot['xdata'] == 'Electricity Production':
yData = ['0101_WindElectr', '0102_OffshoreElectr', '0103_PVElectr', '0105_RiverElectr', '0107_TidalElectr', '0106_WaveElectr', '0104_CSPElectr', '0108_CSP2Electr', '1801_HH-CHPElectr', '0201_HydroElectr', '0701_NuclearElectr', '0702_GeotherElectr', '1303_V2GDischa', '0022_CSHPElectr', '0023_CHPElectr', '0901_TurbineElectr', '0902_Turbine2Electr', '0601_PPElectr', '0602_PP2Electr']
yTitle = plot['xdata'] + ' (TWh/year)'
elif plot['xdata'] == 'Electricity Balance':
yData = ['0025_ImportElectr', '0027_CEEPElectr', '0028_EEEPElectr']
yTitle = plot['xdata'] + ' (TWh/year)'
elif plot['xdata'] == 'District Heat Production':
yData = ['0401_CSHP1Heat', '0402_Waste1Heat', '0005_Boiler1Heat', '0302_Solar1Heat', '0403_CSHP2Heat', '0404_Waste2Heat', '0501_Geoth2Heat', '0006_CHP2Heat', '0007_HP2Heat', '0008_Boiler2Heat', '0009_EH2Heat', '0010_ELT2Heat', '0304_Solar2Heat', '0405_CSHP3Heat', '0406_Waste3Heat', '0504_Geoth3Heat', '0013_CHP3Heat', '0014_HP3Heat', '0015_Boiler3Heat', '0016_EH3Heat', '0017_ELT3Heat', '0306_Solar3Heat']
yTitle = plot['xdata'] + ' (TWh/year)'
elif plot['xdata'] == 'District Heat Gr.1':
yData = ['0401_CSHP1Heat', '0402_Waste1Heat', '0005_Boiler1Heat', '0302_Solar1Heat']
yTitle = plot['xdata'] + ' (TWh/year)'
elif plot['xdata'] == 'District Heat Gr.2':
yData = ['0403_CSHP2Heat', '0404_Waste2Heat', '0501_Geoth2Heat', '0006_CHP2Heat', '0007_HP2Heat', '0008_Boiler2Heat', '0009_EH2Heat', '0010_ELT2Heat', '0304_Solar2Heat']
yTitle = plot['xdata'] + ' (TWh/year)'
elif plot['xdata'] == 'District Heat Gr.3':
yData = ['0405_CSHP3Heat', '0406_Waste3Heat', '0504_Geoth3Heat', '0013_CHP3Heat', '0014_HP3Heat', '0015_Boiler3Heat', '0016_EH3Heat', '0017_ELT3Heat', '0306_Solar3Heat']
yTitle = plot['xdata'] + ' (TWh/year)'
elif plot['xdata'] == 'Individual (HH) Heating Production':
yData = ['1804_HH-EBElectr', '1702_HHCHP+HPHeat', '1703_HHBoilHeat', '1704_HHSolarHeat']
yTitle = plot['xdata'] + ' (TWh/year)'
elif plot['xdata'] == 'Heat Balance':
yData = ['1706_HHBalanHeat', '0005_Boiler1Heat', '0012_Balance2Heat', '0019_Balance3Heat']
yTitle = plot['xdata'] + ' (TWh/year)'
else:
for yData_i, headers in enumerate(list(stdDF.columns.values)):
if plot['ydata'][2:4] == '00':
if plot['ydata'][:2] == headers[:2]:
yData.append(headers)
next
elif plot['ydata'] == headers[:4]:
yData.append(headers)
break
### add index and columns to sumDF
pltDF = pd.DataFrame(0, pltInfoList, ['test'])
if plot['xdata'][:14] == 'Energy Balance':
stdDF = pd.concat([pltDF, stdDF.iloc[rangeStart:rangeEnd, stdDF.columns.get_loc(yData[0]):stdDF.columns.get_loc(yData[-1]) +1]])
else:
stdDF = pd.concat([pltDF, stdDF.loc[xData, yData]])
stdDF.loc['pltid',:] = plot['id']
stdDF.loc['stdid',:] = plot['datasrc']['id']
stdDF.loc['stdname',:] = plot['datasrc']['name']
stdDF.loc['datatype',:] = plot['datatype']
stdDF.loc['tracetype',:] = plot['tracetype']
stdDF.loc['tracestyle',:] = plot['tracestyle']
stdDF.loc['tracefill',:] = plot['tracefill']
stdDF.loc['xstart',:] = plot['xstart']
stdDF.loc['xend',:] = plot['xend']
stdDF.loc['xtitle',:] = plot['xtitle']
stdDF.loc['ytitle',:] = plot['ytitle']
stdDF.loc['xtick',:] = plot['xtick']
stdDF.loc['xstep',:] = plot['xstep']
stdDF.loc['ytick',:] = plot['ytick']
stdDF.loc['ystep',:] = plot['ystep']
stdDF.drop(['test'], axis= 1, inplace=True)
for col in stdDF.columns.values.tolist():
colName = stdDF[col].name
colName = colName[colName.find('_') +1:]
colName = stdDF[col].loc['stdname'] + ': ' + colName + str(j)
stdDF.rename(columns= {stdDF[col].name: colName}, inplace= True)
sumDF = sumDF.join(stdDF)
sumDF['index'] = sumDF.index
sumDF.set_index('indNum', inplace= True, drop= True)
sumDF.sort_index(axis= 0, ascending= True, inplace= True)
sumDF.set_index('index', inplace= True, drop= True)
sumDF.dropna(axis= 0, how= 'all', inplace= True)
indexLoc = sumDF.index.get_loc('ystep') +1
sumDF = sumDF[~sumDF.index.duplicated(keep='last')]
if statMean:
colMean = sumDF.iloc[indexLoc:].mean(axis= 1).tolist()
tmpList = [0] * indexLoc
tmpList.extend(colMean)
colMean = tmpList
sumDF.insert(0, 'Mean0', colMean)
sumDF['Mean0'].iloc[:indexLoc -1] = sumDF.iloc[:indexLoc -1, -1]
if statMedian:
colMedian = sumDF.iloc[indexLoc:].median(axis= 1).tolist()
tmpList = [0] * indexLoc
tmpList.extend(colMedian)
colMedian = tmpList
sumDF.insert(0, 'Median0', colMedian)
sumDF['Median0'].iloc[:indexLoc -1] = sumDF.iloc[:indexLoc -1, -1]
if statOnly and ('Mean0' in sumDF.columns.values.tolist() or 'Median0' in sumDF.columns.values.tolist()):
for col in sumDF:
if col == 'Median0' or col == 'Mean0':
pass
else:
sumDF.drop([col], axis= 1, inplace= True)
if srcPltGrouped[i]['trace'][0] == 'Scatter Plot':
for col in sumDF.columns.values.tolist():
if sumDF[col].loc['tracefill']:
styleFill = 'tonexty'
else:
styleFill = 'none'
if sumDF[col].loc['tracestyle'] == 'Smooth Linear':
styleMode = 'lines'
styleLine = {'shape': 'spline'}
else:
styleMode = str(sumDF[col].loc['tracestyle']).replace('Only', '').replace(' ', '').strip().lower()
styleLine = {'shape': 'linear'}
figure.add_trace(plygo.Scatter(
x= sumDF[col].iloc[indexLoc:].index.tolist(),
y= sumDF[col].iloc[indexLoc:].values.tolist(),
connectgaps= False,
fill= styleFill,
mode= styleMode,
line= styleLine,
name= col[:-1]
), row= posRow, col= posCol)
#elif sumDF[col].loc['tracetype'] == 'Bar Chart':
if srcPltGrouped[i]['trace'][0] == 'Bar Chart':
for col in sumDF.columns.values.tolist():
figure.add_trace(plygo.Bar(
x= sumDF[col].iloc[indexLoc:].index.tolist(),
y= sumDF[col].iloc[indexLoc:].values.tolist(),
text= sumDF[col].iloc[indexLoc:].values.tolist(),
texttemplate= '%{y:,.2d}',
textfont_color= '#000000',
textposition= 'inside',
name= col[:-1]
), row= posRow, col= posCol)
figure.update_layout({'barmode': str(sumDF[col].loc['tracestyle'])[:-2].replace(' ', '').strip().lower()})
#elif sumDF[col].loc['tracetype'] == 'Pie Chart':
if srcPltGrouped[i]['trace'][0] == 'Pie Chart':
for col in sumDF.columns.values.tolist():
if sumDF[col].loc['tracestyle'] == 'Domain':
styleMode = 0
holeSize = 0.1
else:
styleMode = 0.05
holeSize = 0
figure.add_trace(plygo.Pie(
labels= labelsData,
values= valuesData,
texttemplate= templateFormat,
hole= holeSize,
pull= styleMode,
))
#elif sumDF[col].loc['tracetype'] == 'Box Plot':
if srcPltGrouped[i]['trace'][0] == 'Box Plot':
print(sumDF)
break
for col in sumDF.columns.values.tolist():
figure.add_trace(plygo.Box(
x= '',
y= '',
boxpoints= '',
names= '',
jitter= 0.3
))
### update layout & axes
figure.update_xaxes({'title_text': xTitle, 'tickmode': sumDF.loc['xtick'].values.tolist()[0], 'tick0': 0, 'dtick': sumDF.loc['xstep'].values.tolist()[0], 'tickangle': -45}, row= posRow, col= posCol)
figure.update_yaxes({'title_text': yTitle, 'tickmode': sumDF.loc['ytick'].values.tolist()[0], 'tick0': 0, 'dtick': sumDF.loc['ystep'].values.tolist()[0], 'tickangle': 0}, row= posRow, col= posCol)
figure.update_layout(
uniformtext_minsize=18,
font_size= srcFig['font'],
width= srcFig['width'],
height= srcFig['height'],
title= srcFig['name'],
showlegend= visibleLegend,
template= pio.templates['simple_white'])
return figure
def PlotterCollective (srcFig= dict, srcStd= list, xDataSrc= str, xRange= list, traceStyle= str, visibleLegend= bool, visibleTitle= bool):
if xDataSrc == 'Energy Balance (per Index)':
indexList = ['Coal', 'Oil', 'N.Gas', 'Biomass', 'Renewable']
SumDF = pd.DataFrame(0, index= indexList, columns=['test'])
for study in range(len(srcStd)):
stdDF = pd.read_csv(srcStd[study]['path'], delimiter=',', low_memory=False, index_col='Index')
rangeStart = stdDF.index.get_loc('TotalAnnualCosts')
rangeStart = rangeStart + stdDF.iloc[rangeStart:rangeStart+100].index.get_loc(indexList[0])
rangeEnd = stdDF.iloc[rangeStart:rangeStart+100].index.get_loc(indexList[-1])
rangeEnd = rangeEnd + rangeStart +1
xData = stdDF.iloc[rangeStart:rangeEnd].index.values.tolist()
stdDF = stdDF.iloc[rangeStart:rangeEnd]
stdDF = stdDF.loc[:, 'g1_Total']
SumDF.insert(0, 'std' + str(study), stdDF)
SumDF.drop(['test'], axis= 1, inplace=True)
xRangeTarget = SumDF.index.values.tolist()
for j in range(len(xRangeTarget)):
if xRangeTarget[j] not in xRange:
SumDF.drop([xRangeTarget[j]], axis= 0, inplace=True)
figure = make_subplots()
if traceStyle == 'Whiskers & Points':
styleMode = 'all'
elif traceStyle == 'Whiskers':
styleMode = False
elif traceStyle == 'OutLiers':
styleMode = 'suspectedoutliers'
elif traceStyle == 'Whiskers & OutLiers':
styleMode = 'outliers'
for i in range(len(SumDF.index.values.tolist())):
xDataSeries = []
for num1 in range(len(SumDF.columns.values.tolist())):
xDataSeries.append(xData[i])
figure.add_trace(plygo.Box(
x= xDataSeries,
y= SumDF.iloc[i].tolist(),
boxpoints= styleMode,
name= xData[i],
jitter= 0.3
))
figure.update_yaxes({'title_text': '(TWh\Year)'})
figure.update_layout(
uniformtext_minsize=18,
font_size= srcFig['font'],
width= srcFig['width'],
height= srcFig['height'],
title= srcFig['name'],
showlegend= visibleLegend,
template= pio.templates['simple_white'])
return figure
elif xDataSrc == 'Installed Capacities (per Index)':
list1 = ['InputCapPpEl', 'InputCapChp2El', 'InputCapChp3El', 'InputCapPp2El', 'InputNuclearCap', 'InputGeopowerCap', 'InputHydroCap', 'InputRes1Capacity', 'InputRes2Capacity', 'InputRes3Capacity', 'InputRes4Capacity', 'InputRes5Capacity', 'InputRes6Capacity', 'InputRes7Capacity', 'InputCapHp2El', 'InputCapHp3El', 'InputCapElttransEl', 'InputEh2', 'InputEh3', 'InputCapBoiler2Th', 'InputCapBoiler3Th', 'InputCapChp2Thermal', 'InputCapChp3Thermal']
list2 = ['PP1', 'CHP2', 'CHP3', 'PP2', 'Nuclear', 'Geopower', 'Hydro', 'Res1', 'Res2', 'Res3', 'Res4', 'Res5', 'Res6', 'Res7', 'Heat Pump 2', 'Heat Pump 3', 'Electrolysers', 'Boiler 2', 'Boiler 3 ', 'Boiler 2 Thermal', 'Boiler 3 Thermal', 'CHP2 Thermal', 'CHP3 Thermal']
SumDF = pd.DataFrame(0, index= list1, columns=['test'])
for study in range(len(srcStd)):
stdDF = pd.read_csv(srcStd[study]['path'], delimiter=',', low_memory=False, index_col='Index')
rangeStart = stdDF.index.get_loc(list1[0])
rangeEnd = stdDF.index.get_loc(list1[-1]) +1
stdDF = stdDF.iloc[rangeStart:rangeEnd]
stdDF = stdDF.loc[:, 'g0-Data1']
stdDF = stdDF.astype(float)
SumDF.insert(0, 'std' + str(study), stdDF)
SumDF.drop(['test'], axis= 1, inplace=True)
SumDF.rename(index= dict(zip(list1, list2)), inplace= True)
xRangeTarget = SumDF.index.values.tolist()
for j in range(len(xRangeTarget)):
if xRangeTarget[j] not in xRange:
SumDF.drop([xRangeTarget[j]], axis= 0, inplace=True)
SumDF.sort_index(axis=0, inplace=True)
xData = SumDF.index.values.tolist()
figure = make_subplots()
if traceStyle == 'Whiskers & Points':
styleMode = 'all'
elif traceStyle == 'Whiskers':
styleMode = False
elif traceStyle == 'OutLiers':
styleMode = 'suspectedoutliers'
elif traceStyle == 'Whiskers & OutLiers':
styleMode = 'outliers'
for i in range(len(SumDF.index.values.tolist())):
xDataSeries = []
for num1 in range(len(SumDF.columns.values.tolist())):
xDataSeries.append(xData[i])
figure.add_trace(plygo.Box(
x= xDataSeries,
y= SumDF.iloc[i].tolist(),
boxpoints= styleMode,
name= xData[i],
jitter= 0.3
))
figure.update_yaxes({'title_text': '(MW)'})
figure.update_layout(
uniformtext_minsize=18,
font_size= srcFig['font'],
width= srcFig['width'],
height= srcFig['height'],
title= srcFig['name'],
showlegend= visibleLegend,
template= pio.templates['simple_white'])
return figure
elif xDataSrc == 'Total Elect. Demand':
SumDF = pd.DataFrame(0, index= ['test'], columns=['0001_ElectrDemand', '0002_ElecdemCooling', '0003_FixedExp/Imp', '0020_FlexibleElectr', '1802_HH-HPElectr', '1804_HH-EBElectr'])
for study in range(len(srcStd)):
stdDF = pd.read_csv(srcStd[study]['path'], delimiter=',', low_memory=False, index_col='Index')
stdValues = stdDF.loc['Annual', ['0001_ElectrDemand', '0002_ElecdemCooling', '0003_FixedExp/Imp', '0020_FlexibleElectr', '1802_HH-HPElectr', '1804_HH-EBElectr']].tolist()
SumDF.loc[srcStd[study]['name']] = stdValues
SumDF.drop(['test'], axis= 0, inplace=True)
figure = make_subplots()
if traceStyle == 'Whiskers & Points':
styleMode = 'all'
elif traceStyle == 'Whiskers':
styleMode = False
elif traceStyle == 'OutLiers':
styleMode = 'suspectedoutliers'
elif traceStyle == 'Whiskers & OutLiers':
styleMode = 'outliers'
for i in range(len(SumDF.index.values.tolist())):
figure.add_trace(plygo.Box(
y= SumDF.iloc[i].tolist(),
boxpoints= styleMode,
name= SumDF.index[i],
jitter= 0.3
))
figure.update_yaxes({'title_text': '(TWh\Year)'})
figure.update_layout(
uniformtext_minsize=18,
font_size= srcFig['font'],
width= srcFig['width'],
height= srcFig['height'],
title= srcFig['name'],
showlegend= visibleLegend,
template= pio.templates['simple_white'])
return figure
elif xDataSrc == 'Total Heat Demand':
SumDF = pd.DataFrame(0, index= ['test'], columns=['0004_DHDemand', '1701_HHDemHeat'])
for study in range(len(srcStd)):
stdDF = pd.read_csv(srcStd[study]['path'], delimiter=',', low_memory=False, index_col='Index')
stdValues = stdDF.loc['Annual', ['0004_DHDemand', '1701_HHDemHeat']].tolist()
SumDF.loc[srcStd[study]['name']] = stdValues
SumDF.drop(['test'], axis= 0, inplace=True)
figure = make_subplots()
if traceStyle == 'Whiskers & Points':
styleMode = 'all'
elif traceStyle == 'Whiskers':
styleMode = False
elif traceStyle == 'OutLiers':
styleMode = 'suspectedoutliers'
elif traceStyle == 'Whiskers & OutLiers':
styleMode = 'outliers'
for i in range(len(SumDF.index.values.tolist())):
figure.add_trace(plygo.Box(
y= SumDF.iloc[i].tolist(),
boxpoints= styleMode,
name= SumDF.index[i],
jitter= 0.3
))
figure.update_yaxes({'title_text': '(TWh\Year)'})
figure.update_layout(
uniformtext_minsize=18,
font_size= srcFig['font'],
width= srcFig['width'],
height= srcFig['height'],
title= srcFig['name'],
showlegend= visibleLegend,
template= pio.templates['simple_white'])
return figure