-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathcompile_cost_assumptions.py
4187 lines (3678 loc) · 158 KB
/
compile_cost_assumptions.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
# SPDX-FileCopyrightText: Contributors to technology-data <https://github.com/pypsa/technology-data>
#
# SPDX-License-Identifier: GPL-3.0-only
# coding: utf-8
"""
Script creates cost csv for chosen years from different source (source_dict).
The data is standardized for uniform:
- cost years (depending on the rate of inflation )
- technology names
- units
Technology data from the Danish Energy Agency Technology Database are preferred.
If data are missing from all sources, these are taken from the old PyPSA cost
assumptions (with a printed warning)
The script is structured as follows:
(1) DEA data:
(a) read + convert units to same base
(b) specify assumptions for certain technologies
(c) convert to pypsa cost syntax (investment, FOM, VOM, efficiency)
(2) read data from other sources which need additional formatting:
(a) old pypsa cost assumptions
(b) Fraunhofer ISE cost assumptions
(3) merge data from all sources for every year and save it as a csv
@author: Marta, Lisa
"""
import logging
from datetime import date
import numpy as np
import pandas as pd
from _helpers import (
adjust_for_inflation,
configure_logging,
get_relative_fn,
mock_snakemake,
)
from currency_converter import ECB_URL, CurrencyConverter
from scipy import interpolate
logger = logging.getLogger(__name__)
try:
pd.set_option("future.no_silent_downcasting", True)
except Exception:
pass
# ---------- sources -------------------------------------------------------
source_dict = {
"DEA": "Danish Energy Agency",
# solar utility
"Vartiaien": "Impact of weighted average cost of capital, capital expenditure, and other parameters on future utility‐scale PV levelised cost of electricity",
# solar rooftop
"ETIP": "European PV Technology and Innovation Platform",
# fuel cost
"zappa": "Is a 100% renewable European power system feasible by 2050?",
# co2 intensity
"co2": "Entwicklung der spezifischen Kohlendioxid-Emissionen des deutschen Strommix in den Jahren 1990 - 2018",
# gas pipeline costs
"ISE": "WEGE ZU EINEM KLIMANEUTRALEN ENERGIESYSEM, Anhang zur Studie, Fraunhofer-Institut für Solare Energiesysteme ISE, Freiburg",
# Water desalination costs
"Caldera2016": "Caldera et al 2016: Local cost of seawater RO desalination based on solar PV and windenergy: A global estimate. (https://doi.org/10.1016/j.desal.2016.02.004)",
"Caldera2017": "Caldera et al 2017: Learning Curve for Seawater Reverse Osmosis Desalination Plants: Capital Cost Trend of the Past, Present, and Future (https://doi.org/10.1002/2017WR021402)",
# home battery storage and inverter investment costs
"EWG": "Global Energy System based on 100% Renewable Energy, Energywatchgroup/LTU University, 2019",
"HyNOW": "Zech et.al. DBFZ Report Nr. 19. Hy-NOW - Evaluierung der Verfahren und Technologien für die Bereitstellung von Wasserstoff auf Basis von Biomasse, DBFZ, 2014",
# efficiencies + lifetime SMR / SMR + CC
"IEA": "IEA Global average levelised cost of hydrogen production by energy source and technology, 2019 and 2050 (2020), https://www.iea.org/data-and-statistics/charts/global-average-levelised-cost-of-hydrogen-production-by-energy-source-and-technology-2019-and-2050",
# SMR capture rate
"Timmerberg": "Hydrogen and hydrogen-derived fuels through methane decomposition of natural gas – GHG emissions and costs Timmerberg et al. (2020), https://doi.org/10.1016/j.ecmx.2020.100043",
# geothermal (enhanced geothermal systems)
"Aghahosseini2020": "Aghahosseini, Breyer 2020: From hot rock to useful energy: A global estimate of enhanced geothermal systems potential, https://www.sciencedirect.com/science/article/pii/S0306261920312551",
# review of existing deep geothermal projects
"Breede2015": "Breede et al. 2015: Overcoming challenges in the classification of deep geothermal potential, https://eprints.gla.ac.uk/169585/",
# Study of deep geothermal systems in the Northern Upper Rhine Graben
"Frey2022": "Frey et al. 2022: Techno-Economic Assessment of Geothermal Resources in the Variscan Basement of the Northern Upper Rhine Graben",
# vehicles
"vehicles": "PATHS TO A CLIMATE-NEUTRAL ENERGY SYSTEM The German energy transformation in its social context. https://www.ise.fraunhofer.de/en/publications/studies/paths-to-a-climate-neutral-energy-system.html",
}
# [DEA-sheet-names]
dea_sheet_names = {
"onwind": "20 Onshore turbines",
"offwind": "21 Offshore turbines",
"solar-utility": "22 Utility-scale PV",
"solar-utility single-axis tracking": "22 Utility-scale PV tracker",
"solar-rooftop residential": "22 Rooftop PV residential",
"solar-rooftop commercial": "22 Rooftop PV commercial",
"OCGT": "52 OCGT - Natural gas",
"CCGT": "05 Gas turb. CC, steam extract.",
"oil": "50 Diesel engine farm",
"biomass CHP": "09c Straw, Large, 40 degree",
"biomass EOP": "09c Straw, Large, 40 degree",
"biomass HOP": "09c Straw HOP",
"central coal CHP": "01 Coal CHP",
"central gas CHP": "04 Gas turb. simple cycle, L",
"central gas CHP CC": "04 Gas turb. simple cycle, L",
"central solid biomass CHP": "09a Wood Chips, Large 50 degree",
"central solid biomass CHP CC": "09a Wood Chips, Large 50 degree",
"central solid biomass CHP powerboost CC": "09a Wood Chips, Large 50 degree",
"central air-sourced heat pump": "40 Comp. hp, airsource 3 MW",
"central geothermal-sourced heat pump": "45.1.a Geothermal DH, 1200m, E",
"central geothermal heat source": "45.1.a Geothermal DH, 1200m, E",
"central excess-heat-sourced heat pump": "40 Comp. hp, excess heat 10 MW",
"central water-sourced heat pump": "40 Comp. hp, seawater 20 MW",
"central ground-sourced heat pump": "40 Absorption heat pump, DH",
"central resistive heater": "41 Electric Boilers",
"central gas boiler": "44 Natural Gas DH Only",
"decentral gas boiler": "202 Natural gas boiler",
"direct firing gas": "312.a Direct firing Natural Gas",
"direct firing gas CC": "312.a Direct firing Natural Gas",
"direct firing solid fuels": "312.b Direct firing Sold Fuels",
"direct firing solid fuels CC": "312.b Direct firing Sold Fuels",
"decentral ground-sourced heat pump": "207.7 Ground source existing",
"decentral air-sourced heat pump": "207.3 Air to water existing",
"central water pit storage": "140 PTES seasonal",
"central water tank storage": "141 Large hot water tank",
"decentral water tank storage": "142 Small scale hot water tank",
"fuel cell": "12 LT-PEMFC CHP",
"hydrogen storage underground": "151c Hydrogen Storage - Caverns",
"hydrogen storage tank type 1 including compressor": "151a Hydrogen Storage - Tanks",
"micro CHP": "219 LT-PEMFC mCHP - natural gas",
"biogas": "81 Biogas, Basic plant, small",
"biogas CC": "81 Biogas, Basic plant, small",
"biogas upgrading": "82 Upgrading 3,000 Nm3 per h",
"battery": "180 Lithium Ion Battery",
"industrial heat pump medium temperature": "302.a High temp. hp Up to 125 C",
"industrial heat pump high temperature": "302.b High temp. hp Up to 150",
"electric boiler steam": "310.1 Electric boiler steam ",
"gas boiler steam": "311.1c Steam boiler Gas",
"solid biomass boiler steam": "311.1e Steam boiler Wood",
"solid biomass boiler steam CC": "311.1e Steam boiler Wood",
"biomass boiler": "204 Biomass boiler, automatic",
"electrolysis": "86 AEC 100 MW",
"direct air capture": "403.a Direct air capture",
"biomass CHP capture": "401.a Post comb - small CHP",
"cement capture": "401.c Post comb - Cement kiln",
"BioSNG": "84 Gasif. CFB, Bio-SNG",
"BtL": "85 Gasif. Ent. Flow FT, liq fu ",
"biomass-to-methanol": "97 Methanol from biomass gasif.",
"biogas plus hydrogen": "99 SNG from methan. of biogas",
"methanolisation": "98 Methanol from hydrogen",
"Fischer-Tropsch": "102 Hydrogen to Jet",
"central hydrogen CHP": "12 LT-PEMFC CHP",
"Haber-Bosch": "103 Hydrogen to Ammonia",
"air separation unit": "103 Hydrogen to Ammonia",
"waste CHP": "08 WtE CHP, Large, 50 degree",
"waste CHP CC": "08 WtE CHP, Large, 50 degree",
"biochar pyrolysis": "105 Slow pyrolysis, Straw",
"electrolysis small": "86 AEC 10 MW",
}
# [DEA-sheet-names]
uncrtnty_lookup = {
"onwind": "J:K",
"offwind": "J:K",
"solar-utility": "J:K",
"solar-utility single-axis tracking": "J:K",
"solar-rooftop residential": "J:K",
"solar-rooftop commercial": "J:K",
"OCGT": "I:J",
"CCGT": "I:J",
"oil": "I:J",
"biomass CHP": "I:J",
"biomass EOP": "I:J",
"biomass HOP": "I:J",
"central coal CHP": "",
"central gas CHP": "I:J",
"central gas CHP CC": "I:J",
"central hydrogen CHP": "I:J",
"central solid biomass CHP": "I:J",
"central solid biomass CHP CC": "I:J",
"central solid biomass CHP powerboost CC": "I:J",
"solar": "",
"central air-sourced heat pump": "J:K",
"central geothermal-sourced heat pump": "H:K",
"central geothermal heat source": "H:K",
"central excess-heat-sourced heat pump": "H:K",
"central water-sourced heat pump": "H:K",
"central ground-sourced heat pump": "I:J",
"central resistive heater": "I:J",
"central gas boiler": "I:J",
"decentral gas boiler": "I:J",
"direct firing gas": "H:I",
"direct firing gas CC": "H:I",
"direct firing solid fuels": "H:I",
"direct firing solid fuels CC": "H:I",
"decentral ground-sourced heat pump": "I:J",
"decentral air-sourced heat pump": "I:J",
"central water pit storage": "J:K",
"central water tank storage": "J:K",
"decentral water tank storage": "J:K",
"fuel cell": "I:J",
"hydrogen storage underground": "J:K",
"hydrogen storage tank type 1 including compressor": "J:K",
"micro CHP": "I:J",
"biogas": "I:J",
"biogas CC": "I:J",
"biogas upgrading": "I:J",
"electrolysis": "I:J",
"battery": "L,N",
"direct air capture": "I:J",
"cement capture": "I:J",
"biomass CHP capture": "I:J",
"BioSNG": "I:J",
"BtL": "J:K",
"biomass-to-methanol": "J:K",
"biogas plus hydrogen": "J:K",
"industrial heat pump medium temperature": "H:I",
"industrial heat pump high temperature": "H:I",
"electric boiler steam": "H:I",
"gas boiler steam": "H:I",
"solid biomass boiler steam": "H:I",
"solid biomass boiler steam CC": "H:I",
"biomass boiler": "I:J",
"Fischer-Tropsch": "I:J",
"Haber-Bosch": "I:J",
"air separation unit": "I:J",
"methanolisation": "J:K",
"waste CHP": "I:J",
"waste CHP CC": "I:J",
"biochar pyrolysis": "J:K",
"biomethanation": "J:K",
"electrolysis small": "I:J",
}
# since February 2022 DEA uses a new format for the technology data
# all Excel sheets of updated technologies have a different layout and are
# given in EUR_2020 money (instead of EUR_2015)
cost_year_2020 = [
"solar-utility",
"solar-utility single-axis tracking",
"solar-rooftop residential",
"solar-rooftop commercial",
"offwind",
"electrolysis",
"biogas",
"biogas CC",
"biogas upgrading",
"direct air capture",
"biomass CHP capture",
"cement capture",
"BioSNG",
"BtL",
"biomass-to-methanol",
"biogas plus hydrogen",
"methanolisation",
"Fischer-Tropsch",
"biochar pyrolysis",
"biomethanation",
"electrolysis small",
]
cost_year_2019 = [
"direct firing gas",
"direct firing gas CC",
"direct firing solid fuels",
"direct firing solid fuels CC",
"industrial heat pump medium temperature",
"industrial heat pump high temperature",
"electric boiler steam",
"gas boiler steam",
"solid biomass boiler steam",
"solid biomass boiler steam CC",
]
# -------- FUNCTIONS ---------------------------------------------------
def get_excel_sheets(list_of_excel_files: list) -> dict:
"""
The function reads Excel files and returns them in a dictionary.
The dictionary has the files names as keys and the lists of sheet names as values.
Parameters
----------
list_of_excel_files : list
Excel files to process
Returns
-------
Dictionary
data from DEA
"""
excel_sheets_dictionary = {}
for entry in list_of_excel_files:
if entry[-5:] == ".xlsx":
excel_sheets_dictionary[entry] = pd.ExcelFile(entry).sheet_names
logger.info(f"found {len(excel_sheets_dictionary)} excel sheets: ")
for key in excel_sheets_dictionary.keys():
logger.info(f"* {key}")
return excel_sheets_dictionary
def get_sheet_location(
tech_name: str, sheet_names_dict: dict, input_data_dict: dict
) -> str:
"""
The function returns a dictionary. The dictionary has the technology names as keys and
the Excel file names where the technology is saved as values
Parameters
----------
tech_name : str
technology name
sheet_names_dict : dict
dictionary having the technology name as keys and Excel sheet names as values
input_data_dict : dict
dictionary having the files names as keys and the lists of sheet names as values
Returns
-------
str
Excel file name where the technology is present
"""
key_list = [
key
for key, value in input_data_dict.items()
if any(sheet_names_dict[tech_name] in s for s in value)
]
if len(key_list) == 1:
return key_list[0]
elif len(key_list) > 1:
logger.info(f"{tech_name} appears in more than one sheet name")
return "Multiple sheets found"
else:
logger.info(
f"tech {tech_name} with sheet name {sheet_names_dict[tech_name]} not found in excel sheets. "
)
return "Sheet not found"
def get_dea_maritime_data(
fn: str, years: list, input_data_df: pd.DataFrame
) -> pd.DataFrame:
"""
The function returns a dataframe containing the technology data for shipping from the DEA database.
Parameters
----------
fn : str
path to DEA input data file for shipping
years : list
years for which a cost assumption is provided
input_data_df : pandas.DataFrame
technology data cost assumptions
Returns
-------
pandas.DataFrame
technology data cost assumptions enriched with shipping data from DEA
"""
dea_maritime_data_sheet_names = [
"Container feeder, diesel",
"Container feeder, methanol",
"Container feeder, ammonia",
"Container, diesel",
"Container, methanol",
"Container, ammonia",
"Tank&bulk, diesel",
"Tank&bulk, methanol",
"Tankbulk, ammonia",
]
excel = pd.read_excel(
fn,
sheet_name=dea_maritime_data_sheet_names,
index_col=[0, 1],
usecols="A:F",
na_values="N/A",
engine="calamine",
)
wished_index = [
"Typical ship lifetime (years)",
"Upfront ship cost (mill. €)",
"Fixed O&M (€/year)",
"Variable O&M (€/nm)",
]
for sheet in excel.keys():
df = excel[sheet]
df = df.iloc[1:, :].set_axis(df.iloc[0], axis=1)
assert "Typical operational speed" in df.index.get_level_values(1)[22]
# in unit GJ/nm
efficiency = df.iloc[22]
df = df[df.index.get_level_values(1).isin(wished_index)]
df = df.droplevel(level=0)
df.loc["efficiency (GJ/nm)"] = efficiency
df = df.reindex(columns=pd.Index(years).union(df.columns))
df = df.astype(float)
df = df.interpolate(axis=1, limit_direction="both")
df = df[years]
# dropna
df = df.dropna(how="all", axis=0)
# add column for units
df["unit"] = df.rename(
index=lambda x: x[x.rfind("(") + 1 : x.rfind(")")]
).index.values
df["unit"] = df.unit.str.replace("€", "EUR")
# remove units from index
df.index = df.index.str.replace(r" \(.*\)", "", regex=True)
# convert million Euro -> Euro
df_i = df[df.unit == "mill. EUR"].index
df.loc[df_i, years] *= 1e6
df.loc[df_i, "unit"] = "EUR"
# convert FOM in % of investment/year
if "Fixed O&M" in df.index:
df.loc["Fixed O&M", years] /= df.loc["Upfront ship cost", years] * 100
df.loc["Fixed O&M", "unit"] = "%/year"
# convert nm in km
# 1 Nautical Mile (nm) = 1.852 Kilometers (km)
df_i = df[df.unit.str.contains("/nm")].index
df.loc[df_i, years] /= 1.852
df.loc[df_i, "unit"] = df.loc[df_i, "unit"].str.replace("/nm", "/km")
# 1 GJ = 1/3600 * 1e9 Wh = 1/3600 * 1e3 MWh
df_i = df[df.unit.str.contains("GJ")].index
df.loc[df_i, years] *= 1e3 / 3600
df.loc[df_i, "unit"] = df.loc[df_i, "unit"].str.replace("GJ", "MWh")
# add source + cost year
df["source"] = f"Danish Energy Agency, {get_relative_fn(fn)}"
# cost year is 2023 p.10
df["currency_year"] = 2023
# add sheet name
df["further description"] = sheet
# FOM, VOM,efficiency, lifetime, investment
rename = {
"Typical ship lifetime": "lifetime",
"Upfront ship cost": "investment",
"Fixed O&M": "FOM",
"Variable O&M": "VOM",
}
df = df.rename(index=rename)
df = pd.concat([df], keys=[sheet], names=["technology", "parameter"])
input_data_df = pd.concat([input_data_df, df])
return input_data_df
def get_dea_vehicle_data(
fn: str, years: list, technology_dataframe: pd.DataFrame
) -> pd.DataFrame:
"""
The function gets heavy-duty vehicle data from DEA.
Parameters
----------
fn : str
path to DEA input data file for shipping
years : list
years for which a cost assumption is provided
technology_dataframe : pandas.DataFrame
technology data cost assumptions
Returns
-------
pandas.DataFrame
technology data cost assumptions enriched with shipping data from DEA
"""
dea_vehicle_data_sheet_names = [
"Diesel L1",
"Diesel L2",
"Diesel L3",
"Diesel B1",
"Diesel B2",
"BEV L1",
"BEV L2",
"BEV L3",
"BEV B1",
"BEV B2",
"FCV L1",
"FCV L2",
"FCV L3",
"FCV B1",
"FCV B2",
]
excel = pd.read_excel(
fn,
sheet_name=dea_vehicle_data_sheet_names,
index_col=0,
usecols="A:F",
na_values="no data",
engine="calamine",
)
wished_index = [
"Typical vehicle lifetime (years)",
"Upfront vehicle cost (€)",
"Fixed maintenance cost (€/year)",
"Variable maintenance cost (€/km)",
"Motor size (kW)",
]
# clarify DEA names
types = {
"L1": "Truck Solo max 26 tons",
"L2": "Truck Trailer max 56 tons",
"L3": "Truck Semi-Trailer max 50 tons",
"B1": "Bus city",
"B2": "Coach",
}
for sheet in excel.keys():
df = excel[sheet]
tech = sheet.split()[0] + " " + types.get(sheet.split()[1], "")
df = df.iloc[1:, :].set_axis(df.iloc[0], axis=1)
# "Fuel energy - typical load (MJ/km)"
# represents efficiency for average weight vehicle carries during normal
# operation, currently assuming mean between urban, regional and long haul
assert df.index[27] == "Fuel energy - typical load (MJ/km)"
efficiency = df.iloc[28:31].mean()
df = df[df.index.isin(wished_index)]
df.loc["efficiency (MJ/km)"] = efficiency
df = df.reindex(columns=pd.Index(years).union(df.columns))
df = df.interpolate(axis=1, limit_direction="both")
df = df[years]
# add column for units
df["unit"] = df.rename(
index=lambda x: x[x.rfind("(") + 1 : x.rfind(")")]
).index.values
df["unit"] = df.unit.str.replace("€", "EUR")
# remove units from index
df.index = df.index.str.replace(r" \(.*\)", "", regex=True)
# convert MJ in kWh -> 1 kWh = 3.6 MJ
df_i = df.index[df.unit == "MJ/km"]
df.loc[df_i, years] /= 3.6
df.loc[df_i, "unit"] = "kWh/km"
# convert FOM in % of investment/year
df.loc["Fixed maintenance cost", years] /= (
df.loc["Upfront vehicle cost", years] * 100
)
df.loc["Fixed maintenance cost", "unit"] = "%/year"
# clarify costs are per vehicle
df.loc["Upfront vehicle cost", "unit"] += "/vehicle"
# add source + cost year
df["source"] = f"Danish Energy Agency, {get_relative_fn(fn)}"
# cost year is 2022 p.12
df["currency_year"] = 2022
# add sheet name
df["further description"] = sheet
# FOM, VOM,efficiency, lifetime, investment
rename = {
"Typical vehicle lifetime": "lifetime",
"Upfront vehicle cost": "investment",
"Fixed maintenance cost": "FOM",
"Variable maintenance cost": "VOM",
}
df = df.rename(index=rename)
to_keep = ["Motor size", "lifetime", "FOM", "VOM", "efficiency", "investment"]
df = df[df.index.isin(to_keep)]
df = pd.concat([df], keys=[tech], names=["technology", "parameter"])
technology_dataframe = pd.concat([technology_dataframe, df])
return technology_dataframe
def get_data_DEA(
years: list,
tech_name: str,
sheet_names_dict: dict,
input_data_dict: dict,
offwind_no_grid_costs_flag: bool = True,
expectation: str = None,
) -> pd.DataFrame:
"""
The function interpolates costs for a given technology from DEA database sheet and
stores technology data from DEA in a dictionary.
Parameters
----------
years : list
years for which a cost assumption is provided
tech_name : str
technology name
sheet_names_dict : dict
dictionary having the technology name as keys and Excel sheet names as values
input_data_dict : dict
dictionary where the keys are the path to the DEA inputs and the values are the sheet names
offwind_no_grid_costs_flag : bool
flag to remove grid connection costs from DEA for offwind. Such costs are calculated separately in pypsa-eur
expectation : str
tech data uncertainty. The possible options are [None, "optimist", "pessimist"]
Returns
-------
pandas.DataFrame
technology data from DEA
"""
excel_file = get_sheet_location(tech_name, sheet_names_dict, input_data_dict)
if excel_file == "Sheet not found" or excel_file == "Multiple sheets found":
logger.info(f"excel file not found for technology: {tech_name}")
return pd.DataFrame()
if tech_name == "battery":
usecols = "B:J"
elif tech_name in [
"direct air capture",
"cement capture",
"biomass CHP capture",
]:
usecols = "A:F"
elif tech_name in [
"industrial heat pump medium temperature",
"industrial heat pump high temperature",
"electric boiler steam",
"gas boiler steam",
"solid biomass boiler steam",
"solid biomass boiler steam CC",
"direct firing gas",
"direct firing gas CC",
"direct firing solid fuels",
"direct firing solid fuels CC",
]:
usecols = "A:E"
elif tech_name in ["Fischer-Tropsch", "Haber-Bosch", "air separation unit"]:
usecols = "B:F"
elif tech_name in ["central water-sourced heat pump"]:
usecols = "B,I,K"
else:
usecols = "B:G"
usecols += f",{uncrtnty_lookup[tech_name]}"
if (
(tech_name in cost_year_2019)
or (tech_name in cost_year_2020)
or ("renewable_fuels" in excel_file)
):
skiprows = [0]
else:
skiprows = [0, 1]
excel = pd.read_excel(
excel_file,
sheet_name=sheet_names_dict[tech_name],
index_col=0,
usecols=usecols,
skiprows=skiprows,
na_values="N.A",
engine="calamine",
)
excel.dropna(axis=1, how="all", inplace=True)
excel.index = excel.index.fillna(" ")
excel.index = excel.index.astype(str)
excel.dropna(axis=0, how="all", inplace=True)
if tech_name in ["central water-sourced heat pump"]:
# use only upper uncertainty range for systems without existing water intake
# convert "Uncertainty (2025)"" to "2025", "Uncertainty (2050)"" to "2050" (and so on if more years are added)
this_years = (
excel.loc[:, excel.iloc[1, :] == "Lower"]
.iloc[0, :]
.str.slice(-5, -1)
.astype(int)
)
# get values in upper uncertainty range
excel = excel.loc[:, excel.iloc[1, :] == "Upper"]
# rename columns to years constructed above
excel.columns = this_years
# add missing years
for y in years:
if y not in excel.columns:
excel[y] = np.nan
# Sort columns by year
excel = excel.reindex(sorted(excel.columns), axis=1)
# drop row Energy/technical data (not needed, contains strings which break interpolation)
excel = excel[~excel.index.str.contains("Energy/technical data")]
# Interpolate to fill in NaN values
excel = excel.astype(float).interpolate(axis=1, method="linear")
# Extrapolation for missing values (not native in pandas)
# Currently, this is only first column (2020), since DEA data is available for 2025 and 2050
if excel.iloc[:, 0].isnull().all():
excel.iloc[:, 0] = excel.iloc[:, 1] + (
excel.iloc[:, 1] - excel.iloc[:, 2]
) / (excel.columns[2] - excel.columns[1]) * (
excel.columns[1] - excel.columns[0]
)
if 2020 not in excel.columns:
selection = excel[excel.isin([2020])].dropna(how="all").index
excel.columns = excel.loc[selection].iloc[0, :].fillna("Technology", limit=1)
excel.drop(selection, inplace=True)
uncertainty_columns = ["2050-optimist", "2050-pessimist"]
if uncrtnty_lookup[tech_name]:
# hydrogen storage sheets have reverse order of lower/upper estimates
if tech_name in [
"hydrogen storage tank type 1 including compressor",
"hydrogen storage cavern",
]:
uncertainty_columns.reverse()
excel.rename(
columns={
excel.columns[-2]: uncertainty_columns[0],
excel.columns[-1]: uncertainty_columns[1],
},
inplace=True,
)
else:
for col in uncertainty_columns:
excel.loc[:, col] = excel.loc[:, 2050]
swap_patterns = [
"technical life",
"efficiency",
"Hydrogen output, at LHV",
] # cases where bigger is better
swap = [any(term in idx.lower() for term in swap_patterns) for idx in excel.index]
tmp = excel.loc[swap, "2050-pessimist"]
excel.loc[swap, "2050-pessimist"] = excel.loc[swap, "2050-optimist"]
excel.loc[swap, "2050-optimist"] = tmp
if expectation:
# drop duplicates
excel = excel[~excel.index.duplicated()]
excel.loc[:, 2050] = excel.loc[:, f"2050-{expectation}"].combine_first(
excel.loc[:, 2050]
)
excel.drop(columns=uncertainty_columns, inplace=True)
# fix for battery with different Excel sheet format
if tech_name == "battery":
excel.rename(columns={"Technology": 2040}, inplace=True)
if expectation:
excel = excel.loc[:, [2020, 2050]]
parameters = [
"efficiency",
"investment",
"Fixed O&M",
"Variable O&M",
"production capacity for one unit",
"Output capacity expansion cost",
"Hydrogen Output",
"Hydrogen (% total input_e (MWh / MWh))",
"Hydrogen [% total input_e",
" - hereof recoverable for district heating (%-points of heat loss)",
"Cb coefficient",
"Cv coefficient",
"Distribution network costs",
"Technical life",
"Energy storage expansion cost",
"Output capacity expansion cost (M€2015/MW)",
"Heat input",
"Heat input",
"Electricity input",
"Eletricity input",
"Heat out",
"capture rate",
"FT Liquids Output, MWh/MWh Total Input",
" - hereof recoverable for district heating [%-points of heat loss]",
" - hereof recoverable for district heating (%-points of heat loss)",
"Bio SNG Output [% of fuel input]",
"Methanol Output",
"District heat Output",
"Electricity Output",
"Total O&M",
"Biochar Output", # biochar pyrolysis
"Pyrolysis oil Output", # biochar pyrolysis
"Pyrolysis gas Output", # biochar pyrolysis
"Heat Output", # biochar pyrolysis
"Specific energy content [GJ/ton] biochar", # biochar pyrolysis
"Electricity Consumption",
"Feedstock Consumption", # biochar pyrolysis
"Methane Output",
"CO2 Consumption",
"Hydrogen Consumption",
" - of which is equipment excluding heat pump",
" - of which is heat pump including its installation",
"Input capacity",
"Output capacity",
"Energy storage capacity",
]
df = pd.DataFrame()
for para in parameters:
# attr = excel[excel.index.str.contains(para)]
attr = excel[[para in index for index in excel.index]]
if len(attr) != 0:
df = pd.concat([df, attr])
df.index = df.index.str.replace("€", "EUR")
df = df.reindex(columns=df.columns[df.columns.isin(years)])
df = df[~df.index.duplicated(keep="first")]
# replace missing data
df.replace("-", np.nan, inplace=True)
# average data in format "lower_value-upper_value"
df = df.apply(
lambda row: row.apply(
lambda x: (float(x.split("-")[0]) + float(x.split("-")[1])) / 2
if isinstance(x, str) and "-" in x
else x
),
axis=1,
)
# remove symbols "~", ">", "<" and " "
for sym in ["~", ">", "<", " "]:
df = df.apply(
lambda col: col.apply(
lambda x: x.replace(sym, "") if isinstance(x, str) else x
)
)
df = df.astype(float)
df = df.mask(
df.apply(pd.to_numeric, errors="coerce").isnull(),
df.astype(str).apply(lambda x: x.str.strip()),
)
# Modify data loaded from DEA on a per-technology case
if (tech_name == "offwind") and offwind_no_grid_costs_flag:
df.loc["Nominal investment (*total) [MEUR/MW_e, 2020]"] -= excel.loc[
"Nominal investment (installation: grid connection) [M€/MW_e, 2020]"
]
# Exclude indirect costs for centralised system with additional piping.
if tech_name.startswith("industrial heat pump"):
df = df.drop("Indirect investments cost (MEUR per MW)")
if tech_name == "biogas plus hydrogen":
df.drop(df.loc[df.index.str.contains("GJ SNG")].index, inplace=True)
if tech_name == "BtL":
df.drop(df.loc[df.index.str.contains("1,000 t FT Liquids")].index, inplace=True)
if tech_name == "biomass-to-methanol":
df.drop(df.loc[df.index.str.contains("1,000 t Methanol")].index, inplace=True)
if tech_name == "methanolisation":
df.drop(df.loc[df.index.str.contains("1,000 t Methanol")].index, inplace=True)
if tech_name == "Fischer-Tropsch":
df.drop(df.loc[df.index.str.contains("l FT Liquids")].index, inplace=True)
if tech_name == "biomass boiler":
df.drop(
df.loc[df.index.str.contains("Possible additional")].index, inplace=True
)
df.drop(df.loc[df.index.str.contains("Total efficiency")].index, inplace=True)
if tech_name == "Haber-Bosch":
df.drop(
df.loc[
df.index.str.contains("Specific investment mark-up factor optional ASU")
].index,
inplace=True,
)
df.drop(
df.loc[
df.index.str.contains(
"Specific investment (MEUR /TPD Ammonia output", regex=False
)
].index,
inplace=True,
)
df.drop(
df.loc[
df.index.str.contains("Fixed O&M (MEUR /TPD Ammonia", regex=False)
].index,
inplace=True,
)
df.drop(
df.loc[
df.index.str.contains("Variable O&M (EUR /t Ammonia)", regex=False)
].index,
inplace=True,
)
if tech_name == "air separation unit":
divisor = (
(df.loc["Specific investment mark-up factor optional ASU"] - 1.0)
/ excel.loc["N2 Consumption, [t/t] Ammonia"]
).astype(float)
# Calculate ASU cost separate to HB facility in terms of t N2 output
df.loc[
[
"Specific investment [MEUR /TPD Ammonia output]",
"Fixed O&M [kEUR /TPD Ammonia]",
"Variable O&M [EUR /t Ammonia]",
]
] *= divisor
# Convert output to hourly generation
df.loc[
[
"Specific investment [MEUR /TPD Ammonia output]",
"Fixed O&M [kEUR /TPD Ammonia]",
]
] *= 24
# Rename costs for correct units
df.index = df.index.str.replace("MEUR /TPD Ammonia output", "MEUR/t_N2/h")
df.index = df.index.str.replace("kEUR /TPD Ammonia", "kEUR/t_N2/h/year")
df.index = df.index.str.replace("EUR /t Ammonia", "EUR/t_N2")
df.drop(
df.loc[
df.index.str.contains("Specific investment mark-up factor optional ASU")
].index,
inplace=True,
)
df.drop(
df.loc[
df.index.str.contains(
"Specific investment [MEUR /MW Ammonia output]", regex=False
)
].index,
inplace=True,
)
df.drop(
df.loc[
df.index.str.contains("Fixed O&M [kEUR/MW Ammonia/year]", regex=False)
].index,
inplace=True,
)
df.drop(
df.loc[
df.index.str.contains("Variable O&M [EUR/MWh Ammonia]", regex=False)
].index,
inplace=True,
)
if "solid biomass power" in tech_name:
df.index = df.index.str.replace("EUR/MWeh", "EUR/MWh")
if "biochar pyrolysis" in tech_name:
df = biochar_pyrolysis_harmonise_dea(df)
elif tech_name == "central geothermal-sourced heat pump":
df.loc["Nominal investment (MEUR per MW)"] = df.loc[
" - of which is heat pump including its installation"
]
elif tech_name == "central geothermal heat source":
df.loc["Nominal investment (MEUR per MW)"] = df.loc[
" - of which is equipment excluding heat pump"
]
df_final = pd.DataFrame(index=df.index, columns=years)
# [RTD-interpolation-example]
for index in df_final.index:
values = np.interp(
x=years,
xp=df.columns.values.astype(float),
fp=df.loc[index, :].values.astype(float),
)
df_final.loc[index, :] = values
# if year-specific data is missing and not fixed by interpolation fill forward with same values
df_final = df_final.ffill(axis=1)
df_final["source"] = f"{source_dict['DEA']}, {get_relative_fn(excel_file)}"
if (
tech_name in cost_year_2020
and ("for_carbon_capture_transport_storage" not in excel_file)
and ("renewable_fuels" not in excel_file)
):
for attr in ["investment", "Fixed O&M"]:
to_drop = df[