@@ -265,6 +265,7 @@ def get_computer(
265
265
context = Context (model = ModelConfig (regions = "R12" ))
266
266
# Store in `c` for reference by other operations
267
267
c .add ("context" , context )
268
+ c .graph ["config" ].update (regions = "R12" )
268
269
269
270
# Store a model name and scenario name from a single row of the data
270
271
model_name , scenario_name = row0 [["Model" , "Scenario" ]]
@@ -413,11 +414,15 @@ def method_B(c: "Computer") -> None:
413
414
c .add (fe .iea [1 ], "aggregate" , fe .iea [0 ], g , keep = False )
414
415
415
416
# Rename dimensions
416
- c .add (fe .cnt , "rename_dims" , fe .iea [1 ], name_dict = dict (flow = "t" , product = "c" ))
417
+ c .add (fe .cnt [ 0 ] , "rename_dims" , fe .iea [1 ], name_dict = dict (flow = "t" , product = "c" ))
417
418
418
- # Compute ratio
419
- c .add (fe .share [0 ], "select" , fe .cnt , indexers = dict (t = "_1" ), drop = True )
420
- c .add (fe .share [1 ], "select" , fe .cnt , indexers = dict (t = "_2" ), drop = True )
419
+ # Global total
420
+ c .add ("n::world agg" , "nodes_world_agg" , "config" , dim = "n" , name = None )
421
+ c .add (fe .cnt [1 ], "aggregate" , fe .cnt [0 ], "n::world agg" , keep = False )
422
+
423
+ # Ratio of _1 (DOMESAIR - AVBUNK) to _2 (TOTTRANS - AVBUNK)
424
+ c .add (fe .share [0 ], "select" , fe .cnt [1 ], indexers = dict (t = "_1" ), drop = True )
425
+ c .add (fe .share [1 ], "select" , fe .cnt [1 ], indexers = dict (t = "_2" ), drop = True )
421
426
c .add (fe .share , "div" , fe .share [0 ], fe .share [1 ])
422
427
423
428
# Prepare remaining calculations
@@ -467,11 +472,11 @@ def method_BC_common(c: "Computer", k_fe_share: "Key") -> None:
467
472
468
473
# Relabel:
469
474
# - c[ommodity]: 'Liquids|Oil' (IAMC 'variable' component) → 'lightoil'
470
- # - n[ode]: ' AFR' → ' R12_AFR' etc.
471
- labels = dict (
472
- c = {"Liquids|Oil" : "lightoil" },
473
- n = { n . id . partition ( "_" )[ 2 ]: n .id for n in get_codelist ( "node/R12" )},
474
- )
475
+ # - n[ode]: " AFR" → " R12_AFR" etc. "World" is not changed .
476
+ cl = get_codelist ( "node/R12" )
477
+ labels = dict ( c = {"Liquids|Oil" : "lightoil" }, n = {})
478
+ for n in filter ( lambda n : len ( n . child ) and n .id != "World" , cl ):
479
+ labels [ "n" ][ n . id . partition ( "_" )[ 2 ]] = n . id
475
480
c .add (k .fe_in [2 ] / "UNIT" , "relabel" , k .fe_in [1 ] / "UNIT" , labels = labels )
476
481
477
482
### Compute estimate of emissions
@@ -496,7 +501,7 @@ def method_BC_common(c: "Computer", k_fe_share: "Key") -> None:
496
501
c .add (k .units , e_UNIT , "e::codelist" )
497
502
c .add (K .emi [2 ], "mul" , k .emi0 [1 ], k .units , K .bcast )
498
503
499
- # Change labels: restore e.g. "AFR" given "R12_AFR"
504
+ # Restore labels: "R12_AFR" → "AFR" etc. "World" is not changed.
500
505
labels = dict (n = {v : k for k , v in labels ["n" ].items ()})
501
506
c .add (K .emi , "relabel" , K .emi [2 ], labels = labels )
502
507
@@ -527,15 +532,20 @@ def method_C(c: "Computer") -> None:
527
532
# Prepare `c` to compute the final energy share for aviation
528
533
k = Keys (
529
534
# Added by .transport.base.prepare_reporter()
530
- base = "in:nl-t-ya-c:transport+units+0 " ,
535
+ base = "in:nl-t-ya-c:transport+units" ,
531
536
share0 = f"fe share:c-nl-ya:{ L } " ,
532
537
share1 = f"fe share:c-n-y:{ L } " ,
533
538
)
534
539
540
+ # Relabel "R12_GLB" (added by .report.transport.aggregate()) to "World"
541
+ labels = {"nl" : {"R12_GLB" : "World" }}
542
+ c .add (k .base [1 ], "relabel" , k .base [0 ], labels = labels , sums = True )
543
+
535
544
# Select the numerator
536
- c .add (k .share0 ["num" ], "select" , k .base , indexers = dict (t = ["AIR" ]), drop = True )
537
- # Compute the ratio
538
- c .add (k .share0 , "div" , k .share0 ["num" ], k .base / "t" )
545
+ c .add (k .share0 ["num" ], "select" , k .base [1 ], indexers = dict (t = ["AIR" ]), drop = True )
546
+ # Ratio of AIR to the total
547
+ c .add (k .share0 , "div" , k .share0 ["num" ], k .base [1 ] / "t" )
548
+
539
549
# Rename dimensions as expected by method_BC_common
540
550
c .add (k .share1 , "rename_dims" , k .share0 , name_dict = {"nl" : "n" , "ya" : "y" })
541
551
@@ -559,8 +569,18 @@ def process_df(
559
569
# Prepare all other tasks
560
570
c = get_computer (data .iloc [0 , :], method , platform_name = platform_name )
561
571
562
- # Input data: convert `data` to a Quantity with the appropriate structure
563
- c .add (K .input , to_quantity , data , ** IAMC_KW )
572
+ def fillna (df : pd .DataFrame ) -> pd .DataFrame :
573
+ """Replace :py:`np.nan` with 0.0 in certain rows and columns."""
574
+ mask = df .Variable .str .fullmatch (
575
+ r"Emissions\|[^\|]+\|Energy\|Demand\|(Bunkers|Transportation).*"
576
+ )
577
+ to_fill = {c : 0.0 for c in df .columns if str (c ).isnumeric () and int (c ) >= 2020 }
578
+ return df .where (~ mask , df .fillna (to_fill ))
579
+
580
+ # Input data: replace NaN with 0
581
+ c .add (K .input [0 ], fillna , data )
582
+ # Convert `data` to a Quantity with the appropriate structure
583
+ c .add (K .input , to_quantity , K .input [0 ], ** IAMC_KW )
564
584
565
585
# Compute and return the result
566
586
return c .get ("target" )
0 commit comments