From 053619a0f282dc9dffaac9f75a627800080bebd3 Mon Sep 17 00:00:00 2001 From: Jun Shepard Date: Wed, 25 Feb 2026 10:35:11 +0000 Subject: [PATCH 1/2] Ensure imports also have historical activity --- message_ix_models/tools/bilateralize/bare_to_scenario.py | 2 +- .../tools/bilateralize/historical_calibration.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/message_ix_models/tools/bilateralize/bare_to_scenario.py b/message_ix_models/tools/bilateralize/bare_to_scenario.py index 3f2e0a0c09..b68233df1c 100644 --- a/message_ix_models/tools/bilateralize/bare_to_scenario.py +++ b/message_ix_models/tools/bilateralize/bare_to_scenario.py @@ -394,7 +394,7 @@ def bare_to_scenario( for c in covered_tec if c not in ["crudeoil_piped", "foil_piped", "loil_piped"] ]: - add_tec = tec_config[tec][tec + "_trade"]["trade_technology"] + "_exp" + add_tec = tec_config[tec][tec + "_trade"]["trade_technology"] hist_tec[tec] = add_tec for tec in hist_tec.keys(): diff --git a/message_ix_models/tools/bilateralize/historical_calibration.py b/message_ix_models/tools/bilateralize/historical_calibration.py index 942ff30287..9691c441a3 100644 --- a/message_ix_models/tools/bilateralize/historical_calibration.py +++ b/message_ix_models/tools/bilateralize/historical_calibration.py @@ -738,7 +738,7 @@ def build_historical_activity( check_iea_balances(indf=tradedf, project_name=project_name, config_name=config_name) tradedf["ENERGY (GWa)"] = tradedf["ENERGY (TJ)"] * (3.1712 * 1e-5) # TJ to GWa - + outdf = reformat_to_parameter( indf=tradedf, message_regions=message_regions, @@ -746,6 +746,9 @@ def build_historical_activity( project_name=project_name, config_name=config_name, ) + outdf = outdf.groupby(['node_loc', 'technology', 'year_act', + 'mode', 'time'])['value'].sum().reset_index() + outdf["unit"] = "GWa" return outdf.drop_duplicates() From d7101023782db30bf463014812e814088a31b8c6 Mon Sep 17 00:00:00 2001 From: Jun Shepard <51372492+junukitashepard@users.noreply.github.com> Date: Thu, 26 Feb 2026 09:13:10 +0100 Subject: [PATCH 2/2] Reformat for ruff (only bilateralize) --- .../tools/bilateralize/historical_calibration.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/message_ix_models/tools/bilateralize/historical_calibration.py b/message_ix_models/tools/bilateralize/historical_calibration.py index 9691c441a3..41876e28a6 100644 --- a/message_ix_models/tools/bilateralize/historical_calibration.py +++ b/message_ix_models/tools/bilateralize/historical_calibration.py @@ -738,7 +738,7 @@ def build_historical_activity( check_iea_balances(indf=tradedf, project_name=project_name, config_name=config_name) tradedf["ENERGY (GWa)"] = tradedf["ENERGY (TJ)"] * (3.1712 * 1e-5) # TJ to GWa - + outdf = reformat_to_parameter( indf=tradedf, message_regions=message_regions, @@ -746,9 +746,12 @@ def build_historical_activity( project_name=project_name, config_name=config_name, ) - outdf = outdf.groupby(['node_loc', 'technology', 'year_act', - 'mode', 'time'])['value'].sum().reset_index() - + outdf = ( + outdf.groupby(["node_loc", "technology", "year_act", "mode", "time"])["value"] + .sum() + .reset_index() + ) + outdf["unit"] = "GWa" return outdf.drop_duplicates()