Skip to content

Commit ba44b81

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 1432703 commit ba44b81

13 files changed

+169
-123
lines changed

matplotlibrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ image.cmap: viridis
77
figure.autolayout : True
88
figure.constrained_layout.use : True
99
figure.dpi : 400
10-
legend.frameon : False
10+
legend.frameon : False

rules/collect.smk

+11-3
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@ rule plot_resources:
9999
RESOURCES + "graphics/industrial-sites.pdf",
100100
RESOURCES + "graphics/powerplants.pdf",
101101
RESOURCES + "graphics/salt-caverns.pdf",
102-
expand(RESOURCES + "graphics/power-network-{clusters}.pdf", **config["scenario"]),
103-
expand(RESOURCES + "graphics/salt-caverns-{clusters}-nearshore.pdf", **config["scenario"]),
104-
expand(RESOURCES + "graphics/biomass-potentials-{clusters}-biogas.pdf", **config["scenario"]),
102+
expand(
103+
RESOURCES + "graphics/power-network-{clusters}.pdf", **config["scenario"]
104+
),
105+
expand(
106+
RESOURCES + "graphics/salt-caverns-{clusters}-nearshore.pdf",
107+
**config["scenario"]
108+
),
109+
expand(
110+
RESOURCES + "graphics/biomass-potentials-{clusters}-biogas.pdf",
111+
**config["scenario"]
112+
),

rules/plot.smk

+34-13
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
#
33
# SPDX-License-Identifier: MIT
44

5+
56
rule plot_power_network_unclustered:
67
input:
78
network=RESOURCES + "networks/elec.nc",
89
rc="matplotlibrc",
910
output:
10-
multiext(RESOURCES + "graphics/power-network-unclustered", ".png", ".pdf")
11+
multiext(RESOURCES + "graphics/power-network-unclustered", ".png", ".pdf"),
1112
script:
1213
"../scripts/plot_power_network_unclustered.py"
1314

@@ -23,7 +24,7 @@ rule plot_gas_network_unclustered:
2324
storage="data/gas_network/scigrid-gas/data/IGGIELGN_Storages.geojson",
2425
rc="matplotlibrc",
2526
output:
26-
multiext(RESOURCES + "graphics/gas-network-unclustered", ".png", ".pdf")
27+
multiext(RESOURCES + "graphics/gas-network-unclustered", ".png", ".pdf"),
2728
script:
2829
"../scripts/plot_gas_network_unclustered.py"
2930

@@ -34,19 +35,19 @@ rule plot_power_network_clustered:
3435
regions_onshore=RESOURCES + "regions_onshore_elec_s_{clusters}.geojson",
3536
rc="matplotlibrc",
3637
output:
37-
multiext(RESOURCES + "graphics/power-network-{clusters}", ".png", ".pdf")
38+
multiext(RESOURCES + "graphics/power-network-{clusters}", ".png", ".pdf"),
3839
script:
3940
"../scripts/plot_power_network_clustered.py"
4041

4142

4243
rule plot_renewable_potential_unclustered:
4344
input:
44-
regions_onshore=RESOURCES + "regions_onshore.geojson",
45-
regions_offshore=RESOURCES + "regions_offshore.geojson",
4645
**{
4746
f"profile_{tech}": RESOURCES + f"profile_{tech}.nc"
4847
for tech in config["electricity"]["renewable_carriers"]
4948
},
49+
regions_onshore=RESOURCES + "regions_onshore.geojson",
50+
regions_offshore=RESOURCES + "regions_offshore.geojson",
5051
rc="matplotlibrc",
5152
output:
5253
wind=multiext(RESOURCES + "graphics/wind-energy-density", ".png", ".pdf"),
@@ -60,9 +61,13 @@ rule plot_weather_data_map:
6061
cutout=f"cutouts/" + CDIR + config["atlite"]["default_cutout"] + ".nc",
6162
rc="matplotlibrc",
6263
output:
63-
irradiation=multiext(RESOURCES + "graphics/weather-map-irradiation", ".png", ".pdf"),
64+
irradiation=multiext(
65+
RESOURCES + "graphics/weather-map-irradiation", ".png", ".pdf"
66+
),
6467
runoff=multiext(RESOURCES + "graphics/weather-map-runoff", ".png", ".pdf"),
65-
temperature=multiext(RESOURCES + "graphics/weather-map-temperature", ".png", ".pdf"),
68+
temperature=multiext(
69+
RESOURCES + "graphics/weather-map-temperature", ".png", ".pdf"
70+
),
6671
wind=multiext(RESOURCES + "graphics/weather-map-wind", ".png", ".pdf"),
6772
script:
6873
"../scripts/plot_weather_data_map.py"
@@ -106,9 +111,15 @@ rule plot_salt_caverns_clustered:
106111
regions_offshore=RESOURCES + "regions_offshore_elec_s_{clusters}.geojson",
107112
rc="matplotlibrc",
108113
output:
109-
onshore=multiext(RESOURCES + "graphics/salt-caverns-{clusters}-onshore", ".png", ".pdf"),
110-
nearshore=multiext(RESOURCES + "graphics/salt-caverns-{clusters}-nearshore", ".png", ".pdf"),
111-
offshore=multiext(RESOURCES + "graphics/salt-caverns-{clusters}-offshore", ".png", ".pdf"),
114+
onshore=multiext(
115+
RESOURCES + "graphics/salt-caverns-{clusters}-onshore", ".png", ".pdf"
116+
),
117+
nearshore=multiext(
118+
RESOURCES + "graphics/salt-caverns-{clusters}-nearshore", ".png", ".pdf"
119+
),
120+
offshore=multiext(
121+
RESOURCES + "graphics/salt-caverns-{clusters}-offshore", ".png", ".pdf"
122+
),
112123
script:
113124
"../scripts/plot_salt_caverns_clustered.py"
114125

@@ -119,8 +130,18 @@ rule plot_biomass_potentials:
119130
regions_onshore=RESOURCES + "regions_onshore_elec_s_{clusters}.geojson",
120131
rc="matplotlibrc",
121132
output:
122-
solid_biomass=multiext(RESOURCES + "graphics/biomass-potentials-{clusters}-solid_biomass", ".png", ".pdf"),
123-
not_included=multiext(RESOURCES + "graphics/biomass-potentials-{clusters}-not_included", ".png", ".pdf"),
124-
biogas=multiext(RESOURCES + "graphics/biomass-potentials-{clusters}-biogas", ".png", ".pdf"),
133+
solid_biomass=multiext(
134+
RESOURCES + "graphics/biomass-potentials-{clusters}-solid_biomass",
135+
".png",
136+
".pdf",
137+
),
138+
not_included=multiext(
139+
RESOURCES + "graphics/biomass-potentials-{clusters}-not_included",
140+
".png",
141+
".pdf",
142+
),
143+
biogas=multiext(
144+
RESOURCES + "graphics/biomass-potentials-{clusters}-biogas", ".png", ".pdf"
145+
),
125146
script:
126147
"../scripts/plot_biomass_potentials.py"

scripts/plot_biomass_potentials.py

+6-11
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@
66
Plot unclustered salt caverns.
77
"""
88

9-
import pandas as pd
9+
import cartopy
10+
import cartopy.crs as ccrs
1011
import geopandas as gpd
1112
import matplotlib.pyplot as plt
12-
import cartopy.crs as ccrs
13-
import cartopy
13+
import pandas as pd
1414

1515

1616
def plot_biomass_potentials(bio, regions, kind):
17-
1817
crs = ccrs.EqualEarth()
1918
regions = regions.to_crs(crs.proj4_init)
2019

@@ -32,7 +31,7 @@ def plot_biomass_potentials(bio, regions, kind):
3231
cmap="Greens",
3332
legend=True,
3433
linewidth=0.5,
35-
edgecolor='grey',
34+
edgecolor="grey",
3635
legend_kwds={
3736
"label": label,
3837
"shrink": 0.7,
@@ -60,19 +59,15 @@ def plot_biomass_potentials(bio, regions, kind):
6059
snakemake = mock_snakemake(
6160
"plot_biomass_potentials",
6261
clusters=128,
63-
configfiles=["../../config/config.test.yaml"]
62+
configfiles=["../../config/config.test.yaml"],
6463
)
6564

6665
plt.style.use(snakemake.input.rc)
6766

6867
bio = pd.read_csv(snakemake.input.biomass, index_col=0).div(1e6) # TWh/a
6968

70-
regions = gpd.read_file(
71-
snakemake.input.regions_onshore
72-
).set_index("name")
73-
69+
regions = gpd.read_file(snakemake.input.regions_onshore).set_index("name")
7470

7571
plot_biomass_potentials(bio, regions, kind="not included")
7672
plot_biomass_potentials(bio, regions, kind="biogas")
7773
plot_biomass_potentials(bio, regions, kind="solid biomass")
78-

scripts/plot_gas_network_unclustered.py

+17-12
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66
Plot unclustered gas transmission network.
77
"""
88

9-
import pandas as pd
10-
import numpy as np
11-
from shapely import wkt
9+
import cartopy
10+
import cartopy.crs as ccrs
1211
import geopandas as gpd
12+
import matplotlib.colors as mcolors
1313
import matplotlib.pyplot as plt
14-
import cartopy.crs as ccrs
15-
import cartopy
14+
import numpy as np
15+
import pandas as pd
1616
from build_gas_input_locations import build_gas_input_locations
17-
import matplotlib.colors as mcolors
1817
from matplotlib.ticker import LogFormatter
18+
from shapely import wkt
1919

2020
if __name__ == "__main__":
2121
if "snakemake" not in globals():
@@ -40,7 +40,12 @@
4040
pts.loc[pts["type"] == t, "capacity"] /= sums[t]
4141

4242
pts["type"] = pts["type"].replace(
43-
dict(production="Fossil Extraction", lng="LNG Terminal", pipeline="Entrypoint", storage="Storage")
43+
dict(
44+
production="Fossil Extraction",
45+
lng="LNG Terminal",
46+
pipeline="Entrypoint",
47+
storage="Storage",
48+
)
4449
)
4550

4651
df = pd.read_csv(snakemake.input.gas_network, index_col=0)
@@ -63,8 +68,8 @@
6368

6469
df.plot(
6570
ax=ax,
66-
column=df["p_nom"].div(1e3).fillna(0.),
67-
linewidths=np.log(df.p_nom.div(df.p_nom.min())).fillna(0.).div(3),
71+
column=df["p_nom"].div(1e3).fillna(0.0),
72+
linewidths=np.log(df.p_nom.div(df.p_nom.min())).fillna(0.0).div(3),
6873
cmap="Spectral_r",
6974
vmax=vmax,
7075
legend=True,
@@ -75,15 +80,15 @@
7580
pts.plot(
7681
ax=ax,
7782
column="type",
78-
markersize=pts["capacity"].fillna(0.) * 750,
83+
markersize=pts["capacity"].fillna(0.0) * 750,
7984
alpha=0.8,
8085
legend=True,
8186
legend_kwds=dict(loc=[0.08, 0.86]),
82-
zorder=6
87+
zorder=6,
8388
)
8489

8590
ax.gridlines(linestyle=":")
86-
ax.axis('off')
91+
ax.axis("off")
8792

8893
for fn in snakemake.output:
8994
plt.savefig(fn)

scripts/plot_industrial_sites.py

+24-16
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
Plot industrial sites.
77
"""
88

9-
import pandas as pd
10-
import geopandas as gpd
11-
import matplotlib.pyplot as plt
12-
import cartopy.crs as ccrs
139
import cartopy
10+
import cartopy.crs as ccrs
1411
import country_converter as coco
12+
import geopandas as gpd
13+
import matplotlib.pyplot as plt
14+
import pandas as pd
15+
1516
cc = coco.CountryConverter()
1617

1718

@@ -20,19 +21,16 @@ def prepare_hotmaps_database():
2021
Load hotmaps database of industrial sites.
2122
"""
2223

23-
df = pd.read_csv(
24-
snakemake.input.hotmaps, sep=";", index_col=0
25-
)
24+
df = pd.read_csv(snakemake.input.hotmaps, sep=";", index_col=0)
2625

2726
df[["srid", "coordinates"]] = df.geom.str.split(";", expand=True)
2827

2928
# remove those sites without valid locations
3029
df.drop(df.index[df.coordinates.isna()], inplace=True)
3130

3231
df["coordinates"] = gpd.GeoSeries.from_wkt(df["coordinates"])
33-
34-
gdf = gpd.GeoDataFrame(df, geometry="coordinates", crs="EPSG:4326")
3532

33+
gdf = gpd.GeoDataFrame(df, geometry="coordinates", crs="EPSG:4326")
3634

3735
return gdf
3836

@@ -42,15 +40,14 @@ def prepare_hotmaps_database():
4240
from _helpers import mock_snakemake
4341

4442
snakemake = mock_snakemake(
45-
"plot_industrial_sites",
46-
configfiles=["../../config/config.test.yaml"]
43+
"plot_industrial_sites", configfiles=["../../config/config.test.yaml"]
4744
)
4845

4946
plt.style.use(snakemake.input.rc)
5047

5148
crs = ccrs.EqualEarth()
5249

53-
countries = gpd.read_file(snakemake.input.countries).set_index('name')
50+
countries = gpd.read_file(snakemake.input.countries).set_index("name")
5451

5552
hotmaps = prepare_hotmaps_database()
5653
hotmaps = hotmaps.cx[-12:30, 35:72]
@@ -59,25 +56,36 @@ def prepare_hotmaps_database():
5956
not_represented = ["AL", "BA", "RS", "MK", "ME"]
6057
missing_countries = countries.loc[countries.index.intersection(not_represented)]
6158

62-
fig, ax = plt.subplots(figsize=(8,8), subplot_kw={"projection": crs})
59+
fig, ax = plt.subplots(figsize=(8, 8), subplot_kw={"projection": crs})
6360

6461
ax.add_feature(cartopy.feature.COASTLINE.with_scale("50m"), linewidth=0.5, zorder=2)
6562
ax.add_feature(cartopy.feature.BORDERS.with_scale("50m"), linewidth=0.5, zorder=2)
6663

6764
missing_countries.to_crs(crs.proj4_init).plot(
6865
ax=ax,
69-
color='lightgrey',
66+
color="lightgrey",
7067
)
7168

72-
emissions = hotmaps["Emissions_ETS_2014"].fillna(hotmaps["Emissions_EPRTR_2014"]).fillna(hotmaps["Production"]).fillna(2e4)
69+
emissions = (
70+
hotmaps["Emissions_ETS_2014"]
71+
.fillna(hotmaps["Emissions_EPRTR_2014"])
72+
.fillna(hotmaps["Production"])
73+
.fillna(2e4)
74+
)
7375

7476
hotmaps.plot(
7577
ax=ax,
7678
column="Subsector",
7779
markersize=emissions / 4e4,
7880
alpha=0.5,
7981
legend=True,
80-
legend_kwds=dict(title="Industry Sector (radius ~ emissions)", frameon=False, ncols=2, loc=[0,.85], title_fontproperties={'weight':'bold'}),
82+
legend_kwds=dict(
83+
title="Industry Sector (radius ~ emissions)",
84+
frameon=False,
85+
ncols=2,
86+
loc=[0, 0.85],
87+
title_fontproperties={"weight": "bold"},
88+
),
8189
)
8290
ax.axis("off")
8391

0 commit comments

Comments
 (0)