Skip to content

Commit f904bf6

Browse files
maurerlefneum
andauthored
analysis: improve analysis scripts (#250)
do not update data for compare-with-entsoe-stats do not overwrite built-in map command create required output folder for figures Co-authored-by: Fabian Neumann <fabian.neumann@outlook.de>
1 parent 03133c9 commit f904bf6

File tree

5 files changed

+31
-22
lines changed

5 files changed

+31
-22
lines changed

analysis/compare-with-entsoe-stats.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@
2020
root = pathlib.Path(__file__).parent.absolute()
2121
figpath = root / "figures"
2222

23-
UPDATE = True
23+
# whether to update the used dataset or use the precalculated data
24+
UPDATE = False
2425

2526

2627
config = pm.get_config()
2728

28-
powerplants = pm.powerplants(update=UPDATE)
29+
powerplants = pm.powerplants(update=UPDATE, from_url=not UPDATE)
2930

3031

3132
powerplants = powerplants.powerplant.convert_country_to_alpha2()
@@ -47,7 +48,7 @@ def parse(c):
4748
rename.get(c, c), **kwargs
4849
).iloc[0]
4950
except Exception as e:
50-
print(f"Country {c} failed with {e}")
51+
print(f"Country {c} failed with {repr(e)}")
5152
time.sleep(3)
5253
return np.nan
5354

@@ -68,14 +69,17 @@ def parse(c):
6869

6970
sources = [s if isinstance(s, str) else list(s)[0] for s in config["matching_sources"]]
7071

71-
input_dbs = {
72-
s.title(): getattr(pm.data, s)()
73-
.powerplant.convert_country_to_alpha2()
74-
.query(query)
75-
.powerplant.lookup()
76-
.fillna(0)
77-
for s in sources
78-
}
72+
input_dbs = {}
73+
for s in sources:
74+
print(s.title())
75+
input_dbs[s.title()] = (
76+
getattr(pm.data, s)()
77+
.powerplant.convert_country_to_alpha2()
78+
.query(query)
79+
.powerplant.lookup()
80+
.fillna(0)
81+
)
82+
7983
output_dbs = {
8084
s.title(): powerplants[
8185
powerplants.projectID.apply(lambda ds: s in ds)
@@ -103,7 +107,9 @@ def parse(c):
103107
diff[s.title() + " (%)"] = ds.fillna(0)
104108

105109
diff = diff[out_compare.Statistics != 0]
106-
diff = diff.loc[:, list(set(out_compare.index.unique(1)) - {"Wind", "Solar"}), :]
110+
diff = diff.loc[
111+
:, list(set(out_compare.index.unique(1)) - {"Biogas", "Wind", "Solar"}), :
112+
]
107113
diff.index = diff.index.get_level_values(0) + " " + diff.index.get_level_values(1)
108114

109115
df = (diff[diff.Difference > 1]).sort_values("Difference", ascending=False)
@@ -125,6 +131,8 @@ def parse(c):
125131
# country figures #
126132
# ---------------------------------------------------------------------------- #
127133

134+
(figpath / "country-comparison").mkdir(parents=True, exist_ok=True)
135+
128136
fig, ax = plt.subplots(figsize=(5, 20))
129137
diff[diff.abs() > 2].plot.barh(ax=ax, zorder=3)
130138
ax.set_xlabel("Capacity difference (stats - ppm) [GW]")

analysis/danish-powerplants.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
config_da2020 = copy.copy(config)
1717
config_da2020["main_query"] = "Country == 'Denmark'"
1818
config_da2020["hash"] = "DA-2020"
19-
config_da2020["matching_sources"].remove("WIKIPEDIA")
19+
config_da2020["matching_sources"].remove({"WIKIPEDIA": "Fueltype != 'Solar'"})
2020
config_da2020["matching_sources"].remove("JRC")
2121

2222

@@ -42,7 +42,7 @@
4242
name="Select", options=["Fueltype", "Country"]
4343
)
4444

45-
map = df.hvplot.points(
45+
point_map = df.hvplot.points(
4646
"lon",
4747
"lat",
4848
color="Fueltype",
@@ -74,6 +74,6 @@
7474
)
7575
# bars.opts(opts.Overlay(title=None))
7676

77-
plot = map + bars
77+
plot = point_map + bars
7878

7979
hvplot.save(plot, "figures/" + label + ".html")

analysis/german-powerplants.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import copy
66

7+
import geoviews # noqa
78
import hvplot
89
import hvplot.pandas # noqa
910
import hvplot.xarray # noqa
@@ -25,7 +26,7 @@
2526

2627
config_de2030 = copy.copy(config)
2728
config_de2030["main_query"] = query.format(year=2030)
28-
config_de2030["matching_sources"].remove("WIKIPEDIA")
29+
config_de2030["matching_sources"].remove({"WIKIPEDIA": "Fueltype != 'Solar'"})
2930
config_de2030["hash"] = "DE-2030"
3031

3132

@@ -51,7 +52,7 @@
5152
name="Select", options=["Fueltype", "Country"]
5253
)
5354

54-
map = df.hvplot.points(
55+
point_map = df.hvplot.points(
5556
"lon",
5657
"lat",
5758
color="Fueltype",
@@ -83,6 +84,6 @@
8384
)
8485
# bars.opts(opts.Overlay(title=None))
8586

86-
plot = map + bars
87+
plot = point_map + bars
8788

8889
hvplot.save(plot, "figures/" + label + ".html")

analysis/interactive-map-with-widgets.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
cmap = {k: v for k, v in config["fuel_to_color"].items() if k in df.Fueltype.unique()}
1717
checkbox = pn.widgets.CheckButtonGroup(name="Select", options=["Fueltype", "Country"])
1818

19-
map = df.hvplot.points(
19+
point_map = df.hvplot.points(
2020
"lon",
2121
"lat",
2222
color="Fueltype",
@@ -38,5 +38,5 @@
3838
)
3939

4040

41-
panel = pn.Column(checkbox, map)
41+
panel = pn.Column(checkbox, point_map)
4242
panel.show()

analysis/interactive-map.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
cmap = {k: v for k, v in config["fuel_to_color"].items() if k in df.Fueltype.unique()}
2424
# checkbox = pn.widgets.CheckButtonGroup(name="Select", options=["Fueltype", "Country"])
2525

26-
map = df.hvplot.points(
26+
point_map = df.hvplot.points(
2727
"lon",
2828
"lat",
2929
color="Fueltype",
@@ -44,7 +44,7 @@
4444
# features={"rivers": "10m", "lakes": "10m"},
4545
)
4646

47-
hvplot.save(map, "figures/powerplant-map.html")
47+
hvplot.save(point_map, "figures/powerplant-map.html")
4848

4949
bars = grouped.hvplot.barh(
5050
by="Fueltype",

0 commit comments

Comments
 (0)