コード例 #1
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]

    fault = Fault.fromTrace(xp0,
                            yp0,
                            xp1,
                            yp1,
                            zp,
                            widths,
                            dips,
                            reference='From J Smith, (personal communication)')
    fstr = io.StringIO()
    fault.writeFaultFile(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]
    fault = Fault.fromTrace(xp0,
                            yp0,
                            xp1,
                            yp1,
                            zp,
                            widths,
                            dips,
                            reference='From J Smith, (personal communication)')
コード例 #2
0
ファイル: plotfault_test.py プロジェクト: jnf0910/shakemap
def test_plot_fault_wire3d():
    ff = os.path.join(shakedir,
        "tests/data/eventdata/hayward_RC_HN_HS_HE_Shaw09Mod_GEOL.txt")
    flt = Fault.readFaultFile(ff)
    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')
    plot_fault_wire3d(flt, ax)
    return fig
コード例 #3
0
def test_plot_fault_wire3d():
    ff = os.path.join(
        shakedir,
        "tests/data/eventdata/hayward_RC_HN_HS_HE_Shaw09Mod_GEOL.txt")
    flt = Fault.readFaultFile(ff)
    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')
    plot_fault_wire3d(flt, ax)
    return fig
コード例 #4
0
def test_misc():
    # Make a fault
    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)
    fm = flt.getFaultAsMesh()
    fa = flt.getFaultAsArrays()
    ref = flt.getReference()
コード例 #5
0
ファイル: fault_test.py プロジェクト: mhearne-usgs/shakemap
def test_misc():
    # Make a fault
    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)
    fm = flt.getFaultAsMesh()
    fa = flt.getFaultAsArrays()
    ref = flt.getReference()
コード例 #6
0
ファイル: fault_test.py プロジェクト: g-weatherill/shakemap
def _test_correct():
    #this fault should parse correctly
    fault_text = """#SOURCE: Barka, A., H. S. Akyz, E. Altunel, G. Sunal, Z. Akir, A. Dikbas, B. Yerli, R. Armijo, B. Meyer, J. B. d. Chabalier, T. Rockwell, J. R. Dolan, R. Hartleb, T. Dawson, S. Christofferson, A. Tucker, T. Fumal, R. Langridge, H. Stenner, W. Lettis, J. Bachhuber, and W. Page (2002). The Surface Rupture and Slip Distribution of the 17 August 1999 Izmit Earthquake (M 7.4), North Anatolian Fault, Bull. Seism. Soc. Am. 92, 43-60.
    40.70985 29.33760 0
    40.72733 29.51528 0
    40.72933 29.51528 20
    40.71185 29.33760 20
    40.70985 29.33760 0
    >
    40.70513 29.61152 0
    40.74903 29.87519 0
    40.75103 29.87519 20
    40.70713 29.61152 20
    40.70513 29.61152 0
    >
    40.72582 29.88662 0
    40.72336 30.11126 0
    40.73432 30.19265 0
    40.73632 30.19265 20
    40.72536 30.11126 20
    40.72782 29.88662 20
    40.72582 29.88662 0
    >
    40.71210 30.30494 0
    40.71081 30.46540 0
    40.70739 30.56511 0
    40.70939 30.56511 20
    40.71281 30.46540 20
    40.71410 30.30494 20
    40.71210 30.30494 0
    >
    40.71621 30.57658 0
    40.70068 30.63731 0
    40.70268 30.63731 20
    40.71821 30.57658 20
    40.71621 30.57658 0
    >
    40.69947 30.72900 0
    40.79654 30.93655 0
    40.79854 30.93655 20
    40.70147 30.72900 20
    40.69947 30.72900 0
    >
    40.80199 30.94688 0
    40.84501 31.01799 0
    40.84701 31.01799 20
    40.80399 30.94688 20
    40.80199 30.94688 0"""

    cbuf = io.StringIO(fault_text)
    fault = Fault.readFaultFile(cbuf)
コード例 #7
0
ファイル: fault_test.py プロジェクト: mhearne-usgs/shakemap
def test_fromTrace():
    xp0 = [0.0]
    xp1 = [0.0]
    yp0 = [0.0]
    yp1 = [0.05]
    zp = [0.0]
    widths = [10.0]
    dips = [45.0]

    fault = Fault.fromTrace(xp0, yp0, xp1, yp1, zp, widths,
                            dips, reference='From J Smith, (personal communication)')
    fstr = io.StringIO()
    fault.writeFaultFile(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]
    fault = Fault.fromTrace(xp0, yp0, xp1, yp1, zp, widths,
                            dips, reference='From J Smith, (personal communication)')
コード例 #8
0
ファイル: mkfault.py プロジェクト: g-weatherill/shakemap
def main(pargs):
    nargin = len(pargs.coords)
    if nargin < 6:
        print 'You must specify at least two top edge points each with (x y z) coordinates.'
        sys.exit(1)
    if (nargin % 3) != 0:
        print 'Each point must have 3 coordinates (x y z) per top edge point.'
        sys.exit(1)
    npoints = nargin/3
    nquads = ((npoints*2 - 4)/2) + 1
    if pargs.widths is None or len(pargs.widths) != nquads:
        print 'You must specify %i widths' % nquads
        sys.exit(1)
    if pargs.dips is not None and pargs.depths is not None:
        print 'You must specify %i depths or %i dips, not both.' % (nquads,nquads)
        sys.exit(1)
    
    x = np.array(pargs.coords[1::3])
    y = np.array(pargs.coords[0::3])
    z = np.array(pargs.coords[2::3])
    
    fault = Fault.fromTrace(x,y,z,pargs.widths,pargs.dips)

    if pargs.plotfile:
        fig = plt.figure()
        ax0 = fig.add_subplot(2,1,1)
        ax1 = fig.add_subplot(2,1,2, projection='3d')
        for quad in fault.getQuadrilaterals():
            P0,P1,P2,P3 = quad
            xp = np.array([P0.longitude,P1.longitude,P2.longitude,P3.longitude,P0.longitude])
            yp = np.array([P0.latitude,P1.latitude,P2.latitude,P3.latitude,P0.latitude])
            zp = np.array([-P0.depth,-P1.depth,-P2.depth,-P3.depth,-P0.depth])
            ax0.plot(xp,yp)
            ax0.set_xlabel('Longitude')
            ax0.set_xlabel('Latitude')
            ax1.plot(xp,yp,zp)
            ax1.set_xlabel('Longitude')
            ax1.set_xlabel('Latitude')
            ax1.set_zlabel('Depth')
            ax0.axis('equal')
            ax1.axis('equal')
        plt.savefig(pargs.plotfile)

    if pargs.outfile:
        fault.writeFaultFile(pargs.outfile)
コード例 #9
0
ファイル: fault_test.py プロジェクト: g-weatherill/shakemap
def _test_northridge():
    #this should fail!
    fault_text = """
    # Source: Wald, D. J., T. H. Heaton, and K. W. Hudnut (1996). The Slip History of the 1994 Northridge, California, Earthquake Determined from Strong-Motion, Teleseismic, GPS, and Leveling Data, Bull. Seism. Soc. Am. 86, S49-S70.
    34.315 -118.421 5.000
    34.401 -118.587 5.000
    34.261 -118.693 20.427
    34.175 -118.527 20.427
    34.315 -118.421 5.000
    """
    cbuf = io.StringIO(fault_text)
    fault = Fault.readFaultFile(cbuf)
    quad = fault.getQuadrilaterals()[0]
    topdist = quad[0].distance(quad[1])
    fault.multiplyFaultLength(2.0)
    quad = fault.getQuadrilaterals()[0]
    topdist2 = quad[0].distance(quad[1])
    x = 1
コード例 #10
0
def test_slip():
    # Make a fault
    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)

    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)
コード例 #11
0
ファイル: fault_test.py プロジェクト: mhearne-usgs/shakemap
def test_slip():
    # Make a fault
    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)

    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)
コード例 #12
0
ファイル: distance_test.py プロジェクト: cbworden/shakemap
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)
コード例 #13
0
ファイル: fault_test.py プロジェクト: g-weatherill/shakemap
def _test_incorrect():
    fault_text = """# Source: Ji, C., D. V. Helmberger, D. J. Wald, and K.-F. Ma (2003). Slip history and dynamic implications of the 1999 Chi-Chi, Taiwan, earthquake, J. Geophys. Res. 108, 2412, doi:10.1029/2002JB001764.
    24.27980 120.72300	0 
    24.05000 121.00000	17
    24.07190 121.09300	17
    24.33120 121.04300	17
    24.27980 120.72300	0 
    >   
    24.27980 120.72300	0
    23.70000 120.68000	0
    23.60400 120.97200	17
    24.05000 121.00000	17
    24.27980 120.72300	0
    >
    23.60400 120.97200	17 
    23.70000 120.68000	0 
    23.58850 120.58600	0
    23.40240 120.78900	17
    23.60400 120.97200	17"""

    cbuf = io.StringIO(fault_text)
    fault = Fault.readFaultFile(cbuf)
コード例 #14
0
ファイル: fault_test.py プロジェクト: mhearne-usgs/shakemap
def test_incorrect():
    fault_text = """# Source: Ji, C., D. V. Helmberger, D. J. Wald, and K.-F. Ma (2003). Slip history and dynamic implications of the 1999 Chi-Chi, Taiwan, earthquake, J. Geophys. Res. 108, 2412, doi:10.1029/2002JB001764.
    24.27980 120.72300	0 
    24.05000 121.00000	17
    24.07190 121.09300	17
    24.33120 121.04300	17
    24.27980 120.72300	0 
    >   
    24.27980 120.72300	0
    23.70000 120.68000	0
    23.60400 120.97200	17
    24.05000 121.00000	17
    24.27980 120.72300	0
    >
    23.60400 120.97200	17 
    23.70000 120.68000	0 
    23.58850 120.58600	0
    23.40240 120.78900	17
    23.60400 120.97200	17"""

    cbuf = io.StringIO(fault_text)
    with pytest.raises(ShakeMapException):
        fault = Fault.readFaultFile(cbuf)
コード例 #15
0
ファイル: fault_test.py プロジェクト: mhearne-usgs/shakemap
def test_northridge():
    fault_text = """
    # Source: Wald, D. J., T. H. Heaton, and K. W. Hudnut (1996). The Slip History of the 1994 Northridge, California, Earthquake Determined from Strong-Motion, Teleseismic, GPS, and Leveling Data, Bull. Seism. Soc. Am. 86, S49-S70.
    34.315 -118.421 5.000
    34.401 -118.587 5.000
    34.261 -118.693 20.427
    34.175 -118.527 20.427
    34.315 -118.421 5.000
    """
    cbuf = io.StringIO(fault_text)
    fault = Fault.readFaultFile(cbuf)
    strike = fault.getStrike()
    np.testing.assert_allclose(strike, 122.06408, atol=0.001)
    dip = fault.getDip()
    np.testing.assert_allclose(dip, 40.20979, atol=0.001)
    L = fault.getFaultLength()
    np.testing.assert_allclose(L, 17.99198, atol=0.001)
    W = fault.getWidth()
    np.testing.assert_allclose(W, 23.93699, atol=0.001)
    nq = fault.getNumQuads()
    np.testing.assert_allclose(nq, 1)
    ns = fault.getNumSegments()
    np.testing.assert_allclose(ns, 1)
    sind = fault._getSegmentIndex()
    np.testing.assert_allclose(sind, [0])
    ztor = fault.getTopOfRupture()
    np.testing.assert_allclose(ztor, 5, atol=0.001)
    itl = fault.getIndividualTopLengths()
    np.testing.assert_allclose(itl, 17.9919846, atol=0.001)
    iw = fault.getIndividualWidths()
    np.testing.assert_allclose(iw, 23.93699668, atol=0.001)
    lats = fault.getLats()
    lats_d = np.array([34.315,  34.401,  34.261,  34.175,  34.315])
    np.testing.assert_allclose(lats, lats_d, atol=0.001)
    lons = fault.getLons()
    lons_d = np.array([-118.421, -118.587, -118.693, -118.527, -118.421])
    np.testing.assert_allclose(lons, lons_d, atol=0.001)
コード例 #16
0
def test_northridge():
    fault_text = """
    # Source: Wald, D. J., T. H. Heaton, and K. W. Hudnut (1996). The Slip History of the 1994 Northridge, California, Earthquake Determined from Strong-Motion, Teleseismic, GPS, and Leveling Data, Bull. Seism. Soc. Am. 86, S49-S70.
    34.315 -118.421 5.000
    34.401 -118.587 5.000
    34.261 -118.693 20.427
    34.175 -118.527 20.427
    34.315 -118.421 5.000
    """
    cbuf = io.StringIO(fault_text)
    fault = Fault.readFaultFile(cbuf)
    strike = fault.getStrike()
    np.testing.assert_allclose(strike, 122.06408, atol=0.001)
    dip = fault.getDip()
    np.testing.assert_allclose(dip, 40.20979, atol=0.001)
    L = fault.getFaultLength()
    np.testing.assert_allclose(L, 17.99198, atol=0.001)
    W = fault.getWidth()
    np.testing.assert_allclose(W, 23.93699, atol=0.001)
    nq = fault.getNumQuads()
    np.testing.assert_allclose(nq, 1)
    ns = fault.getNumSegments()
    np.testing.assert_allclose(ns, 1)
    sind = fault._getSegmentIndex()
    np.testing.assert_allclose(sind, [0])
    ztor = fault.getTopOfRupture()
    np.testing.assert_allclose(ztor, 5, atol=0.001)
    itl = fault.getIndividualTopLengths()
    np.testing.assert_allclose(itl, 17.9919846, atol=0.001)
    iw = fault.getIndividualWidths()
    np.testing.assert_allclose(iw, 23.93699668, atol=0.001)
    lats = fault.getLats()
    lats_d = np.array([34.315, 34.401, 34.261, 34.175, 34.315])
    np.testing.assert_allclose(lats, lats_d, atol=0.001)
    lons = fault.getLons()
    lons_d = np.array([-118.421, -118.587, -118.693, -118.527, -118.421])
    np.testing.assert_allclose(lons, lons_d, atol=0.001)
コード例 #17
0
ファイル: mapmaker_test.py プロジェクト: cbworden/shakemap
def _test_intensity():

    datadir = os.path.abspath(os.path.join(
        homedir, '..', 'data', 'eventdata', 'northridge'))
    shakefile = os.path.join(datadir, 'northridge_grid.xml')
    topofile = os.path.join(datadir, 'northridge_topo.grd')
    faultfile = os.path.join(datadir, 'northridge_fault.txt')
    cityfile = os.path.join(datadir, 'northridge_cities.txt')
    coastfile = os.path.join(datadir, 'northridge_coastline.json')
    countryfile = os.path.join(datadir, 'northridge_countries.json')
    statefile = os.path.join(datadir, 'northridge_states.json')
    lakefile = os.path.join(datadir, 'northridge_lakes.json')
    oceanfile = os.path.join(datadir, 'northridge_ocean.json')
    stationfile = os.path.join(datadir, 'northridge_stations.db')
    roadfile = os.path.join(datadir, 'northridge_roads.json')
    tancptfile = os.path.join(shakedir, 'shakemap', 'mapping', 'tan.cpt')
    shakecptfile = os.path.join(
        shakedir, 'shakemap', 'mapping', 'shakecpt.cpt')

    layerdict = {'coast': coastfile,
                 'ocean': oceanfile,
                 'lake': lakefile,
                 'country': countryfile,
                 'roads': roadfile,
                 'state': statefile}

    tancolormap = ColorPalette.fromPreset('shaketopo')
    shakecolormap = ColorPalette.fromPreset('mmi')
    cities = BasemapCities.loadFromCSV(cityfile)
    shakemap = ShakeGrid.load(shakefile, adjust='res')
    stations = StationList(stationfile)
    fault = Fault.readFaultFile(faultfile)
    edict = shakemap.getEventDict()
    eventdict = {'lat': edict['lat'],
                 'lon': edict['lon'],
                 'depth': edict['depth'],
                 'mag': edict['magnitude'],
                 'time': edict['event_timestamp']}
    source = Source(eventdict, fault)
    maker = MapMaker(shakemap, topofile, stations,
                     fault, layerdict, source, cities)

    # draw intensity map
    outfolder = os.path.expanduser('~')
    maker.setIntensityLayer('mmi')
    maker.setIntensityGMTColorMap(shakecolormap)
    intensity_map = maker.drawIntensityMap(outfolder)
    print('Intensity map saved as: %s' % intensity_map)

    # draw contour maps
    maker.setContourGMTColorMap(tancolormap)

    # Draw pgv contours
    maker.setContourLayer('pgv')
    contour_pgv_map = maker.drawContourMap(outfolder)
    print('PGV contour map saved as: %s' % contour_pgv_map)

    # Draw pga contours
    maker.setContourLayer('pga')
    contour_pga_map = maker.drawContourMap(outfolder)
    print('PGA contour map saved as: %s' % contour_pga_map)

    # Draw psa0.3 contours
    maker.setContourLayer('psa03')
    contour_psa03_map = maker.drawContourMap(outfolder)
    print('PSA0.3 contour map saved as: %s' % contour_psa03_map)

    # Draw psa1.0 contours
    maker.setContourLayer('psa10')
    contour_psa10_map = maker.drawContourMap(outfolder)
    print('PSA1.0 contour map saved as: %s' % contour_psa10_map)

    # Draw psa3.0 contours
    maker.setContourLayer('psa30')
    contour_psa30_map = maker.drawContourMap(outfolder)
    print('PSA3.0 contour map saved as: %s' % contour_psa30_map)
コード例 #18
0
ファイル: fault_test.py プロジェクト: g-weatherill/shakemap
    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]
    fault = Fault.fromTrace(xp0,
                            yp0,
                            xp1,
                            yp1,
                            zp,
                            widths,
                            dips,
                            reference='From J Smith, (personal communication)')


if __name__ == '__main__':
    xp0 = np.array([-118.0])
    xp1 = np.array([-118.0])
    yp0 = np.array([34.0])
    yp1 = np.array([34.5])
    zp = np.array([5.0])
    widths = np.array([10.0])
    dips = np.array([45.0])
    fault = Fault.fromTrace(xp0, yp0, xp1, yp1, zp, widths, dips)

    _test_trace()
    #_test_northridge()
    #_test_correct()
    # _test_incorrect()
コード例 #19
0
ファイル: distance_test.py プロジェクト: cbworden/shakemap
def test_san_fernando():
    # This is a challenging fault due to overlapping and discordant
    # segments, as brought up by Graeme Weatherill. Our initial
    # implementation put the origin on the wrong side of the fault.
    x0 = np.array([7.1845, 7.8693])
    y0 = np.array([-10.3793, -16.2096])
    z0 = np.array([3.0000, 0.0000])
    x1 = np.array([-7.8506, -7.5856])
    y1 = np.array([-4.9073, -12.0682])
    z1 = np.array([3.0000, 0.0000])
    x2 = np.array([-4.6129, -5.5149])
    y2 = np.array([3.9887, -4.3408])
    z2 = np.array([16.0300, 8.0000])
    x3 = np.array([10.4222, 9.9400])
    y3 = np.array([-1.4833, -8.4823])
    z3 = np.array([16.0300, 8.0000])

    epilat = 34.44000
    epilon = -118.41000
    proj = geo.utils.get_orthographic_projection(
        epilon-1, epilon+1, epilat+1, epilat-1)
    lon0,lat0 = proj(x0, y0, reverse = True)
    lon1,lat1 = proj(x1, y1, reverse = True)
    lon2,lat2 = proj(x2, y2, reverse = True)
    lon3,lat3 = proj(x3, y3, reverse = True)

    flt = Fault.fromVertices(
        lon0, lat0, z0, lon1, lat1, z1, lon2, lat2, z2, lon3, lat3, z3)
    flt._segment_index = [0, 1]
    # Make a source object; most of the 'event' values don't matter
    event = {'lat': 0,  'lon': 0, 'depth':0, 'mag': 6.61, 
             'id':'', 'locstring':'', 'type':'U', 
             'time':ShakeDateTime.utcfromtimestamp(int(time.time())), 
             'timezone':'UTC'}
    source = Source(event, flt)

    # Grid of sites
    buf = 0.25
    lat = np.linspace(np.nanmin(flt._lat)-buf, np.nanmax(flt._lat)+buf, 10)
    lon = np.linspace(np.nanmin(flt._lon)-buf, np.nanmax(flt._lon)+buf, 10)
    lons, lats = np.meshgrid(lon, lat)
    dep = np.zeros_like(lons)
    x,y = proj(lon, lat)
    fltx,flty = proj(flt._lon, flt._lat)

    # Calculate U and T
    dtypes = ['U', 'T']
    dists = get_distance(dtypes, lats, lons, dep, source)

    targetU = np.array(
      [[ 29.37395812,  22.56039569,  15.74545461,   8.92543078,
          2.09723735,  -4.73938823, -11.58093887, -18.42177264,
        -25.25743913, -32.08635501],
       [ 31.84149137,  25.03129417,  18.22007124,  11.40292429,
          4.57583886,  -2.26009972,  -9.09790123, -15.92911065,
        -22.75071243, -29.56450963],
       [ 34.30623138,  27.49382948,  20.67774678,  13.85111535,
          7.0115472 ,   0.16942111,  -6.65327488, -13.45181115,
        -20.24352643, -27.03530618],
       [ 36.78170249,  29.96380633,  23.1270492 ,  16.23906653,
          9.32934682,   2.41729624,  -4.2732657 , -10.94940844,
        -17.703852  , -24.4792072 ],
       [ 39.29233805,  32.49155866,  25.68380903,  18.73823089,
         12.08780156,   5.99219619,  -1.38387344,  -8.28331275,
        -15.08759643, -21.87909368],
       [ 41.84662959,  35.09745097,  28.42432401,  21.98993679,
         15.2994003 ,   8.38037254,   1.3900846 ,  -5.5601922 ,
        -12.4250749 , -19.24690137],
       [ 44.41552101,  37.69652131,  31.0257236 ,  24.38573309,
         17.67059825,  10.84688716,   3.96604399,  -2.920931  ,
         -9.78152208, -16.6132751 ],
       [ 46.97201328,  40.2558351 ,  33.55821495,  26.85923974,
         20.12416451,  13.33640001,   6.50905851,  -0.33349597,
         -7.17138975, -13.99568321],
       [ 49.51154107,  42.79053584,  36.07536907,  29.35382731,
         22.61099757,  15.83894006,   9.04135415,   2.22928601,
         -4.58574545, -11.3959888 ],
       [ 52.03832734,  45.31289877,  38.58842009,  31.85764151,
         25.11309728,  18.35066231,  11.57145669,   4.78070229,
         -2.01505508,  -8.81029694]])
    np.testing.assert_allclose(dists['U'], targetU)

    targetT = np.array(
      [[-40.32654805, -38.14066537, -35.95781299, -33.79265063,
        -31.65892948, -29.56075203, -27.48748112, -25.41823592,
        -23.33452174, -21.22822801],
       [-32.28894353, -30.06603457, -27.83163648, -25.61482279,
        -23.45367121, -21.36959238, -19.34738882, -17.33510593,
        -15.28949735, -13.20224592],
       [-24.30254163, -22.03532096, -19.70590091, -17.35907062,
        -15.10840929, -13.02682541, -11.13554925,  -9.25705749,
         -7.26675455,  -5.19396824],
       [-16.41306482, -14.1418547 , -11.68888578,  -8.9318195 ,
         -6.39939727,  -4.10984325,  -2.85061088,  -1.29211846,
          0.68929792,   2.78115216],
       [ -8.63784529,  -6.5089946 ,  -4.32108309,  -1.44275161,
         -0.05102145,  -0.20890633,   3.92700516,   6.36977183,
          8.55572399,  10.72128633],
       [ -0.88135778,   1.06766314,   2.77955566,   3.8241835 ,
          5.99212478,   8.76823285,  11.54715599,  14.0961506 ,
         16.4200502 ,  18.65346494],
       [  6.98140207,   8.91888936,  10.77724993,  12.6499521 ,
         14.79454638,  17.18482779,  19.63520498,  22.03525644,
         24.35152986,  26.60592498],
       [ 14.95635952,  16.95134069,  18.94768299,  20.99811237,
         23.15975573,  25.42700742,  27.74302905,  30.0547134 ,
         32.33583361,  34.58421221],
       [ 22.9921068 ,  25.0353212 ,  27.09829391,  29.20364631,
         31.3678744 ,  33.58684524,  35.8383652 ,  38.09736043,
         40.34713771,  42.58152772],
       [ 31.05186177,  33.1252095 ,  35.21960344,  37.34488267,
         39.50633206,  41.70076344,  43.91762786,  46.14415669,
         48.37021739,  50.59029205]])
    np.testing.assert_allclose(dists['T'], targetT)
コード例 #20
0
def _test_intensity():

    datadir = os.path.abspath(
        os.path.join(homedir, '..', 'data', 'eventdata', 'northridge'))
    shakefile = os.path.join(datadir, 'northridge_grid.xml')
    topofile = os.path.join(datadir, 'northridge_topo.grd')
    faultfile = os.path.join(datadir, 'northridge_fault.txt')
    cityfile = os.path.join(datadir, 'northridge_cities.txt')
    coastfile = os.path.join(datadir, 'northridge_coastline.json')
    countryfile = os.path.join(datadir, 'northridge_countries.json')
    statefile = os.path.join(datadir, 'northridge_states.json')
    lakefile = os.path.join(datadir, 'northridge_lakes.json')
    oceanfile = os.path.join(datadir, 'northridge_ocean.json')
    stationfile = os.path.join(datadir, 'northridge_stations.db')
    roadfile = os.path.join(datadir, 'northridge_roads.json')
    tancptfile = os.path.join(shakedir, 'shakemap', 'mapping', 'tan.cpt')
    shakecptfile = os.path.join(shakedir, 'shakemap', 'mapping',
                                'shakecpt.cpt')

    layerdict = {
        'coast': coastfile,
        'ocean': oceanfile,
        'lake': lakefile,
        'country': countryfile,
        'roads': roadfile,
        'state': statefile
    }

    tancolormap = GMTColorMap.loadFromCPT(tancptfile)
    shakecolormap = GMTColorMap.loadFromCPT(shakecptfile)
    cities = BasemapCities.loadFromCSV(cityfile)
    shakemap = ShakeGrid.load(shakefile, adjust='res')
    stations = StationList(stationfile)
    fault = Fault.readFaultFile(faultfile)
    edict = shakemap.getEventDict()
    eventdict = {
        'lat': edict['lat'],
        'lon': edict['lon'],
        'depth': edict['depth'],
        'mag': edict['magnitude'],
        'time': edict['event_timestamp']
    }
    source = Source(eventdict, fault)
    maker = MapMaker(shakemap, topofile, stations, fault, layerdict, source,
                     cities)

    # draw intensity map
    outfolder = os.path.expanduser('~')
    maker.setIntensityLayer('mmi')
    maker.setIntensityGMTColorMap(shakecolormap)
    intensity_map = maker.drawIntensityMap(outfolder)
    print('Intensity map saved as: %s' % intensity_map)

    # draw contour maps
    maker.setContourGMTColorMap(tancolormap)

    # Draw pgv contours
    maker.setContourLayer('pgv')
    contour_pgv_map = maker.drawContourMap(outfolder)
    print('PGV contour map saved as: %s' % contour_pgv_map)

    # Draw pga contours
    maker.setContourLayer('pga')
    contour_pga_map = maker.drawContourMap(outfolder)
    print('PGA contour map saved as: %s' % contour_pga_map)

    # Draw psa0.3 contours
    maker.setContourLayer('psa03')
    contour_psa03_map = maker.drawContourMap(outfolder)
    print('PSA0.3 contour map saved as: %s' % contour_psa03_map)

    # Draw psa1.0 contours
    maker.setContourLayer('psa10')
    contour_psa10_map = maker.drawContourMap(outfolder)
    print('PSA1.0 contour map saved as: %s' % contour_psa10_map)

    # Draw psa3.0 contours
    maker.setContourLayer('psa30')
    contour_psa30_map = maker.drawContourMap(outfolder)
    print('PSA3.0 contour map saved as: %s' % contour_psa30_map)
コード例 #21
0
def test_chichi():
    print('Testing Chi-Chi...')
    # read in fault file
    f = '../data/0137A.POL'
    i0 = np.arange(0, 9 * 11 * 3, 11)
    i1 = i0 + 10
    cs = zip(i0, i1)
    df = pd.read_fwf(f, cs, skiprows=2, nrows=5, header=None)
    mat = df.as_matrix()
    ix = np.arange(0, 9 * 3, 3)
    iy = ix + 1
    iz = ix + 2
    x0 = mat[0, ix]
    x1 = mat[1, ix]
    x2 = mat[2, ix]
    x3 = mat[3, ix]
    y0 = mat[0, iy]
    y1 = mat[1, iy]
    y2 = mat[2, iy]
    y3 = mat[3, iy]
    # Depth, positive down
    z0 = np.abs(mat[0, iz])
    z1 = np.abs(mat[1, iz])
    z2 = np.abs(mat[2, iz])
    z3 = np.abs(mat[3, iz])
    epilat = 23.85
    epilon = 120.82
    proj = get_orthographic_projection(epilon - 1, epilon + 1, epilat + 1,
                                       epilat - 1)
    lon0, lat0 = proj(x0, y0, reverse=True)
    lon1, lat1 = proj(x1, y1, reverse=True)
    lon2, lat2 = proj(x2, y2, reverse=True)
    lon3, lat3 = proj(x3, y3, reverse=True)
    flt = Fault.fromVertices(lon0, lat0, z0, lon1, lat1, z1, lon2, lat2, z2,
                             lon3, lat3, z3)
    ask14 = AbrahamsonEtAl2014()
    # event information doesn't matter...
    event = {
        'lat': 0,
        'lon': 0,
        'depth': 0,
        'mag': 7,
        'id': '',
        'locstring': '',
        'type': 'U',
        'time': ShakeDateTime.utcfromtimestamp(int(time.time())),
        'timezone': 'UTC'
    }
    source = Source(event, flt)

    # Get NGA distances
    distfile = '../data/NGAW2_distances.csv'
    df = pd.read_csv(distfile)
    df2 = df.loc[df['EQID'] == 137]
    slat = df2['Station Latitude'].as_matrix()
    slon = df2['Station Longitude'].as_matrix()
    sdep = np.zeros(slat.shape)
    nga_repi = df2['EpiD (km)'].as_matrix()
    nga_rhypo = df2['HypD (km)'].as_matrix()
    nga_rrup = df2['ClstD (km)'].as_matrix()
    nga_rjb = df2['Joyner-Boore Dist. (km)'].as_matrix()
    nga_rx = df2['T'].as_matrix()

    dist = Distance(ask14, source, slat, slon, sdep)
    dctx = dist.getDistanceContext()
    fig = plt.figure(figsize=(8, 8))
    plt.scatter(nga_rjb, dctx.rjb, alpha=0.5, facecolors='none')
    plt.plot([0, nga_rjb.max()], [0, dctx.rjb.max()], 'b')
    plt.savefig('Chi-Chi_Rjb.png')
    fig = plt.figure(figsize=(8, 8))
    plt.scatter(nga_rrup, dctx.rrup, alpha=0.5, facecolors='none')
    plt.plot([0, nga_rrup.max()], [0, dctx.rrup.max()], 'b')
    plt.savefig('Chi-Chi_Rrup.png')
    fig = plt.figure(figsize=(8, 8))
    plt.scatter(nga_rx, dctx.rx, alpha=0.5, facecolors='none')
    plt.plot([nga_rx.min(), nga_rx.max()],
             [dctx.rx.min(), dctx.rx.max()], 'b')
    plt.savefig('Chi-Chi_Rx.png')
コード例 #22
0
ファイル: fault_test.py プロジェクト: mhearne-usgs/shakemap
def parse_complicated_fault():
    fault_text = """#SOURCE: Barka, A., H. S. Akyz, E. Altunel, G. Sunal, Z. Akir, A. Dikbas, B. Yerli, R. Armijo, B. Meyer, J. B. d. Chabalier, T. Rockwell, J. R. Dolan, R. Hartleb, T. Dawson, S. Christofferson, A. Tucker, T. Fumal, R. Langridge, H. Stenner, W. Lettis, J. Bachhuber, and W. Page (2002). The Surface Rupture and Slip Distribution of the 17 August 1999 Izmit Earthquake (M 7.4), North Anatolian Fault, Bull. Seism. Soc. Am. 92, 43-60.
    40.70985 29.33760 0
    40.72733 29.51528 0
    40.72933 29.51528 20
    40.71185 29.33760 20
    40.70985 29.33760 0
    >
    40.70513 29.61152 0
    40.74903 29.87519 0
    40.75103 29.87519 20
    40.70713 29.61152 20
    40.70513 29.61152 0
    >
    40.72582 29.88662 0
    40.72336 30.11126 0
    40.73432 30.19265 0
    40.73632 30.19265 20
    40.72536 30.11126 20
    40.72782 29.88662 20
    40.72582 29.88662 0
    >
    40.71210 30.30494 0
    40.71081 30.46540 0
    40.70739 30.56511 0
    40.70939 30.56511 20
    40.71281 30.46540 20
    40.71410 30.30494 20
    40.71210 30.30494 0
    >
    40.71621 30.57658 0
    40.70068 30.63731 0
    40.70268 30.63731 20
    40.71821 30.57658 20
    40.71621 30.57658 0
    >
    40.69947 30.72900 0
    40.79654 30.93655 0
    40.79854 30.93655 20
    40.70147 30.72900 20
    40.69947 30.72900 0
    >
    40.80199 30.94688 0
    40.84501 31.01799 0
    40.84701 31.01799 20
    40.80399 30.94688 20
    40.80199 30.94688 0"""

    cbuf = io.StringIO(fault_text)
    fault = Fault.readFaultFile(cbuf)
    strike = fault.getStrike()
    np.testing.assert_allclose(strike, -100.464330, atol=0.001)
    dip = fault.getDip()
    np.testing.assert_allclose(dip, 89.3985, atol=0.001)
    L = fault.getFaultLength()
    np.testing.assert_allclose(L, 119.5578, atol=0.001)
    W = fault.getWidth()
    np.testing.assert_allclose(W, 20.001, atol=0.001)
    nq = fault.getNumQuads()
    np.testing.assert_allclose(nq, 9)
    ns = fault.getNumSegments()
    np.testing.assert_allclose(ns, 7)
    sind = fault._getSegmentIndex()
    np.testing.assert_allclose(sind, [0, 1, 2, 2, 3, 3, 4, 5, 6])
    ztor = fault.getTopOfRupture()
    np.testing.assert_allclose(ztor, 0, atol=0.001)
    itl = fault.getIndividualTopLengths()
    itl_d = np.array([15.13750778,  22.80237887,  18.98053425,   6.98263853,
                      13.55978731,   8.43444811,   5.41399812,  20.57788056,
                      7.66869463])
    np.testing.assert_allclose(itl, itl_d, atol=0.001)
    iw = fault.getIndividualWidths()
    iw_d = np.array([20.00122876,  20.00122608,  20.00120173,  20.00121028,
                     20.00121513,  20.00121568,  20.00107293,  20.00105498,
                     20.00083348])
    np.testing.assert_allclose(iw, iw_d, atol=0.001)
    lats = fault.getLats()
    lats_d = np.array([40.70985, 40.72733, 40.72933, 40.71185, 40.70985,
                       np.nan, 40.70513, 40.74903, 40.75103, 40.70713,
                       40.70513, np.nan, 40.72582, 40.72336, 40.73432,
                       40.73632, 40.72536, 40.72782, 40.72582, np.nan,
                       40.7121, 40.71081, 40.70739, 40.70939, 40.71281,
                       40.7141, 40.7121, np.nan, 40.71621, 40.70068,
                       40.70268, 40.71821, 40.71621, np.nan, 40.69947,
                       40.79654, 40.79854, 40.70147, 40.69947, np.nan,
                       40.80199, 40.84501, 40.84701, 40.80399, 40.80199])
    np.testing.assert_allclose(lats, lats_d, atol=0.001)
    lons = fault.getLons()
    lons_d = np.array([29.3376, 29.51528, 29.51528, 29.3376, 29.3376,
                       np.nan, 29.61152, 29.87519, 29.87519, 29.61152,
                       29.61152, np.nan, 29.88662, 30.11126, 30.19265,
                       30.19265, 30.11126, 29.88662, 29.88662, np.nan,
                       30.30494, 30.4654, 30.56511, 30.56511, 30.4654,
                       30.30494, 30.30494, np.nan, 30.57658, 30.63731,
                       30.63731, 30.57658, 30.57658, np.nan, 30.729,
                       30.93655, 30.93655, 30.729, 30.729, np.nan,
                       30.94688,  31.01799, 31.01799, 30.94688, 30.94688])
    np.testing.assert_allclose(lons, lons_d, atol=0.001)
コード例 #23
0
def parse_complicated_fault():
    fault_text = """#SOURCE: Barka, A., H. S. Akyz, E. Altunel, G. Sunal, Z. Akir, A. Dikbas, B. Yerli, R. Armijo, B. Meyer, J. B. d. Chabalier, T. Rockwell, J. R. Dolan, R. Hartleb, T. Dawson, S. Christofferson, A. Tucker, T. Fumal, R. Langridge, H. Stenner, W. Lettis, J. Bachhuber, and W. Page (2002). The Surface Rupture and Slip Distribution of the 17 August 1999 Izmit Earthquake (M 7.4), North Anatolian Fault, Bull. Seism. Soc. Am. 92, 43-60.
    40.70985 29.33760 0
    40.72733 29.51528 0
    40.72933 29.51528 20
    40.71185 29.33760 20
    40.70985 29.33760 0
    >
    40.70513 29.61152 0
    40.74903 29.87519 0
    40.75103 29.87519 20
    40.70713 29.61152 20
    40.70513 29.61152 0
    >
    40.72582 29.88662 0
    40.72336 30.11126 0
    40.73432 30.19265 0
    40.73632 30.19265 20
    40.72536 30.11126 20
    40.72782 29.88662 20
    40.72582 29.88662 0
    >
    40.71210 30.30494 0
    40.71081 30.46540 0
    40.70739 30.56511 0
    40.70939 30.56511 20
    40.71281 30.46540 20
    40.71410 30.30494 20
    40.71210 30.30494 0
    >
    40.71621 30.57658 0
    40.70068 30.63731 0
    40.70268 30.63731 20
    40.71821 30.57658 20
    40.71621 30.57658 0
    >
    40.69947 30.72900 0
    40.79654 30.93655 0
    40.79854 30.93655 20
    40.70147 30.72900 20
    40.69947 30.72900 0
    >
    40.80199 30.94688 0
    40.84501 31.01799 0
    40.84701 31.01799 20
    40.80399 30.94688 20
    40.80199 30.94688 0"""

    cbuf = io.StringIO(fault_text)
    fault = Fault.readFaultFile(cbuf)
    strike = fault.getStrike()
    np.testing.assert_allclose(strike, -100.464330, atol=0.001)
    dip = fault.getDip()
    np.testing.assert_allclose(dip, 89.3985, atol=0.001)
    L = fault.getFaultLength()
    np.testing.assert_allclose(L, 119.5578, atol=0.001)
    W = fault.getWidth()
    np.testing.assert_allclose(W, 20.001, atol=0.001)
    nq = fault.getNumQuads()
    np.testing.assert_allclose(nq, 9)
    ns = fault.getNumSegments()
    np.testing.assert_allclose(ns, 7)
    sind = fault._getSegmentIndex()
    np.testing.assert_allclose(sind, [0, 1, 2, 2, 3, 3, 4, 5, 6])
    ztor = fault.getTopOfRupture()
    np.testing.assert_allclose(ztor, 0, atol=0.001)
    itl = fault.getIndividualTopLengths()
    itl_d = np.array([
        15.13750778, 22.80237887, 18.98053425, 6.98263853, 13.55978731,
        8.43444811, 5.41399812, 20.57788056, 7.66869463
    ])
    np.testing.assert_allclose(itl, itl_d, atol=0.001)
    iw = fault.getIndividualWidths()
    iw_d = np.array([
        20.00122876, 20.00122608, 20.00120173, 20.00121028, 20.00121513,
        20.00121568, 20.00107293, 20.00105498, 20.00083348
    ])
    np.testing.assert_allclose(iw, iw_d, atol=0.001)
    lats = fault.getLats()
    lats_d = np.array([
        40.70985, 40.72733, 40.72933, 40.71185, 40.70985, np.nan, 40.70513,
        40.74903, 40.75103, 40.70713, 40.70513, np.nan, 40.72582, 40.72336,
        40.73432, 40.73632, 40.72536, 40.72782, 40.72582, np.nan, 40.7121,
        40.71081, 40.70739, 40.70939, 40.71281, 40.7141, 40.7121, np.nan,
        40.71621, 40.70068, 40.70268, 40.71821, 40.71621, np.nan, 40.69947,
        40.79654, 40.79854, 40.70147, 40.69947, np.nan, 40.80199, 40.84501,
        40.84701, 40.80399, 40.80199
    ])
    np.testing.assert_allclose(lats, lats_d, atol=0.001)
    lons = fault.getLons()
    lons_d = np.array([
        29.3376, 29.51528, 29.51528, 29.3376, 29.3376, np.nan, 29.61152,
        29.87519, 29.87519, 29.61152, 29.61152, np.nan, 29.88662, 30.11126,
        30.19265, 30.19265, 30.11126, 29.88662, 29.88662, np.nan, 30.30494,
        30.4654, 30.56511, 30.56511, 30.4654, 30.30494, 30.30494, np.nan,
        30.57658, 30.63731, 30.63731, 30.57658, 30.57658, np.nan, 30.729,
        30.93655, 30.93655, 30.729, 30.729, np.nan, 30.94688, 31.01799,
        31.01799, 30.94688, 30.94688
    ])
    np.testing.assert_allclose(lons, lons_d, atol=0.001)
コード例 #24
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)
コード例 #25
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)
コード例 #26
0
ファイル: distance_test.py プロジェクト: klin-usgs/shakemap
def test_chichi():
    print('Testing Chi-Chi...')
    # read in fault file
    f = '../data/0137A.POL'
    i0 = np.arange(0, 9*11*3, 11)
    i1 = i0 + 10
    cs = zip(i0, i1)
    df = pd.read_fwf(f, cs, skiprows = 2, nrows = 5, header = None)
    mat = df.as_matrix()
    ix = np.arange(0, 9*3, 3)
    iy = ix + 1
    iz = ix + 2
    x0 = mat[0, ix]
    x1 = mat[1, ix]
    x2 = mat[2, ix]
    x3 = mat[3, ix]
    y0 = mat[0, iy]
    y1 = mat[1, iy]
    y2 = mat[2, iy]
    y3 = mat[3, iy]
    # Depth, positive down
    z0 = np.abs(mat[0, iz])
    z1 = np.abs(mat[1, iz])
    z2 = np.abs(mat[2, iz])
    z3 = np.abs(mat[3, iz])
    epilat = 23.85
    epilon = 120.82
    proj = get_orthographic_projection(
        epilon-1, epilon+1, epilat+1, epilat-1)
    lon0,lat0 = proj(x0, y0, reverse = True)
    lon1,lat1 = proj(x1, y1, reverse = True)
    lon2,lat2 = proj(x2, y2, reverse = True)
    lon3,lat3 = proj(x3, y3, reverse = True)
    flt = Fault.fromVertices(
        lon0, lat0, z0, lon1, lat1, z1, lon2, lat2, z2, lon3, lat3, z3)
    ask14 = AbrahamsonEtAl2014()
    # event information doesn't matter...
    event = {'lat': 0,  'lon': 0, 'depth':0, 'mag': 7, 
             'id':'', 'locstring':'', 'type':'U', 
             'time':ShakeDateTime.utcfromtimestamp(int(time.time())), 
             'timezone':'UTC'}
    source = Source(event, flt)
    
    # Get NGA distances
    distfile = '../data/NGAW2_distances.csv'
    df = pd.read_csv(distfile)
    df2 = df.loc[df['EQID'] == 137]
    slat = df2['Station Latitude'].as_matrix()
    slon = df2['Station Longitude'].as_matrix()
    sdep = np.zeros(slat.shape)
    nga_repi = df2['EpiD (km)'].as_matrix()
    nga_rhypo = df2['HypD (km)'].as_matrix()
    nga_rrup = df2['ClstD (km)'].as_matrix()
    nga_rjb = df2['Joyner-Boore Dist. (km)'].as_matrix()
    nga_rx = df2['T'].as_matrix()
    
    dist = Distance(ask14, source, slat, slon, sdep)
    dctx = dist.getDistanceContext()
    fig = plt.figure(figsize=(8,8))
    plt.scatter(nga_rjb, dctx.rjb, alpha = 0.5, facecolors='none')
    plt.plot([0, nga_rjb.max()], [0, dctx.rjb.max()], 'b');
    plt.savefig('Chi-Chi_Rjb.png')
    fig = plt.figure(figsize=(8,8))
    plt.scatter(nga_rrup, dctx.rrup, alpha = 0.5, facecolors='none')
    plt.plot([0, nga_rrup.max()], [0, dctx.rrup.max()], 'b');
    plt.savefig('Chi-Chi_Rrup.png')
    fig = plt.figure(figsize=(8,8))
    plt.scatter(nga_rx, dctx.rx, alpha = 0.5, facecolors='none')
    plt.plot([nga_rx.min(), nga_rx.max()],
             [dctx.rx.min(), dctx.rx.max()], 'b');
    plt.savefig('Chi-Chi_Rx.png')
コード例 #27
0
def test_chichi_with_get_distance():
    # read in fault file
    f = os.path.join(shakedir, 'tests/data/0137A.POL')
    i0 = np.arange(0, 9 * 11 * 3, 11)
    i1 = i0 + 10
    cs = list(zip(i0, i1))
    df = pd.read_fwf(f, cs, skiprows=2, nrows=5, header=None)
    mat = df.as_matrix()
    ix = np.arange(0, 9 * 3, 3)
    iy = ix + 1
    iz = ix + 2
    x0 = mat[0, ix]
    x1 = mat[1, ix]
    x2 = mat[2, ix]
    x3 = mat[3, ix]
    y0 = mat[0, iy]
    y1 = mat[1, iy]
    y2 = mat[2, iy]
    y3 = mat[3, iy]
    # Depth, positive down
    z0 = np.abs(mat[0, iz])
    z1 = np.abs(mat[1, iz])
    z2 = np.abs(mat[2, iz])
    z3 = np.abs(mat[3, iz])
    epilat = 23.85
    epilon = 120.82
    proj = get_orthographic_projection(
        epilon - 1, epilon + 1, epilat + 1, epilat - 1)
    lon0, lat0 = proj(x0, y0, reverse=True)
    lon1, lat1 = proj(x1, y1, reverse=True)
    lon2, lat2 = proj(x2, y2, reverse=True)
    lon3, lat3 = proj(x3, y3, reverse=True)
    flt = Fault.fromVertices(
        lon0, lat0, z0, lon1, lat1, z1, lon2, lat2, z2, lon3, lat3, z3)
    # event information doesn't matter except hypocenter
    event = {'lat': 23.85, 'lon': 120.82, 'depth': 8, 'mag': 7.62,
             'id': '', 'locstring': '', 'type': 'U',
             'time': ShakeDateTime.utcfromtimestamp(int(time.time())),
             'timezone': 'UTC'}
    source = Source(event, flt)

    # Get NGA distances
    distfile = os.path.join(shakedir, 'tests/data/NGAW2_distances.csv')
    df = pd.read_csv(distfile)
    df2 = df.loc[df['EQID'] == 137]
    slat = df2['Station Latitude'].as_matrix()
    slon = df2['Station Longitude'].as_matrix()
    sdep = np.zeros(slat.shape)
    nga_repi = df2['EpiD (km)'].as_matrix()
    nga_rhypo = df2['HypD (km)'].as_matrix()
    nga_rrup = df2['ClstD (km)'].as_matrix()
    nga_rjb = df2['Joyner-Boore Dist. (km)'].as_matrix()
    nga_rx = df2['T'].as_matrix()
    nga_T = df2['T'].as_matrix()
    nga_U = df2['U'].as_matrix()
    test_ry = np.array([
        -49.25445446, -76.26871272, -37.1288192, -53.47792996,
        -50.30711637, -63.96322125, -61.01988704, -81.2001781,
        -76.00646939, -74.39038054, -92.23617124, -90.66976945,
        -89.68551411, -102.98798328, -114.70036085, -29.83636082,
        -28.50133134, -27.86922916, -36.00619214, -44.68826209,
        -47.64580208, -53.92619079, -59.11962858, -55.90584822,
        -55.00772025, -48.81756715, -59.27542007, -62.13633659,
        -70.0673351, -75.96977638, -61.6959293, -60.34564074,
        -81.49792285, -78.75933138, -80.80533738, -85.24473008,
        -94.07519297, -93.75010471, -96.87089883, -100.06112271,
        -98.86980873, -95.92330113, -107.44086722, -119.1065369,
        -120.60405905, -113.42995442, -115.94930662, -115.2398216,
        -107.37840927, -49.25445446, -48.78386688, -108.49133002,
        -88.03303353, -44.66653428, -81.04476548, -38.26801619,
        -70.51178983, -69.15679931, -74.74562139, -86.51133446,
        -27.62153029, -48.33279375, -30.0808298, -113.98345018,
        -97.96609537, -87.9863122, -39.45970018, -80.1387617,
        -42.27121388, -82.05027834, -81.55987067, -81.55987067,
        -107.25255717, 67.62695516, -3.27797047, -197.98554369,
        82.30996151, 18.42180605, -22.88851072, -35.75245916,
        -19.54788146, -18.19780517, 19.85077702, 20.33310282,
        19.95448398, 20.55508903, 18.17428572, 17.87997374,
        16.97323804, 16.0025885, 13.88001846, 18.42180605,
        -3.27797047, 51.43098894, 28.97695533, -53.20579538,
        38.7537468, 33.48878882, 26.25189111, 22.54251612,
        13.37141837, -5.80928302, -6.68056794, -14.50860117,
        -15.23992093, -27.63281952, -11.66075049, -36.94595337,
        -40.97168031, -41.2814342, -48.64456898, -61.55777751,
        -11.15038984, -17.16482959, 55.84202839, 36.78540588,
        21.18550074, 19.14658833, 19.22680282, 5.76327358,
        -47.45309937, -44.33194991, -55.15852372, 37.33066096,
        37.64135657, 14.31598698, 4.60495737, 6.87107021,
        18.42180605, 113.59285783, 109.06420877, 104.23416509,
        99.21599973, 95.25204545, 90.29487934, 86.26977557,
        95.28705209, 87.12907925, 101.40561896, 96.68858152,
        92.90287952, 100.36659012, 97.19448577, 92.8627461,
        85.01448355, 93.36767736, 96.90824009, 86.48002825,
        88.71037964, 106.17282325, 102.56142319, 97.60004093,
        99.61798574, 97.36337239, 94.22000798, 86.99488734,
        90.05981676, 90.51189502, 100.7166391, 100.31931988,
        67.62695516, 94.15062409, 87.77053675, 124.21806013,
        99.23108884, 101.48199452, 92.63771423, 78.88723272,
        72.7261356, 80.58682246, 73.30258213, 70.20783518,
        60.57963211, -87.72265602, -148.10933308, -150.41334959,
        -144.12558375, -145.5625388, -132.09479688, -135.12980144,
        -121.10883695, -143.75755221, -117.73616176, -115.28563276,
        -138.79652905, -143.10405603, -151.78419035, -159.75299736,
        -149.69457229, -175.20332448, -181.00970647, -188.86536942,
        -176.88178468, -194.20978527, -204.54944453, -161.04413103,
        -197.98554369, -96.74089367, -133.49237232, -84.71198922,
        -164.97719097, -202.48241157, -74.54550169, -147.37402934,
        -144.64074441, -147.94282804, -122.80976842, -133.1671346,
        -136.3051809, -113.93174768, -151.02125407, -146.5198829,
        -156.19720713, -126.06138725, -131.44422964, -197.62591198,
        -204.42320856, -149.84576063, -121.56474664, -130.99947339,
        -148.41767074, -145.28448367, 104.58903799, 82.1649906,
        67.69977397, 39.46989193, -69.00949731, -133.49237232,
        -128.264754, -84.71198922, -108.49133002, 119.86128724,
        122.73556155, 126.28254009, 125.12436373, 123.32498578,
        123.8337768, 121.39931427, 121.48412837, 122.03669249,
        122.59675818, 119.54338365, 120.33961222, 120.69581745,
        116.96928355, 117.6687724, 116.62277942, 115.39650689,
        112.60751523, 109.82643069, 108.2500678, 130.9143614,
        126.50049543, 112.76229057, 132.76840098, 107.27099883,
        128.16063464, 123.83157143, 120.46711628, 112.55756637,
        135.59953867, 136.66138116, 136.98573162, 134.04528777,
        116.27744752, 129.2794577, 119.13550981, 124.67196321,
        130.9728774, 130.9039439, 128.70028371, 130.04592892,
        140.21819548, 140.60370422, 113.37585901, 123.21523323,
        123.88149248, 128.56894995, 128.45186255, 118.74080853,
        126.71189149, 119.79833338, 130.00866791, -160.01242472,
        13.55424709, 110.26938756, 97.71987778, 110.93671325,
        108.71965725, 105.03432063, 106.36049687, 99.27569343,
        115.06168146, 77.00378531, 81.50139192, 92.15605815,
        79.94311644, 83.16892433, 52.23389149, 50.97110177,
        67.95167063, 63.43930833, 40.20494692, 43.22936492,
        47.21513635, 38.94380012, 53.85489136, 56.69935207,
        48.07036522, 64.46887891, 14.98020647, 17.35046801,
        16.15236633, 14.41062231, 19.99605739, 18.31076661,
        15.07058247, 12.34339267, 13.57621451, 14.72685201,
        22.04539325, 20.47982142, 9.66768974, 8.05139052,
        29.22924869, 3.75876894, 7.8610467, 29.20272495,
        15.19325822, -2.38981899, 5.58349359, -0.62239018,
        -4.38178769, -11.43651893, -20.07048519, -16.0588668,
        82.30996151, 13.55424709, 104.49355303, -11.29628168,
        82.1649906, 34.22207039, 38.08490923, -10.15855131,
        111.0308369, 81.78397481, 73.56334665, 81.27164139,
        74.55979012, 16.08437955, 23.8203941, 24.68836209,
        28.73767914, 21.06714416, 19.44159522, 4.62135887,
        3.41771413, 5.051121, -6.81834189, 6.40341853,
        -0.35693923, -17.74409367, -8.91759817, -18.05278804,
        7.70695248, -5.52733835, -16.02924961, -4.54310111,
        -22.84234773, -1.71908199, 39.46989193, -14.74007542,
        23.59992543, -10.49966883, -11.47733869, -22.8200901,
        -9.72486483, 95.96997763, -115.36487081, -52.88924268,
        -90.2275069, -132.22657274, -100.52455976, -115.24052939,
        -113.84482359, -114.41088165, -114.63386688, -115.92829006,
        -117.52597227, -114.49770514, -114.46881502, -76.26871272,
        -115.36487081, -160.01242472, -110.6429636, -77.47722955,
        -80.24672646, -85.90422427, -94.92075147, -102.44309541,
        -106.23741455, -111.56110193, -115.13402727, -48.64043046,
        -60.86151946, -66.52137871, -110.04628212, -75.27694696,
        -78.87041369, -88.08700161, -90.18844188, -93.65776393,
        -92.58976279, -107.31364843, -115.04064471, -125.98500718,
        -75.9341032, -39.45970018, -14.74007542, -23.16835763])
    test_ry0 = np.array([
        5.38783354, 32.4020918, 0., 9.61130904,
        6.44049545, 20.09660033, 17.15326613, 37.33355718,
        32.13984847, 30.52375962, 48.36955032, 46.80314854,
        45.81889319, 59.12136236, 70.83373993, 0.,
        0., 0., 0., 0.82164117,
        3.77918116, 10.05956987, 15.25300766, 12.0392273,
        11.14109933, 4.95094623, 15.40879915, 18.26971567,
        26.20071419, 32.10315546, 17.82930838, 16.47901983,
        37.63130193, 34.89271046, 36.93871646, 41.37810916,
        50.20857205, 49.88348379, 53.00427791, 56.19450179,
        55.00318781, 52.05668021, 63.5742463, 75.23991598,
        76.73743813, 69.5633335, 72.0826857, 71.37320068,
        63.51178836, 5.38783354, 4.91724596, 64.6247091,
        44.16641261, 0.79991336, 37.17814456, 0.,
        26.64516892, 25.2901784, 30.87900047, 42.64471355,
        0., 4.46617283, 0., 70.11682926,
        54.09947445, 44.11969128, 0., 36.27214079,
        0., 38.18365743, 37.69324975, 37.69324975,
        63.38593626, 31.95985109, 0., 154.11892278,
        46.64285745, 0., 0., 0.,
        0., 0., 0., 0.,
        0., 0., 0., 0.,
        0., 0., 0., 0.,
        0., 15.76388487, 0., 9.33917446,
        3.08664273, 0., 0., 0.,
        0., 0., 0., 0.,
        0., 0., 0., 0.,
        0., 0., 4.77794806, 17.69115659,
        0., 0., 20.17492433, 1.11830182,
        0., 0., 0., 0.,
        3.58647845, 0.46532899, 11.2919028, 1.6635569,
        1.97425251, 0., 0., 0.,
        0., 77.92575377, 73.39710471, 68.56706103,
        63.54889567, 59.58494138, 54.62777528, 50.6026715,
        59.61994802, 51.46197518, 65.7385149, 61.02147746,
        57.23577546, 64.69948606, 61.52738171, 57.19564204,
        49.34737949, 57.7005733, 61.24113602, 50.81292419,
        53.04327558, 70.50571919, 66.89431913, 61.93293686,
        63.95088168, 61.69626833, 58.55290391, 51.32778327,
        54.3927127, 54.84479095, 65.04953504, 64.65221582,
        31.95985109, 58.48352003, 52.10343269, 88.55095607,
        63.56398477, 65.81489046, 56.97061016, 43.22012866,
        37.05903154, 44.9197184, 37.63547806, 34.54073112,
        24.91252804, 43.85603511, 104.24271216, 106.54672867,
        100.25896283, 101.69591788, 88.22817597, 91.26318052,
        77.24221603, 99.89093129, 73.86954084, 71.41901185,
        94.92990813, 99.23743511, 107.91756944, 115.88637645,
        105.82795138, 131.33670356, 137.14308555, 144.9987485,
        133.01516376, 150.34316435, 160.68282361, 117.17751011,
        154.11892278, 52.87427275, 89.6257514, 40.8453683,
        121.11057005, 158.61579065, 30.67888078, 103.50740842,
        100.77412349, 104.07620713, 78.9431475, 89.30051368,
        92.43855998, 70.06512676, 107.15463315, 102.65326198,
        112.33058622, 82.19476634, 87.57760872, 153.75929106,
        160.55658764, 105.97913971, 77.69812572, 87.13285248,
        104.55104982, 101.41786275, 68.92193392, 46.49788654,
        32.0326699, 3.80278787, 25.14287639, 89.6257514,
        84.39813309, 40.8453683, 64.6247091, 84.19418317,
        87.06845748, 90.61543602, 89.45725966, 87.65788171,
        88.16667274, 85.73221021, 85.81702431, 86.36958842,
        86.92965411, 83.87627959, 84.67250815, 85.02871339,
        81.30217949, 82.00166833, 80.95567535, 79.72940282,
        76.94041117, 74.15932662, 72.58296373, 95.24725733,
        90.83339137, 77.0951865, 97.10129692, 71.60389476,
        92.49353057, 88.16446736, 84.80001222, 76.89046231,
        99.93243461, 100.9942771, 101.31862755, 98.37818371,
        80.61034346, 93.61235363, 83.46840575, 89.00485915,
        95.30577334, 95.23683984, 93.03317965, 94.37882485,
        104.55109142, 104.93660016, 77.70875494, 87.54812917,
        88.21438842, 92.90184589, 92.78475848, 83.07370447,
        91.04478743, 84.13122931, 94.34156384, 116.14580381,
        0., 74.60228349, 62.05277372, 75.26960919,
        73.05255319, 69.36721657, 70.69339281, 63.60858937,
        79.3945774, 41.33668124, 45.83428785, 56.48895409,
        44.27601238, 47.50182027, 16.56678743, 15.30399771,
        32.28456656, 27.77220427, 4.53784286, 7.56226086,
        11.54803229, 3.27669605, 18.1877873, 21.032248,
        12.40326116, 28.80177485, 0., 0.,
        0., 0., 0., 0.,
        0., 0., 0., 0.,
        0., 0., 0., 0.,
        0., 0., 0., 0.,
        0., 0., 0., 0.,
        0., 0., 0., 0.,
        46.64285745, 0., 68.82644897, 0.,
        46.49788654, 0., 2.41780516, 0.,
        75.36373283, 46.11687074, 37.89624258, 45.60453732,
        38.89268605, 0., 0., 0.,
        0., 0., 0., 0.,
        0., 0., 0., 0.,
        0., 0., 0., 0.,
        0., 0., 0., 0.,
        0., 0., 3.80278787, 0.,
        0., 0., 0., 0.,
        0., 60.30287357, 71.49824989, 9.02262176,
        46.36088598, 88.35995182, 56.65793884, 71.37390848,
        69.97820268, 70.54426073, 70.76724596, 72.06166914,
        73.65935135, 70.63108422, 70.6021941, 32.4020918,
        71.49824989, 116.14580381, 66.77634268, 33.61060864,
        36.38010555, 42.03760335, 51.05413055, 58.57647449,
        62.37079364, 67.69448101, 71.26740635, 4.77380954,
        16.99489854, 22.65475779, 66.1796612, 31.41032604,
        35.00379277, 44.22038069, 46.32182096, 49.79114301,
        48.72314188, 63.44702751, 71.1740238, 82.11838626,
        32.06748228, 0., 0., 0.])

    dist_types = ['repi', 'rhypo', 'rjb', 'rrup', 'rx', 'ry', 'ry0', 'U', 'T']
    dists = get_distance(dist_types, slat, slon, sdep, source)

    np.testing.assert_allclose(
        nga_repi, dists['repi'], rtol=0, atol=2)

    np.testing.assert_allclose(
        nga_rhypo, dists['rhypo'], rtol=0, atol=2)

    np.testing.assert_allclose(
        nga_rjb, dists['rjb'], rtol=0, atol=2)

    np.testing.assert_allclose(
        nga_rrup, dists['rrup'], rtol=0, atol=2)

    np.testing.assert_allclose(
        nga_rx, dists['rx'], rtol=0, atol=2)

    np.testing.assert_allclose(
        test_ry, dists['ry'], rtol=0, atol=2)

    np.testing.assert_allclose(
        test_ry0, dists['ry0'], rtol=0, atol=2)

    np.testing.assert_allclose(
        nga_U, dists['U'], rtol=0, atol=6)

    np.testing.assert_allclose(
        nga_T, dists['T'], rtol=0, atol=2)