Skip to content

Commit

Permalink
add second panel to regional price plot (#310)
Browse files Browse the repository at this point in the history
* add second panel with difference

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* add title and improve aspect ratio

* redid the elec_price function with better coloring

* Switching workflow to new layout for elec prices

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
lindnemi and pre-commit-ci[bot] authored Jan 17, 2025
1 parent 0fa95bd commit 84172e4
Showing 1 changed file with 190 additions and 20 deletions.
210 changes: 190 additions & 20 deletions workflow/scripts/plot_ariadne_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -1165,26 +1165,42 @@ def plot_elec_prices_spatial(
df["elec_price"] = n.buses_t.marginal_price[buses].mean()

# Netzentgelte, Annuität NEP 2045 - Annuität PyPSA 2045 / Stromverbrauch Pypsa 2045
# (19.38 - 12.56 ) / 1.234
pypsa_netzentgelt = (15.82 - 6.53) / 1.237
elec_price_de = df["elec_price"][df.index.str.contains("DE")]
max_above_mean = elec_price_de.max() - elec_price_de.mean()

mean_with_netzentgelt = elec_price_de.mean() + pypsa_netzentgelt
# Calculate the difference from the mean_with_netzentgelt
df["elec_price_diff"] = mean_with_netzentgelt - df["elec_price"]

# Create figure
fig, ax = plt.subplots(
1, 1, subplot_kw={"projection": ccrs.PlateCarree()}, figsize=(9, 6)
)
crs = ccrs.PlateCarree()

# Calculate aspect ratio based on geographic extent
extent = [5, 16, 47, 56] # Germany bounds
aspect_ratio = (extent[1] - extent[0]) / (extent[3] - extent[2])

# Set figure size dynamically based on aspect ratio
fig_width = 16 # You can adjust this value
fig_height = fig_width / aspect_ratio

# Create figure with two subplots
fig, (ax1, ax2) = plt.subplots(
1, 2, subplot_kw={"projection": crs}, figsize=(fig_width, 0.5 * fig_height)
)

# First subplot: elec_price
mvs = df["elec_price"][df.index.str.contains("DE")]
vmin = np.nanmin(mvs)
vmax = np.nanmax(mvs)

ax.add_feature(cartopy.feature.BORDERS, edgecolor="black", linewidth=0.5)
ax.coastlines(edgecolor="black", linewidth=0.5)
ax.set_facecolor("white")
ax.add_feature(cartopy.feature.OCEAN, color="azure")
ax1.add_feature(cartopy.feature.BORDERS, edgecolor="black", linewidth=0.5)
ax1.coastlines(edgecolor="black", linewidth=0.5)
ax1.set_facecolor("white")
ax1.add_feature(cartopy.feature.OCEAN, color="azure")

df[df.index.str.contains("DE")].to_crs(crs.proj4_init).plot(
column=f"elec_price",
ax=ax,
column="elec_price",
ax=ax1,
cmap=plt.get_cmap("cividis_r"),
linewidth=0.05,
edgecolor="grey",
Expand All @@ -1198,23 +1214,177 @@ def plot_elec_prices_spatial(
},
)

# max_size = df[f"{carriers[i]}_gen"].max()
# df.to_crs(crs.proj4_init).centroid.plot(ax=ax, sizes=df[f"{carriers[i]}_gen"] / max_size *300, color="black", edgecolor="white")
# pypsa.plot.add_legend_circles(ax=ax, sizes=[0.6], labels=["Generation magnitude"], patch_kw={'color': 'black', 'edgecolor': 'white'}, legend_kw={'loc': 'upper left'})
# Set geographic extent for Germany
ax1.set_extent(extent, crs) # Germany bounds
ax1.set_aspect(aspect_ratio)

# Second subplot: elec_price_diff
mvs_diff = df["elec_price_diff"][df.index.str.contains("DE")]

ax2.add_feature(cartopy.feature.BORDERS, edgecolor="black", linewidth=0.5)
ax2.coastlines(edgecolor="black", linewidth=0.5)
ax2.set_facecolor("white")
ax2.add_feature(cartopy.feature.OCEAN, color="azure")

df[df.index.str.contains("DE")].to_crs(crs.proj4_init).plot(
column="elec_price_diff",
ax=ax2,
cmap=plt.get_cmap("Greens"),
linewidth=0.05,
edgecolor="grey",
vmax=np.nanmax(mvs_diff) + np.nanmin(mvs_diff),
vmin=0,
legend=True,
legend_kwds={
"label": "Durchschnittliche Preisreduktion für Endkunden($€/MWh$)",
"orientation": "vertical",
"shrink": 0.9,
},
)

# Set geographic extent for Germany
ax.set_extent([5, 16, 47, 56], ccrs.PlateCarree()) # Germany bounds
# ax.set_title(f"{carriers[i]}", fontsize=16, **font1)
ax2.set_extent(extent, crs) # Germany bounds
ax2.set_aspect(aspect_ratio)

# fig.suptitle(f"Spatial Differences in the electricity generation of the VRE technologies ({model})", fontsize=16, **font1)
fig.tight_layout()
# Adjust layout to place legends on the right

# plt.close()
plt.suptitle(
"Nodale Strompreise und durchschnittliche Preisreduktion",
ha="center",
fontsize=16,
y=0.98,
x=0.5,
)
plt.subplots_adjust(right=0.85)
fig.tight_layout()
plt.show()

fig.savefig(savepath, bbox_inches="tight")


def plot_elec_prices_spatial_new(
network, tech_colors, savepath, onshore_regions, year="2045", region="DE"
):

# onshore_regions = gpd.read_file("/home/julian-geis/repos/pypsa-ariadne-1/resources/20241203-force-onwind-south-49cl-disc/KN2045_Bal_v4/regions_onshore_base_s_49.geojson")
# onshore_regions = onshore_regions.set_index('name')

n = network
buses = n.buses[n.buses.carrier == "AC"].index

df = onshore_regions
df["elec_price"] = n.buses_t.marginal_price[buses].mean()

# Netzentgelte, Annuität NEP 2045 - Annuität PyPSA 2045 / Stromverbrauch Pypsa 2045
pypsa_netzentgelt = (6.53 + 27.51) / 1.237
nep_netzentgelt = (15.82 + 27.51) / 1.237
elec_price_de = df["elec_price"][df.index.str.contains("DE")]
max_above_mean = elec_price_de.max() - elec_price_de.mean()

# Calculate the difference from the mean_with_netzentgelt

df["elec_price_nep"] = elec_price_de.mean() + nep_netzentgelt
df["elec_price_pypsa"] = df["elec_price"] + pypsa_netzentgelt
df["elec_price_diff"] = df["elec_price_nep"] - df["elec_price_pypsa"]

crs = ccrs.PlateCarree()

# Calculate aspect ratio based on geographic extent
extent = [5, 16, 47, 56] # Germany bounds
aspect_ratio = (extent[1] - extent[0]) / (extent[3] - extent[2])

# Set figure size dynamically based on aspect ratio
fig_width = 14 # You can adjust this value
fig_height = fig_width / aspect_ratio

# Create figure with two subplots
fig, (ax1, ax2) = plt.subplots(
1, 2, subplot_kw={"projection": crs}, figsize=(fig_width, 0.55 * fig_height)
)

# First subplot: elec_price
mvs = df["elec_price_pypsa"][df.index.str.contains("DE")]
vmin = np.nanmin(mvs)
vmax = max(np.nanmax(mvs), df["elec_price_nep"].unique().item())

ax1.add_feature(cartopy.feature.BORDERS, edgecolor="black", linewidth=0.5)
ax1.coastlines(edgecolor="black", linewidth=0.5)
ax1.set_facecolor("white")
ax1.add_feature(cartopy.feature.OCEAN, color="azure")
ax1.set_title("Durchschnittspreis, NEP Ausbau", pad=15)
img1 = (
df[df.index.str.contains("DE")]
.to_crs(crs.proj4_init)
.plot(
column="elec_price_nep",
ax=ax1,
linewidth=0.05,
edgecolor="grey",
legend=False,
vmin=vmin,
vmax=vmax,
cmap="viridis_r",
)
)

# Set geographic extent for Germany
ax1.set_extent(extent, crs) # Germany bounds
ax1.set_aspect(aspect_ratio)

# Second subplot: elec_price_diff
ax2.add_feature(cartopy.feature.BORDERS, edgecolor="black", linewidth=0.5)
ax2.coastlines(edgecolor="black", linewidth=0.5)
ax2.set_facecolor("white")
ax2.add_feature(cartopy.feature.OCEAN, color="azure")
ax2.set_title("Nodale Preise, $PyPSA$-$DE$ Ausbau", pad=15)

img2 = (
df[df.index.str.contains("DE")]
.to_crs(crs.proj4_init)
.plot(
column="elec_price_diff",
ax=ax2,
cmap="viridis",
linewidth=0.05,
edgecolor="grey",
vmax=vmax - vmin,
vmin=0,
legend=False,
)
)

# Set geographic extent for Germany
ax2.set_extent(extent, crs) # Germany bounds
ax2.set_aspect(aspect_ratio)

# Create a new axis for the colorbar at the bottom
cax2 = fig.add_axes([0.15, 0.14, 0.6, 0.03]) # [left, bottom, width, height]
cax1 = fig.add_axes([0.15, 0.00, 0.6, 0.03]) # [left, bottom, width, height]

# Add colorbar to the new axis
cbar1 = fig.colorbar(
img1.get_figure().get_axes()[0].collections[0],
cax=cax1,
orientation="horizontal",
)
cbar1.set_label("Börsenstrompreis zzgl. durchschnittlichem Netzentgelt [$€/MWh$]")
cbar1.set_ticklabels(np.linspace(vmax, vmin, 6).round(1))
cbar1.ax.invert_xaxis()

cbar2 = fig.colorbar(
img2.get_figure().get_axes()[0].collections[0],
cax=cax2,
orientation="horizontal",
)
cbar2.set_label("Durchschnittliche Preisreduktion für Endkunden [$€/MWh$]")
cbar2.set_ticklabels(np.linspace(0, vmax - vmin, 6).round(1))

plt.subplots_adjust(right=0.75, bottom=0.22)
# plt.show()

fig.savefig(savepath, bbox_inches="tight")


def assign_location(n):
for c in n.iterate_components(n.one_port_components | n.branch_components):
ifind = pd.Series(c.df.index.str.find(" ", start=4), c.df.index)
Expand Down Expand Up @@ -2463,7 +2633,7 @@ def plot_cap_map_de(
regions = gpd.read_file(snakemake.input.regions_onshore_clustered).set_index("name")

year = 2045
plot_elec_prices_spatial(
plot_elec_prices_spatial_new(
network=networks[planning_horizons.index(year)].copy(),
tech_colors=tech_colors,
onshore_regions=regions,
Expand Down

0 comments on commit 84172e4

Please sign in to comment.