Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise error in tools.costs when a technology is assigned a reduction rate for which it does not have value #270

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions message_ix_models/tools/costs/decay.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,6 @@
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"]]
Expand Down Expand Up @@ -350,6 +348,29 @@
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 warning on line 359 in message_ix_models/tools/costs/decay.py

View check run for this annotation

Codecov / codecov/patch

message_ix_models/tools/costs/decay.py#L359

Added line #L359 was not covered by tests
check_nan.message_technology
+ " + "
+ check_nan.scenario
+ " + "
+ check_nan.reduction_rate
)

raise ValueError(

Check warning on line 367 in message_ix_models/tools/costs/decay.py

View check run for this annotation

Codecov / codecov/patch

message_ix_models/tools/costs/decay.py#L367

Added line #L367 was not covered by tests
"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
df["cost_reduction"] = np.where(df.reduction_rate == "none", 0, df.cost_reduction)

Expand Down
Loading