Skip to content

Commit 1b0c1ed

Browse files
committed
Typos and updates
1 parent f818b23 commit 1b0c1ed

5 files changed

Lines changed: 26 additions & 19 deletions

File tree

examples/04_Scenarios/scenario_example.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@
8383
# Base Case: 60% probability, High Demand: 40% probability
8484
scenario_weights = np.array([0.6, 0.4])
8585

86-
flow_system = fx.FlowSystem(timesteps=timesteps, periods=periods, scenarios=scenarios, weights=scenario_weights)
86+
flow_system = fx.FlowSystem(
87+
timesteps=timesteps, periods=periods, scenarios=scenarios, scenario_weights=scenario_weights
88+
)
8789

8890
# --- Define Energy Buses ---
8991
# These represent nodes, where the used medias are balanced (electricity, heat, and gas)

flixopt/plotting.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1267,7 +1267,7 @@ def heatmap_with_plotly(
12671267
Automatic time reshaping (when only time dimension remains):
12681268
12691269
```python
1270-
# Data with dims ['time', 'scenario', 'period']
1270+
# Data with dims ['time', period','scenario']
12711271
# After faceting and animation, only 'time' remains -> auto-reshapes to (timestep, timeframe)
12721272
fig = heatmap_with_plotly(data_array, facet_by='scenario', animate_by='period')
12731273
```

flixopt/results.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1231,7 +1231,7 @@ def plot_node_balance(
12311231
facet_by: Dimension(s) to create facets (subplots) for. Can be a single dimension name (str)
12321232
or list of dimensions. Each unique value combination creates a subplot. Ignored if not found.
12331233
Example: 'scenario' creates one subplot per scenario.
1234-
Example: ['scenario', 'period'] creates a grid of subplots for each scenario-period combination.
1234+
Example: ['period', 'scenario'] creates a grid of subplots for each scenario-period combination.
12351235
animate_by: Dimension to animate over (Plotly only). Creates animation frames that cycle through
12361236
dimension values. Only one dimension can be animated. Ignored if not found.
12371237
facet_cols: Number of columns in the facet grid layout (default: 3).

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ def simple_flow_system_scenarios() -> fx.FlowSystem:
451451

452452
# Create flow system
453453
flow_system = fx.FlowSystem(
454-
base_timesteps, scenarios=pd.Index(['A', 'B', 'C']), weights=np.array([0.5, 0.25, 0.25])
454+
base_timesteps, scenarios=pd.Index(['A', 'B', 'C']), scenario_weights=np.array([0.5, 0.25, 0.25])
455455
)
456456
flow_system.add_elements(*Buses.defaults())
457457
flow_system.add_elements(storage, costs, co2, boiler, heat_load, gas_tariff, electricity_feed_in, chp)

tests/test_scenarios.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,9 @@ def flow_system_piecewise_conversion_scenarios(flow_system_complex_scenarios) ->
238238
def test_weights(flow_system_piecewise_conversion_scenarios):
239239
"""Test that scenario weights are correctly used in the model."""
240240
scenarios = flow_system_piecewise_conversion_scenarios.scenarios
241-
weights = np.linspace(0.5, 1, len(scenarios))
242-
flow_system_piecewise_conversion_scenarios.weights = weights
241+
scenario_weights = np.linspace(0.5, 1, len(scenarios))
242+
flow_system_piecewise_conversion_scenarios.scenario_weights = scenario_weights
243+
flow_system_piecewise_conversion_scenarios.weights = flow_system_piecewise_conversion_scenarios._compute_weights()
243244
model = create_linopy_model(flow_system_piecewise_conversion_scenarios)
244245
normalized_weights = (
245246
flow_system_piecewise_conversion_scenarios.weights / flow_system_piecewise_conversion_scenarios.weights.sum()
@@ -254,11 +255,14 @@ def test_weights(flow_system_piecewise_conversion_scenarios):
254255
def test_weights_io(flow_system_piecewise_conversion_scenarios):
255256
"""Test that scenario weights are correctly used in the model."""
256257
scenarios = flow_system_piecewise_conversion_scenarios.scenarios
257-
weights = np.linspace(0.5, 1, len(scenarios)) / np.sum(np.linspace(0.5, 1, len(scenarios)))
258-
flow_system_piecewise_conversion_scenarios.weights = weights
258+
scenario_weights = np.linspace(0.5, 1, len(scenarios)) / np.sum(np.linspace(0.5, 1, len(scenarios)))
259+
flow_system_piecewise_conversion_scenarios.scenario_weights = scenario_weights
260+
flow_system_piecewise_conversion_scenarios.weights = flow_system_piecewise_conversion_scenarios._compute_weights()
259261
model = create_linopy_model(flow_system_piecewise_conversion_scenarios)
260-
np.testing.assert_allclose(model.objective_weights.values, weights)
261-
assert_linequal(model.objective.expression, (model.variables['costs'] * weights).sum() + model.variables['Penalty'])
262+
np.testing.assert_allclose(model.objective_weights.values, scenario_weights)
263+
assert_linequal(
264+
model.objective.expression, (model.variables['costs'] * scenario_weights).sum() + model.variables['Penalty']
265+
)
262266
assert np.isclose(model.objective_weights.sum().item(), 1.0)
263267

264268

@@ -317,8 +321,9 @@ def test_io_persistence(flow_system_piecewise_conversion_scenarios):
317321
def test_scenarios_selection(flow_system_piecewise_conversion_scenarios):
318322
flow_system_full = flow_system_piecewise_conversion_scenarios
319323
scenarios = flow_system_full.scenarios
320-
weights = np.linspace(0.5, 1, len(scenarios)) / np.sum(np.linspace(0.5, 1, len(scenarios)))
321-
flow_system_full.weights = weights
324+
scenario_weights = np.linspace(0.5, 1, len(scenarios)) / np.sum(np.linspace(0.5, 1, len(scenarios)))
325+
flow_system_full.scenario_weights = scenario_weights
326+
flow_system_full.weights = flow_system_full._compute_weights()
322327
flow_system = flow_system_full.sel(scenario=scenarios[0:2])
323328

324329
assert flow_system.scenarios.equals(flow_system_full.scenarios[0:2])
@@ -696,13 +701,13 @@ def test_weights_io_persistence():
696701
"""Test that weights persist through IO operations (to_dataset/from_dataset)."""
697702
timesteps = pd.date_range('2023-01-01', periods=24, freq='h')
698703
scenarios = pd.Index(['base', 'mid', 'high'], name='scenario')
699-
custom_weights = np.array([0.3, 0.5, 0.2])
704+
custom_scenario_weights = np.array([0.3, 0.5, 0.2])
700705

701-
# Create FlowSystem with custom weights
706+
# Create FlowSystem with custom scenario weights
702707
fs_original = fx.FlowSystem(
703708
timesteps=timesteps,
704709
scenarios=scenarios,
705-
weights=custom_weights,
710+
scenario_weights=custom_scenario_weights,
706711
)
707712

708713
bus = fx.Bus('grid')
@@ -737,13 +742,13 @@ def test_weights_selection():
737742
"""Test that weights are correctly sliced when using FlowSystem.sel()."""
738743
timesteps = pd.date_range('2023-01-01', periods=24, freq='h')
739744
scenarios = pd.Index(['base', 'mid', 'high'], name='scenario')
740-
custom_weights = np.array([0.3, 0.5, 0.2])
745+
custom_scenario_weights = np.array([0.3, 0.5, 0.2])
741746

742-
# Create FlowSystem with custom weights
747+
# Create FlowSystem with custom scenario weights
743748
fs_full = fx.FlowSystem(
744749
timesteps=timesteps,
745750
scenarios=scenarios,
746-
weights=custom_weights,
751+
scenario_weights=custom_scenario_weights,
747752
)
748753

749754
bus = fx.Bus('grid')
@@ -765,7 +770,7 @@ def test_weights_selection():
765770

766771
# Verify weights are correctly sliced
767772
assert fs_subset.scenarios.equals(pd.Index(['base', 'high'], name='scenario'))
768-
np.testing.assert_allclose(fs_subset.weights.values, custom_weights[[0, 2]])
773+
np.testing.assert_allclose(fs_subset.weights.values, custom_scenario_weights[[0, 2]])
769774

770775
# Verify weights are 1D with just scenario dimension (no period dimension)
771776
assert fs_subset.weights.dims == ('scenario',)

0 commit comments

Comments
 (0)