def test_ss3_m4p5(): magnitude = 4.5 dip = np.array([90]) rake = 180.0 width = np.array([15]) fltx = np.array([0, 0]) flty = np.array([0, 80]) zp = np.array([0]) epix = np.array([0]) epiy = np.array([0.2 * flty[1]]) # Convert to lat/lon proj = geo.utils.get_orthographic_projection(-122, -120, 39, 37) tlon, tlat = proj(fltx, flty, reverse=True) epilon, epilat = proj(epix, epiy, reverse=True) flt = rupture.QuadRupture.fromTrace( np.array([tlon[0]]), np.array([tlat[0]]), np.array([tlon[1]]), np.array([tlat[1]]), zp, width, dip, reference='ss3') event = {'lat': epilat[0], 'lon': epilon[0], 'depth': 10, 'mag': magnitude, 'id': 'ss3', 'locstring': 'test', 'type': 'SS', 'timezone': 'UTC'} event['time'] = ShakeDateTime.utcfromtimestamp(int(time.time())) event['created'] = ShakeDateTime.utcfromtimestamp(int(time.time())) x = np.linspace(0, 20, 6) y = np.linspace(0, 90, 11) site_x, site_y = np.meshgrid(x, y) slon, slat = proj(site_x, site_y, reverse=True) deps = np.zeros_like(slon) source = Source(event, flt) source.setEventParam('rake', rake) test1 = Bayless2013(source, slat, slon, deps, T=1.0) # Test fd fd = test1.getFd() fd_test = np.array( [[ 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., 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., 0., 0.], [ 0., 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0., 0.]]) np.testing.assert_allclose( fd, fd_test, rtol=1e-4)
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)
def test_rv4(): magnitude = 7.0 rake = 90.0 width = np.array([28]) fltx = np.array([0, 0]) flty = np.array([0, 32]) zp = np.array([0]) dip = np.array([30]) # Convert to lat/lon proj = geo.utils.get_orthographic_projection(-122, -120, 39, 37) tlon, tlat = proj(fltx, flty, reverse=True) flt = fault.Fault.fromTrace(np.array([tlon[0]]), np.array([tlat[0]]), np.array([tlon[1]]), np.array([tlat[1]]), zp, width, dip, reference='') L = flt.getFaultLength() # Try to figure out epicenter tmp = flt.getQuadrilaterals()[0] pp0 = Vector.fromPoint(point.Point(tmp[0].longitude, tmp[0].latitude, tmp[0].depth)) pp1 = Vector.fromPoint(point.Point(tmp[1].longitude, tmp[1].latitude, tmp[1].depth)) pp2 = Vector.fromPoint(point.Point(tmp[2].longitude, tmp[2].latitude, tmp[2].depth)) pp3 = Vector.fromPoint(point.Point(tmp[3].longitude, tmp[3].latitude, tmp[3].depth)) dxp = 6/L dyp = (width-8)/width mp0 = pp0 + (pp1 - pp0)*dxp mp1 = pp3 + (pp2 - pp3)*dxp rp = mp0 + (mp1 - mp0)*dyp epilat,epilon,epidepth = ecef2latlon(rp.x, rp.y, rp.z) event = {'lat': epilat, 'lon': epilon, 'depth': epidepth, 'mag': magnitude, 'id': 'test', 'locstring': 'rv4', 'type': 'DS', 'timezone': 'UTC'} event['time'] = ShakeDateTime.utcfromtimestamp(int(time.time())) event['created'] = ShakeDateTime.utcfromtimestamp(int(time.time())) x = np.linspace(-50, 50, 11) y = np.linspace(-50, 50, 11) site_x, site_y = np.meshgrid(x, y) slon, slat = proj(site_x, site_y, reverse=True) deps = np.zeros_like(slon) source = Source(event, flt) source.setEventParam('rake', rake) test1 = Bayless2013(source, slat, slon, deps, T=2.0) # Test fd fd = test1.getFd() fd_test = np.array( [[ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 1.72147747e-03, 1.34981119e-03, 8.95673480e-29, 1.24449087e-03, 1.16145147e-03, 2.25470229e-03, 7.05301515e-04, 0.00000000e+00], [ 0.00000000e+00, 0.00000000e+00, 7.62625126e-03, 1.25136528e-02, 5.61909403e-03, 3.18694606e-28, 4.52275052e-03, 4.67980272e-03, 1.02822365e-02, 5.13171639e-03, -6.13935060e-03], [ 0.00000000e+00, 4.00499692e-03, 2.37611880e-02, 2.37143264e-02, 9.55241972e-03, 5.65693221e-28, 7.70357238e-03, 7.36477919e-03, 1.48241947e-02, 8.40402367e-03, -1.58594139e-02], [ 8.08392720e-19, 9.38156493e-03, 3.38613859e-02, 3.85355818e-02, 1.91047521e-02, 1.27066310e-27, 1.54323543e-02, 1.21915074e-02, 2.04437211e-02, 1.04933053e-02, -1.85937074e-02], [ 2.12026318e-18, 1.37316424e-02, 4.40195705e-02, 6.16565712e-02, 4.77616016e-02, 5.07336347e-27, 3.86325509e-02, 1.97966900e-02, 2.64883302e-02, 1.23336661e-02, -2.07390404e-02], [ 2.64338576e-18, 1.45898071e-02, 4.89104103e-02, 7.70703129e-02, 9.55225254e-02, 1.01875104e-01, 7.73459333e-02, 2.50275520e-02, 2.93537605e-02, 1.30949772e-02, -2.15685118e-02], [ 2.64330042e-18, 1.45898071e-02, 4.89104103e-02, 7.70703129e-02, 9.55225254e-02, 1.01910945e-01, 7.74050830e-02, 2.52307951e-02, 2.92970785e-02, 1.30880672e-02, -2.15685118e-02], [ 2.64318867e-18, 1.45898071e-02, 4.89104103e-02, 7.70703129e-02, 9.55225254e-02, 1.01933432e-01, 7.74421253e-02, 2.53572928e-02, 2.92615177e-02, 1.30837449e-02, -2.15685118e-02], [ 2.64305117e-18, 1.45898071e-02, 4.89104103e-02, 7.70703129e-02, 9.55225254e-02, 1.01942593e-01, 7.74571361e-02, 2.54081650e-02, 2.92472178e-02, 1.30820173e-02, -2.15685118e-02], [ 2.30140686e-18, 1.40209885e-02, 4.56202616e-02, 6.63103459e-02, 5.79255225e-02, 7.72925496e-27, 4.69663059e-02, 2.18399567e-02, 2.72863359e-02, 1.25728195e-02, -2.10226512e-02], [ 1.10671369e-18, 1.04775558e-02, 3.59035524e-02, 4.24605614e-02, 2.24210618e-02, 1.53459722e-27, 1.81723013e-02, 1.39298662e-02, 2.14953705e-02, 1.08710398e-02, -1.90800441e-02]] ) np.testing.assert_allclose(fd, fd_test, rtol=1e-5)
def test_so6(): event_name = 'so6' magnitude = 7.2 dip = np.array([70]) rake = 135 width = np.array([15]) L = 80 fltx = np.array([0, 0]) flty = np.array([0, L]) zp = np.array([0]) # Convert to lat/lon proj = geo.utils.get_orthographic_projection(-122, -120, 39, 37) tlon, tlat = proj(fltx, flty, reverse=True) flt = fault.Fault.fromTrace(np.array([tlon[0]]), np.array([tlat[0]]), np.array([tlon[1]]), np.array([tlat[1]]), zp, width, dip, reference='rv4') x = np.linspace(-80, 80, 21) y = np.linspace(-50, 130, 21) site_x, site_y = np.meshgrid(x, y) slon, slat = proj(site_x, site_y, reverse=True) sdepth = np.zeros_like(slon) tmp = flt.getQuadrilaterals()[0] pp0 = Vector.fromPoint( point.Point(tmp[0].longitude, tmp[0].latitude, tmp[0].depth)) pp1 = Vector.fromPoint( point.Point(tmp[1].longitude, tmp[1].latitude, tmp[1].depth)) pp2 = Vector.fromPoint( point.Point(tmp[2].longitude, tmp[2].latitude, tmp[2].depth)) pp3 = Vector.fromPoint( point.Point(tmp[3].longitude, tmp[3].latitude, tmp[3].depth)) dxp = 10 / L dyp = (width - 5) / width mp0 = pp0 + (pp1 - pp0) * dxp mp1 = pp3 + (pp2 - pp3) * dxp rp = mp0 + (mp1 - mp0) * dyp epilat, epilon, epidepth = ecef2latlon(rp.x, rp.y, rp.z) epix, epiy = proj(epilon, epilat, reverse=False) event = { 'lat': epilat, 'lon': epilon, 'depth': epidepth, 'mag': magnitude, 'id': 'so6', 'locstring': 'so6', 'type': 'RV', 'timezone': 'UTC' } event['time'] = ShakeDateTime.utcfromtimestamp(int(time.time())) event['created'] = ShakeDateTime.utcfromtimestamp(int(time.time())) fltlat = [a.latitude for a in flt.getQuadrilaterals()[0]] fltlon = [a.longitude for a in flt.getQuadrilaterals()[0]] fltlat = np.append(fltlat, fltlat[0]) fltlon = np.append(fltlon, fltlon[0]) fltx, flty = proj(fltlon, fltlat, reverse=False) source = Source(event, flt) source.setEventParam('rake', rake) test1 = Bayless2013(source, slat, slon, sdepth, T=5) fd = test1.getFd() fd_test = np.array([ [ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, -8.92879772e-03, -1.74526918e-02, -2.22981746e-02, -2.34350450e-02, -2.13620062e-02, -1.72712346e-02, -1.29509613e-02, -1.02545064e-02, -1.03010185e-02, -1.28847597e-02, -1.66274727e-02, -1.96984070e-02, -2.05377743e-02, -1.81831337e-02, -1.21881814e-02, -2.64862879e-03, 0.00000000e+00, 0.00000000e+00 ], [ 0.00000000e+00, 0.00000000e+00, -8.73221519e-03, -2.21421374e-02, -3.18438939e-02, -3.71488270e-02, -3.76239913e-02, -3.35015951e-02, -2.61748968e-02, -1.83864728e-02, -1.34793002e-02, -1.36687799e-02, -1.85727143e-02, -2.55527671e-02, -3.14227568e-02, -3.38933995e-02, -3.19289607e-02, -2.53396980e-02, -1.45943649e-02, -3.71405488e-04, 0.00000000e+00 ], [ 0.00000000e+00, -2.54621422e-03, -2.11428566e-02, -3.68609103e-02, -4.87464747e-02, -5.56539037e-02, -5.64419387e-02, -5.05331157e-02, -3.52919381e-02, -2.18782050e-02, -1.40858125e-02, -1.47354546e-02, -2.35727189e-02, -3.74838465e-02, -4.75915414e-02, -5.13000399e-02, -4.87882409e-02, -4.05716321e-02, -2.77368254e-02, -1.13542729e-02, 0.00000000e+00 ], [ 0.00000000e+00, -1.21642958e-02, -3.33747360e-02, -5.21661817e-02, -6.74724509e-02, -7.77628842e-02, -8.00243748e-02, -6.42496853e-02, -4.38124530e-02, -1.97027426e-02, -1.45897731e-02, -1.07427056e-02, -3.08235222e-02, -4.82656988e-02, -6.67692677e-02, -7.35152908e-02, -6.85574283e-02, -5.71811573e-02, -4.12138780e-02, -2.20396726e-02, -6.24121310e-04 ], [ 0.00000000e+00, -2.00643401e-02, -4.39827328e-02, -6.62722434e-02, -8.60268414e-02, -1.01730306e-01, -9.86277741e-02, -9.82914922e-02, -5.22335876e-02, -1.54622435e-02, -1.57487554e-02, -3.06190808e-03, -4.81481586e-02, -8.92480491e-02, -8.63776477e-02, -9.98130440e-02, -8.95491230e-02, -7.33553695e-02, -5.34401725e-02, -3.11601812e-02, -7.33715103e-03 ], [ 0.00000000e+00, -2.50053614e-02, -5.11695772e-02, -7.65997026e-02, -1.00809054e-01, -1.22877573e-01, -1.18738178e-01, -1.55236782e-01, -7.45388001e-02, 1.92779182e-03, -1.94380016e-02, 1.94922939e-02, -7.66669920e-02, -1.53909722e-01, -1.10846875e-01, -1.19746768e-01, -1.07680300e-01, -8.59905101e-02, -6.22042294e-02, -3.71802472e-02, -1.13867485e-02 ], [ 0.00000000e+00, -2.63645827e-02, -5.37984901e-02, -8.11337022e-02, -1.08298371e-01, -1.35146441e-01, -1.34825430e-01, -1.85836050e-01, -1.10730875e-01, -3.18861095e-02, 4.14395701e-02, -1.52711946e-02, -1.31840763e-01, -1.96794707e-01, -1.33453212e-01, -1.34989129e-01, -1.17922385e-01, -9.21637323e-02, -6.58369237e-02, -3.91646838e-02, -1.22685698e-02 ], [ 0.00000000e+00, -2.64622244e-02, -5.40483999e-02, -8.16190336e-02, -1.09162854e-01, -1.36656677e-01, -1.37081504e-01, -1.89522811e-01, -1.17723634e-01, -4.88765748e-02, -5.04529015e-03, -5.76414497e-02, -1.45712183e-01, -2.03062804e-01, -1.36859828e-01, -1.37107390e-01, -1.19124650e-01, -9.28263279e-02, -6.61800709e-02, -3.93088682e-02, -1.22842049e-02 ], [ 0.00000000e+00, -2.58466495e-02, -5.24858827e-02, -7.86086164e-02, -1.03856343e-01, -1.27529509e-01, -1.23794779e-01, -1.68810613e-01, -8.22602627e-02, 1.74236964e-02, 9.38708725e-02, 4.23208284e-02, -8.46343723e-02, -1.70476759e-01, -1.17547884e-01, -1.24569752e-01, -1.11518670e-01, -8.84736806e-02, -6.38037151e-02, -3.81874381e-02, -1.19867610e-02 ], [ 0.00000000e+00, -2.42186547e-02, -4.84175525e-02, -7.09428614e-02, -9.07754575e-02, -1.06117824e-01, -9.50228292e-02, -1.29781980e-01, -3.08573454e-02, 7.39058739e-02, 1.30478117e-01, 8.28181149e-02, -2.70389535e-02, -1.20837502e-01, -8.02081725e-02, -9.70274506e-02, -9.35853383e-02, -7.77422806e-02, -5.77817530e-02, -3.53067886e-02, -1.12414659e-02 ], [ 0.00000000e+00, -2.16818717e-02, -4.22363856e-02, -5.96909893e-02, -7.24805224e-02, -7.81867829e-02, -6.11838569e-02, -9.05679744e-02, 9.95934969e-03, 1.07503875e-01, 1.52073917e-01, 1.05894634e-01, 8.68652263e-03, -7.98571818e-02, -4.16548658e-02, -6.40511838e-02, -6.99337160e-02, -6.26305633e-02, -4.89098800e-02, -3.09284566e-02, -1.00919381e-02 ], [ 0.00000000e+00, -1.84940182e-02, -3.47054606e-02, -4.65278129e-02, -5.22037664e-02, -4.93977115e-02, -2.95395230e-02, -5.82421092e-02, 3.91025654e-02, 1.29337956e-01, 1.67436703e-01, 1.21969296e-01, 3.20823547e-02, -5.00287386e-02, -9.22993907e-03, -3.27186625e-02, -4.52706958e-02, -4.57409325e-02, -3.84701291e-02, -2.55751405e-02, -8.64950254e-03 ], [ 0.00000000e+00, -1.49431380e-02, -2.65887341e-02, -3.29162158e-02, -3.22994323e-02, -2.29081781e-02, -2.60259636e-03, -3.29856530e-02, 6.02631314e-02, 1.45003704e-01, 1.79361264e-01, 1.34292814e-01, 4.88007115e-02, -2.82328554e-02, 1.64212421e-02, -5.72391847e-03, -2.23438861e-02, -2.90246794e-02, -2.76054402e-02, -1.97779758e-02, -7.03945406e-03 ], [ 0.00000000e+00, -1.12771143e-02, -1.84737590e-02, -1.98228664e-02, -1.40092305e-02, 1.84580818e-04, 1.95817303e-02, -1.32608487e-02, 7.62783168e-02, 1.57076433e-01, 1.89083905e-01, 1.44259188e-01, 6.15722813e-02, -1.17505212e-02, 3.65938109e-02, 1.66937711e-02, -2.18970818e-03, -1.35507683e-02, -1.70890527e-02, -1.39519424e-02, -5.37036892e-03 ], [ 0.00000000e+00, -7.67615215e-03, -1.07348257e-02, -7.75276739e-03, 2.22351695e-03, 1.98662250e-02, 3.77611177e-02, 2.42018661e-03, 8.89036172e-02, 1.66855206e-01, 1.97260700e-01, 1.52590263e-01, 7.17981256e-02, 1.18005972e-03, 5.26852303e-02, 3.51638855e-02, 1.51012176e-02, 2.69654076e-04, -7.33815554e-03, -8.36639665e-03, -3.72176313e-03 ], [ 0.00000000e+00, -4.50552324e-03, -4.32262850e-03, 1.73559158e-03, 1.42670366e-02, 3.35040699e-02, 4.97279358e-02, 1.85410528e-02, 9.39950666e-02, 1.46646579e-01, 9.13474746e-02, 1.37004651e-01, 7.74648339e-02, 1.59777072e-02, 6.25334939e-02, 4.74577418e-02, 2.72155518e-02, 1.06174952e-02, 3.94103899e-04, -3.68465400e-03, -2.19830733e-03 ], [ 0.00000000e+00, -1.74629916e-03, 5.44471813e-04, 8.22933499e-03, 2.15699287e-02, 4.04232250e-02, 5.69678048e-02, 5.52408259e-02, 9.04381272e-02, 1.08204635e-01, 9.14439984e-02, 1.06884511e-01, 8.17241884e-02, 5.55282924e-02, 6.78528399e-02, 5.47188925e-02, 3.35251483e-02, 1.69615982e-02, 5.72048628e-03, -8.81437278e-05, -7.36518436e-04 ], [ 0.00000000e+00, 4.07838765e-05, 3.63933766e-03, 1.20080876e-02, 2.51274691e-02, 4.25687176e-02, 6.25685606e-02, 7.33480475e-02, 8.37515545e-02, 9.52500287e-02, 9.15135660e-02, 9.66442834e-02, 8.66659913e-02, 8.10325633e-02, 7.18836713e-02, 5.45548434e-02, 3.55884875e-02, 2.00142359e-02, 8.71200201e-03, 2.04407846e-03, -6.53680674e-06 ], [ 0.00000000e+00, 2.40054729e-04, 4.44975227e-03, 1.27572519e-02, 2.49362989e-02, 4.03831326e-02, 5.80039988e-02, 7.61280192e-02, 8.37404162e-02, 8.89634569e-02, 9.15651607e-02, 9.13586235e-02, 8.83589144e-02, 8.27804032e-02, 6.75666471e-02, 5.00483249e-02, 3.36733366e-02, 1.96758691e-02, 9.00603204e-03, 2.18370401e-03, 0.00000000e+00 ], [ 0.00000000e+00, 0.00000000e+00, 2.78776980e-03, 1.05086036e-02, 2.13238822e-02, 3.45577738e-02, 4.91570145e-02, 6.36787133e-02, 7.63710088e-02, 8.54072310e-02, 8.92960200e-02, 8.75702197e-02, 8.07095447e-02, 6.97999389e-02, 5.63787286e-02, 4.20734776e-02, 2.83073312e-02, 1.61614525e-02, 6.56194125e-03, 1.00721924e-04, 0.00000000e+00 ], [ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 5.49667845e-03, 1.47563319e-02, 2.57955743e-02, 3.76689418e-02, 4.91861917e-02, 5.90108907e-02, 6.58478416e-02, 6.87018515e-02, 6.73174642e-02, 6.20270643e-02, 5.35456385e-02, 4.29400416e-02, 3.14129728e-02, 2.00795162e-02, 9.84001885e-03, 1.53992995e-03, 0.00000000e+00, 0.00000000e+00 ] ]) np.testing.assert_allclose(fd, fd_test, rtol=1e-4)
def test_rv4(): magnitude = 7.0 rake = 90.0 width = np.array([28]) fltx = np.array([0, 0]) flty = np.array([0, 32]) zp = np.array([0]) dip = np.array([30]) # Convert to lat/lon proj = geo.utils.get_orthographic_projection(-122, -120, 39, 37) tlon, tlat = proj(fltx, flty, reverse=True) flt = fault.Fault.fromTrace(np.array([tlon[0]]), np.array([tlat[0]]), np.array([tlon[1]]), np.array([tlat[1]]), zp, width, dip, reference='') L = flt.getFaultLength() # Try to figure out epicenter tmp = flt.getQuadrilaterals()[0] pp0 = Vector.fromPoint( point.Point(tmp[0].longitude, tmp[0].latitude, tmp[0].depth)) pp1 = Vector.fromPoint( point.Point(tmp[1].longitude, tmp[1].latitude, tmp[1].depth)) pp2 = Vector.fromPoint( point.Point(tmp[2].longitude, tmp[2].latitude, tmp[2].depth)) pp3 = Vector.fromPoint( point.Point(tmp[3].longitude, tmp[3].latitude, tmp[3].depth)) dxp = 6 / L dyp = (width - 8) / width mp0 = pp0 + (pp1 - pp0) * dxp mp1 = pp3 + (pp2 - pp3) * dxp rp = mp0 + (mp1 - mp0) * dyp epilat, epilon, epidepth = ecef2latlon(rp.x, rp.y, rp.z) event = { 'lat': epilat, 'lon': epilon, 'depth': epidepth, 'mag': magnitude, 'id': 'test', 'locstring': 'rv4', 'type': 'DS', 'timezone': 'UTC' } event['time'] = ShakeDateTime.utcfromtimestamp(int(time.time())) event['created'] = ShakeDateTime.utcfromtimestamp(int(time.time())) x = np.linspace(-50, 50, 11) y = np.linspace(-50, 50, 11) site_x, site_y = np.meshgrid(x, y) slon, slat = proj(site_x, site_y, reverse=True) deps = np.zeros_like(slon) source = Source(event, flt) source.setEventParam('rake', rake) test1 = Bayless2013(source, slat, slon, deps, T=2.0) # Test fd fd = test1.getFd() fd_test = np.array( [[ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 1.72143257e-03, 1.34977260e-03, 4.33616224e-15, 1.24446253e-03, 1.16142357e-03, 2.25464716e-03, 7.05281751e-04, 0.00000000e+00 ], [ 0.00000000e+00, 0.00000000e+00, 7.62610242e-03, 1.25133844e-02, 5.61896104e-03, 7.63126014e-15, 4.52266194e-03, 4.67970900e-03, 1.02820316e-02, 5.13160096e-03, -6.13926251e-03 ], [ 0.00000000e+00, 4.00495234e-03, 2.37608386e-02, 2.37139333e-02, 9.55224050e-03, 5.66364910e-15, 7.70344813e-03, 7.36466362e-03, 1.48239704e-02, 8.40388145e-03, -1.58592485e-02 ], [ 8.08385547e-19, 9.38150101e-03, 3.38610620e-02, 3.85351492e-02, 1.91044918e-02, 3.98697802e-15, 1.54321666e-02, 1.21913760e-02, 2.04435166e-02, 1.04931859e-02, -1.85935894e-02 ], [ 2.12025421e-18, 1.37316085e-02, 4.40193799e-02, 6.16562477e-02, 4.77612496e-02, 2.60257085e-15, 3.86322888e-02, 1.97965887e-02, 2.64882038e-02, 1.23335908e-02, -2.07389932e-02 ], [ 2.64338576e-18, 1.45898292e-02, 4.89104213e-02, 7.70703166e-02, 9.55225258e-02, 1.01875104e-01, 7.73459329e-02, 2.50275508e-02, 2.93537540e-02, 1.30949577e-02, -2.15685454e-02 ], [ 2.64330042e-18, 1.45898262e-02, 4.89104186e-02, 7.70703146e-02, 9.55225248e-02, 1.01910945e-01, 7.74050835e-02, 2.52307946e-02, 2.92970736e-02, 1.30880504e-02, -2.15685424e-02 ], [ 2.64318867e-18, 1.45898259e-02, 4.89104184e-02, 7.70703144e-02, 9.55225247e-02, 1.01933432e-01, 7.74421258e-02, 2.53572923e-02, 2.92615130e-02, 1.30837284e-02, -2.15685422e-02 ], [ 2.64305117e-18, 1.45898284e-02, 4.89104206e-02, 7.70703161e-02, 9.55225256e-02, 1.01942593e-01, 7.74571359e-02, 2.54081640e-02, 2.92472117e-02, 1.30819985e-02, -2.15685446e-02 ], [ 2.30141673e-18, 1.40210825e-02, 4.56205547e-02, 6.63109661e-02, 5.79266964e-02, 2.33044622e-15, 4.69672564e-02, 2.18401553e-02, 2.72864925e-02, 1.25728575e-02, -2.10227772e-02 ], [ 1.10672535e-18, 1.04777076e-02, 3.59041065e-02, 4.24614318e-02, 2.24217216e-02, 3.66914762e-15, 1.81728517e-02, 1.39301504e-02, 2.14956836e-02, 1.08711460e-02, -1.90802849e-02 ]]) np.testing.assert_allclose(fd, fd_test, rtol=2e-4)
def test_ss3(): magnitude = 7.2 dip = np.array([90]) rake = 180.0 width = np.array([15]) fltx = np.array([0, 0]) flty = np.array([0, 80]) zp = np.array([0]) epix = np.array([0]) epiy = np.array([0.2 * flty[1]]) # Convert to lat/lon proj = geo.utils.get_orthographic_projection(-122, -120, 39, 37) tlon, tlat = proj(fltx, flty, reverse=True) epilon, epilat = proj(epix, epiy, reverse=True) flt = fault.Fault.fromTrace(np.array([tlon[0]]), np.array([tlat[0]]), np.array([tlon[1]]), np.array([tlat[1]]), zp, width, dip, reference='ss3') event = { 'lat': epilat[0], 'lon': epilon[0], 'depth': 10, 'mag': magnitude, 'id': 'ss3', 'locstring': 'test', 'type': 'SS', 'timezone': 'UTC' } event['time'] = ShakeDateTime.utcfromtimestamp(int(time.time())) event['created'] = ShakeDateTime.utcfromtimestamp(int(time.time())) x = np.linspace(-60, 60, 21) y = np.linspace(-60, 138, 34) site_x, site_y = np.meshgrid(x, y) slon, slat = proj(site_x, site_y, reverse=True) deps = np.zeros_like(slon) source = Source(event, flt) source.setEventParam('rake', rake) test1 = Bayless2013(source, slat, slon, deps, T=1.0) # Test fd fd = test1.getFd() fd_test = np.array([ [ 0.00000000e+00, 0.00000000e+00, 2.14620746e-03, 6.47899336e-03, 1.23119791e-02, 1.91676140e-02, 2.64009788e-02, 3.32427846e-02, 3.88863288e-02, 4.26104002e-02, 4.39120296e-02, 4.26104002e-02, 3.88863288e-02, 3.32427846e-02, 2.64009788e-02, 1.91676140e-02, 1.23119791e-02, 6.47899336e-03, 2.14620746e-03, 0.00000000e+00, 0.00000000e+00 ], [ 0.00000000e+00, 8.57780996e-04, 3.99405791e-03, 9.31948105e-03, 1.65406113e-02, 2.51316805e-02, 3.43205435e-02, 4.31274592e-02, 5.04747209e-02, 5.53634169e-02, 5.70796092e-02, 5.53634169e-02, 5.04747209e-02, 4.31274592e-02, 3.43205435e-02, 2.51316805e-02, 1.65406113e-02, 9.31948105e-03, 3.99405791e-03, 8.57780996e-04, 0.00000000e+00 ], [ -7.32594549e-04, 1.80425497e-04, 3.76908220e-03, 1.00175179e-02, 1.86854835e-02, 2.92291145e-02, 4.07487277e-02, 5.20057177e-02, 6.15509770e-02, 6.79776087e-02, 7.02477931e-02, 6.79776087e-02, 6.15509770e-02, 5.20057177e-02, 4.07487277e-02, 2.92291145e-02, 1.86854835e-02, 1.00175179e-02, 3.76908220e-03, 1.80425497e-04, -7.32594549e-04 ], [ -3.29238561e-03, -2.60643191e-03, 1.16635260e-03, 8.15185259e-03, 1.82290773e-02, 3.08983182e-02, 4.51608038e-02, 5.94769126e-02, 7.18919113e-02, 8.03888307e-02, 8.34165399e-02, 8.03888307e-02, 7.18919113e-02, 5.94769126e-02, 4.51608038e-02, 3.08983182e-02, 1.82290773e-02, 8.15185259e-03, 1.16635260e-03, -2.60643191e-03, -3.29238561e-03 ], [ -7.68543266e-03, -7.63179286e-03, -4.08866637e-03, 3.27605236e-03, 1.45558215e-02, 2.94068040e-02, 4.68176355e-02, 6.49397159e-02, 7.72066272e-02, 8.50445368e-02, 8.77974692e-02, 8.50445368e-02, 7.72066272e-02, 6.49397159e-02, 4.68176355e-02, 2.94068040e-02, 1.45558215e-02, 3.27605236e-03, -4.08866637e-03, -7.63179286e-03, -7.68543266e-03 ], [ -1.38078234e-02, -1.49011067e-02, -1.21731364e-02, -5.02168047e-03, 6.98177526e-03, 2.38268531e-02, 4.30419205e-02, 6.00041964e-02, 7.44541603e-02, 8.42939552e-02, 8.77989590e-02, 8.42939552e-02, 7.44541603e-02, 6.00041964e-02, 4.30419205e-02, 2.38268531e-02, 6.98177526e-03, -5.02168047e-03, -1.21731364e-02, -1.49011067e-02, -1.38078234e-02 ], [ -2.13780396e-02, -2.42165379e-02, -2.30613142e-02, -1.70011475e-02, -5.15036128e-03, 1.25885635e-02, 3.24536739e-02, 5.25619351e-02, 7.05100243e-02, 8.31900906e-02, 8.78003567e-02, 8.31900906e-02, 7.05100243e-02, 5.25619351e-02, 3.24536739e-02, 1.25885635e-02, -5.15036128e-03, -1.70011475e-02, -2.30613142e-02, -2.42165379e-02, -2.13780396e-02 ], [ -2.98882710e-02, -3.50862342e-02, -3.63793490e-02, -3.25716319e-02, -2.22546618e-02, -3.59274163e-03, 1.83064517e-02, 4.20112440e-02, 6.46115966e-02, 8.14746164e-02, 8.78016623e-02, 8.14746164e-02, 6.46115966e-02, 4.20112440e-02, 1.83064517e-02, -3.59274163e-03, -2.22546618e-02, -3.25716319e-02, -3.63793490e-02, -3.50862342e-02, -2.98882710e-02 ], [ -3.85810679e-02, -4.66488633e-02, -5.12430987e-02, -5.10089462e-02, -4.20856023e-02, -2.36905234e-02, -6.33876287e-04, 2.66765430e-02, 5.53289928e-02, 7.86066125e-02, 8.78028757e-02, 7.86066125e-02, 5.53289928e-02, 2.66765430e-02, -6.33876287e-04, -2.36905234e-02, -4.20856023e-02, -5.10089462e-02, -5.12430987e-02, -4.66488633e-02, -3.85810679e-02 ], [ -4.64803335e-02, -5.76615888e-02, -6.61458422e-02, -7.06512643e-02, -6.38427394e-02, -4.77258398e-02, -2.55483969e-02, 4.05840724e-03, 3.98470070e-02, 7.33053399e-02, 8.78039969e-02, 7.33053399e-02, 3.98470070e-02, 4.05840724e-03, -2.55483969e-02, -4.77258398e-02, -6.38427394e-02, -7.06512643e-02, -6.61458422e-02, -5.76615888e-02, -4.64803335e-02 ], [ -5.25038299e-02, -6.66129442e-02, -7.90147081e-02, -8.87629178e-02, -8.59653118e-02, -7.42828398e-02, -5.64316505e-02, -2.87083225e-02, 1.25945312e-02, 6.19971667e-02, 8.78050260e-02, 6.19971667e-02, 1.25945312e-02, -2.87083225e-02, -5.64316505e-02, -7.42828398e-02, -8.59653118e-02, -8.87629178e-02, -7.90147081e-02, -6.66129442e-02, -5.25038299e-02 ], [ -5.69779111e-02, -7.36791817e-02, -8.97495345e-02, -1.04799583e-01, -1.07737239e-01, -1.02875880e-01, -9.46568471e-02, -7.95630162e-02, -4.96285112e-02, 6.59954795e-03, 5.25569882e-02, 6.59954795e-03, -4.96285112e-02, -7.95630162e-02, -9.46568471e-02, -1.02875880e-01, -1.07737239e-01, -1.04799583e-01, -8.97495345e-02, -7.36791817e-02, -5.69779111e-02 ], [ -5.90357675e-02, -7.69727119e-02, -9.48442826e-02, -1.12607620e-01, -1.18744885e-01, -1.18201834e-01, -1.17217017e-01, -1.15152899e-01, -1.09694433e-01, -8.82341332e-02, -1.61624035e-02, -8.82341332e-02, -1.09694433e-01, -1.15152899e-01, -1.17217017e-01, -1.18201834e-01, -1.18744885e-01, -1.12607620e-01, -9.48442826e-02, -7.69727119e-02, -5.90357675e-02 ], [ -5.92189452e-02, -7.72680305e-02, -9.53051857e-02, -1.13322519e-01, -1.19770917e-01, -1.19670660e-01, -1.19486798e-01, -1.19092639e-01, -1.17989113e-01, -1.12555820e-01, -4.50009776e-02, -1.12555820e-01, -1.17989113e-01, -1.19092639e-01, -1.19486798e-01, -1.19670660e-01, -1.19770917e-01, -1.13322519e-01, -9.53051857e-02, -7.72680305e-02, -5.92189452e-02 ], [ -5.79249958e-02, -7.51927112e-02, -9.20842554e-02, -1.08361430e-01, -1.12722790e-01, -1.09732675e-01, -1.04531672e-01, -9.44729544e-02, -7.23277773e-02, -2.05699911e-02, 3.58249631e-02, -2.05699911e-02, -7.23277773e-02, -9.44729544e-02, -1.04531672e-01, -1.09732675e-01, -1.12722790e-01, -1.08361430e-01, -9.20842554e-02, -7.51927112e-02, -5.79249958e-02 ], [ -5.42527703e-02, -6.93641123e-02, -8.31684773e-02, -9.49114165e-02, -9.41989454e-02, -8.48645354e-02, -7.00894708e-02, -4.58286259e-02, -6.37563061e-03, 4.68887998e-02, 7.77968419e-02, 4.68887998e-02, -6.37563061e-03, -4.58286259e-02, -7.00894708e-02, -8.48645354e-02, -9.41989454e-02, -9.49114165e-02, -8.31684773e-02, -6.93641123e-02, -5.42527703e-02 ], [ -4.82490057e-02, -5.99997941e-02, -6.91786120e-02, -7.44891242e-02, -6.73705808e-02, -5.13001284e-02, -2.84188057e-02, 3.60143816e-03, 4.47470123e-02, 8.58663851e-02, 1.04548354e-01, 8.58663851e-02, 4.47470123e-02, 3.60143816e-03, -2.84188057e-02, -5.13001284e-02, -6.73705808e-02, -7.44891242e-02, -6.91786120e-02, -5.99997941e-02, -4.82490057e-02 ], [ -4.03203010e-02, -4.79063206e-02, -5.16352259e-02, -4.98707253e-02, -3.67295509e-02, -1.57342058e-02, 1.13668830e-02, 4.46551184e-02, 8.10450840e-02, 1.11780747e-01, 1.24226598e-01, 1.11780747e-01, 8.10450840e-02, 4.46551184e-02, 1.13668830e-02, -1.57342058e-02, -3.67295509e-02, -4.98707253e-02, -5.16352259e-02, -4.79063206e-02, -4.03203010e-02 ], [ -3.10250239e-02, -3.40796094e-02, -3.22089254e-02, -2.37094100e-02, -5.85463114e-03, 1.77402761e-02, 4.57786845e-02, 7.69637052e-02, 1.07537652e-01, 1.30906328e-01, 1.39800436e-01, 1.30906328e-01, 1.07537652e-01, 7.69637052e-02, 4.57786845e-02, 1.77402761e-02, -5.85463114e-03, -2.37094100e-02, -3.22089254e-02, -3.40796094e-02, -3.10250239e-02 ], [ -2.09301700e-02, -1.94475962e-02, -1.22970199e-02, 2.07296407e-03, 2.31516868e-02, 4.74574033e-02, 7.44743481e-02, 1.02380049e-01, 1.27776301e-01, 1.46003379e-01, 1.52690015e-01, 1.46003379e-01, 1.27776301e-01, 1.02380049e-01, 7.44743481e-02, 4.74574033e-02, 2.31516868e-02, 2.07296407e-03, -1.22970199e-02, -1.94475962e-02, -2.09301700e-02 ], [ -1.05257992e-02, -4.74329696e-03, 7.12107274e-03, 2.63431361e-02, 4.93709790e-02, 7.31527220e-02, 9.82233938e-02, 1.22728059e-01, 1.43894925e-01, 1.58465026e-01, 1.63685984e-01, 1.58465026e-01, 1.43894925e-01, 1.22728059e-01, 9.82233938e-02, 7.31527220e-02, 4.93709790e-02, 2.63431361e-02, 7.12107274e-03, -4.74329696e-03, -1.05257992e-02 ], [ -1.89098657e-04, 9.52392382e-03, 2.54577716e-02, 4.85730869e-02, 7.26048516e-02, 9.51726659e-02, 1.17988523e-01, 1.39380421e-01, 1.57176612e-01, 1.69076915e-01, 1.73274075e-01, 1.69076915e-01, 1.57176612e-01, 1.39380421e-01, 1.17988523e-01, 9.51726659e-02, 7.26048516e-02, 4.85730869e-02, 2.54577716e-02, 9.52392382e-03, -1.89098657e-04 ], [ 9.81732797e-03, 2.30419581e-02, 4.24234701e-02, 6.86213308e-02, 9.30164618e-02, 1.14050063e-01, 1.34620894e-01, 1.53304069e-01, 1.68420867e-01, 1.78321253e-01, 1.81774183e-01, 1.78321253e-01, 1.68420867e-01, 1.53304069e-01, 1.34620894e-01, 1.14050063e-01, 9.30164618e-02, 6.86213308e-02, 4.24234701e-02, 2.30419581e-02, 9.81732797e-03 ], [ 1.93290725e-02, 3.56493099e-02, 5.79271157e-02, 8.65611122e-02, 1.10914315e-01, 1.30317702e-01, 1.48798006e-01, 1.65173224e-01, 1.78147031e-01, 1.86513895e-01, 1.89408199e-01, 1.86513895e-01, 1.78147031e-01, 1.65173224e-01, 1.48798006e-01, 1.30317702e-01, 1.10914315e-01, 8.65611122e-02, 5.79271157e-02, 3.56493099e-02, 1.93290725e-02 ], [ 2.68168937e-02, 4.52356810e-02, 6.92261217e-02, 9.89630241e-02, 1.23093435e-01, 1.40640067e-01, 1.56998943e-01, 1.71215219e-01, 1.82297185e-01, 1.89360704e-01, 1.91789146e-01, 1.89360704e-01, 1.82297185e-01, 1.71215219e-01, 1.56998943e-01, 1.40640067e-01, 1.23093435e-01, 9.89630241e-02, 6.92261217e-02, 4.52356810e-02, 2.68168937e-02 ], [ 3.19403269e-02, 5.15051953e-02, 7.61032066e-02, 1.05705197e-01, 1.31722206e-01, 1.47466588e-01, 1.61892450e-01, 1.74235616e-01, 1.83735386e-01, 1.89735533e-01, 1.91788616e-01, 1.89735533e-01, 1.83735386e-01, 1.74235616e-01, 1.61892450e-01, 1.47466588e-01, 1.31722206e-01, 1.05705197e-01, 7.61032066e-02, 5.15051953e-02, 3.19403269e-02 ], [ 3.48604070e-02, 5.49292382e-02, 7.94274234e-02, 1.08149011e-01, 1.38923419e-01, 1.53070440e-01, 1.65849067e-01, 1.76646162e-01, 1.84871647e-01, 1.90029617e-01, 1.91787948e-01, 1.90029617e-01, 1.84871647e-01, 1.76646162e-01, 1.65849067e-01, 1.53070440e-01, 1.38923419e-01, 1.08149011e-01, 7.94274234e-02, 5.49292382e-02, 3.48604070e-02 ], [ 3.53402022e-02, 5.53653759e-02, 7.91965502e-02, 1.06486934e-01, 1.36563003e-01, 1.57713955e-01, 1.69087164e-01, 1.78598269e-01, 1.85784340e-01, 1.90264452e-01, 1.91787141e-01, 1.90264452e-01, 1.85784340e-01, 1.78598269e-01, 1.69087164e-01, 1.57713955e-01, 1.36563003e-01, 1.06486934e-01, 7.91965502e-02, 5.53653759e-02, 3.53402022e-02 ], [ 3.32889822e-02, 5.28319225e-02, 7.55769079e-02, 1.01077605e-01, 1.28592068e-01, 1.57023616e-01, 1.71766715e-01, 1.80199729e-01, 1.86528091e-01, 1.90454829e-01, 1.91786196e-01, 1.90454829e-01, 1.86528091e-01, 1.80199729e-01, 1.71766715e-01, 1.57023616e-01, 1.28592068e-01, 1.01077605e-01, 7.55769079e-02, 5.28319225e-02, 3.32889822e-02 ], [ 2.87295370e-02, 4.74613283e-02, 6.88388861e-02, 9.23568989e-02, 1.17254645e-01, 1.42483223e-01, 1.66695764e-01, 1.81528776e-01, 1.87141877e-01, 1.90611190e-01, 1.91785112e-01, 1.90611190e-01, 1.87141877e-01, 1.81528776e-01, 1.66695764e-01, 1.42483223e-01, 1.17254645e-01, 9.23568989e-02, 6.88388861e-02, 4.74613283e-02, 2.87295370e-02 ], [ 2.17650266e-02, 3.94568191e-02, 5.93023344e-02, 8.07720575e-02, 1.03124482e-01, 1.25394282e-01, 1.46405870e-01, 1.64828303e-01, 1.79288925e-01, 1.88553222e-01, 1.91747252e-01, 1.88553222e-01, 1.79288925e-01, 1.64828303e-01, 1.46405870e-01, 1.25394282e-01, 1.03124482e-01, 8.07720575e-02, 5.93023344e-02, 3.94568191e-02, 2.17650266e-02 ], [ 1.25495284e-02, 2.90572166e-02, 4.72972116e-02, 6.67423656e-02, 8.66951873e-02, 1.06290296e-01, 1.24520131e-01, 1.40293247e-01, 1.52531693e-01, 1.60303860e-01, 1.62970689e-01, 1.60303860e-01, 1.52531693e-01, 1.40293247e-01, 1.24520131e-01, 1.06290296e-01, 8.66951873e-02, 6.67423656e-02, 4.72972116e-02, 2.90572166e-02, 1.25495284e-02 ], [ 1.26441934e-03, 1.65114811e-02, 3.31390978e-02, 5.06407706e-02, 6.83765492e-02, 8.55839448e-02, 1.01408074e-01, 1.14955639e-01, 1.25373662e-01, 1.31946425e-01, 1.34193829e-01, 1.31946425e-01, 1.25373662e-01, 1.14955639e-01, 1.01408074e-01, 8.55839448e-02, 6.83765492e-02, 5.06407706e-02, 3.31390978e-02, 1.65114811e-02, 1.26441934e-03 ], [ 0.00000000e+00, 2.06213867e-03, 1.71162845e-02, 3.27888240e-02, 4.85026462e-02, 6.35932476e-02, 7.73387997e-02, 8.90069217e-02, 9.79166934e-02, 1.03509489e-01, 1.05416736e-01, 1.03509489e-01, 9.79166934e-02, 8.90069217e-02, 7.73387997e-02, 6.35932476e-02, 4.85026462e-02, 3.27888240e-02, 1.71162845e-02, 2.06213867e-03, 0.00000000e+00 ] ]) np.testing.assert_allclose(fd, fd_test, rtol=1e-4)
def __init__(self, event): """ Construct an Origin object. Args: event (dict): Dictionary of values. See list above for required keys. Returns: Origin object. """ #----------------------------------------------------------------------- # Check for missing keys #----------------------------------------------------------------------- missing = [] for req in REQUIRED_KEYS: if req not in list(event.keys()): missing.append(req) if len(missing): raise Exception('Input event dictionary is missing the following ' 'required keys: "%s"' % (','.join(missing))) #----------------------------------------------------------------------- # Check some types, ranges, and defaults #----------------------------------------------------------------------- if not type(event['id']) is str: raise Exception('id must be a string.') event['lat'] = float(event['lat']) if (event['lat'] > 90) or (event['lat'] < -90): raise Exception('lat must be between -90 and 90 degrees.') event['lon'] = float(event['lon']) if (event['lon'] > 180) or (event['lon'] < -180): raise Exception('lat must be between -180 and 180 degrees.') event['depth'] = float(event['depth']) event['mag'] = float(event['mag']) if 'mech' in event.keys(): if event['mech'] == '': event['mech'] = DEFAULT_MECH if not event['mech'] in RAKEDICT.keys(): raise Exception('mech must be SS, NM, RS, or ALL.') elif 'type' in event.keys(): event['mech'] = event['type'] if event['mech'] == '': event['mech'] = DEFAULT_MECH if not event['mech'] in RAKEDICT.keys(): raise Exception('mech must be SS, NM, RS, or ALL.') else: event['mech'] = DEFAULT_MECH #----------------------------------------------------------------------- # Special handling of time #----------------------------------------------------------------------- if ('year' in event.keys()) and \ ('month' in event.keys()) and \ ('day' in event.keys()) and \ ('hour' in event.keys()) and \ ('second' in event.keys()) and \ ('msec' in event.keys()): year = int(event['year']) month = int(event['month']) day = int(event['day']) hour = int(event['hour']) minute = int(event['minute']) second = float(event['second']) msec = int((second - int(second)) * 1e6) # microsec second = int(second) event['time'] = ShakeDateTime( year, month, day, hour, minute, second, msec) else: event['time'] = ShakeDateTime.utcfromtimestamp(int(time.time())) #----------------------------------------------------------------------- # Add keys as class attributes #----------------------------------------------------------------------- for k, v in event.items(): if k == 'rake': setattr(self, k, float(v)) else: setattr(self, k, v) # What about rake? if not hasattr(self, 'rake'): if hasattr(self, 'mech'): mech = self.mech self.rake = RAKEDICT[mech] else: self.rake = RAKEDICT['ALL']
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)
def test_rv4(): magnitude = 7.0 rake = 90.0 width = np.array([28]) fltx = np.array([0, 0]) flty = np.array([0, 32]) zp = np.array([0]) dip = np.array([30]) # Convert to lat/lon proj = geo.utils.get_orthographic_projection(-122, -120, 39, 37) tlon, tlat = proj(fltx, flty, reverse=True) flt = fault.Fault.fromTrace(np.array([tlon[0]]), np.array([tlat[0]]), np.array([tlon[1]]), np.array([tlat[1]]), zp, width, dip, reference='') L = flt.getFaultLength() # Try to figure out epicenter tmp = flt.getQuadrilaterals()[0] pp0 = Vector.fromPoint(point.Point(tmp[0].longitude, tmp[0].latitude, tmp[0].depth)) pp1 = Vector.fromPoint(point.Point(tmp[1].longitude, tmp[1].latitude, tmp[1].depth)) pp2 = Vector.fromPoint(point.Point(tmp[2].longitude, tmp[2].latitude, tmp[2].depth)) pp3 = Vector.fromPoint(point.Point(tmp[3].longitude, tmp[3].latitude, tmp[3].depth)) dxp = 6/L dyp = (width-8)/width mp0 = pp0 + (pp1 - pp0)*dxp mp1 = pp3 + (pp2 - pp3)*dxp rp = mp0 + (mp1 - mp0)*dyp epilat,epilon,epidepth = ecef2latlon(rp.x, rp.y, rp.z) event = {'lat': epilat, 'lon': epilon, 'depth': epidepth, 'mag': magnitude, 'id': 'test', 'locstring': 'rv4', 'type': 'DS', 'timezone': 'UTC'} event['time'] = ShakeDateTime.utcfromtimestamp(int(time.time())) event['created'] = ShakeDateTime.utcfromtimestamp(int(time.time())) x = np.linspace(-50, 50, 11) y = np.linspace(-50, 50, 11) site_x, site_y = np.meshgrid(x, y) slon, slat = proj(site_x, site_y, reverse=True) deps = np.zeros_like(slon) source = Source(event, flt) source.setEventParam('rake', rake) test1 = Bayless2013(source, slat, slon, deps, T=2.0) # Test fd fd = test1.getFd() fd_test = np.array( [[ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 1.72143257e-03, 1.34977260e-03, 4.33616224e-15, 1.24446253e-03, 1.16142357e-03, 2.25464716e-03, 7.05281751e-04, 0.00000000e+00], [ 0.00000000e+00, 0.00000000e+00, 7.62610242e-03, 1.25133844e-02, 5.61896104e-03, 7.63126014e-15, 4.52266194e-03, 4.67970900e-03, 1.02820316e-02, 5.13160096e-03, -6.13926251e-03], [ 0.00000000e+00, 4.00495234e-03, 2.37608386e-02, 2.37139333e-02, 9.55224050e-03, 5.66364910e-15, 7.70344813e-03, 7.36466362e-03, 1.48239704e-02, 8.40388145e-03, -1.58592485e-02], [ 8.08385547e-19, 9.38150101e-03, 3.38610620e-02, 3.85351492e-02, 1.91044918e-02, 3.98697802e-15, 1.54321666e-02, 1.21913760e-02, 2.04435166e-02, 1.04931859e-02, -1.85935894e-02], [ 2.12025421e-18, 1.37316085e-02, 4.40193799e-02, 6.16562477e-02, 4.77612496e-02, 2.60257085e-15, 3.86322888e-02, 1.97965887e-02, 2.64882038e-02, 1.23335908e-02, -2.07389932e-02], [ 2.64338576e-18, 1.45898292e-02, 4.89104213e-02, 7.70703166e-02, 9.55225258e-02, 1.01875104e-01, 7.73459329e-02, 2.50275508e-02, 2.93537540e-02, 1.30949577e-02, -2.15685454e-02], [ 2.64330042e-18, 1.45898262e-02, 4.89104186e-02, 7.70703146e-02, 9.55225248e-02, 1.01910945e-01, 7.74050835e-02, 2.52307946e-02, 2.92970736e-02, 1.30880504e-02, -2.15685424e-02], [ 2.64318867e-18, 1.45898259e-02, 4.89104184e-02, 7.70703144e-02, 9.55225247e-02, 1.01933432e-01, 7.74421258e-02, 2.53572923e-02, 2.92615130e-02, 1.30837284e-02, -2.15685422e-02], [ 2.64305117e-18, 1.45898284e-02, 4.89104206e-02, 7.70703161e-02, 9.55225256e-02, 1.01942593e-01, 7.74571359e-02, 2.54081640e-02, 2.92472117e-02, 1.30819985e-02, -2.15685446e-02], [ 2.30141673e-18, 1.40210825e-02, 4.56205547e-02, 6.63109661e-02, 5.79266964e-02, 2.33044622e-15, 4.69672564e-02, 2.18401553e-02, 2.72864925e-02, 1.25728575e-02, -2.10227772e-02], [ 1.10672535e-18, 1.04777076e-02, 3.59041065e-02, 4.24614318e-02, 2.24217216e-02, 3.66914762e-15, 1.81728517e-02, 1.39301504e-02, 2.14956836e-02, 1.08711460e-02, -1.90802849e-02]] ) np.testing.assert_allclose(fd, fd_test, rtol=2e-4)
def test_distance_no_fault(): # 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 # - Unknown/no tectonic region # - Mech is ALL event = {'lat': 34.1, 'lon': -118.2, 'depth': 1, 'mag': 6, 'id': '', 'locstring': '', 'time': ShakeDateTime.utcfromtimestamp(int(time.time())), 'timezone': 'UTC'} source = Source(event) source.setMechanism('ALL') gmpe = AbrahamsonEtAl2014() dists = Distance.fromSites(gmpe, source, site) dctx = dists.getDistanceContext() rjb = np.array( [[1.69885399, 1.43717125, 1.2401229, 1.12306082, 1.08344161, 1.12306082, 1.2401229, 1.43717125, 1.69885399], [1.31170897, 1.03475736, 0.82507289, 0.69891123, 0.6553167, 0.69891123, 0.82507289, 1.03475736, 1.31170897], [1.02288894, 0.72918893, 0.50725874, 0.36675284, 0.31957002, 0.36675284, 0.50725874, 0.72918893, 1.02288894], [0.83950888, 0.53487557, 0.30135487, 0.14776055, 0.09290799, 0.14776055, 0.30135487, 0.53487557, 0.83950888], [0.77835253, 0.46963915, 0.2280053, 0.06643829, 0., 0.06643829, 0.2280053, 0.46963915, 0.77835253], [0.83964536, 0.53495323, 0.30139344, 0.14777086, 0.09290799, 0.14777086, 0.30139344, 0.53495323, 0.83964536], [1.02314515, 0.72933979, 0.50732902, 0.36677229, 0.31957002, 0.36677229, 0.50732902, 0.72933979, 1.02314515], [1.31208408, 1.03497272, 0.82517579, 0.69893672, 0.6553167, 0.69893672, 0.82517579, 1.03497272, 1.31208408]] ) np.testing.assert_allclose( rjb, dctx.rjb, rtol=0, atol=0.01) rrup = np.array( [[8.55244227, 8.44386675, 8.30721612, 8.28522381, 8.27615555, 8.28522381, 8.30721612, 8.44386675, 8.55244227], [8.36298714, 8.26004043, 8.11921658, 8.11376473, 8.09579991, 8.11376473, 8.11921658, 8.26004043, 8.36298714], [8.25524589, 8.12023764, 8.01816823, 7.93517669, 7.9600631, 7.93517669, 8.01816823, 8.12023764, 8.25524589], [8.13306689, 8.00702434, 7.95888951, 7.8881565, 7.88352525, 7.8881565, 7.95888951, 8.00702434, 8.13306689], [8.12102175, 8.02022568, 7.90722113, 7.85639147, 0., 7.85639147, 7.90722113, 8.02022568, 8.12102175], [8.13319461, 8.00698213, 7.95890141, 7.88813785, 7.88352525, 7.88813785, 7.95890141, 8.00698213, 8.13319461], [8.25535307, 8.12025813, 8.01814988, 7.93520725, 7.9600631, 7.93520725, 8.01814988, 8.12025813, 8.25535307], [8.36326021, 8.26012423, 8.11931772, 8.1137722, 8.09579991, 8.1137722, 8.11931772, 8.26012423, 8.36326021]] ) np.testing.assert_allclose( rrup, dctx.rrup, rtol=0, atol=0.01) # Souce instance # - Tectonic region: active # - Mech is ALL source.setMechanism('ALL') source._tectonic_region = 'Active Shallow Crust' dists = Distance.fromSites(gmpe, source, site) dctx = dists.getDistanceContext() rjb = np.array( [[1.7826962, 1.5154877, 1.31394288, 1.19278311, 1.15168205, 1.19278311, 1.31394288, 1.5154877, 1.7826962], [1.38719993, 1.10115976, 0.88331216, 0.75077594, 0.70491937, 0.75077594, 0.88331216, 1.10115976, 1.38719993], [1.08884025, 0.78261273, 0.54865189, 0.39914713, 0.34852149, 0.39914713, 0.54865189, 0.78261273, 1.08884025], [0.8983245, 0.57800579, 0.32895654, 0.16294131, 0.10290794, 0.16294131, 0.32895654, 0.57800579, 0.8983245], [0.83428851, 0.50865092, 0.25000954, 0.07371315, 0., 0.07371315, 0.25000954, 0.50865092, 0.83428851], [0.89846642, 0.57808833, 0.32899797, 0.16295256, 0.10290794, 0.16295256, 0.32899797, 0.57808833, 0.89846642], [1.08910622, 0.78277133, 0.5487266, 0.39916785, 0.34852149, 0.39916785, 0.5487266, 0.78277133, 1.08910622], [1.38758368, 1.10138329, 0.88341918, 0.75080275, 0.70491937, 0.75080275, 0.88341918, 1.10138329, 1.38758368]] ) np.testing.assert_allclose( rjb, dctx.rjb, rtol=0, atol=0.01) rrup = np.array( [[9.0098969, 8.90622877, 8.76985073, 8.7508322, 8.74262729, 8.7508322, 8.76985073, 8.90622877, 9.0098969], [8.82590475, 8.72726953, 8.58534811, 8.58323541, 8.5654409, 8.58323541, 8.58534811, 8.72726953, 8.82590475], [8.72260676, 8.58922774, 8.4871601, 8.40244887, 8.4297141, 8.40244887, 8.4871601, 8.58922774, 8.72260676], [8.59952763, 8.47470803, 8.42880892, 8.35631312, 8.35201539, 8.35631312, 8.42880892, 8.47470803, 8.59952763], [8.58864463, 8.49021276, 8.37536496, 8.32350188, 0., 8.32350188, 8.37536496, 8.49021276, 8.58864463], [8.59965826, 8.47466149, 8.42882081, 8.35629324, 8.35201539, 8.35629324, 8.42882081, 8.47466149, 8.59965826], [8.72271133, 8.58924512, 8.48713903, 8.4024808, 8.4297141, 8.4024808, 8.48713903, 8.58924512, 8.72271133], [8.8261781, 8.72735075, 8.58545174, 8.5832426, 8.5654409, 8.5832426, 8.58545174, 8.72735075, 8.8261781]] ) np.testing.assert_allclose( rrup, dctx.rrup, rtol=0, atol=0.01) # Souce instance # - Tectonic region: active # - Mech is RS source.setMechanism('RS') source._tectonic_region = 'Active Shallow Crust' dists = Distance.fromSites(gmpe, source, site) dctx = dists.getDistanceContext() rjb = np.array( [[1.62698377, 1.35570722, 1.15237308, 1.03338675, 0.99327828, 1.03338675, 1.15237308, 1.35570722, 1.62698377], [1.22613799, 0.94405696, 0.73298036, 0.61025288, 0.56806407, 0.61025288, 0.73298036, 0.94405696, 1.22613799], [0.93206877, 0.63960501, 0.42680989, 0.29738908, 0.25562246, 0.29738908, 0.42680989, 0.63960501, 0.93206877], [0.74745861, 0.45239173, 0.23958848, 0.10874248, 0.06508855, 0.10874248, 0.23958848, 0.45239173, 0.74745861], [0.68734787, 0.39203111, 0.17571632, 0.04480241, 0., 0.04480241, 0.17571632, 0.39203111, 0.68734787], [0.74759552, 0.45246373, 0.2396224, 0.1087508, 0.06508855, 0.1087508, 0.2396224, 0.45246373, 0.74759552], [0.93232753, 0.63975135, 0.42687494, 0.29740691, 0.25562246, 0.29740691, 0.42687494, 0.63975135, 0.93232753], [1.22652484, 0.94427453, 0.73308353, 0.61027758, 0.56806407, 0.61027758, 0.73308353, 0.94427453, 1.22652484]] ) np.testing.assert_allclose( rjb, dctx.rjb, rtol=0, atol=0.01) rrup = np.array( [[9.10924586, 9.00129817, 8.86119702, 8.8412603, 8.83276567, 8.8412603, 8.86119702, 9.00129817, 9.10924586], [8.91865949, 8.81700098, 8.67259556, 8.6707467, 8.65288076, 8.6707467, 8.67259556, 8.81700098, 8.91865949], [8.81223015, 8.67672238, 8.57444747, 8.49014736, 8.5183922, 8.49014736, 8.57444747, 8.67672238, 8.81223015], [8.68698864, 8.56159881, 8.51774523, 8.44708824, 8.44391005, 8.44708824, 8.51774523, 8.56159881, 8.68698864], [8.67600489, 8.57788943, 8.46484058, 8.41567031, 0., 8.41567031, 8.46484058, 8.57788943, 8.67600489], [8.68712127, 8.56155103, 8.51775668, 8.44706792, 8.44391005, 8.44706792, 8.51775668, 8.56155103, 8.68712127], [8.81233708, 8.67673955, 8.5744255, 8.49017946, 8.5183922, 8.49017946, 8.5744255, 8.67673955, 8.81233708], [8.91894005, 8.81708413, 8.67270074, 8.67075389, 8.65288076, 8.67075389, 8.67270074, 8.81708413, 8.91894005]] ) np.testing.assert_allclose( rrup, dctx.rrup, rtol=0, atol=0.01) # Souce instance # - Tectonic region: active # - Mech is NM source.setMechanism('NM') source._tectonic_region = 'Active Shallow Crust' dists = Distance.fromSites(gmpe, source, site) dctx = dists.getDistanceContext() rjb = np.array( [[1.37668217, 1.14221705, 0.96668127, 0.86561026, 0.8316382, 0.86561026, 0.96668127, 1.14221705, 1.37668217], [1.03033842, 0.7899535, 0.61128249, 0.50843465, 0.47310349, 0.50843465, 0.61128249, 0.7899535, 1.03033842], [0.77980196, 0.53301769, 0.35495992, 0.24706995, 0.21231668, 0.24706995, 0.35495992, 0.53301769, 0.77980196], [0.62353293, 0.37628889, 0.19897762, 0.09028387, 0.05409271, 0.09028387, 0.19897762, 0.37628889, 0.62353293], [0.57300663, 0.32596438, 0.14586493, 0.03728933, 0., 0.03728933, 0.14586493, 0.32596438, 0.57300663], [0.62364878, 0.37634892, 0.19900584, 0.09029076, 0.05409271, 0.09029076, 0.19900584, 0.37634892, 0.62364878], [0.78002107, 0.53314026, 0.35501415, 0.24708481, 0.21231668, 0.24708481, 0.35501415, 0.53314026, 0.78002107], [1.03067234, 0.79013775, 0.61136979, 0.50845534, 0.47310349, 0.50845534, 0.61136979, 0.79013775, 1.03067234]] ) np.testing.assert_allclose( rjb, dctx.rjb, rtol=0, atol=0.01) rrup = np.array( [[8.24181179, 8.13246903, 7.99744833, 7.97427973, 7.96488994, 7.97427973, 7.99744833, 8.13246903, 8.24181179], [8.0523808, 7.94857792, 7.8097532, 7.80275055, 7.78489184, 7.80275055, 7.8097532, 7.94857792, 8.0523808], [7.94376991, 7.80938707, 7.70839546, 7.62713392, 7.65061937, 7.62713392, 7.70839546, 7.80938707, 7.94376991], [7.82330022, 7.69799123, 7.64933048, 7.58013644, 7.57530397, 7.58013644, 7.64933048, 7.69799123, 7.82330022], [7.81082127, 7.7099614, 7.59905656, 7.54904995, 0., 7.54904995, 7.59905656, 7.7099614, 7.81082127], [7.8234252, 7.69795153, 7.64934225, 7.58011859, 7.57530397, 7.58011859, 7.64934225, 7.69795153, 7.8234252], [7.94387723, 7.80940883, 7.70837861, 7.62716348, 7.65061937, 7.62716348, 7.70837861, 7.80940883, 7.94387723], [8.05265024, 7.94866209, 7.80985208, 7.80275807, 7.78489184, 7.80275807, 7.80985208, 7.94866209, 8.05265024]] ) np.testing.assert_allclose( rrup, dctx.rrup, rtol=0, atol=0.01) # Souce instance # - Tectonic region: active # - Mech is SS source.setMechanism('SS') source._tectonic_region = 'Active Shallow Crust' dists = Distance.fromSites(gmpe, source, site) dctx = dists.getDistanceContext() rjb = np.array( [[2.87579088, 2.5456044, 2.29185071, 2.12884849, 2.07268393, 2.12884849, 2.29185071, 2.5456044, 2.87579088], [2.38460904, 2.00333625, 1.69987873, 1.49778447, 1.42682201, 1.49778447, 1.69987873, 2.00333625, 2.38460904], [1.98637252, 1.54679373, 1.17582687, 0.914992, 0.81812345, 0.914992, 1.17582687, 1.54679373, 1.98637252], [1.72104847, 1.22626178, 0.78021345, 0.43426687, 0.29180829, 0.43426687, 0.78021345, 1.22626178, 1.72104847], [1.62592524, 1.10672645, 0.62338097, 0.21787328, 0., 0.21787328, 0.62338097, 1.10672645, 1.62592524], [1.72124839, 1.22640328, 0.7802939, 0.43429295, 0.29180829, 0.43429295, 0.7802939, 1.22640328, 1.72124839], [1.98673898, 1.54703738, 1.17595553, 0.9150287, 0.81812345, 0.9150287, 1.17595553, 1.54703738, 1.98673898], [2.3850933, 2.00364385, 1.7000298, 1.49782584, 1.42682201, 1.49782584, 1.7000298, 2.00364385, 2.3850933]] ) np.testing.assert_allclose( rjb, dctx.rjb, rtol=0, atol=0.01) rrup = np.array( [[8.37718818, 8.22723595, 8.0625333, 8.01740393, 8.00044835, 8.01740393, 8.0625333, 8.22723595, 8.37718818], [8.12814884, 7.97494557, 7.79806013, 7.76281765, 7.735536, 7.76281765, 7.79806013, 7.97494557, 8.12814884], [7.96791548, 7.77614524, 7.62644695, 7.5120851, 7.52225031, 7.5120851, 7.62644695, 7.77614524, 7.96791548], [7.81413881, 7.62326525, 7.51608628, 7.40624352, 7.38577101, 7.40624352, 7.51608628, 7.62326525, 7.81413881], [7.78868149, 7.61851685, 7.44728324, 7.35263272, 0., 7.35263272, 7.44728324, 7.61851685, 7.78868149], [7.81428779, 7.62324614, 7.51610811, 7.40622914, 7.38577101, 7.40622914, 7.51610811, 7.62324614, 7.81428779], [7.96807069, 7.77620063, 7.62644821, 7.51211876, 7.52225031, 7.51211876, 7.62644821, 7.77620063, 7.96807069], [8.12847458, 7.97507013, 7.798177, 7.76283076, 7.735536, 7.76283076, 7.798177, 7.97507013, 8.12847458]] ) np.testing.assert_allclose( rrup, dctx.rrup, rtol=0, atol=0.01) # Souce instance # - Tectonic region: stable # - Mech is all source.setMechanism('ALL') source._tectonic_region = 'Stable Shallow Crust' dists = Distance.fromSites(gmpe, source, site) dctx = dists.getDistanceContext() rjb = np.array( [[2.03925124, 1.73155737, 1.4995708, 1.36023359, 1.3129796, 1.36023359, 1.4995708, 1.73155737, 2.03925124], [1.58388219, 1.25490086, 1.00456938, 0.85266727, 0.80013341, 0.85266727, 1.00456938, 1.25490086, 1.58388219], [1.24073997, 0.8891456, 0.621322, 0.4507253, 0.39310934, 0.4507253, 0.621322, 0.8891456, 1.24073997], [1.02181451, 0.65483395, 0.37085259, 0.18246645, 0.11472522, 0.18246645, 0.37085259, 0.65483395, 1.02181451], [0.94836452, 0.57566287, 0.28111922, 0.08186392, 0., 0.08186392, 0.28111922, 0.57566287, 0.94836452], [1.02197754, 0.65492818, 0.37089972, 0.18247916, 0.11472522, 0.18247916, 0.37089972, 0.65492818, 1.02197754], [1.24104568, 0.88932733, 0.62140729, 0.45074894, 0.39310934, 0.45074894, 0.62140729, 0.88932733, 1.24104568], [1.58432388, 1.2551578, 1.00469232, 0.85269799, 0.80013341, 0.85269799, 1.00469232, 1.2551578, 1.58432388]] ) np.testing.assert_allclose( rjb, dctx.rjb, rtol=0, atol=0.01) rrup = np.array( [[6.77027261, 6.6175234, 6.4620818, 6.41487409, 6.39777405, 6.41487409, 6.4620818, 6.6175234, 6.77027261], [6.52306411, 6.37308879, 6.21401632, 6.17868645, 6.15460391, 6.17868645, 6.21401632, 6.37308879, 6.52306411], [6.36643129, 6.19096821, 6.06108712, 5.96682577, 5.97487576, 5.96682577, 6.06108712, 6.19096821, 6.36643129], [6.22803711, 6.05926472, 5.97000316, 5.88510619, 5.87109182, 5.88510619, 5.97000316, 6.05926472, 6.22803711], [6.2037114, 6.05384337, 5.91573235, 5.84608701, 0., 5.84608701, 5.91573235, 6.05384337, 6.2037114], [6.22816728, 6.05925153, 5.97002045, 5.88509436, 5.87109182, 5.88509436, 5.97002045, 6.05925153, 6.22816728], [6.36657773, 6.1910207, 6.0610899, 5.96685295, 5.97487576, 5.96685295, 6.0610899, 6.1910207, 6.36657773], [6.52336953, 6.37320723, 6.21411804, 6.17869829, 6.15460391, 6.17869829, 6.21411804, 6.37320723, 6.52336953]] ) np.testing.assert_allclose( rrup, dctx.rrup, rtol=0, atol=0.01) # Souce instance # - Tectonic region: stable # - Mech is RS source.setMechanism('RS') source._tectonic_region = 'Stable Shallow Crust' dists = Distance.fromSites(gmpe, source, site) dctx = dists.getDistanceContext() rjb = np.array( [[1.82771374, 1.52643611, 1.30046931, 1.16760601, 1.12277703, 1.16760601, 1.30046931, 1.52643611, 1.82771374], [1.38246113, 1.06775489, 0.83169032, 0.69344486, 0.645892, 0.69344486, 0.83169032, 1.06775489, 1.38246113], [1.05435251, 0.72652464, 0.48639585, 0.33959401, 0.2920419, 0.33959401, 0.48639585, 0.72652464, 1.05435251], [0.84788911, 0.51540522, 0.27378007, 0.12450057, 0.07451822, 0.12450057, 0.27378007, 0.51540522, 0.84788911], [0.78032378, 0.44695345, 0.20099496, 0.05123817, 0., 0.05123817, 0.20099496, 0.44695345, 0.78032378], [0.84804229, 0.51548687, 0.2738187, 0.12451008, 0.07451822, 0.12451008, 0.2738187, 0.51548687, 0.84804229], [1.0546418, 0.72668956, 0.48646962, 0.33961424, 0.2920419, 0.33961424, 0.48646962, 0.72668956, 1.0546418], [1.38289108, 1.06799812, 0.83180576, 0.6934727, 0.645892, 0.6934727, 0.83180576, 1.06799812, 1.38289108]] ) np.testing.assert_allclose( rjb, dctx.rjb, rtol=0, atol=0.01) rrup = np.array( [[6.73175745, 6.58096329, 6.42717448, 6.38198779, 6.36563579, 6.38198779, 6.42717448, 6.58096329, 6.73175745], [6.48753618, 6.34187696, 6.18689857, 6.15537676, 6.13263668, 6.15537676, 6.18689857, 6.34187696, 6.48753618], [6.33544657, 6.1667275, 6.04409157, 5.9555343, 5.96586226, 5.9555343, 6.04409157, 6.1667275, 6.33544657], [6.20063145, 6.04113522, 5.96186983, 5.88482917, 5.87387645, 5.88482917, 5.96186983, 6.04113522, 6.20063145], [6.17796118, 6.03838637, 5.91117189, 5.85034216, 0., 5.85034216, 5.91117189, 6.03838637, 6.17796118], [6.20075891, 6.04111884, 5.96188527, 5.88481675, 5.87387645, 5.88481675, 5.96188527, 6.04111884, 6.20075891], [6.3355881, 6.16677535, 6.04409147, 5.9555607, 5.96586226, 5.9555607, 6.04409147, 6.16677535, 6.3355881], [6.48783842, 6.34199129, 6.18699823, 6.15538781, 6.13263668, 6.15538781, 6.18699823, 6.34199129, 6.48783842]] ) np.testing.assert_allclose( rrup, dctx.rrup, rtol=0, atol=0.01) # Souce instance # - Tectonic region: stable # - Mech is NM source.setMechanism('NM') source._tectonic_region = 'Stable Shallow Crust' dists = Distance.fromSites(gmpe, source, site) dctx = dists.getDistanceContext() rjb = np.array( [[1.90163976, 1.59090426, 1.35772802, 1.21975997, 1.17315714, 1.21975997, 1.35772802, 1.59090426, 1.90163976], [1.44234875, 1.11595412, 0.87047978, 0.72608143, 0.6763976, 0.72608143, 0.87047978, 1.11595412, 1.44234875], [1.10201987, 0.7606424, 0.50965507, 0.35594865, 0.30612448, 0.35594865, 0.50965507, 0.7606424, 1.10201987], [0.88732736, 0.5400275, 0.28698884, 0.13052973, 0.0781228, 0.13052973, 0.28698884, 0.5400275, 0.88732736], [0.81684854, 0.46835876, 0.21071547, 0.05370847, 0., 0.05370847, 0.21071547, 0.46835876, 0.81684854], [0.88748668, 0.54011298, 0.28702933, 0.1305397, 0.0781228, 0.1305397, 0.28702933, 0.54011298, 0.88748668], [1.10232064, 0.76081471, 0.50973231, 0.35596982, 0.30612448, 0.35596982, 0.50973231, 0.76081471, 1.10232064], [1.44279245, 1.116207, 0.87059985, 0.72611052, 0.6763976, 0.72611052, 0.87059985, 1.116207, 1.44279245]] ) np.testing.assert_allclose( rjb, dctx.rjb, rtol=0, atol=0.01) rrup = np.array( [[6.51552789, 6.35105562, 6.18910077, 6.13678714, 6.11808742, 6.13678714, 6.18910077, 6.35105562, 6.51552789], [6.25219098, 6.09163676, 5.92783781, 5.88815939, 5.8632258, 5.88815939, 5.92783781, 6.09163676, 6.25219098], [6.08458377, 5.9012656, 5.76798442, 5.67370059, 5.68021406, 5.67370059, 5.76798442, 5.9012656, 6.08458377], [5.9420166, 5.76720934, 5.67516593, 5.59187321, 5.57813972, 5.59187321, 5.67516593, 5.76720934, 5.9420166], [5.91572554, 5.75981247, 5.62205686, 5.55427369, 0., 5.55427369, 5.62205686, 5.75981247, 5.91572554], [5.9421484, 5.76719951, 5.67518325, 5.59186206, 5.57813972, 5.59186206, 5.67518325, 5.76719951, 5.9421484], [6.0847386, 5.90132265, 5.76798949, 5.67372705, 5.68021406, 5.67372705, 5.76798949, 5.90132265, 6.0847386], [6.25250826, 6.09176251, 5.92794056, 5.88817184, 5.8632258, 5.88817184, 5.92794056, 6.09176251, 6.25250826]] ) np.testing.assert_allclose( rrup, dctx.rrup, rtol=0, atol=0.01) # Souce instance # - Tectonic region: stable # - Mech is SS source.setMechanism('SS') source._tectonic_region = 'Stable Shallow Crust' dists = Distance.fromSites(gmpe, source, site) dctx = dists.getDistanceContext() rjb = np.array( [[2.72873417, 2.37144886, 2.09954885, 1.92851977, 1.86995227, 1.92851977, 2.09954885, 2.37144886, 2.72873417], [2.19864742, 1.7978181, 1.48474703, 1.28392745, 1.21396452, 1.28392745, 1.48474703, 1.7978181, 2.19864742], [1.78020402, 1.3323943, 0.97123526, 0.72919945, 0.64364445, 0.72919945, 0.97123526, 1.3323943, 1.78020402], [1.5064397, 1.01846151, 0.61039475, 0.3191157, 0.20751973, 0.3191157, 0.61039475, 1.01846151, 1.5064397], [1.41089093, 0.90673813, 0.47477623, 0.15160737, 0., 0.15160737, 0.47477623, 0.90673813, 1.41089093], [1.50664467, 1.01859418, 0.61046522, 0.3191364, 0.20751973, 0.3191364, 0.61046522, 1.01859418, 1.50664467], [1.7805844, 1.33263554, 0.97135557, 0.72923321, 0.64364445, 0.72923321, 0.97135557, 1.33263554, 1.7805844], [2.1991657, 1.79813761, 1.48490175, 1.28396831, 1.21396452, 1.28396831, 1.48490175, 1.79813761, 2.1991657]] ) np.testing.assert_allclose( rjb, dctx.rjb, rtol=0, atol=0.01) rrup = np.array( [[5.84874652, 5.62706324, 5.42929028, 5.34392626, 5.31406828, 5.34392626, 5.42929028, 5.62706324, 5.84874652], [5.50458234, 5.27459324, 5.06456452, 4.9821571, 4.94467172, 4.9821571, 5.06456452, 5.27459324, 5.50458234], [5.26448475, 5.00483041, 4.80820132, 4.67381918, 4.65867853, 4.67381918, 4.80820132, 5.00483041, 5.26448475], [5.08135199, 4.81923672, 4.64680257, 4.514164, 4.47986499, 4.514164, 4.64680257, 4.81923672, 5.08135199], [5.03620112, 4.78581905, 4.57286829, 4.44979468, 0., 4.44979468, 4.57286829, 4.78581905, 5.03620112], [5.0815089, 4.81926166, 4.64683299, 4.51415954, 4.47986499, 4.51415954, 4.64683299, 4.81926166, 5.0815089], [5.26470503, 5.00493679, 4.80823501, 4.67384847, 4.65867853, 4.67384847, 4.80823501, 5.00493679, 5.26470503], [5.5049661, 5.27477487, 5.06468553, 4.98217732, 4.94467172, 4.98217732, 5.06468553, 5.27477487, 5.5049661]] ) np.testing.assert_allclose( rrup, dctx.rrup, rtol=0, atol=0.01)
def test_ss3_m6(): magnitude = 6.0 dip = np.array([90]) rake = 180.0 width = np.array([15]) fltx = np.array([0, 0]) flty = np.array([0, 80]) zp = np.array([0]) epix = np.array([0]) epiy = np.array([0.2 * flty[1]]) # Convert to lat/lon proj = geo.utils.get_orthographic_projection(-122, -120, 39, 37) tlon, tlat = proj(fltx, flty, reverse=True) epilon, epilat = proj(epix, epiy, reverse=True) flt = rupture.QuadRupture.fromTrace( np.array([tlon[0]]), np.array([tlat[0]]), np.array([tlon[1]]), np.array([tlat[1]]), zp, width, dip, reference='ss3') event = {'lat': epilat[0], 'lon': epilon[0], 'depth': 10, 'mag': magnitude, 'id': 'ss3', 'locstring': 'test', 'type': 'SS', 'timezone': 'UTC'} event['time'] = ShakeDateTime.utcfromtimestamp(int(time.time())) event['created'] = ShakeDateTime.utcfromtimestamp(int(time.time())) x = np.linspace(0, 20, 6) y = np.linspace(0, 90, 11) site_x, site_y = np.meshgrid(x, y) slon, slat = proj(site_x, site_y, reverse=True) deps = np.zeros_like(slon) source = Source(event, flt) source.setEventParam('rake', rake) test1 = Bayless2013(source, slat, slon, deps, T=1.0) # Test fd fd = test1.getFd() fd_test = np.array( [[ 0.05853668, 0.05032323, 0.0306438 , 0.00839635, -0.01102162, -0.02621319], [ 0.01720501, -0.00687296, -0.03804823, -0.05547473, -0.0644932 , -0.06947135], [-0.03000065, -0.07006634, -0.07708165, -0.07865941, -0.0792369 , -0.07950887], [ 0.0398062 , 0.02571145, -0.0018651 , -0.0255418 , -0.04176278, -0.05235095], [ 0.0696989 , 0.06389524, 0.04890304, 0.02983134, 0.01098535, -0.00545921], [ 0.088278 , 0.08511069, 0.07628596, 0.06350294, 0.04875897, 0.03373495], [ 0.10179334, 0.09978475, 0.09401676, 0.0851842 , 0.07422509, 0.06210369], [ 0.11242209, 0.11102701, 0.10696056, 0.10055471, 0.09229027, 0.08271454], [ 0.12118279, 0.12015315, 0.11712653, 0.11228058, 0.10588323, 0.09825795], [ 0.12785957, 0.12706892, 0.12473264, 0.12095384, 0.11589197, 0.10974684], [ 0.12785908, 0.12724852, 0.12543819, 0.12249026, 0.11850249, 0.11360047]]) np.testing.assert_allclose( fd, fd_test, rtol=1e-4)
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)
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')
def test_timeutils(): time = 1470152355.244582 sdt = ShakeDateTime.utcfromtimestamp(time) assert sdt == ShakeDateTime(2016, 8, 2, 15, 39, 15, 244582)
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)
def test_ss3(): magnitude = 7.2 dip = np.array([90]) rake = 180.0 width = np.array([15]) fltx = np.array([0, 0]) flty = np.array([0, 80]) zp = np.array([0]) epix = np.array([0]) epiy = np.array([0.2 * flty[1]]) # Convert to lat/lon proj = geo.utils.get_orthographic_projection(-122, -120, 39, 37) tlon, tlat = proj(fltx, flty, reverse=True) epilon, epilat = proj(epix, epiy, reverse=True) flt = fault.Fault.fromTrace(np.array([tlon[0]]), np.array([tlat[0]]), np.array([tlon[1]]), np.array([tlat[1]]), zp, width, dip, reference='ss3') event = {'lat': epilat[0], 'lon': epilon[0], 'depth': 10, 'mag': magnitude, 'id': 'ss3', 'locstring': 'test', 'type': 'SS', 'timezone': 'UTC'} event['time'] = ShakeDateTime.utcfromtimestamp(int(time.time())) event['created'] = ShakeDateTime.utcfromtimestamp(int(time.time())) x = np.linspace(-60, 60, 21) y = np.linspace(-60, 138, 34) site_x, site_y = np.meshgrid(x, y) slon, slat = proj(site_x, site_y, reverse=True) deps = np.zeros_like(slon) source = Source(event, flt) source.setEventParam('rake', rake) test1 = Bayless2013(source, slat, slon, deps, T=1.0) # Test fd fd = test1.getFd() fd_test = np.array( [[0.00000000e+00, 0.00000000e+00, 2.14620746e-03, 6.47899336e-03, 1.23119791e-02, 1.91676140e-02, 2.64009788e-02, 3.32427846e-02, 3.88863288e-02, 4.26104002e-02, 4.39120296e-02, 4.26104002e-02, 3.88863288e-02, 3.32427846e-02, 2.64009788e-02, 1.91676140e-02, 1.23119791e-02, 6.47899336e-03, 2.14620746e-03, 0.00000000e+00, 0.00000000e+00], [0.00000000e+00, 8.57780996e-04, 3.99405791e-03, 9.31948105e-03, 1.65406113e-02, 2.51316805e-02, 3.43205435e-02, 4.31274592e-02, 5.04747209e-02, 5.53634169e-02, 5.70796092e-02, 5.53634169e-02, 5.04747209e-02, 4.31274592e-02, 3.43205435e-02, 2.51316805e-02, 1.65406113e-02, 9.31948105e-03, 3.99405791e-03, 8.57780996e-04, 0.00000000e+00], [-7.32594549e-04, 1.80425497e-04, 3.76908220e-03, 1.00175179e-02, 1.86854835e-02, 2.92291145e-02, 4.07487277e-02, 5.20057177e-02, 6.15509770e-02, 6.79776087e-02, 7.02477931e-02, 6.79776087e-02, 6.15509770e-02, 5.20057177e-02, 4.07487277e-02, 2.92291145e-02, 1.86854835e-02, 1.00175179e-02, 3.76908220e-03, 1.80425497e-04, -7.32594549e-04], [-3.29238561e-03, -2.60643191e-03, 1.16635260e-03, 8.15185259e-03, 1.82290773e-02, 3.08983182e-02, 4.51608038e-02, 5.94769126e-02, 7.18919113e-02, 8.03888307e-02, 8.34165399e-02, 8.03888307e-02, 7.18919113e-02, 5.94769126e-02, 4.51608038e-02, 3.08983182e-02, 1.82290773e-02, 8.15185259e-03, 1.16635260e-03, -2.60643191e-03, -3.29238561e-03], [-7.68543266e-03, -7.63179286e-03, -4.08866637e-03, 3.27605236e-03, 1.45558215e-02, 2.94068040e-02, 4.68176355e-02, 6.49397159e-02, 7.72066272e-02, 8.50445368e-02, 8.77974692e-02, 8.50445368e-02, 7.72066272e-02, 6.49397159e-02, 4.68176355e-02, 2.94068040e-02, 1.45558215e-02, 3.27605236e-03, -4.08866637e-03, -7.63179286e-03, -7.68543266e-03], [-1.38078234e-02, -1.49011067e-02, -1.21731364e-02, -5.02168047e-03, 6.98177526e-03, 2.38268531e-02, 4.30419205e-02, 6.00041964e-02, 7.44541603e-02, 8.42939552e-02, 8.77989590e-02, 8.42939552e-02, 7.44541603e-02, 6.00041964e-02, 4.30419205e-02, 2.38268531e-02, 6.98177526e-03, -5.02168047e-03, -1.21731364e-02, -1.49011067e-02, -1.38078234e-02], [-2.13780396e-02, -2.42165379e-02, -2.30613142e-02, -1.70011475e-02, -5.15036128e-03, 1.25885635e-02, 3.24536739e-02, 5.25619351e-02, 7.05100243e-02, 8.31900906e-02, 8.78003567e-02, 8.31900906e-02, 7.05100243e-02, 5.25619351e-02, 3.24536739e-02, 1.25885635e-02, -5.15036128e-03, -1.70011475e-02, -2.30613142e-02, -2.42165379e-02, -2.13780396e-02], [-2.98882710e-02, -3.50862342e-02, -3.63793490e-02, -3.25716319e-02, -2.22546618e-02, -3.59274163e-03, 1.83064517e-02, 4.20112440e-02, 6.46115966e-02, 8.14746164e-02, 8.78016623e-02, 8.14746164e-02, 6.46115966e-02, 4.20112440e-02, 1.83064517e-02, -3.59274163e-03, -2.22546618e-02, -3.25716319e-02, -3.63793490e-02, -3.50862342e-02, -2.98882710e-02], [-3.85810679e-02, -4.66488633e-02, -5.12430987e-02, -5.10089462e-02, -4.20856023e-02, -2.36905234e-02, -6.33876287e-04, 2.66765430e-02, 5.53289928e-02, 7.86066125e-02, 8.78028757e-02, 7.86066125e-02, 5.53289928e-02, 2.66765430e-02, -6.33876287e-04, -2.36905234e-02, -4.20856023e-02, -5.10089462e-02, -5.12430987e-02, -4.66488633e-02, -3.85810679e-02], [-4.64803335e-02, -5.76615888e-02, -6.61458422e-02, -7.06512643e-02, -6.38427394e-02, -4.77258398e-02, -2.55483969e-02, 4.05840724e-03, 3.98470070e-02, 7.33053399e-02, 8.78039969e-02, 7.33053399e-02, 3.98470070e-02, 4.05840724e-03, -2.55483969e-02, -4.77258398e-02, -6.38427394e-02, -7.06512643e-02, -6.61458422e-02, -5.76615888e-02, -4.64803335e-02], [-5.25038299e-02, -6.66129442e-02, -7.90147081e-02, -8.87629178e-02, -8.59653118e-02, -7.42828398e-02, -5.64316505e-02, -2.87083225e-02, 1.25945312e-02, 6.19971667e-02, 8.78050260e-02, 6.19971667e-02, 1.25945312e-02, -2.87083225e-02, -5.64316505e-02, -7.42828398e-02, -8.59653118e-02, -8.87629178e-02, -7.90147081e-02, -6.66129442e-02, -5.25038299e-02], [-5.69779111e-02, -7.36791817e-02, -8.97495345e-02, -1.04799583e-01, -1.07737239e-01, -1.02875880e-01, -9.46568471e-02, -7.95630162e-02, -4.96285112e-02, 6.59954795e-03, 5.25569882e-02, 6.59954795e-03, -4.96285112e-02, -7.95630162e-02, -9.46568471e-02, -1.02875880e-01, -1.07737239e-01, -1.04799583e-01, -8.97495345e-02, -7.36791817e-02, -5.69779111e-02], [-5.90357675e-02, -7.69727119e-02, -9.48442826e-02, -1.12607620e-01, -1.18744885e-01, -1.18201834e-01, -1.17217017e-01, -1.15152899e-01, -1.09694433e-01, -8.82341332e-02, -1.61624035e-02, -8.82341332e-02, -1.09694433e-01, -1.15152899e-01, -1.17217017e-01, -1.18201834e-01, -1.18744885e-01, -1.12607620e-01, -9.48442826e-02, -7.69727119e-02, -5.90357675e-02], [-5.92189452e-02, -7.72680305e-02, -9.53051857e-02, -1.13322519e-01, -1.19770917e-01, -1.19670660e-01, -1.19486798e-01, -1.19092639e-01, -1.17989113e-01, -1.12555820e-01, -4.50009776e-02, -1.12555820e-01, -1.17989113e-01, -1.19092639e-01, -1.19486798e-01, -1.19670660e-01, -1.19770917e-01, -1.13322519e-01, -9.53051857e-02, -7.72680305e-02, -5.92189452e-02], [-5.79249958e-02, -7.51927112e-02, -9.20842554e-02, -1.08361430e-01, -1.12722790e-01, -1.09732675e-01, -1.04531672e-01, -9.44729544e-02, -7.23277773e-02, -2.05699911e-02, 3.58249631e-02, -2.05699911e-02, -7.23277773e-02, -9.44729544e-02, -1.04531672e-01, -1.09732675e-01, -1.12722790e-01, -1.08361430e-01, -9.20842554e-02, -7.51927112e-02, -5.79249958e-02], [-5.42527703e-02, -6.93641123e-02, -8.31684773e-02, -9.49114165e-02, -9.41989454e-02, -8.48645354e-02, -7.00894708e-02, -4.58286259e-02, -6.37563061e-03, 4.68887998e-02, 7.77968419e-02, 4.68887998e-02, -6.37563061e-03, -4.58286259e-02, -7.00894708e-02, -8.48645354e-02, -9.41989454e-02, -9.49114165e-02, -8.31684773e-02, -6.93641123e-02, -5.42527703e-02], [-4.82490057e-02, -5.99997941e-02, -6.91786120e-02, -7.44891242e-02, -6.73705808e-02, -5.13001284e-02, -2.84188057e-02, 3.60143816e-03, 4.47470123e-02, 8.58663851e-02, 1.04548354e-01, 8.58663851e-02, 4.47470123e-02, 3.60143816e-03, -2.84188057e-02, -5.13001284e-02, -6.73705808e-02, -7.44891242e-02, -6.91786120e-02, -5.99997941e-02, -4.82490057e-02], [-4.03203010e-02, -4.79063206e-02, -5.16352259e-02, -4.98707253e-02, -3.67295509e-02, -1.57342058e-02, 1.13668830e-02, 4.46551184e-02, 8.10450840e-02, 1.11780747e-01, 1.24226598e-01, 1.11780747e-01, 8.10450840e-02, 4.46551184e-02, 1.13668830e-02, -1.57342058e-02, -3.67295509e-02, -4.98707253e-02, -5.16352259e-02, -4.79063206e-02, -4.03203010e-02], [-3.10250239e-02, -3.40796094e-02, -3.22089254e-02, -2.37094100e-02, -5.85463114e-03, 1.77402761e-02, 4.57786845e-02, 7.69637052e-02, 1.07537652e-01, 1.30906328e-01, 1.39800436e-01, 1.30906328e-01, 1.07537652e-01, 7.69637052e-02, 4.57786845e-02, 1.77402761e-02, -5.85463114e-03, -2.37094100e-02, -3.22089254e-02, -3.40796094e-02, -3.10250239e-02], [-2.09301700e-02, -1.94475962e-02, -1.22970199e-02, 2.07296407e-03, 2.31516868e-02, 4.74574033e-02, 7.44743481e-02, 1.02380049e-01, 1.27776301e-01, 1.46003379e-01, 1.52690015e-01, 1.46003379e-01, 1.27776301e-01, 1.02380049e-01, 7.44743481e-02, 4.74574033e-02, 2.31516868e-02, 2.07296407e-03, -1.22970199e-02, -1.94475962e-02, -2.09301700e-02], [-1.05257992e-02, -4.74329696e-03, 7.12107274e-03, 2.63431361e-02, 4.93709790e-02, 7.31527220e-02, 9.82233938e-02, 1.22728059e-01, 1.43894925e-01, 1.58465026e-01, 1.63685984e-01, 1.58465026e-01, 1.43894925e-01, 1.22728059e-01, 9.82233938e-02, 7.31527220e-02, 4.93709790e-02, 2.63431361e-02, 7.12107274e-03, -4.74329696e-03, -1.05257992e-02], [-1.89098657e-04, 9.52392382e-03, 2.54577716e-02, 4.85730869e-02, 7.26048516e-02, 9.51726659e-02, 1.17988523e-01, 1.39380421e-01, 1.57176612e-01, 1.69076915e-01, 1.73274075e-01, 1.69076915e-01, 1.57176612e-01, 1.39380421e-01, 1.17988523e-01, 9.51726659e-02, 7.26048516e-02, 4.85730869e-02, 2.54577716e-02, 9.52392382e-03, -1.89098657e-04], [9.81732797e-03, 2.30419581e-02, 4.24234701e-02, 6.86213308e-02, 9.30164618e-02, 1.14050063e-01, 1.34620894e-01, 1.53304069e-01, 1.68420867e-01, 1.78321253e-01, 1.81774183e-01, 1.78321253e-01, 1.68420867e-01, 1.53304069e-01, 1.34620894e-01, 1.14050063e-01, 9.30164618e-02, 6.86213308e-02, 4.24234701e-02, 2.30419581e-02, 9.81732797e-03], [1.93290725e-02, 3.56493099e-02, 5.79271157e-02, 8.65611122e-02, 1.10914315e-01, 1.30317702e-01, 1.48798006e-01, 1.65173224e-01, 1.78147031e-01, 1.86513895e-01, 1.89408199e-01, 1.86513895e-01, 1.78147031e-01, 1.65173224e-01, 1.48798006e-01, 1.30317702e-01, 1.10914315e-01, 8.65611122e-02, 5.79271157e-02, 3.56493099e-02, 1.93290725e-02], [2.68168937e-02, 4.52356810e-02, 6.92261217e-02, 9.89630241e-02, 1.23093435e-01, 1.40640067e-01, 1.56998943e-01, 1.71215219e-01, 1.82297185e-01, 1.89360704e-01, 1.91789146e-01, 1.89360704e-01, 1.82297185e-01, 1.71215219e-01, 1.56998943e-01, 1.40640067e-01, 1.23093435e-01, 9.89630241e-02, 6.92261217e-02, 4.52356810e-02, 2.68168937e-02], [3.19403269e-02, 5.15051953e-02, 7.61032066e-02, 1.05705197e-01, 1.31722206e-01, 1.47466588e-01, 1.61892450e-01, 1.74235616e-01, 1.83735386e-01, 1.89735533e-01, 1.91788616e-01, 1.89735533e-01, 1.83735386e-01, 1.74235616e-01, 1.61892450e-01, 1.47466588e-01, 1.31722206e-01, 1.05705197e-01, 7.61032066e-02, 5.15051953e-02, 3.19403269e-02], [3.48604070e-02, 5.49292382e-02, 7.94274234e-02, 1.08149011e-01, 1.38923419e-01, 1.53070440e-01, 1.65849067e-01, 1.76646162e-01, 1.84871647e-01, 1.90029617e-01, 1.91787948e-01, 1.90029617e-01, 1.84871647e-01, 1.76646162e-01, 1.65849067e-01, 1.53070440e-01, 1.38923419e-01, 1.08149011e-01, 7.94274234e-02, 5.49292382e-02, 3.48604070e-02], [3.53402022e-02, 5.53653759e-02, 7.91965502e-02, 1.06486934e-01, 1.36563003e-01, 1.57713955e-01, 1.69087164e-01, 1.78598269e-01, 1.85784340e-01, 1.90264452e-01, 1.91787141e-01, 1.90264452e-01, 1.85784340e-01, 1.78598269e-01, 1.69087164e-01, 1.57713955e-01, 1.36563003e-01, 1.06486934e-01, 7.91965502e-02, 5.53653759e-02, 3.53402022e-02], [3.32889822e-02, 5.28319225e-02, 7.55769079e-02, 1.01077605e-01, 1.28592068e-01, 1.57023616e-01, 1.71766715e-01, 1.80199729e-01, 1.86528091e-01, 1.90454829e-01, 1.91786196e-01, 1.90454829e-01, 1.86528091e-01, 1.80199729e-01, 1.71766715e-01, 1.57023616e-01, 1.28592068e-01, 1.01077605e-01, 7.55769079e-02, 5.28319225e-02, 3.32889822e-02], [2.87295370e-02, 4.74613283e-02, 6.88388861e-02, 9.23568989e-02, 1.17254645e-01, 1.42483223e-01, 1.66695764e-01, 1.81528776e-01, 1.87141877e-01, 1.90611190e-01, 1.91785112e-01, 1.90611190e-01, 1.87141877e-01, 1.81528776e-01, 1.66695764e-01, 1.42483223e-01, 1.17254645e-01, 9.23568989e-02, 6.88388861e-02, 4.74613283e-02, 2.87295370e-02], [2.17650266e-02, 3.94568191e-02, 5.93023344e-02, 8.07720575e-02, 1.03124482e-01, 1.25394282e-01, 1.46405870e-01, 1.64828303e-01, 1.79288925e-01, 1.88553222e-01, 1.91747252e-01, 1.88553222e-01, 1.79288925e-01, 1.64828303e-01, 1.46405870e-01, 1.25394282e-01, 1.03124482e-01, 8.07720575e-02, 5.93023344e-02, 3.94568191e-02, 2.17650266e-02], [1.25495284e-02, 2.90572166e-02, 4.72972116e-02, 6.67423656e-02, 8.66951873e-02, 1.06290296e-01, 1.24520131e-01, 1.40293247e-01, 1.52531693e-01, 1.60303860e-01, 1.62970689e-01, 1.60303860e-01, 1.52531693e-01, 1.40293247e-01, 1.24520131e-01, 1.06290296e-01, 8.66951873e-02, 6.67423656e-02, 4.72972116e-02, 2.90572166e-02, 1.25495284e-02], [1.26441934e-03, 1.65114811e-02, 3.31390978e-02, 5.06407706e-02, 6.83765492e-02, 8.55839448e-02, 1.01408074e-01, 1.14955639e-01, 1.25373662e-01, 1.31946425e-01, 1.34193829e-01, 1.31946425e-01, 1.25373662e-01, 1.14955639e-01, 1.01408074e-01, 8.55839448e-02, 6.83765492e-02, 5.06407706e-02, 3.31390978e-02, 1.65114811e-02, 1.26441934e-03], [0.00000000e+00, 2.06213867e-03, 1.71162845e-02, 3.27888240e-02, 4.85026462e-02, 6.35932476e-02, 7.73387997e-02, 8.90069217e-02, 9.79166934e-02, 1.03509489e-01, 1.05416736e-01, 1.03509489e-01, 9.79166934e-02, 8.90069217e-02, 7.73387997e-02, 6.35932476e-02, 4.85026462e-02, 3.27888240e-02, 1.71162845e-02, 2.06213867e-03, 0.00000000e+00]] ) np.testing.assert_allclose( fd, fd_test, rtol=1e-4)
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)
def test_so6(): event_name = 'so6' magnitude = 7.2 dip = np.array([70]) rake = 135 width = np.array([15]) L = 80 fltx = np.array([0, 0]) flty = np.array([0, L]) zp = np.array([0]) # Convert to lat/lon proj = geo.utils.get_orthographic_projection(-122, -120, 39, 37) tlon,tlat = proj(fltx, flty, reverse = True) flt = fault.Fault.fromTrace(np.array([tlon[0]]), np.array([tlat[0]]), np.array([tlon[1]]), np.array([tlat[1]]), zp, width, dip, reference = 'rv4') x = np.linspace(-80, 80, 21) y = np.linspace(-50, 130, 21) site_x,site_y = np.meshgrid(x, y) slon,slat = proj(site_x, site_y, reverse = True) sdepth = np.zeros_like(slon) tmp = flt.getQuadrilaterals()[0] pp0 = Vector.fromPoint(point.Point(tmp[0].longitude, tmp[0].latitude, tmp[0].depth)) pp1 = Vector.fromPoint(point.Point(tmp[1].longitude, tmp[1].latitude, tmp[1].depth)) pp2 = Vector.fromPoint(point.Point(tmp[2].longitude, tmp[2].latitude, tmp[2].depth)) pp3 = Vector.fromPoint(point.Point(tmp[3].longitude, tmp[3].latitude, tmp[3].depth)) dxp = 10/L dyp = (width-5)/width mp0 = pp0 + (pp1 - pp0)*dxp mp1 = pp3 + (pp2 - pp3)*dxp rp = mp0 + (mp1 - mp0)*dyp epilat,epilon,epidepth = ecef2latlon(rp.x, rp.y, rp.z) epix,epiy = proj(epilon, epilat, reverse = False) event = {'lat': epilat, 'lon': epilon, 'depth':epidepth, 'mag': magnitude, 'id':'so6', 'locstring':'so6', 'type':'RV', 'timezone':'UTC'} event['time'] = ShakeDateTime.utcfromtimestamp(int(time.time())) event['created'] = ShakeDateTime.utcfromtimestamp(int(time.time())) fltlat = [a.latitude for a in flt.getQuadrilaterals()[0]] fltlon = [a.longitude for a in flt.getQuadrilaterals()[0]] fltlat = np.append(fltlat, fltlat[0]) fltlon = np.append(fltlon, fltlon[0]) fltx,flty = proj(fltlon, fltlat, reverse = False) source = Source(event, flt) source.setEventParam('rake', rake) test1 = Bayless2013(source, slat, slon, sdepth, T = 5) fd = test1.getFd() fd_test = np.array( [[ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, -8.92879772e-03, -1.74526918e-02, -2.22981746e-02, -2.34350450e-02, -2.13620062e-02, -1.72712346e-02, -1.29509613e-02, -1.02545064e-02, -1.03010185e-02, -1.28847597e-02, -1.66274727e-02, -1.96984070e-02, -2.05377743e-02, -1.81831337e-02, -1.21881814e-02, -2.64862879e-03, 0.00000000e+00, 0.00000000e+00], [ 0.00000000e+00, 0.00000000e+00, -8.73221519e-03, -2.21421374e-02, -3.18438939e-02, -3.71488270e-02, -3.76239913e-02, -3.35015951e-02, -2.61748968e-02, -1.83864728e-02, -1.34793002e-02, -1.36687799e-02, -1.85727143e-02, -2.55527671e-02, -3.14227568e-02, -3.38933995e-02, -3.19289607e-02, -2.53396980e-02, -1.45943649e-02, -3.71405488e-04, 0.00000000e+00], [ 0.00000000e+00, -2.54621422e-03, -2.11428566e-02, -3.68609103e-02, -4.87464747e-02, -5.56539037e-02, -5.64419387e-02, -5.05331157e-02, -3.52919381e-02, -2.18782050e-02, -1.40858125e-02, -1.47354546e-02, -2.35727189e-02, -3.74838465e-02, -4.75915414e-02, -5.13000399e-02, -4.87882409e-02, -4.05716321e-02, -2.77368254e-02, -1.13542729e-02, 0.00000000e+00], [ 0.00000000e+00, -1.21642958e-02, -3.33747360e-02, -5.21661817e-02, -6.74724509e-02, -7.77628842e-02, -8.00243748e-02, -6.42496853e-02, -4.38124530e-02, -1.97027426e-02, -1.45897731e-02, -1.07427056e-02, -3.08235222e-02, -4.82656988e-02, -6.67692677e-02, -7.35152908e-02, -6.85574283e-02, -5.71811573e-02, -4.12138780e-02, -2.20396726e-02, -6.24121310e-04], [ 0.00000000e+00, -2.00643401e-02, -4.39827328e-02, -6.62722434e-02, -8.60268414e-02, -1.01730306e-01, -9.86277741e-02, -9.82914922e-02, -5.22335876e-02, -1.54622435e-02, -1.57487554e-02, -3.06190808e-03, -4.81481586e-02, -8.92480491e-02, -8.63776477e-02, -9.98130440e-02, -8.95491230e-02, -7.33553695e-02, -5.34401725e-02, -3.11601812e-02, -7.33715103e-03], [ 0.00000000e+00, -2.50053614e-02, -5.11695772e-02, -7.65997026e-02, -1.00809054e-01, -1.22877573e-01, -1.18738178e-01, -1.55236782e-01, -7.45388001e-02, 1.92779182e-03, -1.94380016e-02, 1.94922939e-02, -7.66669920e-02, -1.53909722e-01, -1.10846875e-01, -1.19746768e-01, -1.07680300e-01, -8.59905101e-02, -6.22042294e-02, -3.71802472e-02, -1.13867485e-02], [ 0.00000000e+00, -2.63645827e-02, -5.37984901e-02, -8.11337022e-02, -1.08298371e-01, -1.35146441e-01, -1.34825430e-01, -1.85836050e-01, -1.10730875e-01, -3.18861095e-02, 4.14395701e-02, -1.52711946e-02, -1.31840763e-01, -1.96794707e-01, -1.33453212e-01, -1.34989129e-01, -1.17922385e-01, -9.21637323e-02, -6.58369237e-02, -3.91646838e-02, -1.22685698e-02], [ 0.00000000e+00, -2.64622244e-02, -5.40483999e-02, -8.16190336e-02, -1.09162854e-01, -1.36656677e-01, -1.37081504e-01, -1.89522811e-01, -1.17723634e-01, -4.88765748e-02, -5.04529015e-03, -5.76414497e-02, -1.45712183e-01, -2.03062804e-01, -1.36859828e-01, -1.37107390e-01, -1.19124650e-01, -9.28263279e-02, -6.61800709e-02, -3.93088682e-02, -1.22842049e-02], [ 0.00000000e+00, -2.58466495e-02, -5.24858827e-02, -7.86086164e-02, -1.03856343e-01, -1.27529509e-01, -1.23794779e-01, -1.68810613e-01, -8.22602627e-02, 1.74236964e-02, 9.38708725e-02, 4.23208284e-02, -8.46343723e-02, -1.70476759e-01, -1.17547884e-01, -1.24569752e-01, -1.11518670e-01, -8.84736806e-02, -6.38037151e-02, -3.81874381e-02, -1.19867610e-02], [ 0.00000000e+00, -2.42186547e-02, -4.84175525e-02, -7.09428614e-02, -9.07754575e-02, -1.06117824e-01, -9.50228292e-02, -1.29781980e-01, -3.08573454e-02, 7.39058739e-02, 1.30478117e-01, 8.28181149e-02, -2.70389535e-02, -1.20837502e-01, -8.02081725e-02, -9.70274506e-02, -9.35853383e-02, -7.77422806e-02, -5.77817530e-02, -3.53067886e-02, -1.12414659e-02], [ 0.00000000e+00, -2.16818717e-02, -4.22363856e-02, -5.96909893e-02, -7.24805224e-02, -7.81867829e-02, -6.11838569e-02, -9.05679744e-02, 9.95934969e-03, 1.07503875e-01, 1.52073917e-01, 1.05894634e-01, 8.68652263e-03, -7.98571818e-02, -4.16548658e-02, -6.40511838e-02, -6.99337160e-02, -6.26305633e-02, -4.89098800e-02, -3.09284566e-02, -1.00919381e-02], [ 0.00000000e+00, -1.84940182e-02, -3.47054606e-02, -4.65278129e-02, -5.22037664e-02, -4.93977115e-02, -2.95395230e-02, -5.82421092e-02, 3.91025654e-02, 1.29337956e-01, 1.67436703e-01, 1.21969296e-01, 3.20823547e-02, -5.00287386e-02, -9.22993907e-03, -3.27186625e-02, -4.52706958e-02, -4.57409325e-02, -3.84701291e-02, -2.55751405e-02, -8.64950254e-03], [ 0.00000000e+00, -1.49431380e-02, -2.65887341e-02, -3.29162158e-02, -3.22994323e-02, -2.29081781e-02, -2.60259636e-03, -3.29856530e-02, 6.02631314e-02, 1.45003704e-01, 1.79361264e-01, 1.34292814e-01, 4.88007115e-02, -2.82328554e-02, 1.64212421e-02, -5.72391847e-03, -2.23438861e-02, -2.90246794e-02, -2.76054402e-02, -1.97779758e-02, -7.03945406e-03], [ 0.00000000e+00, -1.12771143e-02, -1.84737590e-02, -1.98228664e-02, -1.40092305e-02, 1.84580818e-04, 1.95817303e-02, -1.32608487e-02, 7.62783168e-02, 1.57076433e-01, 1.89083905e-01, 1.44259188e-01, 6.15722813e-02, -1.17505212e-02, 3.65938109e-02, 1.66937711e-02, -2.18970818e-03, -1.35507683e-02, -1.70890527e-02, -1.39519424e-02, -5.37036892e-03], [ 0.00000000e+00, -7.67615215e-03, -1.07348257e-02, -7.75276739e-03, 2.22351695e-03, 1.98662250e-02, 3.77611177e-02, 2.42018661e-03, 8.89036172e-02, 1.66855206e-01, 1.97260700e-01, 1.52590263e-01, 7.17981256e-02, 1.18005972e-03, 5.26852303e-02, 3.51638855e-02, 1.51012176e-02, 2.69654076e-04, -7.33815554e-03, -8.36639665e-03, -3.72176313e-03], [ 0.00000000e+00, -4.50552324e-03, -4.32262850e-03, 1.73559158e-03, 1.42670366e-02, 3.35040699e-02, 4.97279358e-02, 1.85410528e-02, 9.39950666e-02, 1.46646579e-01, 9.13474746e-02, 1.37004651e-01, 7.74648339e-02, 1.59777072e-02, 6.25334939e-02, 4.74577418e-02, 2.72155518e-02, 1.06174952e-02, 3.94103899e-04, -3.68465400e-03, -2.19830733e-03], [ 0.00000000e+00, -1.74629916e-03, 5.44471813e-04, 8.22933499e-03, 2.15699287e-02, 4.04232250e-02, 5.69678048e-02, 5.52408259e-02, 9.04381272e-02, 1.08204635e-01, 9.14439984e-02, 1.06884511e-01, 8.17241884e-02, 5.55282924e-02, 6.78528399e-02, 5.47188925e-02, 3.35251483e-02, 1.69615982e-02, 5.72048628e-03, -8.81437278e-05, -7.36518436e-04], [ 0.00000000e+00, 4.07838765e-05, 3.63933766e-03, 1.20080876e-02, 2.51274691e-02, 4.25687176e-02, 6.25685606e-02, 7.33480475e-02, 8.37515545e-02, 9.52500287e-02, 9.15135660e-02, 9.66442834e-02, 8.66659913e-02, 8.10325633e-02, 7.18836713e-02, 5.45548434e-02, 3.55884875e-02, 2.00142359e-02, 8.71200201e-03, 2.04407846e-03, -6.53680674e-06], [ 0.00000000e+00, 2.40054729e-04, 4.44975227e-03, 1.27572519e-02, 2.49362989e-02, 4.03831326e-02, 5.80039988e-02, 7.61280192e-02, 8.37404162e-02, 8.89634569e-02, 9.15651607e-02, 9.13586235e-02, 8.83589144e-02, 8.27804032e-02, 6.75666471e-02, 5.00483249e-02, 3.36733366e-02, 1.96758691e-02, 9.00603204e-03, 2.18370401e-03, 0.00000000e+00], [ 0.00000000e+00, 0.00000000e+00, 2.78776980e-03, 1.05086036e-02, 2.13238822e-02, 3.45577738e-02, 4.91570145e-02, 6.36787133e-02, 7.63710088e-02, 8.54072310e-02, 8.92960200e-02, 8.75702197e-02, 8.07095447e-02, 6.97999389e-02, 5.63787286e-02, 4.20734776e-02, 2.83073312e-02, 1.61614525e-02, 6.56194125e-03, 1.00721924e-04, 0.00000000e+00], [ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 5.49667845e-03, 1.47563319e-02, 2.57955743e-02, 3.76689418e-02, 4.91861917e-02, 5.90108907e-02, 6.58478416e-02, 6.87018515e-02, 6.73174642e-02, 6.20270643e-02, 5.35456385e-02, 4.29400416e-02, 3.14129728e-02, 2.00795162e-02, 9.84001885e-03, 1.53992995e-03, 0.00000000e+00, 0.00000000e+00]] ) np.testing.assert_allclose(fd, fd_test, rtol=1e-4)
def test_ss3_move_hypo1(): magnitude = 7.2 dip = np.array([90]) rake = 180.0 width = np.array([15]) rupx = np.array([0, 0]) rupy = np.array([0, 80]) zp = np.array([0.0]) epix = np.array([1.0]) epiy = np.array([-1.0]) # Convert to lat/lon proj = geo.utils.get_orthographic_projection(-122, -120, 39, 37) tlon, tlat = proj(rupx, rupy, reverse=True) epilon, epilat = proj(epix, epiy, reverse=True) # Origin origin = Origin({'lat':epilat[0], 'lon':epilon[0], 'depth':-1, 'mag':magnitude, 'id':'ss3', 'rake':rake}) rup = rupture.QuadRupture.fromTrace( np.array([tlon[0]]), np.array([tlat[0]]), np.array([tlon[1]]), np.array([tlat[1]]), zp, width, dip, origin, reference='ss3') x = np.linspace(0, 20, 6) y = np.linspace(0, 90, 11) site_x, site_y = np.meshgrid(x, y) slon, slat = proj(site_x, site_y, reverse=True) deps = np.zeros_like(slon) test1 = Bayless2013(origin, rup, slat, slon, deps, T=1.0) phyp = copy.deepcopy(test1.phyp[0]) plat, plon, pdep = ecef2latlon(phyp.x, phyp.y, phyp.z) px, py = proj(plon, plat, reverse=False) np.testing.assert_allclose(plat, 38.004233219183604, rtol=1e-4) np.testing.assert_allclose(plon, -120.98636122402166, rtol=1e-4) np.testing.assert_allclose(pdep, 7.4999999989205968, rtol=1e-4) #--------------------------------------------------------------------------- # Also for multiple segments #--------------------------------------------------------------------------- dip = np.array([90., 90., 90.]) rake = 180.0 width = np.array([15., 15., 10.]) rupx = np.array([0., 0., 10., 20.]) rupy = np.array([0., 20., 60., 80.]) zp = np.array([0., 0., 0.]) epix = np.array([0.]) epiy = np.array([0.]) # Convert to lat/lon proj = geo.utils.get_orthographic_projection(-122, -120, 39, 37) tlon, tlat = proj(rupx, rupy, reverse=True) epilon, epilat = proj(epix, epiy, reverse=True) rup = rupture.QuadRupture.fromTrace( np.array(tlon[0:3]), np.array(tlat[0:3]), np.array(tlon[1:4]), np.array(tlat[1:4]), zp, width, dip, origin, reference='') event = {'lat': epilat[0], 'lon': epilon[0], 'depth': 1.0, 'mag': magnitude, 'id': '', 'locstring': 'test', 'type': 'SS', 'timezone': 'UTC'} event['time'] = ShakeDateTime.utcfromtimestamp(int(time.time())) event['created'] = ShakeDateTime.utcfromtimestamp(int(time.time())) x = np.linspace(0, 20, 6) y = np.linspace(0, 90, 11) site_x, site_y = np.meshgrid(x, y) slon, slat = proj(site_x, site_y, reverse=True) deps = np.zeros_like(slon) origin = Origin(event) origin.rake = rake test1 = Bayless2013(origin, rup, slat, slon, deps, T=1.0) # 1st pseudo-hyp phyp = copy.deepcopy(test1.phyp[0]) plat, plon, pdep = ecef2latlon(phyp.x, phyp.y, phyp.z) px, py = proj(plon, plat, reverse=False) np.testing.assert_allclose(plat, 38.004233219183604, rtol=1e-4) np.testing.assert_allclose(plon, -120.98636122402166, rtol=1e-4) np.testing.assert_allclose(pdep, 7.4999999989205968, rtol=1e-4) # 2nd pseudo-hyp phyp = copy.deepcopy(test1.phyp[1]) plat, plon, pdep = ecef2latlon(phyp.x, phyp.y, phyp.z) px, py = proj(plon, plat, reverse=False) np.testing.assert_allclose(plat, 38.184097835787796, rtol=1e-4) np.testing.assert_allclose(plon, -120.98636122402166, rtol=1e-4) np.testing.assert_allclose(pdep, 7.4999999989103525, rtol=1e-4) # 3rd pseudo-hyp phyp = copy.deepcopy(test1.phyp[2]) plat, plon, pdep = ecef2latlon(phyp.x, phyp.y, phyp.z) px, py = proj(plon, plat, reverse=False) np.testing.assert_allclose(plat, 38.543778594535752, rtol=1e-4) np.testing.assert_allclose(plon, -120.87137783362499, rtol=1e-4) np.testing.assert_allclose(pdep, 4.9999999995063993, rtol=1e-4)
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')