Skip to content

Commit

Permalink
fix load weighted prices (#1287)
Browse files Browse the repository at this point in the history
* fix load weighted prices

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* include pglaum comments

* drop prices if load is zero

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* don't drop prices with zero load

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Fabian Neumann <[email protected]>
  • Loading branch information
3 people authored Nov 11, 2024
1 parent 73ad46c commit ee1b3d9
Showing 1 changed file with 18 additions and 64 deletions.
82 changes: 18 additions & 64 deletions scripts/make_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,77 +540,30 @@ def calculate_prices(n, label, prices):


def calculate_weighted_prices(n, label, weighted_prices):
# Warning: doesn't include storage units as loads

weighted_prices = weighted_prices.reindex(
pd.Index(
[
"electricity",
"heat",
"space heat",
"urban heat",
"space urban heat",
"gas",
"H2",
]
)
)

link_loads = {
"electricity": [
"heat pump",
"resistive heater",
"battery charger",
"H2 Electrolysis",
],
"heat": ["water tanks charger"],
"urban heat": ["water tanks charger"],
"space heat": [],
"space urban heat": [],
"gas": ["OCGT", "gas boiler", "CHP electric", "CHP heat"],
"H2": ["Sabatier", "H2 Fuel Cell"],
}

for carrier, value in link_loads.items():
if carrier == "electricity":
suffix = ""
elif carrier[:5] == "space":
suffix = carrier[5:]
else:
suffix = " " + carrier

buses = n.buses.index[n.buses.index.str[2:] == suffix]

if buses.empty:
continue
carriers = n.buses.carrier.unique()

if carrier in ["H2", "gas"]:
load = pd.DataFrame(index=n.snapshots, columns=buses, data=0.0)
else:
load = n.loads_t.p_set[buses.intersection(n.loads.index)]

for tech in value:
names = n.links.index[n.links.index.to_series().str[-len(tech) :] == tech]

if not names.empty:
load += (
n.links_t.p0[names].T.groupby(n.links.loc[names, "bus0"]).sum().T
)
for carrier in carriers:
grouper = n.statistics.groupers.get_bus_and_carrier
load = (
n.statistics.withdrawal(
groupby=grouper,
aggregate_time=False,
nice_names=False,
bus_carrier=carrier,
)
.groupby(level="bus")
.sum()
.T.fillna(0)
)

# Add H2 Store when charging
# if carrier == "H2":
# stores = n.stores_t.p[buses+ " Store"].groupby(n.stores.loc[buses+ " Store", "bus"],axis=1).sum(axis=1)
# stores[stores > 0.] = 0.
# load += -stores
price = n.buses_t.marginal_price.loc[:, n.buses.carrier == carrier]
price = price.reindex(columns=load.columns, fill_value=1)

weighted_prices.loc[carrier, label] = (
load * n.buses_t.marginal_price[buses]
load * price
).sum().sum() / load.sum().sum()

# still have no idea what this is for, only for debug reasons.
if carrier[:5] == "space":
logger.debug(load * n.buses_t.marginal_price[buses])

return weighted_prices


Expand Down Expand Up @@ -749,6 +702,7 @@ def to_csv(df):
df[key].to_csv(snakemake.output[key])


# %%
if __name__ == "__main__":
if "snakemake" not in globals():
from _helpers import mock_snakemake
Expand Down

0 comments on commit ee1b3d9

Please sign in to comment.