Example #1
0
def impf_dem(x_paa=1, x_mdd=1):
    impf = ImpactFunc()
    impf.haz_type = 'TC'
    impf.id = 1
    impf.intensity_unit = 'm/s'
    impf.intensity = np.linspace(0, 150, num=100)
    impf.mdd = np.repeat(1, len(impf.intensity)) * x_mdd
    impf.paa = np.arange(0, len(impf.intensity)) / len(impf.intensity) * x_paa
    impf.check()
    impf_set = ImpactFuncSet()
    impf_set.append(impf)
    return impf_set
Example #2
0
    def __init__(self):
        ImpactFunc.__init__(self)
        self.id = 1
        self.name = 'flood_1m'
        self.intensity_unit = 'm'
        self.haz_type = HAZ_TYPE

        self.intensity = np.arange(0, 1000, 0.5)
        self.paa = np.ones(self.intensity.size)
        self.mdd = np.zeros(self.intensity.size)
        for idx in range(self.mdd.size):
            if self.intensity[idx] >= 1:
                self.mdd[idx] = 1.0
Example #3
0
def create_impact_func_lin(haz_type, imp_id, m, q = 0):
    """
    Create CLIMADA Impact function
    
    Parameters
    ----------
    haz_type : str
        hazard type ("HL").
    imp_id : int
        id of Impact function.
    m : float
        Impact function parameter.
    q : float
        Impact function parameter (middle_x).


    Returns
    -------
    imp_fun : entity.impact_funcs.base.ImpactFunc
        CLIMADA Impact function.

    """
    name = {1: "Hail (Meshs) on infrastructure",
            2: "Hail (Meshs) on grape production",
            3: "Hail (Meshs) on fruit production",
            4: "Hail (Meshs) on agriculture (without fruits and grape production",
            5: "Hail (duration) on grape production", 
            6: "Hail (duration) on fruit production",
            7: "Hail (duration) on agriculture (without fruits and grape production",
            8: "Hail (duration) on infrastructure",
            9: "Hail (duration) on agriculture (fruit + grape + rest)",
            10: "Hail (Meshs) on agriculture (fruit + grape + rest="
            }
    imp_fun= ImpactFunc() 
    imp_fun.haz_type = haz_type
    imp_fun.id = imp_id
    imp_fun.name = name[imp_id]
    if imp_id <=4 or imp_id == 10:
        imp_fun.intensity_unit = 'mm'
        num = 150
    else:
        imp_fun.intensity_unit = "min"
        num = 120
    x = np.arange(num)
    imp_fun.intensity = np.linspace(0, num, num=num)
    
    imp_fun.mdd = np.linspace(q, m*num, num = num)
    for i in range(len(imp_fun.mdd)):
        if imp_fun.mdd[i]>1:
            imp_fun.mdd[i] = 1

    imp_fun.paa = np.linspace(1, 1, num=num)
    imp_fun.check()
    return imp_fun
Example #4
0
def create_impact_func(haz_type, imp_id, L, x_0, k, y=None):
    """
    Create CLIMADA Impact function
    
    Parameters
    ----------
    haz_type : str
        hazard type ("HL").
    imp_id : int
        id of Impact function.
    L : float
        Impact function parameter (max_y).
    x_0 : float
        Impact function parameter (middle_x).
    k : float
        Impact function parameter (width).
    y : float
        Values for mdd. If == 0 then the fuction will call sigmoid()

    Returns
    -------
    imp_fun : entity.impact_funcs.base.ImpactFunc
        CLIMADA Impact function.

    """
    name = {1: "Hail (Meshs) on infrastructure",
            2: "Hail (Meshs) on grape production",
            3: "Hail (Meshs) on fruit production",
            4: "Hail (Meshs) on agriculture (without fruits and grape production",
            5: "Hail (duration) on grape production", 
            6: "Hail (duration) on fruit production",
            7: "Hail (duration) on agriculture (without fruits and grape production",
            8: "Hail (duration) on infrastructure",
            9: "Hail (duration) on agriculture (fruit + grape + field)",
            10: "Hail (Meshs) on agriculture (fruit + grape + field)",
            11: "Hail (Meshs) Category 20-40mm on infrastructure",
            12: "Hail (Meshs) Category 41-60mm on infrastructure",
            13: "Hail (Meshs) Category +60mm on infrastructure"}
    imp_fun= ImpactFunc() 
    imp_fun.haz_type = haz_type
    imp_fun.id = imp_id
    imp_fun.name = name[imp_id]
    if imp_id <=4 or imp_id >= 10:
        imp_fun.intensity_unit = 'mm'
        num = 150
    else:
        imp_fun.intensity_unit = "min"
        num = 120
    x = np.arange(num)
    imp_fun.intensity = np.linspace(0, num, num=num)
    if type(y) == type(x): #workaround to check wether y is an numpy.ndarray. 
        imp_fun.mdd = y
    else:
        imp_fun.mdd = sigmoid(x, L, x_0, k)

    imp_fun.paa = np.linspace(1, 1, num=num)
    imp_fun.check()
    return imp_fun
Example #5
0
def call_impact_functions(with_without_error):
    """get curve for the impact function:

                        Parameters:

                            with_without_error (bool): rather to give best estimate or to add a random variation. Default: True
                        Returns: climada impact functions set

                              """

    # get the data from the studies:
    directory_if = '../../input_data/impact_functions/'

    file_low = pd.read_csv(''.join([directory_if, 'impact_low.csv']))
    function_low = impact_functions_random(file_low, 'low', with_without_error)

    file_moderate = pd.read_csv(''.join([directory_if, 'impact_moderate.csv']))
    function_moderate = impact_functions_random(file_moderate, 'moderate',
                                                with_without_error)

    file_high = pd.read_csv(''.join([directory_if, 'impact_high.csv']))
    function_high = impact_functions_random(file_high, 'high',
                                            with_without_error)

    # make impact function set:

    if_heat_set = ImpactFuncSet()
    x = np.linspace(20, 40, num=30)

    if_heat1 = ImpactFunc()
    if_heat1.haz_type = 'heat'
    if_heat1.id = 1
    if_heat1.name = 'low physical activity'
    if_heat1.intensity_unit = 'Degrees C'
    if_heat1.intensity = x
    if_heat1.mdd = (sigmoid(x, *function_low)) / 100
    if_heat1.mdd[if_heat1.mdd < 0] = 0  # to avoid having negative values
    if_heat1.mdd[if_heat1.mdd > 100] = 100  # to avoid having values over a 100
    if_heat1.paa = np.linspace(1, 1, num=30)
    if_heat_set.append(if_heat1)

    if_heat2 = ImpactFunc()
    if_heat2.haz_type = 'heat'
    if_heat2.id = 2
    if_heat2.name = 'medium physical activity'
    if_heat2.intensity_unit = 'Degrees C'
    if_heat2.intensity = x
    if_heat2.mdd = (sigmoid(x, *function_moderate)) / 100
    if_heat2.mdd[if_heat2.mdd < 0] = 0
    if_heat2.mdd[if_heat2.mdd > 100] = 100
    if_heat2.paa = np.linspace(1, 1, num=30)
    if_heat_set.append(if_heat2)

    if_heat3 = ImpactFunc()
    if_heat3.haz_type = 'heat'
    if_heat3.id = 3
    if_heat3.name = 'high physical activity'
    if_heat3.intensity_unit = 'Degrees C'
    if_heat3.intensity = x
    if_heat3.mdd = (sigmoid(x, *function_high)) / 100
    if_heat3.mdd[if_heat3.mdd < 0] = 0
    if_heat3.mdd[if_heat3.mdd > 100] = 100
    if_heat3.paa = np.linspace(1, 1, num=30)
    if_heat_set.append(if_heat3)

    return if_heat_set