From 676bb98cef513b424d8b15e6cdfb21d90468b2e3 Mon Sep 17 00:00:00 2001 From: alonsoju95 Date: Fri, 27 May 2022 11:28:33 +0200 Subject: [PATCH 01/15] Defines functions to plot and provide a better context of parameters eGon2035 and eGon100RE --- src/egon/data/datasets/plotdatascn.py | 53 +++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/egon/data/datasets/plotdatascn.py diff --git a/src/egon/data/datasets/plotdatascn.py b/src/egon/data/datasets/plotdatascn.py new file mode 100644 index 000000000..7d5eea2d8 --- /dev/null +++ b/src/egon/data/datasets/plotdatascn.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Tue May 24 14:42:05 2022 +Plotdatascn.py defines functions to plot to provide a better context of the different parameters part of +scenarios eGon2035 and eGon100RE . +@author: Alonso + +""" + +# import logging +# import os +# from matplotlib import pyplot as plt +# import matplotlib.patches as mpatches +#import matplotlib +#import pandas as pd +#import numpy as np +#from math import sqrt, log10 +#from pyproj import Proj, transform +# import tilemapbase +#import geopandas as gpd +#from egon.data import db +#from egon.data.config import settings +#from egon.data.datasets import Dataset +#import egon.data.config +import pandas as pd +from egon.data import db +from egon.data.datasets import Dataset +import egon.data.config +import geopandas as gpd + + +#logger = logging.getLogger(__name__) + +#if 'READTHEDOCS' not in os.environ: + #from geoalchemy2.shape import to_shape + +__copyright__ = ("Flensburg University of Applied Sciences, " + "Europa-Universität Flensburg, " + "Centre for Sustainable Energy Systems, " + "DLR-Institute for Networked Energy Systems") +__license__ = "" +__author__ = "" + +con = db.engine() + # get MV grid districts +sql = "SELECT bus_id, geom FROM grid.egon_mv_grid_district" +distr = gpd.GeoDataFrame.from_postgis(sql, con) +distr = distr.set_index("bus_id") + + + + \ No newline at end of file From ef0cdee15b9296b031c6c6ce9d37ec57120322fb Mon Sep 17 00:00:00 2001 From: alonsoju95 Date: Tue, 31 May 2022 14:10:24 +0200 Subject: [PATCH 02/15] code to add carrier and p_nom values --- src/egon/data/datasets/plotdatascn.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/egon/data/datasets/plotdatascn.py b/src/egon/data/datasets/plotdatascn.py index 7d5eea2d8..7f33d22cb 100644 --- a/src/egon/data/datasets/plotdatascn.py +++ b/src/egon/data/datasets/plotdatascn.py @@ -48,6 +48,9 @@ distr = gpd.GeoDataFrame.from_postgis(sql, con) distr = distr.set_index("bus_id") - - - \ No newline at end of file + # Carriers and p_nom + +sqlCarrier = "SELECT carrier, p_nom, bus FROM grid.egon_etrago_generator" +Carriers = pd.read_sql(sqlCarrier,con) +Carriers = Carriers.set_index("bus") + \ No newline at end of file From 7ef5de23ddc7cfa26474fd380b32fb47003b4825 Mon Sep 17 00:00:00 2001 From: alonsoju95 Date: Fri, 3 Jun 2022 11:42:19 +0200 Subject: [PATCH 03/15] filter to eGon2035 scenario --- src/egon/data/datasets/plotdatascn.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/egon/data/datasets/plotdatascn.py b/src/egon/data/datasets/plotdatascn.py index 7f33d22cb..db78e3360 100644 --- a/src/egon/data/datasets/plotdatascn.py +++ b/src/egon/data/datasets/plotdatascn.py @@ -46,11 +46,28 @@ # get MV grid districts sql = "SELECT bus_id, geom FROM grid.egon_mv_grid_district" distr = gpd.GeoDataFrame.from_postgis(sql, con) -distr = distr.set_index("bus_id") +distr = distr.rename({'bus_id': 'bus'},axis=1) +distr = distr.set_index("bus") +#distr = distr.rename(index={'bus_id': 'bus'}) # Carriers and p_nom sqlCarrier = "SELECT carrier, p_nom, bus FROM grid.egon_etrago_generator" +sqlCarrier = "SELECT * FROM grid.egon_etrago_generator" Carriers = pd.read_sql(sqlCarrier,con) +Carriers = Carriers.loc[Carriers['scn_name'] == 'eGon2035'] Carriers = Carriers.set_index("bus") - \ No newline at end of file + +#Carriers.rename(columns={"bus": "bus_id"}) + + +#result = distr.merge(Carriers.rename(columns={'bus': "bus_id"}), + # how='inner', + # on='bus_id', + # copy=False) + +# Join data from sql and sqlCarrier + + +#sqlFinal = pd.merge(Carriers, distr, how="inner", on="bus") + From 52f39ba35396f6e6415f49f50f5a8f535c181aa9 Mon Sep 17 00:00:00 2001 From: alonsoju95 Date: Thu, 9 Jun 2022 10:40:44 +0200 Subject: [PATCH 04/15] plot for solar rooftop capacity eGon2035 --- src/egon/data/datasets/plotdatascn.py | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/egon/data/datasets/plotdatascn.py b/src/egon/data/datasets/plotdatascn.py index db78e3360..e7636466c 100644 --- a/src/egon/data/datasets/plotdatascn.py +++ b/src/egon/data/datasets/plotdatascn.py @@ -10,9 +10,9 @@ # import logging # import os -# from matplotlib import pyplot as plt -# import matplotlib.patches as mpatches -#import matplotlib +from matplotlib import pyplot as plt +import matplotlib.patches as mpatches +import matplotlib #import pandas as pd #import numpy as np #from math import sqrt, log10 @@ -58,6 +58,27 @@ Carriers = Carriers.loc[Carriers['scn_name'] == 'eGon2035'] Carriers = Carriers.set_index("bus") +#Solar rooftop +SolarRooftop = Carriers.loc[Carriers['carrier'] == 'solar_rooftop'] +SolarRooftopGEO = pd.merge(SolarRooftop, distr, on ='bus') + + + +gdf = gpd.GeoDataFrame(SolarRooftopGEO , geometry='geom') + + + +fig, ax = plt.subplots(figsize=(10,10)) + +ax.set_axis_off(); + +gdf.plot(column='p_nom', ax=ax, legend=True) + + + + + + #Carriers.rename(columns={"bus": "bus_id"}) From 6fa17c9c29acc9034adf92ec5686fddbd7fd66af Mon Sep 17 00:00:00 2001 From: alonsoju95 Date: Thu, 16 Jun 2022 14:25:58 +0200 Subject: [PATCH 05/15] plots for generation-installed capacity for eGon2035 and eGon100RE --- src/egon/data/datasets/plotdatascn.py | 126 +++++++++++++++++++++++++- 1 file changed, 121 insertions(+), 5 deletions(-) diff --git a/src/egon/data/datasets/plotdatascn.py b/src/egon/data/datasets/plotdatascn.py index e7636466c..f85df9bf1 100644 --- a/src/egon/data/datasets/plotdatascn.py +++ b/src/egon/data/datasets/plotdatascn.py @@ -58,26 +58,142 @@ Carriers = Carriers.loc[Carriers['scn_name'] == 'eGon2035'] Carriers = Carriers.set_index("bus") -#Solar rooftop -SolarRooftop = Carriers.loc[Carriers['carrier'] == 'solar_rooftop'] -SolarRooftopGEO = pd.merge(SolarRooftop, distr, on ='bus') +Carrier= Carriers.loc[Carriers['carrier'] == 'wind_onshore'] +Merge= pd.merge(Carrier, distr, on ='bus', how="outer") +#Merge=Merge['p_nom'] = Merge['p_nom'].fillna(0) +Eliminate= Merge.loc[Merge ["carrier"] != "wind_onshore", "p_nom" ] = 0 -gdf = gpd.GeoDataFrame(SolarRooftopGEO , geometry='geom') +gdf = gpd.GeoDataFrame(Merge , geometry='geom') + +fig, ax = plt.subplots(figsize=(10,10)) +ax.set_axis_off(); +plt.title("SolarCapacity in Germany") +gdf.plot(column='p_nom', ax=ax, legend=True, legend_kwds={'label': "p_nom", + + 'orientation': "vertical"}) + + + + + +Merge= pd.merge(Carriers, distr, on ='bus') + +Eliminate= Merge.loc[Merge ["carrier"] != "wind_onshore", "p_nom" ] = 0 + +gdf = gpd.GeoDataFrame(Merge , geometry='geom') + fig, ax = plt.subplots(figsize=(10,10)) +ax.set_axis_off(); +plt.title("SolarCapacity in Germany") +gdf.plot(column='p_nom', ax=ax, legend=True, legend_kwds={'label': "p_nom", + + 'orientation': "vertical"}) + + +CarrierGEO= Merge.loc[Merge['carrier'] == 'wind_onshore'] +gdf = gpd.GeoDataFrame(CarrierGEO , geometry='geom') + + + +fig, ax = plt.subplots(figsize=(10,10)) ax.set_axis_off(); +plt.title("SolarCapacity in Germany") +gdf.plot(column='p_nom', ax=ax, legend=True, legend_kwds={'label': "p_nom", -gdf.plot(column='p_nom', ax=ax, legend=True) + 'orientation': "vertical"}) +#Solar rooftop +SolarRooftop = Carriers.loc[Carriers['carrier'] == 'wind_onshore'] +#SolarRooftopGEO = pd.merge(SolarRooftop, distr, on ='bus', how="left").fillna(value="0") + +SolarRooftopGEO = pd.merge(SolarRooftop, distr, on ='bus') + + +gdf = gpd.GeoDataFrame(SolarRooftopGEO , geometry='geom') + + + +fig, ax = plt.subplots(figsize=(10,10)) +ax.set_axis_off(); +plt.title("SolarCapacity in Germany") +gdf.plot(column='p_nom', ax=ax, legend=True, legend_kwds={'label': "p_nom", + + 'orientation': "vertical"}) + + +# import logging +# import os +from matplotlib import pyplot as plt +import matplotlib.patches as mpatches +import matplotlib +#import pandas as pd +#import numpy as np +#from math import sqrt, log10 +#from pyproj import Proj, transform +# import tilemapbase +#import geopandas as gpd +#from egon.data import db +#from egon.data.config import settings +#from egon.data.datasets import Dataset +#import egon.data.config +import pandas as pd +from egon.data import db +from egon.data.datasets import Dataset +import egon.data.config +import geopandas as gpd + +def plot_generation( + carrier,scenario + ): + con = db.engine() + + sql = "SELECT bus_id, geom FROM grid.egon_mv_grid_district" + distr = gpd.GeoDataFrame.from_postgis(sql, con) + distr = distr.rename({'bus_id': 'bus'},axis=1) + distr = distr.set_index("bus") + + sqlCarrier = "SELECT carrier, p_nom, bus FROM grid.egon_etrago_generator" + sqlCarrier = "SELECT * FROM grid.egon_etrago_generator" + Carriers = pd.read_sql(sqlCarrier,con) + Carriers = Carriers.loc[Carriers['scn_name'] == scenario] + Carriers = Carriers.set_index("bus") + + + CarrierGen = Carriers.loc[Carriers['carrier'] == carrier] + CarrierGenGEO = pd.merge(CarrierGen, distr, on ='bus') + + + + gdf = gpd.GeoDataFrame(CarrierGenGEO , geometry='geom') + + + + fig, ax = plt.subplots(figsize=(10,10)) + ax.set_axis_off(); + plt.title(carrier) + gdf.plot(column='p_nom', ax=ax, legend=True, legend_kwds={'label': "p_nom", + + 'orientation': "vertical"}) + return 0 + plot_generation(carrier, scenario) + + + + + + + + #Carriers.rename(columns={"bus": "bus_id"}) From 10feabc7ba787e3f775b9e97417abbb260bb028b Mon Sep 17 00:00:00 2001 From: alonsoju95 Date: Mon, 25 Jul 2022 20:29:04 +0200 Subject: [PATCH 06/15] plots for generators in grid districts --- src/egon/data/datasets/plotdatascn.py | 192 ++++++-------------------- 1 file changed, 40 insertions(+), 152 deletions(-) diff --git a/src/egon/data/datasets/plotdatascn.py b/src/egon/data/datasets/plotdatascn.py index f85df9bf1..5d05153e8 100644 --- a/src/egon/data/datasets/plotdatascn.py +++ b/src/egon/data/datasets/plotdatascn.py @@ -8,11 +8,13 @@ """ + + # import logging # import os from matplotlib import pyplot as plt import matplotlib.patches as mpatches -import matplotlib +import matplotlib as mpl #import pandas as pd #import numpy as np #from math import sqrt, log10 @@ -42,169 +44,55 @@ __license__ = "" __author__ = "" -con = db.engine() - # get MV grid districts -sql = "SELECT bus_id, geom FROM grid.egon_mv_grid_district" -distr = gpd.GeoDataFrame.from_postgis(sql, con) -distr = distr.rename({'bus_id': 'bus'},axis=1) -distr = distr.set_index("bus") -#distr = distr.rename(index={'bus_id': 'bus'}) - - # Carriers and p_nom - -sqlCarrier = "SELECT carrier, p_nom, bus FROM grid.egon_etrago_generator" -sqlCarrier = "SELECT * FROM grid.egon_etrago_generator" -Carriers = pd.read_sql(sqlCarrier,con) -Carriers = Carriers.loc[Carriers['scn_name'] == 'eGon2035'] -Carriers = Carriers.set_index("bus") - -Carrier= Carriers.loc[Carriers['carrier'] == 'wind_onshore'] - -Merge= pd.merge(Carrier, distr, on ='bus', how="outer") -#Merge=Merge['p_nom'] = Merge['p_nom'].fillna(0) -Eliminate= Merge.loc[Merge ["carrier"] != "wind_onshore", "p_nom" ] = 0 - - - - -gdf = gpd.GeoDataFrame(Merge , geometry='geom') - -fig, ax = plt.subplots(figsize=(10,10)) -ax.set_axis_off(); -plt.title("SolarCapacity in Germany") -gdf.plot(column='p_nom', ax=ax, legend=True, legend_kwds={'label': "p_nom", - - 'orientation': "vertical"}) - - - - - -Merge= pd.merge(Carriers, distr, on ='bus') - -Eliminate= Merge.loc[Merge ["carrier"] != "wind_onshore", "p_nom" ] = 0 - -gdf = gpd.GeoDataFrame(Merge , geometry='geom') - - -fig, ax = plt.subplots(figsize=(10,10)) -ax.set_axis_off(); -plt.title("SolarCapacity in Germany") -gdf.plot(column='p_nom', ax=ax, legend=True, legend_kwds={'label': "p_nom", - - 'orientation': "vertical"}) - - -CarrierGEO= Merge.loc[Merge['carrier'] == 'wind_onshore'] - -gdf = gpd.GeoDataFrame(CarrierGEO , geometry='geom') - - - -fig, ax = plt.subplots(figsize=(10,10)) -ax.set_axis_off(); -plt.title("SolarCapacity in Germany") -gdf.plot(column='p_nom', ax=ax, legend=True, legend_kwds={'label': "p_nom", - - 'orientation': "vertical"}) - - - - - -#Solar rooftop -SolarRooftop = Carriers.loc[Carriers['carrier'] == 'wind_onshore'] -#SolarRooftopGEO = pd.merge(SolarRooftop, distr, on ='bus', how="left").fillna(value="0") - -SolarRooftopGEO = pd.merge(SolarRooftop, distr, on ='bus') - - -gdf = gpd.GeoDataFrame(SolarRooftopGEO , geometry='geom') -fig, ax = plt.subplots(figsize=(10,10)) -ax.set_axis_off(); -plt.title("SolarCapacity in Germany") -gdf.plot(column='p_nom', ax=ax, legend=True, legend_kwds={'label': "p_nom", - 'orientation': "vertical"}) - - -# import logging -# import os -from matplotlib import pyplot as plt -import matplotlib.patches as mpatches -import matplotlib -#import pandas as pd -#import numpy as np -#from math import sqrt, log10 -#from pyproj import Proj, transform -# import tilemapbase -#import geopandas as gpd -#from egon.data import db -#from egon.data.config import settings -#from egon.data.datasets import Dataset -#import egon.data.config -import pandas as pd -from egon.data import db -from egon.data.datasets import Dataset -import egon.data.config -import geopandas as gpd def plot_generation( carrier,scenario ): - con = db.engine() - - sql = "SELECT bus_id, geom FROM grid.egon_mv_grid_district" - distr = gpd.GeoDataFrame.from_postgis(sql, con) - distr = distr.rename({'bus_id': 'bus'},axis=1) - distr = distr.set_index("bus") - - sqlCarrier = "SELECT carrier, p_nom, bus FROM grid.egon_etrago_generator" - sqlCarrier = "SELECT * FROM grid.egon_etrago_generator" - Carriers = pd.read_sql(sqlCarrier,con) - Carriers = Carriers.loc[Carriers['scn_name'] == scenario] - Carriers = Carriers.set_index("bus") + con = db.engine() + SQLBus = "SELECT bus_id, country FROM grid.egon_etrago_bus WHERE country='DE'" + busDE = pd.read_sql(SQLBus,con) + busDE = busDE.rename({'bus_id': 'bus'},axis=1) + #busDE = busDE.loc[busDE['country'] == 'DE'] + sql = "SELECT bus_id, geom FROM grid.egon_mv_grid_district" + distr = gpd.GeoDataFrame.from_postgis(sql, con) + distr = distr.rename({'bus_id': 'bus'},axis=1) + distr = distr.set_index("bus") + distr = pd.merge(busDE, distr, on='bus') - - CarrierGen = Carriers.loc[Carriers['carrier'] == carrier] - CarrierGenGEO = pd.merge(CarrierGen, distr, on ='bus') + sqlCarrier = "SELECT carrier, p_nom, bus FROM grid.egon_etrago_generator" + sqlCarrier = "SELECT * FROM grid.egon_etrago_generator" + Carriers = pd.read_sql(sqlCarrier,con) + Carriers = Carriers.loc[Carriers['scn_name'] == scenario] + Carriers = Carriers.set_index("bus") + CarrierGen = Carriers.loc[Carriers['carrier'] == carrier] - gdf = gpd.GeoDataFrame(CarrierGenGEO , geometry='geom') + Merge = pd.merge(CarrierGen, distr, on ='bus', how="outer") - - - fig, ax = plt.subplots(figsize=(10,10)) - ax.set_axis_off(); - plt.title(carrier) - gdf.plot(column='p_nom', ax=ax, legend=True, legend_kwds={'label': "p_nom", - - 'orientation': "vertical"}) - return 0 - plot_generation(carrier, scenario) - - - - - - - - -#Carriers.rename(columns={"bus": "bus_id"}) - - -#result = distr.merge(Carriers.rename(columns={'bus': "bus_id"}), - # how='inner', - # on='bus_id', - # copy=False) - -# Join data from sql and sqlCarrier - + Merge.loc[Merge ['carrier'] != carrier, "p_nom" ] = 0 + Merge.loc[Merge ['country'] != "DE", "p_nom" ] = 0 + + gdf = gpd.GeoDataFrame(Merge , geometry='geom') + print(Merge) + pnom=gdf['p_nom'] + max_pnom=pnom.quantile(0.99) + print(max_pnom) + fig, ax = plt.subplots(figsize=(10,10)) + ax.set_axis_off(); + plt.title(f" {carrier} installed capacity in MW , {scenario}") + cmap = mpl.cm.coolwarm + norm = mpl.colors.Normalize(vmin=0, vmax=max_pnom) + gdf.plot(column='p_nom', ax=ax, legend=True, legend_kwds={'label': "p_nom(MW)", + + 'orientation': "vertical"}, cmap=cmap, norm=norm) + + + return 0 + plot_generation(carrier, scenario) -#sqlFinal = pd.merge(Carriers, distr, how="inner", on="bus") - From ceb9464a04cf923f66cadd8377aeaf1a4a8e790b Mon Sep 17 00:00:00 2001 From: alonsoju95 Date: Tue, 16 Aug 2022 14:12:01 +0200 Subject: [PATCH 07/15] cartopy changes --- src/egon/data/datasets/plotdatascn.py | 29 ++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/egon/data/datasets/plotdatascn.py b/src/egon/data/datasets/plotdatascn.py index 5d05153e8..4aa814217 100644 --- a/src/egon/data/datasets/plotdatascn.py +++ b/src/egon/data/datasets/plotdatascn.py @@ -10,16 +10,17 @@ -# import logging -# import os +import logging +import os from matplotlib import pyplot as plt import matplotlib.patches as mpatches import matplotlib as mpl #import pandas as pd #import numpy as np #from math import sqrt, log10 -#from pyproj import Proj, transform -# import tilemapbase +from pyproj import Proj, transform +#import tilemapbase +#import tilemapbase #import geopandas as gpd #from egon.data import db #from egon.data.config import settings @@ -31,11 +32,16 @@ import egon.data.config import geopandas as gpd +#import cartopy +#import cartopy.crs as ccrs +#import cartopy.mpl.geoaxes +#import requests -#logger = logging.getLogger(__name__) -#if 'READTHEDOCS' not in os.environ: - #from geoalchemy2.shape import to_shape +logger = logging.getLogger(__name__) + +if 'READTHEDOCS' not in os.environ: + from geoalchemy2.shape import to_shape __copyright__ = ("Flensburg University of Applied Sciences, " "Europa-Universität Flensburg, " @@ -49,9 +55,12 @@ + def plot_generation( - carrier,scenario + carrier,scenario, osm=False ): + + con = db.engine() SQLBus = "SELECT bus_id, country FROM grid.egon_etrago_bus WHERE country='DE'" busDE = pd.read_sql(SQLBus,con) @@ -81,8 +90,10 @@ def plot_generation( gdf = gpd.GeoDataFrame(Merge , geometry='geom') print(Merge) pnom=gdf['p_nom'] - max_pnom=pnom.quantile(0.99) + max_pnom=pnom.quantile(0.95) print(max_pnom) + #import cartopy.crs as ccrs + #fig, ax = plt.subplots(subplot_kw={"projection":ccrs.PlateCarree()}) fig, ax = plt.subplots(figsize=(10,10)) ax.set_axis_off(); plt.title(f" {carrier} installed capacity in MW , {scenario}") From 3f04fe4260dd2f7e8c7f901a0f2ffe4de33da646 Mon Sep 17 00:00:00 2001 From: alonsoju95 Date: Mon, 5 Sep 2022 14:03:01 +0200 Subject: [PATCH 08/15] comments in lines and other changes --- src/egon/data/datasets/plotdatascn.py | 56 ++++++++++++++------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/src/egon/data/datasets/plotdatascn.py b/src/egon/data/datasets/plotdatascn.py index 4aa814217..742111be2 100644 --- a/src/egon/data/datasets/plotdatascn.py +++ b/src/egon/data/datasets/plotdatascn.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- +# File description """ Created on Tue May 24 14:42:05 2022 Plotdatascn.py defines functions to plot to provide a better context of the different parameters part of @@ -15,28 +16,16 @@ from matplotlib import pyplot as plt import matplotlib.patches as mpatches import matplotlib as mpl -#import pandas as pd -#import numpy as np -#from math import sqrt, log10 +import pandas as pd +import numpy as np +from math import sqrt, log10 from pyproj import Proj, transform -#import tilemapbase -#import tilemapbase -#import geopandas as gpd -#from egon.data import db -#from egon.data.config import settings -#from egon.data.datasets import Dataset -#import egon.data.config import pandas as pd from egon.data import db from egon.data.datasets import Dataset import egon.data.config import geopandas as gpd -#import cartopy -#import cartopy.crs as ccrs -#import cartopy.mpl.geoaxes -#import requests - logger = logging.getLogger(__name__) @@ -59,20 +48,35 @@ def plot_generation( carrier,scenario, osm=False ): + """ + Plots color maps according to the capacity of different generators + of the two existing scenarios (eGon2035 and eGon100RE) + + + Parameters + ---------- + carrier : generators + The list of generators: biomass, central_biomass_CHP, central_biomass_CHP_heat, + industrial_biomass_CHP, solar, solar_rooftop, wind_offshore, wind_onshore. + + scenario: eGon2035, eGon100RE + + + """ con = db.engine() - SQLBus = "SELECT bus_id, country FROM grid.egon_etrago_bus WHERE country='DE'" - busDE = pd.read_sql(SQLBus,con) - busDE = busDE.rename({'bus_id': 'bus'},axis=1) - #busDE = busDE.loc[busDE['country'] == 'DE'] - sql = "SELECT bus_id, geom FROM grid.egon_mv_grid_district" + SQLBus = "SELECT bus_id, country FROM grid.egon_etrago_bus WHERE country='DE'" #imports buses of Germany + busDE = pd.read_sql(SQLBus,con) + busDE = busDE.rename({'bus_id': 'bus'},axis=1) + + sql = "SELECT bus_id, geom FROM grid.egon_mv_grid_district"#Imports grid districs distr = gpd.GeoDataFrame.from_postgis(sql, con) distr = distr.rename({'bus_id': 'bus'},axis=1) distr = distr.set_index("bus") - distr = pd.merge(busDE, distr, on='bus') + distr = pd.merge(busDE, distr, on='bus') #merges grid districts with buses - sqlCarrier = "SELECT carrier, p_nom, bus FROM grid.egon_etrago_generator" + sqlCarrier = "SELECT carrier, p_nom, bus FROM grid.egon_etrago_generator" #Imports generator sqlCarrier = "SELECT * FROM grid.egon_etrago_generator" Carriers = pd.read_sql(sqlCarrier,con) Carriers = Carriers.loc[Carriers['scn_name'] == scenario] @@ -81,7 +85,7 @@ def plot_generation( CarrierGen = Carriers.loc[Carriers['carrier'] == carrier] - Merge = pd.merge(CarrierGen, distr, on ='bus', how="outer") + Merge = pd.merge(CarrierGen, distr, on ='bus', how="outer") #merges districts with generators Merge.loc[Merge ['carrier'] != carrier, "p_nom" ] = 0 @@ -89,11 +93,9 @@ def plot_generation( gdf = gpd.GeoDataFrame(Merge , geometry='geom') print(Merge) - pnom=gdf['p_nom'] - max_pnom=pnom.quantile(0.95) + pnom=gdf['p_nom'] + max_pnom=pnom.quantile(0.95) #0.95 quantile is used to filter values that are too high and make noise in the plots. print(max_pnom) - #import cartopy.crs as ccrs - #fig, ax = plt.subplots(subplot_kw={"projection":ccrs.PlateCarree()}) fig, ax = plt.subplots(figsize=(10,10)) ax.set_axis_off(); plt.title(f" {carrier} installed capacity in MW , {scenario}") From f331089b4e4f77271607347a1877e873030ffdda Mon Sep 17 00:00:00 2001 From: alonsoju95 Date: Wed, 14 Sep 2022 14:15:14 +0200 Subject: [PATCH 09/15] plots for installed capacities of different generators in eGon2035 and eGon100RE --- src/egon/data/datasets/plotdatascn.py | 98 +++++++++++++++++++++++++-- 1 file changed, 92 insertions(+), 6 deletions(-) diff --git a/src/egon/data/datasets/plotdatascn.py b/src/egon/data/datasets/plotdatascn.py index 742111be2..c3780df03 100644 --- a/src/egon/data/datasets/plotdatascn.py +++ b/src/egon/data/datasets/plotdatascn.py @@ -11,6 +11,9 @@ + + + import logging import os from matplotlib import pyplot as plt @@ -25,6 +28,10 @@ from egon.data.datasets import Dataset import egon.data.config import geopandas as gpd +import tilemapbase +from math import sqrt, log10 +from pyproj import Proj, transform +import tilemapbase logger = logging.getLogger(__name__) @@ -45,8 +52,64 @@ + + +def set_epsg_network(network): + """ + Change EPSG from 4326 to 3857. Needed when using osm-background. + + Parameters + ---------- + network : PyPSA network container + + Returns + ------- + """ + + inProj = Proj(init='epsg:4326') + outProj = Proj(init='epsg:3857') + x1, y1 = network.buses.x.values, network.buses.y.values + x2, y2 = transform(inProj, outProj, x1, y1) + network.buses.x, network.buses.y = x2, y2 + network.epsg = 3857 + set_epsg_network.counter = set_epsg_network.counter + 1 + +def plot_osm(x, y, zoom, alpha=0.4): + """ + Plots openstreetmap as background of network-plots + + Parameters + ---------- + x : array of two floats + Define x-axis boundaries (lat) of osm plot + y : array of two floats + Define y-axis boundaries (long) of osm plot + zoom : int + Define zoom of osm, higher values for higher resolution + alpha : float + Sets osm-visibility, increase value if osm covers network-plot + + Returns + ------- + """ + + tilemapbase.init(create=True) + + extent = tilemapbase.Extent.from_lonlat(x[0], x[1], y[0], y[1]) + extent = extent.to_aspect(1.0) + extent = extent.to_project_3857() + + fig, ax = plt.subplots() + ax.set_zorder(1) + plt.axis('off') + plotter = tilemapbase.Plotter(extent, tilemapbase.tiles.build_OSM(), + zoom=zoom) + plotter.plot(ax, alpha=alpha) + #ax.plot(x, y, "ro-") + return fig, ax + def plot_generation( - carrier,scenario, osm=False + carrier,scenario, osm = False ): """ Plots color maps according to the capacity of different generators @@ -93,19 +156,42 @@ def plot_generation( gdf = gpd.GeoDataFrame(Merge , geometry='geom') print(Merge) + print(gdf.crs) pnom=gdf['p_nom'] max_pnom=pnom.quantile(0.95) #0.95 quantile is used to filter values that are too high and make noise in the plots. print(max_pnom) - fig, ax = plt.subplots(figsize=(10,10)) + gdf = gdf.to_crs(epsg=3857) + + + # Plot osm map in background + if osm != False: + #if network.srid == 4326: + #set_epsg_network(network) + fig, ax = plot_osm(osm['x'], osm['y'], osm['zoom']) + + else: + fig, ax = plt.subplots(1, 1) + + + ax.set_axis_off(); plt.title(f" {carrier} installed capacity in MW , {scenario}") cmap = mpl.cm.coolwarm norm = mpl.colors.Normalize(vmin=0, vmax=max_pnom) gdf.plot(column='p_nom', ax=ax, legend=True, legend_kwds={'label': "p_nom(MW)", - 'orientation': "vertical"}, cmap=cmap, norm=norm) - - + 'orientation': "vertical"}, cmap=cmap, norm=norm, edgecolor='black', linewidth=0.1,zorder=2) + return 0 - plot_generation(carrier, scenario) + plot_generation(carrier, scenario) + + + + + + + + + + From f71a6d727944108c861ce5b8fafc17f6146da5fe Mon Sep 17 00:00:00 2001 From: alonsoju95 Date: Wed, 28 Sep 2022 10:04:56 +0200 Subject: [PATCH 10/15] plots for installed capacities of different generators in eGon2035 and eGon100RE_final version --- src/egon/data/datasets/plotdatascn.py | 37 +++++++++++++-------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/src/egon/data/datasets/plotdatascn.py b/src/egon/data/datasets/plotdatascn.py index c3780df03..1050cce3a 100644 --- a/src/egon/data/datasets/plotdatascn.py +++ b/src/egon/data/datasets/plotdatascn.py @@ -17,13 +17,10 @@ import logging import os from matplotlib import pyplot as plt -import matplotlib.patches as mpatches import matplotlib as mpl import pandas as pd -import numpy as np from math import sqrt, log10 from pyproj import Proj, transform -import pandas as pd from egon.data import db from egon.data.datasets import Dataset import egon.data.config @@ -32,6 +29,7 @@ from math import sqrt, log10 from pyproj import Proj, transform import tilemapbase +from matplotlib_scalebar.scalebar import ScaleBar logger = logging.getLogger(__name__) @@ -51,7 +49,6 @@ - def set_epsg_network(network): @@ -88,6 +85,12 @@ def plot_osm(x, y, zoom, alpha=0.4): Define zoom of osm, higher values for higher resolution alpha : float Sets osm-visibility, increase value if osm covers network-plot + osm : bool or dict, e.g. {'x': [1,20], 'y': [47, 56], 'zoom' : 6} + If not False, osm is set as background + with the following settings as dict: + 'x': array of two floats, x axis boundaries (lat) + 'y': array of two floats, y axis boundaries (long) + 'zoom' : resolution of osm. The default is False. Returns ------- @@ -99,8 +102,9 @@ def plot_osm(x, y, zoom, alpha=0.4): extent = extent.to_aspect(1.0) extent = extent.to_project_3857() - fig, ax = plt.subplots() + fig, ax = plt.subplots(1,1) ax.set_zorder(1) + ax.add_artist(ScaleBar(1)) plt.axis('off') plotter = tilemapbase.Plotter(extent, tilemapbase.tiles.build_OSM(), zoom=zoom) @@ -155,11 +159,8 @@ def plot_generation( Merge.loc[Merge ['country'] != "DE", "p_nom" ] = 0 gdf = gpd.GeoDataFrame(Merge , geometry='geom') - print(Merge) - print(gdf.crs) pnom=gdf['p_nom'] max_pnom=pnom.quantile(0.95) #0.95 quantile is used to filter values that are too high and make noise in the plots. - print(max_pnom) gdf = gdf.to_crs(epsg=3857) @@ -177,21 +178,19 @@ def plot_generation( ax.set_axis_off(); plt.title(f" {carrier} installed capacity in MW , {scenario}") cmap = mpl.cm.coolwarm + + norm = mpl.colors.Normalize(vmin=0, vmax=max_pnom) - gdf.plot(column='p_nom', ax=ax, legend=True, legend_kwds={'label': "p_nom(MW)", + gdf.plot(column='p_nom', ax=ax, legend=False, legend_kwds={'label': "p_nom(MW)", 'orientation': "vertical"}, cmap=cmap, norm=norm, edgecolor='black', linewidth=0.1,zorder=2) - + scatter = ax.collections[0] + cbar=plt.colorbar(scatter, ax=ax, extend='max') + cbar.set_label('p_nom(MW)', rotation=90) return 0 - plot_generation(carrier, scenario) - - - + + - - - - - + \ No newline at end of file From 7c229faf38cde5e835a79538d1efafde6508ae10 Mon Sep 17 00:00:00 2001 From: alonsoju95 Date: Thu, 6 Oct 2022 11:04:43 +0200 Subject: [PATCH 11/15] changes in format --- src/egon/data/datasets/plotdatascn.py | 39 ++++++++++----------------- 1 file changed, 14 insertions(+), 25 deletions(-) diff --git a/src/egon/data/datasets/plotdatascn.py b/src/egon/data/datasets/plotdatascn.py index 1050cce3a..7f874c4ea 100644 --- a/src/egon/data/datasets/plotdatascn.py +++ b/src/egon/data/datasets/plotdatascn.py @@ -7,13 +7,7 @@ scenarios eGon2035 and eGon100RE . @author: Alonso -""" - - - - - - +""" import logging import os from matplotlib import pyplot as plt @@ -22,13 +16,11 @@ from math import sqrt, log10 from pyproj import Proj, transform from egon.data import db -from egon.data.datasets import Dataset import egon.data.config import geopandas as gpd import tilemapbase from math import sqrt, log10 from pyproj import Proj, transform -import tilemapbase from matplotlib_scalebar.scalebar import ScaleBar @@ -44,13 +36,7 @@ __license__ = "" __author__ = "" - - - - - - def set_epsg_network(network): """ Change EPSG from 4326 to 3857. Needed when using osm-background. @@ -133,17 +119,19 @@ def plot_generation( con = db.engine() - SQLBus = "SELECT bus_id, country FROM grid.egon_etrago_bus WHERE country='DE'" #imports buses of Germany + #imports buses of Germany + SQLBus = "SELECT bus_id, country FROM grid.egon_etrago_bus WHERE country='DE'" busDE = pd.read_sql(SQLBus,con) busDE = busDE.rename({'bus_id': 'bus'},axis=1) - - sql = "SELECT bus_id, geom FROM grid.egon_mv_grid_district"#Imports grid districs + #Imports grid districs + sql = "SELECT bus_id, geom FROM grid.egon_mv_grid_district" distr = gpd.GeoDataFrame.from_postgis(sql, con) distr = distr.rename({'bus_id': 'bus'},axis=1) distr = distr.set_index("bus") - distr = pd.merge(busDE, distr, on='bus') #merges grid districts with buses - - sqlCarrier = "SELECT carrier, p_nom, bus FROM grid.egon_etrago_generator" #Imports generator + #merges grid districts with buses + distr = pd.merge(busDE, distr, on='bus') + #Imports generator + sqlCarrier = "SELECT carrier, p_nom, bus FROM grid.egon_etrago_generator" sqlCarrier = "SELECT * FROM grid.egon_etrago_generator" Carriers = pd.read_sql(sqlCarrier,con) Carriers = Carriers.loc[Carriers['scn_name'] == scenario] @@ -151,16 +139,17 @@ def plot_generation( CarrierGen = Carriers.loc[Carriers['carrier'] == carrier] - - Merge = pd.merge(CarrierGen, distr, on ='bus', how="outer") #merges districts with generators + #merges districts with generators + Merge = pd.merge(CarrierGen, distr, on ='bus', how="outer") Merge.loc[Merge ['carrier'] != carrier, "p_nom" ] = 0 Merge.loc[Merge ['country'] != "DE", "p_nom" ] = 0 gdf = gpd.GeoDataFrame(Merge , geometry='geom') - pnom=gdf['p_nom'] - max_pnom=pnom.quantile(0.95) #0.95 quantile is used to filter values that are too high and make noise in the plots. + pnom=gdf['p_nom'] # + #0.95 quantile is used to filter values that are too high and make noise in the plots. + max_pnom=pnom.quantile(0.95) gdf = gdf.to_crs(epsg=3857) From 5e4a39915c7a45a3c51671be6754baee4e41443d Mon Sep 17 00:00:00 2001 From: alonsoju95 Date: Tue, 25 Oct 2022 11:32:09 +0200 Subject: [PATCH 12/15] Titlemapbase added to setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 417d48035..8d7fcda69 100755 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ from os.path import basename, dirname, join, splitext import io import re - +import Titlemapbase from setuptools import find_packages, setup From fff40acd4d503cb0272a9fde46b195635602e7fb Mon Sep 17 00:00:00 2001 From: alonsoju95 Date: Tue, 25 Oct 2022 13:45:15 +0200 Subject: [PATCH 13/15] Titlemapbase eliminated from setup.py --- setup.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 8d7fcda69..f0aeb4524 100755 --- a/setup.py +++ b/setup.py @@ -5,8 +5,7 @@ from glob import glob from os.path import basename, dirname, join, splitext import io -import re -import Titlemapbase +import re from setuptools import find_packages, setup From c250553bf4cf78074baf4ed75121130c01b8ec01 Mon Sep 17 00:00:00 2001 From: alonsoju95 Date: Tue, 25 Oct 2022 13:49:31 +0200 Subject: [PATCH 14/15] comment related to Tilemapbase library --- src/egon/data/datasets/plotdatascn.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/egon/data/datasets/plotdatascn.py b/src/egon/data/datasets/plotdatascn.py index 7f874c4ea..6503bfd0b 100644 --- a/src/egon/data/datasets/plotdatascn.py +++ b/src/egon/data/datasets/plotdatascn.py @@ -23,6 +23,12 @@ from pyproj import Proj, transform from matplotlib_scalebar.scalebar import ScaleBar +""" +Tilemapbase library could be necessary +to generate the figures + + +""" logger = logging.getLogger(__name__) From e305403779b9738e2837a3531656ba80e875bdfe Mon Sep 17 00:00:00 2001 From: alonsoju95 Date: Thu, 27 Oct 2022 16:22:59 +0200 Subject: [PATCH 15/15] Minor changes before merge --- src/egon/data/datasets/plotdatascn.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/egon/data/datasets/plotdatascn.py b/src/egon/data/datasets/plotdatascn.py index 6503bfd0b..88ac9038f 100644 --- a/src/egon/data/datasets/plotdatascn.py +++ b/src/egon/data/datasets/plotdatascn.py @@ -25,8 +25,9 @@ """ Tilemapbase library could be necessary -to generate the figures - +to generate the figures. +Matplotlib_scalebar.scalebar library could be necessary +to generate the figures. """ @@ -104,7 +105,7 @@ def plot_osm(x, y, zoom, alpha=0.4): #ax.plot(x, y, "ro-") return fig, ax -def plot_generation( +def plot_installedcapacity( carrier,scenario, osm = False ): """ @@ -123,7 +124,8 @@ def plot_generation( """ - + #This function must be called while in the folder + #that contains the file egon-data.configuration.yaml. con = db.engine() #imports buses of Germany SQLBus = "SELECT bus_id, country FROM grid.egon_etrago_bus WHERE country='DE'"