Hi, I’m Élisée from DRC. I got an issue when running scenarios code. I need help to fix it and to understand why O still getting the error. This is what I got as error :
KeyError Traceback (most recent call last)
Cell In[26], line 10
1 grid_calc, mg_pv_hybrid_calc, mg_wind_hybrid_calc, mg_hydro_calc, sa_pv_calc, sa_diesel_calc, mg_pv_hybrid_params, mg_wind_hybrid_params, mg_diesel_params, mg_interconnection, grid_reliability_option, cnse, grid_reliability = init_tech_info(grid_losses, grid_power_plants_capital_cost, grid_generation_cost, grid_discount_rate, grid_mv_line_capacity,
2 grid_MV_line_amperage_limit, grid_mv_line_cost, grid_lv_line_capacity, grid_lv_line_cost, grid_lv_line_max_length,
3 grid_service_Transf_type, grid_service_Transf_cost, grid_max_nodes_per_serv_trans,
(…) 7 sa_pv_capital_cost_4, sa_pv_capital_cost_5, min_mg_size, diesel_gen_cost, battery_cost, pv_life, diesel_life, inverter_cost,
8 inverter_life, lpsp_max, max_diesel, diesel_price)
—> 10 onsseter.df, new_lines_geojson = run_scenario(onsseter, end_year_pop, urban_ratio_end_year, start_year, end_year, yearsofanalysis, x_coordinates, y_coordinates, tier_1,
11 tier_2, tier_3, tier_4, tier_5, hv_line_capacity, hv_line_cost, hv_mv_transformer_cost, hv_mv_transformer_type, eleclimits, time_steps,
12 annual_new_grid_connections_limit, annual_grid_cap_gen_limit, num_people_per_hh_urban, num_people_per_hh_rural, urban_target_tier,
13 rural_target_tier_large, rural_target_tier_small, rural_cutoff_size, mg_diesel_params, mg_wind_hybrid_params, wind_path,
14 mg_pv_hybrid_params, pv_path, mg_hydro_calc, mg_wind_hybrid_calc, sa_pv_calc, mg_pv_hybrid_calc, min_mg_size, mg_min_grid_dist,
15 grid_generation_cost, grid_calc, sa_diesel_calc, max_grid_intensification_cost, auto_intensification, grid_mv_line_max_length,
16 mg_interconnection, grid_reliability_option, cnse, grid_reliability, prio_choice, grid_emission_factor)
18 finalize_results(onsseter, yearsofanalysis)
File ~\AppData\Local\Temp\ipykernel_15848\3540296829.py:62, in run_scenario(onsseter, end_year_pop, urban_ratio_end_year, start_year, end_year, yearsofanalysis, x_coordinates, y_coordinates, tier_1, tier_2, tier_3, tier_4, tier_5, hv_line_capacity, hv_line_cost, hv_mv_transformer_cost, hv_mv_transformer_type, eleclimits, time_steps, annual_new_grid_connections_limit, annual_grid_cap_gen_limit, num_people_per_hh_urban, num_people_per_hh_rural, urban_target_tier, rural_target_tier_large, rural_target_tier_small, rural_cutoff_size, mg_diesel_params, mg_wind_hybrid_params, wind_path, mg_pv_hybrid_params, pv_path, mg_hydro_calc, mg_wind_hybrid_calc, sa_pv_calc, mg_pv_hybrid_calc, min_mg_size, mg_min_grid_dist, grid_generation_cost, grid_calc, sa_diesel_calc, max_grid_intensification_cost, auto_intensification, grid_mv_line_max_length, mg_interconnection, grid_reliability_option, cnse, grid_reliability, prio_choice, grid_emission_factor)
58 onsseter.df[SET_MG_DIESEL_FUEL + “{}”.format(year)].fillna(mean, inplace=True)
60 print(‘Optimize Wind Hybrid Systems’, time.ctime())
61 wind_hybrid_lcoe, wind_hybrid_capacity, wind_hybrid_investment, wind_check =
—> 62 onsseter.wind_hybrids_lcoe_lookuptable(year, time_step, end_year, mg_wind_hybrid_params, wind_path=wind_path)
63 wind_hybrid_investment.fillna(0, inplace=True)
64 wind_hybrid_capacity.fillna(0, inplace=True)
File ~\Documents\Formation_Modilation_energeutique\Codes\OnSSET_Calibration_and_Scenarios\onsset\onsset.py:2578, in SettlementProcessor.wind_hybrids_lcoe_lookuptable(self, year, time_step, end_year, mg_wind_hybrid_specs, wind_path)
2570 return hybrid_lcoe, hybrid_investment, hybrid_capacity, hybrid_fuel_cost
2572 self.df[‘PotentialMG’] = np.where(
2573 ((self.df[SET_POP + “{}”.format(year)] > mg_wind_hybrid_specs[‘min_mg_connections’])
2574 & (self.df[SET_ELEC_FINAL_CODE + “{}”.format(year - time_step)] != 1) &
2575 (self.df[SET_ELEC_FINAL_CODE + “{}”.format(year - time_step)] != 2)) |
2576 (self.df[SET_ELEC_FINAL_CODE + “{}”.format(year - time_step)] == 5), 1, 0)
→ 2578 hybrid_series = self.df.apply(
2579 lambda row: local_hybrid(row[SET_WINDVEL], row[SET_MG_DIESEL_FUEL + “{}”.format(year)],
2580 row[SET_TIER], row[SET_ENERGY_PER_CELL + “{}”.format(year)])
2581 if row[‘PotentialMG’] == 1
2582 else [99, 0, 0, 0],
2583 axis=1,
2584 result_type=‘expand’)
2586 del self.df[‘PotentialMG’]
2588 hybrid_lcoe = pd.Series(hybrid_series[0])
File ~\anaconda3\envs\onsset_drc_env\Lib\site-packages\pandas\core\frame.py:12419, in DataFrame.apply(self, func, axis, raw, result_type, args, by_row, engine, engine_kwargs, **kwargs)
12405 raise ValueError(f"Unknown engine ‘{engine}’")
12407 op = frame_apply(
12408 self,
12409 func=func,
(…) 12417 kwargs=kwargs,
12418 )
12419 return op.apply().finalize(self, method=“apply”)
12420 elif hasattr(engine, “pandas_udf”):
12421 if result_type is not None:
File ~\anaconda3\envs\onsset_drc_env\Lib\site-packages\pandas\core\apply.py:1015, in FrameApply.apply(self)
1012 elif self.raw:
1013 return self.apply_raw(engine=self.engine, engine_kwargs=self.engine_kwargs)
→ 1015 return self.apply_standard()
File ~\anaconda3\envs\onsset_drc_env\Lib\site-packages\pandas\core\apply.py:1167, in FrameApply.apply_standard(self)
1165 def apply_standard(self):
1166 if self.engine == “python”:
→ 1167 results, res_index = self.apply_series_generator()
1168 else:
1169 results, res_index = self.apply_series_numba()
File ~\anaconda3\envs\onsset_drc_env\Lib\site-packages\pandas\core\apply.py:1183, in FrameApply.apply_series_generator(self)
1180 results = {}
1182 for i, v in enumerate(series_gen):
→ 1183 results[i] = self.func(v, *self.args, **self.kwargs)
1184 if isinstance(results[i], ABCSeries):
1185 # If we have a view on v, we need to make a copy because
1186 # series_generator will swap out the underlying data
1187 results[i] = results[i].copy(deep=False)
File ~\Documents\Formation_Modilation_energeutique\Codes\OnSSET_Calibration_and_Scenarios\onsset\onsset.py:2579, in SettlementProcessor.wind_hybrids_lcoe_lookuptable..(row)
2570 return hybrid_lcoe, hybrid_investment, hybrid_capacity, hybrid_fuel_cost
2572 self.df[‘PotentialMG’] = np.where(
2573 ((self.df[SET_POP + “{}”.format(year)] > mg_wind_hybrid_specs[‘min_mg_connections’])
2574 & (self.df[SET_ELEC_FINAL_CODE + “{}”.format(year - time_step)] != 1) &
2575 (self.df[SET_ELEC_FINAL_CODE + “{}”.format(year - time_step)] != 2)) |
2576 (self.df[SET_ELEC_FINAL_CODE + “{}”.format(year - time_step)] == 5), 1, 0)
2578 hybrid_series = self.df.apply(
→ 2579 lambda row: local_hybrid(row[SET_WINDVEL], row[SET_MG_DIESEL_FUEL + “{}”.format(year)],
2580 row[SET_TIER], row[SET_ENERGY_PER_CELL + “{}”.format(year)])
2581 if row[‘PotentialMG’] == 1
2582 else [99, 0, 0, 0],
2583 axis=1,
2584 result_type=‘expand’)
2586 del self.df[‘PotentialMG’]
2588 hybrid_lcoe = pd.Series(hybrid_series[0])
File ~\Documents\Formation_Modilation_energeutique\Codes\OnSSET_Calibration_and_Scenarios\onsset\onsset.py:2565, in SettlementProcessor.wind_hybrids_lcoe_lookuptable..local_hybrid(wind, diesel, tier, energy)
2562 wind = round(wind)
2563 diesel = round(diesel, 1)
→ 2565 hybrid_lcoe = wind_hybrids_lcoe[tier, wind, diesel]
2566 hybrid_investment = wind_hybrid_investment[tier, wind, diesel] #* (energy / 10000)
2567 hybrid_capacity = wind_hybrid_capacity[tier, wind, diesel] #* (energy / 10000)
KeyError: (1, 2, nan)