def test_sigmoid_diffusion():
    """testing
    """
    base_yr = 2015
    curr_yr = 2015
    end_yr = 2020
    sig_midpoint = 0
    sig_steepness = 1

    result = diffusion_technologies.sigmoid_diffusion(base_yr, curr_yr, end_yr,
                                                      sig_midpoint,
                                                      sig_steepness)

    assert result == 0

    base_yr = 2015
    curr_yr = 2020
    end_yr = 2020
    sig_midpoint = 0
    sig_steepness = 1

    result = diffusion_technologies.sigmoid_diffusion(base_yr, curr_yr, end_yr,
                                                      sig_midpoint,
                                                      sig_steepness)

    assert result == 1

    # ---

    base_yr = 2015
    curr_yr = 2015
    end_yr = 2020
    sig_midpoint = 0
    sig_steepness = 1

    result = diffusion_technologies.sigmoid_diffusion(base_yr, curr_yr, end_yr,
                                                      sig_midpoint,
                                                      sig_steepness)

    assert result == 0

    # ---

    base_yr = 2015
    curr_yr = 2020
    end_yr = 2025
    sig_midpoint = 0
    sig_steepness = 1

    result = diffusion_technologies.sigmoid_diffusion(base_yr, curr_yr, end_yr,
                                                      sig_midpoint,
                                                      sig_steepness)

    assert result == 0.5
Example #2
0
def sigm_temp(t_future_yr, t_base_yr, base_yr, curr_yr, t_diff_param):
    """Calculate base temperature depending on sigmoid
    diff and location

    Arguments
    ----------
    t_future_yr : int
        Future year
    t_base_yr : float
        Base year base temperature
    base_yr : int
        Base year
    curr_yr : int
        Current year
    t_diff_param : dict
        Sigmoid diffusion parameters

    Return
    ------
    t_base_cy : float
        Base temperature of current year

    Note
    ----
    Depending on the base temperature in the base and end year
    a sigmoid diffusion from the base temperature from the base year
    to the end year is calculated

    This allows to model changes e.g. in thermal confort
    """
    # Base temperature of end year minus base temp of base year
    t_base_diff = t_future_yr - t_base_yr

    # Sigmoid diffusion
    t_base_frac = diffusion_technologies.sigmoid_diffusion(
        base_yr, curr_yr, t_diff_param['yr_until_changed'],
        t_diff_param['sig_midpoint'], t_diff_param['sig_steepness'])

    # Temp diff until current year
    t_diff_cy = t_base_diff * t_base_frac

    # Add temp change to base year temp
    t_base_cy = t_base_yr + t_diff_cy

    return t_base_cy
Example #3
0
def sigm_temp(base_sim_param, assumptions, t_base_type):
    """Calculate base temperature depending on sigmoid diff and location

    Parameters
    ----------
    base_sim_param : dict
        Base simulation assumptions
    assumptions : dict
        Dictionary with assumptions

    Return
    ------
    t_base_cy : float
        Base temperature of current year

    Note
    ----
    Depending on the base temperature in the base and end year
    a sigmoid diffusion from the base temperature from the base year
    to the end year is calculated

    This allows to model changes e.g. in thermal confort
    """
    # Base temperature of end year minus base temp of base year
    t_base_diff = assumptions[t_base_type]['end_yr'] - assumptions[t_base_type]['base_yr']

    # Sigmoid diffusion
    t_base_frac = diffusion_technologies.sigmoid_diffusion(
        base_sim_param['base_yr'],
        base_sim_param['curr_yr'],
        base_sim_param['end_yr'],
        assumptions['smart_meter_diff_params']['sig_midpoint'],
        assumptions['smart_meter_diff_params']['sig_steeppness']
        )

    # Temp diff until current year
    t_diff_cy = t_base_diff * t_base_frac

    # Add temp change to base year temp
    t_base_cy = t_diff_cy + assumptions[t_base_type]['base_yr']

    return t_base_cy
Example #4
0
def calc_eff_cy(eff_by, technology, base_sim_param, assumptions, eff_achieved_factor, diff_method):
    """Calculate efficiency of current year based on efficiency assumptions and achieved efficiency

    Parameters
    ----------
    eff_by : array
        Efficiency of current year
    technology :
    base_sim_param : dict
        Base simulation parameters
    assumptions : dict
        Assumptions
    eff_achieved_factor : dict
        Efficiency achievement factor (how much of the efficiency is achieved)
    diff_method : str
        Diffusion method

    Returns
    -------
    eff_cy : array
        Array with hourly efficiency of current year

    Notes
    -----
    The development of efficiency improvements over time is assumed to be linear
    This can however be changed with the `diff_method` attribute

    TODO: TODO: Generate two types of sigmoid (convex & concav)
    """
    # Theoretical maximum efficiency potential if theoretical maximum is linearly calculated
    if diff_method == 'linear':
        theor_max_eff = diffusion.linear_diff(
            base_sim_param['base_yr'],
            base_sim_param['curr_yr'],
            assumptions['technologies'][technology]['eff_by'],
            assumptions['technologies'][technology]['eff_ey'],
            base_sim_param['sim_period_yrs']
        )

        # Consider actual achieved efficiency
        eff_cy = theor_max_eff * eff_achieved_factor

        return eff_cy

    elif diff_method == 'sigmoid':

        theor_max_eff = diffusion.sigmoid_diffusion(
            base_sim_param['base_yr'],
            base_sim_param['curr_yr'],
            base_sim_param['end_yr'],
            assumptions['other_enduse_mode_info']['sig_midpoint'],
            assumptions['other_enduse_mode_info']['sig_steeppness'])

        # Differencey in efficiency change
        efficiency_change = theor_max_eff * (
            assumptions['technologies'][technology]['eff_ey'] - assumptions['technologies'][technology]['eff_by'])

        # Actual efficiency potential
        eff_cy = eff_by + efficiency_change

        return eff_cy
Example #5
0
def calc_eff_cy(base_yr, curr_yr, eff_by, eff_ey, yr_until_changed,
                other_enduse_mode_info, eff_achieved_f, diff_method):
    """Calculate efficiency of current year based on efficiency
    assumptions and achieved efficiency

    Arguments
    ----------
    base_yr : int
        Base year
    curr_yr : int
        Current year
    eff_by : dict
        Base year efficiency
    eff_ey : dict
        End year efficiency
    yr_until_changed : int
        Year for which the eff_ey is defined
    other_enduse_mode_info : Dict
        diffusion information
    eff_achieved_f : dict
        Efficiency achievement factor (how much of the efficiency is achieved)
    diff_method : str
        Diffusion method

    Returns
    -------
    eff_cy : array
        Array with hourly efficiency of current year

    Notes
    -----
    The development of efficiency improvements over time is assumed to be linear
    This can however be changed with the `diff_method` attribute

    NICETOHAVE: Generate two types of sigmoid (convex & concav)
    """
    if diff_method == 'linear':
        # Theoretical maximum efficiency potential (linear improvement)
        theor_max_eff = diffusion.linear_diff(base_yr, curr_yr, eff_by, eff_ey,
                                              yr_until_changed)

        # Differencey in efficiency change
        max_eff_gain = theor_max_eff - eff_by

    elif diff_method == 'sigmoid':
        # Theoretical maximum efficiency potential (sigmoid improvement)
        diff_cy = diffusion.sigmoid_diffusion(
            base_yr, curr_yr, yr_until_changed,
            other_enduse_mode_info['sigmoid']['sig_midpoint'],
            other_enduse_mode_info['sigmoid']['sig_steepness'])

        # Differencey in efficiency change
        max_eff_gain = diff_cy * (eff_ey - eff_by)
    else:
        if not diff_method:
            return None
        else:
            logging.exception("Not correct diffusion assigned %s", diff_method)

    # Consider actual achieved efficiency
    actual_eff_gain = max_eff_gain * eff_achieved_f

    # Actual efficiency potential
    eff_cy = eff_by + actual_eff_gain

    return eff_cy
Example #6
0
def generate_general_parameter(
        regions,
        narratives,
        sim_yrs
    ):
    """Based on narrative input, calculate
    the parameter value for every modelled year

    Arguments
    ---------
    regions : list
        Regions
    narratives : List
        List containing all narratives of how a model
        parameter changes over time
    sim_yrs : list
        Simulated years

    Returns
    --------
    container : dict
        All model paramters containing either:
        - all values for each region and year
        - all values for each region
    """
    container = defaultdict(dict)

    # Get latest narrative timestep as it could be that the narrative is
    # not defined as long enough as the simulated years (e.g. narrative only up
    # to 2040 but the year 2050 is simulated). In these cases, use the largest
    # narrative timestep (maximum assumed to stay constant from this time onwards)
    latest_narrative_timestep = 0
    for narrative in narratives:
        if narrative['end_yr'] > latest_narrative_timestep:
            latest_narrative_timestep = narrative['end_yr']

    for sim_yr in sim_yrs:

        # Set curry_yr to largest year defined narrative if sim_yr is larger
        if sim_yr > latest_narrative_timestep:
            curr_yr = latest_narrative_timestep
        else:
            curr_yr = sim_yr

        for narrative in narratives:
            narrative_yrs = range(narrative['base_yr'], narrative['end_yr'] + 1, 1) # Years which narrative covers

            if curr_yr in narrative_yrs:
                if not narrative['regional_specific']:
                    if narrative['diffusion_choice'] == 'linear':
                        change_cy = diffusion_technologies.linear_diff(
                            narrative['base_yr'],
                            curr_yr,
                            narrative['regional_vals_by'],
                            narrative['regional_vals_ey'],
                            narrative['end_yr'])

                    elif narrative['diffusion_choice'] == 'sigmoid':

                        diff_value = narrative['regional_vals_ey'] - narrative['regional_vals_by']
                        sig_diff_factor = diffusion_technologies.sigmoid_diffusion(
                            narrative['base_yr'],
                            curr_yr,
                            narrative['end_yr'],
                            narrative['sig_midpoint'],
                            narrative['sig_steepness'])
                        change_cy = narrative['regional_vals_by'] + (diff_value * sig_diff_factor)

                    container[sim_yr] = change_cy
                else:
                    for region in regions:

                        if narrative['diffusion_choice'] == 'linear':
                            change_cy = diffusion_technologies.linear_diff(
                                narrative['base_yr'],
                                curr_yr,
                                narrative['regional_vals_by'][region],
                                narrative['regional_vals_ey'][region],
                                narrative['end_yr'])
                        elif narrative['diffusion_choice'] == 'sigmoid':
                            diff_value = narrative['regional_vals_ey'][region] - narrative['regional_vals_by'][region]
                            sig_diff_factor = diffusion_technologies.sigmoid_diffusion(
                                narrative['base_yr'],
                                curr_yr,
                                narrative['end_yr'],
                                narrative['sig_midpoint'],
                                narrative['sig_steepness'])
                            change_cy = narrative['regional_vals_by'][region] + (diff_value * sig_diff_factor)

                        container[region][sim_yr] = change_cy

    return dict(container)