Skip to content

Commit 2df36dc

Browse files
committed
Remove .util.sdmx.make_dataflow()
…by merging functionality with Dataflow.__init__(). - Add Dataflow(module, …, i_o) arguments, Dataflow.FLAGS, Dataflow.intent. - Use shorthand functions in .transport.{data,files}. - Add .util.sdmx.{collect_structures,get}().
1 parent 59e65f0 commit 2df36dc

File tree

8 files changed

+354
-303
lines changed

8 files changed

+354
-303
lines changed

message_ix_models/model/transport/build.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -245,14 +245,15 @@ def add_exogenous_data(c: Computer, info: ScenarioInfo) -> None:
245245

246246
# Identify the mode-share file according to the config setting
247247
Dataflow(
248+
module=__name__,
248249
key="mode share:n-t:exo",
249250
path=("mode-share", config.mode_share),
250251
name="Reference (base year) mode share",
251252
units="dimensionless",
252253
replace=True,
253254
)
254255

255-
for _, f in iter_files():
256+
for _, f in filter(lambda x: x[1].intent & Dataflow.FLAG.IN, iter_files()):
256257
c.add("", f, context=context)
257258

258259

message_ix_models/model/transport/data.py

+42
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
same_node,
2828
)
2929
from message_ix_models.util.ixmp import rename_dims
30+
from message_ix_models.util.sdmx import Dataflow
31+
32+
from .files import common_structures
3033

3134
if TYPE_CHECKING:
3235
from sdmx.model.v21 import Code
@@ -409,3 +412,42 @@ class MERtoPPP(MaybeAdaptR11Source):
409412
register_source(cls) # type: ignore [type-abstract]
410413
except ValueError as e:
411414
log.info(str(e))
415+
416+
417+
# Output data flows for reporting
418+
419+
420+
def _make_dataflow(**kwargs) -> "Dataflow":
421+
"""Shorthand for data flows from this module."""
422+
common_structures() # Ensure CS_MESSAGE_TRANSPORT exists
423+
424+
kwargs.setdefault("module", __name__)
425+
kwargs.setdefault("units", "dimensionless") # FIXME Look up the correct units
426+
kwargs.setdefault("i_o", Dataflow.FLAG.OUT)
427+
desc = kwargs.setdefault("description", "")
428+
kwargs["description"] = f"{desc.strip()}\n\nOutput data from MESSAGEix-Transport."
429+
kwargs.setdefault("cs_urn", ("ConceptScheme=IIASA_ECE:CS_MESSAGE_TRANSPORT",))
430+
431+
return Dataflow(**kwargs)
432+
433+
434+
activity_passenger = _make_dataflow(
435+
id="ACTIVITY_PASSENGER",
436+
name="Passenger activity",
437+
key="pdt:n-y-t",
438+
units="dimensionless",
439+
)
440+
activity_vehicle = _make_dataflow(
441+
id="ACTIVITY_VEHICLE",
442+
name="Vehicle activity",
443+
description='Same as "Energy Service|Transportation" IAMC variable.',
444+
key="out:nl-t-ya-c:transport+units",
445+
)
446+
fe_transport = _make_dataflow(
447+
id="FE_TRANSPORT",
448+
name="Final energy",
449+
description='Same as "Final Energy|Transportation" IAMC variable.',
450+
key="in:nl-t-ya-c:transport+units",
451+
)
452+
gdp_in = _make_dataflow(id="GDP_IN", name="GDP", key="gdp:n-y")
453+
population_in = _make_dataflow(id="POPULATION_IN", name="Population", key="pop:n-y")

0 commit comments

Comments
 (0)