Run EnergyScope with LCA impact scores¶
In this notebook, we show how to use LCA data in EnergyScope. We use the core model of EnergyScope as an illustrative example. Before following this tutorial, make sure you have followed the "Generation of LCA impact scores" tutorial to generate the .dat and .mod files of LCA parameters and constraints to be used in EnergyScope.
We show how to:
- easily add the LCA .mod and .dat files to the core version
- run the model
- format the results
- visualise the results using mescal's ⧉ visualisation features
%pip install mescal==1.2.3
%pip install energyscope==2.1.2
Once you have generated your set of LCA metrics, you are ready to run EnergyScope with LCA variables as objective function or constraints.
Import packages¶
from energyscope.models import core, Model
from energyscope.energyscope import Energyscope
from mescal import Plot
import pandas as pd
INPUT_DATA_FOLDER = 'path/to/your/input/files/' # put the path of your data folder here
LCA_RESULTS_FOLDER = 'path/to/your/lca/results/files/' # put the path of your LCA results folder here
license_uuid = 'xxx' # put your AMPL licence UUID here
lifetime = pd.read_csv(INPUT_DATA_FOLDER+'lifetime.csv')
impact_scores_lca = pd.read_csv(LCA_RESULTS_FOLDER+'impact_scores.csv') # LCA impact scores
impact_scores_direct = pd.read_csv(LCA_RESULTS_FOLDER+'impact_scores_direct_emissions.csv') # Impact scores for direct emissions
Run EnergyScope¶
LCA_model = Model([
('mod', LCA_RESULTS_FOLDER+'objectives_lca.mod'),
# ('mod', LCA_RESULTS_FOLDER+'objectives_lca_direct.mod'),
('dat', LCA_RESULTS_FOLDER+'techs_lca.dat'),
# ('dat', LCA_RESULTS_FOLDER+'techs_lca_direct.dat'),
])
core = core.__add__(LCA_model) # add the LCA model to the core model
Make sure to replace the license UUID with your own, you can access it directly from the AMPL portal ⧉. If you don't have an account please create one, and favor your academic address to get access to the free academic license.
energyscope_lca = Energyscope(
model=core,
solver_options={'solver': 'gurobi','gurobi_options':'outlev=1 NumericFocus=2 method=2'},
notebook=True,
modules=['gurobi'],
license_uuid=license_uuid,
)
results_tc = energyscope_lca.calc()
Gurobi 13.0.0: Set parameter LogToConsole to value 1
tech:outlev = 1
Set parameter NumericFocus to value 2
alg:numericfocus = 2
Set parameter Method to value 2
alg:method = 2
Set parameter InfUnbdInfo to value 1
Gurobi Optimizer version 13.0.0 build v13.0.0rc1 (win64 - Windows 11+.0 (26200.2))
CPU model: 12th Gen Intel(R) Core(TM) i7-1255U, instruction set [SSE2|AVX|AVX2]
Thread count: 10 physical cores, 12 logical processors, using up to 12 threads
Non-default parameters:
Method 2
InfUnbdInfo 1
NumericFocus 2
Optimize a model with 491079 rows, 268733 columns and 1576042 nonzeros (Min)
Model fingerprint: 0xd356ac1f
Model has 1 linear objective coefficients
Coefficient statistics:
Matrix range [1e-06, 7e+04]
Objective range [1e+00, 1e+00]
Bounds range [2e-02, 6e+01]
RHS range [1e+00, 4e+04]
Presolve removed 244066 rows and 129177 columns
Presolve time: 2.06s
Presolved: 247013 rows, 139556 columns, 796682 nonzeros
Elapsed ordering time = 5s
Ordering time: 6.22s
Barrier statistics:
Dense cols : 98
AA' NZ : 3.799e+06
Factor NZ : 1.783e+07 (roughly 300 MB of memory)
Factor Ops : 5.419e+09 (less than 1 second per iteration)
Threads : 10
Objective Residual
Iter Primal Dual Primal Dual Compl Time
0 1.16221582e+07 -1.07972572e+06 4.56e+05 1.98e+00 1.00e+06 10s
1 1.25699879e+07 -2.23258072e+06 3.39e+05 8.36e+02 9.02e+05 11s
2 1.28525617e+07 -4.29550079e+06 3.27e+05 8.19e+02 8.30e+05 12s
3 1.45819284e+07 -5.45424209e+07 2.15e+05 6.27e+02 6.54e+05 14s
4 1.57985628e+07 -8.06542194e+07 1.47e+05 2.94e+02 3.34e+05 15s
5 1.58143484e+07 -9.28941450e+07 1.01e+05 1.07e+02 1.43e+05 16s
6 1.37132584e+07 -9.54890885e+07 5.11e+04 3.77e+01 5.86e+04 17s
7 1.21412725e+07 -9.33472784e+07 3.35e+04 2.17e+01 3.57e+04 17s
8 1.02479985e+07 -8.87644492e+07 1.65e+04 1.35e+01 2.09e+04 18s
9 8.81154076e+06 -7.87875007e+07 7.25e+03 5.73e+00 9.06e+03 19s
10 7.41870842e+06 -6.61055957e+07 1.66e+03 1.95e+00 2.90e+03 19s
11 6.33868760e+06 -4.49264671e+07 4.91e+02 5.32e-01 8.72e+02 20s
12 5.09632545e+06 -2.98611201e+07 1.89e+02 2.72e-01 4.45e+02 21s
13 3.61146627e+06 -8.63298365e+06 8.14e+01 6.63e-02 1.18e+02 22s
14 2.21995915e+06 -5.21091545e+06 4.02e+01 3.74e-02 6.61e+01 23s
15 1.65819263e+06 -2.73769548e+06 2.60e+01 1.91e-02 3.55e+01 24s
16 1.16413210e+06 -1.34312887e+06 1.69e+01 9.06e-03 1.82e+01 25s
17 5.50330444e+05 -9.12655663e+05 5.97e+00 6.30e-03 1.13e+01 26s
18 4.12065297e+05 -4.76476645e+05 4.11e+00 3.35e-03 6.35e+00 26s
19 3.51659255e+05 -3.94296399e+05 3.35e+00 2.80e-03 5.30e+00 27s
20 2.64045270e+05 -2.43919304e+05 2.30e+00 1.81e-03 3.51e+00 28s
21 1.61786892e+05 -9.42045456e+04 1.13e+00 8.03e-04 1.66e+00 29s
22 1.12369936e+05 -3.84244935e+04 6.24e-01 4.45e-04 9.53e-01 30s
23 1.03996174e+05 -1.75539668e+03 5.50e-01 2.34e-04 6.03e-01 32s
24 9.13755464e+04 2.91937287e+03 4.54e-01 2.00e-04 5.08e-01 33s
25 8.73187535e+04 1.26145454e+04 4.16e-01 1.42e-04 4.06e-01 34s
26 7.71796901e+04 2.05984982e+04 3.08e-01 1.03e-04 3.04e-01 34s
27 6.34278768e+04 2.79827910e+04 1.77e-01 6.68e-05 1.93e-01 36s
28 5.66737788e+04 3.38869069e+04 1.14e-01 3.72e-05 1.21e-01 37s
29 5.32144210e+04 3.83798497e+04 8.40e-02 1.47e-05 7.23e-02 38s
30 5.01388129e+04 4.05325357e+04 5.78e-02 1.01e-05 4.46e-02 39s
31 4.92983443e+04 4.10253007e+04 5.08e-02 8.37e-06 3.78e-02 39s
32 4.92060856e+04 4.12656878e+04 4.98e-02 7.40e-06 3.56e-02 40s
33 4.84848815e+04 4.14784610e+04 4.38e-02 6.49e-06 3.13e-02 41s
34 4.66655203e+04 4.18354447e+04 2.95e-02 4.88e-06 2.19e-02 42s
35 4.59158134e+04 4.22228092e+04 2.37e-02 3.10e-06 1.62e-02 43s
36 4.53685484e+04 4.23797586e+04 1.96e-02 2.42e-06 1.31e-02 44s
37 4.50601261e+04 4.24216492e+04 1.73e-02 2.21e-06 1.16e-02 46s
38 4.44990860e+04 4.25543765e+04 1.34e-02 1.57e-06 8.53e-03 47s
39 4.40060849e+04 4.26904328e+04 9.25e-03 9.40e-07 5.67e-03 48s
40 4.35846484e+04 4.27413718e+04 5.76e-03 6.72e-07 3.69e-03 49s
41 4.34374269e+04 4.27894049e+04 4.61e-03 4.35e-07 2.76e-03 51s
42 4.32781731e+04 4.28230999e+04 3.28e-03 2.66e-07 1.90e-03 52s
43 4.32062320e+04 4.28423280e+04 2.66e-03 1.73e-07 1.49e-03 52s
44 4.31751965e+04 4.28481539e+04 2.39e-03 1.48e-07 1.33e-03 53s
45 4.31023011e+04 4.28523670e+04 1.77e-03 1.28e-07 1.02e-03 54s
46 4.30142357e+04 4.28624214e+04 1.02e-03 8.28e-08 6.22e-04 54s
47 4.29896240e+04 4.28722208e+04 8.36e-04 3.97e-08 4.62e-04 56s
48 4.29437318e+04 4.28741728e+04 4.59e-04 3.22e-08 2.77e-04 57s
49 4.29351813e+04 4.28769598e+04 3.94e-04 2.25e-08 2.29e-04 58s
50 4.29330983e+04 4.28772479e+04 3.78e-04 2.15e-08 2.19e-04 59s
51 4.29312516e+04 4.28777019e+04 3.64e-04 2.01e-08 2.10e-04 60s
52 4.29174894e+04 4.28788118e+04 2.54e-04 1.62e-08 1.52e-04 61s
53 4.29116030e+04 4.28800171e+04 2.11e-04 1.19e-08 1.23e-04 63s
54 4.29086736e+04 4.28804657e+04 1.88e-04 1.04e-08 1.09e-04 64s
55 4.29058082e+04 4.28807984e+04 1.66e-04 9.32e-09 9.68e-05 66s
56 4.29038163e+04 4.28811254e+04 1.52e-04 8.27e-09 8.76e-05 67s
57 4.29008870e+04 4.28816871e+04 1.30e-04 5.85e-09 7.35e-05 69s
58 4.28992344e+04 4.28824342e+04 1.17e-04 3.49e-09 6.35e-05 70s
59 4.28954488e+04 4.28826129e+04 8.71e-05 3.03e-09 4.86e-05 71s
60 4.28921329e+04 4.28828962e+04 6.30e-05 2.01e-09 3.48e-05 73s
61 4.28912646e+04 4.28830338e+04 5.63e-05 1.71e-09 3.10e-05 76s
62 4.28905126e+04 4.28831294e+04 5.14e-05 1.50e-09 2.78e-05 78s
63 4.28888688e+04 4.28832359e+04 3.87e-05 1.20e-09 2.12e-05 81s
64 4.28874818e+04 4.28833201e+04 2.85e-05 9.81e-10 1.57e-05 83s
65 4.28870771e+04 4.28833635e+04 2.54e-05 8.87e-10 1.40e-05 85s
66 4.28864400e+04 4.28834973e+04 2.03e-05 6.29e-10 1.11e-05 88s
67 4.28860879e+04 4.28836333e+04 1.74e-05 3.63e-10 9.17e-06 90s
68 4.28852039e+04 4.28836858e+04 1.03e-05 2.58e-10 5.68e-06 92s
69 4.28849379e+04 4.28837337e+04 8.34e-06 1.50e-10 4.49e-06 95s
70 4.28844716e+04 4.28837400e+04 4.60e-06 1.39e-10 2.74e-06 97s
71 4.28843262e+04 4.28837646e+04 3.52e-06 8.73e-11 2.10e-06 99s
72 4.28840292e+04 4.28837858e+04 1.40e-06 4.50e-11 9.14e-07 100s
73 4.28838815e+04 4.28838115e+04 4.02e-07 5.06e-12 2.60e-07 102s
74 4.28838282e+04 4.28838150e+04 6.23e-08 2.20e-12 4.97e-08 103s
75 4.28838191e+04 4.28838175e+04 7.71e-09 3.64e-12 6.01e-09 104s
76 4.28838179e+04 4.28838177e+04 1.17e-09 2.73e-12 6.08e-10 105s
Barrier solved model in 76 iterations and 105.20 seconds (60.13 work units)
Optimal objective 4.28838179e+04
Crossover log...
53590 DPushes remaining with DInf 0.0000000e+00 106s
13503 DPushes remaining with DInf 0.0000000e+00 111s
8328 DPushes remaining with DInf 0.0000000e+00 115s
3315 DPushes remaining with DInf 0.0000000e+00 120s
1563 DPushes remaining with DInf 0.0000000e+00 125s
553 DPushes remaining with DInf 0.0000000e+00 130s
0 DPushes remaining with DInf 0.0000000e+00 134s
3817 PPushes remaining with PInf 1.0675306e-04 134s
3059 PPushes remaining with PInf 7.3430441e-02 135s
0 PPushes remaining with PInf 0.0000000e+00 139s
Push phase complete: Pinf 0.0000000e+00, Dinf 1.2346462e+02 139s
Iteration Objective Primal Inf. Dual Inf. Time
40664 4.2883818e+04 0.000000e+00 1.234646e+02 139s
40765 4.2883818e+04 0.000000e+00 2.660964e-02 140s
41270 4.2883818e+04 0.000000e+00 3.090717e+01 146s
41674 4.2883818e+04 0.000000e+00 4.082870e-03 150s
Crossover time: 45.17 seconds (16.75 work units)
41697 4.2883818e+04 0.000000e+00 0.000000e+00 151s
Solved in 41697 iterations and 151.16 seconds (77.11 work units)
Optimal objective 4.288381774e+04
AMPL MP initial flat model has 268733 variables (0 integer, 0 binary);
Objectives: 1 linear;
Constraints: 491079 linear;
AMPL MP final model has 268733 variables (0 integer, 0 binary);
Objectives: 1 linear;
Constraints: 491079 linear;
Gurobi 13.0.0: optimal solution; objective 42883.81774
41697 simplex iterations
76 barrier iterations
results_tc.variables['TotalLCIA']
| TotalLCIA | Run | |
|---|---|---|
| TTEQ | 1682.413198 | 0 |
| TTHH | 1200.001631 | 0 |
You might want to change the objective function with an environmental objective, such as the life-cycle greenhouse gas emissions, or the total damage on human health/ecosystem quality. Alternatively, you can also add a constraint on the total life-cycle impact, to be lower than a certain threshold.
# To change the objective function
# energyscope_lca.es_model.eval("""
# drop obj;
# minimize new_obj: TotalLCIA_TTHH;
# """)
# To add upper limits on environmental impacts
reduction_target = 0.5 # for instance, 50% reduction target of damages
scenario_file_path = LCA_RESULTS_FOLDER + 'scenario.dat'
with open(scenario_file_path, 'w', encoding='utf-8', newline='\n') as f:
f.write(f"let limit_lcia['TTHH'] := {reduction_target} * {results_tc.variables['TotalLCIA'].loc['TTHH'].iloc[0]};\n")
f.write(f"let limit_lcia['TTEQ'] := {reduction_target} * {results_tc.variables['TotalLCIA'].loc['TTEQ'].iloc[0]};\n")
core = core.__add__(Model([('dat', scenario_file_path)])) # add the scenario file to the core model
energyscope_lca = Energyscope(
model=core,
solver_options={'solver': 'gurobi', 'gurobi_options':'outlev=1 NumericFocus=2 method=2'},
notebook=True,
modules=['gurobi'],
license_uuid=license_uuid,
)
results_lca = energyscope_lca.calc()
Gurobi 13.0.0: Set parameter LogToConsole to value 1
tech:outlev = 1
Set parameter NumericFocus to value 2
alg:numericfocus = 2
Set parameter Method to value 2
alg:method = 2
Set parameter InfUnbdInfo to value 1
Gurobi Optimizer version 13.0.0 build v13.0.0rc1 (win64 - Windows 11+.0 (26200.2))
CPU model: 12th Gen Intel(R) Core(TM) i7-1255U, instruction set [SSE2|AVX|AVX2]
Thread count: 10 physical cores, 12 logical processors, using up to 12 threads
Non-default parameters:
Method 2
InfUnbdInfo 1
NumericFocus 2
Optimize a model with 491079 rows, 268733 columns and 1576042 nonzeros (Min)
Model fingerprint: 0x4c617831
Model has 1 linear objective coefficients
Coefficient statistics:
Matrix range [1e-06, 7e+04]
Objective range [1e+00, 1e+00]
Bounds range [2e-02, 8e+02]
RHS range [1e+00, 4e+04]
Presolve removed 243488 rows and 128315 columns
Presolve time: 1.36s
Presolved: 247591 rows, 140418 columns, 824522 nonzeros
Elapsed ordering time = 5s
Ordering time: 6.15s
Barrier statistics:
Dense cols : 98
AA' NZ : 3.840e+06
Factor NZ : 1.875e+07 (roughly 300 MB of memory)
Factor Ops : 7.249e+09 (less than 1 second per iteration)
Threads : 10
Objective Residual
Iter Primal Dual Primal Dual Compl Time
0 2.01588285e+06 -3.78949316e+05 3.23e+06 1.44e+00 1.00e+06 9s
1 2.02961667e+06 -1.05983728e+06 2.98e+06 8.46e+02 9.54e+05 10s
2 2.23051767e+06 -3.13164283e+06 2.56e+06 7.72e+02 8.64e+05 11s
3 2.43833112e+06 -8.41836569e+06 2.31e+06 5.48e+02 6.50e+05 12s
4 3.49303007e+06 -3.83871563e+07 1.74e+06 3.10e+02 4.27e+05 13s
5 4.01758930e+06 -4.57182269e+07 7.44e+05 1.78e+02 2.18e+05 14s
6 3.57671925e+06 -5.06294971e+07 4.04e+05 8.48e+01 1.03e+05 15s
7 2.84239390e+06 -5.64359613e+07 2.24e+05 4.62e+01 5.76e+04 16s
8 1.94953735e+06 -5.92023907e+07 1.24e+05 3.65e+01 4.14e+04 17s
9 1.43348058e+06 -6.93652223e+07 7.97e+04 1.80e+01 2.24e+04 18s
10 1.26019437e+06 -7.33994190e+07 6.73e+04 1.00e+01 1.48e+04 19s
11 1.11193558e+06 -7.29707611e+07 5.64e+04 8.98e+00 1.30e+04 19s
12 9.63042807e+05 -7.36628269e+07 4.56e+04 5.15e+00 8.81e+03 20s
13 8.86370732e+05 -7.24436364e+07 4.01e+04 3.71e+00 7.07e+03 21s
14 8.51428345e+05 -6.84825339e+07 3.76e+04 3.00e+00 6.19e+03 22s
15 7.84686759e+05 -6.46982236e+07 3.31e+04 2.47e+00 5.29e+03 24s
16 6.91361134e+05 -6.28136961e+07 2.69e+04 1.35e+00 3.70e+03 25s
17 4.49366280e+05 -6.02187500e+07 1.23e+04 9.06e-01 2.02e+03 26s
18 3.81110012e+05 -4.88322998e+07 8.59e+03 5.40e-01 1.32e+03 28s
19 3.40650916e+05 -4.18598616e+07 6.61e+03 3.19e-01 9.31e+02 29s
20 3.00223030e+05 -3.20743234e+07 4.58e+03 1.81e-01 5.91e+02 30s
21 2.82822856e+05 -3.31500836e+07 3.77e+03 1.74e-01 5.26e+02 30s
22 2.78521091e+05 -2.86597124e+07 3.58e+03 1.38e-01 4.56e+02 31s
23 2.76667981e+05 -2.65037933e+07 3.51e+03 1.19e-01 4.22e+02 32s
24 2.58638053e+05 -2.23392473e+07 2.84e+03 8.95e-02 3.32e+02 33s
25 2.25562724e+05 -1.52150571e+07 1.51e+03 4.73e-02 1.83e+02 35s
26 1.99570407e+05 -9.58948378e+06 7.44e+02 2.56e-02 9.42e+01 36s
27 1.86018668e+05 -5.70309392e+06 4.41e+02 1.31e-02 5.09e+01 37s
28 1.75733403e+05 -4.07464749e+06 2.49e+02 8.51e-03 3.31e+01 38s
29 1.71191179e+05 -2.60940412e+06 1.67e+02 5.26e-03 2.08e+01 39s
30 1.66183298e+05 -2.24691648e+06 7.85e+01 4.50e-03 1.74e+01 40s
31 1.62339436e+05 -1.84721924e+06 3.66e+01 3.70e-03 1.44e+01 41s
32 1.54651690e+05 -7.21601541e+05 1.51e+01 1.51e-03 6.04e+00 42s
33 1.45908550e+05 -3.98730974e+05 8.26e+00 8.93e-04 3.62e+00 43s
34 1.32958641e+05 -2.35946189e+05 4.56e+00 5.87e-04 2.38e+00 44s
35 1.28069610e+05 -2.00562235e+05 3.62e+00 5.22e-04 2.11e+00 45s
36 1.24593099e+05 -6.94358849e+04 3.07e+00 2.80e-04 1.20e+00 46s
37 1.20426474e+05 -2.45895484e+04 2.54e+00 1.98e-04 8.69e-01 47s
38 1.17969371e+05 -6.82798570e+03 2.29e+00 1.65e-04 7.38e-01 48s
39 1.14139346e+05 1.67815900e+04 1.94e+00 1.25e-04 5.64e-01 49s
40 1.08363105e+05 2.34332988e+04 1.61e+00 1.10e-04 4.93e-01 50s
41 1.04315530e+05 2.86214891e+04 1.45e+00 9.90e-05 4.43e-01 52s
42 1.01741814e+05 3.14864315e+04 1.36e+00 9.27e-05 4.14e-01 53s
43 9.86515393e+04 3.53800475e+04 1.26e+00 8.34e-05 3.75e-01 55s
44 9.74846806e+04 3.76370184e+04 1.22e+00 7.77e-05 3.55e-01 56s
45 9.44766076e+04 4.13981461e+04 1.12e+00 6.83e-05 3.17e-01 58s
46 9.19686597e+04 4.39776972e+04 1.04e+00 6.15e-05 2.90e-01 59s
47 8.93603861e+04 4.60022128e+04 9.51e-01 5.61e-05 2.66e-01 60s
48 8.76859143e+04 4.77486744e+04 8.79e-01 5.18e-05 2.45e-01 62s
49 8.62813695e+04 4.92868516e+04 8.24e-01 4.82e-05 2.28e-01 63s
50 8.56027759e+04 5.13966220e+04 7.84e-01 4.31e-05 2.07e-01 65s
51 8.48957004e+04 5.19816373e+04 7.54e-01 4.15e-05 2.00e-01 66s
52 8.32394680e+04 5.41928043e+04 6.86e-01 3.54e-05 1.74e-01 67s
53 8.17250808e+04 5.59114211e+04 5.84e-01 2.76e-05 1.45e-01 69s
54 7.87495275e+04 5.77675718e+04 4.50e-01 2.28e-05 1.18e-01 70s
55 7.65910015e+04 5.92651673e+04 3.59e-01 1.90e-05 9.66e-02 71s
56 7.36448198e+04 6.01303203e+04 2.43e-01 1.67e-05 7.76e-02 73s
57 7.19088527e+04 6.22074540e+04 1.87e-01 1.11e-05 5.42e-02 74s
58 7.05686900e+04 6.27428127e+04 1.42e-01 9.49e-06 4.46e-02 76s
59 7.01475919e+04 6.33239274e+04 1.29e-01 7.82e-06 3.82e-02 77s
60 6.93732340e+04 6.35928516e+04 1.06e-01 7.05e-06 3.31e-02 78s
61 6.89873744e+04 6.40345232e+04 9.49e-02 5.74e-06 2.79e-02 80s
62 6.84844975e+04 6.43410345e+04 8.14e-02 4.73e-06 2.34e-02 81s
63 6.78596306e+04 6.45634167e+04 6.38e-02 3.96e-06 1.90e-02 83s
64 6.75753884e+04 6.46952693e+04 5.53e-02 3.51e-06 1.68e-02 84s
65 6.73778881e+04 6.48756450e+04 4.98e-02 2.91e-06 1.44e-02 86s
66 6.71801464e+04 6.49678697e+04 4.43e-02 2.59e-06 1.28e-02 87s
67 6.69549892e+04 6.50665396e+04 3.79e-02 2.20e-06 1.09e-02 89s
68 6.67230183e+04 6.51738241e+04 3.13e-02 1.80e-06 8.99e-03 91s
69 6.65736783e+04 6.52317274e+04 2.75e-02 1.55e-06 7.81e-03 92s
70 6.64142693e+04 6.53209532e+04 2.30e-02 1.15e-06 6.16e-03 94s
71 6.62266310e+04 6.53731434e+04 1.77e-02 9.21e-07 4.86e-03 95s
72 6.60582708e+04 6.54437549e+04 1.27e-02 6.04e-07 3.38e-03 96s
73 6.59096102e+04 6.54840234e+04 8.30e-03 4.39e-07 2.36e-03 98s
74 6.58326701e+04 6.55028840e+04 6.16e-03 3.68e-07 1.87e-03 99s
75 6.58071568e+04 6.55173581e+04 5.42e-03 3.13e-07 1.62e-03 100s
76 6.57869278e+04 6.55323894e+04 4.84e-03 2.55e-07 1.39e-03 102s
77 6.57552578e+04 6.55482722e+04 3.93e-03 2.00e-07 1.11e-03 103s
78 6.57239353e+04 6.55730469e+04 3.02e-03 1.13e-07 7.49e-04 105s
79 6.56918208e+04 6.55807579e+04 2.13e-03 8.75e-08 5.54e-04 106s
80 6.56800478e+04 6.55833962e+04 1.80e-03 7.89e-08 4.85e-04 108s
81 6.56739060e+04 6.55857870e+04 1.65e-03 7.19e-08 4.41e-04 109s
82 6.56604181e+04 6.55889154e+04 1.27e-03 6.18e-08 3.62e-04 111s
83 6.56544422e+04 6.55930475e+04 1.11e-03 4.96e-08 3.04e-04 113s
84 6.56462729e+04 6.55950294e+04 8.97e-04 4.31e-08 2.55e-04 115s
85 6.56347720e+04 6.56000346e+04 5.94e-04 2.83e-08 1.71e-04 117s
86 6.56298669e+04 6.56020877e+04 4.66e-04 2.18e-08 1.35e-04 119s
87 6.56254123e+04 6.56038452e+04 3.62e-04 1.65e-08 1.04e-04 121s
88 6.56211635e+04 6.56052583e+04 2.57e-04 1.24e-08 7.63e-05 122s
89 6.56169905e+04 6.56067541e+04 1.58e-04 8.06e-09 4.90e-05 124s
90 6.56133437e+04 6.56081336e+04 7.56e-05 4.33e-09 2.52e-05 126s
91 6.56121677e+04 6.56085089e+04 5.07e-05 3.26e-09 1.79e-05 128s
92 6.56108899e+04 6.56088374e+04 2.33e-05 2.23e-09 1.06e-05 129s
93 6.56102570e+04 6.56092051e+04 1.11e-05 1.16e-09 5.45e-06 130s
94 6.56099389e+04 6.56093319e+04 5.37e-06 7.76e-10 3.29e-06 131s
95 6.56098815e+04 6.56094726e+04 4.28e-06 3.81e-10 2.03e-06 133s
96 6.56097789e+04 6.56095262e+04 2.51e-06 2.39e-10 1.26e-06 134s
97 6.56097299e+04 6.56095824e+04 1.63e-06 9.84e-11 6.79e-07 135s
98 6.56096722e+04 6.56096114e+04 6.78e-07 3.09e-11 2.65e-07 137s
99 6.56096412e+04 6.56096173e+04 2.01e-07 1.93e-11 1.14e-07 138s
100 6.56096347e+04 6.56096239e+04 1.04e-07 6.63e-12 4.82e-08 139s
101 6.56096282e+04 6.56096269e+04 1.05e-08 8.44e-13 5.64e-09 140s
102 6.56096274e+04 6.56096273e+04 1.01e-09 6.25e-13 5.81e-10 141s
Barrier solved model in 102 iterations and 141.06 seconds (84.15 work units)
Optimal objective 6.56096274e+04
Crossover log...
41620 DPushes remaining with DInf 5.1780300e-05 142s
15480 DPushes remaining with DInf 5.1780300e-05 145s
2980 DPushes remaining with DInf 0.0000000e+00 150s
1299 DPushes remaining with DInf 0.0000000e+00 155s
491 DPushes remaining with DInf 0.0000000e+00 161s
0 DPushes remaining with DInf 0.0000000e+00 165s
3665 PPushes remaining with PInf 2.6732668e-04 165s
3571 PPushes remaining with PInf 3.9756959e-04 165s
0 PPushes remaining with PInf 0.0000000e+00 169s
Push phase complete: Pinf 0.0000000e+00, Dinf 1.2544330e-01 170s
Iteration Objective Primal Inf. Dual Inf. Time
26531 6.5609627e+04 0.000000e+00 1.254433e-01 170s
Crossover time: 28.89 seconds (16.88 work units)
26545 6.5609627e+04 0.000000e+00 0.000000e+00 171s
Solved in 26545 iterations and 170.62 seconds (101.29 work units)
Optimal objective 6.560962735e+04
AMPL MP initial flat model has 268733 variables (0 integer, 0 binary);
Objectives: 1 linear;
Constraints: 491079 linear;
AMPL MP final model has 268733 variables (0 integer, 0 binary);
Objectives: 1 linear;
Constraints: 491079 linear;
Gurobi 13.0.0: optimal solution; objective 65609.62735
26545 simplex iterations
102 barrier iterations
results_lca.variables['TotalLCIA']
| TotalLCIA | Run | |
|---|---|---|
| TTEQ | 841.206599 | 0 |
| TTHH | 357.779093 | 0 |
Formatting the results¶
results = results_lca # choose among results_tc and results_lca
df_annual_prod = pd.merge(results.variables['F_t'].reset_index(), results.parameters['t_op'].reset_index(), left_on=['index1', 'index2'], right_on=['index0', 'index1'], suffixes=('', '_'))
df_annual_prod['Annual_Prod'] = df_annual_prod['F_t'] * df_annual_prod['t_op']
df_annual_prod = df_annual_prod.groupby(['index0', 'Run'])['Annual_Prod'].sum().reset_index()
df_installed_cap = results.variables['F'].reset_index()
df_annual_res = df_annual_prod[df_annual_prod.index0.isin(list(results.sets['RESOURCES'].RESOURCES))].rename(columns={'index0':'index', 'Annual_Prod':'Annual_Res'})
df_annual_prod = df_annual_prod[~df_annual_prod.index0.isin(list(results.sets['RESOURCES'].RESOURCES))].rename(columns={'index0':'index'})
esm_results_tech = pd.merge(
df_annual_prod,
df_installed_cap,
on=['index', 'Run']
).rename(columns={'index':'Name', 'Annual_Prod': 'Production', 'F': 'Capacity'})
esm_results_res = df_annual_res.rename(columns={'index': 'Name', 'Annual_Res': 'Import'})
esm_results_tech = esm_results_tech[esm_results_tech.Capacity != 0]
esm_results_tech.head()
| Name | Run | Production | Capacity | |
|---|---|---|---|---|
| 2 | ATM_CCS | 0 | 336.804807 | 2.167426 |
| 4 | BEV_BATT | 0 | 0.000000 | 91.160423 |
| 9 | BOAT_FREIGHT_METHANOL | 0 | 966.908558 | 30.521103 |
| 14 | BUS_COACH_HYDIESEL | 0 | 551.338240 | 6.381230 |
| 15 | CAR_BEV | 0 | 2756.691201 | 191.436889 |
esm_results_res = esm_results_res[esm_results_res.Import != 0]
esm_results_res.head()
| Name | Run | Import | |
|---|---|---|---|
| 7 | BIODIESEL | 0 | 849.952695 |
| 29 | CO2_ATM | 0 | 336.804807 |
| 31 | CO2_EMISSIONS | 0 | 176.167331 |
| 64 | ELEC_EXPORT | 0 | 587.642514 |
| 76 | H2_RE | 0 | 7132.203267 |
esm_results_tech.to_csv(LCA_RESULTS_FOLDER+'esm_results_tech.csv', index=False)
esm_results_res.to_csv(LCA_RESULTS_FOLDER+'esm_results_res.csv', index=False)
Visualise the results¶
plot = Plot(
df_impact_scores=impact_scores_lca,
esm_results_tech=esm_results_tech[~esm_results_tech.Name.isin(['ATM_CCS'])], # negative impacts are not displayed in the following plots
esm_results_res=esm_results_res,
lifetime=lifetime,
)
plot.plot_results(
impact_categories_list=[
(
'IMPACT World+ Damage 2.1 for ecoinvent v3.10',
'Ecosystem quality',
'Total ecosystem quality',
),
(
'IMPACT World+ Damage 2.1 for ecoinvent v3.10',
'Human health',
'Total human health',
),
],
normalized=True,
)
plot.plot_results(
impact_categories_list=[
(
'IMPACT World+ Damage 2.1 for ecoinvent v3.10',
'Ecosystem quality',
'Total ecosystem quality',
),
(
'IMPACT World+ Damage 2.1 for ecoinvent v3.10',
'Human health',
'Total human health',
),
],
normalized=True,
split_by='Name',
N_highest_contributors=10,
)
Due to IAM projections (in the present case, scenario SSP2-RCP26 run in TIAM-UCL) in the LCA database, some important changes occur in LCA datasets. For instance, diesel production has switched to biodiesel (from used cooking oil with CCS). Consequently, CO2 emissions from diesel combustion are biogenic (i.e., their characterization factor is 0) and the impact of TRUCK_DIESEL mostly comes from its construction.