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 | def compute(self, input_data) -> dict:
"""
Execute the bottom-up techno-economic cost computation for the 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"]
# first lets initialize the output data with mean mfsp components by parsing resources and processes
# Prepare outputs
output_data = {k: optional_nan_series.copy() for k in self.output_names}
# First lets compute the core mfsp
for year, needed_capacity in energy_production_commissioned.items():
# Get the technical inputs
private_discount_rate = _get_value_for_year(
input_data.get("private_discount_rate"), year, 0.0
)
lifespan = _get_value_for_year(
input_data.get(f"{self.pathway_name}_eis_plant_lifespan"), year, 25
)
construction_time = _get_value_for_year(
input_data.get(f"{self.pathway_name}_eis_construction_time"), year, 3
)
plant_load_factor = _get_value_for_year(
input_data.get(f"{self.pathway_name}_eis_plant_load_factor"), year, 1
)
# plant production is potentially evaluated beyond scenario end year
vintage_indexes = range(year, year + lifespan)
vintage_mfsp = 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
capex = _get_value_for_year(
input_data.get(f"{self.pathway_name}_eis_capex"), year, 0.0
)
# get the plant load factor for the year: minimum of plant load factor and resource load factors
# TODO what shall we do with processes LF? Uncoupling core and processes make sense in many cases.
main_process_load_factor = plant_load_factor
for key in input_data.get(f"{self.pathway_name}_resource_names", []):
if f"{key}_load_factor" in input_data:
resource_load_factor = _get_value_for_year(
input_data.get(f"{key}_load_factor"), year, 1.0
)
if resource_load_factor is not None:
main_process_load_factor = min(
main_process_load_factor, resource_load_factor
)
# Compute the capital cost per unit of energy produced. Capex in €/(MJ/Year), mfsp capex in €/MJ
mfsp_capex = (
self._spread_capital(capex, private_discount_rate, lifespan, construction_time)
/ main_process_load_factor
)
capex_year = capex * needed_capacity
output_data[f"{self.pathway_name}_capex_cost"].loc[
year - construction_time : year
] = _custom_series_addition(
output_data[f"{self.pathway_name}_capex_cost"].loc[
year - construction_time : year
],
capex_year / construction_time / main_process_load_factor,
)
output_data[f"{self.pathway_name}_mean_unit_capex"].loc[
year : year + lifespan - 1
] = _custom_series_addition(
output_data[f"{self.pathway_name}_mean_unit_capex"].loc[
year : year + lifespan - 1
],
mfsp_capex * relative_share,
)
# compyte the EIS unitary capex
output_data[f"{self.pathway_name}_vintage_unit_capex"].loc[year] = mfsp_capex
# As var opex is in € per MJ we can directly get it
variable_opex = _get_value_for_year(
input_data.get(f"{self.pathway_name}_eis_variable_opex"), year, 0.0
)
output_data[f"{self.pathway_name}_mean_unit_variable_opex"].loc[
year : year + lifespan - 1
] = _custom_series_addition(
output_data[f"{self.pathway_name}_mean_unit_variable_opex"].loc[
year : year + lifespan - 1
],
variable_opex * relative_share,
)
# compyte the EIS variable opex --> No need, directly from input eis_variable_opex
output_data[f"{self.pathway_name}_vintage_unit_variable_opex"].loc[year] = (
variable_opex
)
# As fixed opex is in €/year for a plant of 1 MJ/year, we can directly get it in €/MJ
fixed_opex = (
_get_value_for_year(
input_data.get(f"{self.pathway_name}_eis_fixed_opex"), year, 0.0
)
/ main_process_load_factor
)
output_data[f"{self.pathway_name}_mean_unit_fixed_opex"].loc[
year : year + lifespan - 1
] = _custom_series_addition(
output_data[f"{self.pathway_name}_mean_unit_fixed_opex"].loc[
year : year + lifespan - 1
],
fixed_opex * relative_share,
)
# compyte the EIS fixed opex
output_data[f"{self.pathway_name}_vintage_unit_fixed_opex"].loc[year] = fixed_opex
vintage_mfsp = _custom_series_addition(
vintage_mfsp, mfsp_capex + fixed_opex + variable_opex
)
output_data[f"{self.pathway_name}_mean_mfsp_without_resource"].loc[
year : year + lifespan - 1
] = _custom_series_addition(
output_data[f"{self.pathway_name}_mean_mfsp_without_resource"].loc[
year : year + lifespan - 1
],
vintage_mfsp * relative_share,
)
# II -- Now lets get the resources as in TopDownCost model
for key in self.resource_keys:
# get the specific consumption of the resource
specific_consumption = _get_value_for_year(
input_data.get(
f"{self.pathway_name}_eis_resource_specific_consumption_{key}"
),
year,
None,
)
if specific_consumption is not None:
resource_price = input_data.get(f"{key}_cost", optional_nan_series.copy())
# cast mfsp_resource to a series with the same index as
# vintage_mfsp by keeping correct values (<end year) extending last year value to the end of the vintage_mfsp
mfsp_resource = pd.Series(
[
resource_price[year] * specific_consumption
if year <= self.end_year and year in resource_price.index
else resource_price.iloc[-1] * specific_consumption
for year in vintage_mfsp.index
],
index=vintage_mfsp.index,
)
vintage_mfsp = _custom_series_addition(vintage_mfsp, mfsp_resource)
# Store the resource cost in the output data
output_data[
f"{self.pathway_name}_excluding_processes_{key}_mean_unit_cost"
].loc[year : year + lifespan - 1] = _custom_series_addition(
output_data[
f"{self.pathway_name}_excluding_processes_{key}_mean_unit_cost"
].loc[year : year + lifespan - 1],
mfsp_resource * relative_share,
)
# compyte the EIS resource cost (at first year energy cost)
output_data[
f"{self.pathway_name}_excluding_processes_{key}_vintage_unit_cost"
].loc[year] = mfsp_resource[year]
# get processes that use this resource
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:
process_ressource_price = input_data.get(
f"{key}_cost", optional_nan_series.copy()
)
# cast mfsp_resource to a series with the same index as
# vintage_mfsp by keeping correct values (<end year) extending last year value to the end of the vintage_mfsp
mfsp_process_ressource = pd.Series(
[
process_ressource_price[year] * specific_consumption
if year <= self.end_year
and year in process_ressource_price.index
else process_ressource_price.iloc[-1] * specific_consumption
for year in vintage_mfsp.index
],
index=vintage_mfsp.index,
)
vintage_mfsp = _custom_series_addition(
vintage_mfsp, mfsp_process_ressource
)
# Store the resource cost in the output data
output_data[
f"{self.pathway_name}_{process_key}_{key}_mean_unit_cost"
].loc[year : year + lifespan - 1] = _custom_series_addition(
output_data[
f"{self.pathway_name}_{process_key}_{key}_mean_unit_cost"
].loc[year : year + lifespan - 1],
mfsp_process_ressource * relative_share,
)
# compyte the EIS resource cost (at first year energy cost)
output_data[
f"{self.pathway_name}_{process_key}_{key}_vintage_unit_cost"
].loc[year] = mfsp_process_ressource[year]
# III -- Now lets get the processes
for process_key in self.process_keys:
process_capex = _get_value_for_year(
input_data.get(f"{process_key}_eis_capex"), year, 0.0
)
process_lifespan = _get_value_for_year(
input_data.get(f"{process_key}_eis_plant_lifespan"), year, 25
)
process_construction_time = _get_value_for_year(
input_data.get(f"{process_key}_eis_construction_time"), year, 3.0
)
process_load_factor = _get_value_for_year(
input_data.get(f"{process_key}_eis_plant_load_factor"), year, 1.0
)
# get the process load factor for the year: minimum of process load factor and resource load factors
for key in input_data.get(f"{process_key}_resource_names", []):
if f"{key}_load_factor" in input_data:
resource_load_factor = _get_value_for_year(
input_data.get(f"{key}_load_factor"), year, 1.0
)
if resource_load_factor is not None:
process_load_factor = min(process_load_factor, resource_load_factor)
# Compute the capital cost per unit of energy produced for the process
mfsp_capex_process = (
self._spread_capital(
process_capex,
private_discount_rate,
process_lifespan,
process_construction_time,
)
/ process_load_factor
)
output_data[f"{self.pathway_name}_{process_key}_capex_cost"].loc[
year - process_construction_time : year
] = _custom_series_addition(
output_data[f"{self.pathway_name}_{process_key}_capex_cost"].loc[
year - process_construction_time : year
],
process_capex * needed_capacity / construction_time / process_load_factor,
)
# Get the variable and fixed opex for the process
variable_opex_process = _get_value_for_year(
input_data.get(f"{process_key}_eis_variable_opex"),
year,
0.0,
)
fixed_opex_process = (
_get_value_for_year(
input_data.get(f"{process_key}_eis_fixed_opex"),
year,
0.0,
)
/ process_load_factor
)
# Compute the MFSP for the process
mfsp_process = mfsp_capex_process + variable_opex_process + fixed_opex_process
# Add the MFSP for the process to the pathway MFSP
vintage_mfsp = _custom_series_addition(vintage_mfsp, mfsp_process)
# Store the process cost in the output data
output_data[
f"{self.pathway_name}_{process_key}_mean_unit_cost_without_resources"
].loc[year : year + process_lifespan] = _custom_series_addition(
output_data[
f"{self.pathway_name}_{process_key}_mean_unit_cost_without_resources"
].loc[year : year + process_lifespan],
mfsp_process * relative_share,
)
output_data[f"{self.pathway_name}_{process_key}_mean_unit_capex"].loc[
year : year + lifespan - 1
] = _custom_series_addition(
output_data[f"{self.pathway_name}_{process_key}_mean_unit_capex"].loc[
year : year + lifespan - 1
],
mfsp_capex_process * relative_share,
)
# compyte the EIS unitary capex
output_data[f"{self.pathway_name}_{process_key}_vintage_unit_capex"].loc[
year
] = mfsp_capex_process
output_data[f"{self.pathway_name}_{process_key}_mean_unit_fixed_opex"].loc[
year : year + lifespan - 1
] = _custom_series_addition(
output_data[f"{self.pathway_name}_{process_key}_mean_unit_fixed_opex"].loc[
year : year + lifespan - 1
],
fixed_opex_process * relative_share,
)
# compyte the EIS fixed opex
output_data[f"{self.pathway_name}_{process_key}_vintage_unit_fixed_opex"].loc[
year
] = fixed_opex_process
output_data[f"{self.pathway_name}_{process_key}_mean_unit_variable_opex"].loc[
year : year + lifespan - 1
] = _custom_series_addition(
output_data[
f"{self.pathway_name}_{process_key}_mean_unit_variable_opex"
].loc[year : year + lifespan - 1],
variable_opex_process * relative_share,
)
# compyte the EIS variable opex
output_data[
f"{self.pathway_name}_{process_key}_vintage_unit_variable_opex"
].loc[year] = variable_opex_process
output_data[f"{self.pathway_name}_mean_mfsp"].loc[year : year + lifespan - 1] = (
_custom_series_addition(
output_data[f"{self.pathway_name}_mean_mfsp"].loc[
year : year + lifespan - 1
],
vintage_mfsp * relative_share,
)
)
# marginal mfsp: is the new vintage the marginal one at some point of the scenario?
# Slice the relevant part
target = output_data[f"{self.pathway_name}_marginal_mfsp"].loc[
year : year + lifespan - 1
]
# Find common indices
common_index = target.index.intersection(vintage_mfsp.index)
# Align both Series
target_common = target.loc[common_index]
vintage_common = vintage_mfsp.loc[common_index]
# Build mask:
# (1) vintage > target
# (2) or target is NaN and vintage is not NaN
mask = (vintage_common > target_common) | (
target_common.isna() & vintage_common.notna()
)
# Apply the update
output_data[f"{self.pathway_name}_marginal_mfsp"].loc[common_index] = (
target_common.where(~mask, vintage_common)
)
# compute discounted costs if necessary
if self.compute_abatement_cost:
if vintage_mfsp.notna().any():
discounted_mfsp = self._unitary_cumulative_discounted_costs_vintage(
mfsp_series=vintage_mfsp,
year=year,
plant_lifespan=lifespan,
discount_rate=input_data["social_discount_rate"],
)
else:
discounted_mfsp = np.NaN
output_data[f"{self.pathway_name}_lifespan_unitary_discounted_costs"][year] = (
discounted_mfsp
)
### STEP 2: add taxes and subsidies like in TopDownCost model
# Only pathway subsidies and taxes are considered here, not resources or processes taxes
pathway_unit_subsidy_without_resource = input_data.get(
f"{self.pathway_name}_mean_unit_subsidy_without_resource", optional_nan_series.copy()
)
pathway_unit_tax_without_resource = input_data.get(
f"{self.pathway_name}_mean_unit_tax_without_resource", optional_nan_series.copy()
)
# Avoiding adding nans if subsidies and taxes defined for a shorter period of time than the mfsp
pathway_net_mfsp_without_carbon_tax = _custom_series_addition(
_custom_series_addition(
output_data[f"{self.pathway_name}_mean_mfsp"], pathway_unit_tax_without_resource
),
-pathway_unit_subsidy_without_resource,
)
# Handle possible differential carbon_tax
if f"{self.pathway_name}_carbon_tax" in input_data:
carbon_tax = (
input_data[f"{self.pathway_name}_carbon_tax"] / 1000
) # converted to €/kgCO2
else:
carbon_tax = input_data["carbon_tax"] / 1000 # converted to €/kgCO2
emission_factor = (
input_data[f"{self.pathway_name}_mean_co2_emission_factor"] / 1000
) # converted to kgCO2/MJ
pathway_unit_carbon_tax = carbon_tax * emission_factor
if f"{self.pathway_name}_vintage_eis_co2_emission_factor" in input_data:
vintage_eis_carbon_tax = (
input_data[f"{self.pathway_name}_vintage_eis_co2_emission_factor"]
/ 1000
* carbon_tax
)
output_data[f"{self.pathway_name}_vintage_eis_carbon_tax"] = vintage_eis_carbon_tax
pathway_net_mfsp = _custom_series_addition(
pathway_net_mfsp_without_carbon_tax, pathway_unit_carbon_tax
)
output_data.update(
{
f"{self.pathway_name}_net_mfsp_without_carbon_tax": pathway_net_mfsp_without_carbon_tax,
f"{self.pathway_name}_net_mfsp": pathway_net_mfsp,
f"{self.pathway_name}_mean_unit_tax": pathway_unit_tax_without_resource,
f"{self.pathway_name}_mean_unit_carbon_tax": pathway_unit_carbon_tax,
f"{self.pathway_name}_mean_unit_subsidy": pathway_unit_subsidy_without_resource,
}
)
# Store the results in the df and retun
self._store_outputs(output_data)
return output_data
|