Skip to content

Commit ecbc5ca

Browse files
committed
Output timepoint and start working on post-process step
1 parent 10a08c1 commit ecbc5ca

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

switch_model/tools/templates/config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,4 @@ get_inputs:
5757
# of all the available candidate plants, 0.5 will use the median plant and 0 will use the worst plant.
5858
# aggregate_projects_by_zone:
5959
# agg_techs: ["Central_PV"]
60-
# cf_quantile: 0.95
60+
# cf_method: "file" # Other options are "weighted_mean" and "95_quantile"

switch_model/wecc/get_inputs/post_process_steps/aggregate_candidate_projects.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
)
2929
def post_process(config):
3030
agg_techs = config["agg_techs"]
31-
cf_quantile = config["cf_quantile"]
31+
cf_method = config["cf_method"]
3232
assert type(agg_techs) == list
3333
# Don't allow hydro to be aggregated since we haven't implemented how to handle
3434
# hydro_timeseries.csv
@@ -57,7 +57,7 @@ def post_process(config):
5757

5858
# Specify the new project id (e.g. agg_Wind_CA_SGE) and save a mapping of keys to aggregate keys for later
5959
df["agg_key"] = "agg_" + df["gen_tech"] + "_" + df["gen_load_zone"]
60-
keys_to_agg = df[[key, "agg_key"]]
60+
keys_to_agg = df[[key, "agg_key", "gen_tech", "gen_load_zone"]]
6161
df = df.astype({"gen_capacity_limit_mw": float})
6262
keys_to_agg["weight"] = df["gen_capacity_limit_mw"]
6363
df[key] = df.pop("agg_key")
@@ -99,11 +99,11 @@ def agg_projects(x):
9999
df = df[should_agg]
100100
# Replace the plant id with the aggregated plant id
101101
df = df \
102-
.merge(keys_to_agg,
102+
.merge(keys_to_agg[[key, "agg_key"]],
103103
on=key,
104104
how='left',
105105
validate="many_to_one") \
106-
.drop([key, "weight"], axis=1) \
106+
.drop(key, axis=1) \
107107
.rename({"agg_key": key}, axis=1)
108108

109109
# Aggregate
@@ -141,16 +141,21 @@ def agg_costs(x):
141141
on=key,
142142
how='left',
143143
validate="many_to_one") \
144-
.drop([key, "weight"], axis=1) \
144+
.drop(key, axis=1) \
145145
.rename({"agg_key": key}, axis=1)
146146

147-
# Aggregate by group and key
147+
# Aggregate by group and timepoint
148148
dfgroup = df.groupby([key, "timepoint"], as_index=False, dropna=False, sort=False)
149-
df = dfgroup.quantile(cf_quantile)
150-
# Code to take the weighted average
151-
# df = dfgroup \
152-
# .quantile(lambda x: np.average(x["gen_max_capacity_factor"], weights=x["weight"])) \
153-
# .rename({None: "gen_max_capacity_factor"}, axis=1)
149+
if cf_method == "95_quantile":
150+
df = dfgroup.quantile(0.95)
151+
elif cf_method == "weighted_mean":
152+
# Code to take the weighted average
153+
df = dfgroup \
154+
.quantile(lambda x: np.average(x["gen_max_capacity_factor"], weights=x["weight"])) \
155+
.rename({None: "gen_max_capacity_factor"}, axis=1)
156+
else:
157+
zonal_cf = pd.read_csv("zonal_capacity_factors.csv", index_col=False)
158+
# TODO
154159
df = pd.concat([df, df_keep])
155160
df[columns].to_csv(filename, index=False)
156161

@@ -235,7 +240,7 @@ def create_capacity_factors():
235240

236241
# Add the period to each row by merging with outputs/timestamp.csv
237242
timestamps = pd.read_csv("outputs/timestamps.csv",
238-
usecols=["timestamp", "period"],
243+
usecols=["timestamp", "timepoint", "period"],
239244
index_col=False)
240245
dispatch = dispatch.merge(
241246
timestamps,
@@ -286,7 +291,7 @@ def create_capacity_factors():
286291

287292
dispatch["gen_max_capacity_factor"] = dispatch["DispatchUpperLimit"] / (
288293
dispatch["GenCapacity"] * (1 - dispatch["gen_forced_outage_rate"]))
289-
dispatch = dispatch[["gen_tech", "gen_load_zone", "timestamp", "gen_max_capacity_factor"]]
294+
dispatch = dispatch[["gen_tech", "gen_load_zone", "timestamp", "timepoint", "gen_max_capacity_factor"]]
290295
dispatch.to_csv("zonal_capacity_factors.csv", index=False)
291296

292297

0 commit comments

Comments
 (0)