Return standard deviations as defined in equation 3.5.5-1 page 151
198164
def _get_stddevs(self, stddev_types, pgv):
        
        assert all(stddev_type in self.DEFINED_FOR_STANDARD_DEVIATION_TYPES
                   for stddev_type in stddev_types)
        std = np.zeros_like(pgv)
        std[pgv <= 25] = 0.20
        idx = (pgv > 25) & (pgv <= 50)
        std[idx] = 0.20 - 0.05 * (pgv[idx] - 25) / 25
        std[pgv > 50] = 0.15
        # convert from log10 to ln
        std = np.log(10 ** std)
        return [std for stddev_type in stddev_types]
669975
def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types):
        
        assert all(stddev_type in self.DEFINED_FOR_STANDARD_DEVIATION_TYPES
                   for stddev_type in stddev_types)

        mean = np.zeros_like(sites.vs30)
        stddevs = [np.zeros_like(sites.vs30) for _ in stddev_types]

        idx_rock = sites.vs30 >= self.ROCK_VS30
        idx_soil = sites.vs30 < self.ROCK_VS30

        if idx_rock.any():
            C = self.COEFFS_ROCK[imt]
            self._compute_mean(C, self.CONSTS['A1_rock'],
                               self.CONSTS['A2_rock'], self.CONSTS['A3_rock'],
                               self.CONSTS['A4_rock'], self.CONSTS['A5_rock'],
                               self.CONSTS['A6_rock'], rup.mag, rup.hypo_depth,
                               dists.rrup, mean, idx_rock)
            self._compute_std(C, rup.mag, stddevs, idx_rock)

            if imt == SA(period=4.0, damping=5.0):
                mean = mean / 0.399

        if idx_soil.any():
            C = self.COEFFS_SOIL[imt]
            self._compute_mean(C, self.CONSTS['A1_soil'],
                               self.CONSTS['A2_soil'], self.CONSTS['A3_soil'],
                               self.CONSTS['A4_soil'], self.CONSTS['A5_soil'],
                               self.CONSTS['A6_soil'], rup.mag, rup.hypo_depth,
                               dists.rrup, mean, idx_soil)
            self._compute_std(C, rup.mag, stddevs, idx_soil)

        return mean, stddevs
294085
def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types):
        
        # extracting dictionary of coefficients specific to required
        # intensity measure type.
        C = self.COEFFS_ASC[imt]

        # mean value as given by equation 1, p. 901, without considering the
        # interface and intraslab terms (that is SI, SS, SSL = 0) and the
        # inter and intra event terms, plus the magnitude-squared term
        # correction factor (equation 5 p. 909).
        mean = self._compute_magnitude_term(C, rup.mag) +\
            self._compute_distance_term(C, rup.mag, dists.rrup) +\
            self._compute_focal_depth_term(C, rup.hypo_depth) +\
            self._compute_faulting_style_term(C, rup.rake) +\
            self._compute_site_class_term(C, sites.vs30) +\
            self._compute_magnitude_squared_term(P=0.0, M=6.3, Q=C['QC'],
                                                 W=C['WC'], mag=rup.mag)

        # convert from cm/s**2 to g
        mean = np.log(np.exp(mean) * 1e-2 / g)

        stddevs = self._get_stddevs(C['sigma'], C['tauC'], stddev_types,
                                    num_sites=len(sites.vs30))

        return mean, stddevs
1367907
def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types):
        
        # extract dictionaries of coefficients specific to required
        # intensity measure type
        C = self.COEFFS[imt]

        mean = self._compute_mean(C, rup, dists, sites, imt)

        stddevs = self._get_stddevs(C, stddev_types, sites.vs30.shape[0])

        return mean, stddevs
1287568
def get_mean_and_stddevs(self, sctx, rctx, dctx, imt, stddev_types):
        
        # Return Distance Tables
        imls = self._return_tables(rctx.mag, imt, "IMLs")
        # Get distance vector for the given magnitude
        idx = numpy.searchsorted(self.m_w, rctx.mag)
        dists = self.distances[:, 0, idx - 1]
        # Get mean and standard deviations
        mean = self._get_mean(imls, dctx, dists)
        stddevs = self._get_stddevs(dists, rctx.mag, dctx, imt, stddev_types)
        if self.amplification:
            # Apply amplification
            mean_amp, sigma_amp = self.amplification.get_amplification_factors(
                imt,
                sctx,
                rctx,
                getattr(dctx, self.distance_type),
                stddev_types)
            mean = numpy.log(mean) + numpy.log(mean_amp)
            for iloc in range(len(stddev_types)):
                stddevs[iloc] *= sigma_amp[iloc]
            return mean, stddevs
        else:
            return numpy.log(mean), stddevs
1194566
def _get_stddevs(self, C, stddev_types, num_sites):
        
        assert all(stddev_type in self.DEFINED_FOR_STANDARD_DEVIATION_TYPES
                   for stddev_type in stddev_types)

        # Using a frequency independent value of sigma as recommended
        # in the caption of Table 2 of Atkinson (2010)
        stddevs = [0.26/np.log10(np.e) + np.zeros(num_sites)]

        return stddevs
714720
def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types):
        
        assert all(stddev_type in self.DEFINED_FOR_STANDARD_DEVIATION_TYPES
                   for stddev_type in stddev_types)

        C = self.COEFFS[imt]
        mean = (self._get_magnitude_scaling(C, rup.mag) +
                self._get_distance_scaling(C, rup.mag, dists.rhypo))
        if imt.name in "SA PGA":
            mean = np.log(np.exp(mean) / (100.0 * g))
        stddevs = self._compute_std(C, stddev_types, len(dists.rhypo))
        return mean, stddevs
768471
def _get_stddevs(self, C, stddev_types, num_sites):

        

        # interevent stddev
        sigma_inter = C['tau'] + np.zeros(num_sites)
        # intraevent std
        sigma_intra = C['sigma'] + np.zeros(num_sites)
        std = []

        for stddev_type in stddev_types:
            if stddev_type == const.StdDev.TOTAL:
                # equation in section 5.2 page 200
                std += [np.sqrt(sigma_intra**2 + sigma_inter**2)]
            elif stddev_type == const.StdDev.INTRA_EVENT:
                std.append(sigma_intra)
            elif stddev_type == const.StdDev.INTER_EVENT:
                std.append(sigma_inter)

        return std
1023800
def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types):
        
        mean = self._get_mean(sites.vs30, rup.mag, dists.rrup, imt, scale_fac=0)
        stddevs = self._get_stddevs(stddev_types, num_sites=sites.vs30.size)

        return mean, stddevs
110424
def _get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types, 
        mag_conversion_sigma=0.0):
        
        # extract dictionaries of coefficients specific to required
        # intensity measure type
        C = self.COEFFS[imt]

        # clip distance at 4 km, minimum distance for which the equation is
        # valid (see section 2.2.4, page 201). This also avoids singularity
        # in the equation
        rhypo = dists.rhypo
        rhypo[rhypo < 4.] = 4.

        mean = C['a'] * rup.mag + C['b'] * rhypo - np.log10(rhypo)

        mean[sites.vs30 >= 800] += C['c1']
        mean[sites.vs30 < 800] += C['c2']

        # convert from log10 to ln, and from cm/s2 to g
        mean = mean * np.log(10) - 2 * np.log(10) - np.log(g)

        stddevs = self._get_stddevs(C, stddev_types, rhypo.shape[0], 
            mag_conversion_sigma=mag_conversion_sigma)

        return mean, stddevs
344487
def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types):
        
        assert all(stddev_type in self.DEFINED_FOR_STANDARD_DEVIATION_TYPES
                   for stddev_type in stddev_types)

        C = self.COEFFS[imt]
        mag = self._convert_magnitude(rup.mag)

        mean = (
            C['c1'] + C['c2'] * mag + C['c10'] * (mag - 6) ** 2 +
            (C['c6'] + C['c7'] * mag) * np.log(dists.rjb + np.exp(C['c4']))
        )
        mean = clip_mean(imt, mean)

        stddevs = self._compute_stddevs(C, dists.rjb.size, stddev_types)

        return mean, stddevs
656512
def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types):
        
        C = self.COEFFS[imt]

        # clip rhypo at 10 (this is the minimum distance used in
        # deriving the equation), see page 22, this avoids singularity
        # in mean value equation
        rhypo = dists.rhypo.copy()
        rhypo[rhypo < 10] = 10

        # convert magnitude from Mblg to Mw
        mag = rup.mag * 0.98 - 0.39 if rup.mag <= 5.5 else \
              2.715 - 0.277 * rup.mag + 0.127 * rup.mag * rup.mag

        # functional form as explained in 'Youngs_fit_to_AB95lookup.doc'
        f1 = np.minimum(np.log(rhypo), np.log(70.))
        f2 = np.maximum(np.log(rhypo / 130.), 0)
        mean = (
            C['c1'] + C['c2'] * mag + C['c3'] * mag ** 2 +
            (C['c4'] + C['c5'] * mag) * f1 +
            (C['c6'] + C['c7'] * mag) * f2 +
            C['c8'] * rhypo
        )

        stddevs = self._get_stddevs(stddev_types,  dists.rhypo.shape[0])

        return mean, stddevs
1245710
def get_stddevs(self, C, nsites, stddev_types):
        
        stddevs = []
        zeros_array = np.zeros(nsites)
        for stddev in stddev_types:
            assert stddev in self.DEFINED_FOR_STANDARD_DEVIATION_TYPES
            if stddev == const.StdDev.TOTAL:
                stddevs.append(np.sqrt(C["tau"] ** 2. + C["phi"] ** 2.) +
                               zeros_array)
            elif stddev == const.StdDev.INTER_EVENT:
                stddevs.append(C["tau"] + zeros_array)
            elif stddev == const.StdDev.INTRA_EVENT:
                stddevs.append(C["phi"] + zeros_array)
        return stddevs
461994
def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types):
        
        mean = self._get_mean(sites, rup, dists, imt, stddev_types)
        stddevs = [np.ones(len(dists.rrup))*get_sigma(imt)]
        return mean, stddevs
293024
def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types):
        
        # extracting dictionary of coefficients specific to required
        # intensity measure type.

        C = self.COEFFS[imt]
        mean = (self._get_magnitude_scaling(C, rup.mag) +
                self._get_distance_scaling(C, dists, rup.mag) +
                self._get_site_term(C, sites.vs30))

        # Mean is returned in terms of m/s^2. Need to convert to g
        mean -= np.log(g)
        stddevs = self.get_stddevs(C, sites.vs30.shape, stddev_types)
        return mean + self.adjustment_factor, stddevs
615885
def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types):
        
        mean, stddevs = super().get_mean_and_stddevs(
            sites, rup, dists, imt, stddev_types)

        # this is the firm ground adjustment
        mean += np.log(1.162)

        return mean, stddevs
492095
def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types):
        
        # extract dictionaries of coefficients specific to required
        # intensity measure type and for PGA
        C = self.COEFFS[imt]
        C_PGA = self.COEFFS[PGA()]

        # Get mean and standard deviation of PGA on rock (Vs30 1100 m/s^2)
        pga1100 = np.exp(self.get_mean_values(C_PGA, sites, rup, dists, None))
        # Get mean and standard deviations for IMT
        mean = self.get_mean_values(C, sites, rup, dists, pga1100)
        if imt.name == "SA" and imt.period <= 0.25:
            # According to Campbell & Bozorgnia (2013) [NGA West 2 Report]
            # If Sa (T) < PGA for T < 0.25 then set mean Sa(T) to mean PGA
            # Get PGA on soil
            pga = self.get_mean_values(C_PGA, sites, rup, dists, pga1100)
            idx = mean <= pga
            mean[idx] = pga[idx]
        # Get standard deviations
        stddevs = self._get_stddevs(C,
                                    C_PGA,
                                    rup,
                                    sites,
                                    pga1100,
                                    stddev_types)
        return mean, stddevs