Assess with values from a CSV file
Recall this example:
process electricity_fossil_production {
products {
1 kWh electricity_fossil
}
inputs {
1E-12 p energy_plant
}
emissions {
1.2 kg carbon_dioxide_fossil( compartment = "air" )
}
resources {
1.2 MJ hard_coal( compartment = "ground", sub_compartment = "non-renewable" )
}
}
process electricity_hydro_production {
products {
1 kWh electricity_hydro
}
inputs {
1E-12 p energy_plant
}
resources {
3.8 MJ energy_hydro ( compartment = "water", sub_compartment = "renewable" )
}
}
process electricity_wind_production {
products {
1 kWh electricity_wind
}
inputs {
1E-12 p energy_plant
}
resources {
3.8 MJ energy_wind( compartment = "air", sub_compartment = "renewable" )
}
}
process electricity_production {
params {
from_hydro = 20 percent
from_wind = 10 percent
}
products {
1 kWh electricity
}
inputs {
from_hydro * 1 kWh electricity_hydro
from_wind * 1 kWh electricity_wind
( 100 percent - from_hydro - from_wind ) * 1 kWh electricity_fossil
}
}
// Renewable-only energy mix
process green_factory {
products {
1 p a_product
}
inputs {
10 kWh electricity from electricity_production ( from_hydro = 80 percent, from_wind = 20 percent)
}
}
// Default energy mix
process normal_factory {
products {
1 p a_product
}
inputs {
10 kWh electricity
}
}
We wrote two processes, green_factory
and normal_factory
, each of them corresponding to a different energy mix.
Could we have written only one process, and then used an external data source to supply values for the various
parameters?
Assume, for instance, that we have the following data in an Excel sheet.
country | from_hydro | from_wind |
---|---|---|
France | 12 | 15 |
Switzerland | 60 | 30 |
United Kingdom | 10 | 40 |
Export your Excel sheet to a file called factory.csv
in the same directory as your tutorial.lca
.
This file should look like the following:
country,from_hydro,from_wind
France,12,15
Switzerland,60,30
United Kingdom,10,40
United States,38,2
The tool expects the name of the CSV file used for input to match the name of the process you will run inventory analysis on. The first column will be used for display purposes, and the other columns are data columns: they will be matched by name against the process' parameters.
Let us add a new process that will take its input from the CSV file: it must have the same name as the CSV file and take the same number of parameters as there are of data columns in your file.
process factory {
params {
from_hydro = 20 percent
from_wind = 10 percent
}
products {
1 p a_product
}
inputs {
// We match the from_hydro parameter of electricity_production to our own of the same name.
1 kWh electricity from electricity_production ( from_hydro = from_hydro, from_wind = from_wind )
}
}
This time, instead of choosing "Assess" in the evaluation menu, click on "Assess with factory.csv": you
will see a pop-up informing you that 4 assessments were run (for the four countries defined above),
and that the results were immediately stored in a CSV file, called factory.results.csv
:
Country | from_hydro | from_wind | product | reference unit | energy_plant [p] | carbon_dioxide_fossil [kg] | hard_coal [MJ] | energy_hyrdo [MJ] | energy_wind [MJ] |
---|---|---|---|---|---|---|---|---|---|
France | 12 | 15 | a_product | p | 1.0E-11 | 8.76 | -8.76 | -4.56 | -5.7 |
Switzerland | 60 | 30 | a_product | p | 1.0E-11 | 1.2 | -1.2 | -22.8 | -11.4 |
United Kingdom | 10 | 40 | a_product | p | 1.0E-11 | 6.0 | -6.0 | -3.8 | -15.2 |
United States | 38 | 2 | a_product | p | 1.0E-11 | 7.2 | -7.2 | -14.44 | -0.76 |
Using this method, you can generate multiple outputs revolving around common, parameterized processes, helping readability, traceability, reducing errors and maintenance costs.