Skip to content

Commit

Permalink
export historic stock and refined plots, smaller fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
= committed Jan 29, 2024
1 parent cf54225 commit 7abb6be
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 64 deletions.
33 changes: 25 additions & 8 deletions ODYM_RECC_Main.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,12 +733,15 @@ def main():
# 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,:,Service_Drivg,:,:,:] = ParameterDict['3_EI_Products_UsePhase_passvehicles'].Values[0:115,:,Service_Drivg,:,:,:] * np.einsum('r,cpnS->cpnrS',ParameterDict['6_PR_Calibration'].Values[1,:],np.ones((115,Np,Nn,NS)))
# Calibrate vehicle fuel consumption, cgVnrS
if 'pav' in SectorList:
ParameterDict['3_EI_Products_UsePhase_passvehicles'].Values[0:115,:,Service_Drivg,:,:,:] = ParameterDict['3_EI_Products_UsePhase_passvehicles'].Values[0:115,:,Service_Drivg,:,:,:] * 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,:,[Heating_loc,Cooling_loc,DomstHW_loc],:,:,:,:] = ParameterDict['3_EI_Products_UsePhase_resbuildings'].Values[0:115,:,[Heating_loc,Cooling_loc,DomstHW_loc],:,:,:,:] * np.einsum('r,cBVnSR->cBVnrSR',ParameterDict['6_PR_Calibration'].Values[2,:],np.ones((115,NB,3,Nn,NS,NR)))
if 'reb' in SectorList:
ParameterDict['3_EI_Products_UsePhase_resbuildings'].Values[0:115,:,[Heating_loc,Cooling_loc,DomstHW_loc],:,:,:,:] = ParameterDict['3_EI_Products_UsePhase_resbuildings'].Values[0:115,:,[Heating_loc,Cooling_loc,DomstHW_loc],:,:,:,:] * np.einsum('r,cBVnSR->cBVnrSR',ParameterDict['6_PR_Calibration'].Values[2,:],np.ones((115,NB,3,Nn,NS,NR)))
# Calibrate nonres. building energy consumption
ParameterDict['3_EI_Products_UsePhase_nonresbuildings'].Values[0:115,:,[Heating_loc,Cooling_loc,DomstHW_loc],:,:,:,:] = ParameterDict['3_EI_Products_UsePhase_nonresbuildings'].Values[0:115,:,[Heating_loc,Cooling_loc,DomstHW_loc],:,:,:,:] * np.einsum('r,cNVnSR->cNVnrSR',ParameterDict['6_PR_Calibration'].Values[3,:],np.ones((115,NN,3,Nn,NS,NR)))
if 'nrb' in SectorList:
ParameterDict['3_EI_Products_UsePhase_nonresbuildings'].Values[0:115,:,[Heating_loc,Cooling_loc,DomstHW_loc],:,:,:,:] = ParameterDict['3_EI_Products_UsePhase_nonresbuildings'].Values[0:115,:,[Heating_loc,Cooling_loc,DomstHW_loc],:,:,:,:] * np.einsum('r,cNVnSR->cNVnrSR',ParameterDict['6_PR_Calibration'].Values[3,:],np.ones((115,NN,3,Nn,NS,NR)))

# 12) No recycling scenario (counterfactual reference)
if ScriptConfig['IncludeRecycling'] == 'False': # no recycling and remelting
Expand Down Expand Up @@ -1398,6 +1401,7 @@ def main():

Stock_Detail_UsePhase_B = np.zeros((Nt,Nc,NB,Nr)) # index structure: tcBr. Unit: million m².
Stock_2020_decline_B = np.zeros((Nt,NB,Nr)) # index structure: tBr. Unit: million m².
Stock_2020_agestruct_B = np.zeros((Nc,NB,Nr)) # index structure: cBr. Unit: million m².
Outflow_Detail_UsePhase_B = np.zeros((Nt,Nc,NB,Nr)) # index structure: tcBr. Unit: million m².
Inflow_Detail_UsePhase_B = np.zeros((Nt,NB,Nr)) # index structure: tBr. Unit: million m².

Expand Down Expand Up @@ -1639,6 +1643,7 @@ def main():
Stock_Detail_UsePhase_B[0,:,:,r] += InitialStock.copy() # cgr, needed for correct calculation of mass balance later.
Stock_Detail_UsePhase_B[1::,:,:,r] += Var_S[SwitchTime::,:,:].copy() # tcBr
Stock_2020_decline_B[1::,:,r] += Var_S[SwitchTime::,0:Ind_2020+1,:].copy().sum(axis=1) # tBr
Stock_2020_agestruct_B[:,:,r] += Var_S[Ind_2020,:,:].copy() # cBr
Outflow_Detail_UsePhase_B[1::,:,:,r] += Var_O[SwitchTime::,:,:].copy() # tcBr
Inflow_Detail_UsePhase_B[1::,:,r] += Var_I[SwitchTime::,:].copy() # tBr
# Check for negative inflows:
Expand Down Expand Up @@ -3767,18 +3772,30 @@ def main():
#DF_GHGA_global.to_excel(os.path.join(ProjectSpecs_Path_Result,'GHG_Area_Data.xlsx'), merge_cells=False)

# Export total material stock
ColIndex = IndexTable.Classification[IndexTable.index.get_loc('Engineering materials')].Items
ColIndex_m = IndexTable.Classification[IndexTable.index.get_loc('Engineering materials')].Items
ColIndex_t = IndexTable.Classification[IndexTable.index.get_loc('Time')].Items
ColIndex_c = IndexTable.Classification[IndexTable.index.get_loc('Cohort')].Items
if 'pav' in SectorList:
RowIndex = pd.MultiIndex.from_product([IndexTable.Classification[IndexTable.index.get_loc('Region_Focus')].Items,IndexTable.Classification[IndexTable.index.get_loc('Cars')].Items], names=('Region','Stock_Item'))
DF_matstock2015 = pd.DataFrame(np.einsum('mpr->rpm',TotalMaterialStock_2015_pav).reshape(Nr*Np,Nm), index=RowIndex, columns=ColIndex)
DF_matstock2015 = pd.DataFrame(np.einsum('mpr->rpm',TotalMaterialStock_2015_pav).reshape(Nr*Np,Nm), index=RowIndex, columns=ColIndex_m)
DF_matstock2015.to_excel(pd_xlsx_writer, sheet_name="RECC_matstock_2015_pav_Mt", merge_cells=False)
if 'reb' in SectorList:
RowIndex = pd.MultiIndex.from_product([IndexTable.Classification[IndexTable.index.get_loc('Region_Focus')].Items,IndexTable.Classification[IndexTable.index.get_loc('ResidentialBuildings')].Items], names=('Region','Stock_Item'))
DF_matstock2015 = pd.DataFrame(np.einsum('mBr->rBm',TotalMaterialStock_2015_reb).reshape(Nr*NB,Nm), index=RowIndex, columns=ColIndex)
DF_matstock2015 = pd.DataFrame(np.einsum('mBr->rBm',TotalMaterialStock_2015_reb).reshape(Nr*NB,Nm), index=RowIndex, columns=ColIndex_m)
DF_matstock2015.to_excel(pd_xlsx_writer, sheet_name="RECC_matstock_2015_reb_Mt", merge_cells=False)
# Export pre 2021 age-cohorts building stock, customized export for Jan Streeck building stock comparison
DF_2020_lockin = pd.DataFrame(np.einsum('tBr->rBt',Stock_2020_decline_B).reshape(Nr*NB,Nt), index=RowIndex, columns=ColIndex_t)
DF_2020_lockin.to_excel(pd_xlsx_writer, sheet_name="RECC_2020_lockin_reb_Mm2", merge_cells=False)
DF_2020_agestru = pd.DataFrame(np.einsum('cBr->rBc',Stock_2020_agestruct_B).reshape(Nr*NB,Nc), index=RowIndex, columns=ColIndex_c)
DF_2020_agestru.to_excel(pd_xlsx_writer, sheet_name="RECC_2020_AgeStructure_reb_Mm2", merge_cells=False)
RowIndex = pd.MultiIndex.from_product([IndexTable.Classification[IndexTable.index.get_loc('Region_Focus')].Items,IndexTable.Classification[IndexTable.index.get_loc('Engineering materials')].Items], names=('Region','Material'))
DF_2020_materia = pd.DataFrame(np.einsum('Btcm->mt',RECC_System.StockDict['S_7'].Values[:,0:Ind_2020+1,0,Sector_reb_rge,:,0]).reshape(Nr*Nm,Nt), index=RowIndex, columns=ColIndex_t)
DF_2020_materia.to_excel(pd_xlsx_writer, sheet_name="RECC_2020_lockin_reb_Mt", merge_cells=False)
DF_2020_agestrm = pd.DataFrame(np.einsum('Bcm->mc',RECC_System.StockDict['S_7'].Values[Ind_2020-SwitchTime,:,0,Sector_reb_rge,:,0]).reshape(Nr*Nm,Nc), index=RowIndex, columns=ColIndex_c)
DF_2020_agestrm.to_excel(pd_xlsx_writer, sheet_name="RECC_2020_AgeStructure_reb_Mt", merge_cells=False)
if 'nrb' in SectorList:
RowIndex = pd.MultiIndex.from_product([IndexTable.Classification[IndexTable.index.get_loc('Region_Focus')].Items,IndexTable.Classification[IndexTable.index.get_loc('NonresidentialBuildings')].Items], names=('Region','Stock_Item'))
DF_matstock2015 = pd.DataFrame(np.einsum('mNr->rNm',TotalMaterialStock_2015_nrb).reshape(Nr*NN,Nm), index=RowIndex, columns=ColIndex)
DF_matstock2015 = pd.DataFrame(np.einsum('mNr->rNm',TotalMaterialStock_2015_nrb).reshape(Nr*NN,Nm), index=RowIndex, columns=ColIndex_m)
DF_matstock2015.to_excel(pd_xlsx_writer, sheet_name="RECC_matstock_2015_nrb_Mt", merge_cells=False)

pd_xlsx_writer.close()
Expand Down
4 changes: 2 additions & 2 deletions ODYM_RECC_ScenarioControl.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import ODYM_RECC_Main

#ScenarioSetting, sheet name of RECC_ModelConfig_List.xlsx to be selected:
#ScenarioSetting = 'Test'
ScenarioSetting = 'Buildings_Global_Config_list'
ScenarioSetting = 'Test'
#ScenarioSetting = 'Buildings_Global_Config_list'
#ScenarioSetting = 'Glob_BLd_MediumWood'
#ScenarioSetting = 'CRAFT_Coupling_Config_list'
#ScenarioSetting = 'pav_reb_Config_list_all'
Expand Down
10 changes: 5 additions & 5 deletions plots/RECC_Building_Plots_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,7 @@
title_add = ptitles[m]
Data1 = np.zeros((7,46)) # For first scenario
Data2 = np.zeros((7,46)) # For second scenario
Regio = 'Global'
Regio = pregs[m]
Inds = ['GHG emissions, buildings, use phase','GHG emissions, use phase scope 2 (electricity)','GHG emissions, use phase other indirect (non-el.)','GHG emissions, primary material production','GHG emissions, manufact, wast mgt., remelting and indirect','GHG sequestration by forests (w. neg. sign)','GHG emissions, system-wide (incl. forests)']
# Fetch data
for indi in range(0,7):
Expand Down Expand Up @@ -1058,7 +1058,7 @@
axyl = ax1.get_ylim()
plt.plot([2061.5,2061.5],[axyl[0],axyl[1]],linestyle = '--', linewidth = 0.8, color = 'k')

plt.title(ptitles[m], fontsize = 18)
plt.title(ptitles[m] + '_' + Regio, fontsize = 18)
plt.ylabel(r'Mt of CO$_2$-eq.', fontsize = 18)
plt.xlabel('Year', fontsize = 18)
plt.xticks(fontsize=17)
Expand All @@ -1068,10 +1068,10 @@
ax1.set_ylim(axyl)
plt.xticks([2020,2030,2040,2050,2060,2065.5])
ax1.set_xticklabels(['2020','2030','2040','2050','2060','2060'], rotation = 0, fontsize = 17, fontweight = 'normal', rotation_mode="default")
plt.text(2040, -2300, selectS[0] ,fontsize=18, fontweight='normal', color = 'k', horizontalalignment='left')
plt.text(2059, -2300, selectS[1] ,fontsize=18, fontweight='normal', color = 'k', horizontalalignment='left')
plt.text(2040, 0.5 * axyl[0], selectS[0] ,fontsize=18, fontweight='normal', color = 'k', horizontalalignment='left')
plt.text(2059, 0.5 * axyl[0], selectS[1] ,fontsize=18, fontweight='normal', color = 'k', horizontalalignment='left')
plt.show()
fig.savefig(os.path.join(os.path.join(RECC_Paths.export_path,outpath), ptitles[m] + '.png'), dpi=150, bbox_inches='tight')
fig.savefig(os.path.join(os.path.join(RECC_Paths.export_path,outpath), ptitles[m] + '_' + Regio + '.png'), dpi=150, bbox_inches='tight')


if ptypes[m] == 'Sankey_Haas_Export':
Expand Down
77 changes: 28 additions & 49 deletions plots/RECC_ESC_Plot_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def get_esc_data_from_pandas(ps,selectI,selectR,cscenss):
plt.tight_layout()
plt.show()
title = ctitles[c]
fig.savefig(os.path.join(os.path.join(RECC_Paths.export_path,outpath), title + '.png'), dpi=150, bbox_inches='tight')
fig.savefig(os.path.join(os.path.join(RECC_Paths.export_path,outpath), title + '_' + selectR[0] + '.png'), dpi=150, bbox_inches='tight')


if ctypes[c] == 'version_3':
Expand Down Expand Up @@ -344,71 +344,50 @@ def get_esc_data_from_pandas(ps,selectI,selectR,cscenss):
cc = np.array([[128,128,128,255],[48,84,150,255],[198,89,17,255],[142,105,0,255],[112,48,160,255]])/255 # grey, blue, red, brown, purple

# Plot results
fig, axs = plt.subplots(nrows=1, ncols=8 , figsize=(24, 3))
fig, axs = plt.subplots(nrows=1, ncols=5 , figsize=(16, 3))
fig.suptitle('Energy and material service cascade, ' + cregs[c],fontsize=18)
ProxyHandlesList = [] # For legend

plt.rcParams["axes.prop_cycle"] = plt.cycler("color", cc)

axs[0].plot(np.arange(2016,2061), esc_data[0,1::,:], linewidth = 3)
plta = Line2D(np.arange(2016,2061), esc_data[0,1::,:], linewidth = 3)
ProxyHandlesList.append(plta) # create proxy artist for legend
axs[0].set_title('Energy-GHG per capita = ', weight='bold')
axs[0].set_ylabel('t CO2-eq/yr', fontsize = 12)
#axs[0].set_facecolor((221/255, 235/255, 247/255))
axs[0].set_facecolor((197/255, 221/255, 241/255))

axs[0].plot(np.arange(2016,2061), esc_data[3,1::,:], linewidth = 3.0)
axs[0].set_title('Stock per capita', weight='bold')
axs[0].set_ylabel('m²', fontsize = 12)
axs[0].set_facecolor((237/255, 226/255, 246/255))
axs[0].set_ylim(bottom=0)

axs[1].plot(np.arange(2016,2061), esc_data[1,1::,:] * 1e6, linewidth = 2.0)
axs[1].set_title('GHG per final energy *')
axs[1].set_ylabel('g CO2-eq/MJ', fontsize = 12)
axs[1].set_facecolor((238/255, 245/255, 252/255))
axs[1].plot(np.arange(2016,2061), esc_data[9,1::,:], linewidth = 2.0)
axs[1].set_title('* inflow per stock')
axs[1].set_ylabel('1/yr)', fontsize = 12)
axs[1].set_facecolor((253/255, 239/255, 231/255))
axs[1].set_ylim(bottom=0)
axs[2].plot(np.arange(2016,2061), esc_data[2,1::,:], linewidth = 2.0)
axs[2].set_title('Final energy per stock *')
axs[2].set_ylabel('MJ/(m²·yr)', fontsize = 12)
axs[2].set_facecolor((238/255, 245/255, 252/255))
axs[2].set_ylim(bottom=0)

axs[3].plot(np.arange(2016,2061), esc_data[3,1::,:], linewidth = 3.0)
axs[3].set_title(' <-- | --> \n Stock per capita', weight='bold')
axs[3].set_ylabel('', fontsize = 12)
axs[3].set_facecolor((237/255, 226/255, 246/255))

axs[2].plot(np.arange(2016,2061), esc_data[4,1::,:] * 1e3, linewidth = 2.0)
axs[2].set_title('* material intensity of inflow')
axs[2].set_ylabel('kg/m²', fontsize = 12)
axs[2].set_facecolor((253/255, 239/255, 231/255))
axs[2].set_ylim(bottom=0)

axs[3].plot(np.arange(2016,2061), esc_data[7,1::,:], linewidth = 2.0)
axs[3].set_title('* RMI per material')
axs[3].set_ylabel('t/t', fontsize = 12)
axs[3].set_facecolor((253/255, 239/255, 231/255))
axs[3].set_ylim(bottom=0)

axs[4].plot(np.arange(2016,2061), esc_data[9,1::,:], linewidth = 2.0)
axs[4].set_title('* inflow per stock')
axs[4].set_ylabel('1/yr)', fontsize = 12)
axs[4].set_facecolor((253/255, 239/255, 231/255))
axs[4].plot(np.arange(2016,2061), esc_data[8,1::,:], linewidth = 3.0)
axs[4].set_title('= RMI per capita', weight='bold')
axs[4].set_ylabel('t/yr', fontsize = 12)
#axs[4].set_facecolor((252/255, 228/255, 214/255))
axs[4].set_facecolor((249/255, 203/255, 177/255))
axs[4].set_ylim(bottom=0)

axs[5].plot(np.arange(2016,2061), esc_data[4,1::,:] * 1e3, linewidth = 2.0)
axs[5].set_title('* material intensity of inflow')
axs[5].set_ylabel('kg/m²', fontsize = 12)
axs[5].set_facecolor((253/255, 239/255, 231/255))
axs[5].set_ylim(bottom=0)

axs[6].plot(np.arange(2016,2061), esc_data[7,1::,:], linewidth = 2.0)
axs[6].set_title('* RMI per material')
axs[6].set_ylabel('t/t', fontsize = 12)
axs[6].set_facecolor((253/255, 239/255, 231/255))
axs[6].set_ylim(bottom=0)

axs[7].plot(np.arange(2016,2061), esc_data[8,1::,:], linewidth = 3.0)
axs[7].set_title('= RMI per capita', weight='bold')
axs[7].set_ylabel('t/yr', fontsize = 12)
#axs[7].set_facecolor((252/255, 228/255, 214/255))
axs[7].set_facecolor((249/255, 203/255, 177/255))
axs[7].set_ylim(bottom=0)

Labels = cscenss

fig.legend(Labels, shadow = False, prop={'size':14},ncol=5, loc = 'upper center',bbox_to_anchor=(0.5, -0.02))
plt.tight_layout()
plt.show()
title = ctitles[c]
fig.savefig(os.path.join(os.path.join(RECC_Paths.export_path,outpath), title + '.png'), dpi=150, bbox_inches='tight')
fig.savefig(os.path.join(os.path.join(RECC_Paths.export_path,outpath), title + '_' + selectR[0] + '.png'), dpi=150, bbox_inches='tight')

#
#
Expand Down

0 comments on commit 7abb6be

Please sign in to comment.