def test_convert_multi_1(self): # provides timestep_mins global_conf = {} global_conf['timestep_mins'] = 30 global_conf['carbon_price'] = {2040: 25, 2030: 12.5, 2010: 6} global_conf['data_ts_length'] = 365 * 3 global_conf['time_period_yrs'] = 5 gc = globalconfig.GlobalBase() gc.set_config(global_conf) exp_pre = { 'timestep_mins': 30, 'timestep_hrs': 0.5, 'carbon_price': { 2040: 25, 2030: 12.5, 2010: 6 }, 'carbon_price_m': { 2040: 25e-6, 2030: 12.5e-6, 2010: 6e-6 }, 'data_ts_length': 365 * 3, 'time_period_yrs': 5 } self.assertTrue((exp_pre == gc.get_config())) gc.post_data_global_calcs() exp_post = exp_pre exp_post['time_scale_up_mult'] = 16 * 5 * (365.25 / 365) exp_post['variable_cost_mult'] = exp_post['time_scale_up_mult'] self.assertTrue((exp_post == gc.get_config()))
def test_missing_ts_length(self): # provides both timestep_mins and timestep_hrs. timestep_mins takes priority. global_conf = {} global_conf['timestep_mins'] = 30 global_conf['timestep_hrs'] = 1.5 global_conf['carbon_price'] = 12.5 global_conf['time_period_yrs'] = 5 gc = globalconfig.GlobalBase() gc.set_config(global_conf) exp_pre = { 'timestep_mins': 30, 'timestep_hrs': 0.5, 'carbon_price': 12.5, 'carbon_price_m': 12.5e-6, 'time_period_yrs': 5 } self.assertTrue((exp_pre == gc.get_config())) with self.assertRaises(mureilexception.ConfigException) as cm: gc.post_data_global_calcs() self.assertEqual( cm.exception.msg, 'Global calculations of time_scale_up_mult require the data_ts_length parameter to be set' )
def test_variable_cost_mult(self): # provides both timestep_mins and timestep_hrs. timestep_mins takes priority. global_conf = {} global_conf['timestep_mins'] = 30 global_conf['timestep_hrs'] = 1.5 global_conf['carbon_price'] = 12.5 global_conf['data_ts_length'] = 365 * 3 global_conf['time_period_yrs'] = 5 global_conf['variable_cost_mult'] = 100 gc = globalconfig.GlobalBase() gc.set_config(global_conf) exp_pre = { 'timestep_mins': 30, 'timestep_hrs': 0.5, 'carbon_price': 12.5, 'carbon_price_m': 12.5e-6, 'data_ts_length': 365 * 3, 'time_period_yrs': 5, 'variable_cost_mult': 100 } self.assertTrue((exp_pre == gc.get_config())) gc.post_data_global_calcs() exp_post = exp_pre exp_post['time_scale_up_mult'] = 16 * 5 * (365.25 / 365) exp_post['variable_cost_mult'] = 100 self.assertTrue((exp_post == gc.get_config()))
def test_missing_timestep_carbon(self): # provides not very much global_conf = {} global_conf['data_ts_length'] = 365 * 3 global_conf['time_period_yrs'] = 5 gc = globalconfig.GlobalBase() gc.set_config(global_conf) exp_pre = {'data_ts_length': 365 * 3, 'time_period_yrs': 5} self.assertTrue((exp_pre == gc.get_config())) gc.post_data_global_calcs() exp_post = exp_pre self.assertTrue((exp_post == gc.get_config()))
def test_reject_multi_2(self): # provides timestep_mins, but as a multi-period global_conf = {} global_conf['timestep_mins'] = {2010: 0.5, 2020: 1.0, 2030: 1.5} global_conf['carbon_price'] = {2040: 25, 2030: 12.5, 2010: 6} global_conf['data_ts_length'] = 365 * 3 global_conf['time_period_yrs'] = 5 gc = globalconfig.GlobalBase() with self.assertRaises(mureilexception.ConfigException) as cm: gc.set_config(global_conf) self.assertEqual( cm.exception.msg, 'Global timestep_mins is required to have the same value across the sim.' )
def test_missing_timeperiod_yrs(self): global_conf = {} global_conf['timestep_mins'] = 30 global_conf['carbon_price'] = 25 global_conf['data_ts_length'] = 365 * 3 gc = globalconfig.GlobalBase() gc.set_config(global_conf) exp_pre = { 'timestep_mins': 30, 'timestep_hrs': 0.5, 'carbon_price': 25, 'carbon_price_m': 25e-6, 'data_ts_length': 365 * 3 } self.assertTrue((exp_pre == gc.get_config())) gc.post_data_global_calcs() exp_post = exp_pre self.assertTrue((exp_post == gc.get_config()))