-
Notifications
You must be signed in to change notification settings - Fork 1
/
run.py
489 lines (429 loc) · 29.2 KB
/
run.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
from util import *
# MODULES
from helper import regional_alignments
from input_output import load_cached_graph, cache_graph, cache_exists, extract_assert_scenario_inputs
from network_representation import load_simplified_consolidated_graph
from routing import ods_by_perc_ton_mi, route_flows
from facility_deployment import facility_location
from facility_sizing import facility_sizing, facility_sizing_hybrid
from tea import tea_battery_all_facilities, tea_dropin, tea_hydrogen_all_facilities, tea_hybrid
from lca import lca_battery, lca_dropin, lca_hydrogen, lca_hybrid
from plotting import plot_scenario
def run_scenario_file(scenario_code: str, G: nx.DiGraph = None, plot=True, load_scenario=True, cache_scenario=False):
if load_scenario and cache_exists(scenario_code):
t0 = time.time()
G = load_cached_graph(scenario_code)
print('LOADED GRAPH FROM CACHE:: %s seconds ---' % round(time.time() - t0, 3))
[rr, fuel_type, deployment_perc, range_km, max_flow, budget, extend_graph, reroute, switch_tech,
max_reroute_inc, max_util, station_type, h2_fuel_type, clean_energy, clean_energy_cost, emissions_obj,
eff_energy_p_tender, tender_cost_p_tonmi, diesel_cost_p_gal, comm_group, flow_data_filename,
suppress_output, legend_show, scenario_code] = extract_assert_scenario_inputs(scenario_code=scenario_code)
else:
t0_total = time.time()
[rr, fuel_type, deployment_perc, range_km, max_flow, budget, extend_graph, reroute, switch_tech,
max_reroute_inc, max_util, station_type, h2_fuel_type, clean_energy, clean_energy_cost, emissions_obj,
eff_energy_p_tender, tender_cost_p_tonmi, diesel_cost_p_gal, comm_group, flow_data_filename,
suppress_output, legend_show, scenario_code] = extract_assert_scenario_inputs(scenario_code=scenario_code)
# deployment_perc = float(deployment_perc)
# D = float(D)
# reroute = int(reroute)
# switch_tech = int(switch_tech)
# max_reroute_inc = float(max_reroute_inc)
# max_util = float(max_util)
# clean_energy = int(clean_energy)
# clean_energy_cost = float(clean_energy_cost)
# emissions_obj = int(emissions_obj)
# eff_energy_p_tender = float(eff_energy_p_tender)
# suppress_output = int(suppress_output)
# binary_prog = int(binary_prog)
# radius = float(radius)
# 0. load railroad network representation as a nx.Graph and a simplify and consolidate network
if not G:
G = load_simplified_consolidated_graph(rr)
else:
# get a deep copy of G so that changes made to local G are not made to the original G
G = deepcopy(G)
if fuel_type == 'battery':
G.graph['scenario'] = dict(railroad=rr, range_mi=range_km * KM2MI, fuel_type=fuel_type,
desired_deployment_perc=deployment_perc, reroute=reroute,
switch_tech=switch_tech,
max_reroute_inc=max_reroute_inc, max_util=max_util, station_type=station_type,
eff_kwh_p_batt=eff_energy_p_tender, scenario_code=scenario_code)
# 1. load od_flow_dict for ranking OD pairs and choosing top <perc_ods> for flows for facility location
t0 = time.time()
print('LOOKUP TABLE:: %s seconds ---' % round(time.time() - t0, 3))
t0 = time.time()
# select almost all O-D pairs with non-zero flow (leave out the 20% with the lowest flow values; too many)
ods, od_flows = ods_by_perc_ton_mi(G=G, flow_data_filename=flow_data_filename)
G.graph['framework'] = dict(ods=ods)
print('OD LIST:: %s seconds ---' % round(time.time() - t0, 3))
t0 = time.time()
# 2. locate facilities and extract graph form of this, G, and its induced subgraph, H
G, H = facility_location(G, D=range_km, ods=ods, od_flows=od_flows, flow_min=deployment_perc, budget=budget,
max_flow=max_flow, extend_graph=extend_graph, suppress_output=suppress_output)
print('FACILITY LOCATION:: %s seconds ---' % round(time.time() - t0, 3))
# if no facilities are selected
if G.graph['number_facilities'] == 0:
return G
t0 = time.time()
# 3. reroute flows and get peak and average ton and locomotive flows for each edge
G, H = route_flows(G=G, fuel_type=fuel_type, flow_data_filename=flow_data_filename, H=H, D=range_km,
reroute=reroute, switch_tech=switch_tech, max_reroute_inc=max_reroute_inc)
print('FLOW ASSIGNMENT:: %s seconds ---' % round(time.time() - t0, 3))
t0 = time.time()
# 4. facility sizing based on peak flows and utilization based on average flows
# load cost by state dataframe and assign to each node
# emissions_p_location = elec_rate_state(G, emissions=True, clean_energy=clean_energy,
# clean_elec_prem_dolkwh=clean_energy_cost) # [gCO2/kWh]
# cost_p_location = elec_rate_state(G, clean_energy=clean_energy,
# clean_elec_prem_dolkwh=clean_energy_cost) # in [$/MWh]
G = facility_sizing(G=G, H=H, fuel_type=fuel_type, D=range_km, emissions_obj=emissions_obj,
suppress_output=suppress_output)
print('FACILITY SIZING:: %s seconds ---' % round(time.time() - t0, 3))
t0 = time.time()
actual_dep_perc = G.graph['operations']['deployment_perc'][comm_group]
G.graph['scenario']['actual_deployment_perc'] = actual_dep_perc
# 5.1. TEA
G = tea_battery_all_facilities(G, max_util=max_util,
clean_energy_cost=clean_energy_cost if clean_energy else None,
tender_cost_p_tonmi=tender_cost_p_tonmi, diesel_cost_p_gal=diesel_cost_p_gal)
# baseline and other dropin fuels (easy factor calculation)
G = tea_dropin(G=G, fuel_type='diesel', deployment_perc=1, scenario_fuel_type=fuel_type)
# G = tea_dropin(G, fuel_type='biodiesel', deployment_perc=actual_dep_perc, scenario_fuel_type=fuel_type)
# G = tea_dropin(G, fuel_type='e-fuel', deployment_perc=actual_dep_perc, scenario_fuel_type=fuel_type)
print('TEA:: %s seconds ---' % round(time.time() - t0, 3))
t0 = time.time()
# 5.2. LCA
G = lca_battery(G, clean_energy=clean_energy)
# baseline and other dropin fuels (easy factor calculation)
G = lca_dropin(G, fuel_type='diesel', deployment_perc=1, scenario_fuel_type=fuel_type)
# G = lca_dropin(G, fuel_type='biodiesel', deployment_perc=actual_dep_perc, scenario_fuel_type=fuel_type)
# G = lca_dropin(G, fuel_type='e-fuel', deployment_perc=actual_dep_perc, scenario_fuel_type=fuel_type)
print('LCA:: %s seconds ---' % round(time.time() - t0, 3))
elif fuel_type == 'hydrogen':
G.graph['scenario'] = dict(railroad=rr, range_mi=range_km * KM2MI, fuel_type=fuel_type,
desired_deployment_perc=deployment_perc, reroute=reroute,
switch_tech=switch_tech,
max_reroute_inc=max_reroute_inc, max_util=max_util, station_type=station_type,
eff_kgh2_p_loc=eff_energy_p_tender, scenario_code=scenario_code)
# 1. load od_flow_dict for ranking OD pairs and choosing top <perc_ods> for flows for facility location
t0 = time.time()
print('LOOKUP TABLE:: %s seconds ---' % round(time.time() - t0, 3))
t0 = time.time()
ods, od_flows = ods_by_perc_ton_mi(G=G, flow_data_filename=flow_data_filename)
G.graph['framework'] = dict(ods=ods)
print('OD LIST:: %s seconds ---' % round(time.time() - t0, 3))
t0 = time.time()
# 2. locate facilities and extract graph form of this, G, and its induced subgraph, H
G, H = facility_location(G, D=range_km, ods=ods, od_flows=od_flows, flow_min=deployment_perc, budget=budget,
max_flow=max_flow, extend_graph=extend_graph, suppress_output=suppress_output)
print('FACILITY LOCATION:: %s seconds ---' % round(time.time() - t0, 3))
# if no facilities are selected
if G.graph['number_facilities'] == 0:
return G
t0 = time.time()
# 3. reroute flows and get peak and average ton and locomotive flows for each edge
G, H = route_flows(G=G, fuel_type=fuel_type, flow_data_filename=flow_data_filename, H=H, D=range_km,
reroute=reroute, switch_tech=switch_tech, max_reroute_inc=max_reroute_inc)
print('FLOW ASSIGNMENT:: %s seconds ---' % round(time.time() - t0, 3))
t0 = time.time()
# 4. facility sizing based on peak flows and utilization based on average flows
G = facility_sizing(G=G, H=H, fuel_type=fuel_type, D=range_km, unit_sizing_obj=True,
suppress_output=suppress_output)
print('FACILITY SIZING:: %s seconds ---' % round(time.time() - t0, 3))
t0 = time.time()
actual_dep_perc = G.graph['operations']['deployment_perc'][comm_group]
G.graph['scenario']['actual_deployment_perc'] = actual_dep_perc
# 5.1. TEA
G = tea_hydrogen_all_facilities(G, max_util=max_util, station_type=station_type,
clean_energy_cost=clean_energy_cost if clean_energy else None,
tender_cost_p_tonmi=tender_cost_p_tonmi,
diesel_cost_p_gal=diesel_cost_p_gal)
# baseline and other dropin fuels (easy factor calculation)
G = tea_dropin(G, fuel_type='diesel', deployment_perc=1, scenario_fuel_type=fuel_type)
G = tea_dropin(G, fuel_type='biodiesel', deployment_perc=actual_dep_perc, scenario_fuel_type=fuel_type)
G = tea_dropin(G, fuel_type='e-fuel', deployment_perc=actual_dep_perc, scenario_fuel_type=fuel_type)
print('TEA:: %s seconds ---' % round(time.time() - t0, 3))
t0 = time.time()
# 5.2. LCA
G = lca_hydrogen(G, h2_fuel_type=h2_fuel_type)
# baseline and other dropin fuels (easy factor calculation)
G = lca_dropin(G, fuel_type='diesel', deployment_perc=1, scenario_fuel_type=fuel_type)
G = lca_dropin(G, fuel_type='biodiesel', deployment_perc=actual_dep_perc, scenario_fuel_type=fuel_type)
G = lca_dropin(G, fuel_type='e-fuel', deployment_perc=actual_dep_perc, scenario_fuel_type=fuel_type)
print('LCA:: %s seconds ---' % round(time.time() - t0, 3))
elif 'hybrid' in fuel_type:
# add in regional alignment information to G (based on A-STEP simulation tool)
G = regional_alignments(G)
G.graph['scenario'] = dict(railroad=rr, range_mi=range_km * KM2MI, fuel_type=fuel_type,
desired_deployment_perc=deployment_perc, reroute=reroute,
switch_tech=switch_tech,
max_reroute_inc=max_reroute_inc, max_util=max_util, station_type=station_type,
eff_kwh_p_batt=eff_energy_p_tender, scenario_code=scenario_code)
# 1. load od_flow_dict for ranking OD pairs and choosing top <perc_ods> for flows for facility location
t0 = time.time()
# if perc_ods is None or perc_ods == 'X':
# perc_ods = deployment_perc_lookup_table(df_scenario=df_scenario, deployment_perc=deployment_perc)
print('LOOKUP TABLE:: %s seconds ---' % round(time.time() - t0, 3))
t0 = time.time()
# select almost all O-D pairs with non-zero flow (leave out the 20% with the lowest flow values; too many)
ods, od_flows = ods_by_perc_ton_mi(G=G, flow_data_filename=flow_data_filename)
G.graph['framework'] = dict(ods=ods)
print('OD LIST:: %s seconds ---' % round(time.time() - t0, 3))
t0 = time.time()
# 2. locate facilities and extract graph form of this, G, and its induced subgraph, H
G, H = facility_location(G, D=range_km, ods=ods, od_flows=od_flows, flow_min=deployment_perc, budget=budget,
max_flow=max_flow, extend_graph=extend_graph, suppress_output=suppress_output)
print('FACILITY LOCATION:: %s seconds ---' % round(time.time() - t0, 3))
# if no facilities are selected
if G.graph['number_facilities'] == 0:
return G
t0 = time.time()
# 3. reroute flows and get peak and average ton and locomotive flows for each edge
G, H = route_flows(G=G, fuel_type=fuel_type, flow_data_filename=flow_data_filename, H=G, D=range_km,
reroute=reroute, switch_tech=switch_tech, max_reroute_inc=max_reroute_inc)
print('FLOW ASSIGNMENT:: %s seconds ---' % round(time.time() - t0, 3))
t0 = time.time()
# 4. facility sizing based on peak flows and utilization based on average flows
# load cost by state dataframe and assign to each node
# emissions_p_location = elec_rate_state(G, emissions=True, clean_energy=clean_energy,
# clean_elec_prem_dolkwh=clean_energy_cost) # [gCO2/kWh]
# cost_p_location = elec_rate_state(G, clean_energy=clean_energy,
# clean_elec_prem_dolkwh=clean_energy_cost) # in [$/MWh]
G = facility_sizing_hybrid(G=G, H=H, fuel_type=fuel_type, D=range_km, emissions_obj=emissions_obj,
suppress_output=suppress_output)
print('FACILITY SIZING:: %s seconds ---' % round(time.time() - t0, 3))
t0 = time.time()
actual_dep_perc = G.graph['operations']['deployment_perc'][comm_group]
G.graph['scenario']['actual_deployment_perc'] = actual_dep_perc
# 5.1. TEA
G = tea_hybrid(G, max_util=max_util, station_type=station_type,
clean_energy_cost=clean_energy_cost if clean_energy else None,
tender_cost_p_tonmi=tender_cost_p_tonmi, diesel_cost_p_gal=diesel_cost_p_gal)
# baseline and other dropin fuels (easy factor calculation)
G = tea_dropin(G, fuel_type='diesel', deployment_perc=1, scenario_fuel_type=fuel_type)
# G = tea_dropin(G, fuel_type='biodiesel', deployment_perc=actual_dep_perc, scenario_fuel_type=fuel_type)
# G = tea_dropin(G, fuel_type='e-fuel', deployment_perc=actual_dep_perc, scenario_fuel_type=fuel_type)
print('TEA:: %s seconds ---' % round(time.time() - t0, 3))
t0 = time.time()
# 5.2. LCA
G = lca_hybrid(G, clean_energy=clean_energy)
# baseline and other dropin fuels (easy factor calculation)
G = lca_dropin(G, fuel_type='diesel', deployment_perc=1, scenario_fuel_type=fuel_type)
# G = lca_dropin(G, fuel_type='biodiesel', deployment_perc=actual_dep_perc, scenario_fuel_type=fuel_type)
# G = lca_dropin(G, fuel_type='e-fuel', deployment_perc=actual_dep_perc, scenario_fuel_type=fuel_type)
print('LCA:: %s seconds ---' % round(time.time() - t0, 3))
elif fuel_type == 'e-fuel' or fuel_type == 'biodiesel' or fuel_type == 'diesel':
if deployment_perc is None:
deployment_perc = 1
G.graph['scenario'] = dict(railroad=rr, range_mi=np.nan, fuel_type=fuel_type,
desired_deployment_perc=deployment_perc, reroute=reroute,
switch_tech=switch_tech,
max_reroute_inc=max_reroute_inc, max_util=max_util, station_type=station_type,
scenario_code=scenario_code)
t0 = time.time()
# 1. route baseline flows to get average daily ton and locomotive flows for each edge
G = route_flows(G=G, fuel_type=fuel_type, flow_data_filename=flow_data_filename)
print('FLOW ASSIGNMENT:: %s seconds ---' % round(time.time() - t0, 3))
t0 = time.time()
# 2. TEA
G = tea_dropin(G, fuel_type='diesel', deployment_perc=1, scenario_fuel_type=fuel_type)
G = tea_dropin(G, fuel_type=fuel_type, deployment_perc=deployment_perc)
print('TEA:: %s seconds ---' % round(time.time() - t0, 3))
t0 = time.time()
# 3. LCA
G = lca_dropin(G, fuel_type='diesel', deployment_perc=1, scenario_fuel_type=fuel_type)
G = lca_dropin(G, fuel_type=fuel_type, deployment_perc=deployment_perc)
print('LCA:: %s seconds ---' % round(time.time() - t0, 3))
G = operations_stats(G)
# G = update_graph_values(G=G, fuel_type=fuel_type, max_util=max_util, station_type=station_type,
# clean_energy=clean_energy, clean_energy_cost=clean_energy_cost,
# h2_fuel_type=h2_fuel_type, tender_cost_p_tonmi=tender_cost_p_tonmi,
# diesel_cost_p_gal=diesel_cost_p_gal)
print('SCENARIO RUN:: %s seconds ---' % round(time.time() - t0_total, 3))
if cache_scenario:
t0 = time.time()
cache_graph(G=G, scenario_code=scenario_code)
print('CACHE GRAPH:: %s seconds ---' % round(time.time() - t0, 3))
if plot:
t0 = time.time()
fig = plot_scenario(G, fuel_type=fuel_type, deployment_perc=deployment_perc, comm_group=comm_group,
legend_show=legend_show)
print('PLOTTING:: %s seconds ---' % round(time.time() - t0, 3))
else:
fig = None
return G, fig
def operations_stats(G: nx.DiGraph) -> nx.DiGraph:
# compute the operational stats of solution in G (many relative to diesel baseline)
comm_list = list({c for u, v in G.edges for c in G.edges[u, v]['baseline_avg_ton'].keys()})
if G.graph['scenario']['fuel_type'] == 'battery':
# G.graph['operations'].update(
# dict(
# emissions_change=100 * ((G.graph['diesel_LCA']['annual_total_emissions_tonco2'][comm_group] -
# G.graph['energy_source_LCA']['annual_total_emissions_tonco2']) /
# G.graph['diesel_LCA']['annual_total_emissions_tonco2'][comm_group]),
# cost_avoided_emissions=-1e-3 * ((G.graph['energy_source_TEA']['total_scenario_LCO_tonmi'] -
# G.graph['diesel_TEA']['total_LCO_tonmi']) /
# (G.graph['energy_source_LCA']['avg_emissions_tonco2_tonmi'] -
# G.graph['diesel_LCA']['total_emissions_tonco2_tonmi']))
# )
# )
G.graph['operations'].update(
dict(
emissions_change=dict(zip(
comm_list,
[100 * (G.graph['diesel_LCA']['annual_total_emissions_tonco2'][c] -
G.graph['energy_source_LCA']['annual_total_emissions_tonco2'][c]) /
G.graph['diesel_LCA']['annual_total_emissions_tonco2'][c] for c in comm_list])),
cost_avoided_emissions=dict(zip(
comm_list,
[-1e-3 * (G.graph['energy_source_TEA']['total_scenario_LCO_tonmi'][c] -
G.graph['diesel_TEA']['total_LCO_tonmi'][c]) /
(G.graph['energy_source_LCA']['avg_emissions_tonco2_tonmi'][c] -
G.graph['diesel_LCA']['total_emissions_tonco2_tonmi'][c]) for c in comm_list])),
cost_avoided_emissions_no_delay=dict(zip(
comm_list,
[-1e-3 * (G.graph['energy_source_TEA']['total_scenario_nodelay_LCO_tonmi'][c] -
G.graph['diesel_TEA']['total_LCO_tonmi'][c]) /
(G.graph['energy_source_LCA']['avg_emissions_tonco2_tonmi'][c] -
G.graph['diesel_LCA']['total_emissions_tonco2_tonmi'][c]) for c in comm_list]))
))
elif G.graph['scenario']['fuel_type'] == 'hydrogen':
# G.graph['operations'].update(
# dict(
# emissions_change=100 * ((G.graph['diesel_LCA']['annual_total_emissions_tonco2'] -
# G.graph['energy_source_LCA']['annual_total_emissions_tonco2']) /
# G.graph['diesel_LCA']['annual_total_emissions_tonco2']),
# cost_avoided_emissions=-1e-3 * ((G.graph['energy_source_TEA']['total_scenario_LCO_tonmi'] -
# G.graph['diesel_TEA']['total_LCO_tonmi']) /
# (G.graph['energy_source_LCA']['avg_emissions_tonco2_tonmi'] -
# G.graph['diesel_LCA']['total_emissions_tonco2_tonmi']))
# )
# )
G.graph['operations'].update(
dict(
emissions_change=dict(zip(
comm_list,
[100 * (G.graph['diesel_LCA']['annual_total_emissions_tonco2'][c] -
G.graph['energy_source_LCA']['annual_total_emissions_tonco2'][c]) /
G.graph['diesel_LCA']['annual_total_emissions_tonco2'][c] for c in comm_list])),
cost_avoided_emissions=dict(zip(
comm_list,
[-1e-3 * (G.graph['energy_source_TEA']['total_scenario_LCO_tonmi'][c] -
G.graph['diesel_TEA']['total_LCO_tonmi'][c]) /
(G.graph['energy_source_LCA']['avg_emissions_tonco2_tonmi'][c] -
G.graph['diesel_LCA']['total_emissions_tonco2_tonmi'][c]) for c in comm_list])),
cost_avoided_emissions_no_delay=dict(zip(
comm_list,
[-1e-3 * (G.graph['energy_source_TEA']['total_scenario_LCO_tonmi'][c] -
G.graph['diesel_TEA']['total_LCO_tonmi'][c]) /
(G.graph['energy_source_LCA']['avg_emissions_tonco2_tonmi'][c] -
G.graph['diesel_LCA']['total_emissions_tonco2_tonmi'][c]) for c in comm_list]))
))
elif 'hybrid' in G.graph['scenario']['fuel_type']:
# G.graph['operations'].update(
# dict(
# emissions_change=100 * ((G.graph['diesel_LCA']['annual_total_emissions_tonco2'][comm_group] -
# G.graph['energy_source_LCA']['annual_total_emissions_tonco2']) /
# G.graph['diesel_LCA']['annual_total_emissions_tonco2'][comm_group]),
# cost_avoided_emissions=-1e-3 * ((G.graph['energy_source_TEA']['total_scenario_LCO_tonmi'] -
# G.graph['diesel_TEA']['total_LCO_tonmi']) /
# (G.graph['energy_source_LCA']['avg_emissions_tonco2_tonmi'] -
# G.graph['diesel_LCA']['total_emissions_tonco2_tonmi']))
# )
# )
G.graph['operations'].update(
dict(
emissions_change=dict(zip(
comm_list,
[100 * (G.graph['diesel_LCA']['annual_total_emissions_tonco2'][c] -
G.graph['energy_source_LCA']['annual_total_emissions_tonco2'][c]) /
G.graph['diesel_LCA']['annual_total_emissions_tonco2'][c] for c in comm_list])),
cost_avoided_emissions=dict(zip(
comm_list,
[-1e-3 * (G.graph['energy_source_TEA']['total_scenario_LCO_tonmi'][c] -
G.graph['diesel_TEA']['total_LCO_tonmi'][c]) /
(G.graph['energy_source_LCA']['avg_emissions_tonco2_tonmi'][c] -
G.graph['diesel_LCA']['total_emissions_tonco2_tonmi'][c]) for c in comm_list])),
cost_avoided_emissions_no_delay=dict(zip(
comm_list,
[-1e-3 * (G.graph['energy_source_TEA']['total_scenario_nodelay_LCO_tonmi'][c] -
G.graph['diesel_TEA']['total_LCO_tonmi'][c]) /
(G.graph['energy_source_LCA']['avg_emissions_tonco2_tonmi'][c] -
G.graph['diesel_LCA']['total_emissions_tonco2_tonmi'][c]) for c in comm_list]))
))
elif G.graph['scenario']['fuel_type'] == 'e-fuel' or G.graph['scenario']['fuel_type'] == 'biodiesel':
# G.graph['operations'].update(
# dict(
# emissions_change=100 * ((G.graph['diesel_LCA']['annual_total_emissions_tonco2'] -
# G.graph['energy_source_LCA']['annual_total_emissions_tonco2']) /
# G.graph['diesel_LCA']['annual_total_emissions_tonco2']),
# cost_avoided_emissions=-1e-3 * ((G.graph['energy_source_TEA']['total_LCO_tonmi'] -
# G.graph['diesel_TEA']['total_LCO_tonmi']) /
# (G.graph['energy_source_LCA']['total_emissions_tonco2_tonmi'] -
# G.graph['diesel_LCA']['total_emissions_tonco2_tonmi']))
# )
# )
G.graph['operations'].update(
dict(
emissions_change=dict(zip(
comm_list,
[100 * (G.graph['diesel_LCA']['annual_total_emissions_tonco2'][c] -
G.graph['energy_source_LCA']['annual_total_emissions_tonco2'][c]) /
G.graph['diesel_LCA']['annual_total_emissions_tonco2'][c] for c in comm_list])),
cost_avoided_emissions=dict(zip(
comm_list,
[-1e-3 * (G.graph['energy_source_TEA']['total_LCO_tonmi'][c] -
G.graph['diesel_TEA']['total_LCO_tonmi'][c]) /
(G.graph['energy_source_LCA']['total_emissions_tonco2_tonmi'][c] -
G.graph['diesel_LCA']['total_emissions_tonco2_tonmi'][c]) for c in comm_list]))
))
return G
def update_graph_values(G: nx.DiGraph, fuel_type: str, max_util: float, station_type: str,
clean_energy=True, clean_energy_cost: float = None,
h2_fuel_type: str = None, tender_cost_p_tonmi: float = None,
diesel_cost_p_gal: float = None) -> nx.DiGraph:
# valid <h2_fuel_type> values:
# ['Natural Gas', 'NG with CO2 Sequestration', 'PEM Electrolysis - Solar', 'PEM Electrolysis - Nuclear']
if 'hybrid' in fuel_type:
return G
if not clean_energy and tender_cost_p_tonmi is None and diesel_cost_p_gal is None:
return G
if clean_energy_cost is None:
clean_energy_cost = 0.0
# update TEA with premiums on clean energy costs and LCA with emissions cuts
if fuel_type == 'battery':
t0 = time.time()
G = lca_battery(G=G, clean_energy=clean_energy)
print('LCA2:: ' + str(time.time() - t0))
t0 = time.time()
G = tea_battery_all_facilities(G, max_util=max_util, clean_energy_cost=clean_energy_cost,
tender_cost_p_tonmi=tender_cost_p_tonmi, diesel_cost_p_gal=diesel_cost_p_gal)
G = tea_dropin(G, fuel_type='diesel', deployment_perc=1, scenario_fuel_type=fuel_type,
diesel_cost_p_gal=diesel_cost_p_gal)
print('TEA UPDATE:: ' + str(time.time() - t0))
elif 'hybrid' in fuel_type:
t0 = time.time()
G = lca_hybrid(G=G, clean_energy=clean_energy)
print('LCA2:: ' + str(time.time() - t0))
t0 = time.time()
G = tea_hybrid(G, max_util=max_util, station_type=station_type,
clean_energy_cost=clean_energy_cost, tender_cost_p_tonmi=tender_cost_p_tonmi,
diesel_cost_p_gal=diesel_cost_p_gal)
G = tea_dropin(G, fuel_type='diesel', deployment_perc=1, scenario_fuel_type=fuel_type,
diesel_cost_p_gal=diesel_cost_p_gal)
print('TEA UPDATE:: ' + str(time.time() - t0))
elif fuel_type == 'hydrogen':
if h2_fuel_type is None:
h2_fuel_type = 'Natural Gas'
t0 = time.time()
G = lca_hydrogen(G=G, h2_fuel_type=h2_fuel_type)
print('LCA UPDATE:: ' + str(time.time() - t0))
t0 = time.time()
G = tea_hydrogen_all_facilities(G=G, max_util=max_util, station_type=station_type,
clean_energy_cost=clean_energy_cost, diesel_cost_p_gal=diesel_cost_p_gal)
G = tea_dropin(G, fuel_type='diesel', deployment_perc=1, scenario_fuel_type=fuel_type,
diesel_cost_p_gal=diesel_cost_p_gal)
print('TEA UPDATE:: ' + str(time.time() - t0))
G = operations_stats(G)
return G