Exemple #1
0
def test_autocomplete_switches():
    """testing"""
    service_switches =  [read_data.ServiceSwitch(
        enduse='heating',
        technology_install='techA',
        switch_yr=2050,
        service_share_ey=0.6)]
    defined_temporal_narrative_points = {'heating': [2050]}

    enduses = {'submodelA': ['heating']}
    sectors = {'submodelA': [None]}

    out = fuel_service_switch.autocomplete_switches(
        service_switches=service_switches,
        specified_tech_enduse_by={'heating': {None: ['techA', 'techB', 'techC']}},
        s_tech_by_p={None: {'heating': {'techA': 0.2, 'techB': 0.4, 'techC': 0.4}}},
        crit_all_the_same=True,
        enduses=enduses,
        sectors=sectors,
        regions=['regA'],
        f_diffusion=False,
        techs_affected_spatial_f=False,
        service_switches_from_capacity={'regA':[]})

    assert out[None]['heating']['regA'][2050]['techA'] == 0.6
    assert out[None]['heating']['regA'][2050]['techB'] == 0.2
    assert out[None]['heating']['regA'][2050]['techC'] == 0.2

    # ---
    service_switches = [read_data.ServiceSwitch(
        enduse='heating',
        technology_install='techA',
        switch_yr=2050,
        service_share_ey=0.6)]

    out = fuel_service_switch.autocomplete_switches(
        service_switches=service_switches,
        specified_tech_enduse_by={'heating': {None: ['techA', 'techB', 'techC']}},
        s_tech_by_p= {None: {'heating': {'techA': 0.2, 'techB': 0.4, 'techC': 0.4}}},
        crit_all_the_same=True,
        enduses=enduses,
        sectors=sectors,
        regions=['regA'],
        f_diffusion={'heating':{'regA':1.0, 'regB': 1.0}},
        techs_affected_spatial_f=['techA'],
        service_switches_from_capacity={'regA': [], 'regB': []})

    assert out[None]['heating']['regA'][2050]['techA'] == 0.6
    assert out[None]['heating']['regA'][2050]['techB'] == 0.2
    assert out[None]['heating']['regA'][2050]['techC'] == 0.2
Exemple #2
0
def autocomplete_switches():
    """Testing
    """
    service_switches = [read_data.ServiceSwitch(
        'heating',
        'techA',
        0.5,
        2020)]

    specified_tech_enduse_by = {'heating': ['techA', 'techB']}
    s_tech_by_p = {'heating': {'techA': 0.8, 'techB': 0.2}}

    service_switches = fuel_service_switch.autocomplete_switches(
        service_switches=service_switches,
        specified_tech_enduse_by=specified_tech_enduse_by,
        s_tech_by_p=s_tech_by_p)
    
    for switch in service_switches:
        if switch.technology_install == 'techA':
            assert switch.service_share_ey == 0.5
        
        if switch.technology_install == 'techB':
            assert switch.service_share_ey == 0.5
    #---

    service_switches = [read_data.ServiceSwitch(
        'heating',
        'techA',
        0.3,
        2020)]

    specified_tech_enduse_by = {'heating': ['techA', 'techB', 'techC']}
    s_tech_by_p = {'heating': {'techA': 0.6, 'techB': 0.2,'techC': 0.1}}

    service_switches = fuel_service_switch.autocomplete_switches(
        service_switches=service_switches,
        specified_tech_enduse_by=specified_tech_enduse_by,
        s_tech_by_p=s_tech_by_p)

    for switch in service_switches:
        if switch.technology_install == 'techA':
            assert switch.service_share_ey == 0.3
        if switch.technology_install == 'techB':
            assert switch.service_share_ey == 0.7 * (2.0 / 3.0)
        if switch.technology_install == 'techC':
            assert switch.service_share_ey == 0.7 * (1.0 / 3.0)
def test_autocomplete_switches():
    """testing"""
    service_switches = [
        read_data.ServiceSwitch(enduse='heating',
                                technology_install='techA',
                                switch_yr=2050,
                                service_share_ey=0.6)
    ]

    out_1, out_2 = fuel_service_switch.autocomplete_switches(
        service_switches=service_switches,
        specified_tech_enduse_by={'heating': ['techA', 'techB', 'techC']},
        s_tech_by_p={'heating': {
            'techA': 0.2,
            'techB': 0.4,
            'techC': 0.4
        }},
        sector=False,
        spatial_exliclit_diffusion=False,
        regions=False,
        f_diffusion=False,
        techs_affected_spatial_f=False,
        service_switches_from_capacity=[])

    for switch in out_2:
        if switch.technology_install == 'techA':
            assert switch.service_share_ey == 0.6
        if switch.technology_install == 'techB':
            assert switch.service_share_ey == 0.2
        if switch.technology_install == 'techC':
            assert switch.service_share_ey == 0.2

    # ---
    service_switches = [
        read_data.ServiceSwitch(enduse='heating',
                                technology_install='techA',
                                switch_yr=2050,
                                service_share_ey=0.6)
    ]

    out_1, out_2 = fuel_service_switch.autocomplete_switches(
        service_switches=service_switches,
        specified_tech_enduse_by={'heating': ['techA', 'techB', 'techC']},
        s_tech_by_p={'heating': {
            'techA': 0.2,
            'techB': 0.4,
            'techC': 0.4
        }},
        sector=False,
        spatial_exliclit_diffusion=True,
        regions=['regA', 'regB'],
        f_diffusion={'heating': {
            'regA': 1.0,
            'regB': 1.0
        }},
        techs_affected_spatial_f=['techA'],
        service_switches_from_capacity={
            'regA': [],
            'regB': []
        })

    for reg in out_2:
        for switch in out_2[reg]:
            if switch.technology_install == 'techA':
                assert switch.service_share_ey == 0.6
            if switch.technology_install == 'techB':
                assert switch.service_share_ey == 0.2
            if switch.technology_install == 'techC':
                assert switch.service_share_ey == 0.2
Exemple #4
0
def switch_calculations(sim_yrs, data, f_reg, f_reg_norm, f_reg_norm_abs,
                        crit_all_the_same, service_switches, fuel_switches,
                        capacity_switches):
    """This function creates sigmoid diffusion values based
    on defined switches

    Arguments
    ----------
    sim_yrs : list
        Simulated years
    data : dict
        Data container
    f_reg, f_reg_norm, f_reg_norm_abs : str
        Different spatial diffusion values
    crit_all_the_same : dict
        Criteria whether the diffusion is spatial explicit or not

    Returns
    -------
    annual_tech_diff_params : dict
        All values for every simluation year for every technology
    """
    # ---------------------------------------
    # Convert base year fuel input assumptions to energy service for every submodule
    # ---------------------------------------
    s_tech_by_p = {}
    s_fueltype_by_p = {}
    for submodel in data['assumptions'].submodels_names:
        for sector in data['sectors'][submodel]:
            s_tech_by_p[sector], s_fueltype_by_p[
                sector] = s_fuel_to_service.get_s_fueltype_tech(
                    data['enduses'][submodel],
                    data['assumptions'].fuel_tech_p_by,
                    data['fuels'][submodel], data['assumptions'].technologies,
                    sector)

    # Get all defined narrative timesteps of all switch types
    narrative_timesteps = {}
    narrative_timesteps.update(get_all_narrative_timesteps(service_switches))
    narrative_timesteps.update(get_all_narrative_timesteps(fuel_switches))
    narrative_timesteps.update(get_all_narrative_timesteps(capacity_switches))
    # ========================================================================================
    # Capacity switches
    #
    # Calculate service shares considering potential capacity installations
    # ========================================================================================

    # Convert globally defined switches to regional switches
    f_diffusion = f_reg_norm_abs  # Select diffusion value

    reg_capacity_switches = global_to_reg_capacity_switch(
        data['regions'], capacity_switches, f_diffusion=f_diffusion)

    service_switches_incl_cap = fuel_service_switch.capacity_switch(
        narrative_timesteps, data['regions'], reg_capacity_switches,
        data['assumptions'].technologies, data['fuels']['aggr_sector_fuels'],
        data['assumptions'].fuel_tech_p_by, data['assumptions'].base_yr)

    # ======================================================================================
    # Service switches
    #
    # Get service shares of technologies for future year by considering
    # service switches. Potential capacity switches are used as inputs.
    #
    # Autocomplement defined service switches with technologies not
    # explicitly specified in switch on a global scale and distribute spatially
    # in oder that all technologies match up to 100% service share
    # ========================================================================================

    # Select spatial diffusion
    f_diffusion = f_reg_norm

    share_s_tech_ey_p = fuel_service_switch.autocomplete_switches(
        service_switches,
        data['assumptions'].specified_tech_enduse_by,
        s_tech_by_p,
        data['enduses'],
        data['sectors'],
        crit_all_the_same=crit_all_the_same,
        regions=data['regions'],
        f_diffusion=f_diffusion,
        techs_affected_spatial_f=data['assumptions'].techs_affected_spatial_f,
        service_switches_from_capacity=service_switches_incl_cap)

    # ========================================================================================
    # Fuel switches
    #
    # Calculate sigmoid diffusion considering fuel switches and service switches.
    # As inputs, service (and thus also capacity switches) are used
    # ========================================================================================
    diffusion_param_tech = defaultdict(dict)

    for submodel_name in data['assumptions'].submodels_names:
        for enduse in data['enduses'][submodel_name]:
            for sector in data['sectors'][submodel_name]:

                diffusion_param_tech[enduse][
                    sector] = sig_param_calc_incl_fuel_switch(
                        narrative_timesteps,
                        data['assumptions'].base_yr,
                        data['assumptions'].crit_switch_happening,
                        data['assumptions'].technologies,
                        enduse=enduse,
                        sector=sector,
                        fuel_switches=fuel_switches,
                        s_tech_by_p=s_tech_by_p[sector][enduse],
                        s_fueltype_by_p=s_fueltype_by_p[sector][enduse],
                        share_s_tech_ey_p=share_s_tech_ey_p,
                        fuel_tech_p_by=data['assumptions'].
                        fuel_tech_p_by[enduse][sector],
                        regions=data['regions'],
                        crit_all_the_same=crit_all_the_same)

    # ------------------
    # Calculate annual values based on calculated parameters for every simulation year
    # ------------------
    annual_tech_diff_params = s_scenario_param.calc_annual_switch_params(
        sim_yrs,
        data['regions'],
        dict(diffusion_param_tech),
        base_yr=data['assumptions'].base_yr,
        s_tech_by_p=s_tech_by_p)

    # ------------------------------------------------------
    # Test whether the calculated service shares sum up to 1
    # and if not, then distribute not assigned demand according to
    # base year distribution
    # Can happen because multiple sigmoid for different technologies
    # ------------------------------------------------------
    for region in annual_tech_diff_params:
        for enduse in annual_tech_diff_params[region]:
            for sector in annual_tech_diff_params[region][enduse]:

                for year in sim_yrs:
                    if annual_tech_diff_params[region][enduse][sector] != []:
                        assigned_service_p = 0
                        for tech in annual_tech_diff_params[region][enduse][
                                sector]:
                            assigned_service_p += annual_tech_diff_params[
                                region][enduse][sector][tech][year]

                        # Distribute if not sum up to one according to base year distribution
                        if round(assigned_service_p, 2) != 1:
                            total_not_assined = 1 - assigned_service_p

                            for tech in annual_tech_diff_params[region][
                                    enduse][sector]:
                                # Fraction in base year
                                p_by = annual_tech_diff_params[region][enduse][
                                    sector][tech][data['assumptions'].base_yr]
                                tech_to_add_not_assigned = total_not_assined * p_by
                                annual_tech_diff_params[region][enduse][
                                    sector][tech][
                                        year] += tech_to_add_not_assigned

                        assigned_service_p = 0
                        for tech in annual_tech_diff_params[region][enduse][
                                sector]:
                            assigned_service_p += annual_tech_diff_params[
                                region][enduse][sector][tech][year]

                        assert round(assigned_service_p, 2) == 1

    return annual_tech_diff_params
Exemple #5
0
def scenario_initalisation(path_data_ed, data=False):
    """Scripts which need to be run for every different scenario.
    Only needs to be executed once for each scenario (not for every
    simulation year).

    The following calculations are performed:

        I.      Disaggregation of fuel for every region
        II.     Switches calculations
        III.    Spatial explicit diffusion modelling

    Arguments
    ----------
    path_data_ed : str
        Path to the energy demand data folder
    data : dict
        Data container

    Info
    -----
        # Non spatiall differentiated modelling of
    # technology diffusion (same diffusion pattern for
    # the whole UK) or spatially differentiated (every region)
    """
    logging.info("... Start initialisation scripts")

    init_cont = defaultdict(dict)
    fuel_disagg = {}

    logger_setup.set_up_logger(os.path.join(path_data_ed, "scenario_init.log"))

    # --------------------------------------------
    # Delete results from previous model runs and initialise folders
    # --------------------------------------------
    basic_functions.del_previous_results(
        data['local_paths']['data_processed'],
        data['local_paths']['path_post_installation_data'])

    basic_functions.del_previous_setup(data['result_paths']['data_results'])

    folders_to_create = [
        data['local_paths']['dir_services'],
        data['local_paths']['path_sigmoid_data'],
        data['result_paths']['data_results'],
        data['result_paths']['data_results_PDF'],
        data['result_paths']['data_results_model_run_pop'],
        data['result_paths']['data_results_validation'],
        data['result_paths']['data_results_model_runs']
    ]

    for folder in folders_to_create:
        basic_functions.create_folder(folder)

    # ===========================================
    # I. Disaggregation
    # ===========================================

    # Load data for disaggregateion
    data['scenario_data'][
        'employment_stats'] = data_loader.read_employment_stats(
            data['paths']['path_employment_statistics'])

    # Disaggregate fuel for all regions
    fuel_disagg['rs_fuel_disagg'], fuel_disagg['ss_fuel_disagg'], fuel_disagg[
        'is_fuel_disagg'] = s_disaggregation.disaggregate_base_demand(
            data['regions'], data['assumptions'].base_yr,
            data['assumptions'].curr_yr, data['fuels'], data['scenario_data'],
            data['assumptions'], data['reg_coord'], data['weather_stations'],
            data['temp_data'], data['sectors'], data['sectors']['all_sectors'],
            data['enduses'])

    # Sum demand across all sectors for every region
    fuel_disagg[
        'ss_fuel_disagg_sum_all_sectors'] = sum_across_sectors_all_regs(
            fuel_disagg['ss_fuel_disagg'])

    fuel_disagg['is_aggr_fuel_sum_all_sectors'] = sum_across_sectors_all_regs(
        fuel_disagg['is_fuel_disagg'])

    # ---------------------------------------
    # Convert base year fuel input assumptions to energy service
    # ---------------------------------------

    # Residential
    rs_s_tech_by_p, _, rs_s_fueltype_by_p = s_fuel_to_service.get_s_fueltype_tech(
        data['enduses']['rs_enduses'], data['assumptions'].tech_list,
        data['lookups']['fueltypes'], data['assumptions'].rs_fuel_tech_p_by,
        data['fuels']['rs_fuel_raw'], data['technologies'])

    # Service
    ss_s_tech_by_p = {}
    ss_s_fueltype_by_p = {}
    for sector in data['sectors']['ss_sectors']:
        ss_s_tech_by_p[sector], _, ss_s_fueltype_by_p[
            sector] = s_fuel_to_service.get_s_fueltype_tech(
                data['enduses']['ss_enduses'], data['assumptions'].tech_list,
                data['lookups']['fueltypes'],
                data['assumptions'].ss_fuel_tech_p_by,
                data['fuels']['ss_fuel_raw'], data['technologies'], sector)

    # Industry
    is_s_tech_by_p = {}
    is_s_fueltype_by_p = {}
    for sector in data['sectors']['is_sectors']:
        is_s_tech_by_p[sector], _, is_s_fueltype_by_p[
            sector] = s_fuel_to_service.get_s_fueltype_tech(
                data['enduses']['is_enduses'], data['assumptions'].tech_list,
                data['lookups']['fueltypes'],
                data['assumptions'].is_fuel_tech_p_by,
                data['fuels']['is_fuel_raw'], data['technologies'], sector)

    # ===========================================
    # SPATIAL CALCULATIONS factors
    #
    # Calculate spatial diffusion factors
    # ===========================================
    if data['criterias']['spatial_exliclit_diffusion']:

        f_reg, f_reg_norm, f_reg_norm_abs = spatial_diffusion.calc_spatially_diffusion_factors(
            regions=data['regions'],
            fuel_disagg=fuel_disagg,
            real_values=data['pop_density'],  # Real value to select
            speed_con_max=1.0)  # diffusion speed differences

        # ---------------------
        # Plot figure for paper
        # ---------------------
        plot_fig_paper = True  #FALSE
        plot_fig_paper = False  #FALSE
        if plot_fig_paper:

            # Global value to distribute
            global_value = 50

            # Select spatial diffusion factor
            #diffusion_vals = f_reg                                 # not weighted
            diffusion_vals = f_reg_norm[
                'rs_space_heating']  # Weighted with enduse
            #diffusion_vals = f_reg_norm_abs['rs_space_heating']    # Absolute distribution (only for capacity installements)

            path_shapefile_input = os.path.abspath(
                'C:/Users/cenv0553/ED/data/_raw_data/C_LAD_geography/same_as_pop_scenario/lad_2016_uk_simplified.shp'
            )

            result_mapping.plot_spatial_mapping_example(
                diffusion_vals=diffusion_vals,
                global_value=global_value,
                paths=data['result_paths'],
                regions=data['regions'],
                path_shapefile_input=path_shapefile_input)
    else:
        f_reg = False
        f_reg_norm = False
        f_reg_norm_abs = False
        init_cont['regional_strategy_variables'] = None

    # ===========================================
    # II. Switches
    # ===========================================

    # ========================================================================================
    # Capacity switches
    #
    # Calculate service shares considering potential capacity installations
    # ========================================================================================
    # Service
    ss_aggr_sector_fuels = s_fuel_to_service.sum_fuel_enduse_sectors(
        data['fuels']['ss_fuel_raw'], data['enduses']['ss_enduses'])

    # Industry
    is_aggr_sector_fuels = s_fuel_to_service.sum_fuel_enduse_sectors(
        data['fuels']['is_fuel_raw'], data['enduses']['is_enduses'])

    if data['criterias']['spatial_exliclit_diffusion']:

        # Select diffusion value
        f_diffusion = f_reg_norm_abs

        # Convert globally defined switches to regional switches
        reg_capacity_switches_rs = global_to_reg_capacity_switch(
            data['regions'], data['assumptions'].rs_capacity_switches,
            f_diffusion)
        reg_capacity_switches_ss = global_to_reg_capacity_switch(
            data['regions'], data['assumptions'].ss_capacity_switches,
            f_diffusion)
        reg_capacity_switches_is = global_to_reg_capacity_switch(
            data['regions'], data['assumptions'].is_capacity_switches,
            f_diffusion)

        rs_service_switches_incl_cap = {}
        ss_service_switches_inlc_cap = {}
        is_service_switches_incl_cap = {}

        for region in data['regions']:

            # Residential
            rs_service_switches_incl_cap[
                region] = fuel_service_switch.capacity_switch(
                    reg_capacity_switches_rs[region], data['technologies'],
                    data['assumptions'].
                    enduse_overall_change['other_enduse_mode_info'],
                    data['fuels']['rs_fuel_raw'],
                    data['assumptions'].rs_fuel_tech_p_by,
                    data['assumptions'].base_yr)

            ss_service_switches_inlc_cap[
                region] = fuel_service_switch.capacity_switch(
                    reg_capacity_switches_ss[region], data['technologies'],
                    data['assumptions'].
                    enduse_overall_change['other_enduse_mode_info'],
                    ss_aggr_sector_fuels,
                    data['assumptions'].ss_fuel_tech_p_by,
                    data['assumptions'].base_yr)

            is_service_switches_incl_cap[
                region] = fuel_service_switch.capacity_switch(
                    reg_capacity_switches_is[region], data['technologies'],
                    data['assumptions'].
                    enduse_overall_change['other_enduse_mode_info'],
                    is_aggr_sector_fuels,
                    data['assumptions'].is_fuel_tech_p_by,
                    data['assumptions'].base_yr)
    else:  #Not spatial explicit

        rs_service_switches_incl_cap = fuel_service_switch.capacity_switch(
            data['assumptions'].rs_capacity_switches, data['technologies'],
            data['assumptions'].
            enduse_overall_change['other_enduse_mode_info'],
            data['fuels']['rs_fuel_raw'],
            data['assumptions'].rs_fuel_tech_p_by, data['assumptions'].base_yr)

        ss_service_switches_inlc_cap = fuel_service_switch.capacity_switch(
            data['assumptions'].ss_capacity_switches, data['technologies'],
            data['assumptions'].
            enduse_overall_change['other_enduse_mode_info'],
            ss_aggr_sector_fuels, data['assumptions'].ss_fuel_tech_p_by,
            data['assumptions'].base_yr)

        is_service_switches_incl_cap = fuel_service_switch.capacity_switch(
            data['assumptions'].is_capacity_switches, data['technologies'],
            data['assumptions'].
            enduse_overall_change['other_enduse_mode_info'],
            is_aggr_sector_fuels, data['assumptions'].is_fuel_tech_p_by,
            data['assumptions'].base_yr)

    # ========================================================================================
    # Service switches
    #
    # Get service shares of technologies for future year by considering
    # service switches. Potential capacity switches are used as inputs.
    #
    # Autocomplement defined service switches with technologies not
    # explicitly specified in switch on a global scale and distribute
    # spatially.
    # Autocomplete and regional diffusion levels calculations
    # ========================================================================================

    # Select spatial diffusion
    f_diffusion = f_reg_norm

    # Residential
    rs_share_s_tech_ey_p, rs_switches_autocompleted = fuel_service_switch.autocomplete_switches(
        data['assumptions'].rs_service_switches,
        data['assumptions'].rs_specified_tech_enduse_by,
        rs_s_tech_by_p,
        spatial_exliclit_diffusion=data['criterias']
        ['spatial_exliclit_diffusion'],
        regions=data['regions'],
        f_diffusion=f_diffusion,
        techs_affected_spatial_f=data['assumptions'].techs_affected_spatial_f,
        service_switches_from_capacity=rs_service_switches_incl_cap)

    # Service
    ss_switches_autocompleted = {}
    ss_share_s_tech_ey_p = {}
    for sector in data['sectors']['ss_sectors']:

        # Get all switches of a sector
        sector_switches = get_sector_switches(
            sector, data['assumptions'].ss_service_switches)

        ss_share_s_tech_ey_p[sector], ss_switches_autocompleted[
            sector] = fuel_service_switch.autocomplete_switches(
                sector_switches,
                data['assumptions'].ss_specified_tech_enduse_by,
                ss_s_tech_by_p[sector],
                sector=sector,
                spatial_exliclit_diffusion=data['criterias']
                ['spatial_exliclit_diffusion'],
                regions=data['regions'],
                f_diffusion=f_diffusion,
                techs_affected_spatial_f=data['assumptions'].
                techs_affected_spatial_f,
                service_switches_from_capacity=ss_service_switches_inlc_cap)

    # Industry
    is_switches_autocompleted = {}
    is_share_s_tech_ey_p = {}

    for sector in data['sectors']['is_sectors']:

        # Get all switches of a sector
        sector_switches = get_sector_switches(
            sector, data['assumptions'].is_service_switches)

        is_share_s_tech_ey_p[sector], is_switches_autocompleted[
            sector] = fuel_service_switch.autocomplete_switches(
                sector_switches,
                data['assumptions'].is_specified_tech_enduse_by,
                is_s_tech_by_p[sector],
                sector=sector,
                spatial_exliclit_diffusion=data['criterias']
                ['spatial_exliclit_diffusion'],
                regions=data['regions'],
                f_diffusion=f_diffusion,
                techs_affected_spatial_f=data['assumptions'].
                techs_affected_spatial_f,
                service_switches_from_capacity=is_service_switches_incl_cap)

    # ========================================================================================
    # Fuel switches
    #
    # Calculate sigmoid diffusion considering fuel switches
    # and service switches. As inputs, service (and thus also capacity switches) are used
    # ========================================================================================

    # Residential
    for enduse in data['enduses']['rs_enduses']:
        init_cont['rs_sig_param_tech'][
            enduse] = sig_param_calc_incl_fuel_switch(
                data['assumptions'].base_yr,
                data['assumptions'].crit_switch_happening,
                data['technologies'],
                enduse=enduse,
                fuel_switches=data['assumptions'].rs_fuel_switches,
                service_switches=rs_switches_autocompleted,
                s_tech_by_p=rs_s_tech_by_p[enduse],
                s_fueltype_by_p=rs_s_fueltype_by_p[enduse],
                share_s_tech_ey_p=rs_share_s_tech_ey_p[enduse],
                fuel_tech_p_by=data['assumptions'].rs_fuel_tech_p_by[enduse],
                regions=data['regions'],
                regional_specific=data['criterias']
                ['spatial_exliclit_diffusion'])

    # Service
    for enduse in data['enduses']['ss_enduses']:
        init_cont['ss_sig_param_tech'][enduse] = {}
        for sector in data['sectors']['ss_sectors']:
            init_cont['ss_sig_param_tech'][enduse][
                sector] = sig_param_calc_incl_fuel_switch(
                    data['assumptions'].base_yr,
                    data['assumptions'].crit_switch_happening,
                    data['technologies'],
                    enduse=enduse,
                    fuel_switches=data['assumptions'].ss_fuel_switches,
                    service_switches=ss_switches_autocompleted[sector],
                    s_tech_by_p=ss_s_tech_by_p[sector][enduse],
                    s_fueltype_by_p=ss_s_fueltype_by_p[sector][enduse],
                    share_s_tech_ey_p=ss_share_s_tech_ey_p[sector][enduse],
                    fuel_tech_p_by=data['assumptions'].
                    ss_fuel_tech_p_by[enduse][sector],
                    regions=data['regions'],
                    sector=sector,
                    regional_specific=data['criterias']
                    ['spatial_exliclit_diffusion'])

    # Industry
    for enduse in data['enduses']['is_enduses']:
        init_cont['is_sig_param_tech'][enduse] = {}
        for sector in data['sectors']['is_sectors']:
            init_cont['is_sig_param_tech'][enduse][
                sector] = sig_param_calc_incl_fuel_switch(
                    data['assumptions'].base_yr,
                    data['assumptions'].crit_switch_happening,
                    data['technologies'],
                    enduse=enduse,
                    fuel_switches=data['assumptions'].is_fuel_switches,
                    service_switches=is_switches_autocompleted[sector],
                    s_tech_by_p=is_s_tech_by_p[sector][enduse],
                    s_fueltype_by_p=is_s_fueltype_by_p[sector][enduse],
                    share_s_tech_ey_p=is_share_s_tech_ey_p[sector][enduse],
                    fuel_tech_p_by=data['assumptions'].
                    is_fuel_tech_p_by[enduse][sector],
                    regions=data['regions'],
                    sector=sector,
                    regional_specific=data['criterias']
                    ['spatial_exliclit_diffusion'])

    # ===========================================
    # III. Spatial explicit modelling of scenario variables
    #
    # From UK factors to regional specific factors
    # Convert strategy variables to regional variables
    # ===========================================
    if data['criterias']['spatial_exliclit_diffusion']:
        init_cont['regional_strategy_variables'] = defaultdict(dict)

        # Iterate strategy variables and calculate regional variable
        for var_name, strategy_var in data[
                'assumptions'].strategy_variables.items():

            logging.info("Spatially explicit diffusion modelling %s", var_name)
            logging.info(data['assumptions'].spatially_modelled_vars)

            # Check whether scenario varaible is regionally modelled
            if var_name not in data['assumptions'].spatially_modelled_vars:

                # Variable is not spatially modelled
                for region in data['regions']:
                    init_cont['regional_strategy_variables'][region][
                        var_name] = {
                            'scenario_value':
                            float(strategy_var['scenario_value']),
                            'affected_enduse':
                            data['assumptions'].strategy_variables[var_name]
                            ['affected_enduse']
                        }
            else:

                if strategy_var['affected_enduse'] == []:
                    logging.info(
                        "For scenario var %s no affected enduse is defined. Thus speed is used for diffusion",
                        var_name)
                else:
                    pass

                # Get enduse specific fuel for each region
                fuels_reg = spatial_diffusion.get_enduse_regs(
                    enduse=strategy_var['affected_enduse'],
                    fuels_disagg=[
                        fuel_disagg['rs_fuel_disagg'],
                        fuel_disagg['ss_fuel_disagg'],
                        fuel_disagg['is_fuel_disagg']
                    ])

                # Calculate regional specific strategy variables values
                reg_specific_variables = spatial_diffusion.factor_improvements_single(
                    factor_uk=strategy_var['scenario_value'],
                    regions=data['regions'],
                    f_reg=f_reg,
                    f_reg_norm=f_reg_norm,
                    f_reg_norm_abs=f_reg_norm_abs,
                    fuel_regs_enduse=fuels_reg)

                # Add regional specific strategy variables values
                for region in data['regions']:
                    init_cont['regional_strategy_variables'][region][
                        var_name] = {
                            'scenario_value':
                            float(reg_specific_variables[region]),
                            'affected_enduse': strategy_var['affected_enduse']
                        }

        init_cont['regional_strategy_variables'] = dict(
            init_cont['regional_strategy_variables'])

    logging.info("... finished scenario initialisation")
    return dict(init_cont), fuel_disagg