Running Sensitivity Analysis in openLCA with Python

Sensitivity analysis tests how much your results depend on individual inputs. You vary one parameter at a time, holding everything else at baseline, and see how each impact category responds.

This article covers a script that automates the process. You give it a list of parameters and a variation percentage, and it tests each one individually against your model.

This tool is available on the Below280 Life Cycle Assessment Github, within openLCA-IPC-tools

Before you start

The IPC server needs to be running and the Python packages installed. The Getting Started section covers both if this is your first time.

Your model also needs parameters. The script works by varying parameter values, so your exchanges need to reference parameters. The Parameters article in Getting Started covers this.

The sensitivity CSV

The input file is a plain text list of parameter names, one per line:

<code>electricity_kWh
resin_kg
transport_km
water_m3

The script reads the current baseline value for each parameter from the product system and calculates the variations from there.

Lines starting with # are treated as comments and skipped, so the file can be annotated:

<code># Manufacturing inputs
electricity_kWh
resin_kg

# Transport
transport_km

Running the script

Interactive mode:

<code>python B280_olca_sensitivity.py

Fully scripted:

<code>python B280_olca_sensitivity.py -p "My Product System" -i "EF v3.1" -s sensitivity.csv -v 10
FlagWhat it setsDefault
-pProduct system name (exact match)First system in database
-iImpact assessment method (exact match)EF v3.1
-sPath to sensitivity CSVsensitivity.csv
-vVariation percentage20

A variation of 10 means each parameter is tested at -10% and +10% of its baseline value.

What the script does

First, it validates the parameter list against the product system and reports which ones it found and which are missing. Missing parameters are skipped.

Then it runs a single baseline calculation with all parameters at their default values. This only happens once.

Then, for each parameter, it runs two calculations: one at baseline minus the variation, one at baseline plus. A list of 10 parameters at +/-10% means 20 calculations plus the one baseline, so 21 total. Each calculation redefines only the single parameter being tested. Everything else stays at baseline.

The output

The script creates sensitivity_results_<method_name>.csv:

<code>Impact Category,Unit,Baseline,electricity_kWh -10%,electricity_kWh +10%,resin_kg -10%,resin_kg +10%,...
Acidification potential,mol H+ eq,1.27,1.19,1.35,1.25,1.29,...
Global Warming Potential - fossil,kg CO2 eq,248.3,221.4,275.2,245.1,251.5,...

Each parameter gets two columns (minus and plus). The parameters that cause the biggest shift from baseline are the ones that matter most.

The percentage change from baseline can be calculated in a spreadsheet:

<code>= (plus_value - baseline) / baseline * 100

How this differs from scenario analysis

The scenario script changes multiple parameters at once to represent a complete alternative configuration. Sensitivity analysis changes one at a time to measure individual influence.

They answer different questions. Scenarios answer ‘what do the results look like for this site versus that site?’ Sensitivity analysis answers ‘which inputs should I spend time getting better data for?’

Things to watch

Zero-value parameters stay at zero regardless of the variation percentage (+/-10% of zero is still zero). The console output shows baseline values so these are easy to spot.

Asymmetric results (where -10% gives a different magnitude of shift than +10%) can occur when parameter formulas include non-linear expressions, thresholds, conditionals, or allocation rules. Standard unit-process LCA with fixed technology and linking is linear, so asymmetry usually points to something specific in the foreground model rather than the background system in general.

Parameter names are case-sensitive. Same as with the scenario script, copying them from the product system’s Parameters tab avoids errors.