-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
153 lines (117 loc) · 5.52 KB
/
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
"""
Import the Exiobase database from a *.mat-file.
EXIOBASE 3rx
- 214 Regions
- 200 Categories/Products
- 12 Value added categories
- 7 Final demand categories (7*214 = 1498)
- Basic pricing
- Monetary unit: Million Euros (current prices)
| Value | Size | Field | Description |
|-----------------------|-----------------|-------|--------------------------|
| sparse.csc.csc_matrix | (452, 42800) | S | Stressor matrix |
| | | | per monetary unit |
|-----------------------|-----------------|-------|--------------------------|
| sparse.csc.csc_matrix | (42800, 42800) | A | The coefficient matrix |
| | | | (inputs required |
| | | | per unit of output) |
|-----------------------|-----------------|-------|--------------------------|
| sparse.csc.csc_matrix | (12, 42800) | V | Value added matrix |
|-----------------------|-----------------|-------|--------------------------|
| sparse.csc.csc_matrix | (42800, 1498) | Y | Final demand matrix |
|-----------------------|-----------------|-------|--------------------------|
| sparse.csc.csc_matrix | (42800, 1) | x | Vector of total output |
|-----------------------|-----------------|-------|--------------------------|
| Array of float64 | (200, 214, 214) | TC | Trade cube |
| | | | (product x exporter |
| | | | x importer) |
|-----------------------|-----------------|-------|--------------------------|
| sparse.csc.csc_matrix | (452, 42800) | F | Total stressor matrix |
|-----------------------|-----------------|-------|--------------------------|
| sparse.csc.csc_matrix | (452, 1498) | F_hh | Total household |
| | | | stressor matrix |
|-----------------------|-----------------|-------|--------------------------|
| Array of void256 | (1,) | pop | Population per country |
|-----------------------|-----------------|-------|--------------------------|
| Array of void256 | (1,) | gdp | GDP per country |
|-----------------------|-----------------|-------|--------------------------|
| sparse.csc.csc_matrix | (12, 1498) | VY | Value added final demand |
|-----------------------|-----------------|-------|--------------------------|
"""
import pandas as pd
import scipy.io
# %% Import labels
exio_labs_f = pd.read_csv('./data/exiobase-3rx/labs/f.csv') # 452
exio_labs_v = pd.read_csv('./data/exiobase-3rx/labs/v.csv') # 12
exio_labs_y = pd.read_csv('./data/exiobase-3rx/labs/y.csv') # 7*214 = 1498
exio_labs_z = pd.read_csv('./data/exiobase-3rx/labs/z.csv') # 200*214 = 42800
# %% Import matrices
exiobase = scipy.io.loadmat(
'./data/exiobase-3rx/EXIOBASE_3rx_aggLandUseExtensions_2010_pxp.mat'
)
# Create a dictionary and save selected elements from
# `exiobase` in the dicionary
exio_db_sparse = {}
for key, item in zip(
['S', 'A', 'V', 'Y', 'x', 'TC', 'F', 'F_hh', 'pop', 'gdp', 'VY'],
exiobase['IO'].item()
):
exio_db_sparse[key] = item
exio_db_sparse['header'] = exiobase['__header__']
exio_db_sparse['version'] = exiobase['__version__']
del key, item
del exiobase
# %% Turn sparse matrices into pd.DataFrames with indices
exio_db_dense = {}
exio_db_dense['header'] = exio_db_sparse['header']
exio_db_dense['version'] = exio_db_sparse['version']
exio_db_dense['regions'] = exio_labs_z['Exiobase - Region'].unique()
exio_db_dense['categories'] = exio_labs_z['Exiobase - Category'].unique()
# %%% A - The coefficient matrix (inputs required per unit of outputs)
exio_db_dense['A'] = pd.DataFrame(
exio_db_sparse['A'].todense(),
index=pd.MultiIndex.from_frame(exio_labs_z),
columns=pd.MultiIndex.from_frame(exio_labs_z)
)
# %%% F - Total stressor matrix (452, 42800)
exio_db_dense['F'] = pd.DataFrame(
exio_db_sparse['F'].todense(),
index=pd.MultiIndex.from_frame(exio_labs_f),
columns=pd.MultiIndex.from_frame(exio_labs_z)
)
# %%% F_hh - Total household stressor matrix (452, 1498)
exio_db_dense['F_hh'] = pd.DataFrame(
exio_db_sparse['F_hh'].todense(),
index=pd.MultiIndex.from_frame(exio_labs_f),
columns=pd.MultiIndex.from_frame(exio_labs_y)
)
# %%% S - Stressor matrix per monetary unit (452, 42800)
exio_db_dense['S'] = pd.DataFrame(
exio_db_sparse['S'].todense(),
index=pd.MultiIndex.from_frame(exio_labs_f),
columns=pd.MultiIndex.from_frame(exio_labs_z)
)
# %%% V - Value added matrix (12, 42800)
exio_db_dense['V'] = pd.DataFrame(
exio_db_sparse['V'].todense(),
index=pd.MultiIndex.from_frame(exio_labs_v),
columns=pd.MultiIndex.from_frame(exio_labs_z)
)
# %%% VY - Value added final demand (12, 1498)
exio_db_dense['VY'] = pd.DataFrame(
exio_db_sparse['VY'].todense(),
index=pd.MultiIndex.from_frame(exio_labs_v),
columns=pd.MultiIndex.from_frame(exio_labs_y)
)
# %%% x - Vector of total output (42800, 1)
exio_db_dense['x'] = pd.DataFrame(
exio_db_sparse['x'].todense(),
index=pd.MultiIndex.from_frame(exio_labs_z),
columns=['Exiobase - Total output']
)
# %%% Y Final demand matrix (42800, 1498)
exio_db_dense['Y'] = pd.DataFrame(
exio_db_sparse['Y'].todense(),
index=pd.MultiIndex.from_frame(exio_labs_z),
columns=pd.MultiIndex.from_frame(exio_labs_y)
)