Ejemplo n.º 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]

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

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

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

    xp0 = [-121.81529, -121.82298]
    xp1 = [-121.82298, -121.83068]
    yp0 = [37.73707, 37.74233]
    yp1 = [37.74233, 37.74758]
    zp = [10, 15]
    widths = [15.0, 20.0]
    dips = [30.0, 45.0]
    rupture = QuadRupture.fromTrace(
        xp0, yp0, xp1, yp1, zp, widths,
        dips, reference='From J Smith, (personal communication)')
Ejemplo n.º 3
0
def test_misc():
    # Make a rupture
    lat0 = np.array([34.1])
    lon0 = np.array([-118.2])
    lat1 = np.array([34.2])
    lon1 = np.array([-118.15])
    z = np.array([1.0])
    W = np.array([3.0])
    dip = np.array([30.])
    flt = QuadRupture.fromTrace(lon0, lat0, lon1, lat1, z, W, dip)
    fm = flt.getRuptureAsMesh()
    fa = flt.getRuptureAsArrays()
    ref = flt.getReference()
Ejemplo 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)
Ejemplo 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)
Ejemplo n.º 6
0
def test_slip():
    # Make a rupture
    lat0 = np.array([34.1])
    lon0 = np.array([-118.2])
    lat1 = np.array([34.2])
    lon1 = np.array([-118.15])
    z = np.array([1.0])
    W = np.array([3.0])
    dip = np.array([30.])
    flt = QuadRupture.fromTrace(lon0, lat0, lon1, lat1, z, W, dip)

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

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

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

    slp = get_local_unit_slip_vector(22, 30, 86).getArray()
    slpd = np.array([0.82714003,  0.38830563,  0.49878203])
    np.testing.assert_allclose(slp, slpd)
Ejemplo n.º 8
0
def test_chichi_with_get_distance():
    # read in rupture 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)
    # event information doesn't matter except hypocenter
    event = {'lat': 23.85, 'lon': 120.82, 'depth': 8, 'mag': 7.62,
             'id': '', 'locstring': '', 'type': 'ALL',
             'timezone': 'UTC'}
    origin = Origin(event)
    rup = QuadRupture.fromVertices(
        lon0, lat0, z0, lon1, lat1, z1, lon2, lat2, z2, lon3, lat3, z3,
        origin)

    # 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, rup)

    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)
Ejemplo n.º 9
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)
Ejemplo n.º 10
0
def test_san_fernando():
    # This is a challenging rupture due to overlapping and discordant
    # segments, as brought up by Graeme Weatherill. Our initial
    # implementation put the origin on the wrong side of the rupture.
    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)

    # Rupture requires an origin even when not used:
    origin = Origin({'id':'test','lat':0,'lon':0,'depth':5.0,'mag':7.0})
    rup = QuadRupture.fromVertices(
        lon0, lat0, z0, lon1, lat1, z1, lon2, lat2, z2, lon3, lat3, z3,
        origin)
    # Make a origin object; most of the 'event' values don't matter
    event = {'lat': 0,  'lon': 0, 'depth':0, 'mag': 6.61, 
             'id':'', 'locstring':'', 'type':'ALL', 
             'timezone':'UTC'}
    origin = Origin(event)

    # Grid of sites
    buf = 0.25
    lat = np.linspace(np.nanmin(rup._lat)-buf, np.nanmax(rup._lat)+buf, 10)
    lon = np.linspace(np.nanmin(rup._lon)-buf, np.nanmax(rup._lon)+buf, 10)
    lons, lats = np.meshgrid(lon, lat)
    dep = np.zeros_like(lons)
    x,y = proj(lon, lat)
    rupx,rupy = proj(rup._lon[~np.isnan(rup._lon)],
                     rup._lat[~np.isnan(rup._lat)])

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

    # new method:
    from shakemap.grind.rupture import _computeGC2
    ddict = _computeGC2(rup, lons, lats, dep)

    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, atol = 0.01)

    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, atol = 0.01)
Ejemplo n.º 11
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")
    rupturefile = 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)
    rupture = QuadRupture.readRuptureFile(rupturefile)
    edict = shakemap.getEventDict()
    eventdict = {
        "lat": edict["lat"],
        "lon": edict["lon"],
        "depth": edict["depth"],
        "mag": edict["magnitude"],
        "time": edict["event_timestamp"],
    }
    source = Source(eventdict, rupture)
    maker = MapMaker(shakemap, topofile, stations, rupture, 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)
Ejemplo n.º 12
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')
    rupturefile = 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)
    rupture = QuadRupture.readRuptureFile(rupturefile)
    edict = shakemap.getEventDict()
    eventdict = {'lat': edict['lat'],
                 'lon': edict['lon'],
                 'depth': edict['depth'],
                 'mag': edict['magnitude'],
                 'time': edict['event_timestamp']}
    origin = Origin(eventdict)
    maker = MapMaker(shakemap, topofile, stations,
                     rupture, layerdict, origin, 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)
Ejemplo n.º 13
0
def test_multisegment_discordant():
    # The one thing that isn't check above is discordancy for segments
    # with multiple quads. For this, we need a synthetic example.
    x0 = np.array([0, 1, -1, 10, 9, 7])
    y0 = np.array([0, 10, 20, 40, 35, 30])
    z0 = np.array([0, 0, 0, 0, 0, 0])
    x1 = np.array([1, -1, 0, 9, 7, 6])
    y1 = np.array([10, 20, 30, 35, 30, 25])
    z1 = np.array([0, 0, 0, 0, 0, 0])
    x2 = np.array([3, 1, 2, 7, 5, 4])
    y2 = np.array([10, 20, 30, 35, 30, 25])
    z2 = np.array([10, 10, 10, 10, 10, 10])
    x3 = np.array([2, 3, 1, 8, 7, 5])
    y3 = np.array([0, 10, 20, 40, 35, 30])
    z3 = np.array([10, 10, 10, 10, 10, 10])

    epilat = 32.15270
    epilon = -115.30500
    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)

    # Make an Origin object; most of the 'event' values don't matter for this example
    origin = Origin({"lat": 0, "lon": 0, "depth": 0, "mag": 7.2, "id": ""})
    rup = QuadRupture.fromVertices(
        lon0, lat0, z0, lon1, lat1, z1, lon2, lat2, z2, lon3, lat3, z3, origin, group_index=[0, 0, 0, 1, 1, 1]
    )

    # Sites
    buf = 0.25
    lat = np.linspace(np.nanmin(rup.lats) - buf, np.nanmax(rup.lats) + buf, 20)
    lon = np.linspace(np.nanmin(rup.lons) - buf, np.nanmax(rup.lons) + buf, 20)
    lons, lats = np.meshgrid(lon, lat)
    dep = np.zeros_like(lons)
    x, y = proj(lon, lat)
    rupx, rupy = proj(rup.lons, rup.lats)
    # Calculate U and T
    dtypes = ["U", "T"]
    dists = get_distance(dtypes, lats, lons, dep, rup)

    targetU = np.array(
        [
            [
                -28.53228275,
                -28.36479713,
                -28.20139732,
                -28.0407734,
                -27.88135558,
                -27.72144153,
                -27.55935946,
                -27.39362017,
                -27.22300147,
                -27.04653062,
                -26.86338215,
                -26.67275638,
                -26.47381287,
                -26.26569449,
                -26.04762427,
                -25.81902477,
                -25.57961136,
                -25.32943282,
                -25.06885791,
                -24.79852214,
            ],
            [
                -23.53750292,
                -23.3748086,
                -23.21793537,
                -23.06521934,
                -22.91449689,
                -22.76331684,
                -22.60928211,
                -22.45042208,
                -22.28542121,
                -22.11355532,
                -21.93435402,
                -21.74720475,
                -21.55115107,
                -21.34497916,
                -21.12749377,
                -20.89781118,
                -20.6555466,
                -20.40086149,
                -20.13439948,
                -19.85716145,
            ],
            [
                -18.53499939,
                -18.37689929,
                -18.22732841,
                -18.08427516,
                -17.94468687,
                -17.80472632,
                -17.66045115,
                -17.50880802,
                -17.3484421,
                -17.17963435,
                -17.0032098,
                -16.81921732,
                -16.62638972,
                -16.42258419,
                -16.20564846,
                -15.9741218,
                -15.72753538,
                -15.4663671,
                -15.19180844,
                -14.9054813,
            ],
            [
                -13.52283359,
                -13.36797542,
                -13.22589288,
                -13.09466537,
                -12.97028551,
                -12.84653536,
                -12.71591089,
                -12.57212088,
                -12.41335561,
                -12.24319318,
                -12.06681006,
                -11.88598424,
                -11.69798166,
                -11.49796348,
                -11.28169605,
                -11.04691388,
                -10.79343174,
                -10.52262594,
                -10.23677602,
                -9.93851158,
            ],
            [
                -8.49936685,
                -8.34357094,
                -8.20650964,
                -8.08786858,
                -7.98403171,
                -7.88628837,
                -7.78005273,
                -7.64833307,
                -7.48359988,
                -7.29992491,
                -7.11862682,
                -6.94410189,
                -6.76618701,
                -6.5727842,
                -6.35634881,
                -6.11465447,
                -5.84925708,
                -5.56369035,
                -5.26212482,
                -4.94857454,
            ],
            [
                -3.46638168,
                -3.30047216,
                -3.15914418,
                -3.04618465,
                -2.96252939,
                -2.90194067,
                -2.84436315,
                -2.75029014,
                -2.56983592,
                -2.33744275,
                -2.1512136,
                -1.99833104,
                -1.84066354,
                -1.6541107,
                -1.43071517,
                -1.17252753,
                -0.88592286,
                -0.57817222,
                -0.25582315,
                0.07585567,
            ],
            [
                1.56416954,
                1.75393848,
                1.9183586,
                2.04909316,
                2.13723278,
                2.17776584,
                2.18272501,
                2.20967639,
                2.37405656,
                2.65073289,
                2.80205222,
                2.90973407,
                3.05124404,
                3.2505182,
                3.50336116,
                3.7967575,
                4.11742779,
                4.45465822,
                4.80070204,
                5.15033407,
            ],
            [
                6.5633489,
                6.78740885,
                6.99419348,
                7.17551069,
                7.31963558,
                7.4113505,
                7.43666779,
                7.40177458,
                7.40517136,
                7.58520044,
                7.62013169,
                7.71596777,
                7.90558457,
                8.17213015,
                8.49008681,
                8.83763176,
                9.19937294,
                9.56556659,
                9.9305469,
                10.29132309,
            ],
            [
                11.48996073,
                11.74301446,
                11.99016964,
                12.22782156,
                12.44984059,
                12.6446727,
                12.78798484,
                12.82584849,
                12.61992833,
                12.26579742,
                12.32166685,
                12.54665462,
                12.86628045,
                13.23578462,
                13.62571822,
                14.01882924,
                14.40617707,
                14.78388296,
                15.15089889,
                15.5076165,
            ],
            [
                16.31383216,
                16.57376544,
                16.83189511,
                17.08626411,
                17.33309437,
                17.56429108,
                17.76005623,
                17.85853532,
                17.57101025,
                17.32637346,
                17.45075419,
                17.77199513,
                18.16933168,
                18.58284635,
                18.9891851,
                19.37985879,
                19.75324557,
                20.11079653,
                20.4549905,
                20.78837053,
            ],
            [
                21.03975749,
                21.28450315,
                21.5243142,
                21.75603974,
                21.97469496,
                22.17298057,
                22.34310053,
                22.49668569,
                22.73940191,
                22.70030633,
                22.95351405,
                23.35967832,
                23.75891016,
                24.14867803,
                24.51536915,
                24.85878249,
                25.18398203,
                25.49615514,
                25.79932964,
                26.09638269,
            ],
            [
                25.70484089,
                25.92709225,
                26.14280395,
                26.35119497,
                26.55363501,
                26.75827099,
                26.9915523,
                27.31779086,
                27.77993211,
                27.71070831,
                28.13624949,
                28.723482,
                29.25285078,
                29.66404032,
                30.00169474,
                30.30044315,
                30.57916576,
                30.84804427,
                31.1126134,
                31.37586841,
            ],
            [
                30.35406633,
                30.5585145,
                30.75843356,
                30.95627127,
                31.15811912,
                31.3763124,
                31.63114968,
                31.94156189,
                32.23691802,
                32.38759301,
                32.86915665,
                33.83467935,
                34.46125278,
                34.89905345,
                35.25111257,
                35.55095664,
                35.82150686,
                36.07720619,
                36.32643896,
                36.57385362,
            ],
            [
                35.0222379,
                35.21734711,
                35.41081942,
                35.60589495,
                35.80774808,
                36.02313791,
                36.25826988,
                36.51619168,
                36.81025966,
                37.21777129,
                37.86674108,
                38.66578072,
                39.25203723,
                39.78060643,
                40.20815617,
                40.5606039,
                40.86634527,
                41.14457482,
                41.40732554,
                41.66197722,
            ],
            [
                39.73046099,
                39.92514041,
                40.12152415,
                40.32316112,
                40.5350467,
                40.76393316,
                41.01937758,
                41.3172128,
                41.68596492,
                42.16604148,
                42.77622755,
                43.447503,
                44.03771478,
                44.55012468,
                45.00551259,
                45.40376857,
                45.75505135,
                46.07204699,
                46.36554362,
                46.64361367,
            ],
            [
                44.4876174,
                44.68959464,
                44.89710008,
                45.11420443,
                45.34646809,
                45.60143197,
                45.88932906,
                46.22363997,
                46.61975585,
                47.0884227,
                47.62307543,
                48.1913408,
                48.74937117,
                49.26945799,
                49.74327902,
                50.17123158,
                50.55810895,
                50.91098842,
                51.23731582,
                51.54375617,
            ],
            [
                49.29279265,
                49.50696882,
                49.73006999,
                49.96625305,
                50.22080319,
                50.50022572,
                50.81209441,
                51.1642666,
                51.56290694,
                52.00913021,
                52.49553006,
                53.00565389,
                53.51861282,
                54.01614414,
                54.48672101,
                54.9254339,
                55.33212663,
                55.70951516,
                56.06170563,
                56.39317058,
            ],
            [
                54.13906629,
                54.3671694,
                54.60643024,
                54.86053563,
                55.13377911,
                55.43088558,
                55.75658576,
                56.1148189,
                56.50752978,
                56.93329478,
                57.38640012,
                57.85715119,
                58.33367994,
                58.80451404,
                59.26065475,
                59.69644542,
                60.10938419,
                60.49940252,
                60.86803179,
                61.21767916,
            ],
            [
                59.01741908,
                59.25887491,
                59.51248349,
                59.78119592,
                60.06816694,
                60.37651862,
                60.70895927,
                61.0672529,
                61.45160192,
                61.86010542,
                62.28853397,
                62.73062937,
                63.17894547,
                63.62598375,
                64.06523791,
                64.49185106,
                64.90281064,
                65.2967858,
                65.67377362,
                66.03469546,
            ],
            [
                63.9193099,
                64.17236414,
                64.4376317,
                64.71732366,
                65.01362255,
                65.32847988,
                65.66334836,
                66.0188704,
                66.39457546,
                66.7886684,
                67.19800022,
                67.61828012,
                68.04451487,
                68.47157851,
                68.89476917,
                69.31022713,
                69.71515194,
                70.10782673,
                70.4875021,
                70.85420436,
            ],
        ]
    )
    np.testing.assert_allclose(targetU, dists["U"], atol=0.01)
    targetT = np.array(
        [
            [
                -2.27427469e01,
                -1.97498544e01,
                -1.67512900e01,
                -1.37464632e01,
                -1.07350712e01,
                -7.71715083e00,
                -4.69305811e00,
                -1.66336318e00,
                1.37131605e00,
                4.41047613e00,
                7.45381136e00,
                1.05011799e01,
                1.35524779e01,
                1.66074913e01,
                1.96657949e01,
                2.27267294e01,
                2.57894503e01,
                2.88530154e01,
                3.19164798e01,
                3.49789747e01,
            ],
            [
                -2.30778766e01,
                -2.00896906e01,
                -1.70950973e01,
                -1.40931667e01,
                -1.10834219e01,
                -8.06600712e00,
                -5.04171582e00,
                -2.01179123e00,
                1.02248614e00,
                4.06025218e00,
                7.10129626e00,
                1.01459367e01,
                1.31946312e01,
                1.62475702e01,
                1.93044511e01,
                2.23644788e01,
                2.54265185e01,
                2.84892997e01,
                3.15515954e01,
                3.46123426e01,
            ],
            [
                -2.33971472e01,
                -2.04144525e01,
                -1.74245193e01,
                -1.44256870e01,
                -1.14169177e01,
                -8.39830615e00,
                -5.37141115e00,
                -2.33902937e00,
                6.95823925e-01,
                3.73133431e00,
                6.76769593e00,
                9.80663091e00,
                1.28500821e01,
                1.58991008e01,
                1.89534737e01,
                2.20119662e01,
                2.50728111e01,
                2.81341606e01,
                3.11943854e01,
                3.42522163e01,
            ],
            [
                -2.36965870e01,
                -2.07206976e01,
                -1.77370901e01,
                -1.47426715e01,
                -1.17347885e01,
                -8.71247709e00,
                -5.67801094e00,
                -2.63761285e00,
                4.00625914e-01,
                3.43182302e00,
                6.45782532e00,
                9.48491128e00,
                1.25187545e01,
                1.55616657e01,
                1.86127822e01,
                2.16694756e01,
                2.47286680e01,
                2.77876297e01,
                3.08443066e01,
                3.38973527e01,
            ],
            [
                -2.39698399e01,
                -2.10022612e01,
                -1.80281475e01,
                -1.50423801e01,
                -1.20388157e01,
                -9.01204040e00,
                -5.96160398e00,
                -2.89867328e00,
                1.52194374e-01,
                3.17268218e00,
                6.17334725e00,
                9.17699572e00,
                1.21964990e01,
                1.52330975e01,
                1.82821226e01,
                2.13375815e01,
                2.43943933e01,
                2.74490375e01,
                3.04994435e01,
                3.35446330e01,
            ],
            [
                -2.42070742e01,
                -2.12471979e01,
                -1.82855675e01,
                -1.53163304e01,
                -1.23296744e01,
                -9.31127857e00,
                -6.24535210e00,
                -3.12882361e00,
                -2.24460581e-02,
                2.95354485e00,
                5.89215412e00,
                8.86387424e00,
                1.18748249e01,
                1.49128245e01,
                1.79640055e01,
                2.10182501e01,
                2.40696313e01,
                2.71153177e01,
                3.01543919e01,
                3.31869788e01,
            ],
            [
                -2.43971375e01,
                -2.14368866e01,
                -1.84826148e01,
                -1.55321207e01,
                -1.25786621e01,
                -9.60654678e00,
                -6.58612151e00,
                -3.48118311e00,
                -3.16555025e-01,
                2.61618307e00,
                5.53740540e00,
                8.52666510e00,
                1.15623361e01,
                1.46149780e01,
                1.76674294e01,
                2.07125025e01,
                2.37483764e01,
                2.67756033e01,
                2.97955606e01,
                3.28097430e01,
            ],
            [
                -2.45384925e01,
                -2.15583842e01,
                -1.85874288e01,
                -1.56290738e01,
                -1.26867853e01,
                -9.76140655e00,
                -6.84407754e00,
                -3.90089971e00,
                -8.41806596e-01,
                2.14754495e00,
                5.18583472e00,
                8.26271822e00,
                1.13266091e01,
                1.43684333e01,
                1.73916223e01,
                2.04017469e01,
                2.34034936e01,
                2.64002111e01,
                2.93941282e01,
                3.23866586e01,
            ],
            [
                -2.46576775e01,
                -2.16355610e01,
                -1.86129545e01,
                -1.55919156e01,
                -1.25763765e01,
                -9.57306672e00,
                -6.59044329e00,
                -3.62352541e00,
                -5.92041388e-01,
                2.33255341e00,
                5.29498494e00,
                8.24834463e00,
                1.11833819e01,
                1.41167617e01,
                1.70571082e01,
                2.00065102e01,
                2.29645946e01,
                2.59302937e01,
                2.89023967e01,
                3.18797332e01,
            ],
            [
                -2.48161623e01,
                -2.17489533e01,
                -1.86651328e01,
                -1.55589864e01,
                -1.24224388e01,
                -9.24466730e00,
                -6.01521475e00,
                -2.75148770e00,
                3.89519039e-01,
                2.99589525e00,
                5.45696689e00,
                8.01247078e00,
                1.07291540e01,
                1.35565782e01,
                1.64461360e01,
                1.93723515e01,
                2.23222250e01,
                2.52881249e01,
                2.82650171e01,
                3.12494172e01,
            ],
            [
                -2.50857405e01,
                -2.20002811e01,
                -1.88926336e01,
                -1.57550887e01,
                -1.25770789e01,
                -9.34497451e00,
                -6.04430316e00,
                -2.67290100e00,
                5.40854953e-01,
                2.30509492e00,
                3.58183843e00,
                6.23701436e00,
                9.28727128e00,
                1.23205706e01,
                1.53428945e01,
                1.83666035e01,
                2.13934954e01,
                2.44218171e01,
                2.74496472e01,
                3.04757209e01,
            ],
            [
                -2.55082697e01,
                -2.24454912e01,
                -1.93710045e01,
                -1.62824768e01,
                -1.31767102e01,
                -1.00469827e01,
                -6.86985653e00,
                -3.54681638e00,
                1.07062999e-01,
                3.34891657e-01,
                -1.70694750e-01,
                3.57896940e00,
                7.17013928e00,
                1.05232789e01,
                1.37976070e01,
                1.70230221e01,
                2.02076136e01,
                2.33576919e01,
                2.64794914e01,
                2.95785985e01,
            ],
            [
                -2.60778515e01,
                -2.30695744e01,
                -2.00684150e01,
                -1.70790651e01,
                -1.41074315e01,
                -1.11587507e01,
                -8.23273307e00,
                -5.33306966e00,
                -2.80144302e00,
                -1.84760416e00,
                -1.05368779e00,
                1.26163211e00,
                4.90086292e00,
                8.53883059e00,
                1.20996577e01,
                1.55589098e01,
                1.89237978e01,
                2.22114952e01,
                2.54390313e01,
                2.86203790e01,
            ],
            [
                -2.67537229e01,
                -2.38123298e01,
                -2.08964272e01,
                -1.80168638e01,
                -1.51896230e01,
                -1.24401995e01,
                -9.81536176e00,
                -7.41008520e00,
                -5.38073414e00,
                -3.78262975e00,
                -2.29669890e00,
                -3.53057240e-01,
                3.13642477e00,
                6.97021789e00,
                1.07026969e01,
                1.42945488e01,
                1.77655640e01,
                2.11406146e01,
                2.44409375e01,
                2.76832489e01,
            ],
            [
                -2.74832153e01,
                -2.46028623e01,
                -2.17593854e01,
                -1.89653378e01,
                -1.62381218e01,
                -1.36022404e01,
                -1.10914555e01,
                -8.74572618e00,
                -6.58963863e00,
                -4.58336507e00,
                -2.57607747e00,
                -2.67233150e-01,
                2.82788692e00,
                6.36737407e00,
                9.93334021e00,
                1.34440609e01,
                1.68846862e01,
                2.02577163e01,
                2.35710668e01,
                2.68337230e01,
            ],
            [
                -2.82199728e01,
                -2.53838486e01,
                -2.25869234e01,
                -1.98388981e01,
                -1.71512612e01,
                -1.45365893e01,
                -1.20059297e01,
                -9.56220853e00,
                -7.18799023e00,
                -4.83006994e00,
                -2.39120744e00,
                2.51308627e-01,
                3.17331949e00,
                6.33022626e00,
                9.61428455e00,
                1.29426788e01,
                1.62705993e01,
                1.95770961e01,
                2.28539081e01,
                2.60992146e01,
            ],
            [
                -2.89332200e01,
                -2.61222251e01,
                -2.33461951e01,
                -2.06105222e01,
                -1.79200485e01,
                -1.52776479e01,
                -1.26817390e01,
                -1.01225741e01,
                -7.57801870e00,
                -5.01122873e00,
                -2.37434916e00,
                3.78303328e-01,
                3.27093827e00,
                6.29527723e00,
                9.41912399e00,
                1.26046423e01,
                1.58204753e01,
                1.90448689e01,
                2.22643265e01,
                2.54712657e01,
            ],
            [
                -2.96082809e01,
                -2.68067500e01,
                -2.40331802e01,
                -2.12894659e01,
                -1.85760763e01,
                -1.58910124e01,
                -1.32284735e01,
                -1.05774862e01,
                -7.92111801e00,
                -5.23724922e00,
                -2.50179068e00,
                3.05790568e-01,
                3.19666197e00,
                6.16975035e00,
                9.21353475e00,
                1.23109519e01,
                1.54443017e01,
                1.85982825e01,
                2.17611016e01,
                2.49243957e01,
            ],
            [
                -3.02420504e01,
                -2.74395034e01,
                -2.46578094e01,
                -2.18967353e01,
                -1.91546206e01,
                -1.64278219e01,
                -1.37101816e01,
                -1.09927140e01,
                -8.26378719e00,
                -5.51007519e00,
                -2.71836365e00,
                1.22111758e-01,
                3.01754598e00,
                5.96851903e00,
                8.97043180e00,
                1.20150997e01,
                1.50927299e01,
                1.81935916e01,
                2.13090724e01,
                2.44321477e01,
            ],
            [
                -3.08377073e01,
                -2.80281994e01,
                -2.52335334e01,
                -2.24524366e01,
                -1.96825082e01,
                -1.69199811e01,
                -1.41595768e01,
                -1.13945492e01,
                -8.61701306e00,
                -5.81861191e00,
                -2.99148017e00,
                -1.29317230e-01,
                2.77170749e00,
                5.71249079e00,
                8.69110042e00,
                1.17033684e01,
                1.47437429e01,
                1.78061436e01,
                2.08846464e01,
                2.39739290e01,
            ],
        ]
    )
    np.testing.assert_allclose(targetT, dists["T"], atol=0.01)