Skip to content

Commit

Permalink
add scenario builder parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
ChouaneLouis committed May 31, 2024
1 parent 22fd4ec commit 562f54d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 8 deletions.
21 changes: 21 additions & 0 deletions src/andromede/study/scenario_parsing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright (c) 2024, RTE (https://www.rte-france.com)
#
# See AUTHORS.txt
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# SPDX-License-Identifier: MPL-2.0
#
# This file is part of the Antares project.

from pathlib import Path

import pandas as pd


def parse_scenario_builder(file: Path) -> pd.core.frame.DataFrame:
sb = pd.read_csv(file, names=("name", "year", "scenario"))
sb.rename(columns={0: "name", 1: "year", 2: "scenario"})
return sb
8 changes: 8 additions & 0 deletions tests/unittests/data/scenario_builder.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
load, 0, 0
load, 1, 1
load, 2, 0
load, 3, 1
cost-group, 0, 0
cost-group, 1, 0
cost-group, 2, 1
cost-group, 3, 1
26 changes: 18 additions & 8 deletions tests/unittests/test_scenario_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,26 @@
consistency_check,
resolve_components_and_cnx,
)
from andromede.study.scenario_parsing import parse_scenario_builder


@pytest.fixture
def database(data_dir: Path) -> DataBase:
def scenario_builder(data_dir: Path) -> pd.core.frame.DataFrame:
buider_path = data_dir / "scenario_builder.csv"
return parse_scenario_builder(buider_path)


@pytest.fixture
def database(data_dir: Path, scenario_builder: pd.core.frame.DataFrame) -> DataBase:
components_path = data_dir / "components_for_scenarization_test.yml"
ts_path = data_dir
with components_path.open() as components:
return build_scenarized_data_base(
parse_yaml_components(components), scenario_builder, ts_path
)


def test_parser(scenario_builder):
builder = pd.DataFrame(
{
"name": [
Expand All @@ -47,14 +63,8 @@ def database(data_dir: Path) -> DataBase:
"scenario": [0, 1, 0, 1, 0, 0, 1, 1],
}
)
builder = builder.reset_index()

components_path = data_dir / "components_for_scenarization_test.yml"
ts_path = data_dir
with components_path.open() as components:
return build_scenarized_data_base(
parse_yaml_components(components), builder, ts_path
)
assert builder.equals(scenario_builder)


# cost-group group isnt use in following test because sum can't take time dependant parameters
Expand Down

0 comments on commit 562f54d

Please sign in to comment.