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 | def compute(self, input_data) -> dict:
"""
Compute the environmental impact of the energy carrier pathway.
Each plant (vintage) is commissioned with the characteristics of its commissioning year,
and its emissions are distributed over its lifespan, weighted by its share in annual production.
Parameters
----------
input_data
Dictionary containing all input data required for the computation, completed at model instantiation with information from yaml files and outputs of other models.
Returns
-------
output_data
Dictionary containing all output data resulting from the computation. Contains outputs defined during model instantiation.
"""
optional_nan_series = pd.Series(
np.nan, index=range(self.historic_start_year, self.end_year + 1)
)
energy_production_commissioned = input_data[
f"{self.pathway_name}_energy_production_commissioned"
]
energy_consumption = input_data[f"{self.pathway_name}_energy_consumption"]
energy_unused = input_data[f"{self.pathway_name}_energy_unused"]
# Prepare outputs
output_data = {k: optional_nan_series.copy() for k in self.output_names}
co2_emission_factor = optional_nan_series.copy()
# For each vintage, compute its emission factor and contribution
for year, needed_capacity in energy_production_commissioned.items():
lifespan = _get_value_for_year(
input_data.get(f"{self.pathway_name}_eis_plant_lifespan"), year, 25
)
# The plant will operate from year to year+lifespan (or until end_year)
vintage_indexes = range(year, year + lifespan)
vintage_emission_factor = pd.Series(np.nan, index=vintage_indexes)
if (
energy_consumption[year] > 0
and needed_capacity <= 0
and self.compute_abatement_cost
and not self.compute_all_years
):
print(
f"⚠️ Warning: for {self.pathway_name}, no plants commissioned in {year}. Unable to compute "
f"CAC: compute_all_years = False. Set it true to avoid NaN values in the MACC for this year."
)
if needed_capacity > 0 or self.compute_all_years:
if needed_capacity < 0:
warnings.warn(
f"Negative needed capacity for {self.pathway_name} in year {year}. "
"This is not expected despite the compute_all_years option being set to True."
)
# relative contibution of the vintage
relative_share = needed_capacity / (energy_consumption + energy_unused)
relative_share = relative_share.loc[year : year + lifespan - 1]
# I -- First lets compute the core MFSP (no resources, no processes)
# Get the inputs for the year
core_emission_factor = _get_value_for_year(
input_data.get(f"{self.pathway_name}_eis_co2_emission_factor_without_resource"),
year,
0.0,
)
kerosene_selectivity = _get_value_for_year(
input_data.get(f"{self.pathway_name}_eis_kerosene_selectivity"), year, 1.0
)
vintage_emission_factor = _custom_series_addition(
vintage_emission_factor, core_emission_factor
)
output_data[f"{self.pathway_name}_mean_co2_emission_factor_without_resource"].loc[
year : year + lifespan - 1
] = _custom_series_addition(
output_data[
f"{self.pathway_name}_mean_co2_emission_factor_without_resource"
].loc[year : year + lifespan - 1],
core_emission_factor * relative_share,
)
# II) Now let's compute the emissions from resources that are linked to the pathway itself
for key in self.resource_keys:
specific_consumption = _get_value_for_year(
input_data.get(
f"{self.pathway_name}_eis_resource_specific_consumption_{key}"
),
year,
None,
)
total_ressource_consumption = optional_nan_series.copy()
total_ressource_mobilised_with_selectivity = optional_nan_series.copy()
if specific_consumption is not None:
resources_consumption = (
energy_production_commissioned[year] * specific_consumption
)
resources_consumption_with_selectivity = (
resources_consumption * kerosene_selectivity
)
total_ressource_consumption.loc[year : year + lifespan - 1] = (
resources_consumption
)
total_ressource_mobilised_with_selectivity.loc[
year : year + lifespan - 1
] = resources_consumption_with_selectivity
output_data[
f"{self.pathway_name}_excluding_processes_{key}_total_consumption"
].loc[year : year + lifespan - 1] += resources_consumption
output_data[
f"{self.pathway_name}_excluding_processes_{key}_total_mobilised_with_selectivity"
].loc[year : year + lifespan - 1] += resources_consumption_with_selectivity
# Get the CO2 emission factor for the resource
unit_emissions = input_data.get(
f"{key}_co2_emission_factor", optional_nan_series
)
# beyond sceanrio end year, we stick to last known value
unit_emissions = unit_emissions.reindex(
range(year, year + lifespan), method="ffill"
)
# get resource emission per unit of energy
co2_emission_factor_ressource = specific_consumption * unit_emissions
vintage_emission_factor = _custom_series_addition(
vintage_emission_factor, co2_emission_factor_ressource
)
output_data[
f"{self.pathway_name}_excluding_processes_{key}_mean_co2_emission_factor"
].loc[year : year + lifespan - 1] = _custom_series_addition(
output_data[
f"{self.pathway_name}_excluding_processes_{key}_mean_co2_emission_factor"
].loc[year : year + lifespan - 1],
co2_emission_factor_ressource * relative_share,
)
# III) Now let's compute the emissions from processes that gets a ressource
for process_key in self.process_keys:
specific_consumption = _get_value_for_year(
input_data.get(
f"{process_key}_eis_resource_specific_consumption_{key}"
),
year,
None,
)
if specific_consumption is not None:
resources_consumption = (
energy_production_commissioned[year] * specific_consumption
)
resources_consumption_with_selectivity = (
resources_consumption * kerosene_selectivity
)
total_ressource_consumption.loc[year : year + lifespan - 1] = (
resources_consumption
)
total_ressource_mobilised_with_selectivity.loc[
year : year + lifespan - 1
] = resources_consumption_with_selectivity
output_data[
f"{self.pathway_name}_{process_key}_{key}_total_consumption"
].loc[year : year + lifespan - 1] += resources_consumption
output_data[
f"{self.pathway_name}_{process_key}_{key}_total_mobilised_with_selectivity"
].loc[
year : year + lifespan - 1
] += resources_consumption_with_selectivity
# Get the CO2 emission factor for the resource
unit_emissions = input_data.get(
f"{key}_co2_emission_factor", optional_nan_series
)
# beyond sceanrio end year, we stick to last known value
unit_emissions = unit_emissions.reindex(
range(year, year + lifespan), method="ffill"
)
# get resource emission per unit of energy
co2_emission_factor_ressource = specific_consumption * unit_emissions
vintage_emission_factor = _custom_series_addition(
vintage_emission_factor, co2_emission_factor_ressource
)
output_data[
f"{self.pathway_name}_{process_key}_{key}_mean_co2_emission_factor"
].loc[year : year + lifespan - 1] = _custom_series_addition(
output_data[
f"{self.pathway_name}_{process_key}_{key}_mean_co2_emission_factor"
].loc[year : year + lifespan - 1],
co2_emission_factor_ressource * relative_share,
)
# store the total consumption of the resource
output_data[f"{self.pathway_name}_{key}_total_consumption"].loc[
year : year + lifespan - 1
] = _custom_series_addition(
output_data[f"{self.pathway_name}_{key}_total_consumption"].loc[
year : year + lifespan - 1
],
total_ressource_consumption.loc[year : year + lifespan - 1],
)
output_data[f"{self.pathway_name}_{key}_total_mobilised_with_selectivity"].loc[
year : year + lifespan - 1
] = _custom_series_addition(
output_data[
f"{self.pathway_name}_{key}_total_mobilised_with_selectivity"
].loc[year : year + lifespan - 1],
total_ressource_mobilised_with_selectivity.loc[year : year + lifespan - 1],
)
# IV) Now let's compute the emissions from processes themselves
for process_key in self.process_keys:
# Get the inputs for the year
process_emission_factor = _get_value_for_year(
input_data.get(f"{process_key}_eis_co2_emission_factor_without_resources"),
year,
0.0,
)
vintage_emission_factor = _custom_series_addition(
vintage_emission_factor, process_emission_factor
)
output_data[
f"{self.pathway_name}_{process_key}_without_resources_mean_co2_emission_factor"
].loc[year : year + lifespan - 1] = _custom_series_addition(
output_data[
f"{self.pathway_name}_{process_key}_without_resources_mean_co2_emission_factor"
].loc[year : year + lifespan - 1],
process_emission_factor * relative_share,
)
# Compute the average emission factor from the vintage
co2_emission_factor.loc[year : year + lifespan - 1] = _custom_series_addition(
co2_emission_factor.loc[year : year + lifespan - 1],
vintage_emission_factor * relative_share,
)
# Store the emission factor for the vintage
output_data[f"{self.pathway_name}_vintage_eis_co2_emission_factor"].loc[year] = (
vintage_emission_factor.loc[year]
)
# compute the cumulative and discounted emissions for the vintage
if self.compute_abatement_cost:
if vintage_emission_factor.notna().any():
# Get the exogenous carbon price trajectory and social discount rate
exogenous_carbon_price_trajectory = input_data.get(
"exogenous_carbon_price_trajectory", optional_nan_series
)
social_discount_rate = input_data.get("social_discount_rate", 0.0)
# Compute cumulative and discounted emissions for the vintage
cumul_em, generic_discounted_cumul_em = (
self._unitary_cumul_emissions_vintage(
vintage_emission_factor,
exogenous_carbon_price_trajectory,
social_discount_rate,
)
)
else:
cumul_em = np.NaN
generic_discounted_cumul_em = np.NaN
# Store the cumulative emissions for the vintage
output_data[f"{self.pathway_name}_lifespan_unitary_emissions"].loc[year] = (
cumul_em
)
output_data[f"{self.pathway_name}_lifespan_discounted_unitary_emissions"].loc[
year
] = generic_discounted_cumul_em
# Store the emission factor
output_data[f"{self.pathway_name}_mean_co2_emission_factor"] = co2_emission_factor
# Compute the total emissions from the vintage
total_co2_emissions = energy_consumption * co2_emission_factor
output_data[f"{self.pathway_name}_total_co2_emissions"] = total_co2_emissions
self._store_outputs(output_data)
return output_data
|