-
Notifications
You must be signed in to change notification settings - Fork 1
/
plotting.py
3337 lines (3081 loc) · 134 KB
/
plotting.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
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import numpy as np
from util import *
# MODULES
from network_representation import project_graph, gdfs_from_graph, load_simplified_consolidated_graph
from helper import load_lca_battery_lookup, load_elec_cost_state_df
'''
TO RUN, USE THESE COMMANDS:
from alpha_framework import *
from GUI_trial import *
G = run_scenario('BNSF', radius=10000, D=250*1.6, freq='Y') # only need to chance RR name and D for this...
f = plot_facility_nx_size(G)
'''
# global color assignment
# blue, red, orange, green, purple, teal, pink, olive, darkred, darkblue = plotly.colors.qualitative.G10
# '#8E77B2', '#F9F7FB'; mid purple, light purple
[purple, mid_purple, light_purple,
green1, green2, green3, green4, green5,
red, light_red, black] = ['#512D88', '#DAD0E6', '#ECE6F4',
'#9AD470', '#75D431', '#719B52', '#4A871F', '#2E5413',
'#FF3033', '#FF787A', '#18141C']
'''
MASTER PLOT
'''
def plot_scenario(G: nx.DiGraph, fuel_type: str, deployment_perc: float, comm_group: str = None,
fig=None, additional_plots=True, figlist=True, legend_show=True):
if fuel_type == 'battery':
fig = battery_plot(G, comm_group=comm_group, additional_plots=additional_plots, figlist=figlist,
fig=fig, legend_show=legend_show)
elif fuel_type == 'hydrogen':
fig = hydrogen_plot(G, comm_group=comm_group, additional_plots=additional_plots, figlist=figlist,
fig=fig, legend_show=legend_show)
elif 'hybrid' in fuel_type:
fig = hybrid_plot(G, comm_group=comm_group, additional_plots=additional_plots, figlist=figlist,
fig=fig, legend_show=legend_show)
elif fuel_type == 'diesel' or fuel_type == 'biodiesel' or fuel_type == 'e-fuel':
fig = dropin_plot(G, fuel_type=fuel_type, deployment_perc=deployment_perc, comm_group=comm_group,
additional_plots=additional_plots, figlist=figlist, fig=fig,
legend_show=legend_show)
return fig
'''
BATTERY PLOT
'''
def battery_pie_operations_plot(G, comm_group: str, fig=None):
if fig is None:
fig = make_subplots(
rows=1, cols=1,
specs=[[{"type": "domain"}]],
)
row = 1
col = 1
else:
row = 3
col = 1
labels = ['Battery', 'Diesel']
support_diesel_tonmi = G.graph['operations']['support_diesel_total_tonmi'][comm_group]
battery_tonmi = G.graph['operations']['alt_tech_total_tonmi'][comm_group]
# use the one below if it is desired to adjust the ton-miles to reflect the baseline ton-miles
# battery_tonmi = ((1 - G.graph['operations']['perc_tonmi_inc'] / 100) *
# G.graph['operations']['alt_tech_total_tonmi'][comm_group])
values = [battery_tonmi * 365 / 1e6,
support_diesel_tonmi * 365 / 1e6]
fig.add_trace(
go.Pie(
labels=labels,
values=values,
marker=dict(colors=[green4, purple]),
textinfo='label+percent',
textposition='inside',
hovertemplate='<b>%{label}</b> <br> %{value:.0f} [M ton-mi/yr]',
name='',
showlegend=False
),
row=row, col=col
)
fig.update_layout(font_color=black,
autosize=True,
margin=dict(l=30, r=30, b=0, t=20, pad=1),
legend=dict(
orientation='h',
yanchor='bottom',
y=0,
xanchor='center',
x=0.5
),
title=dict(
text=comm_group.capitalize() + ' Ton-Miles',
font=dict(size=16, color=black),
y=1,
x=0.5,
yanchor='top',
xanchor='center',
pad=dict(t=15, b=5)
)
)
return fig
def battery_tea_plot(G, comm_group: str, fig=None, legend_show=True):
# compute aggregate statistics to plot and be able to compare between battery and diesel
if fig is None:
fig = make_subplots(
rows=1, cols=1,
specs=[[{"type": "bar"}]],
)
row = 1
col = 1
else:
row = 2
col = 2
fig.add_trace(
go.Bar(x=['Diesel', 'Battery'],
y=[0,
G.graph['energy_source_TEA']['station_LCO_tonmi'][comm_group] * 100],
name='Station',
hovertemplate='%{y:.2f} [¢/ton-mi]',
# showlegend=False,
marker=dict(color=green5)
),
row=row, col=col
)
fig.add_trace(
go.Bar(x=['Diesel', 'Battery'],
y=[0,
G.graph['energy_source_TEA']['om_LCO_tonmi'][comm_group] * 100],
name='Station O&M',
hovertemplate='%{y:.2f} [¢/ton-mi]',
# showlegend=False,
marker=dict(color=green2)
),
row=row, col=col
)
fig.add_trace(
go.Bar(x=['Diesel', 'Battery'],
y=[0,
G.graph['energy_source_TEA']['battery_LCO_tonmi'][comm_group] * 100],
name='Battery',
hovertemplate='%{y:.2f} [¢/ton-mi]',
# showlegend=False,
marker=dict(color=green3)
),
row=row, col=col
)
fig.add_trace(
go.Bar(x=['Diesel', 'Battery'],
y=[0,
G.graph['energy_source_TEA']['energy_LCO_tonmi'][comm_group] * 100],
name='Electricity',
hovertemplate='%{y:.2f} [¢/ton-mi]',
# showlegend=False,
marker=dict(color=green1)
),
row=row, col=col
)
fig.add_trace(
go.Bar(x=['Diesel', 'Battery'],
y=[0,
G.graph['energy_source_TEA']['delay_LCO_tonmi'][comm_group] * 100],
name='Delay',
hovertemplate='%{y:.2f} [¢/ton-mi]',
# showlegend=False,
marker=dict(color=red)
),
row=row, col=col
)
fig.add_trace(
go.Bar(x=['Diesel', 'Battery'],
y=[G.graph['diesel_TEA']['fuel_LCO_tonmi'][comm_group] * 100,
0],
name='Fuel',
hovertemplate='%{y:.2f} [¢/ton-mi]',
# showlegend=False,
marker=dict(color=purple)
),
row=row, col=col
)
# Scenario average
fig.add_shape(type='line',
xref='paper', yref='y',
x0=-.5, y0=G.graph['energy_source_TEA']['total_scenario_LCO_tonmi'][comm_group] * 100,
x1=1.5, y1=G.graph['energy_source_TEA']['total_scenario_LCO_tonmi'][comm_group] * 100,
line=dict(color=black, width=2, dash='dash'),
opacity=1,
name='Scenario Average',
row=row, col=col
)
fig.add_trace(
go.Scatter(x=['Battery'],
y=[G.graph['energy_source_TEA']['total_scenario_LCO_tonmi'][comm_group] * 100],
mode='markers',
marker=dict(symbol='line-ew', size=6, line_width=2, opacity=1, color=black, line_color=black),
# opacity=1,
name='Scenario <br> Average',
hovertemplate='%{y:.2f} [¢/ton-mi]',
# showlegend=False
),
row=row, col=col
)
fig.update_layout(barmode='stack',
font=dict(color=black, size=12),
autosize=True,
margin=dict(l=20, r=0, b=0, t=50, pad=0),
showlegend=legend_show,
legend=dict(
orientation='h',
yanchor='top',
y=1,
xanchor='right',
x=1.9,
font=dict(size=10)
),
title=dict(
text='Levelized Cost <br> of Operation',
font=dict(size=16, color=black),
y=1,
x=0.5,
yanchor='top',
xanchor='center',
pad=dict(t=15, b=5)
)
)
# fig.add_annotation(hovertext='Scenario Average: ' +
# str(round(G.graph['energy_source_TEA']['total_scenario_LCO_tonmi'][comm_group] * 100,
# 2)) + ' [¢/ton-mi]',
# # text='Scenario Average',
# text='',
# xref='paper', yref='y',
# x=1.5, y=G.graph['energy_source_TEA']['total_scenario_LCO_tonmi'][comm_group] * 100,
# xanchor='left', yanchor='middle',
# arrowcolor=black,
# font=dict(color=black),
# showarrow=False,
# row=row, col=col
# )
# update yaxis properties
fig.update_yaxes(title=dict(text='[¢ / ton-mi]', standoff=10,
font=dict(size=12)), showgrid=False, row=row, col=col)
return fig
def battery_lca_plot(G, comm_group: str, fig=None, legend_show=True):
# compute aggregate statistics to plot and be able to compare between battery and diesel
if fig is None:
fig = make_subplots(
rows=1, cols=1,
specs=[[{"type": "xy", 'secondary_y': True}]],
)
row = 1
col = 1
else:
row = 2
col = 1
# ton CO2
fig.add_trace(
go.Bar(x=['100% Diesel', 'Scenario'],
y=[G.graph['diesel_LCA']['annual_total_emissions_tonco2'][comm_group] / 1e3,
G.graph['energy_source_LCA']['annual_support_diesel_total_emissions'][comm_group] / 1e3],
name='Diesel',
hovertemplate='%{y:.0f} [kton CO<sub>2</sub>/yr]',
# showlegend=False,
marker=dict(color=purple)
),
row=row, col=col
)
fig.add_trace(
go.Bar(x=['100% Diesel', 'Scenario'],
y=[0,
G.graph['energy_source_LCA']['annual_battery_total_emissions'][comm_group] / 1e3],
name='Electric Grid',
hovertemplate='%{y:.0f} [kton CO<sub>2</sub>/yr]',
# showlegend=False,
marker=dict(color=green4)
),
secondary_y=False,
row=row, col=col
)
# ton CO2 /tonmile
fig.add_trace(
go.Scatter(x=['100% Diesel', 'Scenario'],
y=[1e6 * G.graph['diesel_LCA']['emissions_tonco2_tonmi'][comm_group],
1e6 * G.graph['energy_source_LCA']['avg_emissions_tonco2_tonmi'][comm_group]],
mode='markers',
marker=dict(symbol='diamond', size=10, color=light_red),
name='WTW Emissions Rate',
hovertemplate='%{y:.2f} [g CO<sub>2</sub>/ton-mi]',
showlegend=False
),
secondary_y=True,
row=row, col=col
)
fig.update_layout(barmode='stack',
font_color=black,
autosize=True,
margin=dict(l=0, r=0, b=0, t=50, pad=1),
showlegend=legend_show,
legend=dict(
orientation='h',
yanchor='top',
y=1.2,
xanchor='center',
x=0.5,
font=dict(size=10)),
title=dict(
text='WTW Emissions',
font=dict(size=16, color=black),
y=1,
x=0.5,
yanchor='top',
xanchor='center',
pad=dict(b=30)
)
)
# update yaxis properties
fig.update_yaxes(title=dict(text='[kton CO<sub>2</sub>]', standoff=10,
font=dict(size=12)), secondary_y=False, showgrid=False,
row=row, col=col
)
fig.update_yaxes(title=dict(text='[g CO<sub>2</sub> / ton-mi]', standoff=10,
font=dict(size=12, color=light_red)),
tickfont=dict(color=light_red), showgrid=False,
range=[0, np.ceil(1e6 * G.graph['diesel_LCA']['total_emissions_tonco2_tonmi'][comm_group] /
10) * 10],
secondary_y=True,
row=row, col=col
)
return fig
def battery_summary_table(G: nx.DiGraph, comm_group: str, fig=None):
# plot table of summary of results for battery
if fig is None:
fig = make_subplots(
rows=1, cols=1,
specs=[[{"type": "table"}]]
)
row = 1
col = 1
else:
row = 4
col = 1
des_tea = G.graph['energy_source_TEA']
fig.add_trace(
go.Table(
header=dict(values=['Scenario Summary', 'Statistics'],
font=dict(size=14),
line_color=black,
fill_color=mid_purple,
),
cells=dict(values=[[
'Cost of Avoided Emissions',
'# of Charging Facilities',
'Emissions Reduction' if G.graph['operations']['emissions_change'][comm_group] >= 0
else 'Emissions Increase',
'Average Route Distance Increase',
'# of Chargers',
'Average Charger Utilization',
'Station Capital Cost',
'Total Delay Cost',
'Total Annual Cost',
'Avg. Charge Time per Loc',
'Avg. Queue Time',
'Avg. Queue Length',
'Peak Queue Time',
'Peak Queue Length',
'Avg. Daily Delay Cost per Car'
],
[
str(round(G.graph['operations']['cost_avoided_emissions'][comm_group], 2)) +
' [$/kg CO<sub>2</sub>]',
str(sum([G.nodes[n]['facility'] for n in G])) + ' out of ' + str(G.number_of_nodes()),
str(round(abs(G.graph['operations']['emissions_change'][comm_group]), 2)) + ' %',
str(round(G.graph['operations']['perc_mi_inc'][comm_group], 2)) + ' %',
des_tea['number_chargers'],
str(round(des_tea['actual_utilization'] * 24, 1)) + ' [hrs/day]',
str(round(des_tea['station_total'] / 1e6, 2)) + ' [$M]',
str(round(des_tea['total_annual_delay_cost'] / 1e6, 3)) + ' [$M]',
str(round(des_tea['annual_total_cost'][comm_group] / 1e6, 2)) + ' [$M]',
str(round(des_tea['charge_time'], 2)) + ' [hr]',
str(round(des_tea['avg_queue_time_p_loc'], 3)) + ' [hr]',
str(round(des_tea['avg_queue_length'], 3)) + ' [loc]',
str(round(des_tea['peak_queue_time_p_loc'], 3)) + ' [hr]',
str(round(des_tea['peak_queue_length'], 3)) + ' [loc]',
str(round(des_tea['avg_daily_delay_cost_p_car'], 2)) + ' [$]'
]],
font=dict(size=12),
line_color=black,
fill_color=light_purple,
)
),
row=row, col=col
)
fig.update_layout(font_color=black,
autosize=True,
margin=dict(l=5, r=5, b=5, t=5, pad=1)
)
return fig
def battery_cost_avoided_table(G, comm_group: str, fig=None):
if fig is None:
fig = make_subplots(
rows=1, cols=1,
specs=[[{"type": "table"}]]
)
row = 1
col = 1
else:
row = 3
col = 2
fig.add_trace(
go.Table(
header=dict(values=['Cost of Avoided Emissions'],
font=dict(size=14),
line_color=black,
fill_color=mid_purple,
),
cells=dict(values=[[str(round(G.graph['operations']['cost_avoided_emissions'][comm_group], 2)) +
' [$/kg CO<sub>2</sub>]'
]],
font=dict(size=12),
line_color=black,
fill_color=light_purple,
)
),
row=row, col=col
)
fig.update_layout(font_color=black,
autosize=True,
# width=400,
# height=400,
margin=dict(l=5, r=5, b=5, t=5, pad=1)
)
return fig
def battery_plot(G, comm_group: str, additional_plots=True, crs='WGS84', figlist=False, fig=None, legend_show=True):
# fig.add_trace(go.Scattermapbox(lon=xs, lat=ys, mode='lines', hoverinfo="text", hovertext=caption))
if fig is None:
if additional_plots and not figlist:
fig = make_subplots(
rows=4, cols=3,
specs=[[None, None, {"type": "scattergeo", "rowspan": 4}],
[{"type": "xy", 'secondary_y': True}, {"type": "bar"}, None],
[{"type": "domain"}, {"type": "table"}, None],
[{"type": "table", 'colspan': 2}, None, None]],
column_widths=[0.1, 0.1, 0.8],
row_heights=[0.02, 0.25, 0.25, 0.48],
horizontal_spacing=0.1,
subplot_titles=(None,
'WTW Emissions', 'Levelized Cost of Operation',
comm_group.capitalize() + ' Ton-Miles', None,
None)
)
row = 1
col = 3
else:
t0 = time.time()
fig = base_plot(G.graph['railroad'])
print('\t LOAD BASE PLOT:: ' + str(time.time() - t0))
row = 1
col = 1
# fig = plot_states_bg()
# G = project_graph(G.copy(), to_crs=crs)
t0 = time.time()
nodes_gdf, edges_gdf = gdfs_from_graph(G, crs=crs, smooth_geometry=False)
print('GDF EXTRACTION:: ' + str(time.time() - t0))
t0 = time.time()
# drop non-covered edges
edges_gdf.drop(index=edges_gdf[edges_gdf['covered'] == 0].index, inplace=True)
# keep only these cols
agg_cols = {'miles': 'first', 'geometry': 'first',
'battery_avg_ton': 'sum', 'battery_avg_loc': 'sum',
'support_diesel_avg_ton': 'sum'}
edges_gdf.drop(columns=set(edges_gdf.columns).difference(set(agg_cols.keys())), inplace=True)
# convert cols from dict to float values for the <comm_group> provided
dict_cols = ['battery_avg_ton', 'battery_avg_loc', 'support_diesel_avg_ton']
for col in dict_cols:
edges_gdf[col] = edges_gdf[col].apply(lambda x: x[comm_group])
# create a dict to map {(u, v): (u, v), (v, u): (u, v)}
edge_mapper = dict()
for u, v in edges_gdf.index:
if (u, v) not in edge_mapper.keys():
edge_mapper[u, v] = (u, v)
edge_mapper[v, u] = (u, v)
# map indices
edges_gdf.rename(index=edge_mapper, inplace=True)
edges_gdf.fillna(0, inplace=True)
# groupby (u, v), summing values of 'battery_avg_ton', 'battery_avg_loc', 'support_diesel_avg_ton'
edges_gdf.groupby(by=['u', 'v']).agg(agg_cols)
# compute 'share_battery'
edges_gdf['share_battery'] = 100 * edges_gdf['battery_avg_ton'].div(edges_gdf['support_diesel_avg_ton'] +
edges_gdf['battery_avg_ton']).replace(np.inf,
0.00)
edges_gdf['share_battery'] = edges_gdf['share_battery'].fillna(0.00)
# assign line width to each edge based on battery flow tonnage
edges_gdf['line_width'] = edges_gdf['battery_avg_ton'].apply(lambda x: line_size(x))
# reset index
edges_gdf.reset_index(inplace=True)
# groupby line_width groups and (u, v)
edges_gdf = edges_gdf.groupby(by=['line_width', 'u', 'v']).first()
# get line widths
line_widths = sorted(list(set(edges_gdf.index.get_level_values('line_width'))))
legend_name = 'Battery Network'
lg_group = 1
for lw in line_widths:
e = edges_gdf.loc[lw, slice(None, None)]
lats = []
lons = []
names = []
for u, v in e.index:
x, y = e.loc[(u, v), 'geometry'].xy
lats = np.append(lats, y)
lons = np.append(lons, x)
name = '{v1} miles <br>{v2} {v3} tons/day <br>{v4} {v5} loc/day <br>' \
'Share of {v6} tons moved by battery: {v7}%'.format(v1=round(e.loc[(u, v), 'miles']),
v2=round(e.loc[(u, v), 'battery_avg_ton']),
v3=comm_group.capitalize(),
v4=round(e.loc[(u, v), 'battery_avg_loc']),
v5=comm_group.capitalize(),
v6=comm_group.lower(),
v7=round(e.loc[(u, v), 'share_battery']))
names = np.append(names, [name] * len(y))
lats = np.append(lats, None)
lons = np.append(lons, None)
names = np.append(names, None)
fig.add_trace(
go.Scattergeo(
lon=lons,
lat=lats,
mode='lines',
line=dict(
width=lw,
color=green4,
),
opacity=1,
hoverinfo="text",
hovertext=names,
legendgroup=lg_group,
name=legend_name,
showlegend=lw == 2,
connectgaps=False,
)
)
print('\t EDGES:: ' + str(time.time() - t0))
legend_bool = [True, True]
# od_set = {u for u, _ in G.graph['framework']['ods']}.union({v for _, v in G.graph['framework']['ods']})
t0 = time.time()
for i in range(len(nodes_gdf)):
n = nodes_gdf.loc[nodes_gdf.index[i]]
if n['facility'] == 1:
if n['avg']['energy_transfer'] == 1:
avg_charged_mwh = -n['avg']['daily_demand_mwh']
peak_charged_mwh = -n['peak']['daily_demand_mwh']
else:
avg_charged_mwh = n['avg']['daily_supply_mwh']
peak_charged_mwh = n['peak']['daily_supply_mwh']
if (n['energy_source_TEA']['avg_queue_time_p_loc'] is not None) and (
n['energy_source_TEA']['peak_queue_time_p_loc'] is not None):
text = n['city'] + ', ' + n['state'] + '<br>' + \
str(round(avg_charged_mwh, 2)) + ' MWh/day <br>' + \
str(int(n['avg']['number_loc'])) + ' loc/day <br>' + \
str(n['energy_source_TEA']['number_chargers']) + ' chargers <br>' + \
'Avg. Queue Time: ' + str(
round(n['energy_source_TEA']['avg_queue_time_p_loc'], 2)) + ' hrs <br>' + \
'Avg. Queue Length: ' + str(round(n['energy_source_TEA']['avg_queue_length'], 2)) + ' loc <br>' + \
'Peak Queue Time: ' + str(round(n['energy_source_TEA']['peak_queue_time_p_loc'], 2)) + \
' hrs <br>' + \
'Peak Queue Length: ' + str(
round(n['energy_source_TEA']['peak_queue_length'], 2)) + ' loc <br>' + \
'Utilized ' + str(
round(n['energy_source_TEA']['actual_utilization'] * 24, 1)) + ' hrs/day <br>' + \
'Total LCO: ' + str(round(n['energy_source_TEA']['total_LCO'], 3)) + ' $/kWh <br>' + \
'WTW Emissions: ' + str(round(n['energy_source_LCA']['emissions_tonco2_kwh'] * 1e6, 3)) + \
' g CO<sub>2</sub>' + '/kWh <br>' + \
'Capital Cost: \t $' + str(round(n['energy_source_TEA']['station_total'] / 1e6, 2)) + ' M <br>' + \
'Avg. Delay cost per car: \t $' + \
str(round(n['energy_source_TEA']['avg_daily_delay_cost_p_car'], 2)) + '<br>' + \
'Avg. Daily Delay cost per loc: \t $' + \
str(round(n['energy_source_TEA']['avg_daily_delay_cost_p_loc'], 2)) + '<br>' + \
'Total Daily Delay Cost: \t $' + \
str(round(n['energy_source_TEA']['total_daily_delay_cost'] / 1e3, 2)) + ' K<br>'
else:
text = n['city'] + ', ' + n['state'] + '<br>' + \
str(round(avg_charged_mwh, 2)) + ' MWh/day <br>' + \
str(int(n['avg']['number_loc'])) + ' loc/day <br>' + \
str(n['energy_source_TEA']['number_chargers']) + ' chargers <br>' + \
'Avg. Queue Time: ' + str(
round(0, 2)) + ' hrs <br>' + \
'Avg. Queue Length: ' + str(round(0, 2)) + ' loc <br>' + \
'Peak Queue Time: ' + str(round(0, 2)) + \
' hrs <br>' + \
'Peak Queue Length: ' + str(
round(0, 2)) + ' loc <br>' + \
'Utilized ' + str(
round(n['energy_source_TEA']['actual_utilization'] * 24, 1)) + ' hrs/day <br>' + \
'Total LCO: ' + str(round(n['energy_source_TEA']['total_LCO'], 3)) + ' $/kWh <br>' + \
'WTW Emissions: ' + str(round(n['energy_source_LCA']['emissions_tonco2_kwh'] * 1e6, 3)) + \
' g CO<sub>2</sub>' + '/kWh <br>' + \
'Capital Cost: \t $' + str(round(n['energy_source_TEA']['station_total'] / 1e6, 2)) + ' M <br>' + \
'Avg. Delay cost per car: \t $' + \
str(round(0, 2)) + '<br>' + \
'Avg. Daily Delay cost per loc: \t $' + \
str(round(0, 2)) + '<br>' + \
'Total Daily Delay Cost: \t $' + \
str(round(0, 2)) + ' K<br>'
fig.add_trace(
go.Scattergeo(
uid=n['nodeid'],
locationmode='USA-states',
lon=[n['geometry'].x],
lat=[n['geometry'].y],
hovertemplate=text,
# mode='markers+text',
# text=str(round(n['energy_source_TEA']['number_chargers'])),
# textfont=dict(color='black', size=14),
marker=dict(
size=5 * np.log(peak_charged_mwh + 10),
# size=25,
color=green4,
sizemode='area',
),
# opacity=1,
opacity=0.8,
legendgroup=lg_group,
name='Charging Facility',
showlegend=legend_bool[0],
),
# row=row, col=col
)
legend_bool[0] = False
print('\t FACILITY NODES:: ' + str(time.time() - t0))
t0 = time.time()
for i in range(len(nodes_gdf)):
n = nodes_gdf.loc[nodes_gdf.index[i]]
if n['covered'] == 1:
text = n['city'] + ', ' + n['state']
lg_group = 1
fig.add_trace(
go.Scattergeo(
uid=n['nodeid'],
locationmode='USA-states',
lon=[n['geometry'].x],
lat=[n['geometry'].y],
hoverinfo='skip',
# hovertemplate=text,
marker=dict(size=6,
color=green4,
symbol='square'),
legendgroup=lg_group,
name='Covered (Non-Charging) Facility',
showlegend=legend_bool[1],
),
# row=row, col=col
)
legend_bool[1] = False
print('\t COVERED NODES:: ' + str(time.time() - t0))
if additional_plots:
if figlist:
fig.update_geos(projection_type="albers usa")
fig.update_layout(
autosize=True,
margin=dict(l=0, r=0, b=300, t=0, pad=1),
showlegend=legend_show,
legend=dict(
itemsizing='trace',
orientation='h',
yanchor="top",
y=0.95,
xanchor="center",
x=0.5,
font=dict(size=12, color=black)
),
)
for annotation in fig.layout.annotations:
annotation.font.size = 12
figs = [fig]
# table for summary statistics
figs.append(battery_summary_table(G=G, comm_group=comm_group))
# bar charts for LCA stats
figs.append(battery_lca_plot(G=G, comm_group=comm_group, legend_show=legend_show))
# bar charts for TEA stats
figs.append(battery_tea_plot(G=G, comm_group=comm_group, legend_show=legend_show))
# pie charts for operational stats
figs.append(battery_pie_operations_plot(G=G, comm_group=comm_group))
# table for cost of avoided emissions
figs.append(battery_cost_avoided_table(G=G, comm_group=comm_group))
fig = figs
else:
# pie charts for operational stats
fig = battery_pie_operations_plot(G=G, comm_group=comm_group, fig=fig)
# bar charts for LCA stats
fig = battery_lca_plot(G=G, comm_group=comm_group, fig=fig, legend_show=legend_show)
# bar charts for TEA stats
fig = battery_tea_plot(G=G, comm_group=comm_group, fig=fig, legend_show=legend_show)
# table for summary statistics
fig = battery_summary_table(G=G, comm_group=comm_group, fig=fig)
# table for cost of avoided emissions
fig = battery_cost_avoided_table(G=G, comm_group=comm_group, fig=fig)
fig.update_geos(projection_type="albers usa")
fig.update_layout(
showlegend=legend_show,
legend=dict(
itemsizing='trace',
yanchor='middle',
xanchor='right',
orientation='v',
x=.9,
y=0.5,
font=dict(size=12, color=black)
),
)
for annotation in fig.layout.annotations:
annotation.font.size = 12
labels = []
else:
fig.update_geos(projection_type="albers usa")
fig_title = ''
fig.update_layout(title=dict(text=fig_title, font=dict(color='black', size=6)), font=dict(color='black'),
showlegend=legend_show,
legend=dict(
yanchor='middle',
xanchor='right',
orientation='v',
x=.9,
y=0.5),
)
for annotation in fig.layout.annotations:
annotation.font.size = 12
return fig
def hybrid_pie_operations_plot(G, comm_group: str, fig=None):
if fig is None:
fig = make_subplots(
rows=1, cols=1,
specs=[[{"type": "domain"}]],
)
row = 1
col = 1
else:
row = 3
col = 1
labels = ['Hybrid', 'Diesel']
support_diesel_tonmi = G.graph['operations']['support_diesel_total_tonmi'][comm_group]
hybrid_tonmi = G.graph['operations']['alt_tech_total_tonmi'][comm_group]
# use the one below if it is desired to adjust the ton-miles to reflect the baseline ton-miles
# battery_tonmi = ((1 - G.graph['operations']['perc_tonmi_inc'] / 100) *
# G.graph['operations']['alt_tech_total_tonmi'][comm_group])
values = [hybrid_tonmi * 365 / 1e6,
support_diesel_tonmi * 365 / 1e6]
fig.add_trace(
go.Pie(
labels=labels,
values=values,
marker=dict(colors=[green4, purple]),
textinfo='label+percent',
textposition='inside',
hovertemplate='<b>%{label}</b> <br> %{value:.0f} [M ton-mi/yr]',
name='',
showlegend=False
),
row=row, col=col
)
fig.update_layout(font_color=black,
autosize=True,
margin=dict(l=30, r=30, b=0, t=20, pad=1),
legend=dict(
orientation='h',
yanchor='bottom',
y=0,
xanchor='center',
x=0.5
),
title=dict(
text=comm_group.capitalize() + ' Ton-Miles',
font=dict(size=16, color=black),
y=1,
x=0.5,
yanchor='top',
xanchor='center',
pad=dict(t=15, b=5)
)
)
return fig
def hybrid_tea_plot(G, comm_group: str, fig=None, legend_show=True):
# compute aggregate statistics to plot and be able to compare between battery and diesel
if fig is None:
fig = make_subplots(
rows=1, cols=1,
specs=[[{"type": "bar"}]],
)
row = 1
col = 1
else:
row = 2
col = 2
fig.add_trace(
go.Bar(x=['Diesel', 'Hybrid'],
y=[0,
G.graph['energy_source_TEA']['station_LCO_tonmi'][comm_group] * 100],
name='Station',
hovertemplate='%{y:.2f} [¢/ton-mi]',
# showlegend=False,
marker=dict(color=green5)
),
row=row, col=col
)
fig.add_trace(
go.Bar(x=['Diesel', 'Hybrid'],
y=[0,
G.graph['energy_source_TEA']['om_LCO_tonmi'][comm_group] * 100],
name='Station O&M',
hovertemplate='%{y:.2f} [¢/ton-mi]',
# showlegend=False,
marker=dict(color=green2)
),
row=row, col=col
)
fig.add_trace(
go.Bar(x=['Diesel', 'Hybrid'],
y=[0,
G.graph['energy_source_TEA']['battery_LCO_tonmi'][comm_group] * 100],
name='Battery',
hovertemplate='%{y:.2f} [¢/ton-mi]',
# showlegend=False,
marker=dict(color=green3)
),
row=row, col=col
)
fig.add_trace(
go.Bar(x=['Diesel', 'Hybrid'],
y=[0,
G.graph['energy_source_TEA']['energy_LCO_tonmi'][comm_group] * 100],
name='Electricity',
hovertemplate='%{y:.2f} [¢/ton-mi]',
# showlegend=False,
marker=dict(color=green1)
),
row=row, col=col
)
# fig.add_trace(
# go.Bar(x=['Diesel', 'Hybrid'],
# y=[0,
# G.graph['energy_source_TEA']['delay_LCO_tonmi'][comm_group] * 100],
# name='Delay',
# hovertemplate='%{y:.2f} [¢/ton-mi]',
# # showlegend=False,
# marker=dict(color=red)
# ),
# row=row, col=col
# )
fig.add_trace(
go.Bar(x=['Diesel', 'Hybrid'],
y=[G.graph['diesel_TEA']['fuel_LCO_tonmi'][comm_group] * 100,
G.graph['energy_source_TEA']['fuel_LCO_tonmi'][comm_group] * 100],
name='Fuel',
hovertemplate='%{y:.2f} [¢/ton-mi]',
# showlegend=False,
marker=dict(color=purple)
),
row=row, col=col
)
# Scenario average
fig.add_shape(type='line',
xref='paper', yref='y',
x0=-.5, y0=G.graph['energy_source_TEA']['total_scenario_nodelay_LCO_tonmi'][comm_group] * 100,
x1=1.5, y1=G.graph['energy_source_TEA']['total_scenario_nodelay_LCO_tonmi'][comm_group] * 100,
line=dict(color=black, width=2, dash='dash'),
opacity=1,
name='Scenario Average',
row=row, col=col
)
fig.add_trace(
go.Scatter(x=['Hybrid'],
y=[G.graph['energy_source_TEA']['total_scenario_nodelay_LCO_tonmi'][comm_group] * 100],
mode='markers',
marker=dict(symbol='line-ew', size=6, line_width=2, opacity=1, color=black, line_color=black),
# opacity=1,
name='Scenario <br> Average',
hovertemplate='%{y:.2f} [¢/ton-mi]',
# showlegend=False
),
row=row, col=col
)
fig.update_layout(barmode='stack',
font=dict(color=black, size=12),
autosize=True,
margin=dict(l=20, r=0, b=0, t=50, pad=0),
showlegend=legend_show,
legend=dict(
orientation='h',
yanchor='top',
y=1,
xanchor='right',
x=1.9,
font=dict(size=10)
),
title=dict(
text='Levelized Cost <br> of Operation',
font=dict(size=16, color=black),
y=1,
x=0.5,
yanchor='top',
xanchor='center',
pad=dict(t=15, b=5)
)
)
# fig.add_annotation(hovertext='Scenario Average: ' +
# str(round(G.graph['energy_source_TEA']['total_scenario_LCO_tonmi'][comm_group] * 100,
# 2)) + ' [¢/ton-mi]',
# # text='Scenario Average',
# text='',
# xref='paper', yref='y',
# x=1.5, y=G.graph['energy_source_TEA']['total_scenario_LCO_tonmi'][comm_group] * 100,
# xanchor='left', yanchor='middle',
# arrowcolor=black,
# font=dict(color=black),
# showarrow=False,
# row=row, col=col
# )
# update yaxis properties
fig.update_yaxes(title=dict(text='[¢ / ton-mi]', standoff=10,
font=dict(size=12)), showgrid=False, row=row, col=col)
return fig
def hybrid_lca_plot(G, comm_group: str, fig=None, legend_show=True):
# compute aggregate statistics to plot and be able to compare between battery and diesel
if fig is None:
fig = make_subplots(
rows=1, cols=1,
specs=[[{"type": "xy", 'secondary_y': True}]],
)
row = 1
col = 1
else: