Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/user-guide/outputs.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ df = results.data
~~~

The DataFrame has columns: `block`, `component`, `output`,
`absolute-time-index`, `block-time-index`, `scenario-index`, `value`, `basis-status`.
`absolute_time_index`, `block_time_index`, `scenario_index`, `value`, `basis_status`.

Reading the value of the optimisation variable `var_id` of component `component_id`
for a single time step and scenario:
Expand All @@ -65,12 +65,12 @@ for a single time step and scenario:
value = df[(df["component"] == component_id) & (df["output"] == var_id)]["value"].iloc[0]
~~~

For multi-time or multi-scenario results, filter additionally by `block-time-index`
and `scenario-index`:
For multi-time or multi-scenario results, filter additionally by `block_time_index`
and `scenario_index`:

~~~ python
sub = df[(df["component"] == component_id) & (df["output"] == var_id)]
value_s0_t1 = sub[(sub["scenario-index"] == 0) & (sub["block-time-index"] == 1)]["value"].iloc[0]
value_s0_t1 = sub[(sub["scenario_index"] == 0) & (sub["block_time_index"] == 1)]["value"].iloc[0]
~~~

---
Expand Down
18 changes: 9 additions & 9 deletions src/gems/simulation/simulation_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class OutputView:
"""

def __init__(self, df: pd.DataFrame) -> None:
# df: index = absolute-time-index, columns = scenario-index
# df: index = absolute_time_index, columns = scenario_index
self._df = df

@property
Expand All @@ -32,8 +32,8 @@ def value(

Called with no arguments returns the full Time × Scenario DataFrame.
Called with one argument returns a ``pd.Series``:
- ``value(scenario_index=s)`` → Series indexed by absolute-time-index
- ``value(time_index=t)`` → Series indexed by scenario-index
- ``value(scenario_index=s)`` → Series indexed by absolute_time_index
- ``value(time_index=t)`` → Series indexed by scenario_index
Called with both arguments returns a scalar ``float``.
"""
if time_index is None and scenario_index is None:
Expand Down Expand Up @@ -142,7 +142,7 @@ def to_dataset(self) -> xr.Dataset:
"""Return simulation results as an xr.Dataset.

Each output variable becomes a DataArray with dimensions
(component, absolute-time-index, scenario-index).
(component, absolute_time_index, scenario_index).
Scalar rows without component/time/scenario (e.g. objective-value)
are stored as zero-dimensional variables.
"""
Expand Down Expand Up @@ -174,11 +174,11 @@ class SimulationColumns(str, Enum):
BLOCK = "block"
COMPONENT = "component"
OUTPUT = "output"
ABSOLUTE_TIME_INDEX = "absolute-time-index"
BLOCK_TIME_INDEX = "block-time-index"
SCENARIO_INDEX = "scenario-index"
ABSOLUTE_TIME_INDEX = "absolute_time_index"
BLOCK_TIME_INDEX = "block_time_index"
SCENARIO_INDEX = "scenario_index"
VALUE = "value"
BASIS_STATUS = "basis-status"
BASIS_STATUS = "basis_status"


class SimulationTableBuilder:
Expand Down Expand Up @@ -441,7 +441,7 @@ def _da_to_df(
) -> pd.DataFrame:
"""Vectorize a [component?, time?, scenario?] DataArray into a DataFrame.

Index columns (absolute-time-index, block-time-index, scenario-index) are
Index columns (absolute_time_index, block_time_index, scenario_index) are
set to None for dimensions that are absent from the original DataArray,
signalling that the output is independent of that dimension.
"""
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/functional/test_optim_modes.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@
_KEY_COLS = [
"component",
"output",
"absolute-time-index",
"scenario-index",
"absolute_time_index",
"scenario_index",
]


Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/functional/test_rolling_horizon_suboptimality.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def _get_value(raw, component: str, output: str, timestep: int) -> float:
mask = (
(raw["component"] == component)
& (raw["output"] == output)
& (raw["absolute-time-index"] == timestep)
& (raw["absolute_time_index"] == timestep)
)
rows = raw[mask]
assert (
Expand Down
8 changes: 4 additions & 4 deletions tests/e2e/functional/test_simtable_timeblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
- System: 3 components — node, generator (pmax=200), demand (timevarying: demand[t]=t)
- Data horizon: 150 timesteps
- TimeBlock: [40, 90) → 50 timesteps (indices 40–89)
- Checks that SimulationTable absolute-time-index, block-time-index, and
- Checks that SimulationTable absolute_time_index, block_time_index, and
generation values are all consistent with the partial block.
"""

Expand Down Expand Up @@ -52,8 +52,8 @@ def test_simtable_on_partial_timeblock(lib_dict_unittest: dict[str, Library]) ->
With demand[t] = t and pmax = 200, the optimizer sets generation[t] = t at
every timestep, making all three assertions self-consistent:
1. generation values equal their absolute timestep index.
2. absolute-time-index runs from 40 to 89 (not 0–149 or 0–49).
3. block-time-index runs from 0 to 49 and equals absolute-time-index − 40.
2. absolute_time_index runs from 40 to 89 (not 0–149 or 0–49).
3. block_time_index runs from 0 to 49 and equals absolute_time_index − 40.
"""
node_model = lib_dict_unittest["basic"].models["basic.node"]
generator_model = lib_dict_unittest["basic"].models["basic.generator"]
Expand Down Expand Up @@ -120,7 +120,7 @@ def test_simtable_on_partial_timeblock(lib_dict_unittest: dict[str, Library]) ->
assert abs_times == list(range(BLOCK_START, BLOCK_END))
assert block_times == list(range(BLOCK_END - BLOCK_START))

# absolute-time-index = block-time-index + BLOCK_START for every row
# absolute_time_index = block_time_index + BLOCK_START for every row
offset = (
gen_rows[SimulationColumns.ABSOLUTE_TIME_INDEX.value].astype(int)
- gen_rows[SimulationColumns.BLOCK_TIME_INDEX.value].astype(int)
Expand Down
4 changes: 2 additions & 2 deletions tests/unittests/simulation/test_simulation_table_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def test_to_dataset_values_match_data_single_scenario() -> None:
expected = float(row[SimulationColumns.VALUE.value])
actual = float(
ds[output].sel(
component=comp, **{"absolute-time-index": t, "scenario-index": s}
component=comp, **{"absolute_time_index": t, "scenario_index": s}
)
)
assert actual == pytest.approx(expected)
Expand All @@ -144,7 +144,7 @@ def test_to_dataset_values_match_data_multi_scenario() -> None:
expected = float(row[SimulationColumns.VALUE.value])
actual = float(
ds[output].sel(
component=comp, **{"absolute-time-index": t, "scenario-index": s}
component=comp, **{"absolute_time_index": t, "scenario_index": s}
)
)
assert actual == pytest.approx(expected)
Expand Down
Loading