def test_plot_fault_wire3d(): ff = os.path.join(shakedir, "tests/data/eventdata/hayward_RC_HN_HS_HE_Shaw09Mod_GEOL.txt") flt = Fault.readFaultFile(ff) fig = plt.figure() ax = fig.add_subplot(111, projection='3d') plot_fault_wire3d(flt, ax) return fig
def test_plot_fault_wire3d(): ff = os.path.join( shakedir, "tests/data/eventdata/hayward_RC_HN_HS_HE_Shaw09Mod_GEOL.txt") flt = Fault.readFaultFile(ff) fig = plt.figure() ax = fig.add_subplot(111, projection='3d') plot_fault_wire3d(flt, ax) return fig
def _test_correct(): #this fault should parse correctly fault_text = """#SOURCE: Barka, A., H. S. Akyz, E. Altunel, G. Sunal, Z. Akir, A. Dikbas, B. Yerli, R. Armijo, B. Meyer, J. B. d. Chabalier, T. Rockwell, J. R. Dolan, R. Hartleb, T. Dawson, S. Christofferson, A. Tucker, T. Fumal, R. Langridge, H. Stenner, W. Lettis, J. Bachhuber, and W. Page (2002). The Surface Rupture and Slip Distribution of the 17 August 1999 Izmit Earthquake (M 7.4), North Anatolian Fault, Bull. Seism. Soc. Am. 92, 43-60. 40.70985 29.33760 0 40.72733 29.51528 0 40.72933 29.51528 20 40.71185 29.33760 20 40.70985 29.33760 0 > 40.70513 29.61152 0 40.74903 29.87519 0 40.75103 29.87519 20 40.70713 29.61152 20 40.70513 29.61152 0 > 40.72582 29.88662 0 40.72336 30.11126 0 40.73432 30.19265 0 40.73632 30.19265 20 40.72536 30.11126 20 40.72782 29.88662 20 40.72582 29.88662 0 > 40.71210 30.30494 0 40.71081 30.46540 0 40.70739 30.56511 0 40.70939 30.56511 20 40.71281 30.46540 20 40.71410 30.30494 20 40.71210 30.30494 0 > 40.71621 30.57658 0 40.70068 30.63731 0 40.70268 30.63731 20 40.71821 30.57658 20 40.71621 30.57658 0 > 40.69947 30.72900 0 40.79654 30.93655 0 40.79854 30.93655 20 40.70147 30.72900 20 40.69947 30.72900 0 > 40.80199 30.94688 0 40.84501 31.01799 0 40.84701 31.01799 20 40.80399 30.94688 20 40.80199 30.94688 0""" cbuf = io.StringIO(fault_text) fault = Fault.readFaultFile(cbuf)
def _test_northridge(): #this should fail! fault_text = """ # Source: Wald, D. J., T. H. Heaton, and K. W. Hudnut (1996). The Slip History of the 1994 Northridge, California, Earthquake Determined from Strong-Motion, Teleseismic, GPS, and Leveling Data, Bull. Seism. Soc. Am. 86, S49-S70. 34.315 -118.421 5.000 34.401 -118.587 5.000 34.261 -118.693 20.427 34.175 -118.527 20.427 34.315 -118.421 5.000 """ cbuf = io.StringIO(fault_text) fault = Fault.readFaultFile(cbuf) quad = fault.getQuadrilaterals()[0] topdist = quad[0].distance(quad[1]) fault.multiplyFaultLength(2.0) quad = fault.getQuadrilaterals()[0] topdist2 = quad[0].distance(quad[1]) x = 1
def _test_incorrect(): fault_text = """# Source: Ji, C., D. V. Helmberger, D. J. Wald, and K.-F. Ma (2003). Slip history and dynamic implications of the 1999 Chi-Chi, Taiwan, earthquake, J. Geophys. Res. 108, 2412, doi:10.1029/2002JB001764. 24.27980 120.72300 0 24.05000 121.00000 17 24.07190 121.09300 17 24.33120 121.04300 17 24.27980 120.72300 0 > 24.27980 120.72300 0 23.70000 120.68000 0 23.60400 120.97200 17 24.05000 121.00000 17 24.27980 120.72300 0 > 23.60400 120.97200 17 23.70000 120.68000 0 23.58850 120.58600 0 23.40240 120.78900 17 23.60400 120.97200 17""" cbuf = io.StringIO(fault_text) fault = Fault.readFaultFile(cbuf)
def test_incorrect(): fault_text = """# Source: Ji, C., D. V. Helmberger, D. J. Wald, and K.-F. Ma (2003). Slip history and dynamic implications of the 1999 Chi-Chi, Taiwan, earthquake, J. Geophys. Res. 108, 2412, doi:10.1029/2002JB001764. 24.27980 120.72300 0 24.05000 121.00000 17 24.07190 121.09300 17 24.33120 121.04300 17 24.27980 120.72300 0 > 24.27980 120.72300 0 23.70000 120.68000 0 23.60400 120.97200 17 24.05000 121.00000 17 24.27980 120.72300 0 > 23.60400 120.97200 17 23.70000 120.68000 0 23.58850 120.58600 0 23.40240 120.78900 17 23.60400 120.97200 17""" cbuf = io.StringIO(fault_text) with pytest.raises(ShakeMapException): fault = Fault.readFaultFile(cbuf)
def test_northridge(): fault_text = """ # Source: Wald, D. J., T. H. Heaton, and K. W. Hudnut (1996). The Slip History of the 1994 Northridge, California, Earthquake Determined from Strong-Motion, Teleseismic, GPS, and Leveling Data, Bull. Seism. Soc. Am. 86, S49-S70. 34.315 -118.421 5.000 34.401 -118.587 5.000 34.261 -118.693 20.427 34.175 -118.527 20.427 34.315 -118.421 5.000 """ cbuf = io.StringIO(fault_text) fault = Fault.readFaultFile(cbuf) strike = fault.getStrike() np.testing.assert_allclose(strike, 122.06408, atol=0.001) dip = fault.getDip() np.testing.assert_allclose(dip, 40.20979, atol=0.001) L = fault.getFaultLength() np.testing.assert_allclose(L, 17.99198, atol=0.001) W = fault.getWidth() np.testing.assert_allclose(W, 23.93699, atol=0.001) nq = fault.getNumQuads() np.testing.assert_allclose(nq, 1) ns = fault.getNumSegments() np.testing.assert_allclose(ns, 1) sind = fault._getSegmentIndex() np.testing.assert_allclose(sind, [0]) ztor = fault.getTopOfRupture() np.testing.assert_allclose(ztor, 5, atol=0.001) itl = fault.getIndividualTopLengths() np.testing.assert_allclose(itl, 17.9919846, atol=0.001) iw = fault.getIndividualWidths() np.testing.assert_allclose(iw, 23.93699668, atol=0.001) lats = fault.getLats() lats_d = np.array([34.315, 34.401, 34.261, 34.175, 34.315]) np.testing.assert_allclose(lats, lats_d, atol=0.001) lons = fault.getLons() lons_d = np.array([-118.421, -118.587, -118.693, -118.527, -118.421]) np.testing.assert_allclose(lons, lons_d, atol=0.001)
def _test_intensity(): datadir = os.path.abspath(os.path.join( homedir, '..', 'data', 'eventdata', 'northridge')) shakefile = os.path.join(datadir, 'northridge_grid.xml') topofile = os.path.join(datadir, 'northridge_topo.grd') faultfile = os.path.join(datadir, 'northridge_fault.txt') cityfile = os.path.join(datadir, 'northridge_cities.txt') coastfile = os.path.join(datadir, 'northridge_coastline.json') countryfile = os.path.join(datadir, 'northridge_countries.json') statefile = os.path.join(datadir, 'northridge_states.json') lakefile = os.path.join(datadir, 'northridge_lakes.json') oceanfile = os.path.join(datadir, 'northridge_ocean.json') stationfile = os.path.join(datadir, 'northridge_stations.db') roadfile = os.path.join(datadir, 'northridge_roads.json') tancptfile = os.path.join(shakedir, 'shakemap', 'mapping', 'tan.cpt') shakecptfile = os.path.join( shakedir, 'shakemap', 'mapping', 'shakecpt.cpt') layerdict = {'coast': coastfile, 'ocean': oceanfile, 'lake': lakefile, 'country': countryfile, 'roads': roadfile, 'state': statefile} tancolormap = ColorPalette.fromPreset('shaketopo') shakecolormap = ColorPalette.fromPreset('mmi') cities = BasemapCities.loadFromCSV(cityfile) shakemap = ShakeGrid.load(shakefile, adjust='res') stations = StationList(stationfile) fault = Fault.readFaultFile(faultfile) edict = shakemap.getEventDict() eventdict = {'lat': edict['lat'], 'lon': edict['lon'], 'depth': edict['depth'], 'mag': edict['magnitude'], 'time': edict['event_timestamp']} source = Source(eventdict, fault) maker = MapMaker(shakemap, topofile, stations, fault, layerdict, source, cities) # draw intensity map outfolder = os.path.expanduser('~') maker.setIntensityLayer('mmi') maker.setIntensityGMTColorMap(shakecolormap) intensity_map = maker.drawIntensityMap(outfolder) print('Intensity map saved as: %s' % intensity_map) # draw contour maps maker.setContourGMTColorMap(tancolormap) # Draw pgv contours maker.setContourLayer('pgv') contour_pgv_map = maker.drawContourMap(outfolder) print('PGV contour map saved as: %s' % contour_pgv_map) # Draw pga contours maker.setContourLayer('pga') contour_pga_map = maker.drawContourMap(outfolder) print('PGA contour map saved as: %s' % contour_pga_map) # Draw psa0.3 contours maker.setContourLayer('psa03') contour_psa03_map = maker.drawContourMap(outfolder) print('PSA0.3 contour map saved as: %s' % contour_psa03_map) # Draw psa1.0 contours maker.setContourLayer('psa10') contour_psa10_map = maker.drawContourMap(outfolder) print('PSA1.0 contour map saved as: %s' % contour_psa10_map) # Draw psa3.0 contours maker.setContourLayer('psa30') contour_psa30_map = maker.drawContourMap(outfolder) print('PSA3.0 contour map saved as: %s' % contour_psa30_map)
def parse_complicated_fault(): fault_text = """#SOURCE: Barka, A., H. S. Akyz, E. Altunel, G. Sunal, Z. Akir, A. Dikbas, B. Yerli, R. Armijo, B. Meyer, J. B. d. Chabalier, T. Rockwell, J. R. Dolan, R. Hartleb, T. Dawson, S. Christofferson, A. Tucker, T. Fumal, R. Langridge, H. Stenner, W. Lettis, J. Bachhuber, and W. Page (2002). The Surface Rupture and Slip Distribution of the 17 August 1999 Izmit Earthquake (M 7.4), North Anatolian Fault, Bull. Seism. Soc. Am. 92, 43-60. 40.70985 29.33760 0 40.72733 29.51528 0 40.72933 29.51528 20 40.71185 29.33760 20 40.70985 29.33760 0 > 40.70513 29.61152 0 40.74903 29.87519 0 40.75103 29.87519 20 40.70713 29.61152 20 40.70513 29.61152 0 > 40.72582 29.88662 0 40.72336 30.11126 0 40.73432 30.19265 0 40.73632 30.19265 20 40.72536 30.11126 20 40.72782 29.88662 20 40.72582 29.88662 0 > 40.71210 30.30494 0 40.71081 30.46540 0 40.70739 30.56511 0 40.70939 30.56511 20 40.71281 30.46540 20 40.71410 30.30494 20 40.71210 30.30494 0 > 40.71621 30.57658 0 40.70068 30.63731 0 40.70268 30.63731 20 40.71821 30.57658 20 40.71621 30.57658 0 > 40.69947 30.72900 0 40.79654 30.93655 0 40.79854 30.93655 20 40.70147 30.72900 20 40.69947 30.72900 0 > 40.80199 30.94688 0 40.84501 31.01799 0 40.84701 31.01799 20 40.80399 30.94688 20 40.80199 30.94688 0""" cbuf = io.StringIO(fault_text) fault = Fault.readFaultFile(cbuf) strike = fault.getStrike() np.testing.assert_allclose(strike, -100.464330, atol=0.001) dip = fault.getDip() np.testing.assert_allclose(dip, 89.3985, atol=0.001) L = fault.getFaultLength() np.testing.assert_allclose(L, 119.5578, atol=0.001) W = fault.getWidth() np.testing.assert_allclose(W, 20.001, atol=0.001) nq = fault.getNumQuads() np.testing.assert_allclose(nq, 9) ns = fault.getNumSegments() np.testing.assert_allclose(ns, 7) sind = fault._getSegmentIndex() np.testing.assert_allclose(sind, [0, 1, 2, 2, 3, 3, 4, 5, 6]) ztor = fault.getTopOfRupture() np.testing.assert_allclose(ztor, 0, atol=0.001) itl = fault.getIndividualTopLengths() itl_d = np.array([15.13750778, 22.80237887, 18.98053425, 6.98263853, 13.55978731, 8.43444811, 5.41399812, 20.57788056, 7.66869463]) np.testing.assert_allclose(itl, itl_d, atol=0.001) iw = fault.getIndividualWidths() iw_d = np.array([20.00122876, 20.00122608, 20.00120173, 20.00121028, 20.00121513, 20.00121568, 20.00107293, 20.00105498, 20.00083348]) np.testing.assert_allclose(iw, iw_d, atol=0.001) lats = fault.getLats() lats_d = np.array([40.70985, 40.72733, 40.72933, 40.71185, 40.70985, np.nan, 40.70513, 40.74903, 40.75103, 40.70713, 40.70513, np.nan, 40.72582, 40.72336, 40.73432, 40.73632, 40.72536, 40.72782, 40.72582, np.nan, 40.7121, 40.71081, 40.70739, 40.70939, 40.71281, 40.7141, 40.7121, np.nan, 40.71621, 40.70068, 40.70268, 40.71821, 40.71621, np.nan, 40.69947, 40.79654, 40.79854, 40.70147, 40.69947, np.nan, 40.80199, 40.84501, 40.84701, 40.80399, 40.80199]) np.testing.assert_allclose(lats, lats_d, atol=0.001) lons = fault.getLons() lons_d = np.array([29.3376, 29.51528, 29.51528, 29.3376, 29.3376, np.nan, 29.61152, 29.87519, 29.87519, 29.61152, 29.61152, np.nan, 29.88662, 30.11126, 30.19265, 30.19265, 30.11126, 29.88662, 29.88662, np.nan, 30.30494, 30.4654, 30.56511, 30.56511, 30.4654, 30.30494, 30.30494, np.nan, 30.57658, 30.63731, 30.63731, 30.57658, 30.57658, np.nan, 30.729, 30.93655, 30.93655, 30.729, 30.729, np.nan, 30.94688, 31.01799, 31.01799, 30.94688, 30.94688]) np.testing.assert_allclose(lons, lons_d, atol=0.001)
def parse_complicated_fault(): fault_text = """#SOURCE: Barka, A., H. S. Akyz, E. Altunel, G. Sunal, Z. Akir, A. Dikbas, B. Yerli, R. Armijo, B. Meyer, J. B. d. Chabalier, T. Rockwell, J. R. Dolan, R. Hartleb, T. Dawson, S. Christofferson, A. Tucker, T. Fumal, R. Langridge, H. Stenner, W. Lettis, J. Bachhuber, and W. Page (2002). The Surface Rupture and Slip Distribution of the 17 August 1999 Izmit Earthquake (M 7.4), North Anatolian Fault, Bull. Seism. Soc. Am. 92, 43-60. 40.70985 29.33760 0 40.72733 29.51528 0 40.72933 29.51528 20 40.71185 29.33760 20 40.70985 29.33760 0 > 40.70513 29.61152 0 40.74903 29.87519 0 40.75103 29.87519 20 40.70713 29.61152 20 40.70513 29.61152 0 > 40.72582 29.88662 0 40.72336 30.11126 0 40.73432 30.19265 0 40.73632 30.19265 20 40.72536 30.11126 20 40.72782 29.88662 20 40.72582 29.88662 0 > 40.71210 30.30494 0 40.71081 30.46540 0 40.70739 30.56511 0 40.70939 30.56511 20 40.71281 30.46540 20 40.71410 30.30494 20 40.71210 30.30494 0 > 40.71621 30.57658 0 40.70068 30.63731 0 40.70268 30.63731 20 40.71821 30.57658 20 40.71621 30.57658 0 > 40.69947 30.72900 0 40.79654 30.93655 0 40.79854 30.93655 20 40.70147 30.72900 20 40.69947 30.72900 0 > 40.80199 30.94688 0 40.84501 31.01799 0 40.84701 31.01799 20 40.80399 30.94688 20 40.80199 30.94688 0""" cbuf = io.StringIO(fault_text) fault = Fault.readFaultFile(cbuf) strike = fault.getStrike() np.testing.assert_allclose(strike, -100.464330, atol=0.001) dip = fault.getDip() np.testing.assert_allclose(dip, 89.3985, atol=0.001) L = fault.getFaultLength() np.testing.assert_allclose(L, 119.5578, atol=0.001) W = fault.getWidth() np.testing.assert_allclose(W, 20.001, atol=0.001) nq = fault.getNumQuads() np.testing.assert_allclose(nq, 9) ns = fault.getNumSegments() np.testing.assert_allclose(ns, 7) sind = fault._getSegmentIndex() np.testing.assert_allclose(sind, [0, 1, 2, 2, 3, 3, 4, 5, 6]) ztor = fault.getTopOfRupture() np.testing.assert_allclose(ztor, 0, atol=0.001) itl = fault.getIndividualTopLengths() itl_d = np.array([ 15.13750778, 22.80237887, 18.98053425, 6.98263853, 13.55978731, 8.43444811, 5.41399812, 20.57788056, 7.66869463 ]) np.testing.assert_allclose(itl, itl_d, atol=0.001) iw = fault.getIndividualWidths() iw_d = np.array([ 20.00122876, 20.00122608, 20.00120173, 20.00121028, 20.00121513, 20.00121568, 20.00107293, 20.00105498, 20.00083348 ]) np.testing.assert_allclose(iw, iw_d, atol=0.001) lats = fault.getLats() lats_d = np.array([ 40.70985, 40.72733, 40.72933, 40.71185, 40.70985, np.nan, 40.70513, 40.74903, 40.75103, 40.70713, 40.70513, np.nan, 40.72582, 40.72336, 40.73432, 40.73632, 40.72536, 40.72782, 40.72582, np.nan, 40.7121, 40.71081, 40.70739, 40.70939, 40.71281, 40.7141, 40.7121, np.nan, 40.71621, 40.70068, 40.70268, 40.71821, 40.71621, np.nan, 40.69947, 40.79654, 40.79854, 40.70147, 40.69947, np.nan, 40.80199, 40.84501, 40.84701, 40.80399, 40.80199 ]) np.testing.assert_allclose(lats, lats_d, atol=0.001) lons = fault.getLons() lons_d = np.array([ 29.3376, 29.51528, 29.51528, 29.3376, 29.3376, np.nan, 29.61152, 29.87519, 29.87519, 29.61152, 29.61152, np.nan, 29.88662, 30.11126, 30.19265, 30.19265, 30.11126, 29.88662, 29.88662, np.nan, 30.30494, 30.4654, 30.56511, 30.56511, 30.4654, 30.30494, 30.30494, np.nan, 30.57658, 30.63731, 30.63731, 30.57658, 30.57658, np.nan, 30.729, 30.93655, 30.93655, 30.729, 30.729, np.nan, 30.94688, 31.01799, 31.01799, 30.94688, 30.94688 ]) np.testing.assert_allclose(lons, lons_d, atol=0.001)
def _test_intensity(): datadir = os.path.abspath( os.path.join(homedir, '..', 'data', 'eventdata', 'northridge')) shakefile = os.path.join(datadir, 'northridge_grid.xml') topofile = os.path.join(datadir, 'northridge_topo.grd') faultfile = os.path.join(datadir, 'northridge_fault.txt') cityfile = os.path.join(datadir, 'northridge_cities.txt') coastfile = os.path.join(datadir, 'northridge_coastline.json') countryfile = os.path.join(datadir, 'northridge_countries.json') statefile = os.path.join(datadir, 'northridge_states.json') lakefile = os.path.join(datadir, 'northridge_lakes.json') oceanfile = os.path.join(datadir, 'northridge_ocean.json') stationfile = os.path.join(datadir, 'northridge_stations.db') roadfile = os.path.join(datadir, 'northridge_roads.json') tancptfile = os.path.join(shakedir, 'shakemap', 'mapping', 'tan.cpt') shakecptfile = os.path.join(shakedir, 'shakemap', 'mapping', 'shakecpt.cpt') layerdict = { 'coast': coastfile, 'ocean': oceanfile, 'lake': lakefile, 'country': countryfile, 'roads': roadfile, 'state': statefile } tancolormap = GMTColorMap.loadFromCPT(tancptfile) shakecolormap = GMTColorMap.loadFromCPT(shakecptfile) cities = BasemapCities.loadFromCSV(cityfile) shakemap = ShakeGrid.load(shakefile, adjust='res') stations = StationList(stationfile) fault = Fault.readFaultFile(faultfile) edict = shakemap.getEventDict() eventdict = { 'lat': edict['lat'], 'lon': edict['lon'], 'depth': edict['depth'], 'mag': edict['magnitude'], 'time': edict['event_timestamp'] } source = Source(eventdict, fault) maker = MapMaker(shakemap, topofile, stations, fault, layerdict, source, cities) # draw intensity map outfolder = os.path.expanduser('~') maker.setIntensityLayer('mmi') maker.setIntensityGMTColorMap(shakecolormap) intensity_map = maker.drawIntensityMap(outfolder) print('Intensity map saved as: %s' % intensity_map) # draw contour maps maker.setContourGMTColorMap(tancolormap) # Draw pgv contours maker.setContourLayer('pgv') contour_pgv_map = maker.drawContourMap(outfolder) print('PGV contour map saved as: %s' % contour_pgv_map) # Draw pga contours maker.setContourLayer('pga') contour_pga_map = maker.drawContourMap(outfolder) print('PGA contour map saved as: %s' % contour_pga_map) # Draw psa0.3 contours maker.setContourLayer('psa03') contour_psa03_map = maker.drawContourMap(outfolder) print('PSA0.3 contour map saved as: %s' % contour_psa03_map) # Draw psa1.0 contours maker.setContourLayer('psa10') contour_psa10_map = maker.drawContourMap(outfolder) print('PSA1.0 contour map saved as: %s' % contour_psa10_map) # Draw psa3.0 contours maker.setContourLayer('psa30') contour_psa30_map = maker.drawContourMap(outfolder) print('PSA3.0 contour map saved as: %s' % contour_psa30_map)