From 98300162ecc99d6a9abef5b0d1df13e49c8c039c Mon Sep 17 00:00:00 2001 From: Measrainsey Meng Date: Wed, 18 Dec 2024 12:47:32 +0100 Subject: [PATCH] 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 a28fcb034..2893f1aea 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)