Analysing the source of stressors (flow matrix)

To calculate the source (in terms of regions and sectors) of a certain stressor or impact driven by consumption, one needs to diagonalize this stressor/impact. This section shows how to do this based on the small test mrio included in pymrio. The same procedure can be use for any other MRIO, but keep in mind that diagonalizing a stressor dramatically increases the memory need for the calculations.

Basic example

First we load the test mrio:

[1]:
import pymrio
io = pymrio.load_test()

The test mrio includes several extensions:

[2]:
list(io.get_extensions())
[2]:
['factor_inputs', 'emissions']

For the example here, we use ‘emissions’ - ‘emission_type1’:

[3]:
io.emissions.F
[3]:
region reg1 reg2 ... reg5 reg6
sector food mining manufactoring electricity construction trade transport other food mining ... transport other food mining manufactoring electricity construction trade transport other
stressor compartment
emission_type1 air 1848064.80 986448.090 23613787.00 28139100.00 2584141.80 4132656.3 21766987.0 7842090.6 1697937.30 347378.150 ... 42299319 10773826.0 15777996.0 6420955.5 113172450.0 56022534.0 4861838.5 18195621 47046542.0 21632868
emission_type2 water 139250.47 22343.295 763569.18 273981.55 317396.51 1254477.8 1012999.1 2449178.0 204835.44 29463.944 ... 4199841 7191006.3 4826108.1 1865625.1 12700193.0 753213.7 2699288.3 13892313 8765784.3 16782553

2 rows × 48 columns

[4]:
et1_diag = io.emissions.diag_stressor(('emission_type1', 'air'), name = 'emtype1_diag')

The parameter name is optional, if not given the name is set to the stressor name + ‘_diag’

The new emission matrix now looks like this:

[5]:
et1_diag.F.head(15)
[5]:
region reg1 reg2 ... reg5 reg6
sector food mining manufactoring electricity construction trade transport other food mining ... transport other food mining manufactoring electricity construction trade transport other
region sector
reg1 food 1848064.8 0.00 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.00 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
mining 0.0 986448.09 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.00 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
manufactoring 0.0 0.00 23613787.0 0.0 0.0 0.0 0.0 0.0 0.0 0.00 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
electricity 0.0 0.00 0.0 28139100.0 0.0 0.0 0.0 0.0 0.0 0.00 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
construction 0.0 0.00 0.0 0.0 2584141.8 0.0 0.0 0.0 0.0 0.00 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
trade 0.0 0.00 0.0 0.0 0.0 4132656.3 0.0 0.0 0.0 0.00 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
transport 0.0 0.00 0.0 0.0 0.0 0.0 21766987.0 0.0 0.0 0.00 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
other 0.0 0.00 0.0 0.0 0.0 0.0 0.0 7842090.6 0.0 0.00 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
reg2 food 0.0 0.00 0.0 0.0 0.0 0.0 0.0 0.0 1697937.3 0.00 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
mining 0.0 0.00 0.0 0.0 0.0 0.0 0.0 0.0 0.0 347378.15 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
manufactoring 0.0 0.00 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.00 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
electricity 0.0 0.00 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.00 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
construction 0.0 0.00 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.00 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
trade 0.0 0.00 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.00 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
transport 0.0 0.00 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.00 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0

15 rows × 48 columns

And can be connected back to the system with:

[6]:
io.et1_diag = et1_diag

Finally we can calulate the all stressor accounts with:

[7]:
io.calc_all()
[7]:
<pymrio.core.mriosystem.IOSystem at 0x7f9c25d25d30>

This results in a square footprint matrix. In this matrix, every column respresents the amount of stressor occuring in each region - sector driven by the consumption stated in the column header. Conversly, each row states where the stressor impacts occuring in the row are distributed due (from where they are driven).

[8]:
io.et1_diag.D_cba.head(20)
[8]:
region reg1 reg2 ... reg5 reg6
sector food mining manufactoring electricity construction trade transport other food mining ... transport other food mining manufactoring electricity construction trade transport other
region sector
reg1 food 609347.998747 34.963223 1.987631e+05 7.678755e+02 2.873371e+03 5.603158e+04 1.448778e+03 5.225312e+04 4.826852e+04 0.453097 ... 74.449012 222.953289 25525.516392 6.557600 1.382548e+05 38.345126 408.937891 4.425472e+04 63.940215 4.876200e+02
mining 2527.449441 61271.249639 1.232716e+05 5.406781e+04 1.632967e+05 1.459774e+04 4.916876e+03 4.975184e+04 4.311608e+02 288.903690 ... 261.326848 829.871069 268.406793 1990.840054 7.400739e+04 6327.871035 299.916699 1.732632e+04 242.874444 4.038056e+03
manufactoring 1199.041530 38.236679 4.686837e+06 8.108636e+02 1.816229e+04 7.713610e+03 2.825229e+03 1.634290e+04 3.205155e+02 2.886944 ... 424.008556 517.344586 145.900439 72.195039 3.424703e+06 94.046696 129.127059 7.826193e+03 241.185186 9.015651e+02
electricity 148505.091902 12764.784297 1.519466e+06 1.167804e+07 5.265922e+05 1.307806e+06 4.851957e+05 4.308489e+06 1.908031e+04 240.730963 ... 9294.381551 28937.569016 7947.002552 476.106897 1.072302e+06 38647.049939 495.159380 9.712017e+05 3850.133826 9.804940e+03
construction 49.018479 6.053459 4.019302e+02 3.081457e+02 2.568908e+06 7.291250e+02 5.853107e+02 9.718253e+03 4.408230e+00 0.037972 ... 1.679791 4.461035 2.211530 0.213951 2.898921e+02 1.682977 12.667370 5.303592e+02 0.988979 3.859558e+00
trade 138.041355 3.139596 1.880042e+03 8.852940e+01 1.420349e+03 2.390871e+06 4.371531e+02 2.383210e+03 2.637857e+01 0.095853 ... 36.433641 50.392051 42.098945 1.141682 1.240785e+03 4.989788 14.192623 1.726377e+06 45.633464 4.276151e+01
transport 521.216924 122.504968 1.585636e+04 1.428149e+03 6.467383e+03 2.741408e+04 1.018383e+07 4.388313e+04 9.410163e+01 2.099087 ... 2854.767892 222.900909 568.393996 55.916912 1.130829e+04 285.596244 127.388007 2.198931e+04 8734.726973 1.309008e+03
other 537.062679 24.688020 7.752597e+03 1.170368e+03 8.587431e+03 1.322798e+04 4.448616e+03 7.516913e+06 6.837072e+01 0.767113 ... 56.726997 435.703359 36.640953 3.856648 5.346664e+03 20.750945 15.152425 1.029493e+04 58.278076 1.356728e+03
reg2 food 234.870108 0.041282 1.213308e+03 3.241119e+00 9.719899e+00 1.004924e+01 4.822982e-01 1.281313e+01 1.694248e+06 0.041642 ... 3.026472 0.475024 80.139206 0.025141 2.183449e+02 0.472522 7.011110 1.605455e+02 0.455175 3.092008e+00
mining 215.562762 1690.186670 5.892279e+04 1.862733e+03 7.746514e+02 7.570607e+02 1.582065e+02 2.302825e+03 1.787512e+03 10287.905967 ... 200.678830 58.083367 66.185618 1351.809333 1.430140e+04 2650.008184 42.230072 8.909866e+03 79.981946 3.551366e+03
manufactoring 75.621346 4.229463 7.185296e+06 6.763336e+01 7.171199e+02 4.429766e+02 1.914508e+02 1.076869e+03 9.941057e+02 5.361056 ... 352.701574 125.165588 44.659838 19.157594 1.140699e+06 19.220461 50.982784 3.009360e+03 74.837190 2.460570e+02
electricity 4.912183 4.392270 6.448813e+03 1.947867e+02 1.552407e+01 2.864877e+01 1.010699e+01 9.682693e+01 1.143809e+03 23.763711 ... 225.020323 2.614112 0.740525 3.162466 1.079151e+03 8.601151 0.254639 2.214440e+03 1.186302 1.102287e+01
construction 0.179274 0.201490 4.711030e+02 8.221412e-01 1.045043e+02 1.884894e+00 1.624084e+00 1.924495e+01 1.001309e+02 1.098256 ... 130.390027 4.804088 0.230208 0.152699 7.708346e+01 0.545433 47.750232 3.449526e+02 1.023520 5.208169e+00
trade 9.487802 0.442851 2.547850e+03 5.931388e+00 3.093165e+01 2.414790e+02 8.294245e+00 5.515915e+01 3.073687e+02 1.313536 ... 159.340296 69.421120 25.278297 0.783272 5.438996e+02 2.795486 8.852273 1.174931e+06 20.099409 2.543311e+01
transport 30.167917 11.691703 1.095783e+04 7.704484e+01 2.369344e+02 1.171461e+03 4.962901e+03 1.299130e+03 9.083313e+02 15.109529 ... 789093.398671 117.822465 101.020895 7.816896 2.491430e+03 51.079756 28.609582 8.615321e+03 2234.585845 4.125342e+02
other 4.710152 0.999656 3.487999e+03 1.504331e+01 6.607788e+01 8.958452e+01 3.266330e+01 1.104173e+03 2.621005e+02 3.670327 ... 376.984093 213.700696 7.178914 1.523151 6.818453e+02 7.576198 7.380601 3.072026e+03 37.695142 7.442119e+02
reg3 food 79.487995 0.012420 2.707179e+03 3.212251e-01 1.118965e+00 8.545640e+00 3.848642e-01 2.342262e+01 6.321926e+01 0.001120 ... 0.660378 1.095579 96.427089 0.060430 1.350698e+03 0.136524 0.253732 5.444486e+02 0.330214 1.007920e+02
mining 1.660826 9.283144 2.805174e+03 4.683637e+00 3.721404e+00 1.903501e+01 1.984584e+00 1.130052e+02 1.043411e+00 1.482323 ... 1.579297 4.760043 1.028577 9.018513 1.370585e+03 19.208836 0.609243 7.625285e+02 1.234952 6.075141e+02
manufactoring 256.950787 12.496966 1.951101e+07 1.576456e+02 1.369020e+03 9.774252e+02 4.651207e+02 9.975075e+03 2.274549e+02 2.093210 ... 856.521423 1696.838781 304.748914 109.539716 9.493385e+06 71.802017 260.584083 6.010179e+04 587.491671 3.817698e+04
electricity 346.618944 75.166170 3.907669e+06 8.377082e+03 1.955704e+03 3.618932e+03 1.930657e+03 5.954611e+05 9.697584e+02 33.309324 ... 1833.141385 6869.669139 1750.805701 1639.927136 1.908654e+06 44575.821242 628.061059 6.364065e+06 4888.472424 3.661473e+06

20 rows × 48 columns

The total footprints of a region - sector are given by summing the footprints along rows:

[9]:
io.et1_diag.D_cba.sum(axis=0).reg1
[9]:
sector
food             2.056183e+06
mining           1.794235e+05
manufactoring    9.749300e+07
electricity      1.188759e+07
construction     3.342906e+06
trade            3.885884e+06
transport        1.075027e+07
other            1.582152e+07
dtype: float64
[10]:
io.emissions.D_cba.reg1
[10]:
sector food mining manufactoring electricity construction trade transport other
stressor compartment
emission_type1 air 2.056183e+06 179423.535893 9.749300e+07 1.188759e+07 3.342906e+06 3.885884e+06 1.075027e+07 1.582152e+07
emission_type2 water 2.423103e+05 25278.192086 1.671240e+07 1.371303e+05 3.468292e+05 7.766205e+05 4.999628e+05 8.480505e+06

The total stressor in a sector corresponds to the sum of the columns:

[11]:
io.et1_diag.D_cba.sum(axis=1).reg1
[11]:
sector
food              1848064.80
mining             986448.09
manufactoring    23613787.00
electricity      28139100.00
construction      2584141.80
trade             4132656.30
transport        21766987.00
other             7842090.60
dtype: float64
[12]:
io.emissions.F.reg1
[12]:
sector food mining manufactoring electricity construction trade transport other
stressor compartment
emission_type1 air 1848064.80 986448.090 23613787.00 28139100.00 2584141.80 4132656.3 21766987.0 7842090.6
emission_type2 water 139250.47 22343.295 763569.18 273981.55 317396.51 1254477.8 1012999.1 2449178.0

Aggregation of source footprints

If only one specific aspect of the source is of interest for the analysis, the footprint matrix can easily be aggregated with the standard pandas groupby function.

For example, to aggregate to the source region of stressor, do:

[13]:
io.et1_diag.D_cba.groupby(level='region', axis=0).sum()
[13]:
region reg1 reg2 ... reg5 reg6
sector food mining manufactoring electricity construction trade transport other food mining ... transport other food mining manufactoring electricity construction trade transport other
region
reg1 7.628249e+05 74265.619882 6.554229e+06 1.173668e+07 3.296308e+06 3.818391e+06 1.068369e+07 1.199973e+07 6.829377e+04 535.974719 ... 1.300377e+04 3.122120e+04 3.453617e+04 2.606829e+03 4.727453e+06 4.542033e+04 1.502541e+03 2.799800e+06 1.323776e+04 1.794454e+04
reg2 5.755115e+02 1712.185384 7.269345e+06 2.227236e+03 1.955463e+03 2.743145e+03 5.365729e+03 5.967041e+03 1.699751e+06 10338.264024 ... 7.905415e+05 5.920865e+02 3.254335e+02 1.384431e+03 1.160092e+06 2.740299e+03 1.930713e+02 1.201258e+06 2.449865e+03 4.998925e+03
reg3 1.054578e+03 215.654591 2.382082e+07 9.500254e+03 7.044809e+03 1.285847e+04 2.265449e+04 2.844767e+06 1.740953e+03 54.246936 ... 2.026441e+04 3.336623e+04 5.910854e+03 2.129253e+03 1.160211e+07 4.640647e+04 2.506927e+03 2.295789e+07 4.824482e+04 1.756144e+07
reg4 1.147382e+03 2323.792084 1.219510e+07 3.931814e+03 6.717898e+03 2.272241e+03 2.088695e+03 1.054927e+04 8.986664e+02 5812.809417 ... 1.818417e+03 1.930517e+03 2.402317e+03 1.257375e+06 8.856003e+06 7.878447e+03 2.121123e+03 6.469320e+06 5.546359e+03 1.756339e+04
reg5 1.283812e+06 6596.713907 1.588478e+07 1.642030e+04 1.234768e+04 1.598377e+04 2.387931e+04 2.906402e+04 1.828518e+04 1121.255607 ... 4.126106e+07 1.129572e+07 4.599517e+04 7.759982e+03 1.519859e+07 1.879346e+04 8.076635e+03 7.701012e+06 4.094084e+04 2.125918e+04
reg6 6.769053e+03 94309.570045 3.176873e+07 1.188346e+05 1.853198e+04 3.363451e+04 1.259087e+04 9.314423e+05 4.368062e+03 1283.054207 ... 8.360619e+03 2.378125e+04 1.508319e+07 7.406276e+04 2.990651e+07 3.671043e+07 1.822296e+06 1.286404e+06 4.794367e+07 1.839977e+07

6 rows × 48 columns

In addition, the aggregation function of pymrio also work on the diagonalized footprints. Here as example together with the country converter coco:

[14]:
import country_converter as coco
io.aggregate(region_agg = coco.agg_conc(original_countries=io.get_regions(),
                                        aggregates={'reg1': 'World Region A',
                                                    'reg2': 'World Region A',
                                                    'reg3': 'World Region A',},
                                         missing_countries='World Region B'))
[14]:
<pymrio.core.mriosystem.IOSystem at 0x7f9c25d25d30>
[15]:
io.et1_diag.D_cba
[15]:
region World Region A World Region B
sector food mining manufactoring electricity construction trade transport other food mining manufactoring electricity construction trade transport other
region sector
World Region A food 6.413682e+06 5.952471e+01 6.070321e+05 9.326086e+02 3.306995e+03 5.987980e+04 3.514385e+03 5.762977e+04 3.437446e+04 7.789050e+00 3.648174e+05 6.373523e+01 1.339737e+03 4.505792e+04 1.557188e+02 1.163124e+03
mining 6.832129e+03 2.421509e+06 4.487266e+05 1.936672e+05 1.984123e+05 2.126768e+04 1.676197e+04 7.595762e+04 4.373682e+02 3.805693e+03 2.419141e+05 1.079248e+04 1.073022e+04 2.708989e+04 8.090257e+02 1.908491e+04
manufactoring 1.575255e+04 4.337974e+03 5.857218e+07 5.217160e+03 1.108166e+05 1.787260e+04 4.264953e+04 8.572782e+04 1.196817e+03 2.389005e+02 5.612155e+07 1.442696e+03 6.427781e+03 7.159629e+04 3.128223e+03 9.631846e+04
electricity 1.148908e+06 8.329886e+05 1.095357e+07 5.960881e+07 1.529502e+06 1.771262e+06 3.062426e+06 9.812779e+06 1.717518e+04 2.384122e+03 1.167721e+07 3.179723e+05 1.151092e+04 7.346021e+06 2.360035e+04 8.544805e+06
construction 1.287094e+03 3.530581e+03 7.855368e+03 4.364648e+03 1.082799e+07 1.811093e+03 1.193404e+04 4.796826e+04 8.117404e+00 1.278994e+00 9.064738e+03 2.977577e+01 1.183350e+03 1.057865e+04 1.704971e+02 5.278625e+04
trade 1.302177e+04 3.358650e+03 1.320568e+05 5.581957e+03 7.080932e+04 4.827615e+06 3.359931e+04 6.189364e+04 1.772741e+03 3.095513e+01 1.747324e+05 5.736669e+02 2.618051e+03 1.843441e+07 4.414173e+03 9.440231e+04
transport 1.661673e+04 1.013917e+04 2.026243e+05 1.186026e+04 9.463786e+04 6.605838e+04 6.900978e+07 2.981319e+05 3.570924e+03 2.342901e+02 2.223755e+05 2.064082e+03 4.978304e+03 3.583977e+05 8.792139e+05 3.666801e+05
other 4.973365e+04 5.119490e+04 4.157135e+05 3.141636e+04 2.451423e+05 7.347058e+04 3.463245e+05 3.192544e+07 1.468825e+03 2.988605e+02 5.284564e+05 3.388346e+03 7.111777e+03 6.871237e+05 8.921976e+03 3.158392e+07
World Region B food 1.331074e+06 5.840707e+01 1.158034e+06 7.157090e+02 2.277605e+03 2.977910e+04 1.009061e+03 6.741954e+03 2.366136e+07 1.599984e+02 7.393735e+05 3.069128e+03 2.404678e+04 1.717301e+05 3.012820e+04 7.478749e+04
mining 1.120813e+04 1.223669e+05 6.244537e+06 3.478494e+05 3.383509e+04 1.050007e+05 3.107988e+04 1.118387e+05 3.852121e+04 1.612039e+06 6.627586e+06 1.172268e+06 5.475534e+05 1.556577e+05 8.352660e+04 2.849191e+05
manufactoring 1.165415e+04 1.112145e+03 1.403366e+08 4.253396e+03 1.644812e+04 4.518924e+04 1.350120e+04 3.504348e+04 7.406372e+04 3.204186e+03 1.254308e+08 3.173150e+04 2.217880e+05 8.865177e+04 1.225773e+05 1.739262e+05
electricity 6.624049e+03 2.433130e+04 5.205461e+06 1.790907e+05 1.709844e+04 2.343087e+06 1.540263e+04 8.184191e+05 7.886875e+05 2.316855e+04 6.039318e+06 1.225545e+08 4.700901e+05 2.298746e+05 1.006105e+06 2.680870e+06
construction 2.441345e+03 3.338858e+02 6.498032e+04 1.067936e+03 2.843476e+04 1.094280e+04 2.562950e+03 1.372537e+04 1.229142e+04 2.193007e+03 4.813644e+04 3.446390e+04 1.097151e+07 3.431794e+04 6.586141e+04 3.153222e+05
trade 7.186649e+02 1.172395e+02 8.340493e+04 3.915868e+02 7.298241e+02 1.845264e+07 1.527523e+03 1.037099e+04 1.802717e+04 4.401980e+02 9.207769e+04 4.792922e+03 3.300157e+04 1.960537e+07 4.424292e+04 4.933951e+04
transport 1.118710e+04 1.051599e+03 3.382896e+05 3.512873e+03 4.336422e+03 6.536434e+04 3.522339e+06 2.451637e+04 3.616496e+04 2.977747e+03 2.337329e+05 3.716876e+04 9.823204e+04 2.505787e+05 1.102146e+08 2.615115e+05
other 4.082899e+02 1.690002e+02 4.761138e+04 5.086643e+02 7.504197e+02 2.293492e+04 2.199852e+03 4.906621e+06 5.528324e+03 8.635489e+02 4.987069e+04 8.685131e+03 2.601768e+04 3.556939e+04 3.218539e+04 4.074021e+07