Add calculate_nodal_supply_energy in make summary

This commit is contained in:
Thomas Gilon 2024-04-12 16:10:00 +02:00
parent 5ecd56d53c
commit 45aa714bdc
3 changed files with 74 additions and 0 deletions

View File

@ -181,6 +181,8 @@ Upcoming Release
* Fix custom busmap read in `cluster_network`. * Fix custom busmap read in `cluster_network`.
* Add `nodal_supply_energy` to `make_summary`.
PyPSA-Eur 0.10.0 (19th February 2024) PyPSA-Eur 0.10.0 (19th February 2024)
===================================== =====================================

View File

@ -199,6 +199,7 @@ rule make_summary:
energy=RESULTS + "csvs/energy.csv", energy=RESULTS + "csvs/energy.csv",
supply=RESULTS + "csvs/supply.csv", supply=RESULTS + "csvs/supply.csv",
supply_energy=RESULTS + "csvs/supply_energy.csv", supply_energy=RESULTS + "csvs/supply_energy.csv",
nodal_supply_energy=RESULTS + "csvs/nodal_supply_energy.csv",
prices=RESULTS + "csvs/prices.csv", prices=RESULTS + "csvs/prices.csv",
weighted_prices=RESULTS + "csvs/weighted_prices.csv", weighted_prices=RESULTS + "csvs/weighted_prices.csv",
market_values=RESULTS + "csvs/market_values.csv", market_values=RESULTS + "csvs/market_values.csv",

View File

@ -413,6 +413,76 @@ def calculate_supply_energy(n, label, supply_energy):
return supply_energy return supply_energy
def calculate_nodal_supply_energy(n, label, nodal_supply_energy):
"""
Calculate the total energy supply/consumption of each component at the buses
aggregated by carrier and node.
"""
bus_carriers = n.buses.carrier.unique()
for i in bus_carriers:
bus_map = n.buses.carrier == i
bus_map.at[""] = False
for c in n.iterate_components(n.one_port_components):
items = c.df.index[c.df.bus.map(bus_map).fillna(False)]
if len(items) == 0:
continue
s = (
pd.concat([
(
c.pnl.p[items]
.multiply(n.snapshot_weightings.generators, axis=0)
.sum()
.multiply(c.df.loc[items, "sign"])
),
c.df.loc[items][["bus", "carrier"]]
], axis=1)
.groupby(by=["bus", "carrier"])
.sum()[0]
)
s = pd.concat([s], keys=[c.list_name])
s = pd.concat([s], keys=[i])
nodal_supply_energy = nodal_supply_energy.reindex(s.index.union(nodal_supply_energy.index))
nodal_supply_energy.loc[s.index, label] = s
for c in n.iterate_components(n.branch_components):
for end in [col[3:] for col in c.df.columns if col[:3] == "bus"]:
items = c.df.index[c.df["bus" + str(end)].map(bus_map).fillna(False)]
if (len(items) == 0) or c.pnl["p" + end].empty:
continue
s = (
pd.concat([
(
(-1) * c.pnl["p" + end][items]
.multiply(n.snapshot_weightings.generators, axis=0)
.sum()
),
c.df.loc[items][["bus0", "carrier"]]
], axis=1)
.groupby(by=["bus0", "carrier"])
.sum()[0]
)
s.index = s.index.map(lambda x: (x[0], x[1] + end))
s = pd.concat([s], keys=[c.list_name])
s = pd.concat([s], keys=[i])
nodal_supply_energy = nodal_supply_energy.reindex(
s.index.union(nodal_supply_energy.index)
)
nodal_supply_energy.loc[s.index, label] = s
return nodal_supply_energy
def calculate_metrics(n, label, metrics): def calculate_metrics(n, label, metrics):
metrics_list = [ metrics_list = [
"line_volume", "line_volume",
@ -637,6 +707,7 @@ def make_summaries(networks_dict):
"energy", "energy",
"supply", "supply",
"supply_energy", "supply_energy",
"nodal_supply_energy",
"prices", "prices",
"weighted_prices", "weighted_prices",
"price_statistics", "price_statistics",