Skip to content

Commit 3a48ce9

Browse files
committed
Allow external file for specifying capacity factors
1 parent ecbc5ca commit 3a48ce9

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

switch_model/wecc/get_inputs/post_process_steps/aggregate_candidate_projects.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def post_process(config):
3636
assert "Hydro_Pumped" not in agg_techs
3737

3838
print(
39-
f"\t\tAggregating on projects where gen_tech in {agg_techs} with capacity factors from the {cf_quantile * 100}th percentile")
39+
f"\t\tAggregating on projects where gen_tech in {agg_techs} with capacity factor method {cf_method}")
4040
key = "GENERATION_PROJECT"
4141

4242
#################
@@ -49,8 +49,18 @@ def post_process(config):
4949
columns = df.columns.values
5050
predetermined = pd.read_csv("gen_build_predetermined.csv", usecols=[key], dtype={key: str})[key]
5151
should_agg = df["gen_tech"].isin(agg_techs) & (~df[key].isin(predetermined))
52-
projects_no_agg = df[~should_agg]
53-
df = df[should_agg]
52+
if cf_method == "file":
53+
# Filter out projects where we don't have a capacity factor
54+
zonal_cf = pd.read_csv("zonal_capacity_factors.csv", index_col=False)
55+
valid_proj = df.merge(
56+
zonal_cf[["gen_load_zone", "gen_tech"]].drop_duplicates(),
57+
on=["gen_load_zone", "gen_tech"],
58+
how='right',
59+
validate="many_to_one"
60+
)[key]
61+
should_agg &= df[key].isin(valid_proj)
62+
projects_no_agg = df[~should_agg].copy()
63+
df = df[should_agg].copy()
5464

5565
# Reset the dbid since we're creating a new project
5666
df["gen_dbid"] = "."
@@ -153,10 +163,18 @@ def agg_costs(x):
153163
df = dfgroup \
154164
.quantile(lambda x: np.average(x["gen_max_capacity_factor"], weights=x["weight"])) \
155165
.rename({None: "gen_max_capacity_factor"}, axis=1)
156-
else:
157-
zonal_cf = pd.read_csv("zonal_capacity_factors.csv", index_col=False)
166+
elif cf_method == "file":
167+
df = df.drop(["gen_max_capacity_factor", "weight"], axis=1).drop_duplicates()
168+
df = df.merge(
169+
zonal_cf,
170+
on=["gen_load_zone", "timepoint", "gen_tech"],
171+
how='left'
172+
)
173+
breakpoint()
158174
# TODO
159-
df = pd.concat([df, df_keep])
175+
else:
176+
raise NotImplementedError(f"Method '{cf_method}' is not implemented.")
177+
df = pd.concat([df[columns], df_keep])
160178
df[columns].to_csv(filename, index=False)
161179

162180

0 commit comments

Comments
 (0)