def test_numbers_of_ruptures_not_in_increasing_order(self): pmf = PMF([(0.8, 0), (0.1, 2), (0.1, 1)]) self.assert_failed_creation( NonParametricProbabilisticRupture, ValueError, 'numbers of ruptures must be defined in increasing order', pmf=pmf )
def test_hypocenter_depth_out_of_seismogenic_layer(self): self.assert_failed_creation( ValueError, 'depths of all hypocenters must be in between ' 'lower and upper seismogenic depths', upper_seismogenic_depth=3, lower_seismogenic_depth=8, hypocenter_distribution=PMF([(0.3, 4), (0.7, 8.001)]))
def test_numbers_of_ruptures_not_defined_with_unit_step(self): pmf = PMF([(0.8, 0), (0.2, 2)]) self.assert_failed_creation( NonParametricProbabilisticRupture, ValueError, 'numbers of ruptures must be defined with unit step', pmf=pmf )
def fromdict(self, dic, weights=None): """ Populate a GriddedSource with ruptures """ assert not self.data, '%s is not empty' % self i = 0 for mag, rake, hp, probs, (start, stop) in zip(dic['magnitude'], dic['rake'], dic['hypocenter'], dic['probs_occur'], dic['slice']): mesh = Mesh(dic['mesh3d'][start:stop, 0], dic['mesh3d'][start:stop, 1], dic['mesh3d'][start:stop, 2]) surface = GriddedSurface(mesh) pmf = PMF([(prob, i) for i, prob in enumerate(probs)]) hypocenter = Point(hp[0], hp[1], hp[2]) rup = NonParametricProbabilisticRupture( mag, rake, self.tectonic_region_type, hypocenter, surface, pmf, weight=None if weights is None else weights[i]) self.data.append((rup, pmf)) i += 1
def test_no_dilation(self): mfd = TruncatedGRMFD(a_val=1, b_val=2, min_mag=3, max_mag=5, bin_width=1) np_dist = PMF([(1, NodalPlane(0, 2, 4))]) source = make_point_source(nodal_plane_distribution=np_dist, mfd=mfd) polygon = source.get_rupture_enclosing_polygon() self.assertIsInstance(polygon, Polygon) elons = [ 1.2115590, 1.2115033, 1.2113368, 1.2110612, 1.2106790, 1.2101940, 1.2096109, 1.2089351, 1.2081734, 1.2073329, 1.2064218, 1.2054488, 1.2044234, 1.2033554, 1.2022550, 1.2011330, 1.2000000, 1.1988670, 1.1977450, 1.1966446, 1.1955766, 1.1945512, 1.1935782, 1.1926671, 1.1918266, 1.1910649, 1.1903891, 1.1898060, 1.1893210, 1.1889388, 1.1886632, 1.1884967, 1.1884410, 1.1884967, 1.1886631, 1.1889387, 1.1893209, 1.1898058, 1.1903890, 1.1910647, 1.1918265, 1.1926670, 1.1935781, 1.1945511, 1.1955765, 1.1966446, 1.1977449, 1.1988670, 1.2000000, 1.2011330, 1.2022551, 1.2033554, 1.2044235, 1.2054489, 1.2064219, 1.2073330, 1.2081735, 1.2089353, 1.2096110, 1.2101942, 1.2106791, 1.2110613, 1.2113369, 1.2115033, 1.2115590 ] elats = [ 3.3999999, 3.3988689, 3.3977489, 3.3966505, 3.3955843, 3.3945607, 3.3935894, 3.3926799, 3.3918409, 3.3910805, 3.3904060, 3.3898238, 3.3893397, 3.3889582, 3.3886831, 3.3885169, 3.3884614, 3.3885169, 3.3886831, 3.3889582, 3.3893397, 3.3898238, 3.3904060, 3.3910805, 3.3918409, 3.3926799, 3.3935894, 3.3945607, 3.3955843, 3.3966505, 3.3977489, 3.3988689, 3.3999999, 3.4011309, 3.4022510, 3.4033494, 3.4044156, 3.4054392, 3.4064105, 3.4073200, 3.4081590, 3.4089194, 3.4095940, 3.4101761, 3.4106603, 3.4110418, 3.4113169, 3.4114831, 3.4115386, 3.4114831, 3.4113169, 3.4110418, 3.4106603, 3.4101761, 3.4095940, 3.4089194, 3.4081590, 3.4073200, 3.4064105, 3.4054392, 3.4044156, 3.4033494, 3.4022510, 3.4011309, 3.3999999 ] numpy.testing.assert_allclose(polygon.lons, elons) numpy.testing.assert_allclose(polygon.lats, elats)
def test_mutually_exclusive_ruptures(self): # Test the calculation of hazard curves using mutually exclusive # ruptures for a single source gsim_by_trt = [SadighEtAl1997()] rupture = _create_rupture(10., 6.) data = [(rupture, PMF([(0.7, 0), (0.3, 1)])), (rupture, PMF([(0.6, 0), (0.4, 1)]))] src = NonParametricSeismicSource('0', 'test', TRT.ACTIVE_SHALLOW_CRUST, data) src.src_group_id = [0] group = SourceGroup( src.tectonic_region_type, [src], 'test', 'mutex', 'mutex') param = dict(imtls=self.imtls, filter_distance='rjb') crv = classical(group, self.sites, gsim_by_trt, param)[0] npt.assert_almost_equal(numpy.array([0.35000, 0.32497, 0.10398]), crv[0].array[:, 0], decimal=4)
def test_dilated(self): mfd = TruncatedGRMFD(a_val=1, b_val=2, min_mag=3, max_mag=5, bin_width=1) np_dist = PMF([(1, NodalPlane(0, 2, 4))]) source = make_point_source(nodal_plane_distribution=np_dist, mfd=mfd) polygon = source.get_rupture_enclosing_polygon(dilation=20) self.assertIsInstance(polygon, Polygon) elons = [ 1.3917408, 1.3908138, 1.3880493, 1.3834740, 1.3771320, 1.3690846, 1.3594093, 1.3481992, 1.3355624, 1.3216207, 1.3065082, 1.2903704, 1.2733628, 1.2556490, 1.2373996, 1.2187902, 1.2000000, 1.1812098, 1.1626004, 1.1443510, 1.1266372, 1.1096296, 1.0934918, 1.0783793, 1.0644376, 1.0518008, 1.0405907, 1.0309154, 1.0228680, 1.0165260, 1.0119507, 1.0091862, 1.0082592, 1.0091788, 1.0119361, 1.0165049, 1.0228411, 1.0308838, 1.0405556, 1.0517635, 1.0643995, 1.0783420, 1.0934567, 1.1095979, 1.1266103, 1.1443298, 1.1625858, 1.1812023, 1.2000000, 1.2187977, 1.2374142, 1.2556702, 1.2733897, 1.2904021, 1.3065433, 1.3216580, 1.3356005, 1.3482365, 1.3594444, 1.3691162, 1.3771589, 1.3834951, 1.3880639, 1.3908212, 1.3917408 ] elats = [ 3.3999810, 3.3812204, 3.3626409, 3.3444213, 3.3267370, 3.3097585, 3.2936490, 3.2785638, 3.2646481, 3.2520357, 3.2408482, 3.2311932, 3.2231637, 3.2168369, 3.2122738, 3.2095182, 3.2085967, 3.2095182, 3.2122738, 3.2168369, 3.2231637, 3.2311932, 3.2408482, 3.2520357, 3.2646481, 3.2785638, 3.2936490, 3.3097585, 3.3267370, 3.3444213, 3.3626409, 3.3812204, 3.3999810, 3.4187420, 3.4373226, 3.4555440, 3.4732305, 3.4902120, 3.5063247, 3.5214135, 3.5353329, 3.5479490, 3.5591401, 3.5687983, 3.5768308, 3.5831599, 3.5877248, 3.5904815, 3.5914033, 3.5904815, 3.5877248, 3.5831599, 3.5768308, 3.5687983, 3.5591401, 3.5479490, 3.5353329, 3.5214135, 3.5063247, 3.4902120, 3.4732305, 3.4555440, 3.4373226, 3.4187420, 3.3999810 ] numpy.testing.assert_allclose(polygon.lons, elons) numpy.testing.assert_allclose(polygon.lats, elats)
def test_simple_fault_surface_vertical(self): # Create the rupture mag = 10.0 rake = 90.0 trt = TRT.ACTIVE_SHALLOW_CRUST hypoc = Point(0.25, 0.0, 5) pmf = PMF([(0.8, 0), (0.2, 1)]) rup = NPPR(mag, rake, trt, hypoc, self.srfc1, pmf) # Compute distances param = 'closest_point' sites = SiteCollection( [Site(Point(0.25, -0.1, 0.0)), Site(Point(-0.1, 0.0, 0.0))]) dsts = get_distances(rup, sites, param) # Check first point msg = 'The longitude of the first point is wrong' self.assertTrue(abs(dsts[0, 0] - 0.25) < 1e-2, msg) msg = 'The latitude of the first point is wrong' self.assertTrue(abs(dsts[0][1] - 0.0) < 1e-2, msg) # Check second point msg = 'The longitude of the second point is wrong' self.assertTrue(abs(dsts[1, 0] - 0.0) < 1e-2, msg) msg = 'The latitude of the second point is wrong' self.assertTrue(abs(dsts[1][1] - 0.0) < 1e-2, msg)
def test(self): mfd = TruncatedGRMFD(a_val=1, b_val=2, min_mag=3, max_mag=5, bin_width=1) np_dist = PMF([(0.5, NodalPlane(1, 20, 3)), (0.5, NodalPlane(2, 2, 4))]) source = make_point_source(nodal_plane_distribution=np_dist, mfd=mfd) radius = source._get_max_rupture_projection_radius() self.assertAlmostEqual(radius, 1.2830362) mfd = TruncatedGRMFD(a_val=1, b_val=2, min_mag=5, max_mag=6, bin_width=1) np_dist = PMF([(0.5, NodalPlane(1, 40, 3)), (0.5, NodalPlane(2, 30, 4))]) source = make_point_source(nodal_plane_distribution=np_dist, mfd=mfd) radius = source._get_max_rupture_projection_radius() self.assertAlmostEqual(radius, 3.8712214)
def setUp(self): """ """ #~ self.depth_as_list = [models.HypocentralDepth(0.5, 5.), #~ models.HypocentralDepth(0.5, 10.)] self.depth_as_pmf = PMF([(0.5, 5.), (0.5, 10.)])
def test_get_probability_no_exceedance(self): pmf = PMF([(0.7, 0), (0.2, 1), (0.1, 2)]) poes = numpy.array([[0.9, 0.8, 0.7], [0.6, 0.5, 0.4]]) rup = make_rupture(NonParametricProbabilisticRupture, pmf=pmf) pne = rup.get_probability_no_exceedance(poes, PoissonTOM(20)) numpy.testing.assert_allclose( pne, numpy.array([[0.721, 0.744, 0.769], [0.796, 0.825, 0.856]]))
def test(self): npd = PMF([(0.5, NodalPlane(1, 20, 3)), (0.5, NodalPlane(2, 2, 4))]) hd = PMF([(1, 14)]) mesh = Mesh(numpy.array([0, 1]), numpy.array([0.5, 1])) mmfd = MultiMFD('incrementalMFD', size=2, min_mag=[4.5], bin_width=[2.0], occurRates=[[.3, .1], [.4, .2, .1]]) mps = MultiPointSource('mp1', 'multi point source', 'Active Shallow Crust', mmfd, PeerMSR(), 1.0, 10, 20, npd, hd, mesh) # test the splitting splits = list(mps) self.assertEqual(len(splits), 2) for split in splits: self.assertEqual(split.src_group_id, mps.src_group_id) got = obj_to_node(mps).to_str() print(got) exp = '''\ multiPointSource{id='mp1', name='multi point source', tectonicRegion='Active Shallow Crust'} multiPointGeometry gml:posList [0.0, 0.5, 1.0, 1.0] upperSeismoDepth 10 lowerSeismoDepth 20 magScaleRel 'PeerMSR' ruptAspectRatio 1.0 multiMFD{kind='incrementalMFD', size=2} bin_width [2.0] min_mag [4.5] occurRates [0.3, 0.1, 0.4, 0.2, 0.1] lengths [2, 3] nodalPlaneDist nodalPlane{dip=20, probability=0.5, rake=3, strike=1} nodalPlane{dip=2, probability=0.5, rake=4, strike=2} hypoDepthDist hypoDepth{depth=14, probability=1.0} ''' self.assertEqual(got, exp) # test serialization to and from hdf5 tmp = general.gettemp(suffix='.hdf5') with hdf5.File(tmp, 'w') as f: f[mps.source_id] = mps with hdf5.File(tmp, 'r') as f: f[mps.source_id]
def test_negative_or_zero_prob(self): # negative probs are refused data = [(-1, 0)] + [(1.0, 1), (1.0, 2)] self.assertRaises(ValueError, PMF, data) # 0 probs are accepted data = [(0, 0)] + [(0.5, 1), (0.5, 2)] PMF(data)
def test_negative_or_zero_prob(self): # negative probs are refused data = [(-1, 0)] + [(Decimal('1.0'), 1), (Decimal('1.0'), 2)] self.assertRaises(ValueError, PMF, data) # 0 probs are accepted data = [(0, 0)] + [(Decimal('0.5'), 1), (Decimal('0.5'), 2)] PMF(data)
def test_sample_pmf_numerical(self): """ Tests the sampling function for numerical data - using a random seed approach """ pmf = PMF([(0.3, 1), (0.5, 2), (0.2, 4)]) np.random.seed(22) self.assertListEqual(pmf.sample(10), [1, 2, 2, 4, 1, 2, 1, 2, 1, 4])
def setUp(self): mfd = TruncatedGRMFD(min_mag=4.0, max_mag=6.0, bin_width=0.1, a_val=2.0, b_val=1.0) msr = WC1994() tom = PoissonTOM(1.0) loc = Point(longitude=0.0, latitude=0.0) npd = PMF([(1.0, NodalPlane(0.0, 90.0, 0.0))]) hpd = PMF([(0.7, 10.), (0.3, 20.0)]) self.src1 = PointSource(source_id='1', name='1', tectonic_region_type='Test', mfd=mfd, rupture_mesh_spacing=1, magnitude_scaling_relationship=msr, rupture_aspect_ratio=1., temporal_occurrence_model=tom, upper_seismogenic_depth=0, lower_seismogenic_depth=100., location=loc, nodal_plane_distribution=npd, hypocenter_distribution=hpd) mfd = EvenlyDiscretizedMFD(min_mag=4.0, bin_width=0.1, occurrence_rates=[3., 2., 1.]) self.src2 = PointSource(source_id='1', name='1', tectonic_region_type='Test', mfd=mfd, rupture_mesh_spacing=1, magnitude_scaling_relationship=msr, rupture_aspect_ratio=1., temporal_occurrence_model=tom, upper_seismogenic_depth=0, lower_seismogenic_depth=100., location=loc, nodal_plane_distribution=npd, hypocenter_distribution=hpd)
def test_rupture_close_to_south_pole(self): # data taken from real example and causing "surface's angles are not # right" error mfd = EvenlyDiscretizedMFD( min_mag=5., bin_width=0.1, occurrence_rates=[2.180e-07] ) nodal_plane_dist = PMF([(1., NodalPlane(135., 20., 90.))]) src = PointSource(source_id='1', name='pnt', tectonic_region_type='asc', mfd=mfd, rupture_mesh_spacing=1, magnitude_scaling_relationship=WC1994(), rupture_aspect_ratio=1., temporal_occurrence_model=PoissonTOM(50.), upper_seismogenic_depth=0, lower_seismogenic_depth=26, location=Point(-165.125, -83.600), nodal_plane_distribution=nodal_plane_dist, hypocenter_distribution=PMF([(1., 9.)])) ruptures = list(src.iter_ruptures()) self.assertEqual(len(ruptures), 1)
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 test(self): npd = PMF([(0.5, NodalPlane(1, 20, 3)), (0.5, NodalPlane(2, 2, 4))]) hd = PMF([(1, 14)]) mesh = Mesh(numpy.array([0, 1]), numpy.array([0.5, 1])) tom = PoissonTOM(50.) mmfd = MultiMFD('incrementalMFD', size=2, min_mag=[4.5], bin_width=[2.0], occurRates=[[.3, .1], [.4, .2, .1]]) mps = MultiPointSource('mp1', 'multi point source', 'Active Shallow Crust', mmfd, 2.0, PeerMSR(), 1.0, tom, 10, 20, npd, hd, mesh) mps.src_group_id = 1 # test the splitting splits = list(split_source(mps)) self.assertEqual(len(splits), 2) for split in splits: self.assertEqual(split.src_group_id, mps.src_group_id) got = obj_to_node(mps).to_str() print(got) self.assertEqual(got, '''\ multiPointSource{id='mp1', name='multi point source', tectonicRegion='Active Shallow Crust'} multiPointGeometry gml:posList [0, 0.5, 1, 1.0] upperSeismoDepth 10 lowerSeismoDepth 20 magScaleRel 'PeerMSR' ruptAspectRatio 1.0 multiMFD{kind='incrementalMFD', size=2} bin_width [2.0] min_mag [4.5] occurRates [0.29999999999999999, 0.10000000000000001, 0.40000000000000002, 0.20000000000000001, 0.10000000000000001] lengths [2, 3] nodalPlaneDist nodalPlane{dip=20, probability=0.5, rake=3, strike=1} nodalPlane{dip=2, probability=0.5, rake=4, strike=2} hypoDepthDist hypoDepth{depth=14, probability=1.0} ''')
def test_mutually_exclusive_ruptures(self): # Test the calculation of hazard curves using mutually exclusive # ruptures for a single source gsim_by_trt = [SadighEtAl1997()] rupture = _create_rupture(10., 6.) data = [(rupture, PMF([(0.7, 0), (0.3, 1)])), (rupture, PMF([(0.6, 0), (0.4, 1)]))] src = NonParametricSeismicSource('0', 'test', TRT.ACTIVE_SHALLOW_CRUST, data) group = SourceGroup(src.tectonic_region_type, [src], 'test', 'indep', 'mutex') crv = pmap_from_grp(group, self.sites, self.imtls, gsim_by_trt, truncation_level=None)[0] npt.assert_almost_equal(numpy.array([0.35000, 0.32497, 0.10398]), crv.array[:, 0], decimal=4)
def npd_to_pmf(nodal_plane_dist, use_default=False): """ Returns the nodal plane distribution as an instance of the PMF class """ if isinstance(nodal_plane_dist, PMF): # Aready in PMF format - return return nodal_plane_dist elif isinstance(nodal_plane_dist, list): npd_list = [] for npd in nodal_plane_dist: assert isinstance(npd, models.NodalPlane) npd_list.append( (npd.probability, NodalPlane(npd.strike, npd.dip, npd.rake))) return PMF(npd_list) else: if use_default: return PMF([(1.0, NodalPlane(0.0, 90.0, 0.0))]) else: raise ValueError('Nodal Plane distribution not defined')
def test(self): sitecol = SiteCollection([Site(Point(30.0, 30.0), 760., 1.0, 1.0)]) mfd = TruncatedGRMFD(4.5, 8.0, 0.1, 4.0, 1.0) sources = [PointSource('001', 'Point1', 'Active Shallow Crust', mfd, 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]} hc1 = calc_hazard_curves(sources, sitecol, imtls, { 'Active Shallow Crust': AkkarBommer2010()})['PGA'] hc2 = calc_hazard_curves(sources, sitecol, imtls, { 'Active Shallow Crust': SadighEtAl1997()})['PGA'] hc = .6 * hc1 + .4 * hc2 ag = AvgGMPE(b1=dict(AkkarBommer2010={'weight': .6}), b2=dict(SadighEtAl1997={'weight': .4})) hcm = calc_hazard_curves(sources, sitecol, imtls, { 'Active Shallow Crust': ag})['PGA'] # the AvgGMPE is not producing real means!! numpy.testing.assert_almost_equal(hc, hcm, decimal=3)
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([(1, 4)]), 'upper_seismogenic_depth': 1.3, 'lower_seismogenic_depth': 4.9, 'magnitude_scaling_relationship': PeerMSR(), 'rupture_aspect_ratio': 1.333, 'polygon': polygon, 'area_discretization': discretization, 'rupture_mesh_spacing': 12.33 } default_arguments.update(kwargs) kwargs = default_arguments source = AreaSource(**kwargs) return source
def npd_to_pmf(nodal_plane_dist, use_default=False): """ Returns the nodal plane distribution as an instance of the PMF class """ if isinstance(nodal_plane_dist, PMF): # Aready in PMF format - return return nodal_plane_dist else: if use_default: return PMF([(1.0, NodalPlane(0.0, 90.0, 0.0))]) else: raise ValueError('Nodal Plane distribution not defined')
def test_sample_pmf_convergence(self): """ Tests the PMF sampling function for numerical convergence """ pmf = PMF([(0.3, 1.), (0.5, 2.), (0.2, 4.)]) # Take 100000 samples of the PMF and find the density of the results output = np.histogram(pmf.sample(100000), np.array([0.5, 1.5, 2.5, 3.5, 4.5]), density=True)[0] np.testing.assert_array_almost_equal(output, np.array([0.3, 0.5, 0.0, 0.2]), 2) # Tests to 2 decimal places
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 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 setUp(self): """ """ # # coordinates of point sources lons = [10.00, 10.10, 10.20, 10.00, 10.10, 10.20, 10.00, 10.10, 10.20] lats = [45.10, 45.10, 45.10, 45.05, 45.05, 45.05, 45.00, 45.00, 45.00] deps = [10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00, 10.00] self.lons = lons self.lats = lats # # set main parameters mfd = TruncatedGRMFD(min_mag=4.0, max_mag=6.0, bin_width=0.1, a_val=2.0, b_val=1.0) msr = WC1994() tom = PoissonTOM(1.0) npd = PMF([(1.0, NodalPlane(0.0, 90.0, 0.0))]) hdd = PMF([(0.7, 4.), (0.3, 8.0)]) # # create the list of sources srcs = [] for idx, (lon, lat, dep) in enumerate(zip(lons, lats, deps)): src = PointSource(source_id='1', name='Test', tectonic_region_type=TRT.ACTIVE_SHALLOW_CRUST, mfd=mfd, rupture_mesh_spacing=5.0, magnitude_scaling_relationship=msr, rupture_aspect_ratio=1.0, temporal_occurrence_model=tom, upper_seismogenic_depth=0, lower_seismogenic_depth=10., location=Point(lon, lat, dep), nodal_plane_distribution=npd, hypocenter_distribution=hdd) srcs.append(src) self.points = srcs
def __fromh5__(self, dic, attrs): self.source_id = attrs['source_id'] self.name = attrs['name'] self.tectonic_region_type = attrs['tectonic_region_type'] self.magnitude_scaling_relationship = SCALEREL[ attrs['magnitude_scaling_relationship']] npd = dic.pop('nodal_plane_distribution').value hdd = dic.pop('hypocenter_distribution').value mesh = dic.pop('mesh').value self.rupture_aspect_ratio = dic.pop('rupture_aspect_ratio').value self.lower_seismogenic_depth = dic.pop('lower_seismogenic_depth').value self.upper_seismogenic_depth = dic.pop('upper_seismogenic_depth').value [(mfd_kind, mfd)] = dic.items() self.nodal_plane_distribution = PMF([ (prob, NodalPlane(strike, dip, rake)) for prob, strike, dip, rake in npd]) self.hypocenter_distribution = PMF(hdd) self.mesh = Mesh(mesh['lon'], mesh['lat']) kw = {k: dset.value for k, dset in mfd.items()} kw['size'] = len(mesh) kw['kind'] = mfd_kind self.mfd = MultiMFD(**kw)
def test_sample_pmf_non_numerical(self): """ Tests the sampling function for non-numerical data - using a random seed approach """ pmf = PMF([(0.3, "apples"), (0.1, "oranges"), (0.4, "bananas"), (0.2, "lemons")]) np.random.seed(22) expected = ['apples', 'bananas', 'bananas', 'lemons', 'apples', 'oranges', 'apples', 'bananas', 'apples', 'lemons'] self.assertListEqual(pmf.sample(10), expected)