Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
ChouaneLouis committed May 30, 2024
1 parent 6c8211d commit 68ee8cb
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 1 deletion.
48 changes: 48 additions & 0 deletions tests/unittests/data/components_for_scenarization_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# 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.
study:
nodes:
- id: N
model: node

components:
- id: G
model: sd-generator
parameters:
- name: cost
scenario-group: cost-group
type: timeseries
timeseries: gen-costs
- name: p_max
type: constant
value: 100
- id: D
model: demand
scenario-group: load
parameters:
- name: demand
type: timeseries
timeseries: loads

connections:
- component1: N
port_1: injection_port
component2: D
port_2: injection_port

- component1: N
port_1: injection_port
component2: G
port_2: injection_port



25 changes: 24 additions & 1 deletion tests/unittests/data/lib.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,28 @@ library:
definition: generation
objective: expec(sum(cost * generation))

- id: sd-generator
description: A basic scenario dependent generator model
parameters:
- name: cost
time-dependent: true
scenario-dependent: true
- name: p_max
time-dependent: false
scenario-dependent: false
variables:
- name: generation
lower-bound: 0
upper-bound: p_max
ports:
- name: injection_port
type: flow
port-field-definitions:
- port: injection_port
field: flow
definition: generation
objective: expec(sum(cost * generation))

- id: node
description: A basic balancing node model
ports:
Expand All @@ -51,6 +73,7 @@ library:
binding-constraints:
- name: balance
expression: sum_connections(injection_port.flow) = 0

- id: spillage
description: A basic spillage model
parameters:
Expand All @@ -67,6 +90,7 @@ library:
- port: injection_port
field: flow
definition: -spillage

- id: unsupplied
description: A basic unsupplied model
parameters:
Expand All @@ -84,7 +108,6 @@ library:
field: flow
definition: unsupplied_energy


- id: demand
description: A basic fixed demand model
parameters:
Expand Down
2 changes: 2 additions & 0 deletions tests/unittests/data/loads.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
50 100
50 100
63 changes: 63 additions & 0 deletions tests/unittests/test_scenario_builder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# 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
import pytest

from andromede.study import DataBase
from andromede.study.data import ComponentParameterIndex
from andromede.study.parsing import parse_yaml_components
from andromede.study.resolve_components import build_scenarized_data_base


@pytest.fixture
def database(data_dir: Path) -> DataBase:
builder = pd.DataFrame(
{
"name": [
"load",
"load",
"load",
"load",
"cost-group",
"cost-group",
"cost-group",
"cost-group",
],
"year": [0, 1, 2, 3, 0, 1, 2, 3],
"scenario": [0, 1, 0, 1, 0, 0, 1, 1],
}
)
builder = builder.reset_index()

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


def test_scenarized_data_base(database):
cost_index = ComponentParameterIndex("G", "cost")
assert database.get_value(cost_index, 0, 0) == 100
assert database.get_value(cost_index, 0, 1) == 100
assert database.get_value(cost_index, 0, 2) == 200
assert database.get_value(cost_index, 0, 3) == 200

load_index = ComponentParameterIndex("D", "demand")
assert database.get_value(load_index, 0, 0) == 50
assert database.get_value(load_index, 0, 1) == 100
assert database.get_value(load_index, 0, 2) == 50
assert database.get_value(load_index, 0, 3) == 100

0 comments on commit 68ee8cb

Please sign in to comment.