Exemplo n.º 1
0
def _test(vs30file=None):
    print('Testing creation of Sites object with Vs30 file of %s...' % vs30file)
    cx = -118.2
    cy = 34.1
    dx = 0.0083
    dy = 0.0083
    xspan = 3.0
    yspan = 3.0
    mysite = Sites.createFromCenter(cx,cy,xspan,yspan,dx,dy,vs30File=vs30file,
                                    padding=True,resample=False)
    sc = mysite.getSitesContext()
    
    cx = -118.2
    cy = 83
    dx = 0.0083
    dy = 0.0083
    xspan = 3.0
    yspan = 3.0
    mysite = Sites.createFromCenter(cx,cy,xspan,yspan,dx,dy,vs30File=vs30file,padding=True,resample=False)

    xmin = 116.234
    xmax = 120.876
    ymin = 20.12345
    ymax = 24.75435
    dx = 0.0083
    dy = 0.0083
    mysite = Sites.createFromBounds(xmin,xmax,ymin,ymax,dx,dy,vs30File=vs30file,padding=False,resample=False)
    print('Passed creation of Sites object with Vs30 file of %s' % vs30file)
Exemplo n.º 2
0
def _test(vs30file=None):
    print('Testing creation of Sites object with Vs30 file of %s...' %
          vs30file)
    cx = -118.2
    cy = 34.1
    dx = 0.0083
    dy = 0.0083
    xspan = 3.0
    yspan = 3.0
    mysite = Sites.createFromCenter(cx,
                                    cy,
                                    xspan,
                                    yspan,
                                    dx,
                                    dy,
                                    vs30File=vs30file,
                                    padding=True,
                                    resample=False)
    sc = mysite.getSitesContext()

    cx = -118.2
    cy = 83
    dx = 0.0083
    dy = 0.0083
    xspan = 3.0
    yspan = 3.0
    mysite = Sites.createFromCenter(cx,
                                    cy,
                                    xspan,
                                    yspan,
                                    dx,
                                    dy,
                                    vs30File=vs30file,
                                    padding=True,
                                    resample=False)

    xmin = 116.234
    xmax = 120.876
    ymin = 20.12345
    ymax = 24.75435
    dx = 0.0083
    dy = 0.0083
    mysite = Sites.createFromBounds(xmin,
                                    xmax,
                                    ymin,
                                    ymax,
                                    dx,
                                    dy,
                                    vs30File=vs30file,
                                    padding=False,
                                    resample=False)
    print('Passed creation of Sites object with Vs30 file of %s' % vs30file)
Exemplo n.º 3
0
    def set_sites_depth_parameters(sites, gmpe):
        """
        Need to select the appropriate z1pt0 value for different GMPEs.
        Note that these are required site parameters, so even though
        OQ has these equations built into the class in most cases. 
        I have submitted an issue to OQ requesting subclasses of these
        methods that do not require the depth parameters in the
        SitesContext to make this easier.

        :param sites:
            A sites context.
        :param gmpe:
            A GMPE instance.

        :returns:
            A sites context with the depth parameters set for the
            requested GMPE. 
        """

        sites = Sites._addDepthParameters(sites)

        if gmpe == 'AbrahamsonEtAl2014()':
            sites.z1pt0 = sites.z1pt0_ask14_cal
        if gmpe == 'ChiouYoungs2014()':
            # Also BooreEtAl2014() if using subclass with depth parameter
            sites.z1pt0 = sites.z1pt0_cy14_cal
        if gmpe == 'CampbellBozorgnia2014()':
            sites.z2pt5 = sites.z2pt5_cb14_cal
        if gmpe == 'ChiouYoungs2008()':
            sites.z1pt0 = sites.z1pt0_cy08
        if gmpe == 'CampbellBozorgnia2008()':
            sites.z2pt5 = sites.z2pt5_cb07

        return sites
Exemplo n.º 4
0
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)
Exemplo n.º 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)
Exemplo n.º 6
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.])

    flt = Fault.fromTrace(lon0, lat0, lon1, lat1, z, W, dip)
    event = {'lat': 34.1, 'lon': -118.2, 'depth': 1, 'mag': 6,
             'id': '', 'locstring': '', 'type': 'U', 'mech':'RS',
             'rake':90,
             'time': ShakeDateTime.utcfromtimestamp(int(time.time())),
             'timezone': 'UTC'}
    source = Source(event, flt)

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

    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), source)

    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), source)
Exemplo n.º 7
0
def test(vs30file=None):
    vs30file = os.path.join(shakedir, 'data/Vs30_test.grd')
    cx = -118.2
    cy = 34.1
    dx = 0.0083
    dy = 0.0083
    xspan = 0.0083 * 5
    yspan = 0.0083 * 5
    mysite = Sites.createFromCenter(cx, cy, xspan, yspan, dx, dy,
                                    vs30File=vs30file, padding=True,
                                    resample=False)
    grd = mysite.getVs30Grid().getData()
    grd_target = np.array(
      [[ 409.14199829,  428.24468994,  395.90026855,  426.31658936,
         427.53845215,  433.40481567,  436.59918213,  440.43664551,
         413.60662842],
       [ 423.60855103,  426.64892578,  398.89712524,  428.88549805,
         428.78335571,  428.58578491,  430.54354858,  433.59750366,
         415.18811035],
       [ 391.67398071,  426.20635986,  425.57946777,  428.21954346,
         426.06726074,  421.86233521,  423.53192139,  426.25296021,
         365.48190308],
       [ 385.00396729,  428.14602661,  430.05944824,  429.3427124 ,
         426.13626099,  409.76391602,  383.07299805,  372.39117432,
         426.48486328],
       [ 356.68756104,  432.64077759,  434.55209351,  432.21600342,
         395.53771973,  419.31866455,  421.67749023,  426.23449707,
         427.32818604],
       [ 337.0546875 ,  345.14605713,  403.78097534,  385.49118042,
         413.04779053,  428.22869873,  427.00268555,  426.8951416 ,
         425.62023926],
       [ 403.78884888,  336.48217773,  347.82220459,  425.96798706,
         432.0640564 ,  429.40097046,  427.74179077,  427.00006104,
         419.5062561 ],
       [ 420.07458496,  330.57504272,  392.33255005,  430.33862305,
         432.01391602,  429.43969727,  427.30435181,  425.96151733,
         426.15856934]])

    np.testing.assert_allclose(grd, grd_target)

    sc = mysite.getSitesContext()
    scsamp = mysite.sampleFromSites(np.array([34.1, 34.111]),
                                    np.array([-118.2, -118.222]))

    xmin = -118.2
    xmax = -118.12
    ymin = 34.05
    ymax = 34.1
    dx = 0.0083
    dy = 0.0083
    mysite = Sites.createFromBounds(xmin, xmax, ymin, ymax, dx, dy,
                                    vs30File=vs30file, padding=False,
                                    resample=False)
    grd = mysite.getVs30Grid().getData()
    grd_target = np.array(
      [[ 426.13626099,  409.76391602,  383.07299805,  372.39117432,
         426.48486328,  422.45065308,  417.21685791,  410.43737793,
         405.33862305,  400.5239563 ,  396.03030396],
       [ 395.53771973,  419.31866455,  421.67749023,  426.23449707,
         427.32818604,  424.84860229,  415.17590332,  407.5760498 ,
         404.54788208,  402.28500366,  398.95913696],
       [ 413.04779053,  428.22869873,  427.00268555,  426.8951416 ,
         425.62023926,  419.60952759,  411.7961731 ,  407.53509521,
         406.22122192,  405.31622314,  402.92575073],
       [ 432.0640564 ,  429.40097046,  427.74179077,  427.00006104,
         419.5062561 ,  411.10830688,  407.48901367,  406.53305054,
         406.59658813,  406.24887085,  406.17044067],
       [ 432.01391602,  429.43969727,  427.30435181,  425.96151733,
         426.15856934,  427.56121826,  397.67102051,  399.21054077,
         404.54968262,  407.18515015,  410.00823975],
       [ 426.76913452,  428.86270142,  425.99606323,  423.5692749 ,
         423.59835815,  425.92758179,  408.44885254,  406.55810547,
         409.06945801,  413.75210571,  417.71130371],
       [ 423.1892395 ,  427.91104126,  424.53796387,  419.47485352,
         418.177948  ,  424.14065552,  428.57913208,  432.95300293,
         427.77731323,  431.46524048,  442.75540161],
       [ 410.56729126,  423.15557861,  424.48355103,  419.27658081,
         418.60211182,  423.86721802,  428.06176758,  432.42089844,
         438.54446411,  448.37237549,  462.25509644],
       [ 405.86877441,  414.27923584,  419.53878784,  396.18017578,
         414.54452515,  419.80047607,  425.19824219,  424.48919678,
         424.72061157,  431.52270508,  432.84347534]])
    np.testing.assert_allclose(grd, grd_target)
Exemplo n.º 8
0
def test_virtualipe():

    #
    # Set up the GMPE, IPE, and GMICE
    #
    gmpe_cy14 = ChiouYoungs2014()
    gmpe = MultiGMPE.from_list([gmpe_cy14], [1.0])
    gmice = WGRW12()
    ipe = VirtualIPE.fromFuncs(gmpe, gmice)

    #
    # Use the Calexico event info
    #
    homedir = os.path.dirname(os.path.abspath(__file__))
    datadir = os.path.abspath(os.path.join(homedir, '..', 'data',
            'eventdata', 'Calexico', 'input'))

    #
    # Read the event, origin, and rupture files and produce Rupture and Origin
    # objects
    #
    inputfile = os.path.join(datadir, 'stationlist_dat.xml')
    dyfifile = os.path.join(datadir, 'ciim3_dat.xml')
    eventfile = os.path.join(datadir, 'event.xml')
    rupturefile = os.path.join(datadir, 'wei_fault.txt')

    origin_obj = Origin.fromFile(eventfile)
    rupture_obj = read_rupture_file(origin_obj, rupturefile)
    rx = rupture_obj.getRuptureContext([gmpe])
    rx.rake = 45.

    smdx = 0.0083333333
    smdy = 0.0083333333
    lonspan = 6.0
    latspan = 4.0
    vs30filename = os.path.join(datadir, '..', 'vs30', 'vs30.grd')

    sites_obj_grid = Sites.fromCenter(
            rx.hypo_lon, rx.hypo_lat, lonspan, latspan,
            smdx, smdy, defaultVs30=760.0, vs30File=vs30filename,
            vs30measured_grid=None, padding=False, resample=False
        )

    npts = 200
    lats = np.empty(npts)
    lons = np.empty(npts)
    depths = np.zeros(npts)
    for i in range(npts):
        lats[i] = rx.hypo_lat
        lons[i] = rx.hypo_lon + i * 0.01
    lldict = {'lats': lats, 'lons': lons}

    sx = sites_obj_grid.getSitesContext(lldict=lldict, rock_vs30=760.0)

    dobj = Distance(gmpe, lons, lats, depths, rupture_obj)
    dx = dobj.getDistanceContext()

    sd_types = [oqconst.StdDev.TOTAL]
    mmi_const_vs30, mmi_sd_const_vs30 = \
            ipe.get_mean_and_stddevs(sx, rx, dx, MMI(), sd_types)

# These prints are just so a human can examine the outputs
#    print(mmi_const_vs30)
#    print(mmi_sd_const_vs30)

    sx = sites_obj_grid.getSitesContext(lldict=lldict)
    mmi_variable_vs30, mmi_sd_variable_vs30 = \
            ipe.get_mean_and_stddevs(sx, rx, dx, MMI(), sd_types)

#    print(mmi_variable_vs30)
#    print(mmi_sd_variable_vs30)

    sd_types = [oqconst.StdDev.TOTAL, oqconst.StdDev.INTRA_EVENT, 
                oqconst.StdDev.INTER_EVENT]
    mmi_variable_vs30_intra, mmi_sd_variable_vs30_intra = \
            ipe.get_mean_and_stddevs(sx, rx, dx, MMI(), sd_types)

#    print(mmi_variable_vs30_intra)
#    print(mmi_sd_variable_vs30_intra)
#    assert(0)      # Assert causes test to fail and prints to be displayed

    #
    # Try with PGA
    #
    gmpe.DEFINED_FOR_INTENSITY_MEASURE_TYPES.remove(PGV)
    gmpe.ALL_GMPES_HAVE_PGV = False
    ipe = VirtualIPE.fromFuncs(gmpe, gmice)
    mmi_pga, mmi_sd_pga = \
            ipe.get_mean_and_stddevs(sx, rx, dx, MMI(), sd_types)
    #
    # Try with SA(1.0)
    #
    gmpe.DEFINED_FOR_INTENSITY_MEASURE_TYPES.remove(PGA)
    ipe = VirtualIPE.fromFuncs(gmpe, gmice)
    mmi_psa, mmi_sd_psa = \
            ipe.get_mean_and_stddevs(sx, rx, dx, MMI(), sd_types)

    #
    # This should raise an exception because the IMT isn't MMI
    #
    with pytest.raises(ValueError) as e:
        mmi_psa, mmi_sd_psa = \
                ipe.get_mean_and_stddevs(sx, rx, dx, PGA(), sd_types)
    #
    # This should raise an exception because no valid IMTs are available
    #
    gmpe.DEFINED_FOR_INTENSITY_MEASURE_TYPES.remove(SA)
    with pytest.raises(ShakeMapException) as e:
        ipe = VirtualIPE.fromFuncs(gmpe, gmice)

    #
    # Now do a GMPE that uses Rjb instead of Rrup
    #
    gmpe_ba14 = BooreEtAl2014()
    gmpe = MultiGMPE.from_list([gmpe_ba14], [1.0])
    ipe = VirtualIPE.fromFuncs(gmpe, gmice)
    rx = rupture_obj.getRuptureContext([gmpe])
    rx.rake = 45.
    dobj = Distance(gmpe, lons, lats, depths, rupture_obj)
    dx = dobj.getDistanceContext()

    mmi_rjb, mmi_sd_rjb = \
            ipe.get_mean_and_stddevs(sx, rx, dx, MMI(), sd_types)
    
    #
    # Test the results against a known standard
    #
    savefile = os.path.abspath(os.path.join(homedir, '..', 'data',
            'eventdata', 'Calexico', 'virtualipe_test', 'savefile.npz'))

    #
    # If things change, set remake_save to True, and it will rebuild the
    # saved data file against which the comparisons are done
    # Remember to set this back to False once you've remade the test datafile
    #
    remake_save = False
    if remake_save:
        np.savez_compressed(savefile,
                mmi_const_vs30 = mmi_const_vs30,
                mmi_sd_const_vs30 = mmi_sd_const_vs30[0],
                mmi_variable_vs30 = mmi_variable_vs30,
                mmi_sd_variable_vs30 = mmi_sd_variable_vs30[0],
                mmi_variable_vs30_intra = mmi_variable_vs30_intra,
                mmi_sd_variable_vs30_total = mmi_sd_variable_vs30_intra[0],
                mmi_sd_variable_vs30_intra = mmi_sd_variable_vs30_intra[1],
                mmi_sd_variable_vs30_inter = mmi_sd_variable_vs30_intra[2],
                mmi_pga = mmi_pga,
                mmi_sd_pga = mmi_sd_pga[0],
                mmi_psa = mmi_psa,
                mmi_sd_psa = mmi_sd_psa[0],
                mmi_rjb = mmi_rjb,
                mmi_sd_rjb = mmi_sd_rjb[0])

    td = np.load(savefile)

    assert(np.allclose(td['mmi_const_vs30'], mmi_const_vs30))
    assert(np.allclose(td['mmi_sd_const_vs30'], mmi_sd_const_vs30[0]))
    assert(np.allclose(td['mmi_variable_vs30'], mmi_variable_vs30))
    assert(np.allclose(td['mmi_sd_variable_vs30'], mmi_sd_variable_vs30[0]))
    assert(np.allclose(td['mmi_variable_vs30_intra'], mmi_variable_vs30_intra))
    assert(np.allclose(td['mmi_sd_variable_vs30_total'], 
        mmi_sd_variable_vs30_intra[0]))
    assert(np.allclose(td['mmi_sd_variable_vs30_intra'], 
        mmi_sd_variable_vs30_intra[1]))
    assert(np.allclose(td['mmi_sd_variable_vs30_inter'], 
        mmi_sd_variable_vs30_intra[2]))
    assert(np.allclose(td['mmi_pga'], mmi_pga))
    assert(np.allclose(td['mmi_sd_pga'], mmi_sd_pga[0]))
    assert(np.allclose(td['mmi_psa'], mmi_psa))
    assert(np.allclose(td['mmi_sd_psa'], mmi_sd_psa[0]))
    assert(np.allclose(td['mmi_rjb'], mmi_rjb))
    assert(np.allclose(td['mmi_sd_rjb'], mmi_sd_rjb[0]))

    # The total uncertainties should be greater than the intra-event
    assert(np.all(mmi_sd_variable_vs30[0] > mmi_sd_variable_vs30_intra[1]))

    # The combined intra and inter-event uncertainty should be equal
    # to the total
    tot = np.sqrt(mmi_sd_variable_vs30_intra[1]**2 + mmi_sd_variable_vs30_intra[2]**2)
    assert(np.allclose(tot, mmi_sd_variable_vs30_intra[0], rtol=1e-2))
Exemplo n.º 9
0
def test_sites(vs30file=None):
    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
    mysite = Sites.fromCenter(cx, cy, xspan, yspan, dx, dy,
                                    vs30File=vs30file, padding=True,
                                    resample=False)
    grd = mysite.getVs30Grid().getData()
    grd_target = np.array([[ 426.64892578,  398.89712524,  428.88549805,  428.78335571,
         428.58578491,  430.54354858,  433.59750366],
       [ 426.20635986,  425.57946777,  428.21954346,  426.06726074,
         421.86233521,  423.53192139,  426.25296021],
       [ 428.14602661,  430.05944824,  429.3427124 ,  426.13626099,
         409.76391602,  383.07299805,  372.39117432],
       [ 432.64077759,  434.55209351,  432.21600342,  395.53771973,
         419.31866455,  421.67749023,  426.23449707],
       [ 345.14605713,  403.78097534,  385.49118042,  413.04779053,
         428.22869873,  427.00268555,  426.8951416 ],
       [ 336.48217773,  347.82220459,  425.96798706,  432.0640564 ,
         429.40097046,  427.74179077,  427.00006104],
       [ 330.57504272,  392.33255005,  430.33862305,  432.01391602,
         429.43969727,  427.30435181,  425.96151733]])
    np.testing.assert_allclose(grd, grd_target)

    sc = mysite.getSitesContext()
    scr = mysite.getSitesContext(rock_vs30 = 760.0)

    grd = sc.backarc
    grdt = np.array([[False, False, False, False, False, False, False],
       [False, False, False, False, False, False, False],
       [False, False, False, False, False, False, False],
       [False, False, False, False, False, False, False],
       [False, False, False, False, False, False, False],
       [False, False, False, False, False, False, False],
       [False, False, False, False, False, False, False]], dtype=bool)
    np.testing.assert_allclose(grd, grdt)

    grd = sc.lats
    grdt = np.array([ 34.075     ,  34.08333333,  34.09166667,  34.1       ,
        34.10833333,  34.11666667,  34.125     ])
    np.testing.assert_allclose(grd, grdt)

    grd = sc.lons
    grdt = np.array([-118.225     , -118.21666667, -118.20833333, -118.2       ,
       -118.19166667, -118.18333333, -118.175     ])
    np.testing.assert_allclose(grd, grdt)

    grd = sc.vs30
    grdt = np.array([[ 426.64892578,  398.89712524,  428.88549805,  428.78335571,
         428.58578491,  430.54354858,  433.59750366],
       [ 426.20635986,  425.57946777,  428.21954346,  426.06726074,
         421.86233521,  423.53192139,  426.25296021],
       [ 428.14602661,  430.05944824,  429.3427124 ,  426.13626099,
         409.76391602,  383.07299805,  372.39117432],
       [ 432.64077759,  434.55209351,  432.21600342,  395.53771973,
         419.31866455,  421.67749023,  426.23449707],
       [ 345.14605713,  403.78097534,  385.49118042,  413.04779053,
         428.22869873,  427.00268555,  426.8951416 ],
       [ 336.48217773,  347.82220459,  425.96798706,  432.0640564 ,
         429.40097046,  427.74179077,  427.00006104],
       [ 330.57504272,  392.33255005,  430.33862305,  432.01391602,
         429.43969727,  427.30435181,  425.96151733]])
    np.testing.assert_allclose(grd, grdt)

    grd = scr.vs30
    grdt = np.array([[ 760.,  760.,  760.,  760.,  760.,  760.,  760.],
       [ 760.,  760.,  760.,  760.,  760.,  760.,  760.],
       [ 760.,  760.,  760.,  760.,  760.,  760.,  760.],
       [ 760.,  760.,  760.,  760.,  760.,  760.,  760.],
       [ 760.,  760.,  760.,  760.,  760.,  760.,  760.],
       [ 760.,  760.,  760.,  760.,  760.,  760.,  760.],
       [ 760.,  760.,  760.,  760.,  760.,  760.,  760.]])
    np.testing.assert_allclose(grd, grdt)

    grd = sc.vs30measured
    grdt = np.array([[False, False, False, False, False, False, False],
       [False, False, False, False, False, False, False],
       [False, False, False, False, False, False, False],
       [False, False, False, False, False, False, False],
       [False, False, False, False, False, False, False],
       [False, False, False, False, False, False, False],
       [False, False, False, False, False, False, False]], dtype=bool)
    np.testing.assert_allclose(grd, grdt)

    grd = sc.z1pt0_ask14_cal
    grdt = np.array([[ 335.06579012,  366.39725582,  332.4593083 ,  332.57855835,
         332.80916279,  330.52077553,  326.93706615],
       [ 335.58036296,  336.30856215,  333.23643861,  335.74201097,
         340.60915547,  338.68122322,  335.52619949],
       [ 333.32217548,  331.08730312,  331.92526979,  335.66183031,
         354.37798647,  383.19730994,  394.00166561],
       [ 328.06152136,  325.81357093,  328.56025522,  370.03738338,
         343.53423548,  340.82221914,  335.54765968],
       [ 419.3225465 ,  361.03999163,  380.68893324,  350.67806177,
         333.2257608 ,  334.65418562,  334.77934134],
       [ 426.64586941,  416.9870982 ,  335.85735317,  328.73858131,
         331.85719411,  333.79341356,  334.65724021],
       [ 431.42758271,  373.4746626 ,  330.76064671,  328.79741743,
         331.81193751,  334.30299304,  335.86486938]])
    np.testing.assert_allclose(grd, grdt)

    grd = sc.z1pt0_cy08
    grdt = np.array([[ 183.2043947 ,  217.27787758,  180.56690603,  180.68687904,
         180.91907101,  178.625999  ,  175.08452094],
       [ 183.72884833,  184.47314285,  181.34994816,  183.89385557,
         188.91901585,  186.91536614,  183.67358657],
       [ 181.43651087,  179.19139187,  180.03044953,  183.81199342,
         203.71493023,  237.03939223,  250.05192732],
       [ 176.18920323,  173.98674225,  176.68107716,  221.49002942,
         191.99154431,  189.14149784,  183.69548028],
       [ 280.25774719,  211.16371072,  234.04298229,  199.65723106,
         181.33916991,  182.78577761,  182.91298179],
       [ 288.5669674 ,  277.54780981,  184.01166928,  176.85723522,
         179.96216197,  181.91290358,  182.78888133],
       [ 293.80330679,  225.506479  ,  178.86520526,  176.91538893,
         179.91677656,  182.42922842,  184.01934871]])
    np.testing.assert_allclose(grd, grdt)

    grd = sc.z1pt0_cy14_cal
    grdt = np.array([[ 322.09231215,  357.07647045,  319.22097485,  319.3522119 ,
         319.60603217,  317.08933532,  313.15733537],
       [ 322.65987959,  323.46347258,  320.07644714,  322.83822344,
         328.21884905,  326.08502532,  322.60012698],
       [ 320.17085962,  317.71195569,  318.63340828,  322.74975843,
         343.55342441,  376.19315199,  388.62006436],
       [ 314.38985785,  311.92697475,  314.93687894,  361.19727923,
         331.46256533,  328.4548676 ,  322.62380134],
       [ 418.15243574,  351.03313981,  373.32295288,  339.41631214,
         320.0646893 ,  321.63848529,  321.7764637 ],
       [ 426.80110483,  415.40447342,  322.96549285,  315.13252356,
         318.55852723,  320.68989724,  321.64185267],
       [ 432.47426567,  365.09924657,  317.35292206,  315.19707981,
         318.50874868,  321.25138528,  322.9737867 ]])
    np.testing.assert_allclose(grd, grdt)

    grd = sc.z2pt5_cb07
    grdt = np.array([[ 1177.61979893,  1300.11396989,  1168.13802718,  1168.56933015,
         1169.4040603 ,  1161.16046639,  1148.4288528 ],
       [ 1179.50520975,  1182.18094855,  1170.95306363,  1180.09841078,
         1198.16386197,  1190.96074128,  1179.30654372],
       [ 1171.26425658,  1163.19305376,  1166.20946607,  1179.80411634,
         1251.35517419,  1371.15661506,  1417.9366787 ],
       [ 1152.40018562,  1144.48233838,  1154.16847239,  1315.25665576,
         1209.20960179,  1198.96368474,  1179.3852516 ],
       [ 1526.52660116,  1278.13354004,  1360.38452132,  1236.76774567,
         1170.91431583,  1176.11487052,  1176.57216955],
       [ 1556.3982478 ,  1516.78437627,  1180.52195107,  1154.8017606 ,
         1165.96397227,  1172.97688837,  1176.12602836],
       [ 1575.22288791,  1329.69579201,  1162.02041292,  1155.01082322,
         1165.80081172,  1174.83307617,  1180.5495586 ]])
    np.testing.assert_allclose(grd, grdt)

    grd = sc.z2pt5_cb14_cal
    grdt = np.array([[ 1.17466154,  1.26861168,  1.1676564 ,  1.16797461,  1.16859058,
         1.16251358,  1.15315136],
       [ 1.17605704,  1.17803908,  1.16973403,  1.17649629,  1.18992131,
         1.18455663,  1.17590996],
       [ 1.16996381,  1.16401074,  1.166234  ,  1.17627836,  1.230198  ,
         1.32873844,  1.37243028],
       [ 1.15606906,  1.15025389,  1.15736893,  1.2809454 ,  1.19818264,
         1.19051805,  1.17596823],
       [ 1.49705669,  1.25107322,  1.31920733,  1.21901552,  1.16970542,
         1.1735483 ,  1.17388652],
       [ 1.54123541,  1.48388699,  1.17680997,  1.15783457,  1.16605299,
         1.17122878,  1.17355655],
       [ 1.57278236,  1.29292406,  1.1631469 ,  1.1579883 ,  1.16593269,
         1.17260055,  1.17683042]])
    np.testing.assert_allclose(grd, grdt)

    lldict = {'lats':np.array([34.1, 34.111]),
              'lons':np.array([-118.2, -118.222])}
    scsamp = mysite.getSitesContext(lldict)

    vs30 = scsamp.vs30
    vs30t = np.array([ 395.53771973,  428.14602661])
    np.testing.assert_allclose(vs30, vs30t)

    lldict = {'lats':np.array([34.1, 34.111]),
              'lons':np.array([-118.2, -118.222])}
    scrsamp = mysite.getSitesContext(lldict, rock_vs30=760)
    vs30 = scrsamp.vs30
    vs30t = np.array([ 760.,  760.])
    np.testing.assert_allclose(vs30, vs30t)
    

    lats = np.array([34.1, 34.111])
    lons = np.array([-118.2, -118.222])
    lldict = {'lats':lats, 'lons':lons}
    scsamp = mysite.getSitesContext(lldict)
    grd = scsamp.vs30measured
    grdt = np.array([False, False], dtype=bool)
    np.testing.assert_allclose(grd, grdt)

    with pytest.raises(Exception) as e:
        scsamp = mysite.getSitesContextFromLatLon(
            np.array([34.1, 34.111, 34.5]),
            np.array([-118.2, -118.222]))

    mysite = Sites.fromCenter(cx, cy, xspan, yspan, dx, dy,
                                    vs30File=None, padding=True,
                                    resample=False)
    grd = mysite.getVs30Grid().getData()
    grd_target = np.array(
      [[ 686.,  686.,  686.,  686.,  686.,  686.],
       [ 686.,  686.,  686.,  686.,  686.,  686.],
       [ 686.,  686.,  686.,  686.,  686.,  686.],
       [ 686.,  686.,  686.,  686.,  686.,  686.],
       [ 686.,  686.,  686.,  686.,  686.,  686.],
       [ 686.,  686.,  686.,  686.,  686.,  686.]])
    np.testing.assert_allclose(grd, grd_target)

    xmin = -118.2
    xmax = -118.12
    ymin = 34.05
    ymax = 34.1
    dx = 0.0083
    dy = 0.0083
    mysite = Sites.fromBounds(xmin, xmax, ymin, ymax, dx, dy,
                                    vs30File=vs30file, padding=False,
                                    resample=False)
    grd = mysite.getVs30Grid().getData()
    grd_target = np.array([[ 395.53771973,  419.31866455,  421.67749023,  426.23449707,
         427.32818604,  424.84860229,  415.17590332,  407.5760498 ,
         404.54788208,  402.28500366],
       [ 413.04779053,  428.22869873,  427.00268555,  426.8951416 ,
         425.62023926,  419.60952759,  411.7961731 ,  407.53509521,
         406.22122192,  405.31622314],
       [ 432.0640564 ,  429.40097046,  427.74179077,  427.00006104,
         419.5062561 ,  411.10830688,  407.48901367,  406.53305054,
         406.59658813,  406.24887085],
       [ 432.01391602,  429.43969727,  427.30435181,  425.96151733,
         426.15856934,  427.56121826,  397.67102051,  399.21054077,
         404.54968262,  407.18515015],
       [ 426.76913452,  428.86270142,  425.99606323,  423.5692749 ,
         423.59835815,  425.92758179,  408.44885254,  406.55810547,
         409.06945801,  413.75210571],
       [ 423.1892395 ,  427.91104126,  424.53796387,  419.47485352,
         418.177948  ,  424.14065552,  428.57913208,  432.95300293,
         427.77731323,  431.46524048],
       [ 410.56729126,  423.15557861,  424.48355103,  419.27658081,
         418.60211182,  423.86721802,  428.06176758,  432.42089844,
         438.54446411,  448.37237549]])
    np.testing.assert_allclose(grd, grd_target)

    mysite = Sites.fromBounds(xmin, xmax, ymin, ymax, dx, dy,
                                    vs30File=None, padding=False,
                                    resample=False)
    grd = mysite.getVs30Grid().getData()
    grd_target = np.array([[ 686.,  686.,  686.,  686.,  686.,  686.,  686.,  686.,  686.,
         686.,  686.],
       [ 686.,  686.,  686.,  686.,  686.,  686.,  686.,  686.,  686.,
         686.,  686.],
       [ 686.,  686.,  686.,  686.,  686.,  686.,  686.,  686.,  686.,
         686.,  686.],
       [ 686.,  686.,  686.,  686.,  686.,  686.,  686.,  686.,  686.,
         686.,  686.],
       [ 686.,  686.,  686.,  686.,  686.,  686.,  686.,  686.,  686.,
         686.,  686.],
       [ 686.,  686.,  686.,  686.,  686.,  686.,  686.,  686.,  686.,
         686.,  686.],
       [ 686.,  686.,  686.,  686.,  686.,  686.,  686.,  686.,  686.,
         686.,  686.],
       [ 686.,  686.,  686.,  686.,  686.,  686.,  686.,  686.,  686.,
         686.,  686.]])
    np.testing.assert_allclose(grd, grd_target)
Exemplo n.º 10
0
def test_multigmpe():
    # Define gmpes and their weights
    gmpes = [AbrahamsonEtAl2014(), BooreEtAl2014(),
             CampbellBozorgnia2014(), ChiouYoungs2014()]
    wts = [0.25, 0.25, 0.25, 0.25]

    # 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.createFromCenter(cx, cy, xspan, yspan, dx, dy,
                                  vs30File=vs30file,
                                  padding=True, resample=False)
    sctx = site.getSitesContext()
    sctx.vs30 = np.reshape(sctx.vs30, (-1,))
    sctx.vs30measured = np.reshape(sctx.vs30measured, (-1,))
    sctx.z1pt0 = np.reshape(sctx.z1pt0, (-1,))

    # Need separate z1pt0 arrays
    sctx.z1pt0cy14 = mg._z1_from_vs30_cy14_cal(sctx.vs30)
    sctx.z1pt0ask14 = mg._z1_from_vs30_ask14_cal(sctx.vs30)
    sctx.z2pt5 = mg._z2p5_from_vs30_cb14_cal(sctx.vs30) / 1000.0

    # 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.])

    flt = Fault.fromTrace(lon0, lat0, lon1, lat1, z, W, dip)
    event = {'lat': 34.1, 'lon': -118.2, 'depth': 1, 'mag': 6,
             'id': '', 'locstring': '', 'rake': 30.3,
             'time': ShakeDateTime.utcfromtimestamp(int(time.time())),
             'timezone': 'UTC'}
    source = Source(event, flt)

    # Make a rupture context
    rupt = source.getRuptureContext(gmpes)

    # Make a distance context
    dctx = Distance.fromSites(gmpes, source, site).getDistanceContext()
    dctx.rhypo = np.reshape(dctx.rhypo, (-1,))
    dctx.rx = np.reshape(dctx.rx, (-1,))
    dctx.rjb = np.reshape(dctx.rjb, (-1,))
    dctx.ry0 = np.reshape(dctx.ry0, (-1,))
    dctx.rrup = np.reshape(dctx.rrup, (-1,))

    # Compute weighted GMPE
    iimt = imt.PGV()
    stddev_types = [const.StdDev.TOTAL]
    mgmpe = mg.MultiGMPE.from_list(gmpes, wts)
    lnmu, lnsd = mgmpe.get_mean_and_stddevs(
        sctx, rupt, dctx, iimt, stddev_types)

    lnmud = np.array(
        [3.44828531,  3.49829605,  3.61749432,  3.64343805,  3.7001028,
         3.7348924,  3.76927164,  3.78659955,  3.82600784,  3.46635007,
         3.53816879,  3.6486898,  3.67058155,  3.72223342,  3.75403094,
         3.79315031,  3.79871491,  3.82093027,  3.54889613,  3.57531437,
         3.64441687,  3.69915981,  3.74491289,  3.78931599,  3.80957828,
         3.80870754,  3.8731021,  3.5927326,  3.60764647,  3.66894024,
         3.72148551,  3.75742965,  3.82164661,  3.86341308,  3.87171115,
         3.79092594,  3.64153758,  3.61835381,  3.68166249,  3.7338161,
         3.82454214,  3.81543928,  3.81507658,  3.80006803,  3.77165695,
         3.65178742,  3.71324776,  3.70389969,  3.77034752,  3.78259432,
         3.78677497,  3.79838465,  3.79050287,  3.75066018,  3.52883328,
         3.67813977,  3.71754876,  3.65520574,  3.69463436,  3.72516445,
         3.7457098,  3.74672185,  3.72615784,  3.44535551,  3.61907294,
         3.58790363,  3.58068716,  3.61177983,  3.64349327,  3.66698468,
         3.67129902,  3.65483002]
    )

    lnsdd = np.array(
       [ 0.63560302,  0.63648101,  0.63610581,  0.6390135 ,  0.64203528,
         0.64624098,  0.64851812,  0.64640406,  0.64384305,  0.6361429 ,
         0.63677975,  0.63715381,  0.64040366,  0.64404005,  0.64782624,
         0.6476325 ,  0.64509458,  0.64297808,  0.63477576,  0.63727968,
         0.63899462,  0.64205578,  0.64604037,  0.64815296,  0.64609948,
         0.64402734,  0.63844724,  0.6343891 ,  0.63806041,  0.64043609,
         0.64406094,  0.64776777,  0.64717195,  0.64297191,  0.64011346,
         0.64110084,  0.63137566,  0.63864151,  0.64163093,  0.64588687,
         0.64714873,  0.64603694,  0.64397734,  0.64217431,  0.63958323,
         0.62883338,  0.63127469,  0.63961477,  0.64097303,  0.6442055 ,
         0.64376449,  0.64273526,  0.64112115,  0.63815862,  0.63575399,
         0.6291859 ,  0.63180644,  0.6394421 ,  0.63946545,  0.63947169,
         0.63935499,  0.63832598,  0.63664816,  0.63595663,  0.62755689,
         0.63523274,  0.63663489,  0.63631586,  0.63616589,  0.63597828,
         0.63542126,  0.63500847])

    np.testing.assert_allclose(lnmu, lnmud)
    np.testing.assert_allclose(lnsd[0], lnsdd)

    # Check for exception due to weights:
    with pytest.raises(Exception) as a:
        wts = [0.25, 0.25, 0.25, 0.25 + 1e-4]
        mgmpe = mg.MultiGMPE.from_list(gmpes, wts)

    # Check exception on GMPE check
    with pytest.raises(Exception) as a:
        wts = [1.0]
        mgmpe = mg.MultiGMPE.from_list(['BA08'], wts)

    # Check exception on tectonic region
    with pytest.raises(Exception) as a:
        gmpes = [BooreEtAl2014(), Campbell2003()]
        wts = [0.5, 0.5]
        mgmpe = mg.MultiGMPE.from_list(gmpes, wts)

    # Check exception on length of gmpe and weight lenghts
    with pytest.raises(Exception) as a:
        gmpes = [BooreEtAl2014(), Campbell2003()]
        wts = [1.0]
        mgmpe = mg.MultiGMPE.from_list(gmpes, wts)
    

    # Check PGV from a GMPE without PGV
    gmpes = [Campbell2003()]
    wts = [1.0]
    mgmpe = mg.MultiGMPE.from_list(gmpes, wts)
    lnmu, lnsd = mgmpe.get_mean_and_stddevs(
        sctx, rupt, dctx, iimt, stddev_types)

    lnmud = np.array(
      [ 3.09152212,  3.1524312 ,  3.20749883,  3.25431585,  3.29035521,
        3.31326677,  3.32116911,  3.31341321,  3.29819842,  3.12252648,
        3.18081138,  3.23208034,  3.27383205,  3.30358765,  3.319195  ,
        3.31916753,  3.30623521,  3.28938984,  3.15235911,  3.20745205,
        3.25429394,  3.29035582,  3.31328548,  3.32119931,  3.31344697,
        3.2982328 ,  3.27982759,  3.17945026,  3.23203088,  3.2738231 ,
        3.30360265,  3.31922869,  3.31921198,  3.30628471,  3.28944133,
        3.26955097,  3.18990634,  3.24351181,  3.28521502,  3.31195497,
        3.32124956,  3.3135073 ,  3.29830033,  3.27989827,  3.25860053,
        3.17942778,  3.23201703,  3.27282524,  3.29888607,  3.3078892 ,
        3.30156745,  3.2884687 ,  3.26964276,  3.24701758,  3.14910673,
        3.19888101,  3.23727522,  3.26163304,  3.2701699 ,  3.2690822 ,
        3.26201491,  3.24919602,  3.23101321,  3.10184816,  3.1475792 ,
        3.18259748,  3.20467529,  3.21444387,  3.21832088,  3.21671138,
        3.20966263,  3.19737325]
    )

    lnsdd = np.array(
       [ 0.83458518,  0.83458518,  0.83458518,  0.83458518,  0.83458518,
         0.83458518,  0.83458518,  0.83458518,  0.83458518,  0.83458518,
         0.83458518,  0.83458518,  0.83458518,  0.83458518,  0.83458518,
         0.83458518,  0.83458518,  0.83458518,  0.83458518,  0.83458518,
         0.83458518,  0.83458518,  0.83458518,  0.83458518,  0.83458518,
         0.83458518,  0.83458518,  0.83458518,  0.83458518,  0.83458518,
         0.83458518,  0.83458518,  0.83458518,  0.83458518,  0.83458518,
         0.83458518,  0.83458518,  0.83458518,  0.83458518,  0.83458518,
         0.83458518,  0.83458518,  0.83458518,  0.83458518,  0.83458518,
         0.83458518,  0.83458518,  0.83458518,  0.83458518,  0.83458518,
         0.83458518,  0.83458518,  0.83458518,  0.83458518,  0.83458518,
         0.83458518,  0.83458518,  0.83458518,  0.83458518,  0.83458518,
         0.83458518,  0.83458518,  0.83458518,  0.83458518,  0.83458518,
         0.83458518,  0.83458518,  0.83458518,  0.83458518,  0.83458518,
         0.83458518,  0.83458518]
    )

    np.testing.assert_allclose(lnmu, lnmud)
    np.testing.assert_allclose(lnsd[0], lnsdd)
Exemplo n.º 11
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)
Exemplo n.º 12
0
def test_distance_no_rupture():
    event = {'lat': 34.1, 'lon': -118.2, 'depth': 1, 'mag': 6,
             'id': '', 'locstring': '', 'timezone': 'UTC'}
    origin = Origin(event)
    origin.setMechanism('ALL')
    # 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
    #  - Unknown/no tectonic region
    #  - Mech is ALL

    gmpe = AbrahamsonEtAl2014()
    rupture = PointRupture(origin)
    dists = Distance.fromSites(gmpe, site, rupture)
    dctx = dists.getDistanceContext()

    rjb = np.array([[ 1.03475736,  0.82507289,  0.69891123,  0.6553167 ,  0.69891123,
                      0.82507289,  1.03475736],
                    [ 0.72918893,  0.50725874,  0.36675284,  0.31957002,  0.36675284,
                        0.50725874,  0.72918893],
                    [ 0.53487557,  0.30135487,  0.14776055,  0.09290799,  0.14776055,
                      0.30135487,  0.53487557],
                    [ 0.46963915,  0.2280053 ,  0.06643829,  0.        ,  0.06643829,
                      0.2280053 ,  0.46963915],
                    [ 0.53495323,  0.30139344,  0.14777086,  0.09290799,  0.14777086,
                      0.30139344,  0.53495323],
                    [ 0.72933979,  0.50732902,  0.36677229,  0.31957002,  0.36677229,
                      0.50732902,  0.72933979],
                    [ 1.03497272,  0.82517579,  0.69893672,  0.6553167 ,  0.69893672,
                      0.82517579,  1.03497272]])

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

    rrup = np.array([[ 8.26004043,  8.11921658,  8.11376473,  8.09579991,  8.11376473,
                       8.11921658,  8.26004043],
                       [ 8.12023764,  8.01816823,  7.93517669,  7.9600631 ,  7.93517669,
                         8.01816823,  8.12023764],
                       [ 8.00702434,  7.95888951,  7.8881565 ,  7.88352525,  7.8881565 ,
                         7.95888951,  8.00702434],
                       [ 8.02022568,  7.90722113,  7.85639147,  0.        ,  7.85639147,
                         7.90722113,  8.02022568],
                         [ 8.00698213,  7.95890141,  7.88813785,  7.88352525,  7.88813785,
                           7.95890141,  8.00698213],
                           [ 8.12025813,  8.01814988,  7.93520725,  7.9600631 ,  7.93520725,
                             8.01814988,  8.12025813],
                             [ 8.26012423,  8.11931772,  8.1137722 ,  8.09579991,  8.1137722 ,
                               8.11931772,  8.26012423]])

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

    # Souce instance
    #  - Tectonic region unsupported
    #  - Mech is ALL
    origin._tectonic_region = 'Volcano'
    dists = Distance.fromSites(gmpe, site, rupture)
    dctx = dists.getDistanceContext()
    rjbt = np.array([[ 1.03475736,  0.82507289,  0.69891123,  0.6553167 ,  0.69891123,
         0.82507289,  1.03475736],
       [ 0.72918893,  0.50725874,  0.36675284,  0.31957002,  0.36675284,
         0.50725874,  0.72918893],
       [ 0.53487557,  0.30135487,  0.14776055,  0.09290799,  0.14776055,
         0.30135487,  0.53487557],
       [ 0.46963915,  0.2280053 ,  0.06643829,  0.        ,  0.06643829,
         0.2280053 ,  0.46963915],
       [ 0.53495323,  0.30139344,  0.14777086,  0.09290799,  0.14777086,
         0.30139344,  0.53495323],
       [ 0.72933979,  0.50732902,  0.36677229,  0.31957002,  0.36677229,
         0.50732902,  0.72933979],
       [ 1.03497272,  0.82517579,  0.69893672,  0.6553167 ,  0.69893672,
         0.82517579,  1.03497272]])
    np.testing.assert_allclose(
        rjbt, dctx.rjb, rtol=0, atol=0.01)

    # Souce instance
    #  - Tectonic region: active
    #  - Mech is ALL

    origin.setMechanism('ALL')
    origin._tectonic_region = 'Active Shallow Crust'
    dists = Distance.fromSites(gmpe, site, rupture)
    dctx = dists.getDistanceContext()

    rjb = np.array([[ 1.10115976,  0.88331216,  0.75077594,  0.70491937,  0.75077594,
         0.88331216,  1.10115976],
       [ 0.78261273,  0.54865189,  0.39914713,  0.34852149,  0.39914713,
         0.54865189,  0.78261273],
       [ 0.57800579,  0.32895654,  0.16294131,  0.10290794,  0.16294131,
         0.32895654,  0.57800579],
       [ 0.50865092,  0.25000954,  0.07371315,  0.        ,  0.07371315,
         0.25000954,  0.50865092],
       [ 0.57808833,  0.32899797,  0.16295256,  0.10290794,  0.16295256,
         0.32899797,  0.57808833],
       [ 0.78277133,  0.5487266 ,  0.39916785,  0.34852149,  0.39916785,
         0.5487266 ,  0.78277133],
       [ 1.10138329,  0.88341918,  0.75080275,  0.70491937,  0.75080275,
         0.88341918,  1.10138329]])

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

    rrup = np.array([[ 8.72726953,  8.58534811,  8.58323541,  8.5654409 ,  8.58323541,
         8.58534811,  8.72726953],
       [ 8.58922774,  8.4871601 ,  8.40244887,  8.4297141 ,  8.40244887,
         8.4871601 ,  8.58922774],
       [ 8.47470803,  8.42880892,  8.35631312,  8.35201539,  8.35631312,
         8.42880892,  8.47470803],
       [ 8.49021276,  8.37536496,  8.32350188,  0.        ,  8.32350188,
         8.37536496,  8.49021276],
       [ 8.47466149,  8.42882081,  8.35629324,  8.35201539,  8.35629324,
         8.42882081,  8.47466149],
       [ 8.58924512,  8.48713903,  8.4024808 ,  8.4297141 ,  8.4024808 ,
         8.48713903,  8.58924512],
       [ 8.72735075,  8.58545174,  8.5832426 ,  8.5654409 ,  8.5832426 ,
         8.58545174,  8.72735075]])

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

    # Souce instance
    #  - Tectonic region: active
    #  - Mech is RS

    origin.setMechanism('RS')
    origin._tectonic_region = 'Active Shallow Crust'
    dists = Distance.fromSites(gmpe, site, rupture)
    dctx = dists.getDistanceContext()

    rjb = np.array([[ 0.94405696,  0.73298036,  0.61025288,  0.56806407,  0.61025288,
         0.73298036,  0.94405696],
       [ 0.63960501,  0.42680989,  0.29738908,  0.25562246,  0.29738908,
         0.42680989,  0.63960501],
       [ 0.45239173,  0.23958848,  0.10874248,  0.06508855,  0.10874248,
         0.23958848,  0.45239173],
       [ 0.39203111,  0.17571632,  0.04480241,  0.        ,  0.04480241,
         0.17571632,  0.39203111],
       [ 0.45246373,  0.2396224 ,  0.1087508 ,  0.06508855,  0.1087508 ,
         0.2396224 ,  0.45246373],
       [ 0.63975135,  0.42687494,  0.29740691,  0.25562246,  0.29740691,
         0.42687494,  0.63975135],
       [ 0.94427453,  0.73308353,  0.61027758,  0.56806407,  0.61027758,
         0.73308353,  0.94427453]])

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

    rrup = np.array([[ 8.81700098,  8.67259556,  8.6707467 ,  8.65288076,  8.6707467 ,
         8.67259556,  8.81700098],
       [ 8.67672238,  8.57444747,  8.49014736,  8.5183922 ,  8.49014736,
         8.57444747,  8.67672238],
       [ 8.56159881,  8.51774523,  8.44708824,  8.44391005,  8.44708824,
         8.51774523,  8.56159881],
       [ 8.57788943,  8.46484058,  8.41567031,  0.        ,  8.41567031,
         8.46484058,  8.57788943],
       [ 8.56155103,  8.51775668,  8.44706792,  8.44391005,  8.44706792,
         8.51775668,  8.56155103],
       [ 8.67673955,  8.5744255 ,  8.49017946,  8.5183922 ,  8.49017946,
         8.5744255 ,  8.67673955],
       [ 8.81708413,  8.67270074,  8.67075389,  8.65288076,  8.67075389,
         8.67270074,  8.81708413]])

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

    # Souce instance
    #  - Tectonic region: active
    #  - Mech is NM

    origin.setMechanism('NM')
    origin._tectonic_region = 'Active Shallow Crust'
    dists = Distance.fromSites(gmpe, site, rupture)
    dctx = dists.getDistanceContext()

    rjb = np.array([[ 0.7899535 ,  0.61128249,  0.50843465,  0.47310349,  0.50843465,
         0.61128249,  0.7899535 ],
       [ 0.53301769,  0.35495992,  0.24706995,  0.21231668,  0.24706995,
         0.35495992,  0.53301769],
       [ 0.37628889,  0.19897762,  0.09028387,  0.05409271,  0.09028387,
         0.19897762,  0.37628889],
       [ 0.32596438,  0.14586493,  0.03728933,  0.        ,  0.03728933,
         0.14586493,  0.32596438],
       [ 0.37634892,  0.19900584,  0.09029076,  0.05409271,  0.09029076,
         0.19900584,  0.37634892],
       [ 0.53314026,  0.35501415,  0.24708481,  0.21231668,  0.24708481,
         0.35501415,  0.53314026],
       [ 0.79013775,  0.61136979,  0.50845534,  0.47310349,  0.50845534,
         0.61136979,  0.79013775]])

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

    rrup = np.array([[ 7.94857792,  7.8097532 ,  7.80275055,  7.78489184,  7.80275055,
         7.8097532 ,  7.94857792],
       [ 7.80938707,  7.70839546,  7.62713392,  7.65061937,  7.62713392,
         7.70839546,  7.80938707],
       [ 7.69799123,  7.64933048,  7.58013644,  7.57530397,  7.58013644,
         7.64933048,  7.69799123],
       [ 7.7099614 ,  7.59905656,  7.54904995,  0.        ,  7.54904995,
         7.59905656,  7.7099614 ],
       [ 7.69795153,  7.64934225,  7.58011859,  7.57530397,  7.58011859,
         7.64934225,  7.69795153],
       [ 7.80940883,  7.70837861,  7.62716348,  7.65061937,  7.62716348,
         7.70837861,  7.80940883],
       [ 7.94866209,  7.80985208,  7.80275807,  7.78489184,  7.80275807,
         7.80985208,  7.94866209]])

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

    # Souce instance
    #  - Tectonic region: active
    #  - Mech is SS

    origin.setMechanism('SS')
    origin._tectonic_region = 'Active Shallow Crust'
    dists = Distance.fromSites(gmpe, site, rupture)
    dctx = dists.getDistanceContext()

    rjb = np.array([[ 2.00333625,  1.69987873,  1.49778447,  1.42682201,  1.49778447,
         1.69987873,  2.00333625],
       [ 1.54679373,  1.17582687,  0.914992  ,  0.81812345,  0.914992  ,
         1.17582687,  1.54679373],
       [ 1.22626178,  0.78021345,  0.43426687,  0.29180829,  0.43426687,
         0.78021345,  1.22626178],
       [ 1.10672645,  0.62338097,  0.21787328,  0.        ,  0.21787328,
         0.62338097,  1.10672645],
       [ 1.22640328,  0.7802939 ,  0.43429295,  0.29180829,  0.43429295,
         0.7802939 ,  1.22640328],
       [ 1.54703738,  1.17595553,  0.9150287 ,  0.81812345,  0.9150287 ,
         1.17595553,  1.54703738],
       [ 2.00364385,  1.7000298 ,  1.49782584,  1.42682201,  1.49782584,
         1.7000298 ,  2.00364385]])

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

    rrup = np.array([[ 7.97494557,  7.79806013,  7.76281765,  7.735536  ,  7.76281765,
         7.79806013,  7.97494557],
       [ 7.77614524,  7.62644695,  7.5120851 ,  7.52225031,  7.5120851 ,
         7.62644695,  7.77614524],
       [ 7.62326525,  7.51608628,  7.40624352,  7.38577101,  7.40624352,
         7.51608628,  7.62326525],
       [ 7.61851685,  7.44728324,  7.35263272,  0.        ,  7.35263272,
         7.44728324,  7.61851685],
       [ 7.62324614,  7.51610811,  7.40622914,  7.38577101,  7.40622914,
         7.51610811,  7.62324614],
       [ 7.77620063,  7.62644821,  7.51211876,  7.52225031,  7.51211876,
         7.62644821,  7.77620063],
       [ 7.97507013,  7.798177  ,  7.76283076,  7.735536  ,  7.76283076,
         7.798177  ,  7.97507013]])

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

    # Souce instance
    #  - Tectonic region: stable
    #  - Mech is all

    origin.setMechanism('ALL')
    origin._tectonic_region = 'Stable Shallow Crust'
    dists = Distance.fromSites(gmpe, site, rupture)
    dctx = dists.getDistanceContext()

    rjb = np.array([[ 1.25490086,  1.00456938,  0.85266727,  0.80013341,  0.85266727,
         1.00456938,  1.25490086],
       [ 0.8891456 ,  0.621322  ,  0.4507253 ,  0.39310934,  0.4507253 ,
         0.621322  ,  0.8891456 ],
       [ 0.65483395,  0.37085259,  0.18246645,  0.11472522,  0.18246645,
         0.37085259,  0.65483395],
       [ 0.57566287,  0.28111922,  0.08186392,  0.        ,  0.08186392,
         0.28111922,  0.57566287],
       [ 0.65492818,  0.37089972,  0.18247916,  0.11472522,  0.18247916,
         0.37089972,  0.65492818],
       [ 0.88932733,  0.62140729,  0.45074894,  0.39310934,  0.45074894,
         0.62140729,  0.88932733],
       [ 1.2551578 ,  1.00469232,  0.85269799,  0.80013341,  0.85269799,
         1.00469232,  1.2551578 ]])

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

    rrup = np.array([[ 6.37308879,  6.21401632,  6.17868645,  6.15460391,  6.17868645,
         6.21401632,  6.37308879],
       [ 6.19096821,  6.06108712,  5.96682577,  5.97487576,  5.96682577,
         6.06108712,  6.19096821],
       [ 6.05926472,  5.97000316,  5.88510619,  5.87109182,  5.88510619,
         5.97000316,  6.05926472],
       [ 6.05384337,  5.91573235,  5.84608701,  0.        ,  5.84608701,
         5.91573235,  6.05384337],
       [ 6.05925153,  5.97002045,  5.88509436,  5.87109182,  5.88509436,
         5.97002045,  6.05925153],
       [ 6.1910207 ,  6.0610899 ,  5.96685295,  5.97487576,  5.96685295,
         6.0610899 ,  6.1910207 ],
       [ 6.37320723,  6.21411804,  6.17869829,  6.15460391,  6.17869829,
         6.21411804,  6.37320723]])

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

    # Souce instance
    #  - Tectonic region: stable
    #  - Mech is RS

    origin.setMechanism('RS')
    origin._tectonic_region = 'Stable Shallow Crust'
    dists = Distance.fromSites(gmpe, site, rupture)
    dctx = dists.getDistanceContext()

    rjb = np.array([[ 1.06775489,  0.83169032,  0.69344486,  0.645892  ,  0.69344486,
         0.83169032,  1.06775489],
       [ 0.72652464,  0.48639585,  0.33959401,  0.2920419 ,  0.33959401,
         0.48639585,  0.72652464],
       [ 0.51540522,  0.27378007,  0.12450057,  0.07451822,  0.12450057,
         0.27378007,  0.51540522],
       [ 0.44695345,  0.20099496,  0.05123817,  0.        ,  0.05123817,
         0.20099496,  0.44695345],
       [ 0.51548687,  0.2738187 ,  0.12451008,  0.07451822,  0.12451008,
         0.2738187 ,  0.51548687],
       [ 0.72668956,  0.48646962,  0.33961424,  0.2920419 ,  0.33961424,
         0.48646962,  0.72668956],
       [ 1.06799812,  0.83180576,  0.6934727 ,  0.645892  ,  0.6934727 ,
         0.83180576,  1.06799812]])

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

    rrup = np.array([[ 6.34187696,  6.18689857,  6.15537676,  6.13263668,  6.15537676,
         6.18689857,  6.34187696],
       [ 6.1667275 ,  6.04409157,  5.9555343 ,  5.96586226,  5.9555343 ,
         6.04409157,  6.1667275 ],
       [ 6.04113522,  5.96186983,  5.88482917,  5.87387645,  5.88482917,
         5.96186983,  6.04113522],
       [ 6.03838637,  5.91117189,  5.85034216,  0.        ,  5.85034216,
         5.91117189,  6.03838637],
       [ 6.04111884,  5.96188527,  5.88481675,  5.87387645,  5.88481675,
         5.96188527,  6.04111884],
       [ 6.16677535,  6.04409147,  5.9555607 ,  5.96586226,  5.9555607 ,
         6.04409147,  6.16677535],
       [ 6.34199129,  6.18699823,  6.15538781,  6.13263668,  6.15538781,
         6.18699823,  6.34199129]])

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

    # Souce instance
    #  - Tectonic region: stable
    #  - Mech is NM

    origin.setMechanism('NM')
    origin._tectonic_region = 'Stable Shallow Crust'
    dists = Distance.fromSites(gmpe, site, rupture)
    dctx = dists.getDistanceContext()

    rjb = np.array([[ 1.11595412,  0.87047978,  0.72608143,  0.6763976 ,  0.72608143,
         0.87047978,  1.11595412],
       [ 0.7606424 ,  0.50965507,  0.35594865,  0.30612448,  0.35594865,
         0.50965507,  0.7606424 ],
       [ 0.5400275 ,  0.28698884,  0.13052973,  0.0781228 ,  0.13052973,
         0.28698884,  0.5400275 ],
       [ 0.46835876,  0.21071547,  0.05370847,  0.        ,  0.05370847,
         0.21071547,  0.46835876],
       [ 0.54011298,  0.28702933,  0.1305397 ,  0.0781228 ,  0.1305397 ,
         0.28702933,  0.54011298],
       [ 0.76081471,  0.50973231,  0.35596982,  0.30612448,  0.35596982,
         0.50973231,  0.76081471],
       [ 1.116207  ,  0.87059985,  0.72611052,  0.6763976 ,  0.72611052,
         0.87059985,  1.116207  ]])

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

    rrup = np.array([[ 6.09163676,  5.92783781,  5.88815939,  5.8632258 ,  5.88815939,
         5.92783781,  6.09163676],
       [ 5.9012656 ,  5.76798442,  5.67370059,  5.68021406,  5.67370059,
         5.76798442,  5.9012656 ],
       [ 5.76720934,  5.67516593,  5.59187321,  5.57813972,  5.59187321,
         5.67516593,  5.76720934],
       [ 5.75981247,  5.62205686,  5.55427369,  0.        ,  5.55427369,
         5.62205686,  5.75981247],
       [ 5.76719951,  5.67518325,  5.59186206,  5.57813972,  5.59186206,
         5.67518325,  5.76719951],
       [ 5.90132265,  5.76798949,  5.67372705,  5.68021406,  5.67372705,
         5.76798949,  5.90132265],
       [ 6.09176251,  5.92794056,  5.88817184,  5.8632258 ,  5.88817184,
         5.92794056,  6.09176251]])

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

    # Souce instance
    #  - Tectonic region: stable
    #  - Mech is SS

    origin.setMechanism('SS')
    origin._tectonic_region = 'Stable Shallow Crust'
    dists = Distance.fromSites(gmpe, site, rupture)
    dctx = dists.getDistanceContext()

    rjb = np.array([[ 1.7978181 ,  1.48474703,  1.28392745,  1.21396452,  1.28392745,
         1.48474703,  1.7978181 ],
       [ 1.3323943 ,  0.97123526,  0.72919945,  0.64364445,  0.72919945,
         0.97123526,  1.3323943 ],
       [ 1.01846151,  0.61039475,  0.3191157 ,  0.20751973,  0.3191157 ,
         0.61039475,  1.01846151],
       [ 0.90673813,  0.47477623,  0.15160737,  0.        ,  0.15160737,
         0.47477623,  0.90673813],
       [ 1.01859418,  0.61046522,  0.3191364 ,  0.20751973,  0.3191364 ,
         0.61046522,  1.01859418],
       [ 1.33263554,  0.97135557,  0.72923321,  0.64364445,  0.72923321,
         0.97135557,  1.33263554],
       [ 1.79813761,  1.48490175,  1.28396831,  1.21396452,  1.28396831,
         1.48490175,  1.79813761]])

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

    rrup = np.array([[ 5.27459324,  5.06456452,  4.9821571 ,  4.94467172,  4.9821571 ,
         5.06456452,  5.27459324],
       [ 5.00483041,  4.80820132,  4.67381918,  4.65867853,  4.67381918,
         4.80820132,  5.00483041],
       [ 4.81923672,  4.64680257,  4.514164  ,  4.47986499,  4.514164  ,
         4.64680257,  4.81923672],
       [ 4.78581905,  4.57286829,  4.44979468,  0.        ,  4.44979468,
         4.57286829,  4.78581905],
       [ 4.81926166,  4.64683299,  4.51415954,  4.47986499,  4.51415954,
         4.64683299,  4.81926166],
       [ 5.00493679,  4.80823501,  4.67384847,  4.65867853,  4.67384847,
         4.80823501,  5.00493679],
       [ 5.27477487,  5.06468553,  4.98217732,  4.94467172,  4.98217732,
         5.06468553,  5.27477487]])

    np.testing.assert_allclose(
        rrup, dctx.rrup, rtol=0, atol=0.01)
Exemplo n.º 13
0
def test(vs30file=None):
    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
    mysite = Sites.createFromCenter(cx, cy, xspan, yspan, dx, dy,
                                    vs30File=vs30file, padding=True,
                                    resample=False)
    grd = mysite.getVs30Grid().getData()
    grd_target = np.array(
      [[ 409.14199829,  428.24468994,  395.90026855,  426.31658936,
         427.53845215,  433.40481567,  436.59918213,  440.43664551,
         413.60662842],
       [ 423.60855103,  426.64892578,  398.89712524,  428.88549805,
         428.78335571,  428.58578491,  430.54354858,  433.59750366,
         415.18811035],
       [ 391.67398071,  426.20635986,  425.57946777,  428.21954346,
         426.06726074,  421.86233521,  423.53192139,  426.25296021,
         365.48190308],
       [ 385.00396729,  428.14602661,  430.05944824,  429.3427124 ,
         426.13626099,  409.76391602,  383.07299805,  372.39117432,
         426.48486328],
       [ 356.68756104,  432.64077759,  434.55209351,  432.21600342,
         395.53771973,  419.31866455,  421.67749023,  426.23449707,
         427.32818604],
       [ 337.0546875 ,  345.14605713,  403.78097534,  385.49118042,
         413.04779053,  428.22869873,  427.00268555,  426.8951416 ,
         425.62023926],
       [ 403.78884888,  336.48217773,  347.82220459,  425.96798706,
         432.0640564 ,  429.40097046,  427.74179077,  427.00006104,
         419.5062561 ],
       [ 420.07458496,  330.57504272,  392.33255005,  430.33862305,
         432.01391602,  429.43969727,  427.30435181,  425.96151733,
         426.15856934]])

    np.testing.assert_allclose(grd, grd_target)

    sc = mysite.getSitesContext()
    scsamp = mysite.sampleFromSites(np.array([34.1, 34.111]),
                                    np.array([-118.2, -118.222]))

    xmin = -118.2
    xmax = -118.12
    ymin = 34.05
    ymax = 34.1
    dx = 0.0083
    dy = 0.0083
    mysite = Sites.createFromBounds(xmin, xmax, ymin, ymax, dx, dy,
                                    vs30File=vs30file, padding=False,
                                    resample=False)
    grd = mysite.getVs30Grid().getData()
    grd_target = np.array(
      [[ 426.13626099,  409.76391602,  383.07299805,  372.39117432,
         426.48486328,  422.45065308,  417.21685791,  410.43737793,
         405.33862305,  400.5239563 ,  396.03030396],
       [ 395.53771973,  419.31866455,  421.67749023,  426.23449707,
         427.32818604,  424.84860229,  415.17590332,  407.5760498 ,
         404.54788208,  402.28500366,  398.95913696],
       [ 413.04779053,  428.22869873,  427.00268555,  426.8951416 ,
         425.62023926,  419.60952759,  411.7961731 ,  407.53509521,
         406.22122192,  405.31622314,  402.92575073],
       [ 432.0640564 ,  429.40097046,  427.74179077,  427.00006104,
         419.5062561 ,  411.10830688,  407.48901367,  406.53305054,
         406.59658813,  406.24887085,  406.17044067],
       [ 432.01391602,  429.43969727,  427.30435181,  425.96151733,
         426.15856934,  427.56121826,  397.67102051,  399.21054077,
         404.54968262,  407.18515015,  410.00823975],
       [ 426.76913452,  428.86270142,  425.99606323,  423.5692749 ,
         423.59835815,  425.92758179,  408.44885254,  406.55810547,
         409.06945801,  413.75210571,  417.71130371],
       [ 423.1892395 ,  427.91104126,  424.53796387,  419.47485352,
         418.177948  ,  424.14065552,  428.57913208,  432.95300293,
         427.77731323,  431.46524048,  442.75540161],
       [ 410.56729126,  423.15557861,  424.48355103,  419.27658081,
         418.60211182,  423.86721802,  428.06176758,  432.42089844,
         438.54446411,  448.37237549,  462.25509644],
       [ 405.86877441,  414.27923584,  419.53878784,  396.18017578,
         414.54452515,  419.80047607,  425.19824219,  424.48919678,
         424.72061157,  431.52270508,  432.84347534]])
    np.testing.assert_allclose(grd, grd_target)
Exemplo n.º 14
0
def test_distance_from_sites_source():
    # 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.createFromCenter(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.])

    flt = Fault.fromTrace(lon0, lat0, lon1, lat1, z, W, dip)
    event = {'lat': 34.1, 'lon': -118.2, 'depth': 1, 'mag': 6,
             'id': '', 'locstring': '', 'type': 'U',
             'time': ShakeDateTime.utcfromtimestamp(int(time.time())),
             'timezone': 'UTC'}
    source = Source(event, flt)
    gmpelist = [AbrahamsonEtAl2014(), BergeThierryEtAl2003SIGMA()]
    dists = Distance.fromSites(gmpelist, source, site)
    dctx = dists.getDistanceContext()

    rhypo = np.array(
        [[4.91471497, 4.47602418, 4.13427127, 3.91492565, 3.83902646,
          3.91492565, 4.13427127, 4.47602418, 4.91471497],
         [4.25968568, 3.74498133, 3.32896405, 3.05225679, 2.95426722,
            3.05225679, 3.32896405, 3.74498133, 4.25968568],
            [3.7219197, 3.11965436, 2.60558436, 2.24124201, 2.10583262,
             2.24124201, 2.60558436, 3.11965436, 3.7219197],
            [3.35823105, 2.67523213, 2.05265767, 1.564393, 1.36331682,
             1.564393, 2.05265767, 2.67523213, 3.35823105],
            [3.22800413, 2.50973226, 1.83166664, 1.26045653, 1.,
             1.26045653, 1.83166664, 2.50973226, 3.22800413],
            [3.35850726, 2.67542717, 2.05277065, 1.56443006, 1.36331682,
             1.56443006, 2.05277065, 2.67542717, 3.35850726],
            [3.72241812, 3.11998886, 2.60576236, 2.24129374, 2.10583262,
             2.24129374, 2.60576236, 3.11998886, 3.72241812],
            [4.26033893, 3.74539929, 3.32917303, 3.05231378, 2.95426722,
             3.05231378, 3.32917303, 3.74539929, 4.26033893]]
    )
    np.testing.assert_allclose(
        rhypo, dctx.rhypo, rtol=0, atol=0.01)

    rx = np.array(
        [[-4.25168879e+00, -3.54281195e+00, -2.83395897e+00,
          -2.12512986e+00, -1.41632463e+00, -7.07543303e-01,
          1.21411306e-03, 7.09947601e-01, 1.41865714e+00],
         [-3.89788718e+00, -3.18894046e+00, -2.48001760e+00,
            -1.77111861e+00, -1.06224350e+00, -3.53392295e-01,
          3.55434994e-01, 1.06423835e+00, 1.77301777e+00],
            [-3.54408550e+00, -2.83506891e+00, -2.12607617e+00,
             -1.41710732e+00, -7.08162347e-01, 7.58720005e-04,
             7.09655868e-01, 1.41852908e+00, 2.12737835e+00],
            [-3.19028373e+00, -2.48119729e+00, -1.77213470e+00,
             -1.06309600e+00, -3.54081177e-01, 3.54909735e-01,
             1.06387673e+00, 1.77281978e+00, 2.48173889e+00],
            [-2.83648190e+00, -2.12732562e+00, -1.41819320e+00,
             -7.09084651e-01, 2.56777675e-12, 7.09060743e-01,
             1.41809756e+00, 2.12711045e+00, 2.83609938e+00],
            [-2.48268001e+00, -1.77345390e+00, -1.06425166e+00,
             -3.55073292e-01, 3.54081177e-01, 1.06321174e+00,
             1.77231837e+00, 2.48140106e+00, 3.19045980e+00],
            [-2.12887807e+00, -1.41958215e+00, -7.10310097e-01,
             -1.06192604e-03, 7.08162347e-01, 1.41736271e+00,
             2.12653914e+00, 2.83569163e+00, 3.54482016e+00],
            [-1.77507608e+00, -1.06571037e+00, -3.56368521e-01,
             3.52949440e-01, 1.06224350e+00, 1.77151365e+00,
             2.48075986e+00, 3.18998213e+00, 3.89918045e+00]]
    )

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

    rjb = np.array(
        [[4.25806540e+00, 3.54812473e+00, 2.83820819e+00,
          2.12831587e+00, 1.41844799e+00, 7.08605677e-01,
          2.52145001e-03, 2.71336156e-03, 2.81274718e-03],
         [3.90373176e+00, 3.19372137e+00, 2.48373511e+00,
          1.77377308e+00, 1.06383562e+00, 3.53925643e-01,
          2.25816823e-03, 2.45009861e-03, 2.54949398e-03],
            [3.54939857e+00, 2.83931844e+00, 2.12926243e+00,
             1.41923064e+00, 7.09223517e-01, 1.57594916e-03,
             1.86044244e-03, 2.05239165e-03, 2.15179678e-03],
            [3.21162971e+00, 2.48510934e+00, 1.77479025e+00,
             1.06468863e+00, 3.54611655e-01, 1.04375185e-03,
             1.32827303e-03, 1.52024106e-03, 1.61965594e-03],
            [3.07587955e+00, 2.30690967e+00, 1.53793979e+00,
             7.68969896e-01, 5.88918451e-12, 3.77111295e-04,
             6.61660373e-04, 8.53647223e-04, 2.38384209e-01],
            [3.21191809e+00, 2.48531877e+00, 1.79442084e+00,
             1.20242597e+00, 8.54793253e-01, 5.62052963e-01,
             2.69254693e-01, 5.26105100e-05, 5.93270976e-01],
            [3.58897017e+00, 2.95646628e+00, 2.40489915e+00,
             2.00231070e+00, 1.70958533e+00, 1.41681634e+00,
             1.12398937e+00, 8.63761551e-01, 1.08872127e+00],
            [4.14172611e+00, 3.60741953e+00, 3.17112489e+00,
             2.85711592e+00, 2.56437623e+00, 2.27157856e+00,
             1.97872291e+00, 1.78518260e+00, 1.90424524e+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, 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],
            [3.15917743e-01, 2.29488608e-02, 0.00000000e+00,
             0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
             0.00000000e+00, 0.00000000e+00, 0.00000000e+00],
            [1.17233848e+00, 8.79340738e-01, 5.86285075e-01,
             2.93171494e-01, 6.20905972e-12, 0.00000000e+00,
             0.00000000e+00, 0.00000000e+00, 0.00000000e+00],
            [2.02875906e+00, 1.73573247e+00, 1.44264795e+00,
             1.14950551e+00, 8.56305149e-01, 5.63046877e-01,
             2.69730699e-01, 0.00000000e+00, 0.00000000e+00],
            [2.88517947e+00, 2.59212404e+00, 2.29901067e+00,
             2.00583937e+00, 1.71261015e+00, 1.41932302e+00,
             1.12597797e+00, 8.32575011e-01, 5.39114157e-01],
            [3.74159969e+00, 3.44851542e+00, 3.15537321e+00,
             2.86217307e+00, 2.56891499e+00, 2.27559900e+00,
             1.98222508e+00, 1.68879326e+00, 1.39530352e+00]]
    )

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

    rrup = np.array(
        [[4.37398161, 3.68659567, 3.00969158, 2.35231374, 1.73674834,
          1.22755262, 1.0025215, 1.22371894, 1.57836451],
         [4.02976949, 3.34678672, 2.67788811, 2.03697073, 1.46129187,
            1.06271102, 1.06352692, 1.40073832, 1.75541869],
            [3.68743926, 3.01030105, 2.3526499, 1.73673635, 1.22706347,
             1.00157564, 1.22283363, 1.57764099, 1.93235615],
            [3.3634728, 2.67858182, 2.03712377, 1.46095502, 1.06170931,
             1.06220616, 1.39958479, 1.75442695, 2.1091769],
            [3.23412325, 2.51415965, 1.8343632, 1.26143652, 1.,
             1.2212501, 1.57621925, 1.9310962, 2.28588093],
            [3.36374812, 2.67877609, 2.05412785, 1.56384179, 1.3617346,
             1.50608502, 1.77308319, 2.10764873, 2.46246823],
            [3.72541099, 3.12078859, 2.6043486, 2.23799413, 2.09885629,
             2.11696797, 2.23191013, 2.4299612, 2.69282837],
            [4.26042286, 3.74318473, 3.32482368, 3.04635272, 2.9183523,
             2.86659485, 2.88815116, 2.98141559, 3.13998993]]
    )

    np.testing.assert_allclose(
        rrup, dctx.rrup, rtol=0, atol=0.01)
Exemplo n.º 15
0
def test_station(tmpdir):

    homedir = os.path.dirname(os.path.abspath(__file__))
    datadir = os.path.abspath(os.path.join(homedir, '..', 'data', 
            'eventdata', 'Calexico', 'input'))

    #
    # Read the event, source, and rupture files and produce a Source object
    #
    inputfile = os.path.join(datadir, 'stationlist_dat.xml')
    dyfifile = os.path.join(datadir, 'ciim3_dat.xml')
    eventfile = os.path.join(datadir, 'event.xml')
    rupturefile = os.path.join(datadir, 'wei_fault.txt')

    source_obj = Source.fromFile(eventfile, rupturefile=rupturefile)

    #
    # Set up the GMPE, IPE, and GMICE
    #
    gmpe_cy14 = ChiouYoungs2014()

    gmpe = MultiGMPE.from_list([gmpe_cy14], [1.0])

    gmice = WGRW12()

    ipe = AllenEtAl2012()

    #
    # 
    #
    rupture_ctx = source_obj.getRuptureContext([gmpe])

    smdx = 0.0083333333
    smdy = 0.0083333333
    lonspan = 6.0
    latspan = 4.0
    vs30filename = os.path.join(datadir, '..', 'vs30', 'vs30.grd')

    sites_obj_grid = Sites.fromCenter(
            rupture_ctx.hypo_lon, rupture_ctx.hypo_lat, lonspan, latspan, 
            smdx, smdy, defaultVs30=760.0, vs30File=vs30filename, 
            vs30measured_grid=None, padding=False, resample=False
        )

    xmlfiles = [inputfile, dyfifile]
#    dbfile = str(tmpdir.join('stations.db'))
    dbfile = os.path.join(str(tmpdir), 'stations.db')

    stations = StationList.fromXML(xmlfiles, dbfile, source_obj, 
            sites_obj_grid, gmpe, ipe, gmice)

    df1 = stations.getStationDataframe(1, sort=True)
    df2 = stations.getStationDataframe(0, sort=True)


    #
    # In case the test starts failing because of some minor change
    # in one of the prediction or conversion equations (or roundoff
    # or whatever), but the code is running correctly, uncomment 
    # these lines and re-run the test. Then, copy the new stations.db
    # file into tests/data/eventdata/Calexico/database/. Then
    # recomment these lines and rerun the test. It should succeed.
    #
    #shutil.copy(dbfile,'./stations.db')
    #print(os.getcwd())

    #
    # We should probably check these dataframes against some established
    # set, and also check the database against a known database. 
    #

    ref_dbfile = os.path.join(datadir, '..', 'database', 'stations.db')

    stations2 = StationList(ref_dbfile)

    ref_df1 = stations2.getStationDataframe(1, sort=True)
    ref_df2 = stations2.getStationDataframe(0, sort=True)

#    assert ref_df1.equals(df1)
#    assert ref_df2.equals(df2)

    pdt.assert_frame_equal(df1, ref_df1)
    pdt.assert_frame_equal(df2, ref_df2)