1
+ from typing import List
2
+
1
3
import numpy .testing as npt
2
4
import pytest
3
5
4
- from message_ix import Scenario
5
-
6
6
# from message_ix.testing import make_westeros
7
- from message_ix . util import make_df
7
+ from message_ix import Scenario , make_df
8
8
9
9
MODEL = "test_emissions_price"
10
10
19
19
interest_rate = 0.05
20
20
21
21
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 :
23
23
"""generate a minimal model to test the behaviour of the emission prices"""
24
24
scen .add_spatial_sets ({"country" : "node" })
25
25
scen .add_set ("commodity" , "comm" )
@@ -48,24 +48,44 @@ def model_setup(scen: Scenario, years: list[int], simple_tecs=True) -> None:
48
48
add_two_tecs (scen , years ) if simple_tecs else add_many_tecs (scen , years )
49
49
50
50
51
- def add_two_tecs (scen : Scenario , years : list [int ]) -> None :
51
+ def add_two_tecs (scen : Scenario , years : List [int ]) -> None :
52
52
"""add two technologies to the scenario"""
53
53
scen .add_set ("technology" , ["dirty_tec" , "clean_tec" ])
54
- output_specs = ["node" , "comm" , "level" , "year" , "year" ]
55
54
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
+ )
61
66
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
+ )
66
86
67
87
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 :
69
89
"""add a range of dirty-to-clean technologies to the scenario"""
70
90
# Add some hardcoded tecs for temporary testing
71
91
tecs : dict [str , dict ] = {
@@ -336,18 +356,20 @@ def test_custom_type_variable_periodlength(test_mp, request):
336
356
cumulative = False
337
357
years = [2020 , 2021 , 2022 , 2023 ]
338
358
tag = "yearly_" + str (bound ) + "_equal"
359
+
360
+
339
361
@pytest .mark .parametrize (
340
- "bound, cumulative, years, tag " ,
362
+ "bound, cumulative, years" ,
341
363
[
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 ]),
348
370
],
349
371
)
350
- def test_price_duality (test_mp , request , bound , cumulative , years , tag ):
372
+ def test_price_duality (test_mp , request , bound , cumulative , years ):
351
373
# set up a scenario for cumulative constraints
352
374
scen = Scenario (
353
375
test_mp ,
@@ -356,15 +378,26 @@ def test_price_duality(test_mp, request, bound, cumulative, years, tag):
356
378
version = "new" ,
357
379
)
358
380
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
+ )
359
384
if cumulative :
360
385
scen .add_cat ("year" , "cumulative" , years )
361
386
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
+ ),
363
393
)
364
394
else :
365
395
for y in years :
366
396
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
+ )
368
401
scen .commit ("initialize test scenario" )
369
402
scen .solve (quiet = True , ** solve_args )
370
403
0 commit comments