1
|
|
|
""" |
2
|
|
|
Created on Tue May 24 14:42:05 2022 |
3
|
|
|
Plotdatascn.py defines functions to plot to provide a better context of the different parameters part of |
4
|
|
|
scenarios eGon2035 and eGon100RE . |
5
|
|
|
@author: Alonso |
6
|
|
|
|
7
|
|
|
""" |
8
|
|
|
import logging |
9
|
|
|
import os |
10
|
|
|
|
11
|
|
|
from matplotlib import pyplot as plt |
12
|
|
|
import geopandas as gpd |
13
|
|
|
import matplotlib as mpl |
14
|
|
|
import pandas as pd |
15
|
|
|
|
16
|
|
|
from egon.data import db |
17
|
|
|
|
18
|
|
|
logger = logging.getLogger(__name__) |
19
|
|
|
|
20
|
|
|
if "READTHEDOCS" not in os.environ: |
21
|
|
|
from geoalchemy2.shape import to_shape |
22
|
|
|
|
23
|
|
|
__copyright__ = ( |
24
|
|
|
"Flensburg University of Applied Sciences, " |
25
|
|
|
"Europa-Universität Flensburg, " |
26
|
|
|
"Centre for Sustainable Energy Systems, " |
27
|
|
|
"DLR-Institute for Networked Energy Systems" |
28
|
|
|
) |
29
|
|
|
__license__ = "" |
30
|
|
|
__author__ = "" |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
def plot_installedcapacity(carrier, scenario="eGon2035"): |
34
|
|
|
""" |
35
|
|
|
Plots color maps according to the capacity of different generators |
36
|
|
|
of the two existing scenarios (eGon2035 and eGon100RE) |
37
|
|
|
|
38
|
|
|
|
39
|
|
|
Parameters |
40
|
|
|
---------- |
41
|
|
|
carrier : generators |
42
|
|
|
The list of generators: biomass, central_biomass_CHP, central_biomass_CHP_heat, |
43
|
|
|
industrial_biomass_CHP, solar, solar_rooftop, wind_offshore, wind_onshore. |
44
|
|
|
|
45
|
|
|
scenario: eGon2035, eGon100RE |
46
|
|
|
|
47
|
|
|
Returns |
48
|
|
|
---------- |
49
|
|
|
""" |
50
|
|
|
|
51
|
|
|
# This function must be called while in the folder |
52
|
|
|
# that contains the file egon-data.configuration.yaml. |
53
|
|
|
con = db.engine() |
54
|
|
|
# imports buses of Germany |
55
|
|
|
SQLBus = ( |
56
|
|
|
"SELECT bus_id, country FROM grid.egon_etrago_bus WHERE country='DE'" |
57
|
|
|
) |
58
|
|
|
busDE = pd.read_sql(SQLBus, con) |
59
|
|
|
busDE = busDE.rename({"bus_id": "bus"}, axis=1) |
60
|
|
|
# Imports grid districs |
61
|
|
|
sql = "SELECT bus_id, geom FROM grid.egon_mv_grid_district" |
62
|
|
|
distr = gpd.GeoDataFrame.from_postgis(sql, con) |
63
|
|
|
distr = distr.rename({"bus_id": "bus"}, axis=1) |
64
|
|
|
distr = distr.set_index("bus") |
65
|
|
|
# merges grid districts with buses |
66
|
|
|
distr = pd.merge(busDE, distr, on="bus") |
67
|
|
|
# Imports generator |
68
|
|
|
sqlCarrier = "SELECT carrier, p_nom, bus FROM grid.egon_etrago_generator" |
69
|
|
|
sqlCarrier = "SELECT * FROM grid.egon_etrago_generator" |
70
|
|
|
Carriers = pd.read_sql(sqlCarrier, con) |
71
|
|
|
Carriers = Carriers.loc[Carriers["scn_name"] == scenario] |
72
|
|
|
Carriers = Carriers.set_index("bus") |
73
|
|
|
|
74
|
|
|
CarrierGen = Carriers.loc[Carriers["carrier"] == carrier] |
75
|
|
|
# merges districts with generators |
76
|
|
|
Merge = pd.merge(CarrierGen, distr, on="bus", how="outer") |
77
|
|
|
|
78
|
|
|
Merge.loc[Merge["carrier"] != carrier, "p_nom"] = 0 |
79
|
|
|
Merge.loc[Merge["country"] != "DE", "p_nom"] = 0 |
80
|
|
|
|
81
|
|
|
gdf = gpd.GeoDataFrame(Merge, geometry="geom") |
82
|
|
|
pnom = gdf["p_nom"] # |
83
|
|
|
# 0.95 quantile is used to filter values that are too high and make noise in the plots. |
84
|
|
|
max_pnom = pnom.quantile(0.95) |
85
|
|
|
gdf = gdf.to_crs(epsg=3857) |
86
|
|
|
|
87
|
|
|
fig, ax = plt.subplots(1, 1) |
88
|
|
|
|
89
|
|
|
ax.set_axis_off() |
90
|
|
|
plt.title(f" {carrier} installed capacity in MW , {scenario}") |
91
|
|
|
cmap = mpl.cm.coolwarm |
92
|
|
|
|
93
|
|
|
norm = mpl.colors.Normalize(vmin=0, vmax=max_pnom) |
94
|
|
|
gdf.plot( |
95
|
|
|
column="p_nom", |
96
|
|
|
ax=ax, |
97
|
|
|
legend=False, |
98
|
|
|
legend_kwds={"label": "p_nom(MW)", "orientation": "vertical"}, |
99
|
|
|
cmap=cmap, |
100
|
|
|
norm=norm, |
101
|
|
|
edgecolor="black", |
102
|
|
|
linewidth=0.1, |
103
|
|
|
zorder=2, |
104
|
|
|
) |
105
|
|
|
scatter = ax.collections[0] |
106
|
|
|
cbar = plt.colorbar(scatter, ax=ax, extend="max") |
107
|
|
|
cbar.set_label("p_nom(MW)", rotation=90) |
108
|
|
|
|
109
|
|
|
return |
110
|
|
|
|