-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_dataset.py
226 lines (189 loc) · 8.21 KB
/
generate_dataset.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
# -*- coding: utf-8 -*-
"""
Created on Fri Mar 10 15:05:09 2023
@author: fabic
"""
import pandas as pd
import openpyxl
from statistics import mean
from tqdm import tqdm
import numpy as np
import Infrastructures_classification as ifr
dataset_generation = { # SELECT THE DATASET TO GENERATE
'3_MC_RECC_Infrastructures': False,
'2_S_RECC_FinalProducts_2015_infrastructures': True,
'3_LT_RECC_ProductLifetime_infrastructures': False,
'3_MC_RECC_Buildings_Renovation_Relative': False,
'2_S_RECC_FinalProducts_Future_infrastructures': True
}
data = ifr.materials_data
if dataset_generation['3_MC_RECC_Infrastructures'] == True:
# Generate a TABLE for infrastructure material composition
# ROWS: Sectors_infrastructures, SSP_Regions_32
# COLUMNS: Engineering_Materials_m2
dataset = openpyxl.Workbook()
sheet = dataset.active
sheet.cell(1,1).value = 'i'
sheet.cell(1,2).value = 'r'
Rix = 1 # Row index
Cix = 3 # Column index
for m in ifr.Engineering_Materials_m2:
sheet.cell(Rix,Cix).value = m
Cix +=1
# Loop over columns and rows
Rix = 2
for r in ifr.SSP_Regions_32:
for i in ifr.Sectors_infrastructures:
sheet.cell(Rix,1).value = i
sheet.cell(Rix,2).value = r
Cix = 3
for m in ifr.Engineering_Materials_m2:
sheet.cell(Rix,Cix).value = mean(ifr.materials_data[(
ifr.materials_data['GRIP region'] == ifr.GRIP_region[ifr.SSP_Regions_32[r][0]])
& (ifr.materials_data['Country Alpha-3 Code'] == ifr.SSP_Regions_32[r][1])
& (ifr.materials_data['GRIP road type'] == ifr.Sectors_infrastructures[i][1]) ][ifr.Engineering_Materials_m2[m]] )
Cix+=1
Rix+=1
dataset.save('3_MC_RECC_Infrastructures.xlsx')
print('3_MC_RECC_Infrastructures generated!')
if dataset_generation['3_LT_RECC_ProductLifetime_infrastructures'] == True:
# Generate a LIST for infrastructure lifetime
# COLUMNS: Sectors_infrastructures, SSP_Regions_32
dataset = openpyxl.Workbook()
sheet = dataset.active
sheet.cell(1,1).value = 'i'
sheet.cell(1,2).value = 'r'
sheet.cell(1,3).value = 'Value'
sheet.cell(1,4).value = 'Unit'
# Loop over columns and rows
Rix = 2 #Row index
for r in ifr.SSP_Regions_32:
for i in ifr.Sectors_infrastructures:
sheet.cell(Rix,1).value = i
sheet.cell(Rix,2).value = r
sheet.cell(Rix,3).value = ifr.Infrastructures_lifetime[i]
sheet.cell(Rix,4).value = 'yr'
Rix +=1
dataset.save('3_LT_RECC_ProductLifetime_infrastructures.xlsx')
print('3_LT_RECC_ProductLifetime_infrastructures generated!')
if dataset_generation['3_MC_RECC_Buildings_Renovation_Relative'] == True:
# Generate a TABLE for infrastructure renovation
# ROWS: Time, Engineering_Materials_m2
# COLUMNS: Sectors_infrastructures, SSP_Regions_32
dataset = openpyxl.Workbook()
sheet = dataset.active
# Loop over columns and rows
Rix = 3 #Row index
for t in ifr.Time:
for m in ifr.Engineering_Materials_m2:
Cix = 3 #Row index
for r in ifr.SSP_Regions_32:
for i in ifr.Sectors_infrastructures:
sheet.cell(Rix,1).value = t
sheet.cell(Rix,2).value = m
sheet.cell(1,Cix).value = i
sheet.cell(2,Cix).value = r
sheet.cell(Rix,Cix).value = ifr.Infrastructures_maintenance_r[r][i]
Cix+=1
Rix+=1
dataset.save('3_MC_RECC_Infrastructures_Maintenance_Relative.xlsx')
print('3_MC_RECC_Buildings_Maintenance_Relative generated!')
if dataset_generation['2_S_RECC_FinalProducts_2015_infrastructures'] == True:
# Generate a TABLE for infrastructure stock in 2015
# ROWS: Time, Cohort
# COLUMNS: Sectors_infrastructures, SSP_Regions_32
dataset = openpyxl.Workbook()
sheet = dataset.active
# Loop over columns and rows
Rix = 3 #Row index
for c in ifr.Cohort2015:
Cix = 3 #Row index
for r in ifr.SSP_Regions_32:
for i in ifr.Sectors_infrastructures:
sheet.cell(Rix,1).value = '2015'
sheet.cell(Rix,2).value = c
sheet.cell(1,Cix).value = i
sheet.cell(2,Cix).value = r
if r in ['France','Germany','Italy','Spain','UK','Poland','R32USA','R32CAN','R32JPN']:
scale =1/len(ifr.Cohort2015) # model homogenous distribution
if r in ['Oth_R32EU12-H','R32EU12-M','Oth_R32EU15','R32CHN','R32IND','R5.2OECD_Other','R5.2REF_Other','R5.2ASIA_Other','R5.2LAM_Other','R5.2MNF_Other','R5.2SSA_Other']:
scale = 2 / (len(ifr.Cohort2015)) / (len(ifr.Cohort2015)+1) * (ifr.Cohort2015.index(c)+1)
sheet.cell(Rix,Cix).value = ifr.road_network_extension[r][i] *scale
Cix+=1
Rix+=1
# Add a sheet with total network extension.
# ROWS: SSP_Regions_32
# COLUMNS: total
dataset.create_sheet('Total')
sheet2 = dataset['Total']
sheet2.cell(1,2).value = 'Total'
Rix=2
for r in ifr.SSP_Regions_32:
sheet2.cell(Rix,1).value = r
sheet2.cell(Rix,2).value = sum(ifr.road_network_extension[r].values())
Rix+=1
# Add a sheet with initial type split.
# ROWS: SSP_Regions_32
# COLUMNS: Sectors_infrastructures
dataset.create_sheet('TypeSplit2015')
sheet2 = dataset['TypeSplit2015']
Rix = 1
Cix = 2
for i in ifr.Sectors_infrastructures:
sheet2.cell(Rix,Cix).value = i
Cix+=1
Rix = 2
for r in ifr.SSP_Regions_32:
Cix = 2
for i in ifr.Sectors_infrastructures:
sheet2.cell(Rix,1).value = r
sheet2.cell(Rix,Cix).value = ifr.road_network_extension[r][i] / sum(ifr.road_network_extension[r].values())
Cix+=1
Rix+=1
dataset.save('2_S_RECC_FinalProducts_2015_infrastructures_tcir.xlsx')
print('2_S_RECC_FinalProducts_2015_infrastructures_tcir generated!')
# Generate a TABLE for infrastructure stock in 2015
# ROWS: Time
# COLUMNS: Sectors_infrastructures, SSP_Regions_32
dataset = openpyxl.Workbook()
sheet = dataset.active
sheet.cell(1,1).value = 'r'
sheet.cell(1,2).value = 'i'
sheet.cell(1,3).value = '2015'
Rix=2
for r in ifr.SSP_Regions_32:
for i in ifr.Sectors_infrastructures:
sheet.cell(Rix,1).value = r
sheet.cell(Rix,2).value = i
sheet.cell(Rix,3).value = ifr.road_network_extension[r][i]
Rix+=1
dataset.save('2_S_RECC_FinalProducts_2015_infrastructures_rit.xlsx')
print('2_S_RECC_FinalProducts_2015_infrastructures_rit generated!')
if dataset_generation['2_S_RECC_FinalProducts_Future_infrastructures'] == True:
# Placeholder
# Generate a TABLE for infrastructure stock in 2015
# ROWS: Region, Infrastructure, Time
# COLUMNS: Scenario
dataset = openpyxl.Workbook()
sheet = dataset.active
sheet.cell(1,1).value = 'r'
sheet.cell(1,2).value = 'i'
sheet.cell(1,3).value = 't'
Cix = 4
for s in ifr.Scenarios:
sheet.cell(1,Cix).value = s
Cix +=1
Rix = 2
for r in ifr.SSP_Regions_32:
for i in ifr.Sectors_infrastructures:
for t in ifr.Time:
Cix = 4
for s in ifr.Scenarios:
sheet.cell(Rix,1).value = r
sheet.cell(Rix,2).value = i
sheet.cell(Rix,3).value = t
sheet.cell(Rix,Cix).value = ifr.road_network_extension[r][i]
Cix+=1
Rix+=1
dataset.save('2_S_RECC_FinalProducts_Future_infrastructures.xlsx')
print('2_S_RECC_FinalProducts_Future_infrastructures generated!')