def test_sample_number_of_occurrences(self): time_span = 40 rate = 0.05 num_samples = 8000 tom = PoissonTOM(time_span) numpy.random.seed(31) mean = sum(tom.sample_number_of_occurrences(rate) for i in range(num_samples)) / float(num_samples) self.assertAlmostEqual(mean, rate * time_span, delta=1e-3)
def test_get_probability_no_exceedance(self): time_span = 50. rate = 0.01 poes = numpy.array([[0.9, 0.8, 0.7], [0.6, 0.5, 0.4]]) tom = PoissonTOM(time_span) pne = tom.get_probability_no_exceedance(rate, poes) numpy.testing.assert_allclose( pne, numpy.array([[0.6376282, 0.6703200, 0.7046881], [0.7408182, 0.7788008, 0.8187308]]) )
def _expected_simple(self): incr_mfd = mfd.EvenlyDiscretizedMFD(min_mag=5.0, bin_width=0.1, occurrence_rates=[ 0.0010614989, 8.8291627E-4, 7.3437777E-4, 6.108288E-4, 5.080653E-4 ]) simple = source.SimpleFaultSource( source_id="3", name="Mount Diablo Thrust", tectonic_region_type="Active Shallow Crust", mfd=incr_mfd, rupture_mesh_spacing=self.rupture_mesh_spacing, magnitude_scaling_relationship=scalerel.WC1994(), rupture_aspect_ratio=1.5, upper_seismogenic_depth=10.0, lower_seismogenic_depth=20.0, fault_trace=geo.Line([ geo.Point(-121.82290, 37.73010), geo.Point(-122.03880, 37.87710) ]), dip=45.0, rake=30.0, temporal_occurrence_model=PoissonTOM(50.), hypo_list=numpy.array([[0.25, 0.25, 0.3], [0.75, 0.75, 0.7]]), slip_list=numpy.array([[90, 0.7], [135, 0.3]])) return simple
def make_point_source(lon=1.2, lat=3.4, **kwargs): default_arguments = { 'source_id': 'source_id', 'name': 'source name', 'tectonic_region_type': TRT.SUBDUCTION_INTRASLAB, 'mfd': TruncatedGRMFD(a_val=1, b_val=2, min_mag=3, max_mag=5, bin_width=1), 'location': Point(lon, lat, 5.6), 'nodal_plane_distribution': PMF([(1, NodalPlane(1, 2, 3))]), 'hypocenter_distribution': PMF([(1, 4)]), 'upper_seismogenic_depth': 1.3, 'lower_seismogenic_depth': 4.9, 'magnitude_scaling_relationship': PeerMSR(), 'rupture_aspect_ratio': 1.333, 'rupture_mesh_spacing': 1.234, 'temporal_occurrence_model': PoissonTOM(50.) } default_arguments.update(kwargs) kwargs = default_arguments ps = PointSource(**kwargs) assert_pickleable(ps) return ps
def test_Pago_VeianoMontaguto(self): # regression test fault_trace = Line([Point(15.2368, 41.1594), Point(15.1848, 41.1644), Point(15.1327, 41.1694), Point(15.0807, 41.1745), Point(15.0286, 41.1795), Point(14.9765, 41.1846), Point(14.9245, 41.1896), Point(14.8724, 41.1946), Point(14.8204, 41.1997)]) mfd = EvenlyDiscretizedMFD(min_mag=6.9, bin_width=0.2, occurrence_rates=[1.0]) dip = 70.0 upper_seismogenic_depth = 11.0 lower_seismogenic_depth = 25.0 rake = -130 scalerel = WC1994() rupture_mesh_spacing = 5 rupture_aspect_ratio = 1 tom = PoissonTOM(10) fault = SimpleFaultSource( 'ITCS057', 'Pago Veiano-Montaguto', TRT.ACTIVE_SHALLOW_CRUST, mfd, rupture_mesh_spacing, scalerel, rupture_aspect_ratio, tom, upper_seismogenic_depth, lower_seismogenic_depth, fault_trace, dip, rake ) self.assertEqual(len(list(fault.iter_ruptures())), 1)
def make_rupture(self): # Create the rupture surface. upper_seismogenic_depth = 3. lower_seismogenic_depth = 15. dip = 90. mesh_spacing = 1. fault_trace_start = Point(28.531397, 40.8790859336) fault_trace_end = Point(28.85, 40.9) fault_trace = Line([fault_trace_start, fault_trace_end]) default_arguments = { 'mag': 6.5, 'rake': 180., 'tectonic_region_type': const.TRT.STABLE_CONTINENTAL, 'hypocenter': Point(28.709146553353872, 40.890863701462457, 11.0), 'surface': SimpleFaultSurface.from_fault_data(fault_trace, upper_seismogenic_depth, lower_seismogenic_depth, dip=dip, mesh_spacing=mesh_spacing), 'rupture_slip_direction': 0., 'occurrence_rate': 0.01, 'temporal_occurrence_model': PoissonTOM(50) } kwargs = default_arguments rupture = ParametricProbabilisticRupture(**kwargs) return rupture
class _BaseFaultSourceTestCase(unittest.TestCase): SOURCE_ID = NAME = 'test-source' TRT = 'Active Shallow Crust' STRIKE = 0.0 DIP = 90.0 RAKE = 0 MIN_MAG = 5.0 BIN_WIDTH = 0.1 RATES = [0.3, 0.2, 0.1] CORNER_LONS = numpy.array([-1., 1., -1., 1.]) CORNER_LATS = numpy.array([0., 0., 0., 0.]) CORNER_DEPTHS = numpy.array([0., 0., 10., 10.]) MESH_SPACING = 1.0 TOM = PoissonTOM(50.0) def _make_source(self): points = [ Point(lon, lat, depth) for lon, lat, depth in zip( self.CORNER_LONS, self.CORNER_LATS, self.CORNER_DEPTHS) ] source = CharacteristicFaultSource( source_id=self.SOURCE_ID, name=self.NAME, tectonic_region_type=self.TRT, mfd=EvenlyDiscretizedMFD(self.MIN_MAG, self.BIN_WIDTH, self.RATES), temporal_occurrence_model=self.TOM, surface=PlanarSurface(self.MESH_SPACING, self.STRIKE, self.DIP, points[0], points[1], points[3], points[2]), rake=self.RAKE) assert_pickleable(source) return source
def test(self): sitecol = SiteCollection([Site(Point(-65.13490, 0.0), vs30=760., z1pt0=48.0, z2pt5=0.607, vs30measured=True)]) mfd = ArbitraryMFD([6.0], [0.01604252]) trace = Line([Point(-65.0000, -0.11240), Point(-65.000, 0.11240)]) # 1.0 km Mesh Spacing mesh_spacing = 1.0 msr = PeerMSR() sources = [SimpleFaultSource("001", "PEER Fault Set 2.5", "Active Shallow Crust", mfd, mesh_spacing, msr, 2.0, PoissonTOM(1.0), 0.0, 12., trace, 90., 0.)] imtls = {"PGA": [0.001, 0.01, 0.05, 0.1, 0.2, 0.4, 0.6, 0.8, 1.0, 1.25, 1.5, 2.0, 2.5, 3.0, 4.0, 5.0, 6.0, 7.0]} gmpe = ChiouYoungs2014PEER() gmpe.mixture_model = {"factors": [0.8, 1.2], "weights": [0.5, 0.5]} hcm = calc_hazard_curves(sources, sitecol, imtls, {"Active Shallow Crust": gmpe}) # Match against the benchmark is not exact - but differences in the # log space should be on the order of less than 0.04% expected = numpy.array([-4.140470001, -4.140913368, -4.259457496, -4.724733842, -5.900747959, -7.734816415, -9.019329629, -10.03864778, -10.90333404, -11.83885783, -12.65826442, -14.05429951, -15.22535996, -16.23988897, -17.94685518, -19.36079032, -20.57460101, -21.64201335]) expected = numpy.around(expected, 5) hcm_lnpga = numpy.around(numpy.log(hcm["PGA"].flatten()), 5) perc_diff = 100.0 * ((hcm_lnpga / expected) - 1.0) numpy.testing.assert_allclose(perc_diff, numpy.zeros(len(perc_diff)), atol=0.04)
def _expected_area(self): incr_mfd = mfd.EvenlyDiscretizedMFD( min_mag=6.55, bin_width=0.1, occurrence_rates=[ 0.0010614989, 8.8291627E-4, 7.3437777E-4, 6.108288E-4, 5.080653E-4]) np1 = geo.NodalPlane(strike=0.0, dip=90.0, rake=0.0) np2 = geo.NodalPlane(strike=90.0, dip=45.0, rake=90.0) npd = pmf.PMF([(0.3, np1), (0.7, np2)]) hd = pmf.PMF([(0.5, 4.0), (0.5, 8.0)]) polygon = geo.Polygon( [geo.Point(-122.5, 37.5), geo.Point(-121.5, 37.5), geo.Point(-121.5, 38.5), geo.Point(-122.5, 38.5)]) area = source.AreaSource( source_id="1", name="Quito", tectonic_region_type="Active Shallow Crust", mfd=incr_mfd, rupture_mesh_spacing=self.rupture_mesh_spacing, magnitude_scaling_relationship=scalerel.PeerMSR(), rupture_aspect_ratio=1.5, upper_seismogenic_depth=0.0, lower_seismogenic_depth=10.0, nodal_plane_distribution=npd, hypocenter_distribution=hd, polygon=polygon, area_discretization=1, temporal_occurrence_model=PoissonTOM(50.)) return area
def make_area_source(polygon, discretization, **kwargs): default_arguments = { 'source_id': 'source_id', 'name': 'area source name', 'tectonic_region_type': TRT.VOLCANIC, 'mfd': TruncatedGRMFD(a_val=3, b_val=1, min_mag=5, max_mag=7, bin_width=1), 'nodal_plane_distribution': PMF([(1, NodalPlane(1, 2, 3))]), 'hypocenter_distribution': PMF([(0.5, 4.0), (0.5, 8.0)]), 'upper_seismogenic_depth': 1.3, 'lower_seismogenic_depth': 10.0, 'magnitude_scaling_relationship': PeerMSR(), 'rupture_aspect_ratio': 1.333, 'polygon': polygon, 'area_discretization': discretization, 'rupture_mesh_spacing': 12.33, 'temporal_occurrence_model': PoissonTOM(50.) } default_arguments.update(kwargs) kwargs = default_arguments source = AreaSource(**kwargs) return source
def test_get_cdppvalue(self): rupture = self.make_rupture_fordpp( ParametricProbabilisticRupture, occurrence_rate=0.01, temporal_occurrence_model=PoissonTOM(50)) # Load the testing site. data_path = os.path.dirname(__file__) filename = os.path.join(data_path, "./data/geo_cycs_ss3_testing_site.csv") data = numpy.genfromtxt(filename, dtype=float, delimiter=',', names=True, skip_header=6675, skip_footer=6673) points = [] for loc in range(len(data)): lon = data[loc][0] lat = data[loc][1] points.append(Point(lon, lat)) mesh = Mesh.from_points_list(points) cdpp = rupture.get_cdppvalue(mesh) self.assertAlmostEqual(cdpp[0], data[0][3], delta=0.1) self.assertAlmostEqual(cdpp[1], data[1][3], delta=0.1)
def _setup_fault_source(): """ Builds a fault source using the PEER Bending Fault case. """ point_order_dipping_east = [ Point(-64.78365, -0.45236), Point(-64.80164, -0.45236), Point(-64.90498, -0.36564), Point(-65.0000, -0.16188), Point(-65.0000, 0.0000) ] trace_dip_east = Line(point_order_dipping_east) fault_surface1 = SimpleFaultSurface.from_fault_data( trace_dip_east, 0.0, 12.0, 60., 1.0) # Activity Rates # cm per km2 area = 60. * 12.0 / np.sin(np.radians(60.)) cm2perkm2 = (100. * 1000.)**2. mo1 = 3.0E11 * 0.2 * (area * cm2perkm2) mo_m6p75 = 10.0**(16.05 + 1.5 * 6.75) rate1 = mo1 / mo_m6p75 mfd1 = EvenlyDiscretizedMFD(6.75, 0.01, [rate1]) tom = PoissonTOM(1.0) aspect = 2.0 rake = 90.0 src = SimpleFaultSource("PEER_FLT_EAST", "PEER Bending Fault Dipping East", "Active Shallow Crust", mfd1, 1.0, PeerMSR(), 2.0, tom, 0.0, 12.0, trace_dip_east, 60.0, rake) src.num_ruptures = src.count_ruptures() return src
def compute_disagg(dstore, idxs, cmaker, iml4, trti, bin_edges, monitor): # see https://bugs.launchpad.net/oq-engine/+bug/1279247 for an explanation # of the algorithm used """ :param dstore a DataStore instance :param idxs: an array of indices to ruptures :param cmaker: a :class:`openquake.hazardlib.gsim.base.ContextMaker` instance :param iml4: an ArrayWrapper of shape (N, M, P, Z) :param trti: tectonic region type index :param bin_egdes: a quintet (mag_edges, dist_edges, lon_edges, lat_edges, eps_edges) :param monitor: monitor of the currently running job :returns: a dictionary sid -> 8D-array """ dstore.open('r') oq = dstore['oqparam'] sitecol = dstore['sitecol'] rupdata = {k: dstore['rup/' + k][idxs] for k in dstore['rup']} RuptureContext.temporal_occurrence_model = PoissonTOM( oq.investigation_time) pne_mon = monitor('disaggregate_pne', measuremem=False) mat_mon = monitor('build_disagg_matrix', measuremem=True) gmf_mon = monitor('disagg mean_std', measuremem=False) for sid, mat in disagg.build_matrices( rupdata, sitecol, cmaker, iml4, oq.num_epsilon_bins, bin_edges, pne_mon, mat_mon, gmf_mon): yield {'trti': trti, sid: mat}
def _get_rupture(self, min_mag, max_mag, hypocenter_depth, aspect_ratio, dip, rupture_mesh_spacing, upper_seismogenic_depth=2, lower_seismogenic_depth=16): source_id = name = 'test-source' trt = TRT.ACTIVE_SHALLOW_CRUST mfd = TruncatedGRMFD(a_val=2, b_val=1, min_mag=min_mag, max_mag=max_mag, bin_width=1) location = Point(0, 0) nodal_plane = NodalPlane(strike=45, dip=dip, rake=-123.23) nodal_plane_distribution = PMF([(1, nodal_plane)]) hypocenter_distribution = PMF([(1, hypocenter_depth)]) magnitude_scaling_relationship = PeerMSR() rupture_aspect_ratio = aspect_ratio tom = PoissonTOM(time_span=50) point_source = PointSource( source_id, name, trt, mfd, rupture_mesh_spacing, magnitude_scaling_relationship, rupture_aspect_ratio, tom, upper_seismogenic_depth, lower_seismogenic_depth, location, nodal_plane_distribution, hypocenter_distribution ) ruptures = list(point_source.iter_ruptures()) self.assertEqual(len(ruptures), 1) [rupture] = ruptures self.assertIs(rupture.temporal_occurrence_model, tom) self.assertIs(rupture.tectonic_region_type, trt) self.assertEqual(rupture.rake, nodal_plane.rake) self.assertIsInstance(rupture.surface, PlanarSurface) self.assertEqual(rupture.surface.mesh_spacing, rupture_mesh_spacing) return rupture
def _expected_char_simple(self): tgr_mfd = mfd.TruncatedGRMFD(a_val=-3.5, b_val=1.0, min_mag=5.0, max_mag=6.5, bin_width=1.0) fault_trace = geo.Line( [geo.Point(-121.82290, 37.73010), geo.Point(-122.03880, 37.87710)]) surface = geo.SimpleFaultSurface.from_fault_data( fault_trace=fault_trace, upper_seismogenic_depth=10.0, lower_seismogenic_depth=20.0, dip=45.0, mesh_spacing=self.rupture_mesh_spacing) char = source.CharacteristicFaultSource( source_id="5", name="characteristic source, simple fault", tectonic_region_type="Volcanic", mfd=tgr_mfd, surface=surface, rake=30.0, temporal_occurrence_model=PoissonTOM(50.)) return char
def _expected_char_multi(self): tgr_mfd = mfd.TruncatedGRMFD(a_val=-3.6, b_val=1.0, min_mag=5.2, max_mag=6.4, bin_width=1.0) surfaces = [ geo.PlanarSurface(strike=89.98254582, dip=9.696547068, top_left=geo.Point(-1, 1, 21), top_right=geo.Point(1, 1, 21), bottom_left=geo.Point(-1, -1, 59), bottom_right=geo.Point(1, -1, 59)), geo.PlanarSurface(strike=89.98254582, dip=15.0987061388, top_left=geo.Point(1, 1, 20), top_right=geo.Point(3, 1, 20), bottom_left=geo.Point(1, -1, 80), bottom_right=geo.Point(3, -1, 80)) ] multi_surface = geo.MultiSurface(surfaces) char = source.CharacteristicFaultSource( source_id="7", name="characteristic source, multi surface", tectonic_region_type="Volcanic", mfd=tgr_mfd, surface=multi_surface, rake=90.0, temporal_occurrence_model=PoissonTOM(50.0)) return char
def test_area_with_incr_mfd(self): incr_mfd = mfd.EvenlyDiscretizedMFD( min_mag=6.55, bin_width=0.1, occurrence_rates=[ 0.0010614989, 8.8291627E-4, 7.3437777E-4, 6.108288E-4, 5.080653E-4]) np1 = geo.NodalPlane(strike=0.0, dip=90.0, rake=0.0) np2 = geo.NodalPlane(strike=90.0, dip=45.0, rake=90.0) npd = pmf.PMF([(0.3, np1), (0.7, np2)]) hd = pmf.PMF([(0.5, 4.0), (0.5, 8.0)]) polygon = geo.Polygon( [geo.Point(-122.5, 37.5), geo.Point(-121.5, 37.5), geo.Point(-121.5, 38.5), geo.Point(-122.5, 38.5)]) area = source.AreaSource( source_id="1", name="source A", tectonic_region_type="Active Shallow Crust", mfd=incr_mfd, rupture_mesh_spacing=self.rupture_mesh_spacing, magnitude_scaling_relationship=scalerel.PeerMSR(), rupture_aspect_ratio=1.0, upper_seismogenic_depth=0.0, lower_seismogenic_depth=10.0, nodal_plane_distribution=npd, hypocenter_distribution=hd, polygon=polygon, area_discretization=10, temporal_occurrence_model=PoissonTOM(50.0), ) actual = list(area) self.assertEqual(len(actual), 96) # expected 96 points assert_allclose( actual[0].mfd.occurrence_rates, [1.10572802083e-05, 9.197044479166666e-06, 7.6497684375e-06, 6.3627999999999995e-06, 5.292346875e-06])
def _expected_point(self): tgr_mfd = mfd.TruncatedGRMFD(a_val=-3.5, b_val=1.0, min_mag=5.0, max_mag=6.5, bin_width=1.0) np1 = geo.NodalPlane(strike=0.0, dip=90.0, rake=0.0) np2 = geo.NodalPlane(strike=90.0, dip=45.0, rake=90.0) npd = pmf.PMF([(0.3, np1), (0.7, np2)]) hd = pmf.PMF([(0.5, 4.0), (0.5, 8.0)]) point = source.PointSource( source_id="2", name="point", tectonic_region_type="Stable Continental Crust", mfd=tgr_mfd, rupture_mesh_spacing=self.rupture_mesh_spacing, magnitude_scaling_relationship=scalerel.WC1994(), rupture_aspect_ratio=0.5, upper_seismogenic_depth=0.0, lower_seismogenic_depth=10.0, location=geo.Point(-122.0, 38.0), nodal_plane_distribution=npd, hypocenter_distribution=hd, temporal_occurrence_model=PoissonTOM(50.)) return point
def test_implied_point_sources(self): source = self.make_area_source(Polygon([Point(-2, -2), Point(0, -2), Point(0, 0), Point(-2, 0)]), discretization=66.7, rupture_mesh_spacing=5) ruptures = list(source.iter_ruptures(PoissonTOM(50))) self.assertEqual(len(ruptures), 9 * 2) # resulting 3x3 mesh has points in these coordinates: lons = [-1.4, -0.8, -0.2] lats = [-0.6, -1.2, -1.8] ruptures_iter = iter(ruptures) for lat in lats: for lon in lons: r1 = next(ruptures_iter) r2 = next(ruptures_iter) for rupture in [r1, r2]: self.assertAlmostEqual(rupture.hypocenter.longitude, lon, delta=1e-3) self.assertAlmostEqual(rupture.hypocenter.latitude, lat, delta=1e-3) self.assertEqual(rupture.surface.mesh_spacing, 5) self.assertIs(rupture.source_typology, AreaSource) self.assertEqual(r1.mag, 5.5) self.assertEqual(r2.mag, 6.5) self.assertEqual(len(ruptures), 9 * 2)
def test_area_with_tgr_mfd(self): trunc_mfd = mfd.TruncatedGRMFD(a_val=2.1, b_val=4.2, bin_width=0.1, min_mag=6.55, max_mag=8.91) np1 = geo.NodalPlane(strike=0.0, dip=90.0, rake=0.0) np2 = geo.NodalPlane(strike=90.0, dip=45.0, rake=90.0) npd = pmf.PMF([(0.3, np1), (0.7, np2)]) hd = pmf.PMF([(0.5, 4.0), (0.5, 8.0)]) polygon = geo.Polygon([ geo.Point(-122.5, 37.5), geo.Point(-121.5, 37.5), geo.Point(-121.5, 38.5), geo.Point(-122.5, 38.5) ]) area = source.AreaSource( source_id="1", name="source A", tectonic_region_type="Active Shallow Crust", mfd=trunc_mfd, rupture_mesh_spacing=self.rupture_mesh_spacing, magnitude_scaling_relationship=scalerel.PeerMSR(), rupture_aspect_ratio=1.0, upper_seismogenic_depth=0.0, lower_seismogenic_depth=10.0, nodal_plane_distribution=npd, hypocenter_distribution=hd, polygon=polygon, area_discretization=10, temporal_occurrence_model=PoissonTOM(50.)) actual = list(area) self.assertEqual(len(actual), 96) # expected 96 points self.assertAlmostEqual(actual[0].mfd.a_val, 0.1177287669604317)
def __init__(self, investigation_time, rupture_mesh_spacing, width_of_mfd_bin, area_source_discretization): self.investigation_time = investigation_time self.rupture_mesh_spacing = rupture_mesh_spacing self.width_of_mfd_bin = width_of_mfd_bin self.area_source_discretization = area_source_discretization self.default_tom = PoissonTOM(investigation_time) \ if investigation_time else None # None for scenario calculator
def test_case_11(self): hypocenter_probability = (Decimal(1) / len(test_data.SET1_CASE11_HYPOCENTERS)) hypocenter_pmf = PMF([ (hypocenter_probability, hypocenter) for hypocenter in test_data.SET1_CASE11_HYPOCENTERS ]) # apart from hypocenter pmf repeats case 10 sources = [ AreaSource( source_id='area', name='area', tectonic_region_type=const.TRT.ACTIVE_SHALLOW_CRUST, mfd=test_data.SET1_CASE11_MFD, nodal_plane_distribution=PMF([(1, NodalPlane(0.0, 90.0, 0.0))]), hypocenter_distribution=hypocenter_pmf, upper_seismogenic_depth=0.0, lower_seismogenic_depth=10.0, magnitude_scaling_relationship=PointMSR(), rupture_aspect_ratio=test_data.SET1_RUPTURE_ASPECT_RATIO, temporal_occurrence_model=PoissonTOM(1.), polygon=test_data.SET1_CASE11_SOURCE_POLYGON, area_discretization=10.0, rupture_mesh_spacing=10.0) ] sites = SiteCollection([ test_data.SET1_CASE11_SITE1, test_data.SET1_CASE11_SITE2, test_data.SET1_CASE11_SITE3, test_data.SET1_CASE11_SITE4 ]) gsims = {const.TRT.ACTIVE_SHALLOW_CRUST: SadighEtAl1997()} truncation_level = 0 imts = {str(test_data.IMT): test_data.SET1_CASE11_IMLS} curves = calc_hazard_curves(sources, sites, imts, gsims, truncation_level) s1hc, s2hc, s3hc, s4hc = curves[str(test_data.IMT)] assert_hazard_curve_is(self, s1hc, test_data.SET1_CASE11_SITE1_POES, atol=1e-4, rtol=1e-1) assert_hazard_curve_is(self, s2hc, test_data.SET1_CASE11_SITE2_POES, atol=1e-4, rtol=1e-1) assert_hazard_curve_is(self, s3hc, test_data.SET1_CASE11_SITE3_POES, atol=1e-4, rtol=1e-1) assert_hazard_curve_is(self, s4hc, test_data.SET1_CASE11_SITE4_POES, atol=1e-4, rtol=1e-1)
def _make_pmap(ctxs, cmaker, investigation_time): RuptureContext.temporal_occurrence_model = PoissonTOM(investigation_time) # easy case of independent ruptures, useful for debugging pmap = ProbabilityMap(len(cmaker.loglevels.array), len(cmaker.gsims)) for ctx, poes in cmaker.gen_ctx_poes(ctxs): pnes = ctx.get_probability_no_exceedance(poes) # (N, L, G) for sid, pne in zip(ctx.sids, pnes): pmap.setdefault(sid, 1.).array *= pne return ~pmap
def _make_source(self, edges): source_id = name = 'test-source' trt = "Subduction Interface" tom = PoissonTOM(50.0) magnitude_scaling_relationship = PeerMSR() cfs = ComplexFaultSource(source_id, name, trt, self.mfd, self.spacing, magnitude_scaling_relationship, self.aspect, tom, edges, self.rake) return cfs
def __init__(self, investigation_time=50., rupture_mesh_spacing=10., complex_fault_mesh_spacing=None, width_of_mfd_bin=1.0, area_source_discretization=None): self.area_source_discretization = area_source_discretization self.rupture_mesh_spacing = rupture_mesh_spacing self.complex_fault_mesh_spacing = ( complex_fault_mesh_spacing or rupture_mesh_spacing) self.width_of_mfd_bin = width_of_mfd_bin self.tom = PoissonTOM(investigation_time)
def classical(group, src_filter, gsims, param, monitor=Monitor()): """ Compute the hazard curves for a set of sources belonging to the same tectonic region type for all the GSIMs associated to that TRT. The arguments are the same as in :func:`calc_hazard_curves`, except for ``gsims``, which is a list of GSIM instances. :returns: a dictionary with keys pmap, calc_times, rup_data, extra """ if not hasattr(src_filter, 'sitecol'): # do not filter src_filter = SourceFilter(src_filter, {}) # Get the parameters assigned to the group src_mutex = getattr(group, 'src_interdep', None) == 'mutex' cluster = getattr(group, 'cluster', None) trts = set() maxradius = 0 for src in group: if not src.num_ruptures: # src.num_ruptures may not be set, so it is set here src.num_ruptures = src.count_ruptures() # set the proper TOM in case of a cluster if cluster: src.temporal_occurrence_model = FatedTOM(time_span=1) trts.add(src.tectonic_region_type) if hasattr(src, 'radius'): # for prefiltered point sources maxradius = max(maxradius, src.radius) param['maximum_distance'] = src_filter.integration_distance [trt] = trts # there must be a single tectonic region type cmaker = ContextMaker(trt, gsims, param, monitor) try: cmaker.tom = group.temporal_occurrence_model except AttributeError: # got a list of sources, not a group time_span = param.get('investigation_time') # None for nonparametric cmaker.tom = PoissonTOM(time_span) if time_span else None if cluster: cmaker.tom = FatedTOM(time_span=1) pmap, rup_data, calc_times = PmapMaker(cmaker, src_filter, group).make() extra = {} extra['task_no'] = getattr(monitor, 'task_no', 0) extra['trt'] = trt extra['source_id'] = src.source_id extra['grp_id'] = src.grp_id extra['maxradius'] = maxradius group_probability = getattr(group, 'grp_probability', None) if src_mutex and group_probability: pmap *= group_probability if cluster: tom = getattr(group, 'temporal_occurrence_model') pmap = _cluster(param['imtls'], tom, gsims, pmap) return dict(pmap=pmap, calc_times=calc_times, rup_data=rup_data, extra=extra)
class _BaseFaultSourceTestCase(unittest.TestCase): TRT = TRT.ACTIVE_SHALLOW_CRUST RAKE = 0 TOM = PoissonTOM(50.) def _make_source(self, mfd, aspect_ratio, fault_trace=None, dip=45): source_id = name = 'test-source' trt = self.TRT rake = self.RAKE rupture_mesh_spacing = 1 upper_seismogenic_depth = 0 lower_seismogenic_depth = 4.2426406871192848 magnitude_scaling_relationship = PeerMSR() rupture_aspect_ratio = aspect_ratio tom = self.TOM if fault_trace is None: fault_trace = Line([ Point(0.0, 0.0), Point(0.0, 0.0359728811758), Point(0.0190775080917, 0.0550503815181), Point(0.03974514139, 0.0723925718855) ]) sfs = SimpleFaultSource( source_id, name, trt, mfd, rupture_mesh_spacing, magnitude_scaling_relationship, rupture_aspect_ratio, tom, upper_seismogenic_depth, lower_seismogenic_depth, fault_trace, dip, rake) assert_pickleable(sfs) return sfs def _test_ruptures(self, expected_ruptures, source): ruptures = list(source.iter_ruptures()) for rupture in ruptures: self.assertIsInstance(rupture, ParametricProbabilisticRupture) self.assertIs(rupture.temporal_occurrence_model, self.TOM) self.assertIs(rupture.tectonic_region_type, self.TRT) self.assertEqual(rupture.rake, self.RAKE) self.assertEqual(len(expected_ruptures), source.count_ruptures()) for i in range(len(expected_ruptures)): expected_rupture, rupture = expected_ruptures[i], ruptures[i] self.assertAlmostEqual(rupture.mag, expected_rupture['mag']) self.assertAlmostEqual(rupture.rake, expected_rupture['rake']) self.assertAlmostEqual(rupture.occurrence_rate, expected_rupture['occurrence_rate']) assert_mesh_is(self, rupture.surface, expected_rupture['surface']) self.assertEqual(rupture.hypocenter, Point(*expected_rupture['hypocenter'])) assert_angles_equal(self, rupture.surface.get_strike(), expected_rupture['strike'], delta=0.5) assert_angles_equal(self, rupture.surface.get_dip(), expected_rupture['dip'], delta=3)
def test_get_probability_one_or_more_occurrences(self): pdf = PoissonTOM(time_span=50) self.assertEqual(pdf.get_probability_one_or_more_occurrences(10), 1) aae = self.assertAlmostEqual aae(pdf.get_probability_one_or_more_occurrences(0.1), 0.9932621) aae(pdf.get_probability_one_or_more_occurrences(0.01), 0.39346934) pdf = PoissonTOM(time_span=5) self.assertEqual(pdf.get_probability_one_or_more_occurrences(8), 1) aae = self.assertAlmostEqual aae(pdf.get_probability_one_or_more_occurrences(0.1), 0.3934693) aae(pdf.get_probability_one_or_more_occurrences(0.01), 0.0487706)
def test_get_probability_no_exceedance(self): rupture = make_rupture(ParametricProbabilisticRupture, occurrence_rate=0.01, temporal_occurrence_model=PoissonTOM(50)) poes = numpy.array([[0.9, 0.8, 0.7], [0.6, 0.5, 0.4]]) pne = rupture.get_probability_no_exceedance(poes) numpy.testing.assert_allclose( pne, numpy.array([[0.6376282, 0.6703200, 0.7046881], [0.7408182, 0.7788008, 0.8187308]]))
def setUp(self): self.source_class = FakeSource mfd = EvenlyDiscretizedMFD(min_mag=3, bin_width=1, occurrence_rates=[5, 6, 7]) self.source = FakeSource('source_id', 'name', const.TRT.VOLCANIC, mfd=mfd, rupture_mesh_spacing=2, magnitude_scaling_relationship=PeerMSR(), rupture_aspect_ratio=1, temporal_occurrence_model=PoissonTOM(50.)) self.sitecol = SiteCollection(self.SITES)
def test_param(self): RuptureContext.temporal_occurrence_model = PoissonTOM(50.) ctxs = [ RuptureContext([('occurrence_rate', .001)]), RuptureContext([('occurrence_rate', .002)]) ] for poe in (.1, .5, .9): c1, pnes1 = compose(ctxs, poe) c2, pnes2 = compose(_collapse(ctxs), poe) aac(c1, c2) # the same
def test_sample_number_of_occurrences(self): time_span = 20 rate = 0.01 num_samples = 2000 tom = PoissonTOM(time_span) rupture = make_rupture(ProbabilisticRupture, occurrence_rate=rate, temporal_occurrence_model=tom) numpy.random.seed(37) mean = sum(rupture.sample_number_of_occurrences() for i in xrange(num_samples)) / float(num_samples) self.assertAlmostEqual(mean, rate * time_span, delta=2e-3)
def example_calc(apply): sitecol = SiteCollection([ Site(Point(30.0, 30.0), 760., 1.0, 1.0), Site(Point(30.25, 30.25), 760., 1.0, 1.0), Site(Point(30.4, 30.4), 760., 1.0, 1.0)]) mfd_1 = TruncatedGRMFD(4.5, 8.0, 0.1, 4.0, 1.0) mfd_2 = TruncatedGRMFD(4.5, 7.5, 0.1, 3.5, 1.1) sources = [PointSource('001', 'Point1', 'Active Shallow Crust', mfd_1, 1.0, WC1994(), 1.0, PoissonTOM(50.0), 0.0, 30.0, Point(30.0, 30.5), PMF([(1.0, NodalPlane(0.0, 90.0, 0.0))]), PMF([(1.0, 10.0)])), PointSource('002', 'Point2', 'Active Shallow Crust', mfd_2, 1.0, WC1994(), 1.0, PoissonTOM(50.0), 0.0, 30.0, Point(30.0, 30.5), PMF([(1.0, NodalPlane(0.0, 90.0, 0.0))]), PMF([(1.0, 10.0)]))] imtls = {'PGA': [0.01, 0.1, 0.2, 0.5, 0.8], 'SA(0.5)': [0.01, 0.1, 0.2, 0.5, 0.8]} gsims = {'Active Shallow Crust': AkkarBommer2010()} return calc_hazard_curves(sources, sitecol, imtls, gsims, apply=apply)
def test_get_probability_one_occurrence(self): pdf = PoissonTOM(time_span=30) aae = self.assertAlmostEqual aae(pdf.get_probability_one_occurrence(10), 0) aae(pdf.get_probability_one_occurrence(0.1), 0.1493612) aae(pdf.get_probability_one_occurrence(0.01), 0.2222455)