Skip to content

Commit

Permalink
adjust flh class indices; adjust fstrings for wildcard usage in snake…
Browse files Browse the repository at this point in the history
…file; no initialization of 0-potentials
  • Loading branch information
cpschau committed Sep 16, 2024
1 parent 8bc092a commit 2281468
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 33 deletions.
4 changes: 2 additions & 2 deletions Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -284,15 +284,15 @@ rule prepare_res_potentials:
),
output:
**{
f"{tech}_{year}_{discountrate}_potential_s{simpl}_{clusters}": f"resources/custom_renewables/{tech}/{tech}_{year}_{discountrate}_potential_s{simpl}_{clusters}.csv"
f"{tech}_{year}_{discountrate}_potential_s{simpl}_{clusters}": f"resources/custom_renewables/{tech}/{tech}_{year}_{discountrate}_potential_s{{simpl}}_{{clusters}}.csv"
for tech in config["custom_data"]["renewables"]
for year in config["scenario"]["planning_horizons"]
for discountrate in config["costs"]["discountrate"]
for simpl in config["scenario"]["simpl"]
for clusters in config["scenario"]["clusters"]
},
**{
f"{tech}_{year}_{discountrate}_installable_s{simpl}_{clusters}": f"resources/custom_renewables/{tech}/{tech}_{year}_{discountrate}_installable_s{simpl}_{clusters}.csv"
f"{tech}_{year}_{discountrate}_installable_s{simpl}_{clusters}": f"resources/custom_renewables/{tech}/{tech}_{year}_{discountrate}_installable_s{{simpl}}_{{clusters}}.csv"
for tech in config["custom_data"]["renewables"]
for year in config["scenario"]["planning_horizons"]
for discountrate in config["costs"]["discountrate"]
Expand Down
45 changes: 25 additions & 20 deletions scripts/override_respot.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
import pytz
import xarray as xr
from helpers import mock_snakemake, override_component_attrs, sets_path_to_root
import logging

logger = logging.getLogger(__name__)


def override_values(tech, year, dr, simpl, clusters):
Expand All @@ -23,24 +26,27 @@ def override_values(tech, year, dr, simpl, clusters):
parse_dates=True,
).filter(buses, axis=1)

custom_res = (
pd.read_csv(
snakemake.input[
"custom_res_ins_{0}_{1}_{2}_s{3}_{4}".format(
tech, year, dr, simpl, clusters
)
],
index_col=0,
)
.loc[buses]
.reset_index()
custom_res = pd.read_csv(
snakemake.input[
"custom_res_ins_{0}_{1}_{2}_s{3}_{4}".format(
tech, year, dr, simpl, clusters
)
],
)

custom_res["Generator"] = custom_res["Generator"].apply(lambda x: x + " " + tech)
custom_res = custom_res.set_index("Generator")
custom_res.index = custom_res["Generator"] + " " + tech
custom_res_t.columns = custom_res_t.columns + " " + tech

if tech.replace("-", " ") in n.generators.carrier.unique():
to_drop = n.generators[n.generators.carrier == tech].index
custom_res.loc[to_drop, "installedcapacity"] = n.generators.loc[
to_drop, "p_nom"
]
mask = custom_res["installedcapacity"] > custom_res.p_nom_max
if mask.any():
logger.info(
f"Installed capacities exceed maximum installable capacities for {tech} at nodes {custom_res.loc[mask].index}."
)
n.mremove("Generator", to_drop)

if snakemake.wildcards["planning_horizons"] == 2050:
Expand All @@ -57,19 +63,18 @@ def override_values(tech, year, dr, simpl, clusters):

n.madd(
"Generator",
buses,
" " + tech,
bus=buses,
custom_res.index,
bus=custom_res["Generator"],
carrier=tech,
p_nom_extendable=True,
p_nom_max=custom_res["p_nom_max"].values,
p_nom_max=custom_res["p_nom_max"],
# weight=ds["weight"].to_pandas(),
# marginal_cost=custom_res["fixedomEuroPKW"].values * 1000,
capital_cost=custom_res["annualcostEuroPMW"].values,
capital_cost=custom_res["annualcostEuroPMW"],
efficiency=1.0,
p_max_pu=custom_res_t,
lifetime=custom_res["lifetime"][0],
p_nom_min=existing_res,
lifetime=custom_res["lifetime"],
p_nom_min=custom_res["installedcapacity"],
)


Expand Down
18 changes: 7 additions & 11 deletions scripts/prepare_res_potentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def calculate_flh_classes(group):
n = len(group)
if n < 4:
bins = [i / n for i in range(n + 1)]
labels = [f"Q{i+3}" for i in range(n)]
labels = [f"Q{i}" for i in range(5 - n, 5)]
else:
bins = [0, 0.3, 0.6, 0.9, 1.0]
labels = ["Q1", "Q2", "Q3", "Q4"]
Expand Down Expand Up @@ -171,17 +171,13 @@ def prepare_enertile(df, df_t):
numeric_only=True
)

# if technology == "onwind":
# bins = [-float("inf"), 1, 2, float("inf")]
# labels = ["very good", "good", "remaining"]
# else:
# bins = [-float("inf"), float("inf")]
# labels = ["very good"]

df = df.groupby(["Generator", "step", "simyear"], as_index=False).mean()
df = df.groupby(["Generator", "simyear"], as_index=False).apply(
calculate_flh_classes
)
if technology == "solar":
df["flh_class"] = "Q4"
else:
df = df.groupby(["Generator", "simyear"], as_index=False).apply(
calculate_flh_classes
)

df.set_index(["Generator", "step", "simyear"], inplace=True)
df_t.set_index(["region", "step", "simyear"], inplace=True)
Expand Down

0 comments on commit 2281468

Please sign in to comment.