Exemple #1
0
def test_interpolate_to_closest(test_t, test_t_high, test_t_low, test_y_high,
                                test_y_low, expected):
    sa, sigma_sas = classdef.interpolate_to_closest(test_t, test_t_high,
                                                    test_t_low, test_y_high,
                                                    test_y_low)
    assert (round(sa,
                  DIGITS), [round(sigma_sa, DIGITS)
                            for sigma_sa in sigma_sas]) == (
                                round(expected[0], DIGITS),
                                [round(s, DIGITS) for s in expected[-1]],
                            )
Exemple #2
0
def Abrahamson_2018(site, fault, im=None, periods=None, epistemic_adj=None):
    """

    component returned: geometric mean

    Input Variables

    siteprop.Rrup: closest distance (km) to the ruptured plane
    siteprop.vs30: for site amplification

    faultprop.Mw: moment magnitude
    faultprop.tect_type: SUBDUCTION_INTERFACE or SUBDUCTION_SLAB only
    faultprop.ztor: if SUBDUCTION_SLAB only. depth (km) to the top of ruptured plane

    im: PGA or SA only

    epistemic_adj: None: disabled epistemic adjustment
                   "HIGH": subduction interface or in-slab GMPE with the positive epistemic adjustment factor applied
                   "LOW":  subduction interface or in-slab GMPE with the negative epistemic adjustment factor applied
    """
    results = []
    if im == "PGA":
        periods = [0]
    try:
        periods[0]
    except (TypeError, IndexError) as e:
        periods = [periods]

    for t in periods:
        sorted_t = np.array(sorted(imt))
        closest_index = int(np.argmin(np.abs(sorted_t - t)))
        closest_period = sorted_t[closest_index]
        if np.isclose(closest_period, t):
            result = calculate_Abrahamson(site, fault, closest_period,
                                          epistemic_adj)
        else:
            t_low = sorted_t[t >= sorted_t][-1]
            t_high = sorted_t[t <= sorted_t][0]

            a_low = calculate_Abrahamson(site, fault, t_low, epistemic_adj)
            a_high = calculate_Abrahamson(site, fault, t_high, epistemic_adj)

            result = interpolate_to_closest(t, t_high, t_low, a_high, a_low)
        results.append(result)

    if len(periods) == 1:
        results = results[0]

    return results
Exemple #3
0
def Bradley_2010_Sa(siteprop, faultprop, im, periods=None):
    # declare a whole bunch of coefficients
    ##################

    if im == "PGA":
        periods = [0]
    if im == "PGV":
        periods = [-1]

    results = []

    for period in periods:

        t = period

        tol = 0.0001  # tolerance to the recorded period values before we interpolate

        closest_index = int(np.argmin(np.abs(period_list - t)))
        closest_period = period_list[closest_index]
        if not np.isclose(closest_period,
                          t):  # interpolate between periods if necessary

            # find the period values above and below
            t_low = period_list[t >= period_list][-1]
            t_high = period_list[t <= period_list][0]

            # recursively call this function for the periods above and below
            brad_low = calculate_Bradley(siteprop, faultprop, t_low)
            brad_high = calculate_Bradley(siteprop, faultprop, t_high)

            # now interpolate the low and high values
            result = interpolate_to_closest(t, t_high, t_low, brad_high,
                                            brad_low)

        else:
            result = calculate_Bradley(siteprop, faultprop, t)
        results.append(result)

    if im in ["PGA", "PGV"]:
        results = results[0]

    return results
def Zhaoetal_2006_Sa(site, fault, im, periods=None):
    if im == "PGA":
        periods = [0]
    try:
        periods[0]
    except (TypeError, IndexError) as e:
        periods = [periods]

    results = []
    for period in periods:

        T = period

        max_period = period_list[-1]
        if period > max_period:
            zhao_max = calculate_zhao(site, fault, max_period)
            median_max = zhao_max[0]
            median = median_max * (max_period / period)**2
            result = (median, zhao_max[1])
        else:
            # interpolate between periods if necessary
            closest_index = np.argmin(np.abs(period_list - T))
            closest_period = period_list[closest_index]

            if not np.isclose(closest_period, T):
                T_low = period_list[T >= period_list][-1]
                T_hi = period_list[T <= period_list][0]

                zhao_low = calculate_zhao(site, fault, T_low)
                zhao_high = calculate_zhao(site, fault, T_hi)

                result = interpolate_to_closest(T, T_hi, T_low, zhao_high,
                                                zhao_low)

            else:
                result = calculate_zhao(site, fault, period)
        results.append(result)

    if len(periods) == 1:
        results = results[0]

    return results
def CB_2014_nga(siteprop, faultprop, im=None, period=None, region=0, f_hw=None):

    """
    Campbell and Bozorgnia 2014 ground motion prediciton model. Citation for
    the model:

    Campbell, K. W., and Bozorgnia, Y. (2014). ?NGA-West2 Ground Motion Model 
    for the Average Horizontal Components of PGA, PGV, and 5% Damped Linear 
    Acceleration Response Spectra.? Earthquake Spectra, 30(3), 1087?1115.

    coded by Yue Hua,  4/22/14
        Stanford University, [email protected]
    Modified 4/5/2015 by Jack Baker to fix a few small bugs

    Provides ground-motion prediction equations for computing medians and
    standard deviations of average horizontal components of PGA, PGV and 5%
    damped linear pseudo-absolute aceeleration response spectra

    Input Variables
    siteprop.Rrup = Closest distance coseismic rupture (km)
    siteprop.Rjb  = Joyner-Boore distance (km)
    siteprop.Rx   = Closest distance to the surface projection of the
                       coseismic fault rupture plane
    siteprop.vs30 = shear wave velocity averaged over top 30 m (m/s)
    siteprop.z2p5 = Depth to the 2.5 km/s shear-wave velocity horizon (km)
                    None if in California or Japan and Z2.5 is unknown

    faultprop.dip    = average dip of the rupture place (degree)
    faultprop.hdepth = Hypocentral depth of the earthquake measured from sea level
                       None if unknown
    faultprop.Mw     = Magnitude
    faultprop.rake   = rake angle (degree) - average angle of slip measured in
                       the plance of rupture
    faultprop.width  = down-dip width of the fault rupture plane
                       None if unknown
    faultprop.zbot   = Depth to the bottom of the seismogenic crust
                       needed only when W is unknown
    faultprop.ztor   = Depth to the top of coseismic rupture (km)
                       None if unknown

    period = Period (sec)
             None to output the array of Sa with period

    region = 0 for global (incl. Taiwan)
           = 1 for California
           = 2 for Japan
           = 3 for China or Turkey
           = 4 for Italy

    f_hw = hanging wall effect
           True for including
           False for excluding

    Output Variables
    Sa            = Median spectral acceleration prediction
    sigma         = logarithmic standard deviation of spectral acceleration
                    prediction
    """
    M = faultprop.Mw
    if im == 'pSA':
        T = period
    elif im == 'PGA':
        T = 0
    elif im == 'PGV':
        T = -1
    W = faultprop.width
    Zhyp = faultprop.hdepth
    Ztor = faultprop.ztor
    if f_hw is None:
        f_hw = int(siteprop.Rx >= 0)

    # style of faulting
    f_rv = int(30 < faultprop.rake < 150)
    f_nm = int(-150 < faultprop.rake < -30)

    # Ztor is unknown
    if Ztor is None:
        if f_rv:
            Ztor = max(2.704 - 1.226 * max(M - 5.849, 0), 0) ** 2
        else:
            Ztor = max(2.673 - 1.136 * max(M - 4.970, 0), 0) ** 2

    if W is None:
        if f_rv:
            Ztori = max(2.704 - 1.226 * max(M - 5.849, 0), 0) ** 2
        else:
            Ztori = max(2.673 - 1.136 * max(M - 4.970, 0), 0) ** 2
        try:
            W = min(
                math.sqrt(10 ** ((M - 4.07) / 0.98)),
                (faultprop.zbot - Ztori) / math.sin(math.pi / 180 * faultprop.dip),
            )
        except ZeroDivisionError:
            W = math.sqrt(10 ** ((M - 4.07) / 0.98))
        Zhyp = 9

    elif Zhyp is None:
        fdZM = min(-4.317 + 0.984 * M, 2.325)
        fdZD = 0.0445 * (min(faultprop.dip, 40) - 40)

        if f_rv:
            Ztori = max(2.704 - 1.226 * max(M - 5.849, 0), 0) ** 2
        else:
            Ztori = max(2.673 - 1.136 * max(M - 4.970, 0), 0) ** 2

        # depth to bottom of rupture plane
        Zbor = Ztori + W * math.sin(math.pi / 180 * faultprop.dip)
        try:
            d_Z = math.exp(min(fdZM + fdZD, math.log(0.9 * (Zbor - Ztori))))
        except ValueError:
            # Zbor == Ztori
            d_Z = 0
        Zhyp = d_Z + Ztori

    def sa_sigma(period_i):
        """
        Return Sa and sigma for given period index.
        """
        return CB_2014_nga_sub(
            M,
            period_i,
            siteprop.Rrup,
            siteprop.Rjb,
            siteprop.Rx,
            W,
            Ztor,
            faultprop.zbot,
            faultprop.dip,
            f_hw,
            siteprop.vs30,
            siteprop.z2p5,
            Zhyp,
            faultprop.rake,
            f_rv,
            f_nm,
            region,
        )

    # compute Sa and sigma with user-defined period
    try:
        T[0]
    except TypeError:
        T = [T]
    Sa = np.zeros(len(T))
    sigma = np.zeros((len(T), 3))
    for i, Ti in enumerate(T):
        if not np.isclose(periods, Ti, atol=0.0001).any():
            # user defined period requires interpolation
            ip_high = np.argmin(periods < Ti)
            ip_low = ip_high - 1

            y_low = sa_sigma(ip_low)
            y_high = sa_sigma(ip_high)
            PGA = sa_sigma(PGAi)[0]

            Sa[i], sigma[i] = interpolate_to_closest(Ti, periods[ip_high], periods[ip_low], y_high, y_low)
            if Sa[i] < PGA and Ti < 0.25:
                Sa[i] = PGA
        else:
            ip_T = np.argmin(np.abs(periods - Ti))
            Sa[i], sigma[i] = sa_sigma(ip_T)
            if ip_T != PGAi:
                PGA = sa_sigma(PGAi)[0]
                if Sa[i] < PGA and Ti < 0.25:
                    Sa[i] = PGA

    if len(T) == 1:
        return Sa[0], sigma[0]
    return list(zip(Sa, sigma))
Exemple #6
0
def ASK_2014_nga(siteprop,
                 faultprop,
                 im=None,
                 period=None,
                 region=0,
                 f_hw=None,
                 f_as=0):
    """
    Matlab coded by Yue Hua, 5/19/10
                  Stanford University
                  [email protected]
    edited by Jack Baker, 9/22/2017 to fix an error in f_vs30 variable
    definition in the comments (no change to the function of the code).
    
    Abrahamson, N. A., Silva, W. J., and Kamai, R. (2014). ?Summary of the 
    ASK14 Ground Motion Relation for Active Crustal Regions.? Earthquake 
    Spectra, 30(3), 1025?1055.
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    Input Variables
    siteprop.Rrup         = closest distance (km) to the ruptured plane
    siteprop.Rjb          = Joyner-Boore distance (km); closest distance (km) to surface
                            projection of rupture plane
    siteprop.Rx           = site coordinate (km) measured perpendicular to the fault strike
                            from the fault line with down-dip direction to be positive
    siteprop.Ry          = horizontal distance off the end of the rupture measured parallel
                            to strike
    siteprop.vs30         = shear wave velocity averaged over top 30 m in m/s
                            ref: 1130
    siteprop.vs30measured = True for measured vs30
                            False for vs30 inferred from geology or Japan
    siteprop.z1p0         = Basin depth (km); depth from the groundsurface to the
                            1km/s shear-wave horizon.

    faultprop.dip   = fault dip angle (in degrees)
    faultprop.Mw    = moment magnitude
    faultprop.rake  = Rake angle (in degrees)
    faultprop.width = down-dip rupture width (km)
    faultprop.ztor  = depth (km) to the top of ruptured plane

    period = period (sec); period = -1 for PGV computation
                    None for output the array of Sa with original period (no interpolation)

    region        = 0 for global
                  = 1 for California
                  = 2 for Japan
                  = 3 for China 
                  = 4 for Italy 
                  = 5 for Turkey
                  = 6 for Taiwan

    f_hw   = flag for hanging wall sites

    f_as   = flag for aftershocks

    crjb = centroid crjb, hardcoded to assume no aftershock

    Output Variables
    Sa: Median spectral acceleration prediction
    sigma: logarithmic standard deviation of spectral acceleration
             prediction
    """
    mag = faultprop.Mw
    if im == "PGV":
        period = -1
    if im == "PGA":
        period = 0
    if f_hw is None:
        f_hw = int(siteprop.Rx >= 0)
    T = period
    w = faultprop.width
    z10 = siteprop.z1p0
    ztor = faultprop.ztor

    f_rv = int(30 <= faultprop.rake <= 150)
    f_nm = int(-150 <= faultprop.rake <= -30)

    if ztor is None:
        if f_rv == 1:
            ztor = max(2.704 - 1.226 * max(mag - 5.849, 0), 0)**2
        else:
            ztor = max(2.673 - 1.136 * max(mag - 4.970, 0), 0)**2

    if w is None:
        w = min(18 / math.sin(math.radians(faultprop.dip)),
                10**(-1.75 + 0.45 * mag))

    if z10 is None:
        if region == 2:
            # Japan
            z10 = (math.exp(-5.23 / 2 * math.log(
                (siteprop.vs30**2 + 412**2) / (1360**2 + 412**2))) / 1000)
        else:
            z10 = (math.exp((-7.67 / 4) * math.log(
                (siteprop.vs30**4 + 610**4) / (1360**4 + 610**4))) / 1000)

    def sa_sigma(period_i):
        """
        Return Sa and sigma for given period index.
        """
        return ASK_2014_sub_1(
            mag,
            period_i,
            siteprop.Rrup,
            siteprop.Rjb,
            siteprop.Rx,
            siteprop.Ry,
            ztor,
            faultprop.dip,
            f_rv,
            f_nm,
            f_as,
            f_hw,
            w,
            z10,
            siteprop.vs30,
            siteprop.vs30measured,
            region,
        )

    if T is None:
        # compute Sa and sigma with pre-defined periods
        periods_out = periods[:-2]
        Sa = np.zeros(len(periods_out))
        sigma = np.zeros(len(periods_out))
        for ip in range(len(periods_out)):
            Sa[ip], sigma[ip] = sa_sigma(ip)
        return Sa, sigma, periods_out

    # compute Sa and sigma with user-defined period
    try:
        T[0]
    except TypeError:
        T = [T]
    Sa = np.zeros(len(T))
    sigma = np.zeros([len(T), 3])
    for i, Ti in enumerate(T):
        if not np.isclose(periods, Ti, atol=0.0001).any():
            # user defined period requires interpolation
            ip_high = np.argmin(periods < Ti)
            ip_low = ip_high - 1

            y_low = sa_sigma(ip_low)
            y_high = sa_sigma(ip_high)
            Sa[i], sigma[i] = interpolate_to_closest(Ti, periods[ip_high],
                                                     periods[ip_low], y_high,
                                                     y_low)
        else:
            ip_T = np.argmin(np.abs(periods - Ti))
            Sa[i], sigma[i, :] = sa_sigma(ip_T)

    if len(T) == 1:
        return Sa[0], sigma[0]
    else:
        return list(zip(Sa, sigma))
Exemple #7
0
def CY_2014_nga(siteprop,
                faultprop,
                im=None,
                period=None,
                region=0,
                f_hw=None):
    """
    coded by Yue Hua
                Stanford University
                [email protected]
    Updated 6/16/2017 by Gemma Cremen to fix a bug with the vs30measured flag
    Chiou, B. S.-J., and Youngs, R. R. (2014). ?Update of the Chiou and 
    Youngs NGA Model for the Average Horizontal Component of Peak Ground 
    Motion and Response Spectra.? Earthquake Spectra, 30(3), 1117?1153.

    Input Variables
    siteprop.Rrup     = closest distance (km) to the ruptured plane
    siteprop.Rjb      = Joyner-Boore distance (km); closest distance (km) to surface
                        projection of rupture plane
    siteprop.Rx       = Horizontal distance from top of rupture measured perpendicular 
                        to fault strike (km). See Figures a, b and c for illustation
                        Ztor = Depth(km) to the top of ruptured plane
    siteprop.vs30     = shear wave velocity averaged over top 30 m in m/s
                        ref: 1130
    site.vs30measured = 0 for s30 is inferred from geology
                        1 for measured vs30
    siteprop.z1p0     = basin depth (km); depth from the groundsurface to the
                        1km/s shear-wave horizon.
                        None if unknown

    faultprop.dip  = fault dip angle (in degrees)
    faultprop.Mw   = moment magnitude
    faultprop.rake = rake angle (in degrees)

    period     = Period (sec); period = -1 for PGV computation
                 None for output the array of Sa with original period (no interpolation)

    region = 0 for global (incl. Taiwan)
           = 1 for California
           = 2 for Japan
           = 3 for China
           = 4 for Italy
           = 5 for Turkey

    d_DPP = DPP centered on the site and earthquake specific average
            DPP = 0 for median calc (not included as a variable here)

    Output Variables
    Sa: Median spectral acceleration prediction
    sigma: logarithmic standard deviation of spectral acceleration
            prediction
    """
    if im == "PGV":
        T = -1
    elif im == "PGA":
        T = 0
    elif im == "pSA":
        T = period

    dip = faultprop.dip * math.pi / 180.0
    f_rv = 30 <= faultprop.rake <= 150
    f_nm = -120 <= faultprop.rake <= -60

    if f_hw is None:
        f_hw = int(siteprop.Rx >= 0)

    # d_DPP=0 for median
    d_DPP = 0

    def sa_sigma(period_i):
        """
        Return Sa and sigma for given period index.
        """
        return CY_2014_sub(
            faultprop.Mw,
            period_i,
            siteprop.Rrup,
            siteprop.Rjb,
            siteprop.Rx,
            faultprop.ztor,
            dip,
            f_rv,
            f_nm,
            f_hw,
            siteprop.z1p0,
            siteprop.vs30,
            siteprop.vs30measured,
            region,
            d_DPP,
        )

    PGA, sigma_PGA = sa_sigma(1)

    # compute Sa and sigma with user-defined period
    try:
        T[0]
    except TypeError:
        T = [T]
    Sa = np.zeros(len(T))
    sigma = np.zeros([len(T), 3])
    for i, Ti in enumerate(T):
        if not np.isclose(periods, Ti, atol=0.0001).any():
            # user defined period requires interpolation
            ip_high = np.argmin(periods < Ti)
            ip_low = ip_high - 1

            y_low = sa_sigma(ip_low)
            y_high = sa_sigma(ip_high)

            Sa[i], sigma[i] = interpolate_to_closest(Ti, periods[ip_high],
                                                     periods[ip_low], y_high,
                                                     y_low)
            if Sa[i] < PGA and Ti <= 0.3:
                Sa[i] = PGA
        else:
            ip_T = np.argmin(np.abs(periods - Ti))
            Sa[i], sigma[i] = sa_sigma(ip_T)
            if Sa[i] < PGA and Ti <= 0.3:
                Sa[i] = PGA

    if len(T) == 1:
        return Sa[0], sigma[0]
    return list(zip(Sa, sigma))
def BSSA_2014_nga(siteprop, faultprop, im="pSA", period=None, region=0):
    """
    coded by Yue Hua
                Stanford University
                [email protected]

    modified by Jack Baker, 3/3/2014

    BSSA14 NGA-West2 model, based on teh following citation

    Boore, D. M., Stewart, J. P., Seyhan, E., and Atkinson, G. M. (2014). 
    "NGA-West2 Equations for Predicting PGA, PGV, and 5% Damped PSA for 
    Shallow Crustal Earthquakes." Earthquake Spectra, 30(3), 1057-1085.
    http://www.earthquakespectra.org/doi/abs/10.1193/070113EQS184M

    Provides ground-mtion prediction equations for computing medians and
    standard devisations of average horizontal component internsity measures
    (IMs) for shallow crustal earthquakes in active tectonic regions.

    Input Variables
    siteprop.Rjb  = Joyner-Boore distance (km)
    siteprop.z1p0 = Basin depth (km); depth from the groundsurface to the
                    1km/s shear-wave horizon.
                    None if unknown
    siteprop.vs30 = shear wave velocity averaged over top 30 m in m/s

    faultprop.Mw         = Moment Magnitude
    faultprop.faultstyle = UNKNOWN, STRIKESLIP, NORMAL or REVERSE

    period = Period (sec); Use Period = -1 for PGV computation
                    Use None to output the array of median with original periods
                    (no interpolation)

    region      = 0 for global (incl. Taiwan)
                = 1 for California
                = 2 for Japan
                = 3 for China or Turkey
                = 4 for Italy

    Output Variables
    median        = Median amplitude prediction

    sigma         = NATURAL LOG standard deviation 
    """
    M = faultprop.Mw
    z1 = siteprop.z1p0
    vs30 = siteprop.vs30
    if im == "PGV":
        period = -1
    if im == "PGA":
        period = 0

    # compute median and sigma with user-defined period
    try:
        period[0]
    except TypeError:
        period = [period]
    median = np.zeros(len(period))
    sigma = np.zeros((len(period), 3))
    for i, Ti in enumerate(period):
        if not np.isclose(periods, Ti, atol=0.0001).any():
            # user defined period requires interpolation
            ip_high = np.argmin(periods < Ti)
            ip_low = ip_high - 1

            y_low = BSSA_2014_sub(
                M, ip_low, siteprop.Rjb, faultprop.faultstyle, region, z1, vs30
            )
            y_high = BSSA_2014_sub(
                M, ip_high, siteprop.Rjb, faultprop.faultstyle, region, z1, vs30
            )
            median[i], sigma[i] = interpolate_to_closest(Ti, periods[ip_high], periods[ip_low], y_high, y_low)
        else:
            ip_T = np.argmin(np.abs(periods - Ti))
            median[i], sigma[i] = BSSA_2014_sub(
                M, ip_T, siteprop.Rjb, faultprop.faultstyle, region, z1, vs30
            )

    if len(period) == 1:
        return median[0], sigma[0]
    return list(zip(median, sigma))