forked from IndEcol/RECC-ODYM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ODYM_RECC_Main.py
3637 lines (3236 loc) · 359 KB
/
ODYM_RECC_Main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
"""
Created on February 21, 2020, as copy of ODYM_RECC_V2_3.py
@authors: spauliuk
"""
"""
File ODYM_RECC_Main.py
Contains the ODYM-RECC model v 2.5 for the resource efficiency climate change mitigation nexus
Model version 2_5: Global coverage of five sectors.
passenger vehicles, residential buildings, non-residential buildings, electricity generation, and appliances.
dependencies:
numpy >= 1.9
scipy >= 0.14
"""
#def main():
# Import required libraries:
import os
import sys
import logging as log
import openpyxl
import numpy as np
import time
import datetime
#import scipy.io
import pandas as pd
import shutil
import uuid
import matplotlib.pyplot as plt
from matplotlib.lines import Line2D
import importlib
import getpass
from copy import deepcopy
from tqdm import tqdm
import scipy.stats
from scipy.interpolate import interp1d
from scipy.interpolate import make_interp_spline
import pylab
import pickle
import RECC_Paths # Import path file
log.getLogger('matplotlib.font_manager').disabled = True # required for preventing debugging messages in some console versions
#import re
__version__ = str('2.5')
##################################
# Section 1) Initialize #
##################################
# add ODYM module directory to system path
sys.path.insert(0, os.path.join(os.path.join(RECC_Paths.odym_path,'odym'),'modules'))
### 1.1.) Read main script parameters
# Mylog.info('### 1.1 - Read main script parameters')
ProjectSpecs_Name_ConFile = 'RECC_Config.xlsx'
Model_Configfile = openpyxl.load_workbook(os.path.join(RECC_Paths.data_path,ProjectSpecs_Name_ConFile), data_only=True)
ScriptConfig = {'Model Setting': Model_Configfile['Cover'].cell(4,4).value}
Model_Configsheet = Model_Configfile[ScriptConfig['Model Setting']]
#Read debug modus:
DebugCounter = 0
while Model_Configsheet.cell(DebugCounter+1, 3).value != 'Logging_Verbosity':
DebugCounter += 1
ScriptConfig['Logging_Verbosity'] = Model_Configsheet.cell(DebugCounter+1,4).value # Read loggin verbosity once entry was reached.
# Extract user name from main file
ProjectSpecs_User_Name = getpass.getuser()
# import packages whose location is now on the system path:
import ODYM_Classes as msc # import the ODYM class file
importlib.reload(msc)
import ODYM_Functions as msf # import the ODYM function file
importlib.reload(msf)
import dynamic_stock_model as dsm # import the dynamic stock model library
importlib.reload(dsm)
Name_Script = Model_Configsheet.cell(6,4).value
if Name_Script != 'ODYM_RECC_Main': # Name of this script must equal the specified name in the Excel config file
raise AssertionError('Fatal: The name of the current script does not match to the sript name specfied in the project configuration file. Exiting the script.')
# the model will terminate if the name of the script that is run is not identical to the script name specified in the config file.
Name_Scenario = Model_Configsheet.cell(7,4).value # Regional scope as torso for scenario name
StartTime = datetime.datetime.now()
TimeString = str(StartTime.year) + '_' + str(StartTime.month) + '_' + str(StartTime.day) + '__' + str(StartTime.hour) + '_' + str(StartTime.minute) + '_' + str(StartTime.second)
#DateString = str(StartTime.year) + '_' + str(StartTime.month) + '_' + str(StartTime.day)
ProjectSpecs_Path_Result = os.path.join(RECC_Paths.results_path, Name_Scenario + '__' + TimeString )
if not os.path.exists(ProjectSpecs_Path_Result): # Create model run results directory.
os.makedirs(ProjectSpecs_Path_Result)
# Initialize logger
if ScriptConfig['Logging_Verbosity'] == 'DEBUG':
log_verbosity = eval("log.DEBUG")
log_filename = Name_Scenario + '__' + TimeString + '.md'
[Mylog, console_log, file_log] = msf.function_logger(log_filename, ProjectSpecs_Path_Result,
log_verbosity, log_verbosity)
# log header and general information
Time_Start = time.time()
ScriptConfig['Current_UUID'] = str(uuid.uuid4())
Mylog.info('# Simulation from ' + time.asctime())
Mylog.info('Unique ID of scenario run: ' + ScriptConfig['Current_UUID'])
### 1.2) Read model control parameters
Mylog.info('### 1.2 - Read model control parameters')
#Read control and selection parameters into dictionary
ScriptConfig = msf.ParseModelControl(Model_Configsheet,ScriptConfig)
Mylog.info('Script: ' + Name_Script + '.py')
Mylog.info('Model script version: ' + __version__)
Mylog.info('Model functions version: ' + msf.__version__())
Mylog.info('Model classes version: ' + msc.__version__())
Mylog.info('Current User: ' + ProjectSpecs_User_Name)
Mylog.info('Current Scenario: ' + Name_Scenario)
Mylog.info(ScriptConfig['Description'])
Mylog.debug('----\n')
### 1.3) Organize model output folder and logger
Mylog.info('### 1.3 Organize model output folder and logger')
#Copy Config file and model script into that folder
shutil.copy(os.path.join(RECC_Paths.data_path,ProjectSpecs_Name_ConFile), os.path.join(ProjectSpecs_Path_Result, ProjectSpecs_Name_ConFile))
#shutil.copy(Name_Script + '.py' , os.path.join(ProjectSpecs_Path_Result, Name_Script + '.py'))
#####################################################
# Section 2) Read classifications and data #
#####################################################
Mylog.info('## 2 - Read classification items and define all classifications')
### 2.1) # Read model run config data
Mylog.info('### 2.1 - Read model run config data')
# Note: This part reads the items directly from the Exel master,
# will be replaced by reading them from version-managed csv file.
class_filename = str(ScriptConfig['Version of master classification']) + '.xlsx'
Classfile = openpyxl.load_workbook(os.path.join(RECC_Paths.data_path,class_filename), data_only=True)
Classsheet = Classfile['MAIN_Table']
MasterClassification = msf.ParseClassificationFile_Main(Classsheet,Mylog)
Mylog.info('Read and parse config table, including the model index table, from model config sheet.')
IT_Aspects,IT_Description,IT_Dimension,IT_Classification,IT_Selector,IT_IndexLetter,PL_Names,PL_Description,PL_Version,PL_IndexStructure,PL_IndexMatch,PL_IndexLayer,PrL_Number,PrL_Name,PrL_Comment,PrL_Type,ScriptConfig = msf.ParseConfigFile(Model_Configsheet,ScriptConfig,Mylog)
Mylog.info('Define model classifications and select items for model classifications according to information provided by config file.')
ModelClassification = {} # Dict of model classifications
for m in range(0,len(IT_Aspects)):
ModelClassification[IT_Aspects[m]] = deepcopy(MasterClassification[IT_Classification[m]])
EvalString = msf.EvalItemSelectString(IT_Selector[m],len(ModelClassification[IT_Aspects[m]].Items))
if EvalString.find(':') > -1: # range of items is taken
RangeStart = int(EvalString[0:EvalString.find(':')])
RangeStop = int(EvalString[EvalString.find(':')+1::])
ModelClassification[IT_Aspects[m]].Items = ModelClassification[IT_Aspects[m]].Items[RangeStart:RangeStop]
elif EvalString.find('[') > -1: # selected items are taken
ModelClassification[IT_Aspects[m]].Items = [ModelClassification[IT_Aspects[m]].Items[i] for i in eval(EvalString)]
elif EvalString == 'all':
None
else:
Mylog.error('Item select error for aspect ' + IT_Aspects[m] + ' were found in datafile.')
break
### 2.2) # Define model index table and parameter dictionary
Mylog.info('### 2.2 - Define model index table and parameter dictionary')
Model_Time_Start = int(min(ModelClassification['Time'].Items))
Model_Time_End = int(max(ModelClassification['Time'].Items))
Model_Duration = Model_Time_End - Model_Time_Start + 1
Mylog.info('Define index table dataframe.')
IndexTable = pd.DataFrame({'Aspect' : IT_Aspects, # 'Time' and 'Element' must be present!
'Description' : IT_Description,
'Dimension' : IT_Dimension,
'Classification': [ModelClassification[Aspect] for Aspect in IT_Aspects],
'IndexLetter' : IT_IndexLetter}) # Unique one letter (upper or lower case) indices to be used later for calculations.
# Default indexing of IndexTable, other indices are produced on the fly
IndexTable.set_index('Aspect', inplace=True)
# Add indexSize to IndexTable:
IndexTable['IndexSize'] = pd.Series([len(IndexTable.Classification[i].Items) for i in range(0, len(IndexTable.IndexLetter))],
index=IndexTable.index)
# list of the classifications used for each indexletter
IndexTable_ClassificationNames = [IndexTable.Classification[i].Name for i in range(0, len(IndexTable.IndexLetter))]
# 2.3) Define shortcuts for the most important index sizes:
Nt = len(IndexTable.Classification[IndexTable.index.get_loc('Time')].Items)
Ne = len(IndexTable.Classification[IndexTable.index.get_loc('Element')].Items)
Nc = len(IndexTable.Classification[IndexTable.index.get_loc('Cohort')].Items)
Nr = len(IndexTable.Classification[IndexTable.index.get_loc('Region32')].Items)
Nl = len(IndexTable.Classification[IndexTable.index.get_loc('Region11')].Items)
No = len(IndexTable.Classification[IndexTable.index.get_loc('Region1')].Items)
NG = len(IndexTable.Classification[IndexTable.set_index('IndexLetter').index.get_loc('G')].Items)
Ng = len(IndexTable.Classification[IndexTable.set_index('IndexLetter').index.get_loc('g')].Items)
Np = len(IndexTable.Classification[IndexTable.set_index('IndexLetter').index.get_loc('p')].Items)
NB = len(IndexTable.Classification[IndexTable.set_index('IndexLetter').index.get_loc('B')].Items)
NN = len(IndexTable.Classification[IndexTable.set_index('IndexLetter').index.get_loc('N')].Items) # varies: 24 for region-specific nrb and 4 for aggregated global resolution.
NI = len(IndexTable.Classification[IndexTable.set_index('IndexLetter').index.get_loc('I')].Items)
Na = len(IndexTable.Classification[IndexTable.set_index('IndexLetter').index.get_loc('a')].Items)
#NA = len(IndexTable.Classification[IndexTable.set_index('IndexLetter').index.get_loc('A')].Items)
NS = len(IndexTable.Classification[IndexTable.index.get_loc('Scenario')].Items)
NR = len(IndexTable.Classification[IndexTable.index.get_loc('Scenario_RCP')].Items)
Nw = len(IndexTable.Classification[IndexTable.index.get_loc('Waste_Scrap')].Items)
Nm = len(IndexTable.Classification[IndexTable.index.get_loc('Engineering materials')].Items)
NP = len(IndexTable.Classification[IndexTable.set_index('IndexLetter').index.get_loc('P')].Items)
NX = len(IndexTable.Classification[IndexTable.index.get_loc('Extensions')].Items)
Nx = len(IndexTable.Classification[IndexTable.set_index('IndexLetter').index.get_loc('x')].Items)
Nn = len(IndexTable.Classification[IndexTable.index.get_loc('Energy')].Items)
NV = len(IndexTable.Classification[IndexTable.set_index('IndexLetter').index.get_loc('V')].Items)
Ns = len(IndexTable.Classification[IndexTable.set_index('IndexLetter').index.get_loc('s')].Items)
#NT = len(IndexTable.Classification[IndexTable.set_index('IndexLetter').index.get_loc('T')].Items)
NL = len(IndexTable.Classification[IndexTable.set_index('IndexLetter').index.get_loc('L')].Items)
NO = len(IndexTable.Classification[IndexTable.set_index('IndexLetter').index.get_loc('O')].Items)
#IndexTable.loc['t']['Classification'].Items # get classification items
SwitchTime = Nc-Nt+1 # Index of first model year (2016)
# 2.4) Read model data and parameters.
Mylog.info('Read model data and parameters.')
ParFileName = os.path.join(RECC_Paths.data_path,'RECC_ParameterDict_' + ScriptConfig['RegionalScope'] + '.dat')
try: # Load Pickle parameter dict to save processing time
ParFileObject = open(ParFileName,'rb')
ParameterDict = pickle.load(ParFileObject)
ParFileObject.close()
Mylog.info('Model data and parameters were read from pickled file with pickle file /parameter reading sequence UUID ' + ParameterDict['Checkkey'])
except:
ParameterDict = {}
mo_start = 0 # set mo for re-reading a certain parameter
for mo in range(mo_start,len(PL_Names)):
#mo = 76 # set mo for re-reading a certain parameter
#ParPath = os.path.join(os.path.abspath(os.path.join(ProjectSpecs_Path_Main, '.')), 'ODYM_RECC_Database', PL_Version[mo])
ParPath = os.path.join(RECC_Paths.data_path, PL_Names[mo] + '_' + PL_Version[mo])
Mylog.info('Reading parameter ' + PL_Names[mo])
#MetaData, Values = msf.ReadParameter(ParPath = ParPath,ThisPar = PL_Names[mo], ThisParIx = PL_IndexStructure[mo], IndexMatch = PL_IndexMatch[mo], ThisParLayerSel = PL_IndexLayer[mo], MasterClassification,IndexTable,IndexTable_ClassificationNames,ScriptConfig,Mylog) # Do not change order of parameters handed over to function!
# Do not change order of parameters handed over to function!
MetaData, Values = msf.ReadParameterXLSX(ParPath, PL_Names[mo], PL_IndexStructure[mo], PL_IndexMatch[mo],
PL_IndexLayer[mo], MasterClassification, IndexTable,
IndexTable_ClassificationNames, ScriptConfig, Mylog, False)
ParameterDict[PL_Names[mo]] = msc.Parameter(Name=MetaData['Dataset_Name'], ID=MetaData['Dataset_ID'],
UUID=MetaData['Dataset_UUID'], P_Res=None, MetaData=MetaData,
Indices=PL_IndexStructure[mo], Values=Values, Uncert=None,
Unit=MetaData['Dataset_Unit'])
Mylog.info('Current parameter file UUID: ' + MetaData['Dataset_UUID'])
Mylog.info('_')
Mylog.info('Reading of parameters finished.')
CheckKey = str(uuid.uuid4()) # generate UUID for this parameter reading sequence.
Mylog.info('Current parameter reading sequence UUID: ' + CheckKey)
Mylog.info('Entire parameter set stored under this UUID, will be reloaded for future calculations.')
ParameterDict['Checkkey'] = CheckKey
# Save to pickle file for next model run
ParFileObject = open(ParFileName,'wb')
pickle.dump(ParameterDict,ParFileObject)
ParFileObject.close()
Mylog.info('_')
Mylog.info('_')
##############################################################
# Section 3) Interpolate missing parameter values: #
##############################################################
# 0) obtain specific indices and positions:
# m_reg_o = 0 # reference region for GHG prices and intensities (Default: 0, which is the first region selected in the config file.)
LEDindex = IndexTable.Classification[IndexTable.index.get_loc('Scenario')].Items.index('LED')
SSP1index = IndexTable.Classification[IndexTable.index.get_loc('Scenario')].Items.index('SSP1')
SSP2index = IndexTable.Classification[IndexTable.index.get_loc('Scenario')].Items.index('SSP2')
SectorList = eval(ScriptConfig['SectorSelect'])
if 'nrb' in SectorList and 'nrbg' in SectorList:
raise AssertionError('Fatal: Non-residential buildings are included both globally (nrbg) and for individual regions (nrb). Double-counting. Exiting the script, check config file.')
# index location and range of pass. vehs. in product list.
try:
Sector_pav_loc = IndexTable.Classification[IndexTable.index.get_loc('Sectors')].Items.index('passenger vehicles')
except:
Sector_pav_loc = np.nan
try:
Sector_pav_rge = [IndexTable.Classification[IndexTable.set_index('IndexLetter').index.get_loc('g')].Items.index(i) for i in IndexTable.Classification[IndexTable.set_index('IndexLetter').index.get_loc('p')].Items]
except:
if 'pav' in SectorList:
raise AssertionError('Fatal: All selected items for aspect p must also be selected for aspect g. Exiting the script.')
else:
Sector_pav_rge = []
# index location and range of res. builds. in product list.
try:
Sector_reb_loc = IndexTable.Classification[IndexTable.index.get_loc('Sectors')].Items.index('residential buildings')
except:
Sector_reb_loc = np.nan
try:
Sector_reb_rge = [IndexTable.Classification[IndexTable.set_index('IndexLetter').index.get_loc('g')].Items.index(i) for i in IndexTable.Classification[IndexTable.set_index('IndexLetter').index.get_loc('B')].Items]
except:
if 'reb' in SectorList:
raise AssertionError('Fatal: All selected items for aspect B must also be selected for aspect g. Exiting the script.')
else:
Sector_reb_rge = []
# index location and range of nonres. builds. in product list.
if 'nrb' in SectorList:
try:
Sector_nrb_loc = IndexTable.Classification[IndexTable.index.get_loc('Sectors')].Items.index('nonresidential buildings r')
except:
Sector_nrb_loc = np.nan
try:
Sector_nrb_rge = [IndexTable.Classification[IndexTable.set_index('IndexLetter').index.get_loc('g')].Items.index(i) for i in IndexTable.Classification[IndexTable.set_index('IndexLetter').index.get_loc('N')].Items]
except:
Sector_nrb_rge = []
else:
Sector_nrb_rge = []
# index location and range of nonres. builds. global in product list.
if 'nrbg' in SectorList:
try:
Sector_nrbg_loc = IndexTable.Classification[IndexTable.index.get_loc('Sectors')].Items.index('nonresidential buildings g')
except:
Sector_nrbg_loc = np.nan
try:
Sector_nrbg_rge = [IndexTable.Classification[IndexTable.set_index('IndexLetter').index.get_loc('g')].Items.index(i) for i in IndexTable.Classification[IndexTable.set_index('IndexLetter').index.get_loc('N')].Items]
except:
Sector_nrbg_rge = []
else:
Sector_nrbg_rge = []
# index location and range of industry in product list.
try:
Sector_ind_loc = IndexTable.Classification[IndexTable.index.get_loc('Sectors')].Items.index('industry')
except:
Sector_ind_loc = np.nan
try:
Sector_ind_rge = [IndexTable.Classification[IndexTable.set_index('IndexLetter').index.get_loc('g')].Items.index(i) for i in IndexTable.Classification[IndexTable.set_index('IndexLetter').index.get_loc('I')].Items]
except:
if 'ind' in SectorList:
raise AssertionError('Fatal: All selected items for aspect I must also be selected for aspect g. Exiting the script.')
else:
Sector_ind_rge = []
# index location and range of appliances in product list.
try:
Sector_app_loc = IndexTable.Classification[IndexTable.index.get_loc('Sectors')].Items.index('appliances')
except:
Sector_app_loc = np.nan
try:
Sector_app_rge = [IndexTable.Classification[IndexTable.set_index('IndexLetter').index.get_loc('g')].Items.index(i) for i in IndexTable.Classification[IndexTable.set_index('IndexLetter').index.get_loc('a')].Items]
except:
if 'app' in SectorList:
raise AssertionError('Fatal: All selected items for aspect a must also be selected for aspect g. Exiting the script.')
else:
Sector_app_rge = []
Cement_loc = IndexTable.Classification[IndexTable.index.get_loc('Engineering materials')].Items.index('cement')
Concrete_loc = IndexTable.Classification[IndexTable.index.get_loc('Engineering materials')].Items.index('concrete')
ConcrAgg_loc = IndexTable.Classification[IndexTable.index.get_loc('Engineering materials')].Items.index('concrete aggregates')
Wood_loc = IndexTable.Classification[IndexTable.index.get_loc('Engineering materials')].Items.index('wood and wood products')
WroughtAl_loc = IndexTable.Classification[IndexTable.index.get_loc('Engineering materials')].Items.index('wrought Al')
CastAl_loc = IndexTable.Classification[IndexTable.index.get_loc('Engineering materials')].Items.index('cast Al')
Copper_loc = IndexTable.Classification[IndexTable.index.get_loc('Engineering materials')].Items.index('copper electric grade')
Plastics_loc = IndexTable.Classification[IndexTable.index.get_loc('Engineering materials')].Items.index('plastics')
Zinc_loc = IndexTable.Classification[IndexTable.index.get_loc('Engineering materials')].Items.index('zinc')
PrimCastAl_loc= IndexTable.Classification[IndexTable.index.get_loc('MaterialProductionProcess')].Items.index('production of cast Al, primary')
PrimWrAl_loc = IndexTable.Classification[IndexTable.index.get_loc('MaterialProductionProcess')].Items.index('production of wrought Al, primary')
EffCastAl_loc = IndexTable.Classification[IndexTable.index.get_loc('MaterialProductionProcess')].Items.index('production of cast Al, efficient')
EffWrAl_loc = IndexTable.Classification[IndexTable.index.get_loc('MaterialProductionProcess')].Items.index('production of wrought Al, efficient')
PrimCGSteel_loc = IndexTable.Classification[IndexTable.index.get_loc('MaterialProductionProcess')].Items.index('production of construction grade steel, primary')
PrimASteel_loc = IndexTable.Classification[IndexTable.index.get_loc('MaterialProductionProcess')].Items.index('production of automotive steel, primary')
PrimSSteel_loc = IndexTable.Classification[IndexTable.index.get_loc('MaterialProductionProcess')].Items.index('production of stainless steel, primary')
PrimCastIron_loc = IndexTable.Classification[IndexTable.index.get_loc('MaterialProductionProcess')].Items.index('production of cast iron, primary')
H2CGSteel_loc = IndexTable.Classification[IndexTable.index.get_loc('MaterialProductionProcess')].Items.index('production of construction grade steel, H2')
H2ASteel_loc = IndexTable.Classification[IndexTable.index.get_loc('MaterialProductionProcess')].Items.index('production of automotive steel, H2')
H2SSteel_loc = IndexTable.Classification[IndexTable.index.get_loc('MaterialProductionProcess')].Items.index('production of stainless steel, H2')
H2CastIron_loc = IndexTable.Classification[IndexTable.index.get_loc('MaterialProductionProcess')].Items.index('production of cast iron, H2')
Woodwaste_loc = IndexTable.Classification[IndexTable.index.get_loc('Waste_Scrap')].Items.index('used construction wood')
Electric_loc = IndexTable.Classification[IndexTable.index.get_loc('Energy')].Items.index('electricity')
WoodFuel_loc = IndexTable.Classification[IndexTable.index.get_loc('Energy')].Items.index('fuel wood')
Hydrogen_loc = IndexTable.Classification[IndexTable.index.get_loc('Energy')].Items.index('hydrogen')
all_loc = IndexTable.Classification[IndexTable.index.get_loc('Energy')].Items.index('all')
Carbon_loc = IndexTable.Classification[IndexTable.index.get_loc('Element')].Items.index('C')
ClimPolScen = IndexTable.Classification[IndexTable.index.get_loc('Scenario_RCP')].Items.index('RCP2.6')
CO2_loc = IndexTable.Classification[IndexTable.index.get_loc('Extensions')].Items.index('CO2 emissions per main output')
GWP100_loc = IndexTable.Classification[IndexTable.index.get_loc('Environmental pressure')].Items.index('GWP100')
Land_loc = IndexTable.Classification[IndexTable.index.get_loc('Environmental pressure')].Items.index('Land occupation (LOP)')
Water_loc = IndexTable.Classification[IndexTable.index.get_loc('Environmental pressure')].Items.index('Water consumption potential (WCP)')
dynGWP100_loc = IndexTable.Classification[IndexTable.index.get_loc('Cumulative env. pressure')].Items.index('dynGWP100')
AllMat_loc = IndexTable.Classification[IndexTable.index.get_loc('Environmental pressure')].Items.index('Raw material input (RMI), all materials')
FosFuel_loc = IndexTable.Classification[IndexTable.index.get_loc('Environmental pressure')].Items.index('Raw material input (RMI), fossil fuels')
MetOres_loc = IndexTable.Classification[IndexTable.index.get_loc('Environmental pressure')].Items.index('Raw material input (RMI), metal ores')
nMetOres_loc = IndexTable.Classification[IndexTable.index.get_loc('Environmental pressure')].Items.index('Raw material input (RMI), non-metallic minerals')
Biomass_loc = IndexTable.Classification[IndexTable.index.get_loc('Environmental pressure')].Items.index('Raw material input (RMI), biomass')
Heating_loc = IndexTable.Classification[IndexTable.index.get_loc('ServiceType')].Items.index('Heating')
Cooling_loc = IndexTable.Classification[IndexTable.index.get_loc('ServiceType')].Items.index('Cooling')
DomstHW_loc = IndexTable.Classification[IndexTable.index.get_loc('ServiceType')].Items.index('DHW')
Service_Drivg = IndexTable.Classification[IndexTable.index.get_loc('ServiceType')].Items.index('Driving')
Service_Reb = np.array([Heating_loc,Cooling_loc,DomstHW_loc])
Ind_2015 = 115 #index of year 2015
#Ind_2017 = 117 #index of year 2017
#Ind_2020 = 120 #index of year 2020
IsClose_Remainder_Small = 1e-15
IsClose_Remainder_Large = 1e-7
DPI_RES = ScriptConfig['Plot1Max'] # 50 for overview or 500 for paper plots, defined in ModelConfig_List
# Determine location of the indices of individual sectors in the region-specific list and in the list of all goods
# indices of sectors with same regional scope in complete goods list
Sector_11reg_rge = Sector_ind_rge
Sector_1reg_rge = Sector_app_rge + Sector_nrbg_rge
#indices of individual end-use sectors within regionally separated product lists, check with classification master file!
Sector_ind_rge_reg = np.arange(0,18,1)
Sector_app_rge_reg = np.arange(0,12,1)
Sector_nrbg_rge_reg = np.arange(12,16,1)
OutputDict = {} # Dictionary with output variables for entire model run, to export checks and analyses.
# 1a) Material composition of vehicles, will only use historic age-cohorts.
# Values are given every 5 years, we need all values in between.
if 'pav' in SectorList:
index = PL_Names.index('3_MC_RECC_Vehicles')
MC_Veh_New = np.zeros(ParameterDict[PL_Names[index]].Values.shape)
Idx_Time = [1980,1985,1990,1995,2000,2005,2010,2015,2020,2025,2030,2035,2040,2045,2050,2055,2060]
Idx_Time_Rel = [i -1900 for i in Idx_Time]
tnew = np.linspace(80, 160, num=81, endpoint=True)
for n in range(0,Nm):
for o in range(0,Np):
for p in range(0,Nr):
f2 = interp1d(Idx_Time_Rel, ParameterDict[PL_Names[index]].Values[Idx_Time_Rel,n,o,p], kind='linear')
MC_Veh_New[80::,n,o,p] = f2(tnew)
ParameterDict[PL_Names[index]].Values = MC_Veh_New.copy()
# 1b) Material composition of res buildings, will only use historic age-cohorts.
# Values are given every 5 years, we need all values in between.
if 'reb' in SectorList:
index = PL_Names.index('3_MC_RECC_Buildings')
index_Ren_A = PL_Names.index('3_MC_RECC_Buildings_Renovation_Absolute')
index_Ren_R = PL_Names.index('3_MC_RECC_Buildings_Renovation_Relative')
MC_Bld_New = np.zeros(ParameterDict[PL_Names[index]].Values.shape)
MC_Bld_New_Ren_A = np.zeros(ParameterDict[PL_Names[index_Ren_A]].Values.shape)
MC_Bld_New_Ren_R = np.zeros(ParameterDict[PL_Names[index_Ren_R]].Values.shape)
Idx_Time = [1900,1910,1920,1930,1940,1950,1960,1970,1980,1985,1990,1995,2000,2005,2010,2015,2020,2025,2030,2035,2040,2045,2050,2055,2060]
Idx_Time_Rel = [i -1900 for i in Idx_Time]
tnew = np.linspace(0, 160, num=161, endpoint=True)
for n in range(0,Nm):
for o in range(0,NB):
for p in range(0,Nr):
f2 = interp1d(Idx_Time_Rel, ParameterDict[PL_Names[index]].Values[Idx_Time_Rel,n,o,p], kind='linear')
MC_Bld_New[:,n,o,p] = f2(tnew).copy()
fA = interp1d(Idx_Time_Rel, ParameterDict[PL_Names[index_Ren_A]].Values[Idx_Time_Rel,n,o,p], kind='linear')
MC_Bld_New_Ren_A[:,n,o,p] = fA(tnew).copy()
fR = interp1d(Idx_Time_Rel, ParameterDict[PL_Names[index_Ren_R]].Values[Idx_Time_Rel,n,o,p], kind='linear')
MC_Bld_New_Ren_R[:,n,o,p] = fR(tnew).copy()
ParameterDict[PL_Names[index]].Values = MC_Bld_New.copy()
ParameterDict[PL_Names[index_Ren_A]].Values = MC_Bld_New_Ren_A.copy()
ParameterDict[PL_Names[index_Ren_R]].Values = MC_Bld_New_Ren_R.copy()
# 1c) Material composition of nonres buildings, will only use historic age-cohorts.
# Values are given every 5 years, we need all values in between.
if 'nrb' in SectorList:
index = PL_Names.index('3_MC_RECC_NonResBuildings')
index_Ren_A = PL_Names.index('3_MC_RECC_NonResBuildings_Renovation_Absolute')
MC_nrb_New = np.zeros(ParameterDict[PL_Names[index]].Values.shape)
MC_nrb_New_Ren_A = np.zeros(ParameterDict[PL_Names[index_Ren_A]].Values.shape)
Idx_Time = [1900,1910,1920,1930,1940,1950,1960,1970,1980,1985,1990,1995,2000,2005,2010,2015,2020,2025,2030,2035,2040,2045,2050,2055,2060]
Idx_Time_Rel = [i -1900 for i in Idx_Time]
tnew = np.linspace(0, 160, num=161, endpoint=True)
for n in range(0,Nm):
for o in range(0,NN):
for p in range(0,Nr):
f2 = interp1d(Idx_Time_Rel, ParameterDict[PL_Names[index]].Values[Idx_Time_Rel,n,o,p], kind='linear')
MC_nrb_New[:,n,o,p] = f2(tnew).copy()
fA = interp1d(Idx_Time_Rel, ParameterDict[PL_Names[index_Ren_A]].Values[Idx_Time_Rel,n,o,p], kind='linear')
MC_nrb_New_Ren_A[:,n,o,p] = fA(tnew).copy()
ParameterDict[PL_Names[index]].Values = MC_nrb_New.copy()
ParameterDict[PL_Names[index_Ren_A]].Values = MC_nrb_New_Ren_A.copy()
# 1d) Split concrete in building archetypes into cement and aggregates but keep concrete separately
ParameterDict['3_MC_BuildingArchetypes'].Values[:,:,Cement_loc] = ParameterDict['3_MC_BuildingArchetypes'].Values[:,:,Cement_loc] + ParameterDict['3_MC_CementContentConcrete'].Values[Cement_loc,Concrete_loc] * ParameterDict['3_MC_BuildingArchetypes'].Values[:,:,Concrete_loc].copy()
ParameterDict['3_MC_BuildingArchetypes'].Values[:,:,ConcrAgg_loc] = (1 - ParameterDict['3_MC_CementContentConcrete'].Values[Cement_loc,Concrete_loc]) * ParameterDict['3_MC_BuildingArchetypes'].Values[:,:,Concrete_loc].copy()
ParameterDict['3_MC_NonResBuildingArchetypes'].Values[:,:,Cement_loc] = ParameterDict['3_MC_NonResBuildingArchetypes'].Values[:,:,Cement_loc] + ParameterDict['3_MC_CementContentConcrete'].Values[Cement_loc,Concrete_loc] * ParameterDict['3_MC_NonResBuildingArchetypes'].Values[:,:,Concrete_loc].copy()
ParameterDict['3_MC_NonResBuildingArchetypes'].Values[:,:,ConcrAgg_loc] = (1 - ParameterDict['3_MC_CementContentConcrete'].Values[Cement_loc,Concrete_loc]) * ParameterDict['3_MC_NonResBuildingArchetypes'].Values[:,:,Concrete_loc].copy()
# 1e) Compile parameter for building energy conversion efficiency:
ParameterDict['4_TC_ResidentialEnergyEfficiency'] = msc.Parameter(Name='4_TC_ResidentialEnergyEfficiency', ID='4_TC_ResidentialEnergyEfficiency',
UUID=None, P_Res=None, MetaData=None,
Indices='VRrntS', Values=np.zeros((NV,NR,Nr,Nn,Nt,NS)), Uncert=None,
Unit='1')
ParameterDict['4_TC_ResidentialEnergyEfficiency'].Values = np.einsum('VRrn,tS->VRrntS',ParameterDict['4_TC_ResidentialEnergyEfficiency_Default'].Values[:,:,:,:,0],np.ones((Nt,NS)))
ParameterDict['4_TC_ResidentialEnergyEfficiency'].Values[Heating_loc,:,:,Electric_loc,:,:] = ParameterDict['4_TC_ResidentialEnergyEfficiency_Scenario_Heating'].Values[Heating_loc,:,:,Electric_loc,:,:] / 100
ParameterDict['4_TC_ResidentialEnergyEfficiency'].Values[Cooling_loc,:,:,Electric_loc,:,:] = ParameterDict['4_TC_ResidentialEnergyEfficiency_Scenario_Cooling'].Values[Cooling_loc,:,:,Electric_loc,:,:] / 100
ParameterDict['4_TC_ResidentialEnergyEfficiency'].Values[DomstHW_loc,:,:,Electric_loc,:,:] = ParameterDict['4_TC_ResidentialEnergyEfficiency_Scenario_Heating'].Values[DomstHW_loc,:,:,Electric_loc,:,:] / 100
ParameterDict['4_TC_NonResidentialEnergyEfficiency'] = msc.Parameter(Name='4_TC_NonResidentialEnergyEfficiency', ID='4_TC_NonResidentialEnergyEfficiency',
UUID=None, P_Res=None, MetaData=None,
Indices='VRrntS', Values=np.zeros((NV,NR,Nr,Nn,Nt,NS)), Uncert=None,
Unit='1')
ParameterDict['4_TC_NonResidentialEnergyEfficiency'].Values = np.einsum('VRrn,tS->VRrntS',ParameterDict['4_TC_NonResEnergyEfficiency_Default'].Values[:,:,:,:,0],np.ones((Nt,NS)))
ParameterDict['4_TC_NonResidentialEnergyEfficiency'].Values[Heating_loc,:,:,Electric_loc,:,:] = ParameterDict['4_TC_NonResEnergyEfficiency_Scenario_Heating'].Values[Heating_loc,:,:,Electric_loc,:,:] / 100
ParameterDict['4_TC_NonResidentialEnergyEfficiency'].Values[Cooling_loc,:,:,Electric_loc,:,:] = ParameterDict['4_TC_NonResEnergyEfficiency_Scenario_Cooling'].Values[Cooling_loc,:,:,Electric_loc,:,:] / 100
ParameterDict['4_TC_NonResidentialEnergyEfficiency'].Values[DomstHW_loc,:,:,Electric_loc,:,:] = ParameterDict['4_TC_NonResEnergyEfficiency_Scenario_Heating'].Values[DomstHW_loc,:,:,Electric_loc,:,:] / 100
# 1f) Derive energy supply multipliers for buildings for future age-cohorts
# From energy carrier split and conversion efficiency, the multipliers converting 1 MJ of final building energy demand into different energy carriers are determined.
# For details around the ancillary quantity anc, see the model documentation.
Divisor = ParameterDict['4_TC_ResidentialEnergyEfficiency'].Values #VRrntS
Anc = np.divide(np.einsum('VRrnt,S->VRrntS',ParameterDict['3_SHA_EnergyCarrierSplit_Buildings'].Values, np.ones(NS)), Divisor, out=np.zeros_like(Divisor), where=Divisor!=0)
# Define energy carrier split for useful energy
ParameterDict['3_SHA_EnergyCarrierSplit_Buildings_uf'] = msc.Parameter(Name='3_SHA_EnergyCarrierSplit_Buildings_uf', ID='3_SHA_EnergyCarrierSplit_Buildings_uf',
UUID=None, P_Res=None, MetaData=None,
Indices='VRrntS', Values=np.zeros((NV,NR,Nr,Nn,Nt,NS)), Uncert=None,
Unit='1')
ParameterDict['3_SHA_EnergyCarrierSplit_Buildings_uf'].Values = np.divide(Anc, np.einsum('VRrtS,n->VRrntS',np.einsum('VRrntS->VRrtS',Anc),np.ones(Nn)), out=np.zeros_like(Divisor), where=Divisor!=0)
Divisor = ParameterDict['4_TC_NonResidentialEnergyEfficiency'].Values #VRrntS
Anc = np.divide(np.einsum('VRrnt,S->VRrntS',ParameterDict['3_SHA_EnergyCarrierSplit_NonResBuildings'].Values, np.ones(NS)), Divisor, out=np.zeros_like(Divisor), where=Divisor!=0)
# Define energy carrier split for useful energy
ParameterDict['3_SHA_EnergyCarrierSplit_NonResBuildings_uf'] = msc.Parameter(Name='3_SHA_EnergyCarrierSplit_NonResBuildings_uf', ID='3_SHA_EnergyCarrierSplit_NonResBuildings_uf',
UUID=None, P_Res=None, MetaData=None,
Indices='VRrntS', Values=np.zeros((NV,NR,Nr,Nn,Nt,NS)), Uncert=None,
Unit='1')
ParameterDict['3_SHA_EnergyCarrierSplit_NonResBuildings_uf'].Values = np.divide(Anc, np.einsum('VRrtS,n->VRrntS',np.einsum('VRrntS->VRrtS',Anc),np.ones(Nn)), out=np.zeros_like(Divisor), where=Divisor!=0)
# 2a) Determine future energy intensity and material composition of vehicles by mixing archetypes:
# Check if RE strategies are active and set implementation curves to 2016 value if not.
if 'pav' in SectorList:
if ScriptConfig['Include_REStrategy_MaterialSubstitution'] == 'False': # no additional lightweighting trough material substitution.
ParameterDict['3_SHA_LightWeighting_Vehicles'].Values = np.einsum('prS,t->prtS',ParameterDict['3_SHA_LightWeighting_Vehicles'].Values[:,:,0,:],np.ones((Nt)))
DownSizingBuffer = ParameterDict['3_SHA_DownSizing_Vehicles'].Values.copy()
if ScriptConfig['Include_REStrategy_UsingLessMaterialByDesign'] == 'True': # consider lightweighting trough UsingLessMaterialByDesign (segment shift)
for nnr in range(0,Nr):
for nnS in range(0,NS):
if ParameterDict['8_FLAG_VehicleDownsizingDirection'].Values[nnr,nnS] == 1:
ParameterDict['3_SHA_DownSizing_Vehicles'].Values[:,nnr,:,nnS] = np.einsum('s,t->st',ParameterDict['3_SHA_DownSizing_Vehicles'].Values[:,nnr,0,nnS],np.ones((Nt)))
else: # no lightweighting trough UsingLessMaterialByDesign.
# for regions not selected above (high-income regions): Set downsizing to 2016 levels.
ParameterDict['3_SHA_DownSizing_Vehicles'].Values = np.einsum('srS,t->srtS',ParameterDict['3_SHA_DownSizing_Vehicles'].Values[:,:,0,:],np.ones((Nt)))
for nnr in range(0,Nr):
for nnS in range(0,NS):
if ParameterDict['8_FLAG_VehicleDownsizingDirection'].Values[nnr,nnS] == 1:
ParameterDict['3_SHA_DownSizing_Vehicles'].Values[:,nnr,:,nnS] = DownSizingBuffer[:,nnr,:,nnS].copy()
ParameterDict['3_MC_RECC_Vehicles_RECC'] = msc.Parameter(Name='3_MC_RECC_Vehicles_RECC', ID='3_MC_RECC_Vehicles_RECC',
UUID=None, P_Res=None, MetaData=None,
Indices='cmprS', Values=np.zeros((Nc,Nm,Np,Nr,NS)), Uncert=None,
Unit='kg/unit')
ParameterDict['3_MC_RECC_Vehicles_RECC'].Values[0:SwitchTime-1,:,:,:,:] = np.einsum('cmpr,S->cmprS',ParameterDict['3_MC_RECC_Vehicles'].Values[0:SwitchTime-1,:,:,:],np.ones(NS))
ParameterDict['3_MC_RECC_Vehicles_RECC'].Values[SwitchTime-1::,:,:,:,:] = \
np.einsum('prcS,pmrcS->cmprS',ParameterDict['3_SHA_LightWeighting_Vehicles'].Values/100, np.einsum('rcS,pm->pmrcS',ParameterDict['3_SHA_DownSizing_Vehicles'].Values[0,:,:,:],ParameterDict['3_MC_VehicleArchetypes'].Values[[24,28,32,36,40,44],:])) +\
np.einsum('prcS,pmrcS->cmprS',ParameterDict['3_SHA_LightWeighting_Vehicles'].Values/100, np.einsum('rcS,pm->pmrcS',ParameterDict['3_SHA_DownSizing_Vehicles'].Values[1,:,:,:],ParameterDict['3_MC_VehicleArchetypes'].Values[[25,29,33,37,41,45],:])) +\
np.einsum('prcS,pmrcS->cmprS',ParameterDict['3_SHA_LightWeighting_Vehicles'].Values/100, np.einsum('rcS,pm->pmrcS',ParameterDict['3_SHA_DownSizing_Vehicles'].Values[2,:,:,:],ParameterDict['3_MC_VehicleArchetypes'].Values[[26,30,34,38,42,46],:])) +\
np.einsum('prcS,pmrcS->cmprS',ParameterDict['3_SHA_LightWeighting_Vehicles'].Values/100, np.einsum('rcS,pm->pmrcS',ParameterDict['3_SHA_DownSizing_Vehicles'].Values[3,:,:,:],ParameterDict['3_MC_VehicleArchetypes'].Values[[27,31,35,39,43,47],:])) +\
np.einsum('prcS,pmrcS->cmprS',1 - ParameterDict['3_SHA_LightWeighting_Vehicles'].Values/100, np.einsum('rcS,pm->pmrcS',ParameterDict['3_SHA_DownSizing_Vehicles'].Values[0,:,:,:],ParameterDict['3_MC_VehicleArchetypes'].Values[[0 ,4 ,8 ,12,16,20],:])) +\
np.einsum('prcS,pmrcS->cmprS',1 - ParameterDict['3_SHA_LightWeighting_Vehicles'].Values/100, np.einsum('rcS,pm->pmrcS',ParameterDict['3_SHA_DownSizing_Vehicles'].Values[1,:,:,:],ParameterDict['3_MC_VehicleArchetypes'].Values[[1 ,5 ,9 ,13,17,21],:])) +\
np.einsum('prcS,pmrcS->cmprS',1 - ParameterDict['3_SHA_LightWeighting_Vehicles'].Values/100, np.einsum('rcS,pm->pmrcS',ParameterDict['3_SHA_DownSizing_Vehicles'].Values[2,:,:,:],ParameterDict['3_MC_VehicleArchetypes'].Values[[2 ,6 ,10,14,18,22],:])) +\
np.einsum('prcS,pmrcS->cmprS',1 - ParameterDict['3_SHA_LightWeighting_Vehicles'].Values/100, np.einsum('rcS,pm->pmrcS',ParameterDict['3_SHA_DownSizing_Vehicles'].Values[3,:,:,:],ParameterDict['3_MC_VehicleArchetypes'].Values[[3 ,7 ,11,15,19,23],:]))
ParameterDict['3_EI_Products_UsePhase_passvehicles'].Values[SwitchTime-1::,:,Service_Drivg,:,:,:] = \
np.einsum('prcS,pnrcS->cpnrS',ParameterDict['3_SHA_LightWeighting_Vehicles'].Values/100, np.einsum('rcS,pn->pnrcS',ParameterDict['3_SHA_DownSizing_Vehicles'].Values[0,:,:,:],ParameterDict['3_EI_VehicleArchetypes'].Values[[24,28,32,36,40,44],:])) +\
np.einsum('prcS,pnrcS->cpnrS',ParameterDict['3_SHA_LightWeighting_Vehicles'].Values/100, np.einsum('rcS,pn->pnrcS',ParameterDict['3_SHA_DownSizing_Vehicles'].Values[1,:,:,:],ParameterDict['3_EI_VehicleArchetypes'].Values[[25,29,33,37,41,45],:])) +\
np.einsum('prcS,pnrcS->cpnrS',ParameterDict['3_SHA_LightWeighting_Vehicles'].Values/100, np.einsum('rcS,pn->pnrcS',ParameterDict['3_SHA_DownSizing_Vehicles'].Values[2,:,:,:],ParameterDict['3_EI_VehicleArchetypes'].Values[[26,30,34,38,42,46],:])) +\
np.einsum('prcS,pnrcS->cpnrS',ParameterDict['3_SHA_LightWeighting_Vehicles'].Values/100, np.einsum('rcS,pn->pnrcS',ParameterDict['3_SHA_DownSizing_Vehicles'].Values[3,:,:,:],ParameterDict['3_EI_VehicleArchetypes'].Values[[27,31,35,39,43,47],:])) +\
np.einsum('prcS,pnrcS->cpnrS',1 - ParameterDict['3_SHA_LightWeighting_Vehicles'].Values/100, np.einsum('rcS,pn->pnrcS',ParameterDict['3_SHA_DownSizing_Vehicles'].Values[0,:,:,:],ParameterDict['3_EI_VehicleArchetypes'].Values[[0 ,4 ,8 ,12,16,20],:])) +\
np.einsum('prcS,pnrcS->cpnrS',1 - ParameterDict['3_SHA_LightWeighting_Vehicles'].Values/100, np.einsum('rcS,pn->pnrcS',ParameterDict['3_SHA_DownSizing_Vehicles'].Values[1,:,:,:],ParameterDict['3_EI_VehicleArchetypes'].Values[[1 ,5 ,9 ,13,17,21],:])) +\
np.einsum('prcS,pnrcS->cpnrS',1 - ParameterDict['3_SHA_LightWeighting_Vehicles'].Values/100, np.einsum('rcS,pn->pnrcS',ParameterDict['3_SHA_DownSizing_Vehicles'].Values[2,:,:,:],ParameterDict['3_EI_VehicleArchetypes'].Values[[2 ,6 ,10,14,18,22],:])) +\
np.einsum('prcS,pnrcS->cpnrS',1 - ParameterDict['3_SHA_LightWeighting_Vehicles'].Values/100, np.einsum('rcS,pn->pnrcS',ParameterDict['3_SHA_DownSizing_Vehicles'].Values[3,:,:,:],ParameterDict['3_EI_VehicleArchetypes'].Values[[3 ,7 ,11,15,19,23],:]))
# 2b) Determine future energy intensity and material composition of residential buildings by mixing archetypes:
# Expand building light-weighting split to all building types:
if 'reb' in SectorList:
ParameterDict['3_SHA_LightWeighting_Buildings'].Values = np.einsum('B,rtS->BrtS',np.ones(NB),ParameterDict['3_SHA_LightWeighting_Buildings'].Values[Sector_reb_loc,:,:,:]).copy()
if ScriptConfig['Include_REStrategy_MaterialSubstitution'] == 'False': # no additional lightweighting trough material substitution.
ParameterDict['3_SHA_LightWeighting_Buildings'].Values = np.einsum('BrS,t->BrtS',ParameterDict['3_SHA_LightWeighting_Buildings'].Values[:,:,0,:],np.ones((Nt)))
if ScriptConfig['Include_REStrategy_UsingLessMaterialByDesign'] == 'False': # no lightweighting trough UsingLessMaterialByDesign.
ParameterDict['3_SHA_DownSizing_Buildings'].Values = np.einsum('urS,t->urtS',ParameterDict['3_SHA_DownSizing_Buildings'].Values[:,:,0,:],np.ones((Nt)))
ParameterDict['3_MC_RECC_Buildings_RECC'] = msc.Parameter(Name='3_MC_RECC_Buildings_RECC', ID='3_MC_RECC_Buildings_RECC',
UUID=None, P_Res=None, MetaData=None,
Indices='cmBrS', Values=np.zeros((Nc,Nm,NB,Nr,NS)), Uncert=None,
Unit='kg/m2')
ParameterDict['3_MC_RECC_Buildings_RECC'].Values[0:115,:,:,:,:] = np.einsum('cmBr,S->cmBrS',ParameterDict['3_MC_RECC_Buildings'].Values[0:115,:,:,:],np.ones(NS))
# Split concrete into cement and aggregates for historic age-cohorts (for future age-cohorts, this is done already for the archetypes).
ParameterDict['3_MC_RECC_Buildings_RECC'].Values[0:115,Cement_loc,:,:,:] = ParameterDict['3_MC_CementContentConcrete'].Values[Cement_loc,Concrete_loc] * ParameterDict['3_MC_RECC_Buildings_RECC'].Values[0:115,Concrete_loc,:,:,:].copy()
ParameterDict['3_MC_RECC_Buildings_RECC'].Values[0:115,ConcrAgg_loc,:,:,:] = (1 - ParameterDict['3_MC_CementContentConcrete'].Values[Cement_loc,Concrete_loc]) * ParameterDict['3_MC_RECC_Buildings_RECC'].Values[0:115,Concrete_loc,:,:,:].copy()
# Mix future archetypes for material composition
ParameterDict['3_MC_RECC_Buildings_RECC'].Values[115::,:,:,:,:] = \
np.einsum('BrcS,BmrcS->cmBrS',ParameterDict['3_SHA_LightWeighting_Buildings'].Values, np.einsum('urcS,Brm->BmrcS',ParameterDict['3_SHA_DownSizing_Buildings'].Values, ParameterDict['3_MC_BuildingArchetypes'].Values[[87,88,89,90,91,92,93,94,95,96,97,98,99],:,:])) +\
np.einsum('BrcS,BmrcS->cmBrS',ParameterDict['3_SHA_LightWeighting_Buildings'].Values, np.einsum('urcS,Brm->BmrcS',1 - ParameterDict['3_SHA_DownSizing_Buildings'].Values,ParameterDict['3_MC_BuildingArchetypes'].Values[[61,62,63,64,65,66,67,68,69,70,71,72,73],:,:])) +\
np.einsum('BrcS,BmrcS->cmBrS',1 - ParameterDict['3_SHA_LightWeighting_Buildings'].Values, np.einsum('urcS,Brm->BmrcS',ParameterDict['3_SHA_DownSizing_Buildings'].Values, ParameterDict['3_MC_BuildingArchetypes'].Values[[74,75,76,77,78,79,80,81,82,83,84,85,86],:,:])) +\
np.einsum('BrcS,BmrcS->cmBrS',1 - ParameterDict['3_SHA_LightWeighting_Buildings'].Values, np.einsum('urcS,Brm->BmrcS',1 - ParameterDict['3_SHA_DownSizing_Buildings'].Values,ParameterDict['3_MC_BuildingArchetypes'].Values[[48,49,50,51,52,53,54,55,56,57,58,59,60],:,:]))
# Replicate values for Al, Cu, plastics for future age-cohorts as the archetypes don't have such information.
ParameterDict['3_MC_RECC_Buildings_RECC'].Values[115::,[WroughtAl_loc,CastAl_loc,Copper_loc,Plastics_loc,Zinc_loc],:,:,:] = np.einsum('mBr,cS->cmBrS',ParameterDict['3_MC_RECC_Buildings'].Values[110,[WroughtAl_loc,CastAl_loc,Copper_loc,Plastics_loc,Zinc_loc],:,:].copy(),np.ones((Nt,NS)))
ParameterDict['3_EI_Products_UsePhase_resbuildings'].Values[115::,:,:,:,:,:] = \
np.einsum('BrcS,BnrVcS->cBVnrS',ParameterDict['3_SHA_LightWeighting_Buildings'].Values, np.einsum('urcS,BrVn->BnrVcS',ParameterDict['3_SHA_DownSizing_Buildings'].Values, ParameterDict['3_EI_BuildingArchetypes'].Values[[87,88,89,90,91,92,93,94,95,96,97,98,99],:,:,:])) +\
np.einsum('BrcS,BnrVcS->cBVnrS',ParameterDict['3_SHA_LightWeighting_Buildings'].Values, np.einsum('urcS,BrVn->BnrVcS',1 - ParameterDict['3_SHA_DownSizing_Buildings'].Values,ParameterDict['3_EI_BuildingArchetypes'].Values[[61,62,63,64,65,66,67,68,69,70,71,72,73],:,:,:])) +\
np.einsum('BrcS,BnrVcS->cBVnrS',1 - ParameterDict['3_SHA_LightWeighting_Buildings'].Values, np.einsum('urcS,BrVn->BnrVcS',ParameterDict['3_SHA_DownSizing_Buildings'].Values, ParameterDict['3_EI_BuildingArchetypes'].Values[[74,75,76,77,78,79,80,81,82,83,84,85,86],:,:,:])) +\
np.einsum('BrcS,BnrVcS->cBVnrS',1 - ParameterDict['3_SHA_LightWeighting_Buildings'].Values, np.einsum('urcS,BrVn->BnrVcS',1 - ParameterDict['3_SHA_DownSizing_Buildings'].Values,ParameterDict['3_EI_BuildingArchetypes'].Values[[48,49,50,51,52,53,54,55,56,57,58,59,60],:,:,:]))
# The archetypes report useful energy for 'all' energy carriers together! Must be split into different energy carriers.
# Will happen below as energy carrier split and final-to-useful conversion efficieny is RCP-scenario dependent.
# Define time-dependent final energy parameter:
ParameterDict['3_EI_Products_UsePhase_resbuildings_t'] = msc.Parameter(Name='3_EI_Products_UsePhase_resbuildings_t', ID='3_EI_Products_UsePhase_resbuildings_t',
UUID=None, P_Res=None, MetaData=None,
Indices='cBVnrt', Values=np.zeros((Nc,NB,NV,Nn,Nr,Nt)), Uncert=None,
Unit='MJ/m2/yr')
ParameterDict['3_MC_RECC_Buildings_t'] = msc.Parameter(Name='3_MC_RECC_Buildings_t', ID='3_MC_RECC_Buildings_t',
UUID=None, P_Res=None, MetaData=None,
Indices='mBrctS', Values=np.zeros((Nm,NB,Nr,Nc,Nt,NS)), Uncert=None,
Unit='kg/m2')
# 2c) Determine future energy intensity and material composition of nonresidential buildings by mixing archetypes:
if 'nrb' in SectorList:
# Expand building light-weighting split to all building types:
ParameterDict['3_SHA_LightWeighting_NonResBuildings'].Values = np.einsum('N,rtS->NrtS',np.ones(NN),ParameterDict['3_SHA_LightWeighting_NonResBuildings'].Values[Sector_nrb_loc,:,:,:]).copy()
if ScriptConfig['Include_REStrategy_MaterialSubstitution'] == 'False': # no additional lightweighting trough material substitution.
ParameterDict['3_SHA_LightWeighting_NonResBuildings'].Values = np.einsum('NrS,t->NrtS',ParameterDict['3_SHA_LightWeighting_NonResBuildings'].Values[:,:,0,:],np.ones((Nt)))
if ScriptConfig['Include_REStrategy_UsingLessMaterialByDesign'] == 'False': # no lightweighting trough UsingLessMaterialByDesign.
ParameterDict['3_SHA_DownSizing_NonResBuildings'].Values = np.einsum('urS,t->urtS',ParameterDict['3_SHA_DownSizing_NonResBuildings'].Values[:,:,0,:],np.ones((Nt)))
ParameterDict['3_MC_RECC_NonResBuildings_RECC'] = msc.Parameter(Name='3_MC_RECC_NonResBuildings_RECC', ID='3_MC_RECC_NonResBuildings_RECC',
UUID=None, P_Res=None, MetaData=None,
Indices='cmNrS', Values=np.zeros((Nc,Nm,NN,Nr,NS)), Uncert=None,
Unit='kg/m2')
#For 3_MC: copy over historic age-cohorts first
ParameterDict['3_MC_RECC_NonResBuildings_RECC'].Values[0:115,:,:,:,:] = np.einsum('cmNr,S->cmNrS',ParameterDict['3_MC_RECC_NonResBuildings'].Values[0:115,:,:,:],np.ones(NS))
# Split concrete into cement and aggregates for historic age-cohorts (for future age-cohorts, this is done already for the archetypes).
ParameterDict['3_MC_RECC_NonResBuildings_RECC'].Values[0:115,Cement_loc,:,:,:] = ParameterDict['3_MC_RECC_NonResBuildings_RECC'].Values[0:115,Cement_loc,:,:,:] + ParameterDict['3_MC_CementContentConcrete'].Values[Cement_loc,Concrete_loc] * ParameterDict['3_MC_RECC_NonResBuildings_RECC'].Values[0:115,Concrete_loc,:,:,:].copy()
ParameterDict['3_MC_RECC_NonResBuildings_RECC'].Values[0:115,ConcrAgg_loc,:,:,:] = (1 - ParameterDict['3_MC_CementContentConcrete'].Values[Cement_loc,Concrete_loc]) * ParameterDict['3_MC_RECC_NonResBuildings_RECC'].Values[0:115,Concrete_loc,:,:,:].copy()
#For 3_MC: Replicate standard type data for other types as proxy type, as only for those, empirical 3_MC data were compiled.
ParameterDict['3_MC_RECC_NonResBuildings_RECC'].Values[0:115,:,[0,1,2,3],:,:] = np.einsum('cmr,S,N->cmNrS',ParameterDict['3_MC_RECC_NonResBuildings'].Values[0:115,:,1,:], np.ones(NS),np.ones(4))
ParameterDict['3_MC_RECC_NonResBuildings_RECC'].Values[0:115,:,[4,5,6,7],:,:] = np.einsum('cmr,S,N->cmNrS',ParameterDict['3_MC_RECC_NonResBuildings'].Values[0:115,:,5,:], np.ones(NS),np.ones(4))
ParameterDict['3_MC_RECC_NonResBuildings_RECC'].Values[0:115,:,[8,9,10,11],:,:] = np.einsum('cmr,S,N->cmNrS',ParameterDict['3_MC_RECC_NonResBuildings'].Values[0:115,:,9,:], np.ones(NS),np.ones(4))
ParameterDict['3_MC_RECC_NonResBuildings_RECC'].Values[0:115,:,[12,13,14,15],:,:] = np.einsum('cmr,S,N->cmNrS',ParameterDict['3_MC_RECC_NonResBuildings'].Values[0:115,:,13,:],np.ones(NS),np.ones(4))
ParameterDict['3_MC_RECC_NonResBuildings_RECC'].Values[0:115,:,[16,17,18,19],:,:] = np.einsum('cmr,S,N->cmNrS',ParameterDict['3_MC_RECC_NonResBuildings'].Values[0:115,:,17,:],np.ones(NS),np.ones(4))
ParameterDict['3_MC_RECC_NonResBuildings_RECC'].Values[0:115,:,[20,21,22,23],:,:] = np.einsum('cmr,S,N->cmNrS',ParameterDict['3_MC_RECC_NonResBuildings'].Values[0:115,:,21,:],np.ones(NS),np.ones(4))
# Mix future archetypes for material composition
ParameterDict['3_MC_RECC_NonResBuildings_RECC'].Values[115::,:,:,:,:] = \
np.einsum('NrcS,NmrcS->cmNrS',ParameterDict['3_SHA_LightWeighting_NonResBuildings'].Values, np.einsum('urcS,Nrm->NmrcS',ParameterDict['3_SHA_DownSizing_NonResBuildings'].Values, ParameterDict['3_MC_NonResBuildingArchetypes'].Values[[110,114,106,102,158,162,154,150,174,178,170,166,190,194,186,182,126,130,122,118,142,146,138,134],:,:])) +\
np.einsum('NrcS,NmrcS->cmNrS',ParameterDict['3_SHA_LightWeighting_NonResBuildings'].Values, np.einsum('urcS,Nrm->NmrcS',1 - ParameterDict['3_SHA_DownSizing_NonResBuildings'].Values,ParameterDict['3_MC_NonResBuildingArchetypes'].Values[[109,113,105,101,157,161,153,149,173,177,169,165,189,193,185,181,125,129,121,117,141,145,137,133],:,:])) +\
np.einsum('NrcS,NmrcS->cmNrS',1 - ParameterDict['3_SHA_LightWeighting_NonResBuildings'].Values, np.einsum('urcS,Nrm->NmrcS',ParameterDict['3_SHA_DownSizing_NonResBuildings'].Values, ParameterDict['3_MC_NonResBuildingArchetypes'].Values[[111,115,107,103,159,163,155,151,175,179,171,167,191,195,187,183,127,131,123,119,143,147,139,135],:,:])) +\
np.einsum('NrcS,NmrcS->cmNrS',1 - ParameterDict['3_SHA_LightWeighting_NonResBuildings'].Values, np.einsum('urcS,Nrm->NmrcS',1 - ParameterDict['3_SHA_DownSizing_NonResBuildings'].Values,ParameterDict['3_MC_NonResBuildingArchetypes'].Values[[108,112,104,100,156,160,152,148,172,176,168,164,188,192,184,180,124,128,120,116,140,144,136,132],:,:]))
# Replicate values for Al, Cu, plastics for future age-cohorts as the archetypes don't have such information.
ParameterDict['3_MC_RECC_NonResBuildings_RECC'].Values[115::,[WroughtAl_loc,CastAl_loc,Copper_loc,Plastics_loc,Zinc_loc],:,:,:] = np.einsum('mNr,cS->cmNrS',ParameterDict['3_MC_RECC_NonResBuildings'].Values[110,[WroughtAl_loc,CastAl_loc,Copper_loc,Plastics_loc,Zinc_loc],:,:].copy(),np.ones((Nt,NS)))
# For 3_EI_Products_UsePhase_nonresbuildings: Replicate SSP1 values to LED and SSP2 scenarios (scenario aspect is irrelevant anyway because these are historic data only)
ParameterDict['3_EI_Products_UsePhase_nonresbuildings'].Values[:,:,:,:,:,:] = np.einsum('cNVnr,S->cNVnrS',ParameterDict['3_EI_Products_UsePhase_nonresbuildings'].Values[:,:,:,:,:,1],np.ones(NS))
# Mix future archetypes
ParameterDict['3_EI_Products_UsePhase_nonresbuildings'].Values[115::,:,:,:,:,:] = \
np.einsum('NrcS,NnrVcS->cNVnrS',ParameterDict['3_SHA_LightWeighting_NonResBuildings'].Values, np.einsum('urcS,NrVn->NnrVcS',ParameterDict['3_SHA_DownSizing_NonResBuildings'].Values, ParameterDict['3_EI_NonResBuildingArchetypes'].Values[[110,114,106,102,158,162,154,150,174,178,170,166,190,194,186,182,126,130,122,118,142,146,138,134],:,:,:])) +\
np.einsum('NrcS,NnrVcS->cNVnrS',ParameterDict['3_SHA_LightWeighting_NonResBuildings'].Values, np.einsum('urcS,NrVn->NnrVcS',1 - ParameterDict['3_SHA_DownSizing_NonResBuildings'].Values,ParameterDict['3_EI_NonResBuildingArchetypes'].Values[[109,113,105,101,157,161,153,149,173,177,169,165,189,193,185,181,125,129,121,117,141,145,137,133],:,:,:])) +\
np.einsum('NrcS,NnrVcS->cNVnrS',1 - ParameterDict['3_SHA_LightWeighting_NonResBuildings'].Values, np.einsum('urcS,NrVn->NnrVcS',ParameterDict['3_SHA_DownSizing_NonResBuildings'].Values, ParameterDict['3_EI_NonResBuildingArchetypes'].Values[[111,115,107,103,159,163,155,151,175,179,171,167,191,195,187,183,127,131,123,119,143,147,139,135],:,:,:])) +\
np.einsum('NrcS,NnrVcS->cNVnrS',1 - ParameterDict['3_SHA_LightWeighting_NonResBuildings'].Values, np.einsum('urcS,NrVn->NnrVcS',1 - ParameterDict['3_SHA_DownSizing_NonResBuildings'].Values,ParameterDict['3_EI_NonResBuildingArchetypes'].Values[[108,112,104,100,156,160,152,148,172,176,168,164,188,192,184,180,124,128,120,116,140,144,136,132],:,:,:]))
ParameterDict['3_EI_Products_UsePhase_nonresbuildings_t'] = msc.Parameter(Name='3_EI_Products_UsePhase_nonresbuildings_t', ID='3_EI_Products_UsePhase_nonresbuildings_t',
UUID=None, P_Res=None, MetaData=None,
Indices='cNVnrt', Values=np.zeros((Nc,NN,NV,Nn,Nr,Nt)), Uncert=None,
Unit='MJ/m2/yr')
ParameterDict['3_MC_RECC_NonResBuildings_t'] = msc.Parameter(Name='3_MC_RECC_NonResBuildings_t', ID='3_MC_RECC_NonResBuildings_t',
UUID=None, P_Res=None, MetaData=None,
Indices='mNrctS', Values=np.zeros((Nm,NN,Nr,Nc,Nt,NS)), Uncert=None,
Unit='kg/m2')
if 'nrbg' in SectorList:
# Split concrete into cement and aggregates:
# Cement for buildings remains, as this item refers to cement in mortar, screed, and plaster. Cement in concrete is calculated as ParameterDict['3_MC_CementContentConcrete'].Values * concrete and added here.
# Concrete aggregates (0.87*concrete) are considered as well.
ParameterDict['3_MC_RECC_Nonresbuildings_g'].Values[Cement_loc,:] = ParameterDict['3_MC_RECC_Nonresbuildings_g'].Values[Cement_loc,:] + ParameterDict['3_MC_CementContentConcrete'].Values[Cement_loc,Concrete_loc] * ParameterDict['3_MC_RECC_Nonresbuildings_g'].Values[Concrete_loc,:].copy()
ParameterDict['3_MC_RECC_Nonresbuildings_g'].Values[ConcrAgg_loc,:] = (1 - ParameterDict['3_MC_CementContentConcrete'].Values[Cement_loc,Concrete_loc]) * ParameterDict['3_MC_RECC_Nonresbuildings_g'].Values[Concrete_loc,:].copy()
ParameterDict['3_MC_RECC_Nonresbuildings_g'].Values[Concrete_loc,:] = 0
# 3) Currently not in use.
# 4) Fabrication yield and fabrication scrap diversion:
# Extrapolate 2050-2060 as 2015 values
index = PL_Names.index('4_PY_Manufacturing')
ParameterDict[PL_Names[index]].Values[:,:,:,:,1::,:] = np.einsum('t,mwgFr->mwgFtr',np.ones(45),ParameterDict[PL_Names[index]].Values[:,:,:,:,0,:])
if ScriptConfig['Include_REStrategy_FabScrapDiversion'] == 'False':
ParameterDict['6_PR_FabricationScrapDiversion'].Values = np.zeros((Nm,Nw,No,NS))
# 5) EoL RR, apply world average to all regions
ParameterDict['4_PY_EoL_RecoveryRate'].Values = np.einsum('gmwW,r->grmwW',ParameterDict['4_PY_EoL_RecoveryRate'].Values[:,0,:,:,:],np.ones((Nr)))
# 6) Energy carrier split of vehicles, replicate fixed values for all regions and age-cohorts etc.
ParameterDict['3_SHA_EnergyCarrierSplit_Vehicles'].Values = np.einsum('pn,crVS->cprVnS',ParameterDict['3_SHA_EnergyCarrierSplit_Vehicles'].Values[115,:,0,3,:,SSP1index].copy(),np.ones((Nc,Nr,NV,NS)))
# 7) RE strategy potentials for individual countries are replicated from global average:
ParameterDict['6_PR_ReUse_Bld'].Values = np.einsum('mB,r->mBr',ParameterDict['6_PR_ReUse_Bld'].Values[:,:,0],np.ones(Nr))
ParameterDict['6_PR_ReUse_nonresBld'].Values = np.einsum('mN,r->mNr',ParameterDict['6_PR_ReUse_nonresBld'].Values[:,:,0],np.ones(Nr))
ParameterDict['6_PR_LifeTimeExtension_passvehicles'].Values = np.einsum('pS,r->prS',ParameterDict['6_PR_LifeTimeExtension_passvehicles'].Values[:,0,:],np.ones(Nr))
ParameterDict['6_PR_EoL_RR_Improvement'].Values = np.einsum('gmwW,r->grmwW',ParameterDict['6_PR_EoL_RR_Improvement'].Values[:,0,:,:,:],np.ones(Nr))
# 8) Define a multi-regional RE strategy and building renovation scaleup parameter
ParameterDict['3_SHA_RECC_REStrategyScaleUp_r'] = msc.Parameter(Name='3_SHA_RECC_REStrategyScaleUp_r', ID='3_SHA_RECC_REStrategyScaleUp_r',
UUID=None, P_Res=None, MetaData=None,
Indices='trSR', Values=np.zeros((Nt,Nr,NS,NR)), Uncert=None,
Unit='1')
ParameterDict['3_SHA_RECC_REStrategyScaleUp_r'].Values = np.einsum('RtS,r->trSR',ParameterDict['3_SHA_RECC_REStrategyScaleUp'].Values[:,0,:,:],np.ones(Nr)).copy()
ParameterDict['3_SHA_BuildingRenovationScaleUp_r'] = msc.Parameter(Name='3_SHA_BuildingRenovationScaleUp_r', ID='3_SHA_BuildingRenovationScaleUp_r',
UUID=None, P_Res=None, MetaData=None,
Indices='trSR', Values=np.zeros((Nt,Nr,NS,NR)), Uncert=None,
Unit='1')
ParameterDict['3_SHA_BuildingRenovationScaleUp_r'].Values = np.einsum('RtS,r->trSR',ParameterDict['3_SHA_BuildingRenovationScaleUp'].Values[:,0,:,:],np.ones(Nr)).copy()
# 9) LED scenario data from proxy scenarios:
# 2_P_RECC_Population_SSP_32R
ParameterDict['2_P_RECC_Population_SSP_32R'].Values[:,:,:,LEDindex] = ParameterDict['2_P_RECC_Population_SSP_32R'].Values[:,:,:,SSP2index].copy()
# 3_EI_Products_UsePhase, historic
ParameterDict['3_EI_Products_UsePhase_passvehicles'].Values[0:115,:,:,:,:,LEDindex] = ParameterDict['3_EI_Products_UsePhase_passvehicles'].Values[0:115,:,:,:,:,SSP2index].copy()
ParameterDict['3_EI_Products_UsePhase_resbuildings'].Values[0:115,:,:,:,:,LEDindex] = ParameterDict['3_EI_Products_UsePhase_resbuildings'].Values[0:115,:,:,:,:,SSP2index].copy()
ParameterDict['3_EI_Products_UsePhase_nonresbuildings'].Values[0:115,:,:,:,:,LEDindex] = ParameterDict['3_EI_Products_UsePhase_nonresbuildings'].Values[0:115,:,:,:,:,SSP2index].copy()
# 3_IO_Buildings_UsePhase
ParameterDict['3_IO_Buildings_UsePhase_Historic'].Values[:,:,:,:,LEDindex] = ParameterDict['3_IO_Buildings_UsePhase_Historic'].Values[:,:,:,:,SSP2index].copy()
# 10) Set future vehicle reuse to 2015 levels if strategy is not included:
# (To reflect that reuse is already happening to some extent.)
if ScriptConfig['Include_REStrategy_ReUse'] == 'False':
ParameterDict['6_PR_ReUse_Veh'].Values = np.einsum('mprS,t->mprtS',ParameterDict['6_PR_ReUse_Veh'].Values[:,:,:,1,:],np.ones(Nt)) # stay at current levels, which are > 0.
ParameterDict['6_PR_ReUse_Bld'].Values = np.zeros(ParameterDict['6_PR_ReUse_Bld'].Values.shape) # set to zero, which corresponds to current levels.
ParameterDict['6_PR_ReUse_nonresBld'].Values = np.zeros(ParameterDict['6_PR_ReUse_nonresBld'].Values.shape) # set to zero, which corresponds to current levels.
# 11) MODEL CALIBRATION
# Calibrate vehicle kilometrage: No longer used! VKM is now calibrated in scenario target table process to deliver correct pC stock number for 2015.
#### ParameterDict['3_IO_Vehicles_UsePhase'].Values[3,:,:,:] = ParameterDict['3_IO_Vehicles_UsePhase'].Values[3,:,:,:] * np.einsum('r,tS->rtS',ParameterDict['6_PR_Calibration'].Values[0,:],np.ones((Nt,NS)))
# Calibrate vehicle fuel consumption, cgVnrS
ParameterDict['3_EI_Products_UsePhase_passvehicles'].Values[0:115,:,3,:,:,:] = ParameterDict['3_EI_Products_UsePhase_passvehicles'].Values[0:115,:,3,:,:,:] * np.einsum('r,cpnS->cpnrS',ParameterDict['6_PR_Calibration'].Values[1,:],np.ones((115,Np,Nn,NS)))
# Calibrate res. building energy consumption
ParameterDict['3_EI_Products_UsePhase_resbuildings'].Values[0:115,:,0:3,:,:,:] = ParameterDict['3_EI_Products_UsePhase_resbuildings'].Values[0:115,:,0:3,:,:,:] * np.einsum('r,cBVnS->cBVnrS',ParameterDict['6_PR_Calibration'].Values[2,:],np.ones((115,NB,3,Nn,NS)))
# Calibrate nonres. building energy consumption
ParameterDict['3_EI_Products_UsePhase_nonresbuildings'].Values[0:115,:,0:3,:,:,:] = ParameterDict['3_EI_Products_UsePhase_nonresbuildings'].Values[0:115,:,0:3,:,:,:] * np.einsum('r,cNVnS->cNVnrS',ParameterDict['6_PR_Calibration'].Values[3,:],np.ones((115,NN,3,Nn,NS)))
# 12) No recycling scenario (counterfactual reference)
if ScriptConfig['IncludeRecycling'] == 'False': # no recycling and remelting
ParameterDict['4_PY_EoL_RecoveryRate'].Values = np.zeros(ParameterDict['4_PY_EoL_RecoveryRate'].Values.shape)
ParameterDict['4_PY_MaterialProductionRemelting'].Values = np.zeros(ParameterDict['4_PY_MaterialProductionRemelting'].Values.shape)
# 13) currently not used.
# 14) Define parameter for future vehicle stock:
# a) calculated passenger vehicle stock
ParameterDict['2_S_RECC_FinalProducts_Future_passvehicles'] = msc.Parameter(Name='2_S_RECC_FinalProducts_Future_passvehicles', ID='2_S_RECC_FinalProducts_Future_passvehicles',
UUID=None, P_Res=None, MetaData=None,
Indices='StGr', Values=np.zeros((NS,Nt,NG,Nr)), Uncert=None,
Unit='cars per person')
# b) calculated vehicle kilometrage
ParameterDict['3_IO_Vehicles_UsePhase_eff'] = msc.Parameter(Name='3_IO_Vehicles_UsePhase_eff', ID='3_IO_Vehicles_UsePhase_eff',
UUID=None, P_Res=None, MetaData=None,
Indices='VrtS', Values=np.zeros((NV,Nr,Nt,NS)), Uncert=None,
Unit='km per vehicle')
# 15) Define parameter for future building stock:
# actual future res and nonres building stock
ParameterDict['2_S_RECC_FinalProducts_Future_resbuildings_act'] = msc.Parameter(Name='2_S_RECC_FinalProducts_Future_resbuildings_act', ID='2_S_RECC_FinalProducts_Future_resbuildings_act',
UUID=None, P_Res=None, MetaData=None,
Indices='StGr', Values=np.zeros((NS,Nt,NG,Nr)), Uncert=None,
Unit='m2 per person')
ParameterDict['2_S_RECC_FinalProducts_Future_NonResBuildings_act'] = msc.Parameter(Name='2_S_RECC_FinalProducts_Future_NonResBuildings_act', ID='2_S_RECC_FinalProducts_Future_NonResBuildings_act',
UUID=None, P_Res=None, MetaData=None,
Indices='GrtS', Values=np.zeros((NG,Nr,Nt,NS)), Uncert=None,
Unit='m2 per person')
# 3_IO changing over time:
ParameterDict['3_IO_Buildings_UsePhase'] = msc.Parameter(Name='3_IO_Buildings_UsePhase', ID='3_IO_Buildings_UsePhase',
UUID=None, P_Res=None, MetaData=None,
Indices='tcBVrS', Values=np.zeros((Nt,Nc,NB,NV,Nr,NS)), Uncert=None,
Unit='1')
# Historic age-cohorts:
# ParameterDict['3_IO_Buildings_UsePhase_Historic'] is a combination of climate and socioeconomic 3_IO determinants.
# We single out the former and keep them constant and let the socioeconomic factors change according to the '3_IO_Buildings_UsePhase_Future_...' parameters.
Par_3_IO_Buildings_UsePhase_Historic_Climate_Heating = ParameterDict['3_IO_Buildings_UsePhase_Historic'].Values[0:SwitchTime,:,Heating_loc,:,:] / np.einsum('rS,cB->cBrS',ParameterDict['3_IO_Buildings_UsePhase_Future_Heating'].Values[Sector_reb_loc,:,0,:],np.ones((SwitchTime,NB))) * 100
Par_3_IO_Buildings_UsePhase_Historic_Climate_Heating[np.isnan(Par_3_IO_Buildings_UsePhase_Historic_Climate_Heating)] = 0
ParameterDict['3_IO_Buildings_UsePhase'].Values[:,0:SwitchTime,:,Heating_loc,:,:] = np.einsum('cBrS,t->tcBrS',Par_3_IO_Buildings_UsePhase_Historic_Climate_Heating,np.ones(Nt))
Par_3_IO_Buildings_UsePhase_Historic_Climate_DHW = ParameterDict['3_IO_Buildings_UsePhase_Historic'].Values[0:SwitchTime,:,DomstHW_loc,:,:] / np.einsum('rS,cB->cBrS',ParameterDict['3_IO_Buildings_UsePhase_Future_Heating'].Values[Sector_reb_loc,:,0,:],np.ones((SwitchTime,NB))) * 100
Par_3_IO_Buildings_UsePhase_Historic_Climate_DHW[np.isnan(Par_3_IO_Buildings_UsePhase_Historic_Climate_DHW)] = 0
ParameterDict['3_IO_Buildings_UsePhase'].Values[:,0:SwitchTime,:,DomstHW_loc,:,:] = np.einsum('cBrS,t->tcBrS',Par_3_IO_Buildings_UsePhase_Historic_Climate_DHW,np.ones(Nt))
Par_3_IO_Buildings_UsePhase_Historic_Climate_Cooling = ParameterDict['3_IO_Buildings_UsePhase_Historic'].Values[0:SwitchTime,:,Cooling_loc,:,:] / np.einsum('rS,cB->cBrS',ParameterDict['3_IO_Buildings_UsePhase_Future_Cooling'].Values[Sector_reb_loc,:,0,:],np.ones((SwitchTime,NB))) * 100
Par_3_IO_Buildings_UsePhase_Historic_Climate_Cooling[np.isnan(Par_3_IO_Buildings_UsePhase_Historic_Climate_Cooling)] = 0
ParameterDict['3_IO_Buildings_UsePhase'].Values[:,0:SwitchTime,:,Cooling_loc,:,:] = np.einsum('cBrS,t->tcBrS',Par_3_IO_Buildings_UsePhase_Historic_Climate_Cooling,np.ones(Nt))
# Correct for if some of the corrections lead to IO > 1 which may be the case when hist. IO data are incomplete and thus set to 1 already.
ParameterDict['3_IO_Buildings_UsePhase'].Values[ParameterDict['3_IO_Buildings_UsePhase'].Values > 1] = 1
# Future age-cohorts:
ParameterDict['3_IO_Buildings_UsePhase'].Values[:,SwitchTime::,:,Heating_loc,:,:] = np.einsum('rtS,cB->tcBrS',ParameterDict['3_IO_Buildings_UsePhase_Future_Heating'].Values[Sector_reb_loc,:,:,:]/100,np.ones((Nc-SwitchTime,NB)))
ParameterDict['3_IO_Buildings_UsePhase'].Values[:,SwitchTime::,:,DomstHW_loc,:,:] = np.einsum('rtS,cB->tcBrS',ParameterDict['3_IO_Buildings_UsePhase_Future_Heating'].Values[Sector_reb_loc,:,:,:]/100,np.ones((Nc-SwitchTime,NB)))
ParameterDict['3_IO_Buildings_UsePhase'].Values[:,SwitchTime::,:,Cooling_loc,:,:] = np.einsum('rtS,cB->tcBrS',ParameterDict['3_IO_Buildings_UsePhase_Future_Cooling'].Values[Sector_reb_loc,:,:,:]/100,np.ones((Nc-SwitchTime,NB)))
# expand 3_IO parameter for nonres buildings with 1 for post 2015 years:
ParameterDict['3_IO_NonResBuildings_UsePhase'].Values[SwitchTime::,:,:,:,:] = 1
# 16) Currently not used.
# 17) No energy efficiency improvements (counterfactual reference)
# Freeze type split and archetypes at 2015/17/2020 levels:
if ScriptConfig['No_EE_Improvements'] == 'True':
SwitchIndex = Ind_2015 # choose between Ind_2015/17/20 (for continuation from 2015/17/20 onwards.
if 'pav' in SectorList:
for nnr in range(0,Nr):
for nnS in range(0,NS):
if ParameterDict['8_FLAG_VehicleDownsizingDirection'].Values[nnr,nnS] == 0: # don't consider type split reset for cases, where type split change involves larger vehicles.
ParameterDict['3_EI_Products_UsePhase_passvehicles'].Values[SwitchIndex::,:,:,:,nnr,nnS] = np.einsum('pVn,c->cpVn',ParameterDict['3_EI_Products_UsePhase_passvehicles'].Values[SwitchIndex,:,:,:,nnr,nnS],np.ones(Nc-SwitchIndex))
ParameterDict['3_MC_RECC_Vehicles_RECC'].Values[SwitchIndex::,:,:,nnr,nnS] = np.einsum('mp,c->cmp',ParameterDict['3_MC_RECC_Vehicles_RECC'].Values[SwitchIndex,:,:,nnr,nnS],np.ones(Nc-SwitchIndex))
ParameterDict['3_SHA_TypeSplit_Vehicles'].Values[:,:,:,:,4::] = np.einsum('GrRp,t->GrRpt',ParameterDict['3_SHA_TypeSplit_Vehicles'].Values[:,:,:,:,4],np.ones(Nt-4)) # index 4 is year 2020.
if 'reb' in SectorList:
ParameterDict['3_EI_Products_UsePhase_resbuildings'].Values[SwitchIndex::,:,:,:,:,:] = np.einsum('BVnrS,c->cBVnrS',ParameterDict['3_EI_Products_UsePhase_resbuildings'].Values[SwitchIndex,:,:,:,:,:],np.ones(Nc-SwitchIndex))
ParameterDict['3_MC_RECC_Buildings_RECC'].Values[SwitchIndex::,:,:,:,:] = np.einsum('mBrS,c->cmBrS',ParameterDict['3_MC_RECC_Buildings_RECC'].Values[SwitchIndex,:,:,:,:],np.ones(Nc-SwitchIndex))
ParameterDict['3_SHA_TypeSplit_Buildings'].Values[:,:,4::,:] = np.einsum('BrS,t->BrtS',ParameterDict['3_SHA_TypeSplit_Buildings'].Values[:,:,4,:],np.ones(Nt-4)) # index 4 is year 2020.
ParameterDict['4_TC_ResidentialEnergyEfficiency'].Values[:,:,:,:,4::,:] = np.einsum('VRrnS,t->VRrntS',ParameterDict['4_TC_ResidentialEnergyEfficiency'].Values[:,:,:,:,4,:],np.ones(Nt-4)) # index 4 is year 2020.
if 'nrb' in SectorList:
ParameterDict['3_EI_Products_UsePhase_nonresbuildings'].Values[SwitchIndex::,:,:,:,:,:] = np.einsum('NVnrS,c->cNVnrS',ParameterDict['3_EI_Products_UsePhase_nonresbuildings'].Values[SwitchIndex,:,:,:,:,:],np.ones(Nc-SwitchIndex))
ParameterDict['3_MC_RECC_NonResBuildings_RECC'].Values[SwitchIndex::,:,:,:,:] = np.einsum('mNrS,c->cmNrS',ParameterDict['3_MC_RECC_NonResBuildings_RECC'].Values[SwitchIndex,:,:,:,:],np.ones(Nc-SwitchIndex))
ParameterDict['3_SHA_TypeSplit_NonResBuildings'].Values[:,:,4::,:] = np.einsum('NrS,t->NrtS',ParameterDict['3_SHA_TypeSplit_NonResBuildings'].Values[:,:,4,:],np.ones(Nt-4)) # index 4 is year 2020.
ParameterDict['4_TC_NonResidentialEnergyEfficiency'].Values[:,:,:,:,4::,:] = np.einsum('VRrnS,t->VRrntS',ParameterDict['4_TC_NonResidentialEnergyEfficiency'].Values[:,:,:,:,4,:],np.ones(Nt-4)) # index 4 is year 2020.
# 18) Currently not used.
# 19) Make sure that all share parameters are non-negative and add up to 100%:
# not necessary for res. buildings as data fulfil constraints.
#ParameterDict['3_SHA_TypeSplit_Buildings'].Values[ParameterDict['3_SHA_TypeSplit_Buildings'].Values < 0] = 0
#ParameterDict['3_SHA_TypeSplit_Buildings'].Values = ParameterDict['3_SHA_TypeSplit_Buildings'].Values / np.einsum('rtS,B->BrtS',ParameterDict['3_SHA_TypeSplit_Buildings'].Values.sum(axis=0),np.ones(NB))
#ParameterDict['3_SHA_TypeSplit_Buildings'].Values[np.isnan(ParameterDict['3_SHA_TypeSplit_Buildings'].Values)] = 0
ParameterDict['3_SHA_TypeSplit_NonResBuildings'].Values[ParameterDict['3_SHA_TypeSplit_NonResBuildings'].Values < 0] = 0
ParameterDict['3_SHA_TypeSplit_NonResBuildings'].Values = ParameterDict['3_SHA_TypeSplit_NonResBuildings'].Values / np.einsum('rtS,B->BrtS',ParameterDict['3_SHA_TypeSplit_NonResBuildings'].Values.sum(axis=0),np.ones(NN))
ParameterDict['3_SHA_TypeSplit_NonResBuildings'].Values[np.isnan(ParameterDict['3_SHA_TypeSplit_NonResBuildings'].Values)] = 0
# 20) Extrapolate appliances beyond 2050:
for noS in range(0,NS):
for noR in range(0,NR):
for noa in range(0,Na):
if ParameterDict['1_F_RECC_FinalProducts_appliances'].Values[0,140,noS,noR,noa] != 0:
growthrate = (ParameterDict['1_F_RECC_FinalProducts_appliances'].Values[0,150,noS,noR,noa]/ParameterDict['1_F_RECC_FinalProducts_appliances'].Values[0,140,noS,noR,noa]-1)/10
else:
growthrate = 0
for noT in range(151,161):
ParameterDict['1_F_RECC_FinalProducts_appliances'].Values[0,noT,noS,noR,noa] = ParameterDict['1_F_RECC_FinalProducts_appliances'].Values[0,150,noS,noR,noa] * np.power(1+growthrate,noT-150)
# 21) GWP_bio factor interpolation
Idx_Time = [1900,1910,1920,1930,1940,1950,1960,1970,1980,1990,2000]
Idx_Time_Rel = [i -1900 for i in Idx_Time]
tnew = np.linspace(0, 100, num=101, endpoint=True)
f2 = interp1d(Idx_Time_Rel, ParameterDict['6_MIP_GWP_Bio'].Values[Idx_Time_Rel].copy(), kind='linear')
ParameterDict['6_MIP_GWP_Bio'].Values = np.zeros((300))
ParameterDict['6_MIP_GWP_Bio'].Values[0:101] = f2(tnew).copy()
ParameterDict['6_MIP_GWP_Bio'].Values[101::] = -1
# 22) calculate Stocks on 1. Jan 2016:
pC_AgeCohortHist = np.zeros((NG,Nr))
#pC_FutureStock = np.zeros((NS,NG,Nr))
# a) from historic data:
Stocks_2016_passvehicles = ParameterDict['2_S_RECC_FinalProducts_2015_passvehicles'].Values[0,:,:,:].sum(axis=0)
pCStocks_2016_passvehicles = np.einsum('pr,r->rp',Stocks_2016_passvehicles,1/ParameterDict['2_P_RECC_Population_SSP_32R'].Values[0,0,:,1])
Stocks_2016_resbuildings = ParameterDict['2_S_RECC_FinalProducts_2015_resbuildings'].Values[0,:,:,:].sum(axis=0)
pCStocks_2016_resbuildings = np.einsum('Br,r->rB',Stocks_2016_resbuildings,1/ParameterDict['2_P_RECC_Population_SSP_32R'].Values[0,0,:,1])
Stocks_2016_nresbuildings = ParameterDict['2_S_RECC_FinalProducts_2015_nonresbuildings'].Values[0,:,:,:].sum(axis=0)
pCStocks_2016_nresbuildings= np.einsum('Nr,r->rN',Stocks_2016_nresbuildings,1/ParameterDict['2_P_RECC_Population_SSP_32R'].Values[0,0,:,1])
if 'pav' in SectorList:
pC_AgeCohortHist[Sector_pav_loc, :] = pCStocks_2016_passvehicles.sum(axis =1)
if 'reb' in SectorList:
pC_AgeCohortHist[Sector_reb_loc, :] = pCStocks_2016_resbuildings.sum(axis =1)
if 'nrb' in SectorList:
pC_AgeCohortHist[Sector_nrb_loc, :] = pCStocks_2016_nresbuildings.sum(axis =1)
OutputDict['pC_AgeCohortHist'] = pC_AgeCohortHist.copy()
# b) from future stock curves:
#This is done for the individual sector calculations below.
# c) Total 2015 material stock, all in Mt!
if 'pav' in SectorList:
TotalMaterialStock_2015_pav = np.einsum('cgr,cmgr->mgr',ParameterDict['2_S_RECC_FinalProducts_2015_passvehicles'].Values[0,:,:,:],ParameterDict['3_MC_RECC_Vehicles_RECC'].Values[:,:,:,:,0])/1000
if 'reb' in SectorList:
TotalMaterialStock_2015_reb = np.einsum('cgr,cmgr->mgr',ParameterDict['2_S_RECC_FinalProducts_2015_resbuildings'].Values[0,:,:,:],ParameterDict['3_MC_RECC_Buildings_RECC'].Values[:,:,:,:,0])/1000
if 'nrb' in SectorList:
TotalMaterialStock_2015_nrb = np.einsum('cgr,cmgr->mgr',ParameterDict['2_S_RECC_FinalProducts_2015_nonresbuildings'].Values[0,:,:,:],ParameterDict['3_MC_RECC_NonResBuildings_RECC'].Values[:,:,:,:,0])/1000
# 23) Material and process-dependent electricity mix (with aluminium electricity mix)
# reshape electricity mix: oRit->PRit
Par_ElectricityMix_P = np.einsum('RIt,P->PRIt', ParameterDict['4_SHA_ElectricityMix_World'].Values[0,:,:,:], np.ones(NP) )
if ScriptConfig['Include_AluminiumElectricityMix'] == 'True':
# overwright aluminium energy mix
for mP in [PrimCastAl_loc,PrimWrAl_loc,EffCastAl_loc,EffWrAl_loc]:
Par_ElectricityMix_P[mP,:,:,:] = np.einsum('I,Rt->RIt',ParameterDict['4_SHA_ElectricityMix_World_Alu'].Values[0,0,:,0],np.ones((NR,Nt)))
# Time dependent extensions. Versions: o-version for generic energy use, material-version for primary production.
# This is needed because aluminium might have a separate electricity mix, depending on ScriptConfig
ParameterDict['4_PE_ProcessExtensions_EnergyCarriers_MJ_o'] = msc.Parameter(Name='4_PE_ProcessExtensions_EnergyCarriers_MJ_o', ID='4_PE_ProcessExtensions_EnergyCarriers_MJ_o',
UUID=None, P_Res=None, MetaData=None,
Indices='nxotR', Values=np.zeros((Nn,Nx,No,Nt,NR)), Uncert=None,
Unit='impact-eq/MJ')
ParameterDict['4_PE_ProcessExtensions_EnergyCarriers_MJ_Materials'] = msc.Parameter(Name='4_PE_ProcessExtensions_EnergyCarriers_MJ_material', ID='4_PE_ProcessExtensions_EnergyCarriers_MJ_material',
UUID=None, P_Res=None, MetaData=None,
Indices='mnxotR', Values=np.zeros((Nm,Nn,Nx,No,Nt,NR)), Uncert=None,
Unit='impact-eq/MJ') # For energy demand of material production
# replicate 2015 values. The current dataset contains only the 2015 initial value.
# Formula calculates impact / kg * kg /MJ = impact / MJ
# Electricity is added separately in the next step
ParameterDict['4_PE_ProcessExtensions_EnergyCarriers_MJ_o'].Values = np.einsum('nxo,n,tR->nxotR', ParameterDict['4_PE_ProcessExtensions_EnergyCarriers'].Values[:,:,:,0],ParameterDict['4_EI_SpecificEnergy_EnergyCarriers'].Values,np.ones((Nt,NR)))
ParameterDict['4_PE_ProcessExtensions_EnergyCarriers_MJ_Materials'].Values = np.einsum('nxo,n,tRm->mnxotR',ParameterDict['4_PE_ProcessExtensions_EnergyCarriers'].Values[:,:,:,0],ParameterDict['4_EI_SpecificEnergy_EnergyCarriers'].Values,np.ones((Nt,NR,Nm)))
# Replicate 2015 values for 4_PE_ProcessExtensions_Industry
ParameterDict['4_PE_ProcessExtensions_Industry'].Values = np.einsum('Ixo,t->Ixot',ParameterDict['4_PE_ProcessExtensions_Industry'].Values[:,:,:,0],np.ones((Nt)))
# add electricity calculated from electriciy mix
ParameterDict['4_PE_ProcessExtensions_EnergyCarriers_MJ_o'].Values[Electric_loc,:,:,:,:] = np.einsum('oRIt,Ixot->xotR',
ParameterDict['4_SHA_ElectricityMix_World'].Values, # MJ industry/MJ el
ParameterDict['4_PE_ProcessExtensions_Industry'].Values/3.6) # impact/MJ industry
ParameterDict['4_PE_ProcessExtensions_EnergyCarriers_MJ_Materials'].Values[:,Electric_loc,:,:,:,:] = np.einsum('oRIt,Ixot,m->mxotR',
ParameterDict['4_SHA_ElectricityMix_World'].Values, # MJ industry/MJ el
ParameterDict['4_PE_ProcessExtensions_Industry'].Values/3.6, # impact/MJ industry
np.ones((Nm)) )
if ScriptConfig['Include_AluminiumElectricityMix'] == 'True':
# overwrite aluminium energy mix
ParameterDict['4_PE_ProcessExtensions_EnergyCarriers_MJ_Materials'].Values[[WroughtAl_loc,CastAl_loc],Electric_loc,:,:,:,:] = np.einsum('oRIt,Ixot,m->mxotR',
ParameterDict['4_SHA_ElectricityMix_World_Alu'].Values, # MJ industry/MJ el
ParameterDict['4_PE_ProcessExtensions_Industry'].Values/3.6, # impact/MJ industry
np.ones((2)) )
# Now the same, but with extended regional scope for later use
ParameterDict['4_PE_ProcessExtensions_EnergyCarriers_MJ_r'] = msc.Parameter(Name='4_PE_ProcessExtensions_EnergyCarriers_MJ_r', ID='4_PE_ProcessExtensions_EnergyCarriers_MJ_r',
UUID=None, P_Res=None, MetaData=None,
Indices='nxrtR', Values=np.zeros((Nn,Nx,Nr,Nt,NR)), Uncert=None,
Unit='[impact unit]/MJ')
# replicate 2015 values. In current dataset is only initial value. Electricity is added separately in the next step
# Formula calculates impact / kg * kg /MJ = impact / MJ
ParameterDict['4_PE_ProcessExtensions_EnergyCarriers_MJ_r'].Values = np.einsum('nx,n,rtR->nxrtR',ParameterDict['4_PE_ProcessExtensions_EnergyCarriers'].Values[:,:,0,0],ParameterDict['4_EI_SpecificEnergy_EnergyCarriers'].Values,np.ones((Nr,Nt,NR)))
# add electricity calculated from electriciy mix
ParameterDict['4_PE_ProcessExtensions_EnergyCarriers_MJ_r'].Values[Electric_loc,:,:,:,:] = np.einsum('rRIt,Ixt->xrtR',
ParameterDict['4_SHA_ElectricityMix'].Values, # MJ industry/MJ el
ParameterDict['4_PE_ProcessExtensions_Industry'].Values[:,:,0,:]/3.6) # impact/MJ industry
# emission factors
EmissionFactorElectricity_r = ParameterDict['4_PE_ProcessExtensions_EnergyCarriers_MJ_r'].Values[Electric_loc,GWP100_loc,:,:,:]
EmissionFactorElectricity_o = ParameterDict['4_PE_ProcessExtensions_EnergyCarriers_MJ_o'].Values[Electric_loc,GWP100_loc,0,:,:]
# diagnostic
impact_elect = np.einsum('I,Ix->x',
ParameterDict['4_SHA_ElectricityMix_World'].Values[0,0,:,0], # MJ industry/MJ el
ParameterDict['4_PE_ProcessExtensions_Industry'].Values[:,:,0,0]/3.6, # impact/MJ industry
) # Impact/MJ el
# 24) Computing residuals(=process emissions) for material production processes
ParameterDict['4_PE_ProcessExtensions_Residual'] = msc.Parameter(Name='4_PE_ProcessExtensions_Residual', ID='4_PE_ProcessExtensions_Residual',
UUID=None, P_Res=None, MetaData=None,
Indices='Pxt', Values=np.zeros((NP,Nx,Nt)), Uncert=None,
Unit='[impact unit]/kg')
# Fuel contributions
fuel_production = np.einsum('nx,n,Pn->Px',
ParameterDict['4_PE_ProcessExtensions_EnergyCarriers'].Values[:,:,0,0], # impact/kg fuel
ParameterDict['4_EI_SpecificEnergy_EnergyCarriers'].Values, # kg fuel/MJ fuel
ParameterDict['4_EI_ProcessEnergyIntensity'].Values[:,:,0,0] # MJ fuel/kg mat
) # Impact/kg mat
# Direct contributions
direct_impact = np.einsum('Xn,xX,Pn->Px',
ParameterDict['6_PR_DirectEmissions'].Values, # impact/MJ fuel
ParameterDict['6_MIP_CharacterisationFactors'].Values,
ParameterDict['4_EI_ProcessEnergyIntensity'].Values[:,:,0,0] # MJ fuel/kg mat
) # Impact/kg mat
# Electricity generation
elec_production = np.einsum('P,Pi,ix->Px',
ParameterDict['4_EI_ProcessEnergyIntensity'].Values[:,Electric_loc,0,0], # MJ el/kg mat
Par_ElectricityMix_P[:,0,:,0], # MJ industry/MJ el
ParameterDict['4_PE_ProcessExtensions_Industry'].Values[:,:,0,0]/3.6 # impact/MJ industry
) # Impact/kg mat
# compute residuals
residuals = ParameterDict['4_PE_ProcessExtensions_Materials'].Values[:,:,0,0] - fuel_production - direct_impact - elec_production # Index_ Px, Unit: [impact unit]/kg mat
# RCP production processes represent technologies that are not out there yet.
# They are modelled as the same production steps, with different energy inputs.
# Hence, the residual extensions (i.e. the process impacts) are the same as the Baseline technology.
residuals[EffCastAl_loc,:] = residuals[PrimCastAl_loc,:]
residuals[EffWrAl_loc,:] = residuals[PrimWrAl_loc,:]
residuals[H2CGSteel_loc,:] = residuals[PrimCGSteel_loc,:]
residuals[H2ASteel_loc,:] = residuals[PrimASteel_loc,:]
residuals[H2CastIron_loc,:] = residuals[PrimCastIron_loc,:]
residuals[H2SSteel_loc,:] = residuals[PrimSSteel_loc,:]
ParameterDict['4_PE_ProcessExtensions_Residual'].Values[:,:,0] = residuals
# Replicate residuals over time
ParameterDict['4_PE_ProcessExtensions_Residual'].Values = np.einsum('Px,t->Pxt',ParameterDict['4_PE_ProcessExtensions_Residual'].Values[:,:,0],np.ones((Nt)))
# 25) Dynamic primary production intensity for diagnostic purposes
MaterialProductionIntensity_P = \
np.einsum('Pxt,R->PxtR',
ParameterDict['4_PE_ProcessExtensions_Residual'].Values,
np.ones((NR))) + \
np.einsum('Xn,xX,Pnt,R->PxtR',
ParameterDict['6_PR_DirectEmissions'].Values[:,:],
ParameterDict['6_MIP_CharacterisationFactors'].Values,
ParameterDict['4_EI_ProcessEnergyIntensity'].Values[:,:,:,0],
np.ones((NR))) +\
np.einsum('nxtR,Pnt->PxtR',
ParameterDict['4_PE_ProcessExtensions_EnergyCarriers_MJ_o'].Values[:,:,0,:,:],
ParameterDict['4_EI_ProcessEnergyIntensity'].Values[:,:,:,0])
MaterialProductionIntensity_m = np.einsum('PxtR,tmRP->mxtR',
MaterialProductionIntensity_P,
ParameterDict['4_SHA_MaterialsTechnologyShare'].Values[0,:,:,:,:])
MaterialProductionIntensityGHG_m = MaterialProductionIntensity_m[:,GWP100_loc,:,:]
##########################################################
# Section 4) Initialize dynamic MFA model for RECC #
##########################################################
Mylog.info('Initialize dynamic MFA model for RECC')
Mylog.info('Define RECC system and processes.')
#Define arrays for result export:
Impacts_System_3579di = np.zeros((Nx,Nt,NS,NR))
Impacts_UsePhase_7d = np.zeros((Nx,Nt,NS,NR))
Impacts_OtherThanUsePhaseDirect = np.zeros((Nx,Nt,NS,NR))
Impacts_Materials_3di_9di = np.zeros((Nx,Nt,NS,NR)) # all processes and their energy supply chains except for manufacturing and use phase
Impacts_Vehicles_Direct = np.zeros((Nx,Nt,Nr,NS,NR)) # use phase only
Impacts_ReBuildgs_Direct = np.zeros((Nx,Nt,Nr,NS,NR)) # use phase only
Impacts_NRBuildgs_Direct = np.zeros((Nx,Nt,Nr,NS,NR)) # use phase only
Impacts_NRBuildgs_Direct_g = np.zeros((Nx,Nt,NS,NR)) # use phase only
#Impacts_NonResBuildings_Direct = np.zeros((Nx,Nt,Nr,NS,NR)) # use phase only
Impacts_Vehicles_indir = np.zeros((Nx,Nt,NS,NR)) # energy supply only
Impacts_AllBuildings_indir = np.zeros((Nx,Nt,NS,NR)) # energy supply only
#Impacts_NonResBuilding_id = np.zeros((Nx,Nt,NS,NR)) # energy supply only
Impacts_Manufact_5di_all = np.zeros((Nx,Nt,NS,NR))
Impacts_WasteMgt_9di_all = np.zeros((Nx,Nt,NS,NR))
Impacts_PrimaryMaterial_3di = np.zeros((Nx,Nt,NS,NR))
Impacts_PrimaryMaterial_3di_m = np.zeros((Nx,Nt,Nm,NS,NR))
Impacts_SecondaryMetal_di_m = np.zeros((Nx,Nt,Nm,NS,NR))
Impacts_UsePhase_7i_Scope2_El = np.zeros((Nx,Nt,NS,NR))
Impacts_UsePhase_7i_OtherIndir = np.zeros((Nx,Nt,NS,NR))
Impacts_MaterialCycle_5di_9di = np.zeros((Nx,Nt,NS,NR))
Impacts_RecyclingCredit = np.zeros((Nx,Nt,NS,NR))
Impacts_ForestCO2Uptake = np.zeros((Nx,Nt,NS,NR))
Impacts_ForestCO2Uptake_r = np.zeros((Nx,Nt,Nr,NS,NR))
Impacts_WoodCycle = np.zeros((Nx,Nt,NS,NR)) # net GHG impact of wood use: forest uptake + wood-related emissions from waste mgt. Pos sign for flow from system to environment.
Impacts_EnergyRecoveryWasteWood = np.zeros((Nx,Nt,NS,NR))
Impacts_ByEnergyCarrier_UsePhase_d = np.zeros((Nx,Nt,Nr,Nn,NS,NR))
Impacts_ByEnergyCarrier_UsePhase_i = np.zeros((Nx,Nt,Nr,Nn,NS,NR))