From e850b8e39bad4a46cb14460481e5048cfd737814 Mon Sep 17 00:00:00 2001 From: Fridolin Glatter Date: Fri, 1 Dec 2023 10:40:20 +0100 Subject: [PATCH] Refactor existing changes to fit latest code structure --- message_ix/models.py | 14 ++++-- .../tests/test_feature_price_emission.py | 46 +++++++++++-------- 2 files changed, 38 insertions(+), 22 deletions(-) diff --git a/message_ix/models.py b/message_ix/models.py index 5c9253f71..b95c23bde 100644 --- a/message_ix/models.py +++ b/message_ix/models.py @@ -4,7 +4,7 @@ from dataclasses import InitVar, dataclass, field from functools import partial from pathlib import Path -from typing import Mapping, MutableMapping, Optional, Tuple +from typing import MutableMapping, Optional, Tuple from warnings import warn import ixmp.model.gams @@ -175,7 +175,7 @@ class GAMSModel(ixmp.model.gams.GAMSModel): #: Mapping from model item (equation, parameter, set, or variable) names to #: :class:`.Item` describing the item. - items: Mapping[str, Item] + items: MutableMapping[str, Item] def __init__(self, name=None, **model_options): # Update the default options with any user-provided options @@ -407,6 +407,8 @@ def initialize(cls, scenario): par("commodity_stock", "n c l y") par("construction_time", "nl t yv") par("demand", "n c l y h") +par("df_year", "y") +par("df_period", "y") par("duration_period", "y") par("duration_time", "h") par("dynamic_land_lo", "n s y u") @@ -455,6 +457,7 @@ def initialize(cls, scenario): par("level_cost_activity_soft_up", "nl t ya h") par("level_cost_new_capacity_soft_lo", "nl t yv") par("level_cost_new_capacity_soft_up", "nl t yv") +par("levelized_cost", "n t y h") par("min_utilization_factor", "nl t yv ya") par("operation_factor", "nl t yv ya") par("output", "nl t yv ya m nd c l h hd") @@ -559,6 +562,11 @@ def initialize(cls, scenario): "n type_emission type_tec y", "Emission price (derived from marginals of EMISSION_BOUND constraint)", ) +var( + "PRICE_EMISSION_NEW", + "n type_emission type_tec y", + "TEMPORARY test for Emission price fix", +) var( "REL", "r nr yr", @@ -768,7 +776,7 @@ def initialize(cls, scenario): ) equ( "EMISSION_EQUIVALENCE", - "", + "n e type_tec y", "Auxiliary equation to simplify the notation of emissions", ) equ("EXTRACTION_BOUND_UP", "", "Upper bound on extraction (by grade)") diff --git a/message_ix/tests/test_feature_price_emission.py b/message_ix/tests/test_feature_price_emission.py index 6cc12b852..b74e275c8 100644 --- a/message_ix/tests/test_feature_price_emission.py +++ b/message_ix/tests/test_feature_price_emission.py @@ -56,7 +56,8 @@ def add_many_tecs(scen, years, n=50): """add a range of dirty-to-clean technologies to the scenario""" output_specs = ["node", "comm", "level", "year", "year"] - # tec: [emissions, var_cost, bound_activity_up] + # Add some hardcoded tecs for temporary testing + # tec: [emission_factor, var_cost, bound_activity_up] # tecs = { # "tec1": [10, 5, 1], # "tec2": [-1, 10, 0.4], @@ -64,29 +65,36 @@ def add_many_tecs(scen, years, n=50): # "tec4": [-15, 1200, 0.2], # "tec5": [-50, 6000, 0.1], # } - # tecs = { - # "tec1": [10, 5, 1], - # "tec2": [-10, 10, 0.4], - # "tec3": [-12, 20, 0.3], - # "tec4": [-14, 30, 0.2], - # "tec5": [-16, 40, 0.1], - # } - for i in range(1, n + 1): - t = f"tec{i}" + tecs = { + "tec1": [10, 5, 1], + "tec2": [-10, 10, 0.4], + "tec3": [-12, 20, 0.3], + "tec4": [-14, 30, 0.2], + "tec5": [-16, 40, 0.1], + } + # This is the original and we want to convert back to it after testing: + # for i in range(1, n + 1): + # t = f"tec{i}" + # ----------------- + for t in tecs: scen.add_set("technology", t) for y in years: tec_specs = ["node", t, y, y, "mode"] - # variable costs grow quadratically over technologies - # to get rid of the curse of linearity - c = (10 * i / n) ** 2 * (1.045) ** (y - years[0]) - e = 1 - i / n + # This is the original, convert back after testing: + # # variable costs grow quadratically over technologies + # # to get rid of the curse of linearity + # c = (10 * i / n) ** 2 * (1.045) ** (y - years[0]) + # e = 1 - i / n + # scen.add_par("var_cost", tec_specs + ["year"], c, "USD/GWa") + # scen.add_par("emission_factor", tec_specs + ["co2"], e, "tCO2") + # ------------- scen.add_par("output", tec_specs + output_specs, 1, "GWa") - scen.add_par("var_cost", tec_specs + ["year"], c, "USD/GWa") - scen.add_par("emission_factor", tec_specs + ["co2"], e, "tCO2") - # scen.add_par("var_cost", tec_specs + ["year"], tecs[t][1], "USD/GWa") - # scen.add_par("emission_factor", tec_specs + ["co2"], tecs[t][0], "tCO2") - # scen.add_par("bound_activity_up", ["node", t, y, "mode", "year"], tecs[t][2], "GWa") + scen.add_par("var_cost", tec_specs + ["year"], tecs[t][1], "USD/GWa") + scen.add_par("emission_factor", tec_specs + ["co2"], tecs[t][0], "tCO2") + scen.add_par( + "bound_activity_up", ["node", t, y, "mode", "year"], tecs[t][2], "GWa" + ) scen.add_set("type_addon", "mitigation") scen.add_set("map_tec_addon", ["tec1", "mitigation"])