From b8f1f3018365a9b553ad9bad0148a7c6d1452cd0 Mon Sep 17 00:00:00 2001 From: Tom Brown Date: Wed, 9 Dec 2020 15:18:01 +0100 Subject: [PATCH] Make code compatible with PyPSA-Eur v0.3.0 Only change was to remove the Store-Link-Bus combinations for batteries and H2 storage from PyPSA-Eur, since they are implemented with different names, costs and voltage level in PyPSA-Eur-Sec. Removals are now done in a more transparent way in the config.yaml. --- config.default.yaml | 9 +++++++++ scripts/prepare_sector_network.py | 17 ++++++++--------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/config.default.yaml b/config.default.yaml index 016913c9..1885a8d0 100644 --- a/config.default.yaml +++ b/config.default.yaml @@ -56,6 +56,15 @@ electricity: battery: 6 H2: 168 +# regulate what components with which carriers are kept from PyPSA-Eur; +# some technologies are removed because they are implemented differently +# or have different year-dependent costs in PyPSA-Eur-Sec +pypsa_eur: + "Bus": ["AC"] + "Link": ["DC"] + "Generator": ["onwind", "offwind-ac", "offwind-dc", "solar", "ror"] + "StorageUnit": ["PHS","hydro"] + biomass: year: 2030 scenario: "Med" diff --git a/scripts/prepare_sector_network.py b/scripts/prepare_sector_network.py index 423421aa..7105f806 100644 --- a/scripts/prepare_sector_network.py +++ b/scripts/prepare_sector_network.py @@ -155,16 +155,15 @@ def remove_elec_base_techs(n): """remove conventional generators (e.g. OCGT) and storage units (e.g. batteries and H2) from base electricity-only network, since they're added here differently using links """ - to_keep = {"generators" : snakemake.config["plotting"]["vre_techs"], - "storage_units" : snakemake.config["plotting"]["renewable_storage_techs"]} - n.carriers = n.carriers.loc[to_keep["generators"] + to_keep["storage_units"]] - - for components, techs in iteritems(to_keep): - df = getattr(n,components) - to_remove = df.carrier.value_counts().index^techs - print("removing {} with carrier {}".format(components,to_remove)) - df.drop(df.index[df.carrier.isin(to_remove)],inplace=True) + for c in n.iterate_components(snakemake.config["pypsa_eur"]): + to_keep = snakemake.config["pypsa_eur"][c.name] + to_remove = pd.Index(c.df.carrier.unique())^to_keep + print("Removing",c.list_name,"with carrier",to_remove) + names = c.df.index[c.df.carrier.isin(to_remove)] + print(names) + n.mremove(c.name, names) + n.carriers.drop(to_remove, inplace=True, errors="ignore") def add_co2_tracking(n):