Skip to content

Commit

Permalink
Merge pull request #1018 from koen-vg/existing-caps-from-pm
Browse files Browse the repository at this point in the history
Use powerplantmatching IRENASTAT for renewable capacities in `add_existing_baseyear`
  • Loading branch information
fneum authored Apr 30, 2024
2 parents 3034863 + 33dddbf commit 03fd9bf
Show file tree
Hide file tree
Showing 13 changed files with 23 additions and 251 deletions.
1 change: 0 additions & 1 deletion config/config.default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ enable:
retrieve_sector_databundle: true
retrieve_cost_data: true
build_cutout: false
retrieve_irena: false
retrieve_cutout: true
build_natura_raster: false
retrieve_natura_raster: true
Expand Down
34 changes: 0 additions & 34 deletions data/existing_infrastructure/offwind_capacity_IRENA.csv

This file was deleted.

34 changes: 0 additions & 34 deletions data/existing_infrastructure/onwind_capacity_IRENA.csv

This file was deleted.

34 changes: 0 additions & 34 deletions data/existing_infrastructure/solar_capacity_IRENA.csv

This file was deleted.

1 change: 0 additions & 1 deletion doc/configtables/enable.csv
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ retrieve_databundle,bool,"{true, false}","Switch to retrieve databundle from zen
retrieve_sector_databundle,bool,"{true, false}","Switch to retrieve sector databundle from zenodo via the rule :mod:`retrieve_sector_databundle` or whether to keep a custom databundle located in the corresponding folder."
retrieve_cost_data,bool,"{true, false}","Switch to retrieve technology cost data from `technology-data repository <https://github.com/PyPSA/technology-data>`_."
build_cutout,bool,"{true, false}","Switch to enable the building of cutouts via the rule :mod:`build_cutout`."
retrieve_irena,bool,"{true, false}",Switch to enable the retrieval of ``existing_capacities`` from IRENASTAT with :mod:`retrieve_irena`.
retrieve_cutout,bool,"{true, false}","Switch to enable the retrieval of cutouts from zenodo with :mod:`retrieve_cutout`."
build_natura_raster,bool,"{true, false}","Switch to enable the creation of the raster ``natura.tiff`` via the rule :mod:`build_natura_raster`."
retrieve_natura_raster,bool,"{true, false}","Switch to enable the retrieval of ``natura.tiff`` from zenodo with :mod:`retrieve_natura_raster`."
Expand Down
2 changes: 2 additions & 0 deletions doc/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ Upcoming Release

* Fix custom busmap read in `cluster_network`.

* Data on existing renewable capacities is now consistently taken from powerplantmatching (instead of being retrieved separately); the dataset has also been updated to include 2023 values.

* Added shapes to .nc file for different stages of the network object in `base_network`, `build_bus_regions`, and `cluster_network`.

* Fix p_nom_min of renewables generators for myopic approach and add check of existing capacities in `add_land_use_constraint_m`.
Expand Down
5 changes: 0 additions & 5 deletions doc/retrieve.rst
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,6 @@ This rule downloads techno-economic assumptions from the `technology-data reposi

- ``resources/costs.csv``

Rule ``retrieve_irena``
================================

.. automodule:: retrieve_irena

Rule ``retrieve_ship_raster``
================================

Expand Down
2 changes: 1 addition & 1 deletion envs/environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ dependencies:
- yaml
- pytables
- lxml
- powerplantmatching>=0.5.5,!=0.5.9
- powerplantmatching>=0.5.13
- numpy
- pandas>=2.1
- geopandas>=0.11.0
Expand Down
18 changes: 0 additions & 18 deletions rules/retrieve.smk
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,6 @@ if config["enable"]["retrieve"] and config["enable"].get("retrieve_databundle",
"../scripts/retrieve_databundle.py"


if config["enable"].get("retrieve_irena"):

rule retrieve_irena:
output:
offwind="data/existing_infrastructure/offwind_capacity_IRENA.csv",
onwind="data/existing_infrastructure/onwind_capacity_IRENA.csv",
solar="data/existing_infrastructure/solar_capacity_IRENA.csv",
log:
"logs/retrieve_irena.log",
resources:
mem_mb=1000,
retries: 2
conda:
"../envs/retrieve.yaml"
script:
"../scripts/retrieve_irena.py"


if config["enable"]["retrieve"] and config["enable"].get("retrieve_cutout", True):

rule retrieve_cutout:
Expand Down
3 changes: 0 additions & 3 deletions rules/solve_myopic.smk
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ rule add_existing_baseyear:
existing_heating_distribution=resources(
"existing_heating_distribution_elec_s{simpl}_{clusters}_{planning_horizons}.csv"
),
existing_solar="data/existing_infrastructure/solar_capacity_IRENA.csv",
existing_onwind="data/existing_infrastructure/onwind_capacity_IRENA.csv",
existing_offwind="data/existing_infrastructure/offwind_capacity_IRENA.csv",
output:
RESULTS
+ "prenetworks-brownfield/elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}.nc",
Expand Down
3 changes: 0 additions & 3 deletions rules/solve_perfect.smk
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ rule add_existing_baseyear:
"existing_heating_distribution_elec_s{simpl}_{clusters}_{planning_horizons}.csv"
),
existing_heating="data/existing_infrastructure/existing_heating_raw.csv",
existing_solar="data/existing_infrastructure/solar_capacity_IRENA.csv",
existing_onwind="data/existing_infrastructure/onwind_capacity_IRENA.csv",
existing_offwind="data/existing_infrastructure/offwind_capacity_IRENA.csv",
output:
RESULTS
+ "prenetworks-brownfield/elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}.nc",
Expand Down
29 changes: 20 additions & 9 deletions scripts/add_existing_baseyear.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import country_converter as coco
import numpy as np
import pandas as pd
import powerplantmatching as pm
import pypsa
import xarray as xr
from _helpers import (
Expand Down Expand Up @@ -60,14 +61,22 @@ def add_existing_renewables(df_agg, costs):
Append existing renewables to the df_agg pd.DataFrame with the conventional
power plants.
"""
carriers = {"solar": "solar", "onwind": "onwind", "offwind": "offwind-ac"}
tech_map = {"solar": "PV", "onwind": "Onshore", "offwind": "Offshore"}

for tech in ["solar", "onwind", "offwind"]:
carrier = carriers[tech]
countries = snakemake.config["countries"]
irena = pm.data.IRENASTAT().powerplant.convert_country_to_alpha2()
irena = irena.query("Country in @countries")
irena = irena.groupby(["Technology", "Country", "Year"]).Capacity.sum()

df = pd.read_csv(snakemake.input[f"existing_{tech}"], index_col=0).fillna(0.0)
irena = irena.unstack().reset_index()

for carrier, tech in tech_map.items():
df = (
irena[irena.Technology.str.contains(tech)]
.drop(columns=["Technology"])
.set_index("Country")
)
df.columns = df.columns.astype(int)
df.index = cc.convert(df.index, to="iso2")

# calculate yearly differences
df.insert(loc=0, value=0.0, column="1999")
Expand Down Expand Up @@ -97,14 +106,16 @@ def add_existing_renewables(df_agg, costs):

for year in nodal_df.columns:
for node in nodal_df.index:
name = f"{node}-{tech}-{year}"
name = f"{node}-{carrier}-{year}"
capacity = nodal_df.loc[node, year]
if capacity > 0.0:
df_agg.at[name, "Fueltype"] = tech
df_agg.at[name, "Fueltype"] = carrier
df_agg.at[name, "Capacity"] = capacity
df_agg.at[name, "DateIn"] = year
df_agg.at[name, "lifetime"] = costs.at[tech, "lifetime"]
df_agg.at[name, "DateOut"] = year + costs.at[tech, "lifetime"] - 1
df_agg.at[name, "lifetime"] = costs.at[carrier, "lifetime"]
df_agg.at[name, "DateOut"] = (
year + costs.at[carrier, "lifetime"] - 1
)
df_agg.at[name, "cluster_bus"] = node


Expand Down
Loading

0 comments on commit 03fd9bf

Please sign in to comment.