@@ -658,122 +658,80 @@ def within_plot(
658658 return fig
659659
660660
661+ import pandas as pd
662+ import numpy as np
663+ import matplotlib .pyplot as plt
664+
665+
661666def elec_val_plot (df , savepath ):
662- # electricity validation for 2020
667+ years = df .columns .astype (int )
668+
669+ # use 2020 if available, otherwise first available year
670+ if 2020 in years :
671+ year = 2020
672+ title_suffix = "2020"
673+ else :
674+ year = years [0 ]
675+ title_suffix = f"{ year } (2020 data unavailable)"
676+
663677 elec_capacities = pd .DataFrame (
664678 index = [
665- "ror" ,
666- "hydro" ,
667- "battery" ,
668- "biomass" ,
669- "nuclear" ,
670- "lignite" ,
671- "coal" ,
672- "oil" ,
673- "gas" ,
674- "wind_onshore" ,
675- "wind_offshore" ,
676- "solar" ,
679+ "ror" , "hydro" , "battery" , "biomass" , "nuclear" ,
680+ "lignite" , "coal" , "oil" , "gas" ,
681+ "wind_onshore" , "wind_offshore" , "solar" ,
677682 ]
678683 )
679684 elec_generation = pd .DataFrame (
680685 index = [
681- "net exports" ,
682- "ror" ,
683- "hydro" ,
684- "battery" ,
685- "biomass" ,
686- "nuclear" ,
687- "lignite" ,
688- "coal" ,
689- "oil" ,
690- "gas" ,
691- "wind" ,
692- "solar" ,
686+ "net exports" , "ror" , "hydro" , "battery" , "biomass" ,
687+ "nuclear" , "lignite" , "coal" , "oil" , "gas" , "wind" , "solar" ,
693688 ]
694689 )
695690
691+ # real capacities (fixed 2020 reference)
696692 elec_capacities ["real" ] = [
697- 4.94 ,
698- 9.69 ,
699- 2.4 ,
700- 8.72 ,
701- 8.11 ,
702- 20.86 ,
703- 23.74 ,
704- 4.86 ,
705- 32.54 ,
706- 54.25 ,
707- 7.86 ,
708- 54.36 ,
709- ] # https://energy-charts.info/charts/installed_power/chart.htm?l=en&c=DE&year=2020
693+ 4.94 , 9.69 , 2.4 , 8.72 , 8.11 , 20.86 , 23.74 , 4.86 ,
694+ 32.54 , 54.25 , 7.86 , 54.36 ,
695+ ]
696+
697+ # PyPSA model capacities (year-dependent)
710698 elec_capacities ["pypsa" ] = [
711699 0 ,
712- df .loc [("Capacity|Electricity|Hydro" , "GW" ), 2020 ],
700+ df .loc [("Capacity|Electricity|Hydro" , "GW" ), year ],
713701 0 ,
714- df .loc [("Capacity|Electricity|Biomass" , "GW" ), 2020 ],
715- df .loc [("Capacity|Electricity|Nuclear" , "GW" ), 2020 ],
716- df .loc [("Capacity|Electricity|Coal|Lignite" , "GW" ), 2020 ],
717- df .loc [("Capacity|Electricity|Coal|Hard Coal" , "GW" ), 2020 ],
718- df .loc [("Capacity|Electricity|Oil" , "GW" ), 2020 ],
719- df .loc [("Capacity|Electricity|Gas" , "GW" ), 2020 ],
720- df .loc [("Capacity|Electricity|Wind|Onshore" , "GW" ), 2020 ],
721- df .loc [("Capacity|Electricity|Wind|Offshore" , "GW" ), 2020 ],
722- df .loc [("Capacity|Electricity|Solar" , "GW" ), 2020 ],
702+ df .loc [("Capacity|Electricity|Biomass" , "GW" ), year ],
703+ df .loc [("Capacity|Electricity|Nuclear" , "GW" ), year ],
704+ df .loc [("Capacity|Electricity|Coal|Lignite" , "GW" ), year ],
705+ df .loc [("Capacity|Electricity|Coal|Hard Coal" , "GW" ), year ],
706+ df .loc [("Capacity|Electricity|Oil" , "GW" ), year ],
707+ df .loc [("Capacity|Electricity|Gas" , "GW" ), year ],
708+ df .loc [("Capacity|Electricity|Wind|Onshore" , "GW" ), year ],
709+ df .loc [("Capacity|Electricity|Wind|Offshore" , "GW" ), year ],
710+ df .loc [("Capacity|Electricity|Solar" , "GW" ), year ],
723711 ]
724712
725713 elec_generation ["real (gross)" ] = [
726- - 18.9 , # net exports",
727- np .nan , # ror
728- 18.7 , # hydro
729- np .nan , # battery
730- 45 , # biomass
731- 64 , # nuclear
732- 91 , # lignite
733- 43 , # coal
734- 4.7 , # oil
735- 95 , # gas
736- 132 , # wind
737- 50 , # solar
714+ - 18.9 , np .nan , 18.7 , np .nan , 45 , 64 , 91 , 43 , 4.7 , 95 , 132 , 50 ,
738715 ]
739- # https://www.destatis.de/DE/Themen/Branchen-Unternehmen/Energie/Erzeugung/Tabellen/bruttostromerzeugung.html
740- # https://www.bdew.de/media/documents/Bruttostromerz_D_Entw_10J_online_o_dw2x_jaehrlich_FS_05042024_nlA6lUa.pdf
741-
742- # obtained so that it fits how pypsa models the energy sector
743716 elec_generation ["real (net, pypsa representation)" ] = [
744- - 18.9 , # 34 TWH in 2019 "net exports",
745- 0 , # "ror" due to reporting
746- 18.54 , # "hydro"
747- np .nan , # "battery"
748- 44.85 , # "biomass"
749- 60.91 , # "nuclear"
750- 84.5 , # "lignite" (82.13 + 2.37 (industrial own production)
751- 38.7 , # "coal"
752- 3.71 , # "oil"
753- 91.7 , # "gas" 34.6 (industry self consumption) + 57.1 (fossil gas grid feed in)
754- 129.64 , # "wind"
755- 48.5 , # "solar"
717+ - 18.9 , 0 , 18.54 , np .nan , 44.85 , 60.91 , 84.5 , 38.7 , 3.71 , 91.7 , 129.64 , 48.5 ,
756718 ]
757- # https://energy-charts.info/charts/energy_pie/chart.htm?l=de&c=DE&interval=year&year=2020
758- # https://www.bundesnetzagentur.de/SharedDocs/Pressemitteilungen/DE/2021/20210102_smard.html
759- # https://energy-charts.info/charts/energy/chart.htm?l=en&c=DE&interval=year&year=2020&source=total
760-
761719 elec_generation ["pypsa (net)" ] = [
762- - df .loc [("Trade|Secondary Energy|Electricity|Volume" , "TWh/yr" ), 2020 ],
720+ - df .loc [("Trade|Secondary Energy|Electricity|Volume" , "TWh/yr" ), year ],
763721 0 ,
764- df .loc [("Secondary Energy|Electricity|Hydro" , "TWh/yr" ), 2020 ],
722+ df .loc [("Secondary Energy|Electricity|Hydro" , "TWh/yr" ), year ],
765723 0 ,
766- df .loc [("Secondary Energy|Electricity|Biomass" , "TWh/yr" ), 2020 ],
767- df .loc [("Secondary Energy|Electricity|Nuclear" , "TWh/yr" ), 2020 ],
768- df .loc [("Secondary Energy|Electricity|Coal|Lignite" , "TWh/yr" ), 2020 ],
769- df .loc [("Secondary Energy|Electricity|Coal|Hard Coal" , "TWh/yr" ), 2020 ],
770- df .loc [("Secondary Energy|Electricity|Oil" , "TWh/yr" ), 2020 ],
771- df .loc [("Secondary Energy|Electricity|Gas" , "TWh/yr" ), 2020 ],
772- df .loc [("Secondary Energy|Electricity|Wind" , "TWh/yr" ), 2020 ],
773- df .loc [("Secondary Energy|Electricity|Solar" , "TWh/yr" ), 2020 ],
724+ df .loc [("Secondary Energy|Electricity|Biomass" , "TWh/yr" ), year ],
725+ df .loc [("Secondary Energy|Electricity|Nuclear" , "TWh/yr" ), year ],
726+ df .loc [("Secondary Energy|Electricity|Coal|Lignite" , "TWh/yr" ), year ],
727+ df .loc [("Secondary Energy|Electricity|Coal|Hard Coal" , "TWh/yr" ), year ],
728+ df .loc [("Secondary Energy|Electricity|Oil" , "TWh/yr" ), year ],
729+ df .loc [("Secondary Energy|Electricity|Gas" , "TWh/yr" ), year ],
730+ df .loc [("Secondary Energy|Electricity|Wind" , "TWh/yr" ), year ],
731+ df .loc [("Secondary Energy|Electricity|Solar" , "TWh/yr" ), year ],
774732 ]
775733
776- # elec_generation.loc["sum/10"] = elec_generation.sum().div(10 )
734+ # difference check rows (optional )
777735 elec_generation .loc ["sum_real_gross-sum_pypsa" , "sum_real_gross-sum_pypsa" ] = (
778736 elec_generation .sum ()["real (gross)" ] - elec_generation .sum ()["pypsa (net)" ]
779737 )
@@ -783,18 +741,18 @@ def elec_val_plot(df, savepath):
783741 )
784742
785743 fig , axes = plt .subplots (1 , 2 , figsize = (14 , 6 ), width_ratios = [1 , 1.5 ])
744+
786745 elec_capacities .plot (kind = "bar" , ax = axes [0 ])
787746 axes [0 ].set_ylabel ("GW" )
788- axes [0 ].set_title ("Installed Capacities Germany 2020 " )
747+ axes [0 ].set_title (f "Installed Capacities Germany { title_suffix } " )
789748
790749 elec_generation .plot (kind = "bar" , ax = axes [1 ])
791750 axes [1 ].set_ylabel ("TWh" )
792- axes [1 ].set_title ("Electricity Generation Germany 2020 " )
751+ axes [1 ].set_title (f "Electricity Generation Germany { title_suffix } " )
793752
794753 plt .tight_layout ()
795- plt .close ()
796754 fig .savefig (savepath , bbox_inches = "tight" )
797-
755+ plt . close ( fig )
798756 return fig
799757
800758
@@ -828,8 +786,9 @@ def elec_val_plot(df, savepath):
828786 ).round (5 )
829787
830788 years = df .columns .astype (int )
789+ elec_val_plot (df , savepath = snakemake .output .elec_val_2020 )
790+
831791 if 2020 in years :
832- elec_val_plot (df , savepath = snakemake .output .elec_val_2020 )
833792 df .drop (columns = [2020 ], inplace = True )
834793
835794 leitmodell = "REMIND-EU v1.1"
0 commit comments