|
13 | 13 | import pandas as pd
|
14 | 14 | import xarray as xr
|
15 | 15 |
|
| 16 | +def plot_map(regions, color, cmap, label, vmin=None, vmax=None): |
| 17 | + |
| 18 | + proj = ccrs.EqualEarth() |
| 19 | + regions = regions.to_crs(proj.proj4_init) |
| 20 | + fig, ax = plt.subplots(figsize=(7, 7), subplot_kw={"projection": proj}) |
| 21 | + regions.plot( |
| 22 | + ax=ax, |
| 23 | + column=color, |
| 24 | + cmap=cmap, |
| 25 | + linewidths=0, |
| 26 | + legend=True, |
| 27 | + vmin=vmin, |
| 28 | + vmax=vmax, |
| 29 | + legend_kwds={"label": label, "shrink": 0.8}, |
| 30 | + ) |
| 31 | + ax.add_feature(cartopy.feature.COASTLINE.with_scale("50m"), linewidth=0.5, zorder=4) |
| 32 | + ax.add_feature(cartopy.feature.BORDERS.with_scale("50m"), linewidth=0.5, zorder=2) |
| 33 | + ax.gridlines(linestyle=":") |
| 34 | + ax.axis("off") |
| 35 | + |
| 36 | + return fig, ax |
| 37 | + |
| 38 | + |
16 | 39 | if __name__ == "__main__":
|
17 | 40 | if "snakemake" not in globals():
|
18 | 41 | from _helpers import mock_snakemake
|
|
41 | 64 | wind = wind.groupby(level=0).sum().reindex(regions.index, fill_value=0)
|
42 | 65 | wind_per_skm = wind / regions.Area / 1e3 # GWh
|
43 | 66 |
|
44 |
| - proj = ccrs.EqualEarth() |
45 |
| - regions = regions.to_crs(proj.proj4_init) |
46 |
| - fig, ax = plt.subplots(figsize=(7, 7), subplot_kw={"projection": proj}) |
47 |
| - regions.plot( |
48 |
| - ax=ax, |
49 |
| - column=wind_per_skm, |
50 |
| - cmap="Blues", |
51 |
| - linewidths=0, |
52 |
| - legend=True, |
53 |
| - legend_kwds={"label": r"Wind Energy Potential [GWh/a/km$^2$]", "shrink": 0.8}, |
54 |
| - ) |
55 |
| - ax.add_feature(cartopy.feature.COASTLINE.with_scale("50m"), linewidth=0.5, zorder=4) |
56 |
| - ax.add_feature(cartopy.feature.BORDERS.with_scale("50m"), linewidth=0.5, zorder=2) |
57 |
| - ax.gridlines(linestyle=":") |
58 |
| - ax.axis("off") |
| 67 | + fig, ax = plot_map(regions, wind_per_skm, "Blues", r"Wind Energy Potential [GWh/a/km$^2$]") |
59 | 68 |
|
60 | 69 | for fn in snakemake.output["wind"]:
|
61 | 70 | plt.savefig(fn)
|
62 | 71 |
|
| 72 | + cf = pd.Series() |
| 73 | + for profile in ["onwind", "offwind-ac", "offwind-dc"]: |
| 74 | + ds = xr.open_dataset(snakemake.input[f"profile_{profile}"]) |
| 75 | + cf = pd.concat([cf, (ds.profile.mean("time") * 100).to_pandas()]) |
| 76 | + cf = cf.groupby(level=0).mean().reindex(regions.index, fill_value=0.) |
| 77 | + |
| 78 | + fig, ax = plot_map(regions, cf, "Blues", r"Wind Capacity Factor [%]", vmin=0, vmax=60) |
| 79 | + |
| 80 | + for fn in snakemake.output["wind_cf"]: |
| 81 | + plt.savefig(fn) |
| 82 | + |
63 | 83 | onregions = gpd.read_file(snakemake.input.regions_onshore).set_index("name")
|
64 | 84 | onregions["Area"] = onregions.to_crs(epsg=3035).area.div(1e6)
|
65 | 85 |
|
66 | 86 | ds = xr.open_dataset(snakemake.input.profile_solar)
|
67 | 87 | solar = (ds.p_nom_max * ds.profile.sum("time")).to_pandas()
|
68 | 88 |
|
69 |
| - solar = solar.groupby(level=0).sum().reindex(onregions.index, fill_value=0) |
| 89 | + solar = solar.groupby(level=0).sum().reindex(onregions.index, fill_value=0.) |
70 | 90 | solar_per_skm = solar / onregions.Area / 1e3 # GWh
|
71 | 91 |
|
72 |
| - proj = ccrs.EqualEarth() |
73 |
| - onregions = onregions.to_crs(proj.proj4_init) |
74 |
| - fig, ax = plt.subplots(figsize=(7, 7), subplot_kw={"projection": proj}) |
75 |
| - onregions.plot( |
76 |
| - ax=ax, |
77 |
| - column=solar_per_skm, |
78 |
| - cmap="Reds", |
79 |
| - linewidths=0, |
80 |
| - legend=True, |
81 |
| - legend_kwds={"label": r"Solar Energy Potential [GWh/a/km$^2$]", "shrink": 0.8}, |
82 |
| - ) |
83 |
| - ax.add_feature(cartopy.feature.COASTLINE.with_scale("50m"), linewidth=0.5, zorder=2) |
84 |
| - ax.add_feature(cartopy.feature.BORDERS.with_scale("50m"), linewidth=0.5, zorder=2) |
85 |
| - ax.gridlines(linestyle=":") |
86 |
| - ax.axis("off") |
| 92 | + fig, ax = plot_map(onregions, solar_per_skm, "Reds", r"Solar Energy Potential [GWh/a/km$^2$]") |
87 | 93 |
|
88 | 94 | for fn in snakemake.output["solar"]:
|
89 | 95 | plt.savefig(fn)
|
| 96 | + |
| 97 | + cf = (ds.profile.mean("time") * 100).to_pandas() |
| 98 | + cf = cf.groupby(level=0).mean().reindex(onregions.index, fill_value=0.) |
| 99 | + |
| 100 | + fig, ax = plot_map(onregions, cf, "Reds", r"Solar Capacity Factor [%]", vmin=6, vmax=20) |
| 101 | + |
| 102 | + for fn in snakemake.output["solar_cf"]: |
| 103 | + plt.savefig(fn) |
0 commit comments