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