Skip to content

Commit ec88a76

Browse files
committed
Remove unused tag parameter
1 parent 8093b2a commit ec88a76

File tree

1 file changed

+59
-26
lines changed

1 file changed

+59
-26
lines changed

message_ix/tests/test_feature_price_emission.py

Lines changed: 59 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
from typing import List
2+
13
import numpy.testing as npt
24
import pytest
35

4-
from message_ix import Scenario
5-
66
# from message_ix.testing import make_westeros
7-
from message_ix.util import make_df
7+
from message_ix import Scenario, make_df
88

99
MODEL = "test_emissions_price"
1010

@@ -19,7 +19,7 @@
1919
interest_rate = 0.05
2020

2121

22-
def model_setup(scen: Scenario, years: list[int], simple_tecs=True) -> None:
22+
def model_setup(scen: Scenario, years: List[int], simple_tecs=True) -> None:
2323
"""generate a minimal model to test the behaviour of the emission prices"""
2424
scen.add_spatial_sets({"country": "node"})
2525
scen.add_set("commodity", "comm")
@@ -48,24 +48,44 @@ def model_setup(scen: Scenario, years: list[int], simple_tecs=True) -> None:
4848
add_two_tecs(scen, years) if simple_tecs else add_many_tecs(scen, years)
4949

5050

51-
def add_two_tecs(scen: Scenario, years: list[int]) -> None:
51+
def add_two_tecs(scen: Scenario, years: List[int]) -> None:
5252
"""add two technologies to the scenario"""
5353
scen.add_set("technology", ["dirty_tec", "clean_tec"])
54-
output_specs = ["node", "comm", "level", "year", "year"]
5554

56-
for y in years:
57-
# the dirty technology is free (no costs) but has emissions
58-
tec_specs = ["node", "dirty_tec", y, y, "mode"]
59-
scen.add_par("output", tec_specs + output_specs, 1, "GWa")
60-
scen.add_par("emission_factor", tec_specs + ["CO2"], 1, "tCO2")
55+
common_base = dict(
56+
node_loc="node", year_vtg=years, year_act=years, mode="mode", value=1
57+
)
58+
common_output = dict(
59+
node_dest="node",
60+
commodity="comm",
61+
level="level",
62+
time="year",
63+
time_dest="year",
64+
unit="GWa",
65+
)
6166

62-
# the clean technology has variable costs but no emissions
63-
tec_specs = ["node", "clean_tec", y, y, "mode"]
64-
scen.add_par("output", tec_specs + output_specs, 1, "GWa")
65-
scen.add_par("var_cost", tec_specs + ["year"], 1, "USD/GWa")
67+
# the dirty technology is free (no costs) but has emissions
68+
scen.add_par(
69+
"output",
70+
make_df("output", technology="dirty_tec", **common_base, **common_output),
71+
)
72+
scen.add_par(
73+
"emission_factor",
74+
make_df("emission_factor", technology="dirty_tec", emission="CO2", unit="tCO2"),
75+
)
76+
77+
# the clean technology has variable costs but no emissions
78+
scen.add_par(
79+
"output",
80+
make_df("output", technology="clean_tec", **common_base, **common_output),
81+
)
82+
scen.add_par(
83+
"var_cost",
84+
make_df("var_cost", technology="clean_tec", time="year", unit="USD/GWa"),
85+
)
6686

6787

68-
def add_many_tecs(scen: Scenario, years: list[int], n=50) -> None:
88+
def add_many_tecs(scen: Scenario, years: List[int], n=50) -> None:
6989
"""add a range of dirty-to-clean technologies to the scenario"""
7090
# Add some hardcoded tecs for temporary testing
7191
tecs: dict[str, dict] = {
@@ -336,18 +356,20 @@ def test_custom_type_variable_periodlength(test_mp, request):
336356
cumulative = False
337357
years = [2020, 2021, 2022, 2023]
338358
tag = "yearly_" + str(bound) + "_equal"
359+
360+
339361
@pytest.mark.parametrize(
340-
"bound, cumulative, years, tag",
362+
"bound, cumulative, years",
341363
[
342-
(0.25, True, [2020, 2030, 2040, 2050], "0.25_equal"),
343-
(0.25, True, [2020, 2025, 2030, 2040, 2050], "0.25_varying"),
344-
(0.50, True, [2020, 2030, 2040, 2050], "0.5_equal"),
345-
(0.50, True, [2020, 2025, 2030, 2040, 2050], "0.5_varying"),
346-
(0.75, True, [2020, 2030, 2040, 2050], "0.75_equal"),
347-
(0.75, True, [2020, 2025, 2030, 2040, 2050], "0.75_varying"),
364+
(0.25, True, [2020, 2030, 2040, 2050]),
365+
(0.25, True, [2020, 2025, 2030, 2040, 2050]),
366+
(0.50, True, [2020, 2030, 2040, 2050]),
367+
(0.50, True, [2020, 2025, 2030, 2040, 2050]),
368+
(0.75, True, [2020, 2030, 2040, 2050]),
369+
(0.75, True, [2020, 2025, 2030, 2040, 2050]),
348370
],
349371
)
350-
def test_price_duality(test_mp, request, bound, cumulative, years, tag):
372+
def test_price_duality(test_mp, request, bound, cumulative, years):
351373
# set up a scenario for cumulative constraints
352374
scen = Scenario(
353375
test_mp,
@@ -356,15 +378,26 @@ def test_price_duality(test_mp, request, bound, cumulative, years, tag):
356378
version="new",
357379
)
358380
model_setup(scen, years, simple_tecs=False)
381+
bound_emission_base = dict(
382+
node="World", type_emission="ghg", type_tec="all", value=bound, unit="tCO2"
383+
)
359384
if cumulative:
360385
scen.add_cat("year", "cumulative", years)
361386
scen.add_par(
362-
"bound_emission", ["World", "ghg", "all", "cumulative"], bound, "tCO2",
387+
"bound_emission",
388+
make_df(
389+
"bound_emission",
390+
type_year="cumulative",
391+
**bound_emission_base,
392+
),
363393
)
364394
else:
365395
for y in years:
366396
scen.add_cat("year", y, y)
367-
scen.add_par("bound_emission", ["World", "ghg", "all", y], bound, "tCO2")
397+
scen.add_par(
398+
"bound_emission",
399+
make_df("bound_emission", type_year=y, **bound_emission_base),
400+
)
368401
scen.commit("initialize test scenario")
369402
scen.solve(quiet=True, **solve_args)
370403

0 commit comments

Comments
 (0)