Skip to content

Rule add_electricity

Workflow Diagram

See the complete workflow in the repository.

digraph snakemake_dag { graph [bgcolor=white, margin=0, size="8,5" ]; node [fontname=sans, fontsize=10, penwidth=2, shape=box, style=rounded ]; edge [color=grey, penwidth=2 ]; 3 [color="0.25 0.6 0.85", label=simplify_network]; 4 [color="0.50 0.6 0.85", fillcolor=gray, label=add_electricity, style=filled]; 4 -> 3; 5 [color="0.36 0.6 0.85", label=build_bus_regions]; 5 -> 4; 6 [color="0.58 0.6 0.85", label=base_network]; 6 -> 4; 7 [color="0.31 0.6 0.85", label=build_powerplants]; 7 -> 4; 8 [color="0.28 0.6 0.85", label=build_shapes]; 8 -> 4; 9 [color="0.22 0.6 0.85", label=build_renewable_profiles]; 9 -> 4; 10 [color="0.44 0.6 0.85", label=build_hydro_profile]; 10 -> 4; }

Script Documentation

Adds electrical generators, load and existing hydro storage units to a base network.

Relevant Settings

.. code:: yaml

costs:
    output_currency:

electricity:
    max_hours:
    marginal_cost:
    capital_cost:
    conventional_carriers:
    co2limit:
    extendable_carriers:
    include_renewable_capacities_from_OPSD:
    estimate_renewable_capacities_from_capacity_stats:

renewable:
    hydro:
        carriers:
        hydro_max_hours:
        hydro_max_hours_default:
        hydro_capital_cost:

lines:
    length_factor:

.. seealso:: Documentation of the configuration file config.yaml at :ref:costs_cf, :ref:electricity_cf, :ref:load_options_cf, :ref:renewable_cf, :ref:lines_cf

Inputs

  • 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.
  • data/bundle/hydro_capacities.csv: Hydropower plant store/discharge power capacities, energy storage capacity, and average hourly inflow by country. Not currently used!

    .. image:: /img/hydrocapacities.png

  • data/geth2015_hydro_capacities.csv: alternative to capacities above; not currently used!

  • resources/demand_profiles.csv: a csv file containing the demand profile associated with buses
  • resources/shapes/gadm_shapes.geojson: confer :ref:shapes
  • resources/powerplants.csv: confer :ref:powerplants
  • resources/profile_{}.nc: all technologies in config["renewables"].keys(), confer :ref:renewableprofiles
  • networks/base.nc: confer :ref:base

Outputs

  • networks/elec.nc:

    .. image:: /img/elec.png :width: 75 % :align: center

Description

The rule :mod:add_electricity ties all the different data inputs from the preceding rules together into a detailed PyPSA network that is stored in networks/elec.nc. It includes:

  • today's transmission topology and transfer capacities (in future, optionally including lines which are under construction according to the config settings lines: under_construction and links: under_construction),
  • today's thermal and hydro power generation capacities (for the technologies listed in the config setting electricity: conventional_carriers), and
  • today's load time-series (upsampled in a top-down approach according to population and gross domestic product)

It further adds extendable generators with zero capacity for

  • photovoltaic, onshore and AC- as well as DC-connected offshore wind installations with today's locational, hourly wind and solar capacity factors (but no current capacities),
  • additional open- and combined-cycle gas turbines (if OCGT and/or CCGT is listed in the config setting electricity: extendable_carriers)

load_powerplants(ppl_fn, costs=None, fill_values=None, grouping_years=None)

Load and preprocess powerplant matching data, fill missing datein/dateout, and assign grouping years. Parameters


ppl_fn : str Path to powerplant matching csv file. costs : pd.DataFrame DataFrame containing technology costs. fill_values : dict Dictionary containing default values for lifetime. grouping_years : list List of years to group build years into.

Returns

ppl : pd.DataFrame Power plant list DataFrame.

fill_datein_dateout(ppl, costs, fill_values)

Fill missing datein and dateout values in ppl DataFrame.

Parameters

ppl : pd.DataFrame Dataframe containing power plants. costs : pd.DataFrame DataFrame containing cost assumptions. fill_values : dict Dictionary containing default values for lifetime.

Returns

ppl : pd.DataFrame Power plant list DataFrame with filled missing datein and dateout columns.

attach_load(n, demand_profiles)

Add load profiles to network buses.

Parameters

n: pypsa network

demand_profiles: str Path to csv file of elecric demand time series, e.g. "resources/demand_profiles.csv" Demand profile has snapshots as rows and bus names as columns.

Returns

n : pypsa network Now attached with load time series

get_grouping_year(build_year, grouping_years)

Map build_year to the nearest grouping year bin.

Each build year is assigned to the first grouping year that is greater than or equal to it (i.e. the right edge of its bin).

Example: grouping_years = [1980, 2000, 2010, 2015, 2020] build_year = 2012 → returns 2015 build_year = 2018 → returns 2020

aggregate_ppl_by_bus_carrier_year(ppl)

Aggregate power plants by (bus, carrier, grouping_year).

Creates a new carrier name with grouping year suffix (e.g., "CCGT-2020") and aggregates capacity and other attributes.

Parameters

ppl : pd.DataFrame Power plant DataFrame with columns: bus, carrier, grouping_year, p_nom, efficiency, marginal_cost, datein, dateout and so on.

Returns

pd.DataFrame Aggregated power plants with columns: bus, carrier, carrier_gy, p_nom, efficiency, marginal_cost, build_year, lifetime.

Example

Input: bus carrier grouping_year p_nom bus1 CCGT 2015 100 bus1 CCGT 2015 200 bus1 CCGT 2020 150

Output: bus carrier carrier_gy p_nom bus1 CCGT CCGT-2015 300 bus1 CCGT CCGT-2020 150

aggregate_inflow_by_group(ppl, ppl_grouped, inflow_t)

Aggregate inflow time series by (bus, carrier, grouping_year) groups.

Parameters

ppl : pd.DataFrame Original (ungrouped) power plant DataFrame with columns: bus, carrier, grouping_year. ppl_grouped : pd.DataFrame Aggregated power plant DataFrame with columns: bus, carrier, carrier_gy. inflow_t : pd.DataFrame Inflow time series DataFrame with plant indices as columns.

Returns

pd.DataFrame Aggregated inflow time series with ppl_grouped indices as columns.

get_irena_targets_for_carrier(carrier, estimate_renewable_capacities_config, countries)

Return IRENA installed capacity targets for a given carrier as a Series indexed by country (MW).

The function reads IRENASTAT installed capacity data using the existing estimate_renewable_capacities configuration. Offshore wind is mapped entirely to offwind-ac.

attach_wind_and_solar(n, costs, ppl, input_files, carriers, extendable_carriers, line_length_factor)

Attach wind and solar generators.

Existing capacities are taken from powerplants.csv and spatialized to buses. National capacity gaps with respect to IRENA targets are filled and redistributed uniformly across buses within each country.

Offshore wind is treated entirely as offwind-ac.

Parameters

n : pypsa.Network The PyPSA network to modify. costs : pd.DataFrame DataFrame containing technology costs. ppl : pd.DataFrame Power plant DataFrame. input_files : dict Snakemake input object containing renewable profile files. carriers : set Set of renewable carriers to be added. extendable_carriers : dict Dictionary of extendable carriers for different component types. line_length_factor : float Factor to adjust line lengths for connection cost calculations.

Returns

None

attach_conventional_generators(n, costs, ppl, conventional_carriers, extendable_carriers, renewable_carriers, conventional_config, conventional_inputs)

Add existing conventional generators to the network and extendable conventional generators at all buses.

Parameters

n : pypsa.Network The PyPSA network to modify. costs : pd.DataFrame DataFrame containing technology costs. ppl : pd.DataFrame Power plant DataFrame. conventional_carriers : list List of conventional carriers to be added. extendable_carriers : dict Dictionary of extendable carriers for different component types. renewable_carriers : set Set of renewable carriers. conventional_config : list List of conventional configuration settings. conventional_inputs : dict Dictionary of conventional input parameters.

Returns

None

apply_nuclear_p_max_pu(n, nuclear_p_max_pu)

Apply country-level static nuclear p_max_pu limits based on historical Energy Availability Factor (IAEA, 2022–2024).

  • If country is in CSV: apply p_max_pu
  • If country is NOT in CSV: keep default p_max_pu = 1.0 and warn

attach_hydro(n, costs, ppl, hydro_min_inflow_pu=1.0)

Add existing hydro powerplants to the network as Hydro Storage units, Run-Of-River generators, and Pumped Hydro storage units.

Parameters

n : pypsa.Network The PyPSA network to modify. costs : pd.DataFrame DataFrame containing technology costs. ppl : pd.DataFrame Power plant DataFrame.

Returns

None

attach_existing_batteries(n, costs, ppl)

Add existing battery storage units from powerplants.csv to the network.

Parameters

n : pypsa.Network The PyPSA network to modify. costs : pd.DataFrame DataFrame containing technology costs. ppl : pd.DataFrame Power plant DataFrame.

Returns

None

attach_extendable_generators(n, costs, ppl)

Add extendable conventional generators (OCGT, CCGT, nuclear) with zero capacity.

Parameters

n : pypsa.Network The PyPSA network to modify. costs : pd.DataFrame DataFrame containing technology costs. ppl : pd.DataFrame Power plant DataFrame.

Returns

None

add_nice_carrier_names(n, config)

Add nice names and colors to carriers.

Parameters

n : pypsa.Network The PyPSA network to modify. config : dict The configuration dictionary containing plotting settings.

Returns

None