def test_fromTrace():
    xp0 = [0.0]
    xp1 = [0.0]
    yp0 = [0.0]
    yp1 = [0.05]
    zp = [0.0]
    widths = [10.0]
    dips = [45.0]

    rupture = QuadRupture.fromTrace(
        xp0, yp0, xp1, yp1, zp, widths,
        dips, reference='From J Smith, (personal communication)')
    fstr = io.StringIO()
    rupture.writeTextFile(fstr)

    xp0 = [-121.81529, -121.82298]
    xp1 = [-121.82298, -121.83068]
    yp0 = [37.73707, 37.74233]
    yp1 = [37.74233, 37.74758]
    zp = [10, 15]
    widths = [15.0, 20.0]
    dips = [30.0, 45.0]
    rupture = QuadRupture.fromTrace(
        xp0, yp0, xp1, yp1, zp, widths,
        dips, reference='From J Smith, (personal communication)')
Exemple #2
0
def test_fromTrace():
    xp0 = [0.0]
    xp1 = [0.0]
    yp0 = [0.0]
    yp1 = [0.05]
    zp = [0.0]
    widths = [10.0]
    dips = [45.0]

    # Rupture requires an origin even when not used:
    origin = Origin({'id':'test','lat':0,'lon':0,'depth':5.0,'mag':7.0})
    rupture = QuadRupture.fromTrace(
        xp0, yp0, xp1, yp1, zp, widths,
        dips, origin,
        reference='From J Smith, (personal communication)')
    fstr = io.StringIO()
    rupture.writeTextFile(fstr)

    xp0 = [-121.81529, -121.82298]
    xp1 = [-121.82298, -121.83068]
    yp0 = [37.73707, 37.74233]
    yp1 = [37.74233, 37.74758]
    zp = [10, 15]
    widths = [15.0, 20.0]
    dips = [30.0, 45.0]
    rupture = QuadRupture.fromTrace(
        xp0, yp0, xp1, yp1, zp, widths,
        dips, origin, 
        reference='From J Smith, (personal communication)')
def test_misc():
    # Make a rupture
    lat0 = np.array([34.1])
    lon0 = np.array([-118.2])
    lat1 = np.array([34.2])
    lon1 = np.array([-118.15])
    z = np.array([1.0])
    W = np.array([3.0])
    dip = np.array([30.])
    flt = QuadRupture.fromTrace(lon0, lat0, lon1, lat1, z, W, dip)
    fm = flt.getRuptureAsMesh()
    fa = flt.getRuptureAsArrays()
    ref = flt.getReference()
def test_EdgeRupture_vs_QuadRupture():
    # Sites stuff
    sites = Sites.fromCenter(-122.15, 37.15, 1.5, 1.5, 0.01, 0.01)
    sm_dict = sites._GeoDict
    west = sm_dict.xmin
    east = sm_dict.xmax
    south = sm_dict.ymin
    north = sm_dict.ymax
    nx = sm_dict.nx
    ny = sm_dict.ny
    lats = np.linspace(north, south, ny)
    lons = np.linspace(west, east, nx)
    lon, lat = np.meshgrid(lons, lats)
    dep = np.zeros_like(lon)

    # Construct QuadRupture
    xp0 = np.array([-122.0, -122.5])
    yp0 = np.array([37.1, 37.4])
    xp1 = np.array([-121.7, -122.3])
    yp1 = np.array([37.2, 37.2])
    zp = np.array([0, 6])
    widths = np.array([30, 20])
    dips = np.array([30, 40])

    origin = Origin({"lat": 0, "lon": 0, "depth": 0, "mag": 7.2, "id": ""})
    qrup = QuadRupture.fromTrace(xp0, yp0, xp1, yp1, zp, widths, dips, origin)
    rrup_q = qrup.computeRrup(lon, lat, dep)
    rjb_q = qrup.computeRjb(lon, lat, dep)

    # Construct equivalent EdgeRupture
    toplons = np.array([-122.0, -121.7, -122.5, -122.3])
    toplats = np.array([37.1, 37.2, 37.4, 37.2])
    topdeps = np.array([0, 0, 6, 6])
    botlons = np.array([-121.886864, -121.587568, -122.635467, -122.435338])
    botlats = np.array([36.884527, 36.984246, 37.314035, 37.114261])
    botdeps = np.array([15.0000, 14.9998, 18.8558, 18.8559])
    group_index = [0, 0, 1, 1]

    erup = EdgeRupture.fromArrays(toplons, toplats, topdeps, botlons, botlats, botdeps, origin, group_index)
    rrup_e = erup.computeRrup(lon, lat, dep)
    rjb_e = erup.computeRjb(lon, lat, dep)

    # Check that QuadRupture and EdgeRupture give the same result
    # (we check the absolute values of QuadRupture elsewhere)
    np.testing.assert_allclose(rrup_e, rrup_q, atol=0.35)
    np.testing.assert_allclose(rjb_e, rjb_q, atol=0.35)
Exemple #5
0
def test_exceptions():
    vs30file = os.path.join(shakedir, 'tests/data/Vs30_test.grd')
    cx = -118.2
    cy = 34.1
    dx = 0.0083
    dy = 0.0083
    xspan = 0.0083 * 5
    yspan = 0.0083 * 5
    site = Sites.fromCenter(cx, cy, xspan, yspan, dx, dy,
                            vs30File=vs30file,
                            padding=True, resample=False)
    # Make souce instance
    lat0 = np.array([34.1])
    lon0 = np.array([-118.2])
    lat1 = np.array([34.2])
    lon1 = np.array([-118.15])
    z = np.array([1.0])
    W = np.array([3.0])
    dip = np.array([30.])

    # Rupture requires an origin even when not used:
    origin = Origin({'id':'test','lat':0,'lon':0,'depth':5.0,'mag':7.0})
    rup = QuadRupture.fromTrace(lon0, lat0, lon1, lat1, z, W, dip, 
                                origin)

    event = {'lat': 34.1, 'lon': -118.2, 'depth': 1, 'mag': 6,
             'id': '', 'locstring': '', 'type': 'U', 'mech':'RS',
             'rake':90, 'timezone': 'UTC'}
    origin = Origin(event)

    gmpelist = ["Primate"]
    with pytest.raises(Exception) as e:
        dists = Distance.fromSites(gmpelist, origin, site, rup)

    gmpelist = [AbrahamsonEtAl2014()]
    sctx = site.getSitesContext()
    dist_types = ['repi', 'rhypo', 'rjb', 'rrup', 'rx', 'ry', 'ry0', 'U', 'V']
    with pytest.raises(Exception) as e:
        dists = get_distance(dist_types, sctx.lats, sctx.lons,
                             np.zeros_like(sctx.lons), rup)

    dist_types = ['repi', 'rhypo', 'rjb', 'rrup', 'rx', 'ry', 'ry0', 'U', 'T']
    with pytest.raises(Exception) as e:
        dists = get_distance(dist_types, sctx.lats, sctx.lons[0:4,],
                             np.zeros_like(sctx.lons), rup)
def test_slip():
    # Make a rupture
    lat0 = np.array([34.1])
    lon0 = np.array([-118.2])
    lat1 = np.array([34.2])
    lon1 = np.array([-118.15])
    z = np.array([1.0])
    W = np.array([3.0])
    dip = np.array([30.])
    flt = QuadRupture.fromTrace(lon0, lat0, lon1, lat1, z, W, dip)

    slp = get_quad_slip(flt.getQuadrilaterals()[0], 30).getArray()
    slpd = np.array([0.80816457,  0.25350787,  0.53160491])
    np.testing.assert_allclose(slp, slpd)

    slp = get_local_unit_slip_vector(22, 30, 86).getArray()
    slpd = np.array([0.82714003,  0.38830563,  0.49878203])
    np.testing.assert_allclose(slp, slpd)
Exemple #7
0
def test_slip():
    # Rupture requires an origin even when not used:
    origin = Origin({'id':'test','lat':0,'lon':0,'depth':5.0,'mag':7.0})
    # Make a rupture
    lat0 = np.array([34.1])
    lon0 = np.array([-118.2])
    lat1 = np.array([34.2])
    lon1 = np.array([-118.15])
    z = np.array([1.0])
    W = np.array([3.0])
    dip = np.array([30.])
    rup = QuadRupture.fromTrace(lon0, lat0, lon1, lat1, z, W, dip, origin)

    slp = get_quad_slip(rup.getQuadrilaterals()[0], 30).getArray()
    slpd = np.array([0.80816457,  0.25350787,  0.53160491])
    np.testing.assert_allclose(slp, slpd)

    slp = get_local_unit_slip_vector(22, 30, 86).getArray()
    slpd = np.array([0.82714003,  0.38830563,  0.49878203])
    np.testing.assert_allclose(slp, slpd)
Exemple #8
0
def test_distance_from_sites_origin():
    # Make sites instance
    vs30file = os.path.join(shakedir, 'tests/data/Vs30_test.grd')
    cx = -118.2
    cy = 34.1
    dx = 0.0083
    dy = 0.0083
    xspan = 0.0083 * 5
    yspan = 0.0083 * 5
    site = Sites.fromCenter(cx, cy, xspan, yspan, dx, dy,
                            vs30File=vs30file,
                            padding=True, resample=False)
    # Make souce instance
    lat0 = np.array([34.1])
    lon0 = np.array([-118.2])
    lat1 = np.array([34.2])
    lon1 = np.array([-118.15])
    z = np.array([1.0])
    W = np.array([3.0])
    dip = np.array([30.])

    event = {'lat': 34.1, 'lon': -118.2, 'depth': 1, 'mag': 6,
             'id': '', 'locstring': '', 'type': 'ALL',
             'timezone': 'UTC'}
    origin = Origin(event)

    rup = QuadRupture.fromTrace(lon0, lat0, lon1, lat1, z, W, dip, origin)
    gmpelist = [AbrahamsonEtAl2014(), BergeThierryEtAl2003SIGMA()]
    dists = Distance.fromSites(gmpelist, site, rup)
    dctx = dists.getDistanceContext()

    rhypo = np.array([[ 3.74498133,  3.32896405,  3.05225679,  2.95426722,  3.05225679,
         3.32896405,  3.74498133],
       [ 3.11965436,  2.60558436,  2.24124201,  2.10583262,  2.24124201,
         2.60558436,  3.11965436],
       [ 2.67523213,  2.05265767,  1.564393  ,  1.36331682,  1.564393  ,
         2.05265767,  2.67523213],
       [ 2.50973226,  1.83166664,  1.26045653,  1.        ,  1.26045653,
         1.83166664,  2.50973226],
       [ 2.67542717,  2.05277065,  1.56443006,  1.36331682,  1.56443006,
         2.05277065,  2.67542717],
       [ 3.11998886,  2.60576236,  2.24129374,  2.10583262,  2.24129374,
         2.60576236,  3.11998886],
       [ 3.74539929,  3.32917303,  3.05231378,  2.95426722,  3.05231378,
         3.32917303,  3.74539929]])
    np.testing.assert_allclose(
        rhypo, dctx.rhypo, rtol=0, atol=0.01)

    rx = np.array([[ -3.18894050e+00,  -2.48001769e+00,  -1.77111874e+00,
         -1.06224366e+00,  -3.53392480e-01,   3.55434794e-01,
          1.06423815e+00],
       [ -2.83506890e+00,  -2.12607622e+00,  -1.41710740e+00,
         -7.08162466e-01,   7.58576362e-04,   7.09655709e-01,
          1.41852892e+00],
       [ -2.48119723e+00,  -1.77213470e+00,  -1.06309603e+00,
         -3.54081243e-01,   3.54909645e-01,   1.06387662e+00,
          1.77281967e+00],
       [ -2.12732550e+00,  -1.41819312e+00,  -7.09084619e-01,
          2.56774082e-12,   7.09060719e-01,   1.41809752e+00,
          2.12711040e+00],
       [ -1.77345370e+00,  -1.06425151e+00,  -3.55073182e-01,
          3.54081255e-01,   1.06321179e+00,   1.77231841e+00,
          2.48140110e+00],
       [ -1.41958186e+00,  -7.10309855e-01,  -1.06172493e-03,
          7.08162516e-01,   1.41736285e+00,   2.12653927e+00,
          2.83569175e+00],
       [ -1.06570997e+00,  -3.56368176e-01,   3.52949744e-01,
          1.06224377e+00,   1.77151390e+00,   2.48076010e+00,
          3.18998236e+00]])

    np.testing.assert_allclose(
        rx, dctx.rx, rtol=0, atol=0.01)

    rjb = np.array([[  3.19372137e+00,   2.48373511e+00,   1.77377308e+00,
          1.06383562e+00,   3.53925643e-01,   2.25816823e-03,
          2.45009861e-03],
       [  2.83931844e+00,   2.12926243e+00,   1.41923064e+00,
          7.09223517e-01,   1.57594916e-03,   1.86044244e-03,
          2.05239165e-03],
       [  2.48510934e+00,   1.77479025e+00,   1.06468863e+00,
          3.54611655e-01,   1.04375185e-03,   1.32827303e-03,
          1.52024106e-03],
       [  2.30690967e+00,   1.53793979e+00,   7.68969896e-01,
          5.88918451e-12,   3.77111295e-04,   6.61660373e-04,
          8.53647223e-04],
       [  2.48531877e+00,   1.79442084e+00,   1.20242597e+00,
          8.54793253e-01,   5.62052963e-01,   2.69254693e-01,
          5.26105100e-05],
       [  2.95646628e+00,   2.40489915e+00,   2.00231070e+00,
          1.70958533e+00,   1.41681634e+00,   1.12398937e+00,
          8.63761551e-01],
       [  3.60741953e+00,   3.17112489e+00,   2.85711592e+00,
          2.56437623e+00,   2.27157856e+00,   1.97872291e+00,
          1.78518260e+00]])

    np.testing.assert_allclose(
        rjb, dctx.rjb, rtol=0, atol=0.01)

    ry0 = np.array([[  0.00000000e+00,   0.00000000e+00,   0.00000000e+00,
          0.00000000e+00,   0.00000000e+00,   0.00000000e+00,
          0.00000000e+00],
       [  0.00000000e+00,   0.00000000e+00,   0.00000000e+00,
          0.00000000e+00,   0.00000000e+00,   0.00000000e+00,
          0.00000000e+00],
       [  2.29490054e-02,   0.00000000e+00,   0.00000000e+00,
          0.00000000e+00,   0.00000000e+00,   0.00000000e+00,
          0.00000000e+00],
       [  8.79341006e-01,   5.86285236e-01,   2.93171565e-01,
          6.21003581e-12,   0.00000000e+00,   0.00000000e+00,
          0.00000000e+00],
       [  1.73573289e+00,   1.44264826e+00,   1.14950573e+00,
          8.56305300e-01,   5.63046975e-01,   2.69730762e-01,
          0.00000000e+00],
       [  2.59212463e+00,   2.29901116e+00,   2.00583977e+00,
          1.71261048e+00,   1.41932329e+00,   1.12597821e+00,
          8.32575235e-01],
       [  3.44851622e+00,   3.15537391e+00,   2.86217367e+00,
          2.56891553e+00,   2.27559947e+00,   1.98222553e+00,
          1.68879368e+00]])

    np.testing.assert_allclose(
        ry0, dctx.ry0, rtol=0, atol=0.01)

    rrup = np.array([[ 3.34678672,  2.67788811,  2.03697073,  1.46129187,  1.06271102,
         1.06352692,  1.40073832],
       [ 3.01030105,  2.3526499 ,  1.73673635,  1.22706347,  1.00157564,
         1.22283363,  1.57764099],
       [ 2.67858182,  2.03712377,  1.46095502,  1.06170931,  1.06220616,
         1.39958479,  1.75442695],
       [ 2.51415965,  1.8343632 ,  1.26143652,  1.        ,  1.2212501 ,
         1.57621925,  1.9310962 ],
       [ 2.67877609,  2.05412785,  1.56384179,  1.3617346 ,  1.50608502,
         1.77308319,  2.10764873],
       [ 3.12078859,  2.6043486 ,  2.23799413,  2.09885629,  2.11696797,
         2.23191013,  2.4299612 ],
       [ 3.74318473,  3.32482368,  3.04635272,  2.9183523 ,  2.86659485,
         2.88815116,  2.98141559]])

    np.testing.assert_allclose(
        rrup, dctx.rrup, rtol=0, atol=0.01)