Skip to content

Commit 3badd09

Browse files
committed
Allow external file for specifying capacity factors
1 parent 717cc97 commit 3badd09

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

switch_model/wecc/get_inputs/post_process_steps/aggregate_candidate_projects.py

Lines changed: 22 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
)
4141
key = "GENERATION_PROJECT"
4242

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

5868
# Reset the dbid since we're creating a new project
5969
df["gen_dbid"] = "."
@@ -154,10 +164,16 @@ def agg_costs(x):
154164
df = dfgroup.quantile(
155165
lambda x: np.average(x["gen_max_capacity_factor"], weights=x["weight"])
156166
).rename({None: "gen_max_capacity_factor"}, axis=1)
157-
else:
158-
zonal_cf = pd.read_csv("zonal_capacity_factors.csv", index_col=False)
167+
elif cf_method == "file":
168+
df = df.drop(["gen_max_capacity_factor", "weight"], axis=1).drop_duplicates()
169+
df = df.merge(
170+
zonal_cf, on=["gen_load_zone", "timepoint", "gen_tech"], how="left"
171+
)
172+
breakpoint()
159173
# TODO
160-
df = pd.concat([df, df_keep])
174+
else:
175+
raise NotImplementedError(f"Method '{cf_method}' is not implemented.")
176+
df = pd.concat([df[columns], df_keep])
161177
df[columns].to_csv(filename, index=False)
162178

163179

0 commit comments

Comments
 (0)