Fix bug when no # of wind/pv rows specified in settings
If a region didn't have a specified number of wind/pv rows in the settings
the code would throw an KeyError.
@@ -565,25 +565,54 @@ def atb_new_generators(results, atb_costs, atb_hr, settings):
def add_extra_wind_solar_rows(df, region, settings):
+ """Add additional rows of wind and solar generation to the new generation options
+ in each region. Each row has a specific CF and available capacity.
+
+ Parameters
+ ----------
+ df : DataFrame
+ New generation technologies for a single model region
+ region : str
+ Name of the model region. Used to look up how many total wind/solar rows are
+ needed from the settings file.
+ settings : dict
+ User-defined parameters from a settings file
+
+ Returns
+ -------
+ [type]
+ [description]
+ """
+ # Need to add offshore wind to this?
+
+ try:
wind_bins = settings["new_wind_solar_regional_bins"]["LandbasedWind"][region]
extra_wind_bins = wind_bins - 1
+
+ for i in range(extra_wind_bins):
+ row_iloc = np.argwhere(
+ df.technology.str.contains("LandbasedWind")
+ ).flatten()[-1]
+ df = pd.concat(
+ [df.iloc[:row_iloc], df.iloc[[row_iloc]], df.iloc[row_iloc:]]
+ )
+
+ except KeyError:
+ logger.info(f"Not adding any extra onshore wind rows to {region}")
+ try:
solar_bins = settings["new_wind_solar_regional_bins"]["UtilityPV"][region]
extra_solar_bins = solar_bins - 1
- for i in range(extra_wind_bins):
- row_iloc = np.argwhere(df.technology.str.contains("LandbasedWind")).flatten()[
+ for i in range(extra_solar_bins):
+ row_iloc = np.argwhere(df.technology.str.contains("UtilityPV")).flatten()[
-1
]
- df = pd.concat([df.iloc[:row_iloc], df.iloc[[row_iloc]], df.iloc[row_iloc:]])
-
- # if len(df.query("technology.str.contains('Wind')")) != wind_bins:
- # wind_rows = len(df.query("technology.str.contains('LandbasedWind')"))
- # print(df)
- # raise ValueError(f"Number of wind rows in {region} is {wind_rows}, need {wind_bins}")
+ df = pd.concat(
+ [df.iloc[:row_iloc], df.iloc[[row_iloc]], df.iloc[row_iloc:]]
+ )
- for i in range(extra_solar_bins):
- row_iloc = np.argwhere(df.technology.str.contains("UtilityPV")).flatten()[-1]
- df = pd.concat([df.iloc[:row_iloc], df.iloc[[row_iloc]], df.iloc[row_iloc:]])
+ except KeyError:
+ logger.info(f"Not adding any extra utility PV rows to {region}")
df = df.reset_index(drop=True)
