Example #1
0
def read_gm(eqrm_output_path, site_tag, flag_soil=True):

    from eqrm_code.RSA2MMI import rsa2mmi_array
    from eqrm_code.worden_et_al import worden_et_al

    ''' read ground motion, an output of EQRM run'''

    atten_periods = np.load(os.path.join(eqrm_output_path, site_tag + \
        '_motion/atten_periods.npy'))

    selected_periods = [0.0, 0.3, 1.0]

    idx_period = [(np.abs(atten_periods - period)).argmin() \
        for period in selected_periods]

    if flag_soil:
        gmotion = np.load(os.path.join(eqrm_output_path, site_tag +\
            '_motion/soil_SA.npy')) # (1,1,1,sites,nsims,nperiods)
    else:
        gmotion = np.load(os.path.join(eqrm_output_path, site_tag +\
            '_motion/bedrock_SA.npy'))

    pga = gmotion[0, 0, 0, :, :, idx_period[0]]
    sa03 = gmotion[0, 0, 0, :, :, idx_period[1]]
    sa10 = gmotion[0, 0, 0, :, :, idx_period[2]]
    mmi_AK = rsa2mmi_array(sa03)
    mmi_W = worden_et_al(sa03*980, 0.3)

    return(pga, sa03, sa10, mmi_AK, mmi_W)
Example #2
0
def read_gm(eqrm_output_path, site_tag):
    ''' read ground motion, an output of EQRM run'''

    from eqrm_code.RSA2MMI import rsa2mmi_array

    atten_periods = np.load(os.path.join(eqrm_output_path, site_tag +
                            '_motion/atten_periods.npy'))

    selected_periods = [0.0, 0.3, 1.0]

    idx_period = [(np.abs(atten_periods - period)).argmin()
                  for period in selected_periods]

    try:
        print 'GM at soil is loaded'
        gmotion = np.load(os.path.join(eqrm_output_path, site_tag +
                          '_motion/soil_SA.npy'))  # (1,1,1,sites,nsims,nperiods)
    except IOError:
        print 'GM at bedrock is loaded'
        gmotion = np.load(os.path.join(eqrm_output_path, site_tag +
                          '_motion/bedrock_SA.npy'))

    pga = gmotion[0, 0, 0, :, :, idx_period[0]]
    sa03 = gmotion[0, 0, 0, :, :, idx_period[1]]
    sa10 = gmotion[0, 0, 0, :, :, idx_period[2]]
    mmi = rsa2mmi_array(sa10, period=1.0)

    return(pga, sa03, sa10, mmi)
    def calc_loss(self, SA, atten_periods):
        """
        Calculate the economic loss at a site for a user defined vulnerability
        curve.

        The curve data should be loaded in with the analysis function
        load_data() and self.vulnerability_set defined. If it hasn't and this
        function is called a runtime error is thrown.

        SA                 array of Spectral Acceleration, in g, with axis;
                               sites, psudo_events, periods
                           the site axis usually has a size of 1

        Returns economic_loss where:
          economic_loss    A dollar loss, with the the dimensions of;
                           (site, event)
        """

        if self.vulnerability_set is None:
            raise RuntimeError('Vulnerability set not found')

        IMT = self.vulnerability_set.intensity_measure_type
        # print "IMT", IMT

        if IMT == "PGA":
            period = 0
        elif IMT == "MMI":
            # Only send the SA at this period, when converting to MMI
            period = 1.0

        periods_indexs = find_period_indices(atten_periods,
                                             wanted_periods=[period],
                                             epsilon=1.0e-3)

        # Calculate intensity measure level
        # print "SA", SA
        SA_period = SA[..., periods_indexs[period]]

        if IMT == "PGA":
            IML = array(SA_period)
        elif IMT == "MMI":
            IML = rsa2mmi_array(SA_period, period=period)

        # Get mean and sigma for this measure level and site type
        mean_loss = zeros(IML.shape)
        sigma = zeros(IML.shape)
        for i, func_id in enumerate(
                self.attributes['STRUCTURE_CLASSIFICATION']):
            (mean_loss[i, :], sigma[i, :]) = self.vulnerability_set.calc_mean(
                func_id, IML[i, :])

        # Get the loss_ratio by taking a random sample
        loss_ratio = self.vulnerability_set.sample(func_id, mean_loss, sigma)

        # loss_ratio dimensions (site, psudo_events)
        # Note psudo_events probably has other dimensions colapsed into it,
        # such as ground motion models, spawning and reccurance models.

        # Perform a cutoff for the ratio limits
        loss_ratio = self.vulnerability_set.ratio_cutoff(loss_ratio)

        # Calculate economic loss
        structure_cost = self.cost_breakdown()
        economic_loss = structure_cost[:, newaxis, newaxis] * loss_ratio

        # economic_loss shape (sites, pseudo_events)
        return economic_loss
Example #4
0
    def calc_loss(self, SA, atten_periods):
        """
        Calculate the economic loss at a site for a user defined vulnerability
        curve.

        The curve data should be loaded in with the analysis function
        load_data() and self.vulnerability_set defined. If it hasn't and this
        function is called a runtime error is thrown.

        SA                 array of Spectral Acceleration, in g, with axis;
                               sites, psudo_events, periods
                           the site axis usually has a size of 1

        Returns economic_loss where:
          economic_loss    A dollar loss, with the the dimensions of;
                           (site, event)
        """

        if self.vulnerability_set is None:
            raise RuntimeError('Vulnerability set not found')

        IMT = self.vulnerability_set.intensity_measure_type
        # print "IMT", IMT

        if IMT == "PGA":
            period = 0
        elif IMT == "MMI":
            # Only send the SA at this period, when converting to MMI
            period = 1.0

        periods_indexs = find_period_indices(atten_periods,
                                             wanted_periods=[period],
                                             epsilon=1.0e-3)

        # Calculate intensity measure level
        # print "SA", SA
        SA_period = SA[..., periods_indexs[period]]

        if IMT == "PGA":
            IML = array(SA_period)
        elif IMT == "MMI":
            IML = rsa2mmi_array(SA_period,
                                period=period)

        # Get mean and sigma for this measure level and site type
        mean_loss = zeros(IML.shape)
        sigma = zeros(IML.shape)
        for i, func_id in enumerate(self.attributes['STRUCTURE_CLASSIFICATION']):
            (mean_loss[i, :], 
             sigma[i, :]) = self.vulnerability_set.calc_mean(func_id, IML[i,:])

        # Get the loss_ratio by taking a random sample
        loss_ratio = self.vulnerability_set.sample(func_id, mean_loss, sigma)

        # loss_ratio dimensions (site, psudo_events)
        # Note psudo_events probably has other dimensions colapsed into it,
        # such as ground motion models, spawning and reccurance models.

        # Perform a cutoff for the ratio limits
        loss_ratio = self.vulnerability_set.ratio_cutoff(loss_ratio)

        # Calculate economic loss
        structure_cost = self.cost_breakdown()
        economic_loss = structure_cost[:, newaxis, newaxis] * loss_ratio

        # economic_loss shape (sites, pseudo_events)
        return economic_loss