Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add calculate_nodal_supply_energy in make summary #1046

Merged
merged 2 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions doc/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,15 @@ Upcoming Release

* Fix custom busmap read in `cluster_network`.

* Add `nodal_supply_energy` to `make_summary`.

* 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`.

* Add documentation section for how to contribute documentation

* Add documentation section for how to contribute documentation.

PyPSA-Eur 0.10.0 (19th February 2024)
=====================================
Expand Down
1 change: 1 addition & 0 deletions rules/postprocess.smk
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ rule make_summary:
energy=RESULTS + "csvs/energy.csv",
supply=RESULTS + "csvs/supply.csv",
supply_energy=RESULTS + "csvs/supply_energy.csv",
nodal_supply_energy=RESULTS + "csvs/nodal_supply_energy.csv",
prices=RESULTS + "csvs/prices.csv",
weighted_prices=RESULTS + "csvs/weighted_prices.csv",
market_values=RESULTS + "csvs/market_values.csv",
Expand Down
71 changes: 71 additions & 0 deletions scripts/make_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,76 @@ def calculate_supply_energy(n, label, 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):
metrics_list = [
"line_volume",
Expand Down Expand Up @@ -637,6 +707,7 @@ def make_summaries(networks_dict):
"energy",
"supply",
"supply_energy",
"nodal_supply_energy",
"prices",
"weighted_prices",
"price_statistics",
Expand Down
Loading