Skip to content

Commit

Permalink
temporary bug fix to make_summary
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasFrankenQ committed Nov 27, 2023
1 parent 8135fa0 commit c3d0156
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 35 deletions.
19 changes: 10 additions & 9 deletions rules/postprocess.smk
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ localrules:

rule plot_network:
input:
overrides="data/override_component_attrs",
# overrides="data/override_component_attrs",
network=RESULTS + "networks/elec_s{simpl}_ec_l{ll}_{opts}_{flexopts}_{fes}_{year}.nc",
# regions=RESOURCES + "regions_onshore_elec_s{simpl}_{gb_regions}.geojson",
regions="data/eso_zones.geojson",
Expand Down Expand Up @@ -91,14 +91,15 @@ rule make_summary:
costs=RESULTS + "csvs/costs.csv",
capacities=RESULTS + "csvs/capacities.csv",
curtailment=RESULTS + "csvs/curtailment.csv",
energy=RESULTS + "csvs/energy.csv",
supply=RESULTS + "csvs/supply.csv",
supply_energy=RESULTS + "csvs/supply_energy.csv",
prices=RESULTS + "csvs/prices.csv",
weighted_prices=RESULTS + "csvs/weighted_prices.csv",
market_values=RESULTS + "csvs/market_values.csv",
price_statistics=RESULTS + "csvs/price_statistics.csv",
metrics=RESULTS + "csvs/metrics.csv",
# energy=RESULTS + "csvs/energy.csv",
# supply=RESULTS + "csvs/supply.csv",
# supply_energy=RESULTS + "csvs/supply_energy.csv",
# prices=RESULTS + "csvs/prices.csv",
# weighted_prices=RESULTS + "csvs/weighted_prices.csv",
# market_values=RESULTS + "csvs/market_values.csv",
# price_statistics=RESULTS + "csvs/price_statistics.csv",
# metrics=RESULTS + "csvs/metrics.csv",
flex_statistics=RESULTS + "csvs/flex_statistics.csv",
threads: 2
resources:
mem_mb=10000,
Expand Down
40 changes: 14 additions & 26 deletions scripts/make_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,14 +662,11 @@ def calculate_price_statistics(n, label, 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"]:

Expand All @@ -687,8 +684,8 @@ def get_co2_balance(n):

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)
df_atmosphere["dac_atm"] = n.links_t.p0[mask].sum().mul(-1).set_axis(nodes)
df_co2["dac_co2"] = 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
Expand Down Expand Up @@ -728,10 +725,6 @@ def get_transmission_capacity(n):


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


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

Expand All @@ -740,8 +733,6 @@ def get_carrier_energy(n, carrier):
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():
Expand All @@ -753,15 +744,13 @@ def get_carrier_energy(n, carrier):
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 [
get_carrier_energy(n, carrier).rename(carrier+"_energy") for carrier in [
"OCGT",
"CCGT",
"allam",
Expand Down Expand Up @@ -789,9 +778,7 @@ def get_carrier_energy(n, carrier):
)
)

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

return flex_statistics
Expand All @@ -811,14 +798,14 @@ def make_summaries(networks_dict):
"costs",
"capacities",
"curtailment",
"energy",
"supply",
"supply_energy",
"prices",
"weighted_prices",
"price_statistics",
"market_values",
"metrics",
# "energy",
# "supply",
# "supply_energy",
# "prices",
# "weighted_prices",
# "price_statistics",
# "market_values",
# "metrics",
]

columns = pd.MultiIndex.from_tuples(
Expand Down Expand Up @@ -882,7 +869,8 @@ def to_csv(df):

df = make_summaries(networks_dict)

df["metrics"].loc["total costs"] = df["costs"].sum()
if "metrics" in df.columns:
df["metrics"].loc["total costs"] = df["costs"].sum()

to_csv(df)

Expand Down

0 comments on commit c3d0156

Please sign in to comment.