From dc6d8054a4494662430d3039b04aaf9eaf38bae0 Mon Sep 17 00:00:00 2001 From: Paul Natsuo Kishimoto Date: Wed, 4 Dec 2024 23:13:39 +0100 Subject: [PATCH] Align keys in .transport.{freight,non_ldv} with .ldv --- message_ix_models/model/transport/freight.py | 11 +++++++---- message_ix_models/model/transport/non_ldv.py | 20 ++++++++++++-------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/message_ix_models/model/transport/freight.py b/message_ix_models/model/transport/freight.py index 3ca6cf93e..315f1c70b 100644 --- a/message_ix_models/model/transport/freight.py +++ b/message_ix_models/model/transport/freight.py @@ -26,6 +26,9 @@ level="l", ) +#: Shorthand for tags on keys +Fi = "::F+ixmp" + def prepare_computer(c: genno.Computer): from genno.core.attrseries import AttrSeries @@ -47,7 +50,7 @@ def prepare_computer(c: genno.Computer): c.add(k[2], "as_message_df", prev, name="input", dims=DIMS, common=COMMON) # Convert units - to_add.append("input::transport F+ixmp") + to_add.append(f"input{Fi}") c.add(to_add[-1], convert_units, k[2], "transport info") # Extract the 'input' data frame @@ -100,7 +103,7 @@ def prepare_computer(c: genno.Computer): c.add(k[5], convert_units, k[4], "transport info") # Fill values - to_add.append("other::transport F+ixmp") + to_add.append(f"other{Fi}") c.add(to_add[-1], same_node, k[5]) # Base values for conversion technologies @@ -116,7 +119,7 @@ def prepare_computer(c: genno.Computer): # Convert output to MESSAGE data structure c.add(k[10], "as_message_df", prev, name="output", dims=DIMS, common=COMMON) - to_add.append("usage output::transport F+ixmp") + to_add.append(f"usage output{Fi}") c.add(to_add[-1], lambda v: same_time(same_node(v)), k[10]) # Create corresponding input values in Gv km @@ -133,7 +136,7 @@ def prepare_computer(c: genno.Computer): prev = c.add( k[i + 3], "as_message_df", prev, name="input", dims=DIMS, common=COMMON ) - to_add.append("usage input::transport F+ixmp") + to_add.append(f"usage input{Fi}") c.add(to_add[-1], prev) # Merge data to one collection diff --git a/message_ix_models/model/transport/non_ldv.py b/message_ix_models/model/transport/non_ldv.py index c9af2beaf..831430fc8 100644 --- a/message_ix_models/model/transport/non_ldv.py +++ b/message_ix_models/model/transport/non_ldv.py @@ -56,6 +56,10 @@ Units: TJ """ +#: Shorthand for tags on keys +Oi = "::O+ixmp" +Pi = "::P+ixmp" + def prepare_computer(c: Computer): from . import files as exo @@ -84,7 +88,7 @@ def prepare_computer(c: Computer): keys.append(k + "emi") # Data for usage technologies - k_usage = "transport nonldv usage::ixmp" + k_usage = f"transport usage{Pi}" keys.append(k_usage) c.add(k_usage, usage_data, exo.load_factor_nonldv, t_modes, n, y) @@ -122,7 +126,7 @@ def prepare_computer(c: Computer): # Add minimum activity for transport technologies keys.extend(iter_keys(c.apply(bound_activity_lo))) - k_constraint = "constraints::ixmp+transport+non-ldv" + k_constraint = f"constraints{Pi}" keys.append(k_constraint) c.add(k_constraint, constraint_data, "t::transport", t_modes, n, y, "config") @@ -130,7 +134,7 @@ def prepare_computer(c: Computer): keys.extend(bound_activity(c)) # Add to the scenario - k_all = "transport nonldv::ixmp" + k_all = f"transport{Pi}" c.add(k_all, "merge_data", *keys) c.add("transport_data", __name__, key=k_all) @@ -188,7 +192,7 @@ def bound_activity(c: "Computer") -> list[Key]: dims=dict(node_loc="n", technology="t", year_act="y"), common=dict(mode="all", time="year"), ) - k_bau = Key("bound_activity_up::non_ldv+ixmp") + k_bau = Key(f"bound_activity_up{Pi}") c.add(k_bau, "as_message_df", base, name=k_bau.name, **kw) return [k_bau] @@ -351,9 +355,9 @@ def broadcast_other_transport(technologies) -> Quantity: dims=dict(node_loc="n", technology="t", year_act="y"), common=dict(mode="all", time="year"), ) - k_bal = Key("bound_activity_lo::transport other+ixmp") + k_bal = Key(f"bound_activity_lo{Oi}") c.add(k_bal, "as_message_df", k_cnty.prev, name=k_bal.name, **kw) - k_bau = Key("bound_activity_up::transport other+ixmp") + k_bau = Key(f"bound_activity_up{Oi}") c.add(k_bau, "as_message_df", k_cnty.prev, name=k_bau.name, **kw) # Divide by self to ensure values = 1.0 but same dimensionality @@ -364,10 +368,10 @@ def broadcast_other_transport(technologies) -> Quantity: # Produce MESSAGE parameter input:nl-t-yv-ya-m-no-c-l-h-ho kw["dims"].update(commodity="c", node_origin="n", year_vtg="y") kw["common"].update(level="final", time_origin="year") - k_input = Key("input::transport other+ixmp") + k_input = Key(f"input{Oi}") c.add(k_input, "as_message_df", k_cnty.prev, name=k_input.name, **kw) - result = Key("transport other::ixmp") + result = Key(f"transport{Oi}") c.add(result, "merge_data", k_bal, k_bau, k_input) return [result]