Post · 8 min read· pp. 49–58

Carbon Management

In this example, we show how to manage different biomass stocks with different potentials and costs, synthetic fuel production, direct air capture (DAC) and carbon capture and usage/sequestration/cycling.

Demand for electricity and diesel transport have to be met from various biomass sources, natural gas with possibility for carbon capture, electrolysis for hydrogen production, direct air capture of CO2, and diesel synthesis via Fischer-Tropsch processes.

The system has to reach a target of net negative emissions over the optimisation period.

All numbers/costs/efficiencies are fictitious to allow easy analysis.

In [2]:

Copied! diagram

ipynb
import pypsa

n = pypsa.Network()
n.set_snapshots(range(10))

import pypsa n = pypsa.Network() n.set_snapshots(range(10))

text
/tmp/ipykernel_2736/1084327959.py:3: PyPSA2Warning: pandas reads strings as `str` dtype since 3.0. PyPSA converts them back to object dtype on import, but keeps `str` from PyPSA 2.0 on. Set `pypsa.options.future.string_dtype` to True to opt in now or to False to keep the current behaviour.
  n = pypsa.Network()

Add a constant electrical load, a constant demand for transport, a diesel storage, and a hydrogen storage (which are not limited in capacity).

In [3]:

Copied! diagram

ipynb
n.add("Bus", "electricity")
n.add("Load", "load", bus="electricity", p_set=1)

n.add("Bus", "transport")
n.add("Load", "transport", bus="transport", p_set=1)

n.add("Bus", "diesel")
n.add("Store", "diesel", bus="diesel", e_cyclic=True, e_nom=1000)

n.add("Bus", "hydrogen")
n.add("Store", "hydrogen", bus="hydrogen", e_cyclic=True, e_nom=1000);

n.add("Bus", "electricity") n.add("Load", "load", bus="electricity", p_set=1) n.add("Bus", "transport") n.add("Load", "transport", bus="transport", p_set=1) n.add("Bus", "diesel") n.add("Store", "diesel", bus="diesel", e_cyclic=True, e_nom=1000) n.add("Bus", "hydrogen") n.add("Store", "hydrogen", bus="hydrogen", e_cyclic=True, e_nom=1000);

Add a link to represent electrolysis for hydrogen production from electricity.

In [4]:

Copied! diagram

ipynb
n.add(
    "Link",
    "electrolysis",
    p_nom=2.0,
    efficiency=0.8,
    bus0="electricity",
    bus1="hydrogen",
);

n.add( "Link", "electrolysis", p_nom=2.0, efficiency=0.8, bus0="electricity", bus1="hydrogen", );

Next we set up the accounting of CO2 in the system. We add a carrier for CO2 (with minus sign because it runs opposite to how fossil fuels are used; burning of gas reduces gas, but CO2 in the atmosphere up), a bus and store for the CO2 in the atmosphere (which can be negative for the optimisation period), and a bus with a store for the CO2 that is captured and stored (for sequestration or use).

In [5]:

Copied! diagram

ipynb
n.add("Carrier", "co2", co2_emissions=-1)

n.add("Bus", "co2 atmosphere", carrier="co2")
n.add("Store", "co2 atmosphere", e_nom=1000, e_min_pu=-1, bus="co2 atmosphere")

n.add("Bus", "co2 stored")
n.add("Store", "co2 stored", e_nom=1000, e_min_pu=-1, bus="co2 stored");

n.add("Carrier", "co2", co2_emissions=-1) n.add("Bus", "co2 atmosphere", carrier="co2") n.add("Store", "co2 atmosphere", e_nom=1000, e_min_pu=-1, bus="co2 atmosphere") n.add("Bus", "co2 stored") n.add("Store", "co2 stored", e_nom=1000, e_min_pu=-1, bus="co2 stored");

With that, add a multi-link for the production of diesel from H2 and CO2 using Fischer-Tropsch. Note that CO2 is another input, hence, the efficiency2 has to be negative.

In [6]:

Copied! diagram

ipynb
n.add(
    "Link",
    "Fischer-Tropsch",
    p_nom=4,
    bus0="hydrogen",
    bus1="diesel",
    bus2="co2 stored",
    efficiency=1,
    efficiency2=-1,
);

n.add( "Link", "Fischer-Tropsch", p_nom=4, bus0="hydrogen", bus1="diesel", bus2="co2 stored", efficiency=1, efficiency2=-1, );

Direct air capture consumes electricity to take CO2 from the air to the store.

In [7]:

Copied! diagram

ipynb
n.add(
    "Link",
    "DAC",
    bus0="electricity",
    bus1="co2 stored",
    bus2="co2 atmosphere",
    efficiency=1,
    efficiency2=-1,
    p_nom=5,
);

n.add( "Link", "DAC", bus0="electricity", bus1="co2 stored", bus2="co2 atmosphere", efficiency=1, efficiency2=-1, p_nom=5, );

Add a link to meet transport demands with diesel. This emits CO2 into the atmosphere.

In [8]:

Copied! diagram

ipynb
n.add(
    "Link",
    "diesel car",
    bus0="diesel",
    bus1="transport",
    bus2="co2 atmosphere",
    efficiency=1,
    efficiency2=1,
    p_nom=2,
);

n.add( "Link", "diesel car", bus0="diesel", bus1="transport", bus2="co2 atmosphere", efficiency=1, efficiency2=1, p_nom=2, );

Add two gas power plants, one with carbon capture and one without. The one without carbon capture emits CO2 into the atmosphere. The one with carbon capture captures CO2, but imperfectly, so that some CO2 is still emitted into the atmosphere.

In [9]:

Copied! diagram

ipynb
n.add("Bus", "gas")

n.add("Store", "gas", e_initial=50, e_nom=50, marginal_cost=20, bus="gas")

n.add(
    "Link",
    "OCGT",
    bus0="gas",
    bus1="electricity",
    bus2="co2 atmosphere",
    p_nom_extendable=True,
    efficiency=0.5,
    efficiency2=1,
)

n.add(
    "Link",
    "OCGT+CCS",
    bus0="gas",
    bus1="electricity",
    bus2="co2 stored",
    bus3="co2 atmosphere",
    p_nom_extendable=True,
    efficiency=0.4,
    efficiency2=0.9,
    efficiency3=0.1,
);

n.add("Bus", "gas") n.add("Store", "gas", e_initial=50, e_nom=50, marginal_cost=20, bus="gas") n.add( "Link", "OCGT", bus0="gas", bus1="electricity", bus2="co2 atmosphere", p_nom_extendable=True, efficiency=0.5, efficiency2=1, ) n.add( "Link", "OCGT+CCS", bus0="gas", bus1="electricity", bus2="co2 stored", bus3="co2 atmosphere", p_nom_extendable=True, efficiency=0.4, efficiency2=0.9, efficiency3=0.1, );

Add two biomass generators, one with carbon capture and one without. The one without carbon capture simultaneously withdraws and emits CO2 into the atmosphere (hence we can ignore it for the purposes of carbon accounting). The one with carbon capture captures the renewable CO2, which counts as negative emissions if it remains in the CO2 store.

In [10]:

Copied! diagram

ipynb
n.add("Bus", "biomass")

n.add(
    "Store",
    "biomass",
    bus="biomass",
    marginal_cost=30,
    e_nom=55,
    e_initial=55,
)

n.add(
    "Link",
    "biomass",
    bus0="biomass",
    bus1="electricity",
    p_nom_extendable=True,
    capital_cost=1,
    efficiency=0.5,
)

n.add(
    "Link",
    "biomass+CCS",
    bus0="biomass",
    bus1="electricity",
    bus2="co2 stored",
    bus3="co2 atmosphere",
    p_nom_extendable=True,
    capital_cost=1,
    efficiency=0.4,
    efficiency2=1,
    efficiency3=-1,
);

n.add("Bus", "biomass") n.add( "Store", "biomass", bus="biomass", marginal_cost=30, e_nom=55, e_initial=55, ) n.add( "Link", "biomass", bus0="biomass", bus1="electricity", p_nom_extendable=True, capital_cost=1, efficiency=0.5, ) n.add( "Link", "biomass+CCS", bus0="biomass", bus1="electricity", bus2="co2 stored", bus3="co2 atmosphere", p_nom_extendable=True, capital_cost=1, efficiency=0.4, efficiency2=1, efficiency3=-1, );

Finally, we add a global constraint on the amount of CO2 that can be emitted into the atmosphere. In fact, we can set this to a negative value, which means that the system has to reach a target of net negative emissions over the optimisation period. In this example, we can go as far as -50, but at some point not enough electricity can be generated to supply the DAC.

In [11]:

Copied! diagram

ipynb
n.add(
    "GlobalConstraint",
    "co2_limit",
    sense="<=",
    constant=-50,
);

n.add( "GlobalConstraint", "co2_limit", sense="<=", constant=-50, );

In [12]:

Copied! diagram

ipynb
n.optimize();

n.optimize();

text
/tmp/ipykernel_2736/1450685117.py:1: PyPSA2Warning: From PyPSA 2.0 on, the objective leaves out the capital costs of existing capacity on extendable assets, which improves LP conditioning. Pass `include_objective_constant` to `n.optimize` to choose per call. Set `pypsa.options.future.exclude_objective_constant` to True to opt in now or to False to keep the current behaviour.
  n.optimize();
WARNING:pypsa.consistency:The following buses have carriers which are not defined. Run n.sanitize() to add them. Components with undefined carriers:
Index(['electricity', 'transport', 'diesel', 'hydrogen', 'co2 stored', 'gas',
       'biomass'],
      dtype='object', name='name')
text
WARNING:pypsa.consistency:The following links have carriers which are not defined. Run n.sanitize() to add them. Components with undefined carriers:
Index(['electrolysis', 'Fischer-Tropsch', 'DAC', 'diesel car', 'OCGT',
       'OCGT+CCS', 'biomass', 'biomass+CCS'],
      dtype='object', name='name')
text
WARNING:pypsa.consistency:The following stores have carriers which are not defined. Run n.sanitize() to add them. Components with undefined carriers:
Index(['diesel', 'hydrogen', 'co2 stored', 'gas', 'biomass'], dtype='object', name='name')
text
INFO:linopy.model: Solve problem using Gurobi solver
text
INFO:linopy.model:Solver options:
 - log_to_console: False
text
INFO:linopy.io: Writing time: 0.07s
text
Set parameter WLSAccessID
text
Set parameter WLSSecret
text
Set parameter LicenseID to value 2537914
text
Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.de
text
Read LP format model from file /tmp/linopy-problem-g0zwfows.lp
text
Reading time = 0.00 seconds
text
obj: 545 rows, 264 columns, 921 nonzeros
text
Set parameter LogToConsole to value 0
text
INFO:linopy.constants: Optimization successful: 
Status: ok
Termination condition: optimal
Solution: 264 primals, 665 duals
Objective: 2.02e+03
Solver: gurobi
Runtime: 0.00s
Dual bound: 2.02e+03
Solver model: available
Solver message: 2
text
INFO:pypsa.optimization.optimize:The shadow-prices of the constraints Link-fix-p-lower, Link-fix-p-upper, Link-ext-p-lower, Link-ext-p-upper, Store-fix-e-lower, Store-fix-e-upper, Store-fix-p-lower, Store-fix-p-upper, Store-fix-p_store-lower, Store-fix-p_store-upper, Store-energy_balance were not assigned to the network.

How do the different stores in the system behave?

In [13]:

Copied! diagram

ipynb
n.stores_t.e.plot()

n.stores_t.e.plot()

Out[13]:

text
<Axes: xlabel='snapshot'>

No description has been provided for this image

Let's have a look at the production

In [14]:

Copied! diagram

ipynb
n.links_t.p0.plot()

n.links_t.p0.plot()

Out[14]:

text
<Axes: xlabel='snapshot'>

No description has been provided for this image

At all times, the amount of carbon in the system is constant, meaning that all carbon is tracked through the system.

In [15]:

Copied! diagram

ipynb
n.stores_t.e[["co2 stored", "co2 atmosphere", "gas", "diesel"]].sum(axis=1)

n.stores_t.e[["co2 stored", "co2 atmosphere", "gas", "diesel"]].sum(axis=1)

Out[15]:

text
snapshot
0    50.0
1    50.0
2    50.0
3    50.0
4    50.0
5    50.0
6    50.0
7    50.0
8    50.0
9    50.0
dtype: float64

diagram 2026-08-05

diagram 2020-02-28