Skip to content

Commit

Permalink
Align keys in .transport.{freight,non_ldv} with .ldv
Browse files Browse the repository at this point in the history
  • Loading branch information
khaeru committed Dec 4, 2024
1 parent 230f1a4 commit dc6d805
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
11 changes: 7 additions & 4 deletions message_ix_models/model/transport/freight.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
level="l",
)

#: Shorthand for tags on keys
Fi = "::F+ixmp"

Check warning on line 30 in message_ix_models/model/transport/freight.py

View check run for this annotation

Codecov / codecov/patch

message_ix_models/model/transport/freight.py#L30

Added line #L30 was not covered by tests


def prepare_computer(c: genno.Computer):
from genno.core.attrseries import AttrSeries
Expand All @@ -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}")

Check warning on line 53 in message_ix_models/model/transport/freight.py

View check run for this annotation

Codecov / codecov/patch

message_ix_models/model/transport/freight.py#L53

Added line #L53 was not covered by tests
c.add(to_add[-1], convert_units, k[2], "transport info")

# Extract the 'input' data frame
Expand Down Expand Up @@ -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}")

Check warning on line 106 in message_ix_models/model/transport/freight.py

View check run for this annotation

Codecov / codecov/patch

message_ix_models/model/transport/freight.py#L106

Added line #L106 was not covered by tests
c.add(to_add[-1], same_node, k[5])

# Base values for conversion technologies
Expand All @@ -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}")

Check warning on line 122 in message_ix_models/model/transport/freight.py

View check run for this annotation

Codecov / codecov/patch

message_ix_models/model/transport/freight.py#L122

Added line #L122 was not covered by tests
c.add(to_add[-1], lambda v: same_time(same_node(v)), k[10])

# Create corresponding input values in Gv km
Expand All @@ -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}")

Check warning on line 139 in message_ix_models/model/transport/freight.py

View check run for this annotation

Codecov / codecov/patch

message_ix_models/model/transport/freight.py#L139

Added line #L139 was not covered by tests
c.add(to_add[-1], prev)

# Merge data to one collection
Expand Down
20 changes: 12 additions & 8 deletions message_ix_models/model/transport/non_ldv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}"

Check warning on line 91 in message_ix_models/model/transport/non_ldv.py

View check run for this annotation

Codecov / codecov/patch

message_ix_models/model/transport/non_ldv.py#L91

Added line #L91 was not covered by tests
keys.append(k_usage)
c.add(k_usage, usage_data, exo.load_factor_nonldv, t_modes, n, y)

Expand Down Expand Up @@ -122,15 +126,15 @@ 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}"

Check warning on line 129 in message_ix_models/model/transport/non_ldv.py

View check run for this annotation

Codecov / codecov/patch

message_ix_models/model/transport/non_ldv.py#L129

Added line #L129 was not covered by tests
keys.append(k_constraint)
c.add(k_constraint, constraint_data, "t::transport", t_modes, n, y, "config")

# Add other constraints on activity of non-LDV technologies
keys.extend(bound_activity(c))

# Add to the scenario
k_all = "transport nonldv::ixmp"
k_all = f"transport{Pi}"

Check warning on line 137 in message_ix_models/model/transport/non_ldv.py

View check run for this annotation

Codecov / codecov/patch

message_ix_models/model/transport/non_ldv.py#L137

Added line #L137 was not covered by tests
c.add(k_all, "merge_data", *keys)
c.add("transport_data", __name__, key=k_all)

Expand Down Expand Up @@ -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}")

Check warning on line 195 in message_ix_models/model/transport/non_ldv.py

View check run for this annotation

Codecov / codecov/patch

message_ix_models/model/transport/non_ldv.py#L195

Added line #L195 was not covered by tests
c.add(k_bau, "as_message_df", base, name=k_bau.name, **kw)

return [k_bau]
Expand Down Expand Up @@ -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}")

Check warning on line 358 in message_ix_models/model/transport/non_ldv.py

View check run for this annotation

Codecov / codecov/patch

message_ix_models/model/transport/non_ldv.py#L358

Added line #L358 was not covered by tests
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}")

Check warning on line 360 in message_ix_models/model/transport/non_ldv.py

View check run for this annotation

Codecov / codecov/patch

message_ix_models/model/transport/non_ldv.py#L360

Added line #L360 was not covered by tests
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
Expand All @@ -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}")

Check warning on line 371 in message_ix_models/model/transport/non_ldv.py

View check run for this annotation

Codecov / codecov/patch

message_ix_models/model/transport/non_ldv.py#L371

Added line #L371 was not covered by tests
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}")

Check warning on line 374 in message_ix_models/model/transport/non_ldv.py

View check run for this annotation

Codecov / codecov/patch

message_ix_models/model/transport/non_ldv.py#L374

Added line #L374 was not covered by tests
c.add(result, "merge_data", k_bal, k_bau, k_input)
return [result]

Expand Down

0 comments on commit dc6d805

Please sign in to comment.