Skip to content

Commit

Permalink
Merge branch 'feature/add-nodal-supply-energy' of github.com:Climact/…
Browse files Browse the repository at this point in the history
…pypsa-eur-climact into Climact-feature/add-nodal-supply-energy
  • Loading branch information
fneum committed May 13, 2024
2 parents 4f98a4b + a139bb6 commit e322e21
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
2 changes: 2 additions & 0 deletions doc/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ 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`, `simplify_network`, and `cluster_network`; the `build_bus_regions` rule is now integrated into the `base_network` rule.
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

0 comments on commit e322e21

Please sign in to comment.