Skip to content

Commit 1c30bb0

Browse files
committed
Refactor existing changes to fit latest code structure
1 parent f8101b7 commit 1c30bb0

File tree

2 files changed

+38
-22
lines changed

2 files changed

+38
-22
lines changed

Diff for: message_ix/models.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from dataclasses import InitVar, dataclass, field
55
from functools import partial
66
from pathlib import Path
7-
from typing import Mapping, MutableMapping, Optional, Tuple
7+
from typing import MutableMapping, Optional, Tuple
88
from warnings import warn
99

1010
import ixmp.model.gams
@@ -173,7 +173,7 @@ class GAMSModel(ixmp.model.gams.GAMSModel):
173173

174174
#: Mapping from model item (equation, parameter, set, or variable) names to
175175
#: :class:`.Item` describing the item.
176-
items: Mapping[str, Item]
176+
items: MutableMapping[str, Item]
177177

178178
def __init__(self, name=None, **model_options):
179179
# Update the default options with any user-provided options
@@ -405,6 +405,8 @@ def initialize(cls, scenario):
405405
par("commodity_stock", "n c l y")
406406
par("construction_time", "nl t yv")
407407
par("demand", "n c l y h")
408+
par("df_year", "y")
409+
par("df_period", "y")
408410
par("duration_period", "y")
409411
par("duration_time", "h")
410412
par("dynamic_land_lo", "n s y u")
@@ -453,6 +455,7 @@ def initialize(cls, scenario):
453455
par("level_cost_activity_soft_up", "nl t ya h")
454456
par("level_cost_new_capacity_soft_lo", "nl t yv")
455457
par("level_cost_new_capacity_soft_up", "nl t yv")
458+
par("levelized_cost", "n t y h")
456459
par("min_utilization_factor", "nl t yv ya")
457460
par("operation_factor", "nl t yv ya")
458461
par("output", "nl t yv ya m nd c l h hd")
@@ -557,6 +560,11 @@ def initialize(cls, scenario):
557560
"n type_emission type_tec y",
558561
"Emission price (derived from marginals of EMISSION_BOUND constraint)",
559562
)
563+
var(
564+
"PRICE_EMISSION_NEW",
565+
"n type_emission type_tec y",
566+
"TEMPORARY test for Emission price fix",
567+
)
560568
var(
561569
"REL",
562570
"r nr yr",
@@ -766,7 +774,7 @@ def initialize(cls, scenario):
766774
)
767775
equ(
768776
"EMISSION_EQUIVALENCE",
769-
"",
777+
"n e type_tec y",
770778
"Auxiliary equation to simplify the notation of emissions",
771779
)
772780
equ("EXTRACTION_BOUND_UP", "", "Upper bound on extraction (by grade)")

Diff for: message_ix/tests/test_feature_price_emission.py

+27-19
Original file line numberDiff line numberDiff line change
@@ -67,37 +67,45 @@ def add_many_tecs(scen, years, n=50):
6767
"""add a range of dirty-to-clean technologies to the scenario"""
6868
output_specs = ["node", "comm", "level", "year", "year"]
6969

70-
# tec: [emissions, var_cost, bound_activity_up]
70+
# Add some hardcoded tecs for temporary testing
71+
# tec: [emission_factor, var_cost, bound_activity_up]
7172
# tecs = {
7273
# "tec1": [10, 5, 1],
7374
# "tec2": [-1, 10, 0.4],
7475
# "tec3": [-5, 200, 0.3],
7576
# "tec4": [-15, 1200, 0.2],
7677
# "tec5": [-50, 6000, 0.1],
7778
# }
78-
# tecs = {
79-
# "tec1": [10, 5, 1],
80-
# "tec2": [-10, 10, 0.4],
81-
# "tec3": [-12, 20, 0.3],
82-
# "tec4": [-14, 30, 0.2],
83-
# "tec5": [-16, 40, 0.1],
84-
# }
85-
for i in range(1, n + 1):
86-
t = f"tec{i}"
79+
tecs = {
80+
"tec1": [10, 5, 1],
81+
"tec2": [-10, 10, 0.4],
82+
"tec3": [-12, 20, 0.3],
83+
"tec4": [-14, 30, 0.2],
84+
"tec5": [-16, 40, 0.1],
85+
}
86+
# This is the original and we want to convert back to it after testing:
87+
# for i in range(1, n + 1):
88+
# t = f"tec{i}"
89+
# -----------------
90+
for t in tecs:
8791
scen.add_set("technology", t)
8892
for y in years:
8993
tec_specs = ["node", t, y, y, "mode"]
90-
# variable costs grow quadratically over technologies
91-
# to get rid of the curse of linearity
92-
c = (10 * i / n) ** 2 * (1.045) ** (y - years[0])
93-
e = 1 - i / n
94+
# This is the original, convert back after testing:
95+
# # variable costs grow quadratically over technologies
96+
# # to get rid of the curse of linearity
97+
# c = (10 * i / n) ** 2 * (1.045) ** (y - years[0])
98+
# e = 1 - i / n
99+
# scen.add_par("var_cost", tec_specs + ["year"], c, "USD/GWa")
100+
# scen.add_par("emission_factor", tec_specs + ["co2"], e, "tCO2")
101+
# -------------
94102
scen.add_par("output", tec_specs + output_specs, 1, "GWa")
95-
scen.add_par("var_cost", tec_specs + ["year"], c, "USD/GWa")
96-
scen.add_par("emission_factor", tec_specs + ["co2"], e, "tCO2")
97103

98-
# scen.add_par("var_cost", tec_specs + ["year"], tecs[t][1], "USD/GWa")
99-
# scen.add_par("emission_factor", tec_specs + ["co2"], tecs[t][0], "tCO2")
100-
# scen.add_par("bound_activity_up", ["node", t, y, "mode", "year"], tecs[t][2], "GWa")
104+
scen.add_par("var_cost", tec_specs + ["year"], tecs[t][1], "USD/GWa")
105+
scen.add_par("emission_factor", tec_specs + ["co2"], tecs[t][0], "tCO2")
106+
scen.add_par(
107+
"bound_activity_up", ["node", t, y, "mode", "year"], tecs[t][2], "GWa"
108+
)
101109

102110
scen.add_set("type_addon", "mitigation")
103111
scen.add_set("map_tec_addon", ["tec1", "mitigation"])

0 commit comments

Comments
 (0)