Skip to content

Commit 8c75ab0

Browse files
khaeruglatterf42
authored andcommitted
Adjust units, order of LED PDT per capita
- Set up full calculation first, then replace/truncate. - Add a test case and expand checks. - Relax expectation that .transport.Config.project(navigate=…) is present.
1 parent 32e0a5b commit 8c75ab0

File tree

5 files changed

+23
-13
lines changed

5 files changed

+23
-13
lines changed

message_ix_models/data/transport/R12/pdt-cap.csv

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Projected passenger-distance travelled (PDT) per capita
22
#
3-
# Units: km / passenger
3+
# Units: km / year
44
#
55
scenario, node, technology, year, value
66
LED, R12_AFR, 2W, 2020, 360

message_ix_models/model/transport/demand.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -316,14 +316,22 @@ def prepare_computer(c: Computer) -> None:
316316

317317
config: "Config" = c.graph["context"].transport
318318

319-
if config.project.get("LED", False):
320-
# Select from the file input
321-
c.add(pdt_cap, "select", exo.pdt_cap_proj, indexers=dict(scenario="LED"))
322-
else:
323-
c.apply(pdt_per_capita)
319+
# Compute total PDT per capita
320+
c.apply(pdt_per_capita)
324321

325322
# Insert a scaling factor that varies according to SSP setting
326323
c.apply(factor.insert, pdt_cap, name="pdt non-active", target=pdt_cap + "adj")
327324

325+
# Add other tasks for demand calculation
328326
c.add_queue(TASKS)
327+
328+
if config.project.get("LED", False):
329+
# Replace certain calculations for LED projected activity
330+
331+
# Select data from input file: projected PDT per capita
332+
c.add(pdt_cap * "t", "select", exo.pdt_cap_proj, indexers=dict(scenario="LED"))
333+
334+
# Multiply by population for the total
335+
c.add(pdt_nyt + "0", "mul", pdt_cap * "t", pop)
336+
329337
c.add("transport_data", __name__, key="transport demand::ixmp")

message_ix_models/model/transport/files.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ def read_structures() -> "sdmx.message.StructureMessage":
329329
key="P activity:scenario-n-t-y:exo",
330330
path="pdt-cap",
331331
name="Projected passenger-distance travelled (PDT) per capita",
332-
units="km / passenger / year",
332+
units="km / year",
333333
required=False,
334334
)
335335

message_ix_models/model/transport/operator.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ def factor_fv(n: list[str], y: list[int], config: dict) -> "AnyQuantity":
493493
df.iloc[0, :] = 1.0
494494

495495
# NAVIGATE T3.5 "act" demand-side scenario
496-
if T35_POLICY.ACT & config["transport"].project["navigate"]:
496+
if T35_POLICY.ACT & config["transport"].project.get("navigate", T35_POLICY.REF):
497497
years = list(filter(lambda y: y <= 2050, y))
498498
df.loc[years, "value"] = np.interp(years, [y[0], 2050], [1.0, 0.865])
499499

@@ -540,7 +540,7 @@ def _not_disutility(tech):
540540
df.iloc[0, :] = 1.0
541541

542542
# NAVIGATE T3.5 "tec" demand-side scenario
543-
if T35_POLICY.TEC & config["transport"].project["navigate"]:
543+
if T35_POLICY.TEC & config["transport"].project.get("navigate", T35_POLICY.REF):
544544
years = list(filter(partial(gt, 2050), df.index))
545545

546546
# Prepare a dictionary mapping technologies to their respective EI improvement
@@ -586,7 +586,7 @@ def factor_pdt(n: list[str], y: list[int], t: list[str], config: dict) -> "AnyQu
586586
df.iloc[0, :] = 1.0
587587

588588
# Handle particular scenarios
589-
if T35_POLICY.ACT & config["transport"].project["navigate"]:
589+
if T35_POLICY.ACT & config["transport"].project.get("navigate", T35_POLICY.REF):
590590
# NAVIGATE T3.5 "act" demand-side scenario
591591
years = list(filter(lambda y: y <= 2050, y))
592592
df.loc[years, "LDV"] = np.interp(years, [y[0], 2050], [1.0, 0.8])

message_ix_models/tests/model/transport/test_build.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,7 @@ def test_build_existing(tmp_path, test_context, url, solve=False):
232232
"votm:n-y": (HasUnits(""),),
233233
key.price.base: (HasUnits("USD / km"),),
234234
"cost:n-y-c-t": (HasUnits("USD / km"),),
235-
# These units are implied by the test of "transport pdt:*":
236-
# "transport pdt:n-y:total" [=] Mm / year
235+
demand.pdt_nyt + "0": (HasUnits("passenger km / year"),),
237236
demand.pdt_nyt + "1": (HasUnits("passenger km / year"),),
238237
demand.ldv_ny + "total": (HasUnits("Gp km / a"),),
239238
# FIXME Handle dimensionality instead of exact units
@@ -292,6 +291,7 @@ def test_build_existing(tmp_path, test_context, url, solve=False):
292291
dict(regions="R11", years="B", options=dict(futures_scenario="debug")),
293292
dict(regions="R12", years="B"),
294293
dict(regions="R12", years="B", options=dict(navigate_scenario="act+ele+tec")),
294+
dict(regions="R12", years="B", options=dict(project={"LED": True})),
295295
param(dict(regions="R14", years="B"), marks=MARK[9]),
296296
param(dict(regions="ISR", years="A"), marks=MARK[3]),
297297
),
@@ -320,8 +320,10 @@ def test_debug(
320320
k = "test_debug"
321321
result = insert_checks(c, k, CHECKS, common)
322322

323+
# Show and get a different key
324+
# k = key.pdt_cny
325+
323326
# Show what will be computed
324-
# k = "pdt:n-y:capita+adj+ssp factor"
325327
if verbosity:
326328
print(c.describe(k))
327329

0 commit comments

Comments
 (0)