forked from PyPSA/powerplantmatching
-
Notifications
You must be signed in to change notification settings - Fork 0
/
german-powerplants.py
91 lines (75 loc) · 2.1 KB
/
german-powerplants.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
import copy
import cartopy.crs as ccrs
import hvplot
import hvplot.pandas # noqa
import hvplot.xarray # noqa
import pandas as pd
import panel as pn
import xarray as xr
from holoviews import opts
from holoviews.plotting.util import process_cmap
from xarray import align
import powerplantmatching as pm
config = pm.get_config()
query = (
"(DateOut >= {year} or DateOut != DateOut) and "
"(DateIn <= {year} or DateIn != DateIn) and "
"Country == 'Germany'"
)
config_de2020 = copy.copy(config)
config_de2020["main_query"] = query.format(year=2019)
config_de2020["hash"] = "DE-2020"
config_de2030 = copy.copy(config)
config_de2030["main_query"] = query.format(year=2030)
config_de2030["matching_sources"].remove("WIKIPEDIA")
config_de2030["hash"] = "DE-2030"
for config in [config_de2020, config_de2030]:
label = config["hash"]
df = pm.powerplants(config=config)
df = df[df.lat.notnull()]
grouped = (
df.groupby(["Fueltype", "Country"])
.Capacity.sum()
.div(1e3)
.sort_index(level=1, ascending=False)
)
grouped.name = "Capacity [GW]"
config = pm.get_config()
cmap = {
k: v for k, v in config["fuel_to_color"].items() if k in df.Fueltype.unique()
}
checkbox = pn.widgets.CheckButtonGroup(
name="Select", options=["Fueltype", "Country"]
)
map = df.hvplot.points(
"lon",
"lat",
color="Fueltype",
# groupby=checkbox,
s="Capacity",
scale=0.5,
hover_cols=["Name", "Technology", "Country", "DateOut"],
legend=False,
cmap=cmap,
geo=True,
alpha=0.4,
frame_height=500,
frame_width=500,
tiles="EsriTerrain",
xaxis=None,
yaxis=None,
title="",
features={"rivers": "10m", "lakes": "10m"},
)
bars = grouped.hvplot.barh(
by="Fueltype",
stacked=True,
cmap=cmap,
alpha=0.5,
title="",
frame_height=500,
frame_width=500,
)
# bars.opts(opts.Overlay(title=None))
plot = map + bars
hvplot.save(plot, "figures/" + label + ".html")