|
28 | 28 | ) |
29 | 29 | def post_process(config): |
30 | 30 | agg_techs = config["agg_techs"] |
31 | | - cf_quantile = config["cf_quantile"] |
| 31 | + cf_method = config["cf_method"] |
32 | 32 | assert type(agg_techs) == list |
33 | 33 | # Don't allow hydro to be aggregated since we haven't implemented how to handle |
34 | 34 | # hydro_timeseries.csv |
@@ -57,7 +57,7 @@ def post_process(config): |
57 | 57 |
|
58 | 58 | # Specify the new project id (e.g. agg_Wind_CA_SGE) and save a mapping of keys to aggregate keys for later |
59 | 59 | 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"]] |
61 | 61 | df = df.astype({"gen_capacity_limit_mw": float}) |
62 | 62 | keys_to_agg["weight"] = df["gen_capacity_limit_mw"] |
63 | 63 | df[key] = df.pop("agg_key") |
@@ -99,11 +99,11 @@ def agg_projects(x): |
99 | 99 | df = df[should_agg] |
100 | 100 | # Replace the plant id with the aggregated plant id |
101 | 101 | df = df \ |
102 | | - .merge(keys_to_agg, |
| 102 | + .merge(keys_to_agg[[key, "agg_key"]], |
103 | 103 | on=key, |
104 | 104 | how='left', |
105 | 105 | validate="many_to_one") \ |
106 | | - .drop([key, "weight"], axis=1) \ |
| 106 | + .drop(key, axis=1) \ |
107 | 107 | .rename({"agg_key": key}, axis=1) |
108 | 108 |
|
109 | 109 | # Aggregate |
@@ -141,16 +141,21 @@ def agg_costs(x): |
141 | 141 | on=key, |
142 | 142 | how='left', |
143 | 143 | validate="many_to_one") \ |
144 | | - .drop([key, "weight"], axis=1) \ |
| 144 | + .drop(key, axis=1) \ |
145 | 145 | .rename({"agg_key": key}, axis=1) |
146 | 146 |
|
147 | | - # Aggregate by group and key |
| 147 | + # Aggregate by group and timepoint |
148 | 148 | 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 |
154 | 159 | df = pd.concat([df, df_keep]) |
155 | 160 | df[columns].to_csv(filename, index=False) |
156 | 161 |
|
@@ -235,7 +240,7 @@ def create_capacity_factors(): |
235 | 240 |
|
236 | 241 | # Add the period to each row by merging with outputs/timestamp.csv |
237 | 242 | timestamps = pd.read_csv("outputs/timestamps.csv", |
238 | | - usecols=["timestamp", "period"], |
| 243 | + usecols=["timestamp", "timepoint", "period"], |
239 | 244 | index_col=False) |
240 | 245 | dispatch = dispatch.merge( |
241 | 246 | timestamps, |
@@ -286,7 +291,7 @@ def create_capacity_factors(): |
286 | 291 |
|
287 | 292 | dispatch["gen_max_capacity_factor"] = dispatch["DispatchUpperLimit"] / ( |
288 | 293 | 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"]] |
290 | 295 | dispatch.to_csv("zonal_capacity_factors.csv", index=False) |
291 | 296 |
|
292 | 297 |
|
|
0 commit comments