2022-09-16 13:04:04 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2023-02-16 10:50:55 +00:00
|
|
|
# SPDX-FileCopyrightText: : 2017-2023 The PyPSA-Eur Authors
|
2020-05-29 07:50:55 +00:00
|
|
|
#
|
2021-09-14 14:37:41 +00:00
|
|
|
# SPDX-License-Identifier: MIT
|
2020-05-29 07:50:55 +00:00
|
|
|
|
2019-11-19 18:36:28 +00:00
|
|
|
# coding: utf-8
|
|
|
|
"""
|
|
|
|
Adds extra extendable components to the clustered and simplified network.
|
|
|
|
|
|
|
|
Relevant Settings
|
|
|
|
-----------------
|
|
|
|
|
|
|
|
.. code:: yaml
|
|
|
|
|
|
|
|
costs:
|
|
|
|
year:
|
2020-10-16 09:38:26 +00:00
|
|
|
version:
|
2019-11-19 18:36:28 +00:00
|
|
|
dicountrate:
|
|
|
|
emission_prices:
|
|
|
|
|
|
|
|
electricity:
|
|
|
|
max_hours:
|
|
|
|
marginal_cost:
|
|
|
|
capital_cost:
|
|
|
|
extendable_carriers:
|
|
|
|
StorageUnit:
|
|
|
|
Store:
|
|
|
|
|
|
|
|
.. seealso::
|
2023-04-21 08:41:44 +00:00
|
|
|
Documentation of the configuration file ``config/config.yaml`` at :ref:`costs_cf`,
|
2019-11-19 18:36:28 +00:00
|
|
|
:ref:`electricity_cf`
|
|
|
|
|
|
|
|
Inputs
|
|
|
|
------
|
|
|
|
|
2020-10-16 09:38:26 +00:00
|
|
|
- ``resources/costs.csv``: The database of cost assumptions for all included technologies for specific years from various sources; e.g. discount rate, lifetime, investment (CAPEX), fixed operation and maintenance (FOM), variable operation and maintenance (VOM), fuel costs, efficiency, carbon-dioxide intensity.
|
2019-11-19 18:36:28 +00:00
|
|
|
|
|
|
|
Outputs
|
|
|
|
-------
|
|
|
|
|
2020-12-03 18:50:53 +00:00
|
|
|
- ``networks/elec_s{simpl}_{clusters}_ec.nc``:
|
2019-11-19 18:36:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
Description
|
|
|
|
-----------
|
|
|
|
|
2023-04-21 08:41:44 +00:00
|
|
|
The rule :mod:`add_extra_components` attaches additional extendable components to the clustered and simplified network. These can be configured in the ``config/config.yaml`` at ``electricity: extendable_carriers:``. It processes ``networks/elec_s{simpl}_{clusters}.nc`` to build ``networks/elec_s{simpl}_{clusters}_ec.nc``, which in contrast to the former (depending on the configuration) contain with **zero** initial capacity
|
2019-11-19 18:36:28 +00:00
|
|
|
|
|
|
|
- ``StorageUnits`` of carrier 'H2' and/or 'battery'. If this option is chosen, every bus is given an extendable ``StorageUnit`` of the corresponding carrier. The energy and power capacities are linked through a parameter that specifies the energy capacity as maximum hours at full dispatch power and is configured in ``electricity: max_hours:``. This linkage leads to one investment variable per storage unit. The default ``max_hours`` lead to long-term hydrogen and short-term battery storage units.
|
|
|
|
|
|
|
|
- ``Stores`` of carrier 'H2' and/or 'battery' in combination with ``Links``. If this option is chosen, the script adds extra buses with corresponding carrier where energy ``Stores`` are attached and which are connected to the corresponding power buses via two links, one each for charging and discharging. This leads to three investment variables for the energy capacity, charging and discharging capacity of the storage unit.
|
|
|
|
"""
|
|
|
|
import logging
|
2019-11-28 07:22:52 +00:00
|
|
|
|
2019-12-02 11:22:30 +00:00
|
|
|
import numpy as np
|
2022-09-16 13:04:04 +00:00
|
|
|
import pandas as pd
|
|
|
|
import pypsa
|
2023-08-15 13:02:41 +00:00
|
|
|
from _helpers import configure_logging, set_scenario_config
|
2024-02-05 15:16:34 +00:00
|
|
|
from add_electricity import load_costs, sanitize_carriers, sanitize_locations
|
2019-11-19 18:36:28 +00:00
|
|
|
|
|
|
|
idx = pd.IndexSlice
|
|
|
|
|
2020-12-03 18:50:53 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2023-06-15 16:52:25 +00:00
|
|
|
def attach_storageunits(n, costs, extendable_carriers, max_hours):
|
|
|
|
carriers = extendable_carriers["StorageUnit"]
|
2019-11-19 18:36:28 +00:00
|
|
|
|
2023-05-03 11:24:57 +00:00
|
|
|
n.madd("Carrier", carriers)
|
2019-11-19 18:36:28 +00:00
|
|
|
|
|
|
|
buses_i = n.buses.index
|
|
|
|
|
2020-12-03 09:02:23 +00:00
|
|
|
lookup_store = {"H2": "electrolysis", "battery": "battery inverter"}
|
|
|
|
lookup_dispatch = {"H2": "fuel cell", "battery": "battery inverter"}
|
|
|
|
|
2019-11-19 18:36:28 +00:00
|
|
|
for carrier in carriers:
|
2022-06-27 08:21:08 +00:00
|
|
|
roundtrip_correction = 0.5 if carrier == "battery" else 1
|
2022-09-16 13:04:04 +00:00
|
|
|
|
|
|
|
n.madd(
|
|
|
|
"StorageUnit",
|
|
|
|
buses_i,
|
|
|
|
" " + carrier,
|
|
|
|
bus=buses_i,
|
|
|
|
carrier=carrier,
|
|
|
|
p_nom_extendable=True,
|
|
|
|
capital_cost=costs.at[carrier, "capital_cost"],
|
|
|
|
marginal_cost=costs.at[carrier, "marginal_cost"],
|
|
|
|
efficiency_store=costs.at[lookup_store[carrier], "efficiency"]
|
|
|
|
** roundtrip_correction,
|
|
|
|
efficiency_dispatch=costs.at[lookup_dispatch[carrier], "efficiency"]
|
|
|
|
** roundtrip_correction,
|
|
|
|
max_hours=max_hours[carrier],
|
|
|
|
cyclic_state_of_charge=True,
|
2022-06-27 08:21:08 +00:00
|
|
|
)
|
2019-11-19 18:36:28 +00:00
|
|
|
|
2020-12-03 18:50:53 +00:00
|
|
|
|
2023-06-15 16:52:25 +00:00
|
|
|
def attach_stores(n, costs, extendable_carriers):
|
|
|
|
carriers = extendable_carriers["Store"]
|
2019-11-19 18:36:28 +00:00
|
|
|
|
2023-05-03 11:24:57 +00:00
|
|
|
n.madd("Carrier", carriers)
|
2019-11-19 18:36:28 +00:00
|
|
|
|
|
|
|
buses_i = n.buses.index
|
|
|
|
|
2022-09-16 13:04:04 +00:00
|
|
|
if "H2" in carriers:
|
2024-02-05 15:16:34 +00:00
|
|
|
h2_buses_i = n.madd("Bus", buses_i + " H2", carrier="H2", location=buses_i)
|
2019-11-19 18:36:28 +00:00
|
|
|
|
2022-09-16 13:04:04 +00:00
|
|
|
n.madd(
|
|
|
|
"Store",
|
|
|
|
h2_buses_i,
|
|
|
|
bus=h2_buses_i,
|
|
|
|
carrier="H2",
|
|
|
|
e_nom_extendable=True,
|
|
|
|
e_cyclic=True,
|
|
|
|
capital_cost=costs.at["hydrogen storage underground", "capital_cost"],
|
|
|
|
)
|
2023-04-25 15:26:23 +00:00
|
|
|
|
2022-09-16 13:04:04 +00:00
|
|
|
n.madd(
|
|
|
|
"Link",
|
|
|
|
h2_buses_i + " Electrolysis",
|
|
|
|
bus0=buses_i,
|
|
|
|
bus1=h2_buses_i,
|
|
|
|
carrier="H2 electrolysis",
|
|
|
|
p_nom_extendable=True,
|
|
|
|
efficiency=costs.at["electrolysis", "efficiency"],
|
|
|
|
capital_cost=costs.at["electrolysis", "capital_cost"],
|
|
|
|
marginal_cost=costs.at["electrolysis", "marginal_cost"],
|
|
|
|
)
|
|
|
|
|
|
|
|
n.madd(
|
|
|
|
"Link",
|
|
|
|
h2_buses_i + " Fuel Cell",
|
|
|
|
bus0=h2_buses_i,
|
|
|
|
bus1=buses_i,
|
|
|
|
carrier="H2 fuel cell",
|
|
|
|
p_nom_extendable=True,
|
|
|
|
efficiency=costs.at["fuel cell", "efficiency"],
|
|
|
|
# NB: fixed cost is per MWel
|
|
|
|
capital_cost=costs.at["fuel cell", "capital_cost"]
|
|
|
|
* costs.at["fuel cell", "efficiency"],
|
|
|
|
marginal_cost=costs.at["fuel cell", "marginal_cost"],
|
|
|
|
)
|
|
|
|
|
|
|
|
if "battery" in carriers:
|
|
|
|
b_buses_i = n.madd(
|
2024-02-05 15:16:34 +00:00
|
|
|
"Bus", buses_i + " battery", carrier="battery", location=buses_i
|
2022-09-16 13:04:04 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
n.madd(
|
|
|
|
"Store",
|
|
|
|
b_buses_i,
|
|
|
|
bus=b_buses_i,
|
|
|
|
carrier="battery",
|
|
|
|
e_cyclic=True,
|
|
|
|
e_nom_extendable=True,
|
|
|
|
capital_cost=costs.at["battery storage", "capital_cost"],
|
|
|
|
marginal_cost=costs.at["battery", "marginal_cost"],
|
|
|
|
)
|
2023-04-25 15:26:23 +00:00
|
|
|
|
|
|
|
n.madd("Carrier", ["battery charger", "battery discharger"])
|
2022-09-16 13:04:04 +00:00
|
|
|
|
|
|
|
n.madd(
|
|
|
|
"Link",
|
|
|
|
b_buses_i + " charger",
|
|
|
|
bus0=buses_i,
|
|
|
|
bus1=b_buses_i,
|
|
|
|
carrier="battery charger",
|
|
|
|
# the efficiencies are "round trip efficiencies"
|
|
|
|
efficiency=costs.at["battery inverter", "efficiency"] ** 0.5,
|
|
|
|
capital_cost=costs.at["battery inverter", "capital_cost"],
|
|
|
|
p_nom_extendable=True,
|
|
|
|
marginal_cost=costs.at["battery inverter", "marginal_cost"],
|
|
|
|
)
|
|
|
|
|
|
|
|
n.madd(
|
|
|
|
"Link",
|
|
|
|
b_buses_i + " discharger",
|
|
|
|
bus0=b_buses_i,
|
|
|
|
bus1=buses_i,
|
|
|
|
carrier="battery discharger",
|
|
|
|
efficiency=costs.at["battery inverter", "efficiency"] ** 0.5,
|
|
|
|
p_nom_extendable=True,
|
|
|
|
marginal_cost=costs.at["battery inverter", "marginal_cost"],
|
|
|
|
)
|
2019-11-19 18:36:28 +00:00
|
|
|
|
2020-12-03 18:50:53 +00:00
|
|
|
|
2023-06-15 16:52:25 +00:00
|
|
|
def attach_hydrogen_pipelines(n, costs, extendable_carriers):
|
|
|
|
as_stores = extendable_carriers.get("Store", [])
|
2019-12-02 11:22:30 +00:00
|
|
|
|
2023-06-15 16:52:25 +00:00
|
|
|
if "H2 pipeline" not in extendable_carriers.get("Link", []):
|
2022-09-16 13:04:04 +00:00
|
|
|
return
|
2019-12-02 11:22:30 +00:00
|
|
|
|
2022-09-16 13:04:04 +00:00
|
|
|
assert "H2" in as_stores, (
|
|
|
|
"Attaching hydrogen pipelines requires hydrogen "
|
|
|
|
"storage to be modelled as Store-Link-Bus combination. See "
|
|
|
|
"`config.yaml` at `electricity: extendable_carriers: Store:`."
|
|
|
|
)
|
2019-12-02 11:22:30 +00:00
|
|
|
|
|
|
|
# determine bus pairs
|
2022-09-16 13:04:04 +00:00
|
|
|
attrs = ["bus0", "bus1", "length"]
|
|
|
|
candidates = pd.concat(
|
|
|
|
[n.lines[attrs], n.links.query('carrier=="DC"')[attrs]]
|
|
|
|
).reset_index(drop=True)
|
2019-12-02 11:22:30 +00:00
|
|
|
|
|
|
|
# remove bus pair duplicates regardless of order of bus0 and bus1
|
2022-09-16 13:04:04 +00:00
|
|
|
h2_links = candidates[
|
|
|
|
~pd.DataFrame(np.sort(candidates[["bus0", "bus1"]])).duplicated()
|
|
|
|
]
|
2019-12-02 11:22:30 +00:00
|
|
|
h2_links.index = h2_links.apply(lambda c: f"H2 pipeline {c.bus0}-{c.bus1}", axis=1)
|
|
|
|
|
|
|
|
# add pipelines
|
2023-04-25 15:26:23 +00:00
|
|
|
n.add("Carrier", "H2 pipeline")
|
|
|
|
|
2022-09-16 13:04:04 +00:00
|
|
|
n.madd(
|
|
|
|
"Link",
|
|
|
|
h2_links.index,
|
|
|
|
bus0=h2_links.bus0.values + " H2",
|
|
|
|
bus1=h2_links.bus1.values + " H2",
|
|
|
|
p_min_pu=-1,
|
|
|
|
p_nom_extendable=True,
|
|
|
|
length=h2_links.length.values,
|
|
|
|
capital_cost=costs.at["H2 pipeline", "capital_cost"] * h2_links.length,
|
|
|
|
efficiency=costs.at["H2 pipeline", "efficiency"],
|
|
|
|
carrier="H2 pipeline",
|
|
|
|
)
|
2019-11-19 18:36:28 +00:00
|
|
|
|
2020-12-03 18:50:53 +00:00
|
|
|
|
2019-11-19 18:36:28 +00:00
|
|
|
if __name__ == "__main__":
|
2022-09-16 13:04:04 +00:00
|
|
|
if "snakemake" not in globals():
|
2019-12-09 20:29:15 +00:00
|
|
|
from _helpers import mock_snakemake
|
2022-09-16 13:04:04 +00:00
|
|
|
|
|
|
|
snakemake = mock_snakemake("add_extra_components", simpl="", clusters=5)
|
2019-11-28 07:22:52 +00:00
|
|
|
configure_logging(snakemake)
|
2023-08-15 13:02:41 +00:00
|
|
|
set_scenario_config(snakemake)
|
2022-01-14 10:05:15 +00:00
|
|
|
|
2022-01-24 18:48:26 +00:00
|
|
|
n = pypsa.Network(snakemake.input.network)
|
2023-06-15 16:52:25 +00:00
|
|
|
extendable_carriers = snakemake.params.extendable_carriers
|
|
|
|
max_hours = snakemake.params.max_hours
|
2022-09-16 13:04:04 +00:00
|
|
|
|
|
|
|
Nyears = n.snapshot_weightings.objective.sum() / 8760.0
|
|
|
|
costs = load_costs(
|
2023-06-15 16:52:25 +00:00
|
|
|
snakemake.input.tech_costs, snakemake.params.costs, max_hours, Nyears
|
2022-09-16 13:04:04 +00:00
|
|
|
)
|
2019-11-19 18:36:28 +00:00
|
|
|
|
2023-06-15 16:52:25 +00:00
|
|
|
attach_storageunits(n, costs, extendable_carriers, max_hours)
|
|
|
|
attach_stores(n, costs, extendable_carriers)
|
|
|
|
attach_hydrogen_pipelines(n, costs, extendable_carriers)
|
2023-04-25 15:26:23 +00:00
|
|
|
|
2023-05-03 11:24:57 +00:00
|
|
|
sanitize_carriers(n, snakemake.config)
|
2024-02-05 15:16:34 +00:00
|
|
|
sanitize_locations(n)
|
2019-11-19 18:36:28 +00:00
|
|
|
|
2022-06-30 06:39:03 +00:00
|
|
|
n.meta = dict(snakemake.config, **dict(wildcards=dict(snakemake.wildcards)))
|
2022-01-24 18:48:26 +00:00
|
|
|
n.export_to_netcdf(snakemake.output[0])
|