6
6
import genno
7
7
import numpy as np
8
8
import pandas as pd
9
- from dask .core import literal
10
- from genno import Computer , KeySeq
9
+ from genno import Key , literal
11
10
from message_ix import make_df
12
11
13
12
from message_ix_models .report .key import GDP
14
13
from message_ix_models .util import broadcast
15
14
15
+ from . import factor
16
16
from .key import (
17
17
cg ,
18
18
cost ,
36
36
)
37
37
38
38
if TYPE_CHECKING :
39
+ from genno import Computer
39
40
from genno .types import AnyQuantity
40
41
41
42
from .config import Config
@@ -136,15 +137,15 @@ def dummy(
136
137
# Mode shares
137
138
((ms , "logit" , cost , sw , "lambda:" , y ), dict (dim = "t" )),
138
139
# Total PDT (n, t, y), with modes for the 't' dimension
139
- (pdt_nyt + "0" , "mul" , pdt_ny , ms ),
140
+ (pdt_nyt [ 0 ] , "mul" , pdt_ny , ms ),
140
141
# Scenario-specific adjustment factors
141
142
("pdt factor:n-y-t" , "factor_pdt" , n , y , t_modes , "config" ),
142
143
# Only the LDV values
143
144
(
144
145
("ldv pdt factor:n-y" , "select" , "pdt factor:n-y-t" ),
145
146
dict (indexers = dict (t = "LDV" ), drop = True ),
146
147
),
147
- (pdt_nyt , "mul" , pdt_nyt + "0" , "pdt factor:n-y-t" ),
148
+ (pdt_nyt , "mul" , pdt_nyt [ 0 ] , "pdt factor:n-y-t" ),
148
149
# Per capita (for validation)
149
150
(pdt_nyt + "capita+post" , "div" , pdt_nyt , pop ),
150
151
# LDV PDT only (n, y)
@@ -163,18 +164,18 @@ def dummy(
163
164
# LDV PDT shared out by consumer group (cg, n, y)
164
165
(ldv_nycg , "mul" , ldv_ny + "total" , cg ),
165
166
# Select only non-LDV PDT
166
- ((pdt_nyt + "1" , "select" , pdt_nyt ), dict (indexers = dict (t = ["LDV" ]), inverse = True )),
167
+ ((pdt_nyt [ 1 ] , "select" , pdt_nyt ), dict (indexers = dict (t = ["LDV" ]), inverse = True )),
167
168
# Relabel PDT
168
169
(
169
- (pdt_cny + "0" , "relabel2" , pdt_nyt + "1" ),
170
+ (pdt_cny [ 0 ] , "relabel2" , pdt_nyt [ 1 ] ),
170
171
dict (new_dims = {"c" : "transport pax {t.lower()}" }),
171
172
),
172
- (pdt_cny , "convert_units" , pdt_cny + "0" , "Gp km / a" ),
173
+ (pdt_cny , "convert_units" , pdt_cny [ 0 ] , "Gp km / a" ),
173
174
# Convert to ixmp format
174
175
(("demand::P+ixmp" , "as_message_df" , pdt_cny ), _DEMAND_KW ),
175
176
# Relabel ldv pdt:n-y-cg
176
- ((ldv_cny + "0" , "relabel2" , ldv_nycg ), dict (new_dims = {"c" : "transport pax {cg}" })),
177
- (ldv_cny , "convert_units" , ldv_cny + "0" , "Gp km / a" ),
177
+ ((ldv_cny [ 0 ] , "relabel2" , ldv_nycg ), dict (new_dims = {"c" : "transport pax {cg}" })),
178
+ (ldv_cny , "convert_units" , ldv_cny [ 0 ] , "Gp km / a" ),
178
179
(("demand::LDV+ixmp" , "as_message_df" , ldv_cny ), _DEMAND_KW ),
179
180
# Dummy demands, if these are configured
180
181
("demand::dummy+ixmp" , dummy , "c::transport" , "nodes::ex world" , y , "config" ),
@@ -189,7 +190,7 @@ def dummy(
189
190
]
190
191
191
192
192
- def pdt_per_capita (c : Computer ) -> None :
193
+ def pdt_per_capita (c : " Computer" ) -> None :
193
194
"""Set up calculation of :data:`~.key.pdt_cap`.
194
195
195
196
Per Schäfer et al. (2009) Figure 2.5: linear interpolation between log GDP PPP per
@@ -202,12 +203,12 @@ def pdt_per_capita(c: Computer) -> None:
202
203
between projected, log GDP in each future period and the log GDP in the reference
203
204
year.
204
205
"""
205
- gdp = KeySeq (GDP )
206
- pdt = KeySeq ("_pdt:n-y" )
206
+ gdp = Key (GDP )
207
+ pdt = Key ("_pdt:n-y" )
207
208
208
209
# GDP expressed in PPP. In the SSP(2024) input files, this conversion is already
209
210
# applied, so no need to multiply by a mer_to_ppp factor here → simple alias.
210
- c .add (gdp ["PPP" ], gdp . base )
211
+ c .add (gdp ["PPP" ], gdp )
211
212
212
213
# GDP PPP per capita
213
214
c .add (gdp ["capita" ], "div" , gdp ["PPP" ], pop )
@@ -229,7 +230,7 @@ def _delta(qty: "AnyQuantity", y0: int) -> "AnyQuantity":
229
230
# Same transformation for both quantities
230
231
for x , reference_values in ((gdp , gdp ["capita" ]), (pdt , pdt ["ref" ])):
231
232
# Retrieve value from configuration
232
- k = KeySeq ( f" { x .name } :: fixed" )
233
+ k = Key ( x .name , (), " fixed" )
233
234
c .add (k [0 ], "quantity_from_config" , "config" , name = f"fixed_{ x .name .strip ('_' )} " )
234
235
# Broadcast on `n` dimension
235
236
c .add (k [1 ] * "n" , "mul" , k [0 ], "n:n:ex world" )
@@ -286,15 +287,13 @@ def _delta(qty: "AnyQuantity", y0: int) -> "AnyQuantity":
286
287
c .add (gdp_cap + "adj" , gdp [6 ])
287
288
288
289
289
- def prepare_computer (c : Computer ) -> None :
290
+ def prepare_computer (c : " Computer" ) -> None :
290
291
"""Prepare `c` to calculate and add transport demand data.
291
292
292
293
See also
293
294
--------
294
295
TASKS
295
296
"""
296
- from . import factor
297
-
298
297
config : "Config" = c .graph ["context" ].transport
299
298
300
299
# Compute total PDT per capita
@@ -313,6 +312,6 @@ def prepare_computer(c: Computer) -> None:
313
312
c .add (pdt_cap * "t" , "select" , exo .pdt_cap_proj , indexers = dict (scenario = "LED" ))
314
313
315
314
# Multiply by population for the total
316
- c .add (pdt_nyt + "0" , "mul" , pdt_cap * "t" , pop )
315
+ c .add (pdt_nyt [ 0 ] , "mul" , pdt_cap * "t" , pop )
317
316
318
317
c .add ("transport_data" , __name__ , key = "transport demand::ixmp" )
0 commit comments