diff --git a/hourlize/write_site_parameters.py b/hourlize/write_site_parameters.py index 6ab073f14..bfa6b18de 100644 --- a/hourlize/write_site_parameters.py +++ b/hourlize/write_site_parameters.py @@ -8,6 +8,23 @@ import reeds +def check_negative_values(df, cost_cols): + neg_vals_all = {} + for cc in cost_cols.values(): + if cc in df.columns: + neg_vals = sum(df[cc] < 0) + if neg_vals: + neg_vals_all[cc] = neg_vals + + if neg_vals_all: + message = "\n".join( + f"{cc} -> {count}" for cc, count in neg_vals_all.items() + ) + raise ValueError( + f"The following cost columns have negative values:\n{message}\n" + "Check reV data to confirm these." + ) + #%%### Fixed inputs if reeds.io.hpc: remotepath = '/kfs2/shared-projects/reeds' @@ -116,8 +133,23 @@ _diff = len(outcols) - dfland.shape[1] assert _diff == 0, len(_diff) +# drop ac suffix for cost columns +cost_cols = { + 'cost_spur_usd_per_mw_ac': 'cost_spur_usd_per_mw', + 'cost_poi_usd_per_mw_ac': 'cost_poi_usd_per_mw', + 'cost_reinforcement_usd_per_mw_ac': 'cost_reinforcement_usd_per_mw', + 'cost_total_trans_usd_per_mw_ac': 'cost_total_trans_usd_per_mw', + 'cost_export_usd_per_mw_ac': 'cost_export_usd_per_mw' +} +dfland = dfland.rename(columns=cost_cols) + +# subset to outcols dfland = dfland[list(outcols.keys())].astype(outcols) +# check for negative values +check_negative_values(dfland, cost_cols) + + #%% Write it drop = ['trans_gid', 'trans_type'] drop = [] @@ -188,6 +220,14 @@ columns_meshed = {'Zone_ReEDS':'ba'} #%% Make combined dataframe +for offshoretype in ['radial', 'meshed']: + cost_cols_sub = { + k: v for k, v in cost_cols.items() + if v not in dictin[f'offshore_{offshoretype}'].columns + } + dictin[f'offshore_{offshoretype}'] = dictin[f'offshore_{offshoretype}'].rename(columns=cost_cols_sub) + check_negative_values(dictin[f'offshore_{offshoretype}'], cost_cols) + dfwrite = dictin['offshore_radial'][columns_same].copy() for col in columns_different: for offshoretype in ['radial', 'meshed']: diff --git a/reeds/input_processing/writesupplycurves.py b/reeds/input_processing/writesupplycurves.py index e0a1d421c..1a6aa4d49 100644 --- a/reeds/input_processing/writesupplycurves.py +++ b/reeds/input_processing/writesupplycurves.py @@ -30,8 +30,6 @@ numbins_other = 5 ### Rounding precision decimals = 7 -### spur_cutoff [$/MW]: Cutoff for spur line costs; clip cost for sites with larger costs -spur_cutoff = 1e7 # %% =========================================================================== ### --- FUNCTIONS --- @@ -89,7 +87,6 @@ def agg_supplycurve( numbins_tech, bin_method='equal_cap_cut', bin_col='supply_curve_cost_per_mw', - spur_cutoff=1e7, deflate=None, ): """ @@ -129,8 +126,6 @@ def agg_supplycurve( ) ### Aggregate it dfout = dfin.groupby(index_cols).agg(aggs) - ### Clip negative costs and costs above cutoff - dfout.supply_curve_cost_per_mw = dfout.supply_curve_cost_per_mw.clip(lower=0, upper=spur_cutoff) return dfin, dfout @@ -226,7 +221,6 @@ def main( scpath=os.path.join(inputs_case,f'supplycurve_wind-{s}.csv'), inputs_case=inputs_case, numbins_tech=numbins[f'wind-{s}'], - spur_cutoff=spur_cutoff, deflate=deflate, ) @@ -328,7 +322,6 @@ def main( scpath=os.path.join(inputs_case, 'supplycurve_upv.csv'), inputs_case=inputs_case, numbins_tech=numbins['upv'], - spur_cutoff=spur_cutoff, deflate=deflate, ) @@ -411,7 +404,6 @@ def main( scpath=os.path.join(inputs_case, 'supplycurve_csp.csv'), inputs_case=inputs_case, numbins_tech=numbins['csp'], - spur_cutoff=spur_cutoff, deflate=deflate, ) @@ -492,7 +484,6 @@ def main( ), numbins_tech=numbins[s], inputs_case=inputs_case, - spur_cutoff=spur_cutoff, deflate=deflate ) spurout_list.append(