def global_to_reg_capacity_switch(regions, global_capactiy_switch, f_diffusion): """Conversion of global capacity switch installations to regional installation Arguments --------- regions : list Regions global_capactiy_switch : float Global switch f_diffusion : dict Returns ------- reg_capacity_switch : dict Regional capacity switch """ reg_capacity_switch = {} # Get all affected enduses of capacity switches switch_enduses = fuel_service_switch.get_all_enduses_of_switches( global_capactiy_switch) for region in regions: reg_capacity_switch[region] = [] for enduse in switch_enduses: # Get all capacity switches related to this enduse enduse_capacity_switches = fuel_service_switch.get_switches_of_enduse( global_capactiy_switch, enduse, crit_region=False) for switch in enduse_capacity_switches: global_capacity = switch.installed_capacity regional_capacity = global_capacity * f_diffusion[ switch.enduse][region] new_switch = read_data.CapacitySwitch( enduse=switch.enduse, technology_install=switch.technology_install, switch_yr=switch.switch_yr, installed_capacity=regional_capacity, sector=switch.sector) reg_capacity_switch[region].append(new_switch) return reg_capacity_switch
def global_to_reg_capacity_switch(regions, global_capactiy_switch, spatial_factors): """Conversion of global capacity switch instlalations to regional installation """ reg_capacity_switch = {} for reg in regions: reg_capacity_switch[reg] = [] # Get all affected enduses of capacity switches switch_enduses = set([]) for switch in global_capactiy_switch: switch_enduses.add(switch.enduse) switch_enduses = list(switch_enduses) for enduse in switch_enduses: # Get all capacity switches related to this enduse enduse_capacity_switches = [] for switch in global_capactiy_switch: if switch.enduse == enduse: enduse_capacity_switches.append(switch) test = 0 for region in regions: for switch in enduse_capacity_switches: global_capacity = switch.installed_capacity regional_capacity = global_capacity * spatial_factors[ switch.enduse][region] test += regional_capacity new_switch = read_data.CapacitySwitch( enduse=switch.enduse, technology_install=switch.technology_install, switch_yr=switch.switch_yr, installed_capacity=regional_capacity, sector=switch.sector) reg_capacity_switch[region].append(new_switch) return reg_capacity_switch
def test_capacity_switch(): """Testing """ other_enduse_mode_info = { 'diff_method': 'linear', 'sigmoid': { 'sig_midpoint': 0, 'sig_steepness': 1 } } technologies = { 'techA': read_data.TechnologyData(fueltype='oil', eff_by=1.0, eff_ey=1.0, year_eff_ey=2020, eff_achieved=1.0, diff_method='linear', market_entry=2010, tech_list='tech_heating', tech_max_share=1.0) } capacity_switches = [ read_data.CapacitySwitch(enduse='heating', technology_install='techA', switch_yr=2050, installed_capacity=200) ] result_service_switches = fuel_service_switch.capacity_switch( capacity_switches=capacity_switches, technologies=technologies, other_enduse_mode_info=other_enduse_mode_info, fuels={'heating': { 0: 100 }}, fuel_shares_enduse_by={'heating': { 0: { 'techA': 1.0 } }}, base_yr=2015) for switch in result_service_switches: if switch.technology_install == 'techA': assert switch.service_share_ey == 1.0 #--------------- technologies = { 'techA': read_data.TechnologyData(fueltype='oil', eff_by=1.0, eff_ey=1.0, year_eff_ey=2020, eff_achieved=1.0, diff_method='linear', market_entry=2010, tech_list='tech_heating', tech_max_share=1.0), 'techB': read_data.TechnologyData(fueltype='oil', eff_by=1.0, eff_ey=1.0, year_eff_ey=2020, eff_achieved=1.0, diff_method='linear', market_entry=2010, tech_list='tech_heating', tech_max_share=1.0) } capacity_switches = [ read_data.CapacitySwitch(enduse='heating', technology_install='techA', switch_yr=2050, installed_capacity=200) ] result_service_switches = fuel_service_switch.capacity_switch( capacity_switches=capacity_switches, technologies=technologies, other_enduse_mode_info=other_enduse_mode_info, fuels={'heating': { 0: 100 }}, fuel_shares_enduse_by={'heating': { 0: { 'techA': 0.5, 'techB': 0.5 } }}, base_yr=2015) for switch in result_service_switches: if switch.technology_install == 'techA': assert round(switch.service_share_ey, 3) == round( (1 / (300)) * 250, 3) if switch.technology_install == 'techB': assert round(switch.service_share_ey, 3) == round((1 / (300)) * 50, 3)
def test_create_service_switch(): """testing """ installed_capacity = 100 enduses = ['heating'] capacity_switches = [ read_data.CapacitySwitch(enduse='heating', technology_install='boiler_gas', switch_yr=2020, installed_capacity=installed_capacity) ] capacity_switch = read_data.CapacitySwitch( enduse='heating', technology_install='boiler_gas', switch_yr=2020, installed_capacity=installed_capacity) assumptions = { 'technologies': { 'boiler_oil': read_data.TechnologyData(fueltype='oil', eff_by=1.0, eff_ey=1.0, year_eff_ey=2020, eff_achieved=1.0, diff_method='linear', market_entry=2010, tech_list='tech_heating', tech_max_share=1.0), 'boiler_gas': read_data.TechnologyData(fueltype='gas', eff_by=1.0, eff_ey=1.0, year_eff_ey=2020, eff_achieved=1.0, diff_method='linear', market_entry=2010, tech_list='tech_heating', tech_max_share=1.0) }, 'other_enduse_mode_info': { 'diff_method': 'linear', 'sigmoid': { 'sig_midpoint': 0, 'sig_steepness': 1 } }, 'rs_fuel_tech_p_by': { 0: { 'boiler_gas': 0.0 }, 1: { 'boiler_oil': 1.0 } } } base_yr = 2015 fuels = {0: 0, 1: 10} #array originally sector = None results = fuel_service_switch.create_service_switch( enduses, sector, capacity_switch, capacity_switches, assumptions['technologies'], assumptions['other_enduse_mode_info'], assumptions['rs_fuel_tech_p_by'], base_yr, fuels) # Fuel share boiler_gas expected = 1 / (10 + installed_capacity) * installed_capacity for entry in results: if entry.technology_install == 'boiler_gas': assert expected == entry.service_share_ey
def test_capacity_switch(): """Testing """ technologies = { 'techA': read_data.TechnologyData(fueltype='oil', eff_by=1.0, eff_ey=1.0, year_eff_ey=2020, eff_achieved=1.0, diff_method='linear', market_entry=2010, tech_type='tech_heating', tech_max_share=1.0) } capacity_switches = { "regA": [ read_data.CapacitySwitch(enduse='heating', technology_install='techA', switch_yr=2050, installed_capacity=200) ] } narrative_timesteps = {'heating': [2050]} regions = ["regA"] result_service_switches = fuel_service_switch.capacity_switch( narrative_timesteps=narrative_timesteps, regions=regions, capacity_switches=capacity_switches, technologies=technologies, fuels={'heating': { 0: 100 }}, fuel_shares_enduse_by={'heating': { 0: { 'techA': 1.0 } }}, base_yr=2015) for region in regions: for switch in result_service_switches[region]: if switch.technology_install == 'techA': assert switch.service_share_ey == 1.0 #--------------- technologies = { 'techA': read_data.TechnologyData(fueltype='oil', eff_by=1.0, eff_ey=1.0, year_eff_ey=2020, eff_achieved=1.0, diff_method='linear', market_entry=2010, tech_type='tech_heating', tech_max_share=1.0), 'techB': read_data.TechnologyData(fueltype='oil', eff_by=1.0, eff_ey=1.0, year_eff_ey=2020, eff_achieved=1.0, diff_method='linear', market_entry=2010, tech_type='tech_heating', tech_max_share=1.0) } capacity_switches = { "regA": [ read_data.CapacitySwitch(enduse='heating', technology_install='techA', switch_yr=2050, installed_capacity=200) ] } result_service_switches = fuel_service_switch.capacity_switch( narrative_timesteps=narrative_timesteps, regions=regions, capacity_switches=capacity_switches, technologies=technologies, fuels={'heating': { 0: 100 }}, fuel_shares_enduse_by={'heating': { 0: { 'techA': 0.5, 'techB': 0.5 } }}, base_yr=2015) for region in regions: for switch in result_service_switches[region]: if switch.technology_install == 'techA': assert round(switch.service_share_ey, 3) == round( (1 / (300)) * 250, 3) if switch.technology_install == 'techB': assert round(switch.service_share_ey, 3) == round( (1 / (300)) * 50, 3)