Skip to content

Commit fb9841e

Browse files
committed
battery data in plotting tests
1 parent f9b798e commit fb9841e

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

tests/test_plotting/test_generation.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,17 +178,29 @@ def test_plot_dispatch_with_geography(csv_str_to_df):
178178

179179

180180
def test_plot_dispatch_system_level(csv_str_to_df):
181-
"""Test plot_dispatch without geography_level returns system-level structure."""
181+
"""Test plot_dispatch without geography_level returns system-level structure.
182+
183+
Includes battery data with both charging (negative) and discharging (positive)
184+
to verify battery traces are correctly split in the plot. Battery charging
185+
and discharging are on separate timesteps to ensure both traces are created
186+
(since values are aggregated by timestep before splitting).
187+
"""
182188
dispatch_csv = """
183189
generator, node, fuel_type, investment_period, timestep, dispatch_mw
184190
Gen1, SubA, Coal, 2024, 2024-01-01 12:00:00, 100
185191
Gen2, SubB, Wind, 2024, 2024-01-01 12:00:00, 50
192+
Bat1, SubA, Battery, 2024, 2024-01-01 12:00:00, 30
193+
Gen1, SubA, Coal, 2024, 2024-01-01 13:00:00, 100
194+
Gen2, SubB, Wind, 2024, 2024-01-01 13:00:00, 50
195+
Bat1, SubA, Battery, 2024, 2024-01-01 13:00:00, -20
186196
"""
187197

188198
demand_csv = """
189199
node, load, investment_period, timestep, demand_mw
190200
SubA, Load1, 2024, 2024-01-01 12:00:00, 80
191201
SubB, Load2, 2024, 2024-01-01 12:00:00, 70
202+
SubA, Load1, 2024, 2024-01-01 13:00:00, 80
203+
SubB, Load2, 2024, 2024-01-01 13:00:00, 70
192204
"""
193205

194206
dispatch = csv_str_to_df(dispatch_csv)
@@ -204,9 +216,16 @@ def test_plot_dispatch_system_level(csv_str_to_df):
204216
entry = result["2024"]["2024-01-01"]
205217
assert isinstance(entry["plot"], go.Figure)
206218
assert isinstance(entry["data"], pd.DataFrame)
207-
# Total dispatch should be 150 (100 + 50)
208-
assert entry["data"]["dispatch_mw"].sum() == 150
209-
assert set(entry["data"]["fuel_type"].unique()) == {"Coal", "Wind"}
219+
# Total dispatch should be 310 (100+50+30 + 100+50-20)
220+
assert entry["data"]["dispatch_mw"].sum() == 310
221+
assert set(entry["data"]["fuel_type"].unique()) == {"Coal", "Wind", "Battery"}
222+
223+
# Check that plot has separate battery charging and discharging traces
224+
trace_names = [trace.name for trace in entry["plot"].data]
225+
assert "Battery Discharging" in trace_names
226+
assert "Battery Charging" in trace_names
227+
# Raw "Battery" should not appear as a trace (it's split)
228+
assert "Battery" not in trace_names
210229

211230

212231
def test_prepare_generation_capacity(csv_str_to_df):

0 commit comments

Comments
 (0)