From d286c5b30e439d0e3851a5b93953202856697814 Mon Sep 17 00:00:00 2001 From: Measrainsey Meng Date: Wed, 18 Dec 2024 12:47:32 +0100 Subject: [PATCH 1/3] Raise error when a technology is assigned a reduction rate it does not have --- message_ix_models/tools/costs/decay.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/message_ix_models/tools/costs/decay.py b/message_ix_models/tools/costs/decay.py index a28fcb0341..2893f1aeae 100644 --- a/message_ix_models/tools/costs/decay.py +++ b/message_ix_models/tools/costs/decay.py @@ -350,6 +350,27 @@ def get_technology_reduction_scenarios_data( cost_reduction_long, on=["message_technology", "reduction_rate"], how="left" ).merge(adj_first_year, on="message_technology", how="left") + # filter for rows where cost_reduction is NaN and reduction rate is not "none" + # these are instances where a technology has a reduction_rate that + # does not have a cost_reduction value + check_nan = df.query("cost_reduction.isnull() and reduction_rate != 'none'")[ + ["message_technology", "scenario", "reduction_rate"] + ] + + if not check_nan.empty: + check_nan["print"] = ( + check_nan.message_technology + + " + " + + check_nan.scenario + + " + " + + check_nan.reduction_rate + ) + + raise ValueError( + f"The following technology + scenario + reduction rate combinations are missing data. Please check the reduction rate exists for the technology.\n\ + {check_nan.print.unique().tolist()}." + ) + # if reduction_rate is "none", then set cost_reduction to 0 df["cost_reduction"] = np.where(df.reduction_rate == "none", 0, df.cost_reduction) From ece612a918a460b4b8cec28e6d5c5476691c1741 Mon Sep 17 00:00:00 2001 From: Measrainsey Meng Date: Wed, 18 Dec 2024 13:45:02 +0100 Subject: [PATCH 2/3] Remove random query line --- message_ix_models/tools/costs/decay.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/message_ix_models/tools/costs/decay.py b/message_ix_models/tools/costs/decay.py index 2893f1aeae..55296cc070 100644 --- a/message_ix_models/tools/costs/decay.py +++ b/message_ix_models/tools/costs/decay.py @@ -314,8 +314,6 @@ def get_technology_reduction_scenarios_data( scenarios_reduction = _get_module_scenarios_reduction(module, energy_map, tech_map) cost_reduction = _get_module_cost_reduction(module, energy_map, tech_map) - cost_reduction.query("message_technology == 'bio_hpl'") - # get first year values adj_first_year = ( tech_map[["message_technology", "first_year_original"]] From ecf2597c186b5a39f02e7280db17602872a6f6cb Mon Sep 17 00:00:00 2001 From: Measrainsey Meng Date: Wed, 18 Dec 2024 13:59:39 +0100 Subject: [PATCH 3/3] Fix line length for linting --- message_ix_models/tools/costs/decay.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/message_ix_models/tools/costs/decay.py b/message_ix_models/tools/costs/decay.py index 55296cc070..71b19f1403 100644 --- a/message_ix_models/tools/costs/decay.py +++ b/message_ix_models/tools/costs/decay.py @@ -365,8 +365,10 @@ def get_technology_reduction_scenarios_data( ) raise ValueError( - f"The following technology + scenario + reduction rate combinations are missing data. Please check the reduction rate exists for the technology.\n\ - {check_nan.print.unique().tolist()}." + "The following technology + scenario + reduction rate combinations " + "are missing data. " + "Please check that the reduction rate exists for the technology.\n" + f"{check_nan.print.unique().tolist()}." ) # if reduction_rate is "none", then set cost_reduction to 0