Esempio n. 1
0
def test_TechStock():

    from energy_demand.read_write import read_data

    base_yr = 2015
    curr_yr = 2020

    all_technologies = {'boilerA': read_data.TechnologyData()}
    all_technologies['boilerA'].fueltype_str = 'electricity'
    all_technologies['boilerA'].eff_achieved = 1.0
    all_technologies['boilerA'].diff_method = 'linear'
    all_technologies['boilerA'].eff_by = 1.0
    all_technologies['boilerA'].eff_ey = 1.0
    all_technologies['boilerA'].year_eff_ey = 2020

    stock_obj = technological_stock.TechStock(
        name="name",
        technologies=all_technologies,
        tech_list={
            'heating_non_const': [],
            'heating_const': ['boilerA']
        },
        other_enduse_mode_info={'linear'},
        base_yr=base_yr,
        curr_yr=curr_yr,
        fueltypes={'electricity': 2},
        temp_by=np.ones((365, 24)) + 10,
        temp_cy=np.ones((365, 24)) + 10,
        t_base_heating_by=15.5,
        potential_enduses=['heating'],
        t_base_heating_cy=15.5,
        enduse_technologies={'heating': ['boilerA']})

    assert stock_obj.name == "name"
    assert stock_obj.get_tech_attr('heating', 'boilerA', 'eff_by') == 1.0
def test_tech_sigmoid_paramters():
    """testing
    """

    fuel_switches = [read_data.FuelSwitch(
        enduse='heating',
        technology_install='boilerA',
        switch_yr=2050)]

    technologies = {
        'boilerA': read_data.TechnologyData(market_entry=1990),
        'boilerB': read_data.TechnologyData(market_entry=1990)}

    assump_fy = 1.0
    result = s_generate_sigmoid.tech_sigmoid_parameters(
        yr_until_switched=2050,
        switch_yr_start=2010,
        technologies=technologies,
        l_values={'boilerA': 1.0, 'boilerB': 1.0},
        s_tech_by_p={'boilerA': 0.5, 'boilerB': 0.5},
        s_tech_switched_p={'boilerA': assump_fy, 'boilerB': 0})

    y_calculated = diffusion_technologies.sigmoid_function(
        2050, 1.0, result['boilerA']['midpoint'], result['boilerA']['steepness'])

    assert y_calculated >= (assump_fy - 0.02) and y_calculated <= assump_fy + 0.02

    # ------------
    assump_fy = 1.0
    result = s_generate_sigmoid.tech_sigmoid_parameters(
        yr_until_switched=2050,
        switch_yr_start=2010,
        technologies=technologies,
        l_values={'boilerA': 1.0, 'boilerB': 1.0},
        s_tech_by_p={'boilerA': 0.5, 'boilerB': 0.5},
        s_tech_switched_p={'boilerA': assump_fy, 'boilerB': 0})

    y_calculated = diffusion_technologies.sigmoid_function(
        2050, 1.0, result['boilerA']['midpoint'], result['boilerA']['steepness'])

    assert y_calculated >= (assump_fy - 0.02) and y_calculated <= assump_fy + 0.02
def test_calc_av_heat_pump_eff_ey():
    """testing
    """
    technologies = {
        'heat_pump_ASHP_electricity': read_data.TechnologyData(),
        'heat_pump_GSHP_electricity': read_data.TechnologyData(),
        'heat_pumps_electricity': read_data.TechnologyData()
        }
    technologies['heat_pump_ASHP_electricity'].fueltype_str = 'electricity'
    technologies['heat_pump_ASHP_electricity'].eff_achieved = 1.0
    technologies['heat_pump_ASHP_electricity'].diff_method = 'linear'
    technologies['heat_pump_ASHP_electricity'].eff_by = 0.5
    technologies['heat_pump_ASHP_electricity'].eff_ey = 0.5
    technologies['heat_pump_ASHP_electricity'].year_eff_ey = 2020

    technologies['heat_pump_GSHP_electricity'].fueltype_str = 'electricity'
    technologies['heat_pump_GSHP_electricity'].eff_achieved = 1.0
    technologies['heat_pump_GSHP_electricity'].diff_method = 'linear'
    technologies['heat_pump_GSHP_electricity'].eff_by = 1.0
    technologies['heat_pump_GSHP_electricity'].eff_ey = 1.0
    technologies['heat_pump_GSHP_electricity'].year_eff_ey = 2020

    technologies['heat_pumps_electricity'].fueltype_str = 'electricity'
    technologies['heat_pumps_electricity'].eff_achieved = 1.0
    technologies['heat_pumps_electricity'].diff_method = 'linear'
    technologies['heat_pumps_electricity'].eff_by = 1.0
    technologies['heat_pumps_electricity'].eff_ey = 99999
    technologies['heat_pumps_electricity'].year_eff_ey = 2020

    heat_pump_assump = {
        'electricity': {
            'heat_pump_ASHP_electricity': 0.7,
            'heat_pump_GSHP_electricity': 0.3
            }
    }

    result = tech_related.calc_av_heat_pump_eff_ey(
        technologies,
        heat_pump_assump)

    assert result['heat_pumps_electricity'].eff_ey == 0.7 * 0.5 + 0.3 * 1.0
Esempio n. 4
0
def test_calc_fuel_tech_y():
    """Testing
    """
    technologies = {'techA': read_data.TechnologyData()}
    technologies['techA'].fueltype_str = 'gas'
    technologies['techA'].eff_achieved = 1.0
    technologies['techA'].diff_method = 'linear'
    technologies['techA'].eff_by = 0.5
    technologies['techA'].eff_ey = 0.5
    technologies['techA'].year_eff_ey = 2020
    fueltypes = {'gas': 0}

    tech_stock = technological_stock.TechStock(
        name="name",
        technologies=technologies,
        tech_list={
            'heating_non_const': [],
            'heating_const': ['techA']
        },
        other_enduse_mode_info={'linear'},
        base_yr=2015,
        curr_yr=2020,
        fueltypes=fueltypes,
        temp_by=np.ones((365, 24)) + 10,
        temp_cy=np.ones((365, 24)) + 10,
        t_base_heating_by=15.5,
        potential_enduses=['heating'],
        t_base_heating_cy=15.5,
        enduse_technologies={'heating': ['techA']})

    result = enduse_func.calc_fuel_tech_y(enduse='heating',
                                          tech_stock=tech_stock,
                                          fuel_tech_y={'techA': 100},
                                          fueltypes_nr=2,
                                          fueltypes={
                                              'heat': 1,
                                              'gas': 0
                                          },
                                          mode_constrained=False)

    assert result[1] == 100

    result = enduse_func.calc_fuel_tech_y(enduse='heating',
                                          tech_stock=tech_stock,
                                          fuel_tech_y={'techA': 100},
                                          fueltypes_nr=2,
                                          fueltypes={
                                              'heat': 1,
                                              'gas': 0
                                          },
                                          mode_constrained=True)

    assert result[0] == 100
Esempio n. 5
0
def test_service_to_fuel():
    """Testing"""
    technologies = {'techA': read_data.TechnologyData()}
    technologies['techA'].fueltype_str = 'gas'
    technologies['techA'].eff_achieved = 1.0
    technologies['techA'].diff_method = 'linear'
    technologies['techA'].eff_by = 0.5
    technologies['techA'].eff_ey = 0.5
    technologies['techA'].year_eff_ey = 2020

    fueltypes = {'gas': 0}

    tech_stock = technological_stock.TechStock(
        name="name",
        technologies=technologies,
        tech_list={
            'heating_non_const': [],
            'heating_const': ['techA']
        },
        other_enduse_mode_info={'linear'},
        base_yr=2015,
        curr_yr=2020,
        fueltypes=fueltypes,
        temp_by=np.ones((365, 24)) + 10,
        temp_cy=np.ones((365, 24)) + 10,
        t_base_heating_by=15.5,
        potential_enduses=['heating'],
        t_base_heating_cy=15.5,
        enduse_technologies={'heating': ['techA']})

    fuel_y, fuel_per_tech = enduse_func.service_to_fuel(
        "heating", {'techA': 100}, tech_stock, len(fueltypes), fueltypes, True)

    assert fuel_per_tech['techA'] == 200
    assert fuel_y == np.array([200])

    # ----

    fueltypes = {'gas': 0, 'heat': 1}

    fuel_y, fuel_per_tech = enduse_func.service_to_fuel(
        "heating", {'techA': 100}, tech_stock, len(fueltypes), fueltypes,
        False)

    assert fuel_per_tech['techA'] == 100
    assert fuel_y[1] == 100
Esempio n. 6
0
def test_service_to_fuel():
    """Testing"""
    technologies = {'techA': read_data.TechnologyData()}
    technologies['techA'].fueltype_str = 'gas'
    technologies['techA'].eff_achieved = 1.0
    technologies['techA'].diff_method = 'linear'
    technologies['techA'].eff_by = 0.5
    technologies['techA'].eff_ey = 0.5
    technologies['techA'].year_eff_ey = 2020

    fueltypes = {'electricity': 0, 'gas': 1}

    tech_stock = technological_stock.TechStock(
        name="name",
        technologies=technologies,
        base_yr=2015,
        curr_yr=2020,
        fueltypes=fueltypes,
        temp_by=np.ones((365, 24)) + 10,
        temp_cy=np.ones((365, 24)) + 10,
        t_base_heating_by=15.5,
        potential_enduses=['heating'],
        t_base_heating_cy=15.5,
        enduse_technologies={'heating': {
            'sectorA': ['techA']
        }})

    fuel_y, fuel_per_tech = enduse_func.service_to_fuel(
        "heating", 'sectorA', {'techA': 100}, tech_stock, len(fueltypes),
        fueltypes, True)

    assert fuel_per_tech['techA'] == 200
    assert fuel_y[0] == 0
    assert fuel_y[1] == 200
    # ----

    fueltypes = {'gas': 0, 'heat': 1}

    fuel_y, fuel_per_tech = enduse_func.service_to_fuel(
        "heating", 'sectorA', {'techA': 100}, tech_stock, len(fueltypes),
        fueltypes, False)

    assert fuel_per_tech['techA'] == 100
    assert fuel_y[1] == 100
Esempio n. 7
0
def test_set_same_eff_all_tech():
    """Test
    """
    eff_to_assign = 0.5

    technologies = {
        'boilerA':
        read_data.TechnologyData(fueltype='gas',
                                 eff_by=0.5,
                                 eff_ey=0.5,
                                 year_eff_ey=2015,
                                 eff_achieved=1.0,
                                 diff_method='linear',
                                 market_entry=1990,
                                 tech_max_share=1.0)
    }

    techs_eff = helpers.set_same_eff_all_tech(technologies=technologies,
                                              f_eff_achieved=0.44)

    assert techs_eff['boilerA'].eff_achieved == 0.44
def test_get_sig_diffusion():
    """
    """
    fueltype_lookup = {
        'solid_fuel': 0,
        'gas': 1,
        'electricity': 2,
        'oil': 3,
        'heat_sold': 4,
        'biomass': 5,
        'hydrogen': 6,
        'heat': 7}

    technologies = {
        'boilerA': read_data.TechnologyData(
            fueltype='gas',
            eff_by=0.5,
            eff_ey=0.5,
            year_eff_ey=2015,
            eff_achieved=1.0,
            diff_method='linear',
            market_entry=1990,
            tech_max_share=1.0),
        'boilerC': read_data.TechnologyData(
            fueltype='gas',
            eff_by=0.5,
            eff_ey=0.5,
            year_eff_ey=2015,
            eff_achieved=1.0,
            diff_method='linear',
            market_entry=1990,
            tech_max_share=0.999),
        'boilerB': read_data.TechnologyData(
            fueltype='electricity',
            eff_by=0.5,
            eff_ey=0.5,
            year_eff_ey=2015,
            eff_achieved=1.0,
            diff_method='linear',
            market_entry=1990,
            tech_max_share=1.0)}

    tech_increased_service = ['boilerA']

    regions = ['regA']

    sig_param = s_generate_sigmoid.get_l_values( 
        technologies,
        tech_increased_service,
        regions)

    assert sig_param['regA']['boilerA'] == 1.0

    # -----

    tech_increased_service = ['boilerC']

    sig_param = s_generate_sigmoid.get_l_values(
        technologies,
        tech_increased_service,
        regions)

    assert sig_param['regA']['boilerC'] == 0.999

    # -----

    tech_increased_service = ['boilerC']

    sig_param = s_generate_sigmoid.get_l_values(
        technologies,
        tech_increased_service,
        regions=regions)

    assert sig_param['regA']['boilerC'] == 0.999
def test_tech_l_sigmoid():
    """testing
    """
    fueltype_lookup = {
        'solid_fuel': 0,
        'gas': 1,
        'electricity': 2,
        'oil': 3,
        'heat_sold': 4,
        'biomass': 5,
        'hydrogen': 6,
        'heat': 7}

    technologies = {
        'boilerA': read_data.TechnologyData(
            fueltype='gas',
            eff_by=0.5,
            eff_ey=0.5,
            year_eff_ey=2015,
            eff_achieved=1.0,
            diff_method='linear',
            market_entry=1990,
            tech_max_share=1.0),

        'boilerB': read_data.TechnologyData(
            fueltype='electricity',
            eff_by=0.5,
            eff_ey=0.5,
            year_eff_ey=2015,
            eff_achieved=1.0,
            diff_method='linear',
            market_entry=1990,
            tech_max_share=1.0)
        }

    fuel_switches = [
        read_data.FuelSwitch(
            enduse='heating',
            technology_install='boilerB',
            switch_yr=2020,
            fueltype_replace=tech_related.get_fueltype_int('gas'),
            fuel_share_switched_ey=1.0
        )]

    service_fueltype_p =  {1: 1.0, 2: 0.0}
    s_tech_by_p = {
        'boilerA': 1.0,
        'boilerB': 0.0}

    fuel_tech_p_by = {
        1: {'boilerA': 1.0},
        2: {'boilerB': 1.0}}
    installed_tech = ['boilerB']

    s_tech_switched_ey = {
        'boilerA': 0.0,
        'boilerB': 1.0}

    result = s_generate_sigmoid.tech_l_sigmoid(
        s_tech_switched_ey=s_tech_switched_ey,
        enduse_fuel_switches=fuel_switches,
        technologies=technologies,
        installed_tech=installed_tech,
        s_fueltype_by_p=service_fueltype_p,
        s_tech_by_p=s_tech_by_p,
        fuel_tech_p_by=fuel_tech_p_by)

    assert result['boilerB'] == 1.0

    # -----
    technologies = {
        'boilerA': read_data.TechnologyData(
            fueltype='gas',
            eff_by=0.5,
            eff_ey=0.5,
            year_eff_ey=2015,
            eff_achieved=1.0,
            diff_method='linear',
            market_entry=1990,
            tech_max_share=1.0),

        'boilerB': read_data.TechnologyData(
            fueltype='electricity',
            eff_by=0.5,
            eff_ey=0.5,
            year_eff_ey=2015,
            eff_achieved=1.0,
            diff_method='linear',
            market_entry=1990,
            tech_max_share=0.8)
        }

    fuel_switches = [
        read_data.FuelSwitch(
            enduse='heating',
            technology_install='boilerB',
            switch_yr=2020,
            fueltype_replace=tech_related.get_fueltype_int('gas'),
            fuel_share_switched_ey=0.5 #info lower than max
        )]

    service_fueltype_p = {1: 1.0, 2: 0.0}
    s_tech_by_p = {'boilerA': 1.0, 'boilerB': 0.0}
    fuel_tech_p_by = {1: {'boilerA': 1.0}, 2: {'boilerB': 1.0}}
    installed_tech = ['boilerB']

    s_tech_switched_ey = {'boilerA': 0.5, 'boilerB': 0.5}

    result = s_generate_sigmoid.tech_l_sigmoid(
        s_tech_switched_ey=s_tech_switched_ey,
        enduse_fuel_switches=fuel_switches,
        technologies=technologies,
        installed_tech=installed_tech,
        s_fueltype_by_p=service_fueltype_p,
        s_tech_by_p=s_tech_by_p,
        fuel_tech_p_by=fuel_tech_p_by)
    assert result['boilerB'] == 0.8
def test_calc_service_fuel_switched():
    """
    """
    fueltype_lookup = {
        'solid_fuel': 0,
        'gas': 1,
        'electricity': 2,
        'oil': 3,
        'heat_sold': 4,
        'biomass': 5,
        'hydrogen': 6,
        'heat': 7}

    technologies = {
        'boilerA': read_data.TechnologyData(
            fueltype='gas',
            eff_by=0.5,
            eff_ey=0.5,
            year_eff_ey=2015,
            eff_achieved=1.0,
            diff_method='linear',
            market_entry=1990),
        'boilerB': read_data.TechnologyData(
            fueltype='electricity',
            eff_by=0.5,
            eff_ey=0.5,
            year_eff_ey=2015,
            eff_achieved=1.0,
            diff_method='linear',
            market_entry=1990),
        'boilerC': read_data.TechnologyData(
            fueltype='gas',
            eff_by=0.5,
            eff_ey=0.5,
            year_eff_ey=2015,
            eff_achieved=1.0,
            diff_method='linear',
            market_entry=1990)}

    enduse = 'heating'

    fuel_switches = [
        read_data.FuelSwitch(
            enduse='heating',
            technology_install='boilerB',
            switch_yr=2020,
            fueltype_replace=tech_related.get_fueltype_int('gas'),
            fuel_share_switched_ey=1.0
        )]

    service_fueltype_p = {1: 1.0, 2: 0.0}
    s_tech_by_p = {'boilerA': 1.0, 'boilerB': 0.0}
    fuel_tech_p_by = {1: {'boilerA': 1.0}, 2: {'boilerB': 1.0}}

    result = s_generate_sigmoid.calc_service_fuel_switched(
        fuel_switches,
        technologies,
        service_fueltype_p,
        s_tech_by_p,
        fuel_tech_p_by,
        switch_type='actual_switch')

    assert result['boilerB'] == 1.0
    assert result['boilerA'] == 0.0

    # -------

    fuel_switches = [
        read_data.FuelSwitch(
            enduse='heating',
            technology_install='boilerB',
            switch_yr=3050,
            fueltype_replace=tech_related.get_fueltype_int('gas'),
            fuel_share_switched_ey=0.5
        )]

    service_fueltype_p = {1: 1.0, 2: 0.0}
    s_tech_by_p = {'boilerA': 1.0, 'boilerB': 0.0}
    fuel_tech_p_by = {1: {'boilerA': 1.0}, 2: {'boilerB': 1.0}}

    result = s_generate_sigmoid.calc_service_fuel_switched(
        fuel_switches,
        technologies,
        service_fueltype_p,
        s_tech_by_p,
        fuel_tech_p_by,
        switch_type='actual_switch')

    assert result['boilerB'] == 0.5
    assert result['boilerA'] == 0.5

    # -------

    fuel_switches = [
        read_data.FuelSwitch(
            enduse='heating',
            technology_install='boilerB',
            switch_yr=3050,
            fueltype_replace=tech_related.get_fueltype_int('gas'),
            fuel_share_switched_ey=0.5
        )]

    service_fueltype_p = {1: 0.5, 2: 0.5}
    s_tech_by_p = {'boilerA': 0.5, 'boilerB': 0.5}
    fuel_tech_p_by = {1: {'boilerA': 1.0}, 2: {'boilerB': 1.0}}

    result = s_generate_sigmoid.calc_service_fuel_switched(
        fuel_switches,
        technologies,
        service_fueltype_p,
        s_tech_by_p,
        fuel_tech_p_by,
        switch_type='actual_switch')

    assert result['boilerB'] == 0.75
    assert result['boilerA'] == 0.25

    # -------

    fuel_switches = [
        read_data.FuelSwitch(
            enduse='heating',
            technology_install='boilerB',
            switch_yr=3050,
            fueltype_replace=tech_related.get_fueltype_int('gas'),
            fuel_share_switched_ey=0.5
        )]

    service_fueltype_p = {1: 0.5, 2: 0.5}
    s_tech_by_p = {'boilerA': 0.25, 'boilerB': 0.5, 'boilerC': 0.25}
    fuel_tech_p_by  = {1: {'boilerA': 0.5, 'boilerC': 0.5,}, 2: {'boilerB': 1.0}}

    result = s_generate_sigmoid.calc_service_fuel_switched(
        fuel_switches,
        technologies,
        service_fueltype_p,
        s_tech_by_p,
        fuel_tech_p_by,
        switch_type='actual_switch')

    assert result['boilerC'] == 0.125
    assert result['boilerB'] == 0.75
    assert result['boilerA'] == 0.125
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
Esempio n. 13
0
def generate_heat_pump_from_split(technologies, heat_pump_assump, fueltypes):
    """Define average new heat pumptechnologies 'av_heat_pump_fueltype' with
    efficiency depending on installed ratio of heat pumps

    Arguments
    ----------
    technologies : dict
        Technologies
    heat_pump_assump : dict
        The split of the ASHP and GSHP
    fueltypes : dict
        Fueltypes lookup

    Returns
    -------
    technologies : dict
        Technologies with added averaged heat pump technologies for every fueltype
    temp_dependent_tech_list : list
        List with added temperature dependent technologies

    Note
    ----
    - Market Entry of different technologies must be the same year!
      (the lowest is selected if different years)
    - Diff method is linear
    """
    temp_dependent_tech_list = []
    heat_pumps = []

    # Calculate average efficiency of heat pump depending on installed ratio
    for fueltype in heat_pump_assump:
        av_eff_hps_by, av_eff_hps_ey, eff_achieved_av, market_entry_lowest = 0, 0, 0, 2200
        av_year_eff_ey = 0

        for heat_pump_type in heat_pump_assump[fueltype]:
            share_heat_pump = heat_pump_assump[fueltype][heat_pump_type]

            eff_heat_pump_by = technologies[heat_pump_type].eff_by
            eff_heat_pump_ey = technologies[heat_pump_type].eff_ey
            eff_achieved = technologies[heat_pump_type].eff_achieved
            market_entry = technologies[heat_pump_type].market_entry
            tech_max_share = technologies[heat_pump_type].tech_max_share

            av_year_eff_ey += technologies[heat_pump_type].year_eff_ey

            # Calc average values
            av_eff_hps_by += share_heat_pump * eff_heat_pump_by
            av_eff_hps_ey += share_heat_pump * eff_heat_pump_ey
            eff_achieved_av += share_heat_pump * eff_achieved

            if market_entry < market_entry_lowest:
                market_entry_lowest = market_entry

        # Calculate average year until efficiency improvements are implemented
        av_year_eff_ey = av_year_eff_ey / len(heat_pump_assump[fueltype])

        # Add average 'av_heat_pumps' to technology dict
        name_av_hp = "heat_pumps_{}".format(fueltype)

        # Add technology to temperature dependent technology list
        temp_dependent_tech_list.append(name_av_hp)

        # Add new averaged technology
        technologies[name_av_hp] = read_data.TechnologyData(
            fueltype=fueltype,
            eff_by=av_eff_hps_by,
            eff_ey=av_eff_hps_ey,
            year_eff_ey=av_year_eff_ey,
            eff_achieved=eff_achieved_av,
            diff_method='linear',
            market_entry=market_entry_lowest,
            tech_list='heating_non_const',
            tech_max_share=tech_max_share,
            fueltypes=fueltypes)

        heat_pumps.append(name_av_hp)

    return technologies, temp_dependent_tech_list, heat_pumps
Esempio n. 14
0
def test_fuel_to_service():
    """
    """
    enduse = 'heating'
    sector = 'sectorA'
    fuel_y = {0: 2000}

    fuel_tech_p_by = {0: {'techA': 1.0}}
    technologies = {'techA': read_data.TechnologyData()}
    technologies['techA'].fueltype_str = 'gas'
    technologies['techA'].eff_achieved = 1.0
    technologies['techA'].diff_method = 'linear'
    technologies['techA'].eff_by = 0.5
    technologies['techA'].eff_ey = 0.5
    technologies['techA'].year_eff_ey = 2020

    fueltypes = {'electricity': 0, 'gas': 1}  #, 'heat': 1}

    tech_stock = technological_stock.TechStock(
        name="name",
        technologies=technologies,
        base_yr=2015,
        curr_yr=2020,
        fueltypes=fueltypes,
        temp_by=np.ones((365, 24)) + 10,
        temp_cy=np.ones((365, 24)) + 10,
        t_base_heating_by=15.5,
        potential_enduses=['heating'],
        t_base_heating_cy=15.5,
        enduse_technologies={'heating': {
            'sectorA': ['techA']
        }})

    tot_s_y, service_tech = enduse_func.fuel_to_service(
        enduse=enduse,
        sector=sector,
        fuel_y=fuel_y,
        fuel_tech_p_by=fuel_tech_p_by,
        tech_stock=tech_stock,
        fueltypes=fueltypes,
        mode_constrained=True)

    assert service_tech['techA'] == 1000

    # ---
    fuel_y = {0: 0, 1: 2000}
    fuel_tech_p_by = {0: {}, 1: {'techA': 1.0}}
    fueltypes = {'gas': 0, 'heat': 1}

    tech_stock = technological_stock.TechStock(
        name="name",
        technologies=technologies,
        base_yr=2015,
        curr_yr=2020,
        fueltypes=fueltypes,
        temp_by=np.ones((365, 24)) + 10,
        temp_cy=np.ones((365, 24)) + 10,
        t_base_heating_by=15.5,
        potential_enduses=['heating'],
        t_base_heating_cy=15.5,
        enduse_technologies={'heating': {
            'sectorA': ['techA']
        }})

    tot_s_y, service_tech = enduse_func.fuel_to_service(
        enduse=enduse,
        sector=sector,
        fuel_y=fuel_y,
        fuel_tech_p_by=fuel_tech_p_by,
        tech_stock=tech_stock,
        fueltypes=fueltypes,
        mode_constrained=False)  #Difference

    assert service_tech['techA'] == 2000
Esempio n. 15
0
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)
def test_get_s_fueltype_tech():
    """
    """
    tech_list = {
        'heating_non_const': ['heat_p'],
        'heating_const': ['boilerA'],
        'storage_heating_electricity': ['boilerC'],
        'secondary_heating_electricity': []
    }

    fueltypes = {'gas': 0}

    technologies = {
        'boilerA':
        read_data.TechnologyData(fueltype='gas',
                                 eff_by=0.5,
                                 eff_ey=0.5,
                                 year_eff_ey=2015,
                                 eff_achieved=1.0,
                                 diff_method='linear',
                                 market_entry=1990,
                                 tech_max_share=1.0,
                                 fueltypes=fueltypes)
    }

    fuel_p_tech_by = {'heating': {0: {'boilerA': 1.0}}}

    other_enduse_mode_info = {
        'diff_method': 'linear',
        'sigmoid': {
            'sig_midpoint': 0,
            'sig_steepness': 1
        }
    }

    s_tech_by_p, s_fueltype_tech_by_p, s_fueltype_by_p = s_fuel_to_service.get_s_fueltype_tech(
        enduses=['heating'],
        tech_list=tech_list,
        fueltypes=fueltypes,
        fuel_p_tech_by=fuel_p_tech_by,
        fuels={'heating': np.array([100])},  # 0 == gas
        technologies=technologies)

    assert s_tech_by_p['heating']['boilerA'] == 1.0
    assert s_fueltype_tech_by_p['heating'][0]['boilerA'] == 1.0
    assert s_fueltype_by_p['heating'][0] == 1.0

    # -------------------------------------
    technologies = {
        'boilerA':
        read_data.TechnologyData(fueltype='gas',
                                 eff_by=0.5,
                                 eff_ey=0.5,
                                 year_eff_ey=2015,
                                 eff_achieved=1.0,
                                 diff_method='linear',
                                 market_entry=1990,
                                 tech_max_share=1.0,
                                 fueltypes=fueltypes),
        'boilerB':
        read_data.TechnologyData(fueltype='gas',
                                 eff_by=0.5,
                                 eff_ey=0.5,
                                 year_eff_ey=2015,
                                 eff_achieved=1.0,
                                 diff_method='linear',
                                 market_entry=1990,
                                 tech_max_share=1.0,
                                 fueltypes=fueltypes)
    }

    fuel_p_tech_by = {'heating': {0: {'boilerA': 0.5, 'boilerB': 0.5}}}

    other_enduse_mode_info = {
        'diff_method': 'linear',
        'sigmoid': {
            'sig_midpoint': 0,
            'sig_steepness': 1
        }
    }

    s_tech_by_p, s_fueltype_tech_by_p, s_fueltype_by_p = s_fuel_to_service.get_s_fueltype_tech(
        enduses=['heating'],
        tech_list=tech_list,
        fueltypes=fueltypes,
        fuel_p_tech_by=fuel_p_tech_by,
        fuels={'heating': np.array([100])},  # 0 == gas
        technologies=technologies)

    assert s_tech_by_p['heating']['boilerA'] == 0.5
    assert s_tech_by_p['heating']['boilerB'] == 0.5
    assert s_fueltype_tech_by_p['heating'][0]['boilerA'] == 0.5
    assert s_fueltype_tech_by_p['heating'][0]['boilerB'] == 0.5
    assert s_fueltype_by_p['heating'][0] == 1.0

    # -------------------------------------

    tech_list = {
        'heating_non_const': ['heat_p'],
        'heating_const': ['boilerA', 'boilerB'],
        'storage_heating_electricity': [],
        'secondary_heating_electricity': []
    }

    fueltypes = {'gas': 0, 'electricity': 1}

    technologies = {
        'boilerA':
        read_data.TechnologyData(fueltype='gas',
                                 eff_by=0.5,
                                 eff_ey=0.5,
                                 year_eff_ey=2015,
                                 eff_achieved=1.0,
                                 diff_method='linear',
                                 market_entry=1990,
                                 tech_max_share=1.0,
                                 fueltypes=fueltypes),
        'boilerB':
        read_data.TechnologyData(fueltype='electricity',
                                 eff_by=0.5,
                                 eff_ey=0.5,
                                 year_eff_ey=2015,
                                 eff_achieved=1.0,
                                 diff_method='linear',
                                 market_entry=1990,
                                 tech_max_share=1.0,
                                 fueltypes=fueltypes)
    }

    fuel_p_tech_by = {'heating': {0: {'boilerA': 1.0}, 1: {'boilerB': 1.0}}}

    other_enduse_mode_info = {
        'diff_method': 'linear',
        'sigmoid': {
            'sig_midpoint': 0,
            'sig_steepness': 1
        }
    }

    s_tech_by_p, s_fueltype_tech_by_p, s_fueltype_by_p = s_fuel_to_service.get_s_fueltype_tech(
        enduses=['heating'],
        tech_list=tech_list,
        fueltypes=fueltypes,
        fuel_p_tech_by=fuel_p_tech_by,
        fuels={'heating': np.array([100, 300])},  # tripple elec than gas
        technologies=technologies)

    assert s_tech_by_p['heating']['boilerA'] == 0.25
    assert s_tech_by_p['heating']['boilerB'] == 0.75
    assert s_fueltype_tech_by_p['heating'][0]['boilerA'] == 1.0
    assert s_fueltype_tech_by_p['heating'][1]['boilerB'] == 1.0
    assert s_fueltype_by_p['heating'][0] == 0.25
    assert s_fueltype_by_p['heating'][1] == 0.75
Esempio n. 17
0
def insert_placholder_techs(technologies, tech_p_by, specified_tech_enduse_by):
    """If no technology is defined for a fueltype in an enduse add
    a dumppy technology. This is necessary because the model needs
    a technology for every fueltype in an enduse.

    Arguments
    ----------
    technologies : dict
        Technologies
    tech_p_by : dict
        Fuel assignement of technologies in base year
    specified_tech_enduse_by : dict
        Technologies per enduse

    Returns
    -------
    tech_p_by : dict
        Fuel assignement of technologies in base year
    specified_tech_enduse_by : dict
        Technologies per enduse
    technologies : dict
        Technologies
    """
    out_tech_p_by = {}
    for enduse, enduse_fueltypes_techs in tech_p_by.items():
        out_tech_p_by[enduse] = {}
        if list(enduse_fueltypes_techs.keys())[0] != 0:

            for sector in enduse_fueltypes_techs:
                out_tech_p_by[enduse][sector] = {}

                # Test if a technology is defined in any fueltype
                c_tech_defined = test_if_tech_defined(
                    enduse_fueltypes_techs[sector])

                if not c_tech_defined:
                    for fueltype in enduse_fueltypes_techs[sector]:
                        if enduse_fueltypes_techs[sector][fueltype] == {}:

                            # Assign total fuel demand to dummy technology
                            out_tech_p_by[enduse][sector][fueltype] = {
                                "placeholder_tech": 1.0
                            }

                    specified_tech_enduse_by[enduse][sector].append(
                        "placeholder_tech")
                else:
                    out_tech_p_by[enduse][sector] = enduse_fueltypes_techs[
                        sector]
        else:
            # If no sector is defined, add a dummy None setor
            dummy_sector = None

            out_tech_p_by[enduse][dummy_sector] = {}
            c_tech_defined = test_if_tech_defined(enduse_fueltypes_techs)
            if not c_tech_defined:
                for fueltype in enduse_fueltypes_techs:
                    if enduse_fueltypes_techs[fueltype] == {}:
                        out_tech_p_by[enduse][dummy_sector][fueltype] = {
                            "placeholder_tech": 1.0
                        }

                specified_tech_enduse_by[enduse][dummy_sector].append(
                    "placeholder_tech")
            else:
                out_tech_p_by[enduse][dummy_sector] = enduse_fueltypes_techs

    # Insert placeholder technology
    technologies['placeholder_tech'] = read_data.TechnologyData(
        eff_by=1,
        eff_ey=1,
        year_eff_ey=2100,
        eff_achieved=1,
        diff_method='linear',
        tech_type='placeholder_tech')

    return out_tech_p_by, specified_tech_enduse_by, technologies
Esempio n. 18
0
def insert_placholder_techs(technologies,
                            tech_p_by,
                            all_specified_tech_enduse_by,
                            sector_crit=False):
    """If no technology is defined for a fueltype in an enduse add
    a dumppy technology. This is necessary because the model needs
    a technology for every fueltype in an enduse.

    Arguments
    ----------
    technologies : dict
        Technologies
    tech_p_by : dict
        Fuel assignement of technologies in base year
    all_specified_tech_enduse_by : dict
        Technologies per enduse

    Returns
    -------
    tech_p_by : dict
        Fuel assignement of technologies in base year
    all_specified_tech_enduse_by : dict
        Technologies per enduse
    technologies : dict
        Technologies
    """
    if sector_crit is True:

        for end_use, enduse_fueltypes_techs in tech_p_by.items():
            for sector in enduse_fueltypes_techs:

                # Test if a technology is defined in any fueltype
                c_tech_defined = test_if_tech_defined(
                    enduse_fueltypes_techs[sector])

                if not c_tech_defined:
                    for fueltype in enduse_fueltypes_techs[sector]:
                        if enduse_fueltypes_techs[sector][fueltype] == {}:

                            # Assign total fuel demand to dummy technology
                            tech_p_by[end_use][sector][fueltype] = {
                                "placeholder_tech": 1.0
                            }

                    all_specified_tech_enduse_by[end_use].append(
                        "placeholder_tech")
                else:
                    pass
    else:
        for end_use, enduse_fueltypes_techs in tech_p_by.items():

            # Test if a technology is defined in any fueltype
            c_tech_defined = test_if_tech_defined(enduse_fueltypes_techs)

            if not c_tech_defined:
                for fueltype in enduse_fueltypes_techs:
                    if enduse_fueltypes_techs[fueltype] == {}:
                        # Assign total fuel demand to dummy technology
                        tech_p_by[end_use][fueltype] = {
                            "placeholder_tech": 1.0
                        }

                all_specified_tech_enduse_by[end_use].append(
                    "placeholder_tech")
            else:
                pass

    # Insert placeholder technology
    technologies['placeholder_tech'] = read_data.TechnologyData(
        eff_by=1,
        eff_ey=1,
        year_eff_ey=2100,
        eff_achieved=1,
        diff_method='linear')

    return tech_p_by, all_specified_tech_enduse_by, technologies
Esempio n. 19
0
def test_calc_fuel_tech_yh():
    """Testing
    """
    fueltypes = {'gas': 0, 'heat': 1}

    technologies = {'techA': read_data.TechnologyData()}
    technologies['techA'].fueltype_str = 'gas'
    technologies['techA'].eff_achieved = 1.0
    technologies['techA'].diff_method = 'linear'
    technologies['techA'].eff_by = 0.5
    technologies['techA'].eff_ey = 0.5
    technologies['techA'].year_eff_ey = 2020
    '''tech_stock = technological_stock.TechStock(
        name="name",
        technologies=technologies,
        base_yr=2015,
        curr_yr=2020,
        fueltypes=fueltypes,
        temp_by=np.ones((365, 24)) + 10,
        temp_cy=np.ones((365, 24)) + 10,
        t_base_heating_by=15.5,
        potential_enduses=['heating'],
        t_base_heating_cy=15.5,
        enduse_technologies={'heating': ['techA']})'''

    lp_stock_obj = load_profile.LoadProfileStock("test_stock")

    _a = np.zeros((365, 24))
    _b = np.array(range(365))
    shape_yh = _a + _b[:, np.newaxis]
    shape_yh = shape_yh / float(np.sum(range(365)) * 24)
    model_yeardays = list(range(365))

    lp_stock_obj.add_lp(unique_identifier="A123",
                        technologies=['techA'],
                        enduses=['heating'],
                        shape_yd=np.full((365, 24), 1 / 365),
                        shape_yh=shape_yh,
                        sectors=['sectorA'],
                        shape_y_dh=np.full((365), 1 / 365),
                        model_yeardays=model_yeardays)

    fuel = 200
    results = enduse_func.calc_fuel_tech_yh(enduse='heating',
                                            sector='sectorA',
                                            enduse_techs=['techA'],
                                            fuel_tech_y={'techA': fuel},
                                            load_profiles=lp_stock_obj,
                                            fueltypes_nr=2,
                                            fueltypes=fueltypes,
                                            mode_constrained=False)

    assert results[1][3][0] == 3.0 / float(np.sum(range(365)) * 24) * 200

    # ---
    results = enduse_func.calc_fuel_tech_yh(enduse='heating',
                                            sector='sectorA',
                                            enduse_techs=['techA'],
                                            fuel_tech_y={'techA': fuel},
                                            load_profiles=lp_stock_obj,
                                            fueltypes_nr=2,
                                            fueltypes=fueltypes,
                                            mode_constrained=True)

    assert results['techA'][3][0] == 3.0 / float(np.sum(range(365)) * 24) * 200