Skip to content

Commit

Permalink
added flexibility metric to make_summary
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasFrankenQ committed Nov 27, 2023
1 parent 66b4d84 commit 8135fa0
Show file tree
Hide file tree
Showing 2 changed files with 157 additions and 12 deletions.
23 changes: 14 additions & 9 deletions config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,29 @@ scenario:
simpl:
- ''
ll: # allowed transmission line volume expansion, can be any float >= 1.0 with a prefix v|c (today) or "copt"
- v1.5
- copt
fes: # Future energy scenario considered (see https://www.nationalgrideso.com/future-energy/future-energy-scenarios)
# - 'FS' # Falling Short
- 'LW' # Leading the Way
year: # year of Future Energy Scenario modelled
- 2040
# - 2040
# - 2025
# - 2030
- 2030
# - 2035
# - 2040
flexopts:
- ""
# ss: # one hour events, any weekday in winter, Saving Sessions style
# go: # EVs with go-like tariff
# int: # intelligent EV charging; centrally optimal charging of EV fleet
# v2g: # switches on vehicle to grid
# cosy: # heat flex cosy-like: Allows shifting of morning and afternoon peaks by 3 hours
# tank: # simulates the presence of a watertank for increased heat flexibility
- "ss"
- "cosy" # EVs with go-like tariff
- "tank" # intelligent EV charging; centrally optimal charging of EV fleet
- "go" # intelligent EV charging; centrally optimal charging of EV fleet
- "int-v2g"
- "go-cosy"
- "int-v2g-tank"
- "int-v2g-cosy-ss"
- "go-tank-ss"
- "int-tank-ss"
- "int-tank-ss-v2g"

opts: # only relevant for PyPSA-Eur
# - 'morocco' # adds Xlinks project; interconnection to Morocco with renewable generation
Expand Down
146 changes: 143 additions & 3 deletions scripts/make_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import numpy as np
import pandas as pd
import pypsa
from _helpers import override_component_attrs
# from _helpers import override_component_attrs
from prepare_sector_network import prepare_costs

idx = pd.IndexSlice
Expand Down Expand Up @@ -660,11 +660,150 @@ def calculate_price_statistics(n, label, price_statistics):
return price_statistics


def calculate_flex_statistics(n, label, flex_statistics):


nodes = n.buses.index[(n.buses.index.str.contains("GB")) & (n.buses.carrier == "AC")]
assign_loc = lambda series: series.apply(lambda s: " ".join(s.split(" ")[:2]))

def get_generation_capacity(n):

print("generation caps")
print(n.links.carrier.unique())
caps = pd.DataFrame(index=nodes)
for carrier in ["OCGT", "CCGT", "allam", "nuclear", "biomass"]:

g = n.links.loc[n.links.carrier == carrier, "p_nom_opt"]
g.index = assign_loc(pd.Series(g.index))

caps.loc[g.index, carrier] = g

return caps

def get_co2_balance(n):

df_atmosphere = pd.DataFrame(index=nodes)
df_co2 = pd.DataFrame(index=nodes)

mask = n.links.loc[n.links.carrier == "DAC"].index

df_atmosphere["dac"] = n.links_t.p0[mask].sum().mul(-1).set_axis(nodes)
df_co2["dac"] = n.links_t.p1[mask].sum().mul(-1).set_axis(nodes)

for carrier in ["OCGT", "CCGT"]:
mask = n.links.loc[n.links.carrier == carrier].index

emission = n.links_t.p2[mask].sum().mul(-1)
emission.index = assign_loc(pd.Series(emission.index))
df_atmosphere.loc[emission.index, carrier] = emission

bu = n.links.loc[n.links.carrier == "biogas upgrading"].index
df_atmosphere["biogas upgrading"] = n.links_t.p2[bu].sum().mul(-1).set_axis(nodes)

bm = n.links.loc[n.links.carrier == "biomass"].index
df_atmosphere["biomass"] = n.links_t.p2[bm].sum().mul(-1).set_axis(nodes)

allam = n.links.loc[n.links.carrier == "allam"].index
df_co2["abated combustion"] = n.links_t.p2[allam].sum().mul(-1).set_axis(nodes)

return df_co2, df_atmosphere


def get_distribution_capacity(n):
l = n.links.loc[n.links.carrier == "electricity distribution grid", "p_nom_opt"]
l.index = assign_loc(pd.Series(l.index))
return l


def get_transmission_capacity(n):
t = (
(l := n.lines)
.loc[
l.bus0.isin(nodes) & l.bus1.isin(nodes),
"s_nom_opt"]
.sum()
)

return pd.Series(t.sum() / len(nodes), nodes)


def get_carrier_energy(n, carrier):
print(label)
print(carrier)
print("=====================")


energy = pd.Series(0, nodes, name=carrier)

if carrier in n.generators.carrier.unique():

g = n.generators.loc[(n.generators.carrier == carrier) & (n.generators.bus.isin(nodes))].index
g = pd.Series(n.generators_t.p[g].sum().values, index=n.generators.loc[g, 'bus'])

print("in gens")
print(g.head())
energy.loc[g.index] += g

if carrier in n.links.carrier.unique():

g = n.links.loc[(n.links.carrier == carrier) & (n.links.bus1.isin(nodes))].index
etas = n.links.loc[g, "efficiency"]
g = pd.Series(
n.links_t.p0[g].mul(etas, axis=1).sum().values,
index=n.links.loc[g, "bus1"]
)

print("in links")
print(g.head())
energy.loc[g.index] += g

return energy

flex_stats = (
pd.concat([
get_carrier_energy(n, carrier).rename(carrier+"_p_nom") for carrier in [
"OCGT",
"CCGT",
"allam",
"nuclear",
"modular nuclear",
"biomass",
"solar",
"onwind",
"offwind-ac",
"offwind-dc",
"ror"
]] + [
get_transmission_capacity(n).rename("transmission_p_nom"),
get_distribution_capacity(n).rename("distribution_p_nom")] +
list(get_co2_balance(n)) + [
get_generation_capacity(n).rename(columns=lambda s: s+"_p_nom")
], axis=1)
.fillna(0)
.stack()
)

flex_statistics = flex_statistics.reindex(
flex_statistics.index.union(
flex_stats.index
)
)

flex_stats.name = label
print(flex_statistics.head())
print(flex_stats.head())
flex_statistics.loc[flex_stats.index, label] = flex_stats

return flex_statistics



def make_summaries(networks_dict):

logger.warning("Currently not doing nodal capacities")

outputs = [
"flex_statistics",
"nodal_costs",
# "nodal_capacities",
"nodal_cfs",
Expand Down Expand Up @@ -695,8 +834,9 @@ def make_summaries(networks_dict):
for label, filename in networks_dict.items():
logger.info(f"Make summary for scenario {label}, using {filename}")

overrides = override_component_attrs(snakemake.input.overrides)
n = pypsa.Network(filename, override_component_attrs=overrides)
# overrides = override_component_attrs(snakemake.input.overrides)
# n = pypsa.Network(filename, override_component_attrs=overrides)
n = pypsa.Network(filename)

assign_carriers(n)
assign_locations(n)
Expand Down

0 comments on commit 8135fa0

Please sign in to comment.