Skip to content

Commit

Permalink
ext GC plot: show prices for balanced_market only
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan.schirmeister committed Nov 20, 2024
1 parent 516dc73 commit 5e447a3
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions simba/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def generate_plots(schedule, scenario, args):
plot_consumption_per_rotation_distribution(extended_plots_path, schedule)
plot_distance_per_rotation_distribution(extended_plots_path, schedule)
plot_charge_type_distribution(extended_plots_path, scenario, schedule)
plot_gc_power_timeseries(extended_plots_path, scenario, schedule)
plot_gc_power_timeseries(extended_plots_path, scenario, schedule, args)
plot_active_rotations(extended_plots_path, scenario, schedule)

# revert logging override
Expand Down Expand Up @@ -557,7 +557,7 @@ def plot_charge_type_distribution(extended_plots_path, scenario, schedule):
plt.close()


def plot_gc_power_timeseries(extended_plots_path, scenario, schedule):
def plot_gc_power_timeseries(extended_plots_path, scenario, schedule, args):
"""Plots the different loads (total, feedin, external) of all grid connectors.
:param extended_plots_path: directory to save plot to
Expand All @@ -566,6 +566,8 @@ def plot_gc_power_timeseries(extended_plots_path, scenario, schedule):
:type scenario: spice_ev.Scenario
:param schedule: provides default time windows
:type schedule: simba.schedule.Schedule
:param args: Configuration arguments
:type args: argparse.Namespace
"""
for gcID, gc in scenario.components.grid_connectors.items():
fig, ax = plt.subplots()
Expand All @@ -578,8 +580,12 @@ def plot_gc_power_timeseries(extended_plots_path, scenario, schedule):
"sum CS power [kW]",
"battery power [kW]",
"bat. stored energy [kWh]",
"price [EUR/kWh]",
]
# for stations simulated with balanced market, plot price as well
station = schedule.stations[gcID]
plot_price = vars(args).get(f"strategy_{station['type']}") == "balanced_market"
if plot_price:
headers.append("price [ct/kWh]")

has_battery_column = False
has_prices = False
Expand All @@ -597,7 +603,7 @@ def plot_gc_power_timeseries(extended_plots_path, scenario, schedule):
# column does not exist
continue

if header == "price [EUR/kWh]":
if header == "price [ct/kWh]":
has_prices = True
twin_price = ax.twinx()
# get next color from color cycle (just plotting would start with first color)
Expand All @@ -606,8 +612,9 @@ def plot_gc_power_timeseries(extended_plots_path, scenario, schedule):
time_values, header_values, label=header, c=next_color, linestyle="dashdot")
twin_price.yaxis.label.set_color(next_color)
twin_price.tick_params(axis='y', colors=next_color)
twin_price.set_ylabel("price [€/kWh]")
twin_price.legend()
twin_price.set_ylabel("price [ct/kWh]")
# add dummy values to primary axis for legend
ax.plot([], [], next_color, linestyle="dashdot", label=header)
elif header == "bat. stored energy [kWh]":
has_battery_column = True
twin_bat = ax.twinx()
Expand All @@ -618,11 +625,15 @@ def plot_gc_power_timeseries(extended_plots_path, scenario, schedule):
twin_bat.yaxis.label.set_color(next_color)
twin_bat.tick_params(axis='y', colors=next_color)
twin_bat.set_ylabel("stored battery energy [kWh]")
twin_bat.legend()
# add dummy values to primary axis for legend
ax.plot([], [], next_color, linestyle="dashdot", label=header)
else:
# normal plot (no price or battery)
ax.plot(time_values, header_values, label=header)

if plot_price and not has_prices:
logging.error(f"Plot GC power: {gcID} simulated with balanced_market, but has no price")

# align y axis so that 0 is shared
# (limits not necessary, as power, energy and prices can't be compared directly)
# find smallest ratio of all axes
Expand Down Expand Up @@ -683,7 +694,7 @@ def plot_gc_power_timeseries(extended_plots_path, scenario, schedule):
label=label, facecolor=color, alpha=0.2)
start_idx = i

ax.legend()
ax.legend() # fig.legend places legend outside of plot
# plt.xticks(rotation=30)
ax.set_ylabel("Power [kW]")
ax.set_title(f"Power: {gcID}")
Expand Down

0 comments on commit 5e447a3

Please sign in to comment.