Skip to content

Commit

Permalink
Improve .ssp.transport
Browse files Browse the repository at this point in the history
- aviation_share(): use coordinates from a reference quantity; document.
- Correct "Emission|" → "Emissions|" in generated variable names.
- Renumber KeySeq references.
  • Loading branch information
khaeru committed Oct 2, 2024
1 parent c2b674c commit 755138c
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions message_ix_models/project/ssp/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,28 @@

from genno.types import AnyQuantity

# TODO Retrieve from a package data code list
EMISSION = "BC CH4 CO CO2 N2O NH3 NOx OC Sulfur VOC".split()


def aviation_share() -> "AnyQuantity":
def aviation_share(ref: "AnyQuantity") -> "AnyQuantity":
"""Return (dummy) data for the share of aviation in emissions.
Currently this returns exactly the value `0.2`.
Parameters
----------
ref :
Reference quantity. The dimensions and coordinates :math:`(n, e, y)` of the
returned value exactly match `ref`.
Returns
-------
genno.Quantity
with dimensions :math:`(n, e, y)`.
"""
return (
genno.Quantity(0.2, units="dimensionless")
.expand_dims({"e": EMISSION}) # Full list
.expand_dims({"n": ["CHN", "NAM"]}) # Test data specimen
.expand_dims({"y": list(range(1990, 2110 + 1))}) # Crudely cover the full list
.expand_dims({"e": sorted(ref.coords["e"].data)})
.expand_dims({"n": sorted(ref.coords["n"].data)})
.expand_dims({"y": sorted(ref.coords["y"].data)})
)


Expand Down Expand Up @@ -69,7 +74,7 @@ def _expand(qty):
.reset_index()
.assign(
Variable=lambda df: (
"Emission|" + df["e"] + "|Energy|Demand|Transportation|" + df["t"]
"Emissions|" + df["e"] + "|Energy|Demand|Transportation|" + df["t"]
).str.replace("|_T", "")
)
.drop(["e", "t"], axis=1)
Expand Down Expand Up @@ -213,7 +218,7 @@ def main(path_in: "pathlib.Path", path_out: "pathlib.Path"):
# Share from aviation
# TODO Compute this using an emission factor and the energy use totals
k_share = genno.Key("AIR emission share", tuple("eny"))
c.add(k_share, aviation_share)
c.add(k_share, aviation_share, k[2] / "t")

# Product of the total and aviation share → aviation emissions
c.add(k[3] / t, "mul", k[2] / t, k_share)
Expand All @@ -234,10 +239,10 @@ def main(path_in: "pathlib.Path", path_out: "pathlib.Path"):
},
),
)
c.add(k[5], "mul", k[3] / t, "broadcast:t:AIR emissions")
c.add(k[4], "mul", k[3] / t, "broadcast:t:AIR emissions")

# Add to the input data
c.add(k[6], "add", k[1], k[5])
c.add(k[5], "add", k[1], k[4])

# - Collapse to IAMC "VARIABLE" dimension name
# - Recombine with other data
Expand All @@ -246,10 +251,11 @@ def main(path_in: "pathlib.Path", path_out: "pathlib.Path"):
"target",
finalize,
k_input,
k[6],
k[5],
"model name",
"scenario name",
path_out=path_out,
)

# Execute
c.get("target")

0 comments on commit 755138c

Please sign in to comment.