This notebook describes how to apply the model on different data as presented in the thesis. It will be explained:
The created model requires an excel file in a specific format. A function was created to create a plain excel file in the right format. The function requires a list entailing the product categories which are treated by the model, a string naming the product category which flows into the reuse part of the model, a list indication the products treated in the reuse part of the model, and the number of considered use cycles in the reuse part. Furthermore, a file name has to be provided. The created file will appear in the "data_model" folder.
from functions import input_file_creator
input_file_creator(
product_categories=['electronics', 'cars', 'industrial applications'],
category_for_reuse='electronics', products=['shaver', 'phone', 'TV'],
considered_use_cycles=2, file_name = 'example_file_creator')
All sheets of the file are empty and to be filled by the user.
import pandas as pd
pd.read_excel('data_model/example_file_creator.xlsx')
Product categories | share | |
---|---|---|
0 | electronics | NaN |
1 | cars | NaN |
2 | industrial applications | NaN |
import os
os.remove('data_model/example_file_creator.xlsx')
To showcase how to input data, an example file will be considered.
pd.read_excel('data_model/data_example.xlsx', sheet_name='MaTrace_initial_inflow')
Product categories | share | |
---|---|---|
0 | electronics | 0.412 |
1 | mobility batteries | 0.012 |
2 | hydroprocessing catalysts coke | 0.020 |
3 | hydroprocessing catalysts poisoning | 0.000 |
4 | hydroformylation catalysts | 0.003 |
5 | pet precursors catalysts | 0.017 |
6 | dissipative uses | 0.090 |
7 | hard metals | 0.230 |
8 | magnets | 0.006 |
9 | other metallic uses | 0.210 |
The sum of this column has to equal 1.
pd.read_excel('data_model/data_example.xlsx',
sheet_name='MaTrace_initial_inflow')['share'].sum(axis = 0)
1.0
The same holds true for the sheet "Reuse_inflow_split".
pd.read_excel('data_model/data_example.xlsx', sheet_name='MaTrace_initial_inflow')
Product categories | share | |
---|---|---|
0 | electronics | 0.412 |
1 | mobility batteries | 0.012 |
2 | hydroprocessing catalysts coke | 0.020 |
3 | hydroprocessing catalysts poisoning | 0.000 |
4 | hydroformylation catalysts | 0.003 |
5 | pet precursors catalysts | 0.017 |
6 | dissipative uses | 0.090 |
7 | hard metals | 0.230 |
8 | magnets | 0.006 |
9 | other metallic uses | 0.210 |
And as well for the sheet "MaTrace_D_secondary_material". In this case, the last two rows need to be excluded since the indicate the export and to production rate.
pd.read_excel('data_model/data_example.xlsx',
sheet_name='MaTrace_D_secondary_material')
Product categories | Co metal or compound | W-Co powder | |
---|---|---|---|
0 | electronics | 0.0000 | 0 |
1 | mobility batteries | 0.0210 | 0 |
2 | hydroprocessing catalysts coke | 0.0135 | 0 |
3 | hydroprocessing catalysts poisoning | 0.0135 | 0 |
4 | hydroformylation catalysts | 0.0050 | 0 |
5 | pet precursors catalysts | 0.0240 | 0 |
6 | dissipative uses | 0.1670 | 0 |
7 | hard metals | 0.3130 | 1 |
8 | magnets | 0.0170 | 0 |
9 | other metallic uses | 0.4260 | 0 |
10 | export rate | 0.1330 | 0 |
11 | to production rate | 0.8670 | 1 |
print(pd.read_excel('data_model/data_example.xlsx',
sheet_name='MaTrace_D_secondary_material').iloc[:-2, :])
print()
print('Sum of columns without export rate and to production rate:')
print(pd.read_excel('data_model/data_example.xlsx',
sheet_name='MaTrace_D_secondary_material').iloc[:-2, :].sum(axis=0))
Product categories Co metal or compound W-Co powder 0 electronics 0.0000 0 1 mobility batteries 0.0210 0 2 hydroprocessing catalysts coke 0.0135 0 3 hydroprocessing catalysts poisoning 0.0135 0 4 hydroformylation catalysts 0.0050 0 5 pet precursors catalysts 0.0240 0 6 dissipative uses 0.1670 0 7 hard metals 0.3130 1 8 magnets 0.0170 0 9 other metallic uses 0.4260 0 Sum of columns without export rate and to production rate: Product categories electronicsmobility batterieshydroprocessing c... Co metal or compound 1.0 W-Co powder 1 dtype: object
Furthermore, some transfer coefficients must sum up to 1. In the model one transfer coefficient is sufficient to define a flow which splits into two. However, for the Monte Carlo simulations both are needed.
The following cell shows the example of the sheet "MaTrace_end_of_life":
pd.read_excel('data_model/data_example.xlsx', sheet_name='MaTrace_end_of_life')
Product categories | fraction export eol products | fraction collected eol products | collection to recycling rate | postconsumer disposal rate | pre-treatment efficiency | |
---|---|---|---|---|---|---|
0 | electronics | 0.2 | 0.8 | 0.64 | 0.36 | 0.95 |
1 | mobility batteries | 0.0 | 1.0 | 1.00 | 0.00 | 0.85 |
2 | hydroprocessing catalysts coke | 0.0 | 1.0 | 1.00 | 0.00 | 0.85 |
3 | hydroprocessing catalysts poisoning | 0.0 | 1.0 | 0.00 | 1.00 | 0.00 |
4 | hydroformylation catalysts | 0.0 | 1.0 | 0.90 | 0.10 | 0.85 |
5 | pet precursors catalysts | 0.0 | 1.0 | 0.50 | 0.50 | 0.85 |
6 | dissipative uses | 0.0 | 1.0 | 0.00 | 1.00 | 0.00 |
7 | hard metals | 0.0 | 1.0 | 0.47 | 0.53 | 0.77 |
8 | magnets | 0.0 | 1.0 | 0.99 | 0.01 | 0.65 |
9 | other metallic uses | 0.0 | 1.0 | 0.84 | 0.16 | 0.65 |
The column "fraction export eol products" and "fraction collected eol products" as well as the columns "collection to recycling rate" and "postconsumer disposal" have to sum up to 1 for every product category.
Please also consult the system diagram or the excel file data_example.xlsx to find the respective transfer coefficients.
The sheet "MaTrace_in_use_stock" show examples on how to define survival curves in the model implementation:
pd.read_excel('data_model/data_example.xlsx', sheet_name='MaTrace_in_use_stock')
Product categories | distribution | location | scale | shape | |
---|---|---|---|---|---|
0 | electronics | normal | 1 | 4.051716 | 2.09 |
1 | mobility batteries | weibull | 0 | 10.631501 | 2.20 |
2 | hydroprocessing catalysts coke | gamma | 0 | 2.894742 | 2.50 |
3 | hydroprocessing catalysts poisoning | defined_distribution_example_dist | 0 | 0.000000 | 0.00 |
4 | hydroformylation catalysts | lognormal | 1 | 2.315793 | 2.50 |
5 | pet precursors catalysts | normal | 0 | 0.578948 | 2.50 |
6 | dissipative uses | weibull | 0 | 14.435166 | 3.50 |
7 | hard metals | gamma | 0 | 8.915235 | 1.16 |
8 | magnets | gompertz | 2 | 13.905022 | 1.93 |
9 | other metallic uses | lognormal | 0 | 14.628064 | 1.47 |
One can select a distribution via the column "distribution". The normal, lognormal, weibull, gamma, and gompertz distribution are preimplemented. The location, scale and shape factors can be set via the corresponding columns. It is also possible to define own distributions.
An example for this is the distribution for the product category "hydroprocessing catalysts poisoning". The string says "defined_distribution_example_dist". This works in the following way. A distribution is defined in the file "defined_distributions.xlsx" (see next cell).
pd.read_excel('data_model/defined_distributions.xlsx').iloc[:10]
example_dist | example_dist_2 | |
---|---|---|
0 | 1.00 | 1.00 |
1 | 0.60 | 0.70 |
2 | 0.55 | 0.55 |
3 | 0.50 | 0.50 |
4 | 0.45 | 0.45 |
5 | 0.40 | 0.40 |
6 | 0.35 | 0.35 |
7 | 0.30 | 0.30 |
8 | 0.25 | 0.20 |
9 | 0.20 | 0.20 |
The file holds survival curves defined by the user. Only the first 10 lines are shown. It is important that the distribution is defined for a sufficient number of years, meaning at least the number of considered years.
To use this distribution in the model, one has to fill the column "distribution" with "defined_distribution_column_name". Hence, when the entry in the column "distribution" says "defined_distribution_example_dist", the defined distribution "example_dist" will be used for this product category. If it says "defined_distribution_exmaple_dist_2" the distribution "example_dist_2" will be used for the product category.
The first step to execute the model is to load the required data. The model receives a dictionary as input which contains the sheets of the mentioned excel file as pandas data frames. The following code cell creates this dictionary.
file_path = 'data_model/data_example.xlsx'
data_sheets = pd.ExcelFile(file_path).sheet_names
data_dic = {}
for data_sheet in data_sheets:
try:
data_dic[data_sheet] = pd.read_excel(file_path,
sheet_name=data_sheet).set_index('Product categories')
except:
data_dic[data_sheet] = pd.read_excel(file_path,
sheet_name=data_sheet).set_index('Products')
Furthermore, the number of years and the start year have to be defined. A pandas dataframe containing the "defined_distributions.xlsx" file has to be passed as well.
number_of_years = 25
start_year = 2022
defined_distributions_pd = pd.read_excel('data_model/defined_distributions.xlsx')
Optionally, one can decide to print the state to have an indication whether the model is stuck or how long it will still run. One can also define whether the simplified model output shall differentiate between use cycles. Lastly, one can select the number of considered use cycles (default is 3).
The following code shows the execution of the model:
from combined_reuse_matrace_model import evaluate_cohort_combined_model
matrace_data_dic, reuse_data_dic, graph_data_pd = \
evaluate_cohort_combined_model(data_dic=data_dic,
n_years=number_of_years, start_year=start_year,
defined_distributions_pd= defined_distributions_pd,
print_state=True, separate_reuse_graph=True, considered_use_cycles=3)
Year 1 of 25 Year 2 of 25 Year 3 of 25 Year 4 of 25 Year 5 of 25 Year 6 of 25 Year 7 of 25 Year 8 of 25 Year 9 of 25 Year 10 of 25 Year 11 of 25 Year 12 of 25 Year 13 of 25 Year 14 of 25 Year 15 of 25 Year 16 of 25 Year 17 of 25 Year 18 of 25 Year 19 of 25 Year 20 of 25 Year 21 of 25 Year 22 of 25 Year 23 of 25 Year 24 of 25 Year 25 of 25
The returned dictionaries "matrace_data_dic" and "reuse_data_dic" are structured in the same way. The first key takes a string containing the considered year. The second key takes a string indicating a stock or a flow in the year. This will then return a pandas containing the values over product categories or products.
The following code cell shows the second keys of "matrace_data_dic".
matrace_data_dic['0'].keys()
Index(['U.A use stock', 'U.2 use outflow', 'U.3 hoarding inflow', 'U.4 no hoarding flow', 'U.B hoarding stock', 'U.5 hoarding outflow', 'U.6 eol products', 'E.2 exported eol products', 'E.1 to waste treatment', 'E.3 to pretreatment', 'E.4 E.5 non-selective collection', 'E.6 to recycling', 'E.7 pretreatment waste', 'E.12 downcycling', 'recycled w-co powder', 'co metal compound', 'E.8 recycling waste', 'E.11 exported recycled materials', 'P.1 total recycled products', 'P.8 export recycled products', 'U.1 product inflow', 'P.7 processing waste', 'P.5p downcycled scrap', 'P.4p disposed scrap', 'P.2 manufacturing waste', 'P.5m downcycled scrap', 'P.4m disposed scrap', 'P.4 disposed scrap', 'P.5 downcycled scrap'], dtype='object')
And the following code cell shows the second keys of "reuse_data_dic".
reuse_data_dic['0'].keys()
Index(['total_use_stock', 'total_hoarding_stock', 'to_disposal_flow', 'use_stock_1', 'storage_stock_1', 'use_1_to_storage_1_flow', 'use_1_to_disposal_flow', 'storage_1_to_disposal_flow', 'use_1_to_use_2_flow', 'storage_1_to_use_2_flow', 'use_stock_2', 'storage_stock_2', 'use_2_to_storage_2_flow', 'use_2_to_disposal_flow', 'storage_2_to_disposal_flow', 'use_2_to_use_3_flow', 'storage_2_to_use_3_flow', 'use_stock_3', 'storage_stock_3', 'use_3_to_storage_3_flow', 'use_3_to_disposal_flow', 'storage_3_to_disposal_flow'], dtype='object')
The following code cell shows the content.
reuse_data_dic['0']['total_use_stock']
Products computer 0.026567 phone 0.045320 fan 0.082400 dish washer 0.185400 e-bikes 0.024720 power tools 0.019502 Name: total_use_stock, dtype: float64
matrace_data_dic['0']['U.A use stock']
Products electronics 0.38391 mobility batteries 0.012 hydroprocessing catalysts coke 0.02 hydroprocessing catalysts poisoning 0.0 hydroformylation catalysts 0.003 pet precursors catalysts 0.0085 dissipative uses 0.09 hard metals 0.23 magnets 0.006 other metallic uses 0.21 Name: U.A use stock, dtype: object
The retuned pandas dataframe "graph_data_pd" contains the stocks and the accumulated outflows.
graph_data_pd
Electronics 1st use | Electronics 2nd use | Electronics 3rd use | Mobility batteries | Hydroprocessing catalysts coke | Hydroprocessing catalysts poisoning | Hydroformylation catalysts | Pet precursors catalysts | Dissipative uses | Hard metals | Magnets | Other metallic uses | Hoarded | Exported | Downcycled | Non-selective collection | Production losses | Pre-treatment losses | Recycling losses | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Year | |||||||||||||||||||
2022 | 0.377540 | 0.005548 | 0.000821 | 0.012176 | 0.020113 | 0.000113 | 0.003042 | 0.008701 | 0.090867 | 0.231415 | 0.006049 | 0.211641 | 0.005956 | 0.008817 | 0.003840 | 0.010625 | 0.000423 | 0.001204 | 0.001109 |
2023 | 0.281169 | 0.017890 | 0.001593 | 0.012589 | 0.020090 | 0.000421 | 0.003156 | 0.001363 | 0.093221 | 0.219753 | 0.006182 | 0.208973 | 0.045974 | 0.032574 | 0.009901 | 0.034468 | 0.001577 | 0.004941 | 0.004165 |
2024 | 0.199773 | 0.026279 | 0.002235 | 0.012901 | 0.019297 | 0.000728 | 0.002181 | 0.000912 | 0.095838 | 0.207615 | 0.006334 | 0.202697 | 0.067202 | 0.058810 | 0.014661 | 0.061596 | 0.002894 | 0.010318 | 0.007728 |
2025 | 0.142881 | 0.031148 | 0.002443 | 0.012958 | 0.017849 | 0.000909 | 0.001956 | 0.000887 | 0.097935 | 0.195219 | 0.005663 | 0.195900 | 0.075340 | 0.081793 | 0.019619 | 0.086854 | 0.004054 | 0.015708 | 0.010885 |
2026 | 0.106036 | 0.032665 | 0.002545 | 0.012749 | 0.016026 | 0.001010 | 0.001813 | 0.000769 | 0.099312 | 0.182762 | 0.005026 | 0.189072 | 0.075795 | 0.101039 | 0.024431 | 0.109548 | 0.005039 | 0.020781 | 0.013581 |
2027 | 0.083086 | 0.031205 | 0.002917 | 0.012286 | 0.014056 | 0.001063 | 0.001694 | 0.000640 | 0.099778 | 0.170409 | 0.004414 | 0.182273 | 0.073877 | 0.116546 | 0.028950 | 0.129684 | 0.005846 | 0.025469 | 0.015808 |
2028 | 0.068224 | 0.028201 | 0.003453 | 0.011605 | 0.012104 | 0.001080 | 0.001590 | 0.000525 | 0.099193 | 0.158352 | 0.003831 | 0.175593 | 0.068781 | 0.128968 | 0.035074 | 0.148456 | 0.006506 | 0.030823 | 0.017643 |
2029 | 0.057489 | 0.024919 | 0.003829 | 0.010758 | 0.010275 | 0.001073 | 0.001499 | 0.000435 | 0.097446 | 0.146769 | 0.003287 | 0.169140 | 0.062795 | 0.139154 | 0.042008 | 0.166424 | 0.007057 | 0.036456 | 0.019188 |
2030 | 0.047519 | 0.021968 | 0.003884 | 0.009806 | 0.008634 | 0.001056 | 0.001422 | 0.000378 | 0.094478 | 0.135845 | 0.002792 | 0.163060 | 0.057904 | 0.148166 | 0.048851 | 0.184186 | 0.007550 | 0.041928 | 0.020573 |
2031 | 0.041138 | 0.019131 | 0.003691 | 0.008783 | 0.007190 | 0.001019 | 0.001352 | 0.000321 | 0.090127 | 0.125476 | 0.002344 | 0.157197 | 0.053550 | 0.155440 | 0.055173 | 0.201414 | 0.007957 | 0.046971 | 0.021727 |
2032 | 0.034343 | 0.016645 | 0.003386 | 0.007755 | 0.005957 | 0.000974 | 0.001293 | 0.000288 | 0.084505 | 0.115843 | 0.001952 | 0.151742 | 0.050097 | 0.162294 | 0.061008 | 0.219100 | 0.008339 | 0.051667 | 0.022811 |
2033 | 0.028269 | 0.014450 | 0.003054 | 0.006757 | 0.004920 | 0.000924 | 0.001240 | 0.000265 | 0.077682 | 0.106887 | 0.001613 | 0.146616 | 0.046845 | 0.168544 | 0.066382 | 0.237046 | 0.008688 | 0.056016 | 0.023804 |
2034 | 0.022851 | 0.012621 | 0.002727 | 0.005817 | 0.004056 | 0.000861 | 0.001194 | 0.000240 | 0.069864 | 0.098556 | 0.001325 | 0.141769 | 0.043833 | 0.174160 | 0.071330 | 0.255063 | 0.009003 | 0.060031 | 0.024700 |
2035 | 0.018026 | 0.011123 | 0.002423 | 0.004960 | 0.003344 | 0.000788 | 0.001151 | 0.000217 | 0.061378 | 0.090825 | 0.001083 | 0.137183 | 0.040872 | 0.179258 | 0.075887 | 0.272941 | 0.009289 | 0.063738 | 0.025513 |
2036 | 0.014967 | 0.009819 | 0.002153 | 0.004191 | 0.002755 | 0.000703 | 0.001110 | 0.000189 | 0.052592 | 0.083600 | 0.000882 | 0.132765 | 0.037721 | 0.183520 | 0.080080 | 0.290082 | 0.009530 | 0.067135 | 0.026206 |
2037 | 0.012373 | 0.008728 | 0.001925 | 0.003523 | 0.002274 | 0.000615 | 0.001071 | 0.000165 | 0.043978 | 0.076902 | 0.000717 | 0.128559 | 0.034692 | 0.187336 | 0.083949 | 0.306351 | 0.009745 | 0.070268 | 0.026828 |
2038 | 0.010187 | 0.007783 | 0.001740 | 0.002954 | 0.001882 | 0.000538 | 0.001035 | 0.000147 | 0.035944 | 0.070701 | 0.000585 | 0.124550 | 0.031811 | 0.190751 | 0.087527 | 0.321385 | 0.009938 | 0.073157 | 0.027384 |
2039 | 0.008353 | 0.006950 | 0.001594 | 0.002477 | 0.001563 | 0.000472 | 0.001001 | 0.000131 | 0.028814 | 0.064961 | 0.000479 | 0.120720 | 0.029177 | 0.193771 | 0.090842 | 0.334887 | 0.010108 | 0.075822 | 0.027878 |
2040 | 0.006823 | 0.006196 | 0.001475 | 0.002081 | 0.001302 | 0.000416 | 0.000970 | 0.000116 | 0.022792 | 0.059655 | 0.000395 | 0.117060 | 0.026758 | 0.196455 | 0.093922 | 0.346723 | 0.010259 | 0.078284 | 0.028318 |
2041 | 0.005552 | 0.005507 | 0.001374 | 0.001758 | 0.001089 | 0.000368 | 0.000940 | 0.000103 | 0.017939 | 0.054755 | 0.000329 | 0.113563 | 0.024538 | 0.198844 | 0.096790 | 0.356885 | 0.010393 | 0.080563 | 0.028710 |
2042 | 0.004501 | 0.004883 | 0.001281 | 0.001493 | 0.000916 | 0.000327 | 0.000912 | 0.000091 | 0.014188 | 0.050235 | 0.000276 | 0.110220 | 0.022505 | 0.200971 | 0.099468 | 0.365487 | 0.010512 | 0.082675 | 0.029060 |
2043 | 0.003637 | 0.004319 | 0.001191 | 0.001278 | 0.000773 | 0.000291 | 0.000885 | 0.000081 | 0.011382 | 0.046068 | 0.000235 | 0.107022 | 0.020648 | 0.202866 | 0.101973 | 0.372724 | 0.010618 | 0.084636 | 0.029373 |
2044 | 0.002928 | 0.003814 | 0.001101 | 0.001101 | 0.000656 | 0.000258 | 0.000860 | 0.000072 | 0.009324 | 0.042230 | 0.000202 | 0.103962 | 0.018957 | 0.204554 | 0.104323 | 0.378833 | 0.010713 | 0.086460 | 0.029652 |
2045 | 0.002350 | 0.003365 | 0.001011 | 0.000955 | 0.000559 | 0.000230 | 0.000836 | 0.000064 | 0.007814 | 0.038698 | 0.000175 | 0.101032 | 0.017419 | 0.206057 | 0.106531 | 0.384045 | 0.010797 | 0.088158 | 0.029901 |
2046 | 0.001880 | 0.002968 | 0.000923 | 0.000834 | 0.000479 | 0.000204 | 0.000814 | 0.000057 | 0.006685 | 0.035449 | 0.000153 | 0.098227 | 0.016024 | 0.207395 | 0.108610 | 0.388560 | 0.010872 | 0.089743 | 0.030124 |
It is easily possible to create a stacked area chart out of it.
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = [10, 7]
graph_data_pd.plot.area()
plt.legend(reversed(plt.legend().legendHandles), reversed(
graph_data_pd.columns), bbox_to_anchor=(1.05, 1))
plt.ylabel('Stock distribution by product categories and losses in %')
plt.tight_layout()
plt.show()
The code to conduct Monte Carlo simulations consists of three files which need to be executed one after another:
In the following it will be discussed what each file does and how to use it. To do so, files and the data used in the cobalt case study will be used. Each of the files has the variable "proof_of_concept" in the very top. If this is "True", an exemplary Monte Carlo simulation and evaluation considering 10 runs will be conducted. If it is set to "False" the results as presented in the thesis will be reproduced.
# The folder holding the results of the following demonstration
# needs to be deleted in order to be created and populated.
# This is a necessary step but not relevant in the context of
# the explenation.
import shutil
try:
shutil.rmtree('monte_carlo_results/proof_of_concept/')
except:
print('Dictionary does not excist.')
At the start of the file, the user can adjust the settings. Those are the number of runs ("n_runs"), the number of the considered years ("n_years"), the start year ("start_year"), and the number of the considered use cycles ("considered_use_cycles").
Then, the data to be loaded needs to be specified. Firstly, the file entailing the survival curves designed by the user has to be loaded (see above). Secondly, the path to the input data (format as described above) has to be specified. Lastly, the excel file containing the uncertainty rating has to be set.
This file must entail the same sheet names as the input file. Instead of the data, the colums must hold the uncertainty score (0 to 5, as explained in the main body of the thesis).
If an input shall not be varied, the column can be either deleted from the file holding the uncertainty scores, or all values can be set to 0. Only numerical inputs can be considered.
The following cell shows one sheet of the excel holding the input data. The next one shows the uncertainty ratings of those inputs.
pd.read_excel('data_cobalt_case_study/data_input_cobalt_extended_data_set.xlsx', sheet_name='MaTrace_in_use_stock')
Product categories | distribution | location | scale | shape | |
---|---|---|---|---|---|
0 | portable batteries | weibull | 0 | 4.051716 | 2.09 |
1 | mobility batteries | weibull | 0 | 10.631501 | 2.20 |
2 | hydroprocessing catalysts coke | weibull | 0 | 2.894742 | 2.50 |
3 | hydroprocessing catalysts poisoning | weibull | 0 | 1.505266 | 2.50 |
4 | hydroformylation catalysts | weibull | 0 | 2.315793 | 2.50 |
5 | pet precursors catalysts | weibull | 0 | 0.578948 | 2.50 |
6 | dissipative uses | weibull | 0 | 14.435166 | 3.50 |
7 | hard metals | weibull | 0 | 8.915235 | 1.16 |
8 | magnets | weibull | 0 | 13.905022 | 1.93 |
9 | other metallic uses | weibull | 0 | 14.628064 | 1.47 |
10 | superalloys | weibull | 0 | 17.282543 | 1.74 |
pd.read_excel(
'data_cobalt_case_study/data_uncertainty_rating_cobalt_case_study.xlsx',
sheet_name='MaTrace_in_use_stock')
Product categories | shape | scale | |
---|---|---|---|
0 | portable batteries | 0 | 0 |
1 | mobility batteries | 1 | 4 |
2 | hydroprocessing catalysts coke | 2 | 4 |
3 | hydroprocessing catalysts poisoning | 2 | 4 |
4 | hydroformylation catalysts | 2 | 4 |
5 | pet precursors catalysts | 1 | 4 |
6 | dissipative uses | 2 | 3 |
7 | hard metals | 1 | 2 |
8 | magnets | 1 | 2 |
9 | other metallic uses | 1 | 2 |
10 | superalloys | 1 | 2 |
As it can be seen, only the uncertainty scores for the columns "shape" and "scale" appear. This is intended since only numerical values can be varied by this implementation and the location of the Weibull distribution is a factor which was not considered.
Once the paths and the settings are defined, the script can be run. The next cell executes the script for 10 runs.
%run monte_carlo_simulations.py
Creating dictionary for results. Path: monte_carlo_results/proof_of_concept Importing data Creating inputs for Monte Carlo simulations based on uncertainty score Normalize inputs
c:\Users\rapha\Desktop\master_thesis_hand_in\monte_carlo_simulations.py:154: PerformanceWarning: indexing past lexsort depth may impact performance. for column in input_pd.loc[:, ("MaTrace_initial_inflow", "share")].columns:
Starting runs Run 1 of 10 Mass balance run 0: True Run 2 of 10 Mass balance run 1: True Run 3 of 10 Mass balance run 2: True Run 4 of 10 Mass balance run 3: True Run 5 of 10 Mass balance run 4: True Run 6 of 10 Mass balance run 5: True Run 7 of 10 Mass balance run 6: True Run 8 of 10 Mass balance run 7: True Run 9 of 10 Mass balance run 8: True Run 10 of 10 Mass balance run 9: True Total time - seconds: 21, hours: 0.005833333333333334 Time per run: 2.1 Inputs and results are stored.
The printed output reflects the steps of the code. After the data is imported, random numbers following the defined distributions are created. Since some split vectors and transfer coefficients will not sum up to 1 anymore (see above) they have to be normalized. Afterwards, the experiments are run. The data is collected in a dictionary. If several thousand runs are executed, the dictionary is dumped in splits to decrease the runtime.
The results and a file containing the used model inputs can be found in the folder "monte_carlo_results/proof_of_concept".
The following cell shows part of the saved inputs. The rows represent runs.
import pickle
with open('monte_carlo_results/proof_of_concept/inputs.pkl', 'rb') as f:
input_pd = pickle.load(f)
input_pd
sheet | MaTrace_initial_inflow | ... | Reuse_storage_time_3 | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
column | share | ... | scale | shape | |||||||||||||||||
item | portable batteries | mobility batteries | hydroprocessing catalysts coke | hydroprocessing catalysts poisoning | hydroformylation catalysts | pet precursors catalysts | dissipative uses | hard metals | magnets | other metallic uses | ... | e-bikes | power tools | others | smartphones | mobile phones | tablets | laptops | e-bikes | power tools | others |
0 | 0.195626 | 0.069050 | 0.049883 | 0.023999 | 0.059167 | 0.004703 | 0.059462 | 0.111802 | 0.152205 | 0.103031 | ... | 2.360890 | 1.291785 | 3.787781 | 1.432013 | 1.664109 | 1.575216 | 1.521198 | 1.797884 | 1.552458 | 1.790137 |
1 | 0.221689 | 0.031145 | 0.057574 | 0.063652 | 0.049747 | 0.142862 | 0.095038 | 0.195235 | 0.006055 | 0.000673 | ... | 2.125174 | 2.125348 | 4.687217 | 1.619985 | 1.358189 | 1.447141 | 1.486905 | 1.621413 | 1.769031 | 1.507384 |
2 | 0.203971 | 0.067055 | 0.028344 | 0.034823 | 0.238051 | 0.132933 | 0.013254 | 0.094126 | 0.013634 | 0.018468 | ... | 1.950079 | 2.244345 | 4.647316 | 1.565251 | 1.402054 | 1.377444 | 2.026306 | 1.699196 | 1.397294 | 1.565706 |
3 | 0.411710 | 0.092229 | 0.039897 | 0.041033 | 0.107387 | 0.019387 | 0.066506 | 0.077042 | 0.014983 | 0.001555 | ... | 1.975120 | 2.126083 | 4.158380 | 1.663245 | 1.301536 | 1.298786 | 1.530208 | 1.430551 | 1.514807 | 1.453668 |
4 | 0.279781 | 0.026076 | 0.036750 | 0.036071 | 0.015810 | 0.016235 | 0.012234 | 0.252920 | 0.066690 | 0.065006 | ... | 2.485666 | 1.718379 | 2.079817 | 1.317759 | 1.575214 | 1.413565 | 1.546306 | 1.562307 | 1.452043 | 1.174145 |
5 | 0.282791 | 0.069646 | 0.045512 | 0.080305 | 0.017813 | 0.049054 | 0.052628 | 0.199520 | 0.080029 | 0.001548 | ... | 2.255336 | 1.821774 | 3.588646 | 1.733470 | 1.747479 | 1.478725 | 1.723377 | 1.577003 | 1.513890 | 1.475730 |
6 | 0.321172 | 0.040106 | 0.077813 | 0.053932 | 0.036862 | 0.058657 | 0.062004 | 0.152609 | 0.024801 | 0.059288 | ... | 1.975133 | 3.343770 | 3.361317 | 1.345725 | 1.570218 | 1.414150 | 1.409801 | 1.476518 | 1.607588 | 1.452492 |
7 | 0.252250 | 0.032541 | 0.046556 | 0.083294 | 0.096109 | 0.016466 | 0.031111 | 0.144579 | 0.031795 | 0.022306 | ... | 1.730407 | 1.167725 | 4.327077 | 1.679690 | 1.238038 | 1.600540 | 1.522313 | 1.524402 | 1.467380 | 1.247346 |
8 | 0.267555 | 0.034854 | 0.015555 | 0.001666 | 0.069714 | 0.074432 | 0.065195 | 0.219638 | 0.015209 | 0.033571 | ... | 1.065056 | 3.033024 | 3.515732 | 1.788227 | 1.506585 | 1.421502 | 1.489797 | 1.832488 | 1.288020 | 1.568852 |
9 | 0.326831 | 0.035760 | 0.133187 | 0.041984 | 0.067035 | 0.004005 | 0.014350 | 0.163488 | 0.058476 | 0.040129 | ... | 1.811120 | 3.231110 | 4.266448 | 1.281956 | 1.798759 | 1.401711 | 1.200397 | 1.545702 | 1.573716 | 1.740299 |
10 rows × 541 columns
The results are saved in the form of nested dictionaries:
with open('monte_carlo_results/proof_of_concept/results.pkl', 'rb') as f:
results_dic = pickle.load(f)
The fist key represents runs:
results_dic.keys()
dict_keys(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'])
The second part specifies from which part of the model the data is coming from:
results_dic['0'].keys()
dict_keys(['matrace_data_dic', 'reuse_data_dic'])
Since this data structure is hard to handle, the script "monte_carlo_evaluation.py" serves the purpose to transfer the data into multidimensional pandas data frames.
In order to execute this script, one has to adjust the settings in the beginning of the file so they are the same as the used ones in "mone_carlo_simulations.py". The path to the results has to be defined. Then the file is ready to be executed.
%run monte_carlo_evaluation.py
Loading file: Create dictionary: Start treating data run 1 of 10 run 2 of 10 run 3 of 10 run 4 of 10 run 5 of 10 run 6 of 10 run 7 of 10 run 8 of 10 run 9 of 10 run 10 of 10 Compact results are stored.
This script creates the multidimensional pandas data frame 'compact_results'. The first key entails the runs, the second the stock or flow, and the third one the product or the product category.
with open('monte_carlo_results/proof_of_concept/compact_results.pkl',
'rb') as f:
compact_results = pickle.load(f)
compact_results
run | 0 | ... | 9 | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
stock_flow | total_use_stock | total_hoarding_stock | ... | P.5 downcycled scrap | |||||||||||||||||
item | sum | smartphones | mobile phones | tablets | laptops | e-bikes | power tools | others | sum | smartphones | ... | mobility batteries | hydroprocessing catalysts coke | hydroprocessing catalysts poisoning | hydroformylation catalysts | pet precursors catalysts | dissipative uses | hard metals | magnets | other metallic uses | superalloys |
2015 | 0.195626 | 0.057242 | 0.047268 | 0.02614 | 0.048304 | 0.001794 | 0.006937 | 0.007942 | 0.0 | 0.0 | ... | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 |
2016 | 0.177952 | 0.053884 | 0.036155 | 0.02468 | 0.047307 | 0.001774 | 0.006729 | 0.007423 | 0.010898 | 0.001788 | ... | 0.000142 | 0.000282 | 0.000015 | 0.000009 | 0.000275 | 0.0001 | 0.000076 | 0.000011 | 0.000022 | 0.000043 |
2017 | 0.1475 | 0.046705 | 0.021888 | 0.020836 | 0.044188 | 0.001634 | 0.006348 | 0.005901 | 0.027659 | 0.004951 | ... | 0.000313 | 0.000585 | 0.000032 | 0.000018 | 0.000541 | 0.000227 | 0.000158 | 0.000022 | 0.000044 | 0.000096 |
2018 | 0.116835 | 0.037369 | 0.012804 | 0.015898 | 0.039273 | 0.001304 | 0.005903 | 0.004284 | 0.040423 | 0.008003 | ... | 0.000238 | 0.000434 | 0.000024 | 0.000013 | 0.000392 | 0.000175 | 0.000117 | 0.000016 | 0.000033 | 0.000074 |
2019 | 0.090162 | 0.027998 | 0.008145 | 0.011246 | 0.033273 | 0.000864 | 0.005448 | 0.003187 | 0.046628 | 0.009983 | ... | 0.000129 | 0.000245 | 0.000013 | 0.000008 | 0.000231 | 0.000092 | 0.000066 | 0.000009 | 0.000019 | 0.000039 |
2020 | 0.069089 | 0.020143 | 0.006213 | 0.007728 | 0.027022 | 0.000502 | 0.005007 | 0.002473 | 0.046801 | 0.010628 | ... | 0.000098 | 0.000195 | 0.00001 | 0.000006 | 0.000189 | 0.000069 | 0.000052 | 0.000007 | 0.000015 | 0.00003 |
2021 | 0.053197 | 0.01421 | 0.00547 | 0.005481 | 0.021222 | 0.000322 | 0.00459 | 0.001902 | 0.042964 | 0.010219 | ... | 0.000096 | 0.000189 | 0.00001 | 0.000006 | 0.000183 | 0.000068 | 0.000051 | 0.000007 | 0.000015 | 0.000029 |
2022 | 0.041158 | 0.009933 | 0.004847 | 0.004179 | 0.016291 | 0.000263 | 0.004195 | 0.00145 | 0.037263 | 0.009191 | ... | 0.000092 | 0.000181 | 0.00001 | 0.000006 | 0.000175 | 0.000065 | 0.000049 | 0.000007 | 0.000014 | 0.000028 |
2023 | 0.031819 | 0.006883 | 0.003998 | 0.003389 | 0.012354 | 0.000232 | 0.003823 | 0.001141 | 0.031138 | 0.007893 | ... | 0.000086 | 0.000168 | 0.000009 | 0.000005 | 0.000162 | 0.000061 | 0.000045 | 0.000006 | 0.000013 | 0.000026 |
2024 | 0.024471 | 0.004703 | 0.003038 | 0.002799 | 0.009323 | 0.000194 | 0.003472 | 0.000942 | 0.025294 | 0.006544 | ... | 0.000078 | 0.000152 | 0.000008 | 0.000005 | 0.000147 | 0.000055 | 0.000041 | 0.000006 | 0.000012 | 0.000024 |
2025 | 0.01869 | 0.003151 | 0.002168 | 0.002264 | 0.007016 | 0.00015 | 0.003139 | 0.000802 | 0.020025 | 0.005262 | ... | 0.000069 | 0.000135 | 0.000007 | 0.000004 | 0.000131 | 0.000048 | 0.000036 | 0.000005 | 0.00001 | 0.000021 |
2026 | 0.014169 | 0.002059 | 0.001487 | 0.001757 | 0.005248 | 0.000108 | 0.002824 | 0.000686 | 0.015459 | 0.004107 | ... | 0.00006 | 0.000118 | 0.000006 | 0.000004 | 0.000115 | 0.000042 | 0.000032 | 0.000005 | 0.000009 | 0.000018 |
2027 | 0.010659 | 0.00131 | 0.000997 | 0.001299 | 0.003875 | 0.000073 | 0.002528 | 0.000577 | 0.011653 | 0.003112 | ... | 0.000051 | 0.000103 | 0.000005 | 0.000003 | 0.0001 | 0.000036 | 0.000028 | 0.000004 | 0.000008 | 0.000015 |
2028 | 0.007954 | 0.000811 | 0.000655 | 0.000915 | 0.002804 | 0.000046 | 0.00225 | 0.000472 | 0.008603 | 0.002289 | ... | 0.000044 | 0.000089 | 0.000005 | 0.000003 | 0.000087 | 0.000031 | 0.000024 | 0.000003 | 0.000007 | 0.000013 |
2029 | 0.005892 | 0.000489 | 0.00042 | 0.000614 | 0.001976 | 0.000027 | 0.001991 | 0.000375 | 0.006242 | 0.001634 | ... | 0.000038 | 0.000076 | 0.000004 | 0.000003 | 0.000076 | 0.000026 | 0.000021 | 0.000003 | 0.000006 | 0.000011 |
2030 | 0.004344 | 0.000287 | 0.00026 | 0.000393 | 0.001349 | 0.000015 | 0.001752 | 0.000288 | 0.004468 | 0.001133 | ... | 0.000032 | 0.000066 | 0.000003 | 0.000002 | 0.000066 | 0.000023 | 0.000018 | 0.000003 | 0.000005 | 0.00001 |
2031 | 0.003204 | 0.000165 | 0.000153 | 0.00024 | 0.000891 | 0.000008 | 0.001532 | 0.000213 | 0.003166 | 0.000764 | ... | 0.000028 | 0.000057 | 0.000003 | 0.000002 | 0.000057 | 0.000019 | 0.000015 | 0.000002 | 0.000004 | 0.000008 |
2032 | 0.002377 | 0.000092 | 0.000086 | 0.00014 | 0.000569 | 0.000004 | 0.001332 | 0.000153 | 0.002227 | 0.000501 | ... | 0.000024 | 0.00005 | 0.000003 | 0.000002 | 0.00005 | 0.000017 | 0.000013 | 0.000002 | 0.000004 | 0.000007 |
2033 | 0.001785 | 0.00005 | 0.000046 | 0.000078 | 0.000351 | 0.000002 | 0.001152 | 0.000106 | 0.001561 | 0.00032 | ... | 0.000021 | 0.000043 | 0.000002 | 0.000002 | 0.000043 | 0.000015 | 0.000012 | 0.000002 | 0.000003 | 0.000006 |
2034 | 0.001363 | 0.000027 | 0.000023 | 0.000042 | 0.00021 | 0.000001 | 0.00099 | 0.000071 | 0.001095 | 0.0002 | ... | 0.000018 | 0.000038 | 0.000002 | 0.000001 | 0.000038 | 0.000013 | 0.00001 | 0.000001 | 0.000003 | 0.000005 |
2035 | 0.001061 | 0.000014 | 0.000011 | 0.000021 | 0.000121 | 0.0 | 0.000847 | 0.000046 | 0.000772 | 0.000121 | ... | 0.000016 | 0.000033 | 0.000002 | 0.000001 | 0.000033 | 0.000011 | 0.000009 | 0.000001 | 0.000003 | 0.000005 |
2036 | 0.00084 | 0.000007 | 0.000005 | 0.00001 | 0.000068 | 0.0 | 0.000721 | 0.000029 | 0.000551 | 0.000072 | ... | 0.000014 | 0.000029 | 0.000002 | 0.000001 | 0.000029 | 0.00001 | 0.000008 | 0.000001 | 0.000002 | 0.000004 |
2037 | 0.000675 | 0.000004 | 0.000002 | 0.000005 | 0.000037 | 0.0 | 0.00061 | 0.000018 | 0.000399 | 0.000042 | ... | 0.000012 | 0.000025 | 0.000001 | 0.000001 | 0.000025 | 0.000009 | 0.000007 | 0.000001 | 0.000002 | 0.000004 |
2038 | 0.000549 | 0.000002 | 0.000001 | 0.000002 | 0.000019 | 0.0 | 0.000515 | 0.00001 | 0.000295 | 0.000024 | ... | 0.000011 | 0.000022 | 0.000001 | 0.000001 | 0.000022 | 0.000008 | 0.000006 | 0.000001 | 0.000002 | 0.000003 |
2039 | 0.00045 | 0.000001 | 0.0 | 0.000001 | 0.00001 | 0.0 | 0.000432 | 0.000006 | 0.000223 | 0.000013 | ... | 0.00001 | 0.000019 | 0.000001 | 0.000001 | 0.000019 | 0.000007 | 0.000005 | 0.000001 | 0.000001 | 0.000003 |
2040 | 0.000371 | 0.0 | 0.0 | 0.0 | 0.000005 | 0.0 | 0.000361 | 0.000003 | 0.000172 | 0.000007 | ... | 0.000009 | 0.000017 | 0.000001 | 0.000001 | 0.000017 | 0.000006 | 0.000005 | 0.000001 | 0.000001 | 0.000003 |
2041 | 0.000306 | 0.0 | 0.0 | 0.0 | 0.000002 | 0.0 | 0.000301 | 0.000002 | 0.000135 | 0.000004 | ... | 0.000008 | 0.000015 | 0.000001 | 0.0 | 0.000014 | 0.000005 | 0.000004 | 0.000001 | 0.000001 | 0.000002 |
2042 | 0.000252 | 0.0 | 0.0 | 0.0 | 0.000001 | 0.0 | 0.00025 | 0.000001 | 0.000108 | 0.000002 | ... | 0.000007 | 0.000013 | 0.000001 | 0.0 | 0.000012 | 0.000005 | 0.000003 | 0.0 | 0.000001 | 0.000002 |
2043 | 0.000208 | 0.0 | 0.0 | 0.0 | 0.000001 | 0.0 | 0.000207 | 0.000001 | 0.000087 | 0.000001 | ... | 0.000006 | 0.000011 | 0.000001 | 0.0 | 0.000011 | 0.000004 | 0.000003 | 0.0 | 0.000001 | 0.000002 |
2044 | 0.000171 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.000171 | 0.0 | 0.000071 | 0.000001 | ... | 0.000005 | 0.00001 | 0.000001 | 0.0 | 0.000009 | 0.000004 | 0.000003 | 0.0 | 0.000001 | 0.000002 |
2045 | 0.000141 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.00014 | 0.0 | 0.000058 | 0.0 | ... | 0.000005 | 0.000009 | 0.0 | 0.0 | 0.000008 | 0.000003 | 0.000002 | 0.0 | 0.000001 | 0.000001 |
2046 | 0.000115 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.000115 | 0.0 | 0.000047 | 0.0 | ... | 0.000004 | 0.000008 | 0.0 | 0.0 | 0.000007 | 0.000003 | 0.000002 | 0.0 | 0.000001 | 0.000001 |
2047 | 0.000094 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.000094 | 0.0 | 0.000039 | 0.0 | ... | 0.000004 | 0.000007 | 0.0 | 0.0 | 0.000006 | 0.000003 | 0.000002 | 0.0 | 0.000001 | 0.000001 |
2048 | 0.000077 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.000077 | 0.0 | 0.000032 | 0.0 | ... | 0.000003 | 0.000006 | 0.0 | 0.0 | 0.000005 | 0.000002 | 0.000002 | 0.0 | 0.0 | 0.000001 |
2049 | 0.000063 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.000063 | 0.0 | 0.000026 | 0.0 | ... | 0.000003 | 0.000005 | 0.0 | 0.0 | 0.000005 | 0.000002 | 0.000001 | 0.0 | 0.0 | 0.000001 |
2050 | 0.000051 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.000051 | 0.0 | 0.000022 | 0.0 | ... | 0.000002 | 0.000004 | 0.0 | 0.0 | 0.000004 | 0.000002 | 0.000001 | 0.0 | 0.0 | 0.000001 |
36 rows × 5240 columns
In order to execute this script, one has to adjust the settings in the beginning of the file so they are the same as the used ones in "mone_carlo_simulations.py" and "monte_carlo_evaluation.py". The path to the results has to be defined. Then the file is ready to be executed.
The file calculates for all considered years the spearman correlation and the normalized spearman square correlation between all inputs and the total in-use stock, the total hibernating stock, the total disposal flow, and the total export flow.
The results are written into the files "monte_carlo_results" (results of mentioned stocks and flows over years and runs), "speaman_results_abs" (spearman correlation between inputs and outputs over years) and "spearman_results_normalized" (normalized spareman square correlation between inputs and outputs over years).
%run monte_carlo_uncertainty.py
Calculate spearman correlation between inputs and: ['total_use_stock', 'total_hoarding_stock', 'to_disposal_flow', 'U.B hoarding stock', 'U.A use stock', 'total_export', 'total_disposal'] Year 1 of 36
c:\Users\rapha\.conda\envs\master_thesis\lib\site-packages\scipy\stats\stats.py:4484: SpearmanRConstantInputWarning: An input array is constant; the correlation coefficient is not defined. warnings.warn(SpearmanRConstantInputWarning())
Year 2 of 36 Year 3 of 36 Year 4 of 36 Year 5 of 36 Year 6 of 36 Year 7 of 36 Year 8 of 36 Year 9 of 36 Year 10 of 36 Year 11 of 36 Year 12 of 36 Year 13 of 36 Year 14 of 36 Year 15 of 36 Year 16 of 36 Year 17 of 36 Year 18 of 36 Year 19 of 36 Year 20 of 36 Year 21 of 36 Year 22 of 36 Year 23 of 36 Year 24 of 36 Year 25 of 36 Year 26 of 36 Year 27 of 36 Year 28 of 36 Year 29 of 36 Year 30 of 36 Year 31 of 36 Year 32 of 36 Year 33 of 36 Year 34 of 36 Year 35 of 36 Year 36 of 36 Export Monte Carlo results Export spearman absolute results Export spearman normalized results
The following cell shows a part of the table displaying the normalized square spearmen correlation.
with open(
'monte_carlo_results/proof_of_concept/spearman_results_normalized.pkl',
'rb') as f:
spearman_results_normalized_pd= pickle.load(f)
spearman_results_normalized_pd
result_item | total_use_stock | ... | total_disposal | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
sheet | MaTrace_initial_inflow | ... | Reuse_storage_time_3 | ||||||||||||||||||
column | share | ... | scale | shape | |||||||||||||||||
item | portable batteries | mobility batteries | hydroprocessing catalysts coke | hydroprocessing catalysts poisoning | hydroformylation catalysts | pet precursors catalysts | dissipative uses | hard metals | magnets | other metallic uses | ... | e-bikes | power tools | others | smartphones | mobile phones | tablets | laptops | e-bikes | power tools | others |
0 | 2.045029 | 0.114251 | 0.081801 | 0.138889 | 0.033126 | 0.138889 | 0.016901 | 0.012695 | 0.001878 | 0.012695 | ... | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN |
1 | 1.986973 | 0.039561 | 0.062895 | 0.081441 | 0.039561 | 0.179560 | 0.003664 | 0.021613 | 0.000673 | 0.000075 | ... | 0.391401 | 0.346062 | 0.415117 | 0.439530 | 0.192605 | 0.004272 | 0.019618 | 0.263753 | 0.054494 | 0.025198 |
2 | 1.887136 | 0.012615 | 0.032919 | 0.021573 | 0.012615 | 0.151159 | 0.012615 | 0.026947 | 0.003658 | 0.006046 | ... | 0.292899 | 0.022749 | 1.229923 | 0.009525 | 0.740630 | 0.009525 | 0.003857 | 0.173882 | 0.107761 | 0.028416 |
3 | 1.887136 | 0.012615 | 0.032919 | 0.021573 | 0.012615 | 0.151159 | 0.012615 | 0.026947 | 0.003658 | 0.006046 | ... | 0.104374 | 0.047651 | 1.430971 | 0.055580 | 0.603906 | 0.009225 | 0.214161 | 0.140970 | 0.027523 | 0.040332 |
4 | 1.887136 | 0.012615 | 0.032919 | 0.021573 | 0.012615 | 0.151159 | 0.012615 | 0.026947 | 0.003658 | 0.006046 | ... | 0.000757 | 0.052555 | 0.236201 | 0.037082 | 0.333742 | 0.010175 | 0.333742 | 0.091571 | 0.070717 | 0.758888 |
5 | 1.949861 | 0.081918 | 0.021740 | 0.039793 | 0.009102 | 0.195656 | 0.006093 | 0.003686 | 0.001881 | 0.003686 | ... | 0.056047 | 0.387566 | 0.479825 | 0.366038 | 0.184595 | 0.142156 | 0.387566 | 0.199972 | 0.129240 | 0.324829 |
6 | 1.949861 | 0.081918 | 0.021740 | 0.039793 | 0.009102 | 0.195656 | 0.006093 | 0.003686 | 0.001881 | 0.003686 | ... | 0.079654 | 0.122956 | 0.221262 | 0.290311 | 0.122956 | 0.389787 | 0.254616 | 0.175620 | 0.111253 | 0.053322 |
7 | 1.956062 | 0.228274 | 0.021809 | 0.055012 | 0.000679 | 0.092442 | 0.012753 | 0.000075 | 0.000075 | 0.012753 | ... | 0.245442 | 0.000730 | 0.077973 | 0.194812 | 0.068237 | 0.301914 | 0.099394 | 0.111078 | 0.164304 | 0.000081 |
8 | 1.812508 | 0.063447 | 0.001886 | 0.000075 | 0.009129 | 0.103281 | 0.009129 | 0.003697 | 0.012750 | 0.006111 | ... | 0.348333 | 0.038704 | 0.063979 | 0.228272 | 0.265484 | 0.038704 | 0.193869 | 0.000088 | 0.285143 | 0.285143 |
9 | 1.887136 | 0.012615 | 0.032919 | 0.021573 | 0.012615 | 0.151159 | 0.012615 | 0.026947 | 0.003658 | 0.006046 | ... | 0.614613 | 0.135698 | 0.004372 | 0.097157 | 0.075031 | 0.004372 | 0.197080 | 0.047196 | 0.475435 | 0.214209 |
10 | 1.769097 | 0.000663 | 0.005964 | 0.008910 | 0.021281 | 0.206843 | 0.000074 | 0.061928 | 0.000074 | 0.008910 | ... | 0.614613 | 0.135698 | 0.004372 | 0.097157 | 0.075031 | 0.004372 | 0.197080 | 0.047196 | 0.475435 | 0.214209 |
11 | 1.643312 | 0.001850 | 0.001850 | 0.003627 | 0.053960 | 0.177721 | 0.000666 | 0.101333 | 0.000074 | 0.016654 | ... | 0.619059 | 0.104962 | 0.072059 | 0.117300 | 0.045326 | 0.014480 | 0.240683 | 0.104962 | 0.318826 | 0.117300 |
12 | 1.331594 | 0.053264 | 0.038651 | 0.003580 | 0.089504 | 0.190040 | 0.021116 | 0.289992 | 0.005918 | 0.038651 | ... | 0.705611 | 0.092792 | 0.129602 | 0.092792 | 0.019172 | 0.024625 | 0.221627 | 0.081885 | 0.338192 | 0.053255 |
13 | 1.331594 | 0.053264 | 0.038651 | 0.003580 | 0.089504 | 0.190040 | 0.021116 | 0.289992 | 0.005918 | 0.038651 | ... | 0.486022 | 0.124682 | 0.247971 | 0.112222 | 0.013854 | 0.051234 | 0.230264 | 0.124682 | 0.112222 | 0.023690 |
14 | 1.305751 | 0.021333 | 0.090426 | 0.021333 | 0.039049 | 0.207352 | 0.080387 | 0.207352 | 0.008932 | 0.062080 | ... | 0.133836 | 0.009634 | 0.630646 | 0.023009 | 0.023009 | 0.009634 | 0.223644 | 0.086703 | 0.001990 | 0.049761 |
15 | 1.049711 | 0.001853 | 0.352918 | 0.101480 | 0.026760 | 0.071236 | 0.071236 | 0.275826 | 0.001853 | 0.012527 | ... | 0.040197 | 0.055395 | 1.004931 | 0.027431 | 0.012842 | 0.001900 | 0.321046 | 0.017097 | 0.001900 | 0.012842 |
16 | 1.049711 | 0.001853 | 0.352918 | 0.101480 | 0.026760 | 0.071236 | 0.071236 | 0.275826 | 0.001853 | 0.012527 | ... | 0.000075 | 0.244924 | 1.031938 | 0.033245 | 0.012740 | 0.054955 | 0.446954 | 0.012740 | 0.000075 | 0.016962 |
17 | 1.049711 | 0.001853 | 0.352918 | 0.101480 | 0.026760 | 0.071236 | 0.071236 | 0.275826 | 0.001853 | 0.012527 | ... | 0.009178 | 0.182117 | 1.110530 | 0.021921 | 0.006144 | 0.033450 | 0.382363 | 0.033450 | 0.009178 | 0.040125 |
18 | 1.200942 | 0.012583 | 0.334245 | 0.091212 | 0.000670 | 0.054280 | 0.016753 | 0.137674 | 0.001861 | 0.000074 | ... | 0.006119 | 0.166885 | 1.336367 | 0.009141 | 0.033317 | 0.027273 | 0.262982 | 0.039965 | 0.033317 | 0.047217 |
19 | 0.971130 | 0.033540 | 0.549488 | 0.182605 | 0.040232 | 0.012853 | 0.009202 | 0.093166 | 0.027455 | 0.012853 | ... | 0.016798 | 0.194181 | 1.360613 | 0.012617 | 0.039493 | 0.062786 | 0.151179 | 0.032923 | 0.102205 | 0.039493 |
20 | 1.022361 | 0.209790 | 0.442806 | 0.062810 | 0.054445 | 0.000075 | 0.001867 | 0.054445 | 0.016804 | 0.125545 | ... | 0.000075 | 0.062887 | 1.444752 | 0.032976 | 0.102369 | 0.016825 | 0.102369 | 0.000075 | 0.165181 | 0.016825 |
21 | 1.079578 | 0.292661 | 0.351060 | 0.012461 | 0.021310 | 0.001843 | 0.000074 | 0.046085 | 0.001843 | 0.177042 | ... | 0.000075 | 0.062887 | 1.444752 | 0.032976 | 0.102369 | 0.016825 | 0.102369 | 0.000075 | 0.165181 | 0.016825 |
22 | 1.079578 | 0.292661 | 0.351060 | 0.012461 | 0.021310 | 0.001843 | 0.000074 | 0.046085 | 0.001843 | 0.177042 | ... | 0.001882 | 0.047050 | 1.102184 | 0.114502 | 0.166295 | 0.016938 | 0.126547 | 0.047050 | 0.211463 | 0.012722 |
23 | 0.962534 | 0.424015 | 0.379993 | 0.016961 | 0.092341 | 0.003694 | 0.000075 | 0.006106 | 0.021785 | 0.262400 | ... | 0.013193 | 0.000078 | 1.032383 | 0.041295 | 0.056908 | 0.022560 | 0.085011 | 0.056908 | 0.329816 | 0.001952 |
24 | 0.893307 | 0.569097 | 0.400676 | 0.054812 | 0.102932 | 0.006090 | 0.003684 | 0.000075 | 0.000075 | 0.126391 | ... | 0.035755 | 0.029269 | 0.860146 | 0.013702 | 0.023431 | 0.059105 | 0.050673 | 0.068186 | 0.456058 | 0.003973 |
25 | 0.893307 | 0.569097 | 0.400676 | 0.054812 | 0.102932 | 0.006090 | 0.003684 | 0.000075 | 0.000075 | 0.126391 | ... | 0.069717 | 0.029926 | 0.627457 | 0.036558 | 0.069717 | 0.051811 | 0.036558 | 0.183122 | 0.598940 | 0.010031 |
26 | 0.752894 | 0.666098 | 0.274632 | 0.000664 | 0.311830 | 0.001845 | 0.001845 | 0.039043 | 0.003616 | 0.239795 | ... | 0.069717 | 0.029926 | 0.627457 | 0.036558 | 0.069717 | 0.051811 | 0.036558 | 0.183122 | 0.598940 | 0.010031 |
27 | 0.752894 | 0.666098 | 0.274632 | 0.000664 | 0.311830 | 0.001845 | 0.001845 | 0.039043 | 0.003616 | 0.239795 | ... | 0.010066 | 0.069961 | 0.688879 | 0.113884 | 0.090592 | 0.036686 | 0.014059 | 0.113884 | 0.545796 | 0.000749 |
28 | 0.880273 | 0.697121 | 0.136994 | 0.003630 | 0.294067 | 0.026747 | 0.001852 | 0.062310 | 0.000074 | 0.224125 | ... | 0.073177 | 0.119119 | 0.438626 | 0.054382 | 0.019578 | 0.025146 | 0.002175 | 0.119119 | 0.887607 | 0.010528 |
29 | 0.880273 | 0.697121 | 0.136994 | 0.003630 | 0.294067 | 0.026747 | 0.001852 | 0.062310 | 0.000074 | 0.224125 | ... | 0.045704 | 0.145232 | 0.485978 | 0.038101 | 0.072659 | 0.083027 | 0.006998 | 0.190849 | 0.916575 | 0.006998 |
30 | 0.880273 | 0.697121 | 0.136994 | 0.003630 | 0.294067 | 0.026747 | 0.001852 | 0.062310 | 0.000074 | 0.224125 | ... | 0.045704 | 0.145232 | 0.485978 | 0.038101 | 0.072659 | 0.083027 | 0.006998 | 0.190849 | 0.916575 | 0.006998 |
31 | 0.880273 | 0.697121 | 0.136994 | 0.003630 | 0.294067 | 0.026747 | 0.001852 | 0.062310 | 0.000074 | 0.224125 | ... | 0.031193 | 0.242715 | 0.435574 | 0.006999 | 0.105848 | 0.118290 | 0.045709 | 0.261379 | 1.064612 | 0.002160 |
32 | 0.779623 | 0.663220 | 0.123532 | 0.016535 | 0.176442 | 0.021238 | 0.012419 | 0.016535 | 0.008892 | 0.238759 | ... | 0.044414 | 0.253974 | 0.472267 | 0.002099 | 0.114939 | 0.061206 | 0.024264 | 0.052474 | 0.856461 | 0.018891 |
33 | 0.779623 | 0.663220 | 0.123532 | 0.016535 | 0.176442 | 0.021238 | 0.012419 | 0.016535 | 0.008892 | 0.238759 | ... | 0.044414 | 0.253974 | 0.472267 | 0.002099 | 0.114939 | 0.061206 | 0.024264 | 0.052474 | 0.856461 | 0.018891 |
34 | 0.779623 | 0.663220 | 0.123532 | 0.016535 | 0.176442 | 0.021238 | 0.012419 | 0.016535 | 0.008892 | 0.238759 | ... | 0.066528 | 0.108296 | 0.626600 | 0.022862 | 0.076021 | 0.017799 | 0.013369 | 0.006408 | 0.684189 | 0.160190 |
35 | 0.779623 | 0.663220 | 0.123532 | 0.016535 | 0.176442 | 0.021238 | 0.012419 | 0.016535 | 0.008892 | 0.238759 | ... | 0.066528 | 0.108296 | 0.626600 | 0.022862 | 0.076021 | 0.017799 | 0.013369 | 0.006408 | 0.684189 | 0.160190 |
36 rows × 3787 columns
Using this data, one can create plots displaying the contribution of an input to the uncertainty of an output. The following graph is not representative since only 10 runs were conducted.
graph_pd = spearman_results_normalized_pd.groupby(level=[0,1,2], axis = 1).sum()
graph_pd = graph_pd['U.A use stock'].copy()
graph_pd.columns = ['_'.join(col) for col in graph_pd.columns]
graph_pd
dic_legend = {'n_initial_products_Share': r'$\eta$: Initial inflow distribution',
'n_use_1_in_use_Weibull scale': r'$S_{Uk}$: Weibull scale',
'n_use_1_in_use_Weibull shape': r'$S_{Uk}$: Weibull shape',
'reuse_split_split': r'$\delta$: Split portable batteries to products'
}
handles_names_list = []
fig, ax = plt.subplots()
stacks = ax.stackplot(graph_pd.index, graph_pd.transpose().to_numpy())
plt.ylabel('Normalized square of Spearman\'s rank correlation in %')
plt.xlabel('Year')
Text(0.5, 0, 'Year')