Islanded Fuel Production
In this example, we build a simple model to assess the economics of islanded methanol production in Namibia (or Argentina). The model can optimise investment and operation of wind and solar, electrolysers, turbine, hydrogen and battery storage, direct air capture, CO storage, methanolisation and methanol stores to supply a constant methanol demand of 1 TWh/a.
In [2]:
Copied!
import pandas as pd
import pypsa
from pypsa.costs import annuityimport pandas as pd import pypsa from pypsa.costs import annuity
Techno-economic assumptions
We take techno-economic assumptions from the technology-data repository which collects assumptions on costs and efficiencies:
In [3]:
Copied!
YEAR = 2030
url = f"https://raw.githubusercontent.com/PyPSA/technology-data/master/outputs/costs_{YEAR}.csv"
costs = pd.read_csv(url, index_col=[0, 1])
costs.loc[costs.unit.str.contains("/kW"), "value"] *= 1e3
costs = costs.value.unstack().fillna({"discount rate": 0.07, "lifetime": 20, "FOM": 0})
# Let's also take a little more optimistic view on the costs of electrolysers
costs.loc["electrolysis", "investment"] = 500 # €/kWYEAR = 2030 url = f"https://raw.githubusercontent.com/PyPSA/technology-data/master/outputs/costs\_{YEAR}.csv" costs = pd.read_csv(url, index_col=[0, 1]) costs.loc[costs.unit.str.contains("/kW"), "value"] *= 1e3 costs = costs.value.unstack().fillna({"discount rate": 0.07, "lifetime": 20, "FOM": 0})
Let's also take a little more optimistic view on the costs of electrolysers
costs.loc["electrolysis", "investment"] = 500 # €/kW
We calculate the capital costs (i.e. annualised investment costs, €/MW/a or €/MWh/a for storage), using a small utility function to calculate the annuity factor to annualise investment costs based on is the discount rate and lifetime .
In [4]:
Copied!
a = costs.apply(lambda x: annuity(x["discount rate"], x["lifetime"]), axis=1)a = costs.apply(lambda x: annuity(x["discount rate"], x["lifetime"]), axis=1)
In [5]:
Copied!
costs["capital_cost"] = (a + costs["FOM"] / 100) * costs["investment"]costs["capital_cost"] = (a + costs["FOM"] / 100) * costs["investment"]
Wind and solar time series
The wind and solar capacity factor time series have been retrieved from model.energy. Go there to find more time series for other countries and plug them in here.
In [6]:
Copied!
RESOLUTION = 4 # hours
url = "https://model.energy/data/time-series-ca2bcb9e843aeb286cd6295854c885b6.csv" # South of Argentina
# url = "https://model.energy/data/time-series-57f7bbcb5c4821506de052e52d022b48.csv" # Namibia
ts = pd.read_csv(url, index_col=0, parse_dates=True)[::RESOLUTION]RESOLUTION = 4 # hours url = "https://model.energy/data/time-series-ca2bcb9e843aeb286cd6295854c885b6.csv" # South of Argentina
url = "https://model.energy/data/time-series-57f7bbcb5c4821506de052e52d022b48.csv" # Namibia
ts = pd.read_csv(url, index_col=0, parse_dates=True)[::RESOLUTION]
In [7]:
Copied!
ts.head(3)ts.head(3)
Out[7]:
| onwind | solar | |
|---|---|---|
| 2011-01-01 00:00:00 | 0.910 | 0.032 |
| 2011-01-01 04:00:00 | 0.831 | 0.000 |
| 2011-01-01 08:00:00 | 0.758 | 0.000 |
Build model
Initialisation
Add buses, carriers and set snapshots.
In [8]:
Copied!
n = pypsa.Network()
for carrier in ["electricity", "hydrogen", "co2", "methanol"]:
n.add("Bus", carrier, carrier=carrier, unit="t/h" if carrier == "co2" else "MW")
n.set_snapshots(ts.index)
n.snapshot_weightings.loc[:, :] = RESOLUTIONn = pypsa.Network() for carrier in ["electricity", "hydrogen", "co2", "methanol"]: n.add("Bus", carrier, carrier=carrier, unit="t/h" if carrier == "co2" else "MW") n.set_snapshots(ts.index) n.snapshot_weightings.loc[:, :] = RESOLUTION
/tmp/ipykernel_3938/4108911308.py:1: 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()In [9]:
Copied!
carriers = {
"wind": "dodgerblue",
"solar": "gold",
"hydrogen storage": "blueviolet",
"battery storage 3h": "yellowgreen",
"battery storage 6h": "yellowgreen",
"electrolysis": "magenta",
"turbine": "darkorange",
"methanolisation": "cyan",
"direct air capture": "coral",
"co2 storage": "black",
"methanol storage": "cadetblue",
"electricity": "grey",
"hydrogen": "grey",
"co2": "grey",
"methanol": "grey",
}
n.add("Carrier", carriers.keys(), color=carriers.values())carriers = { "wind": "dodgerblue", "solar": "gold", "hydrogen storage": "blueviolet", "battery storage 3h": "yellowgreen", "battery storage 6h": "yellowgreen", "electrolysis": "magenta", "turbine": "darkorange", "methanolisation": "cyan", "direct air capture": "coral", "co2 storage": "black", "methanol storage": "cadetblue", "electricity": "grey", "hydrogen": "grey", "co2": "grey", "methanol": "grey", } n.add("Carrier", carriers.keys(), color=carriers.values())
Demand
Add a constant methanol demand adding up to an annual target production of 1 TWh of methanol:
In [10]:
Copied!
n.add(
"Load",
"demand",
bus="methanol",
p_set=1e6 / 8760,
)n.add( "Load", "demand", bus="methanol", p_set=1e6 / 8760, )
Wind and solar
Add the wind and solar generators:
In [11]:
Copied!
n.add(
"Generator",
"wind",
bus="electricity",
carrier="wind",
p_max_pu=ts.onwind,
capital_cost=costs.at["onwind", "capital_cost"],
p_nom_extendable=True,
)n.add( "Generator", "wind", bus="electricity", carrier="wind", p_max_pu=ts.onwind, capital_cost=costs.at["onwind", "capital_cost"], p_nom_extendable=True, )
In [12]:
Copied!
n.add(
"Generator",
"solar",
bus="electricity",
carrier="solar",
p_max_pu=ts.solar,
capital_cost=costs.at["solar", "capital_cost"],
p_nom_extendable=True,
)n.add( "Generator", "solar", bus="electricity", carrier="solar", p_max_pu=ts.solar, capital_cost=costs.at["solar", "capital_cost"], p_nom_extendable=True, )
Batteries
Add a 3-hour and a 6-hour battery storage:
In [13]:
Copied!
for max_hours in [3, 6]:
n.add(
"Store",
f"battery storage {max_hours}h",
bus="electricity",
carrier=f"battery storage {max_hours}h",
max_hours=max_hours,
capital_cost=costs.at["battery inverter", "capital_cost"] / max_hours
+ costs.at["battery storage", "capital_cost"],
efficiency_store=costs.at["battery inverter", "efficiency"],
efficiency_dispatch=costs.at["battery inverter", "efficiency"],
e_nom_extendable=True,
e_cyclic=True,
)for max_hours in [3, 6]: n.add( "Store", f"battery storage {max_hours}h", bus="electricity", carrier=f"battery storage {max_hours}h", max_hours=max_hours, capital_cost=costs.at["battery inverter", "capital_cost"] / max_hours
- costs.at["battery storage", "capital_cost"], efficiency_store=costs.at["battery inverter", "efficiency"], efficiency_dispatch=costs.at["battery inverter", "efficiency"], e_nom_extendable=True, e_cyclic=True, )
Hydrogen
Add electrolysers, hydrogen storage (steel tank), hydrogen turbine:
In [14]:
Copied!
n.add(
"Link",
"electrolysis",
bus0="electricity",
bus1="hydrogen",
carrier="electrolysis",
p_nom_extendable=True,
efficiency=costs.at["electrolysis", "efficiency"],
capital_cost=costs.at["electrolysis", "capital_cost"],
)n.add( "Link", "electrolysis", bus0="electricity", bus1="hydrogen", carrier="electrolysis", p_nom_extendable=True, efficiency=costs.at["electrolysis", "efficiency"], capital_cost=costs.at["electrolysis", "capital_cost"], )
In [15]:
Copied!
n.add(
"Link",
"turbine",
bus0="hydrogen",
bus1="electricity",
carrier="turbine",
p_nom_extendable=True,
efficiency=costs.at["OCGT", "efficiency"],
capital_cost=costs.at["OCGT", "capital_cost"] / costs.at["OCGT", "efficiency"],
)n.add( "Link", "turbine", bus0="hydrogen", bus1="electricity", carrier="turbine", p_nom_extendable=True, efficiency=costs.at["OCGT", "efficiency"], capital_cost=costs.at["OCGT", "capital_cost"] / costs.at["OCGT", "efficiency"], )
In [16]:
Copied!
tech = "hydrogen storage tank type 1 including compressor"
n.add(
"Store",
"hydrogen storage",
bus="hydrogen",
carrier="hydrogen storage",
capital_cost=costs.at[tech, "capital_cost"],
e_nom_extendable=True,
e_cyclic=True,
)tech = "hydrogen storage tank type 1 including compressor" n.add( "Store", "hydrogen storage", bus="hydrogen", carrier="hydrogen storage", capital_cost=costs.at[tech, "capital_cost"], e_nom_extendable=True, e_cyclic=True, )
Carbon Dioxide
Add liquid carbon dioxide storage and direct air capture, assuming for simplicity an electricity demand 2 MWh/tCO2 for heat and electricity needs of the process. More detailed modelling would also model the heat supply for the direct air capture.
In [17]:
Copied!
electricity_input = 2 # MWh/tCO2
n.add(
"Link",
"direct air capture",
bus0="electricity",
bus1="co2",
carrier="direct air capture",
p_nom_extendable=True,
efficiency=1 / electricity_input,
capital_cost=costs.at["direct air capture", "capital_cost"] / electricity_input,
)electricity_input = 2 # MWh/tCO2 n.add( "Link", "direct air capture", bus0="electricity", bus1="co2", carrier="direct air capture", p_nom_extendable=True, efficiency=1 / electricity_input, capital_cost=costs.at["direct air capture", "capital_cost"] / electricity_input, )
In [18]:
Copied!
n.add(
"Store",
"co2 storage",
bus="co2",
carrier="co2 storage",
capital_cost=costs.at["CO2 storage tank", "capital_cost"],
e_nom_extendable=True,
e_cyclic=True,
)n.add( "Store", "co2 storage", bus="co2", carrier="co2 storage", capital_cost=costs.at["CO2 storage tank", "capital_cost"], e_nom_extendable=True, e_cyclic=True, )
Methanol
Add methanolisation unit, which takes hydrogen, electricity and carbon dioxide as input, and methanol storage.
Efficiencies and capital costs need to be expressed in units of bus0.
In [19]:
Copied!
eff_h2 = 1 / costs.at["methanolisation", "hydrogen-input"]
n.add(
"Link",
"methanolisation",
bus0="hydrogen",
bus1="methanol",
bus2="electricity",
bus3="co2",
carrier="methanolisation",
p_nom_extendable=True,
capital_cost=costs.at["methanolisation", "capital_cost"] * eff_h2,
efficiency=eff_h2,
efficiency2=-costs.at["methanolisation", "electricity-input"] * eff_h2,
efficiency3=-costs.at["methanolisation", "carbondioxide-input"] * eff_h2,
)eff_h2 = 1 / costs.at["methanolisation", "hydrogen-input"] n.add( "Link", "methanolisation", bus0="hydrogen", bus1="methanol", bus2="electricity", bus3="co2", carrier="methanolisation", p_nom_extendable=True, capital_cost=costs.at["methanolisation", "capital_cost"] * eff_h2, efficiency=eff_h2, efficiency2=-costs.at["methanolisation", "electricity-input"] * eff_h2, efficiency3=-costs.at["methanolisation", "carbondioxide-input"] * eff_h2, )
Costs for g is given in €/m³. We need to convert it to €/MWh, using the volumetric energy density of methanol (15.6 MJ/L).
In [20]:
Copied!
capital_cost = costs.at[
"General liquid hydrocarbon storage (crude)", "capital_cost"
] / (15.6 * 1000 / 3600)
n.add(
"Store",
"methanol storage",
bus="co2",
carrier="methanol storage",
capital_cost=capital_cost,
e_nom_extendable=True,
e_cyclic=True,
)capital_cost = costs.at[ "General liquid hydrocarbon storage (crude)", "capital_cost" ] / (15.6 * 1000 / 3600) n.add( "Store", "methanol storage", bus="co2", carrier="methanol storage", capital_cost=capital_cost, e_nom_extendable=True, e_cyclic=True, )
Optimisation
In [21]:
Copied!
n.optimize()n.optimize()
/tmp/ipykernel_3938/1261279110.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()INFO:linopy.model: Solve problem using Gurobi solverINFO:linopy.model:Solver options:
- log_to_console: FalseINFO:linopy.io:Writing objective.Writing constraints.: 0%| | 0/15 [00:00<?, ?it/s]Writing constraints.: 100%|██████████| 15/15 [00:00<00:00, 159.58it/s]Writing continuous variables.: 0%| | 0/8 [00:00<?, ?it/s]Writing continuous variables.: 100%|██████████| 8/8 [00:00<00:00, 368.65it/s]INFO:linopy.io: Writing time: 0.14sSet parameter WLSAccessIDSet parameter WLSSecretSet parameter LicenseID to value 2537914Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.deRead LP format model from file /tmp/linopy-problem-q62qhv_f.lpReading time = 0.13 secondsobj: 98291 rows, 45875 columns, 193285 nonzerosSet parameter LogToConsole to value 0INFO:linopy.constants: Optimization successful:
Status: ok
Termination condition: optimal
Solution: 45875 primals, 111395 duals
Objective: 2.24e+08
Solver: gurobi
Runtime: 1.29s
Dual bound: 2.24e+08
Solver model: available
Solver message: 2INFO:pypsa.optimization.optimize:The shadow-prices of the constraints Generator-ext-p-lower, Generator-ext-p-upper, Link-ext-p-lower, Link-ext-p-upper, Store-ext-e-lower, Store-ext-e-upper, Store-ext-p-lower, Store-ext-p-upper, Store-ext-p_store-lower, Store-ext-p_store-upper, Store-energy_balance were not assigned to the network.Out[21]:
('ok', 'optimal')Model evaluation
Total system cost by technology (we only added CAPEX components):
In [22]:
Copied!
n.statistics.capex().div(1e6).sort_values(ascending=False) # mn€/an.statistics.capex().div(1e6).sort_values(ascending=False) # mn€/a
Out[22]:
component carrier
Generator wind 65.960159
solar 53.567253
Store hydrogen storage 48.579899
Link direct air capture 33.507477
methanolisation 16.916982
Store battery storage 6h 5.003787
methanol storage 0.077775
Link electrolysis 0.031580
dtype: float64Costs per unit of fuel (€/MWh):
In [23]:
Copied!
n.statistics.capex().sum() / (8760 * n.loads.p_set.sum())n.statistics.capex().sum() / (8760 * n.loads.p_set.sum())
Out[23]:
np.float64(223.64491163334)The optimised capacities in MW (MWh for Store component):
In [24]:
Copied!
n.statistics.optimal_capacity()n.statistics.optimal_capacity()
Out[24]:
component carrier
Generator solar 829.72636
wind 514.08343
Link direct air capture 61.73482
electrolysis 502.02806
methanolisation 129.90868
Store battery storage 6h 232.85533
hydrogen storage 8820.73540
methanol storage 13477.63523
dtype: float64Utilisation rates and capacity factors for each technology (in percent):
In [25]:
Copied!
n.statistics.capacity_factor() * 100n.statistics.capacity_factor() * 100
Out[25]:
component carrier
Generator solar 6.424358
wind 47.329178
Link direct air capture 91.716474
electrolysis 41.622610
methanolisation 100.000000
Load - NaN
Store battery storage 6h 17.898779
hydrogen storage 37.356335
methanol storage 52.980686
dtype: float64Curtailment for each technology (in TWh):
In [26]:
Copied!
n.statistics.curtailment().div(1e6)n.statistics.curtailment().div(1e6)
Out[26]:
component carrier
Generator solar 0.432898
wind 0.446138
Link direct air capture 0.044674
electrolysis 2.560267
dtype: float64System operation on electricity, hydrogen, carbon dioxide and methanol sides (in MW):
In [27]:
Copied!
n.statistics.energy_balance.plot.area(linewidth=0, bus_carrier="electricity")n.statistics.energy_balance.plot.area(linewidth=0, bus_carrier="electricity")
Out[27]:
(<Figure size 781x300 with 1 Axes>,
<Axes: xlabel='snapshot', ylabel='Energy Balance [MW]'>,
<seaborn.axisgrid.FacetGrid at 0x75d8b45c2510>)
In [28]:
Copied!
n.statistics.energy_balance.plot.area(linewidth=0, bus_carrier="hydrogen")n.statistics.energy_balance.plot.area(linewidth=0, bus_carrier="hydrogen")
Out[28]:
(<Figure size 775.688x300 with 1 Axes>,
<Axes: xlabel='snapshot', ylabel='Energy Balance [MW]'>,
<seaborn.axisgrid.FacetGrid at 0x75d8b47f4f50>)
In [29]:
Copied!
n.statistics.energy_balance.plot.area(linewidth=0, bus_carrier="co2")n.statistics.energy_balance.plot.area(linewidth=0, bus_carrier="co2")
Out[29]:
(<Figure size 776x300 with 1 Axes>,
<Axes: xlabel='snapshot', ylabel='Energy Balance [t/h]'>,
<seaborn.axisgrid.FacetGrid at 0x75d85c09bb10>)
In [30]:
Copied!
n.statistics.energy_balance.plot.area(linewidth=0, bus_carrier="methanol")n.statistics.energy_balance.plot.area(linewidth=0, bus_carrier="methanol")
Out[30]:
(<Figure size 765x300 with 1 Axes>,
<Axes: xlabel='snapshot', ylabel='Energy Balance [MW]'>,
<seaborn.axisgrid.FacetGrid at 0x75d8549dd1d0>)
Modifications: Biogenic Carbon Dioxide
How are costs affected by the availability of biogenic carbon dioxide costed at 50 €/t?
In [31]:
Copied!
n.add(
"Generator",
"biogenic co2",
bus="co2",
carrier="biogenic co2",
p_nom=1000, # non-binding
marginal_cost=50,
)
n.add(
"Carrier",
"biogenic co2",
color="forestgreen",
)
n.optimize()n.add( "Generator", "biogenic co2", bus="co2", carrier="biogenic co2", p_nom=1000, # non-binding marginal_cost=50, ) n.add( "Carrier", "biogenic co2", color="forestgreen", ) n.optimize()
INFO:linopy.model: Solve problem using Gurobi solverINFO:linopy.model:Solver options:
- log_to_console: FalseINFO:linopy.io:Writing objective.Writing constraints.: 0%| | 0/17 [00:00<?, ?it/s]Writing constraints.: 100%|██████████| 17/17 [00:00<00:00, 161.99it/s]Writing constraints.: 100%|██████████| 17/17 [00:00<00:00, 160.74it/s]Writing continuous variables.: 0%| | 0/8 [00:00<?, ?it/s]Writing continuous variables.: 100%|██████████| 8/8 [00:00<00:00, 356.20it/s]INFO:linopy.io: Writing time: 0.14sSet parameter WLSAccessIDSet parameter WLSSecretSet parameter LicenseID to value 2537914Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.deRead LP format model from file /tmp/linopy-problem-kiqb11lm.lpReading time = 0.13 secondsobj: 102659 rows, 48059 columns, 199837 nonzerosSet parameter LogToConsole to value 0INFO:linopy.constants: Optimization successful:
Status: ok
Termination condition: optimal
Solution: 48059 primals, 115763 duals
Objective: 2.01e+08
Solver: gurobi
Runtime: 0.96s
Dual bound: 2.01e+08
Solver model: available
Solver message: 2INFO:pypsa.optimization.optimize:The shadow-prices of the constraints Generator-fix-p-lower, Generator-fix-p-upper, Generator-ext-p-lower, Generator-ext-p-upper, Link-ext-p-lower, Link-ext-p-upper, Store-ext-e-lower, Store-ext-e-upper, Store-ext-p-lower, Store-ext-p-upper, Store-ext-p_store-lower, Store-ext-p_store-upper, Store-energy_balance were not assigned to the network.Out[31]:
('ok', 'optimal')In [32]:
Copied!
(n.statistics.capex().sum() + n.statistics.opex().sum()) / 1e6 # €/MWh(n.statistics.capex().sum() + n.statistics.opex().sum()) / 1e6 # €/MWh
Out[32]:
np.float64(200.52105032881002)In [33]:
Copied!
n.statistics.energy_balance(bus_carrier="co2")n.statistics.energy_balance(bus_carrier="co2")
Out[33]:
component carrier bus_carrier
Generator biogenic co2 co2 247320.54795
Link methanolisation co2 -247320.54795
dtype: float64Modifications: Inflexible PtX
How are costs affected by limited flexibility of electrolyer and methanolisation units (e.g. with a minimum part load of 80%)?
In [34]:
Copied!
n.links.loc["electrolysis", "p_min_pu"] = 0.8
n.links.loc["methanolisation", "p_min_pu"] = 0.8
n.optimize()n.links.loc["electrolysis", "p_min_pu"] = 0.8 n.links.loc["methanolisation", "p_min_pu"] = 0.8 n.optimize()
INFO:linopy.model: Solve problem using Gurobi solverINFO:linopy.model:Solver options:
- log_to_console: FalseINFO:linopy.io:Writing objective.Writing constraints.: 0%| | 0/17 [00:00<?, ?it/s]Writing constraints.: 100%|██████████| 17/17 [00:00<00:00, 169.90it/s]Writing continuous variables.: 0%| | 0/8 [00:00<?, ?it/s]Writing continuous variables.: 100%|██████████| 8/8 [00:00<00:00, 370.88it/s]INFO:linopy.io: Writing time: 0.13sSet parameter WLSAccessIDSet parameter WLSSecretSet parameter LicenseID to value 2537914Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.deRead LP format model from file /tmp/linopy-problem-hsvh0kxm.lpReading time = 0.13 secondsobj: 102659 rows, 48059 columns, 204205 nonzerosSet parameter LogToConsole to value 0INFO:linopy.constants: Optimization successful:
Status: ok
Termination condition: optimal
Solution: 48059 primals, 115763 duals
Objective: 3.03e+08
Solver: gurobi
Runtime: 1.14s
Dual bound: 3.03e+08
Solver model: available
Solver message: 2INFO:pypsa.optimization.optimize:The shadow-prices of the constraints Generator-fix-p-lower, Generator-fix-p-upper, Generator-ext-p-lower, Generator-ext-p-upper, Link-ext-p-lower, Link-ext-p-upper, Store-ext-e-lower, Store-ext-e-upper, Store-ext-p-lower, Store-ext-p-upper, Store-ext-p_store-lower, Store-ext-p_store-upper, Store-energy_balance were not assigned to the network.Out[34]:
('ok', 'optimal')In [35]:
Copied!
(n.statistics.capex().sum() + n.statistics.opex().sum()) / 1e6 # €/MWh(n.statistics.capex().sum() + n.statistics.opex().sum()) / 1e6 # €/MWh
Out[35]:
np.float64(303.27748910231)In [36]:
Copied!
n.statistics.optimal_capacity()n.statistics.optimal_capacity()
Out[36]:
component carrier
Generator biogenic co2 1000.00000
solar 780.11055
wind 1010.92272
Link electrolysis 211.83481
methanolisation 129.90868
turbine 15.38233
Store battery storage 6h 3645.06522
hydrogen storage 2418.75950
dtype: float64
2026-11-02
2025-04-08