def test_increment_b_check_constraints(self): mfd = TruncatedGRMFD(min_mag=6.0, max_mag=7.0, bin_width=0.1, a_val=1, b_val=1) self.assert_mfd_error(mfd.modify, 'increment_b', {'value': -1}) mfd = TruncatedGRMFD(min_mag=6.0, max_mag=7.0, bin_width=0.1, a_val=1, b_val=1) self.assert_mfd_error(mfd.modify, 'increment_b', {'value': -2})
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_5(self): # rupture length and width greater than fault length and width # respectively mfd = TruncatedGRMFD(a_val=0.5, b_val=1.0, min_mag=6.0, max_mag=7.0, bin_width=1.0) self._test_ruptures(test_data.TEST5_RUPTURES, self._make_source(mfd=mfd, aspect_ratio=1.0))
def test_3(self): # rupture length greater than fault length, number of nodes along # length is odd and along width is even mfd = TruncatedGRMFD(a_val=0.5, b_val=1.0, min_mag=5.0, max_mag=6.0, bin_width=1.0) self._test_ruptures(test_data.TEST3_RUPTURES, self._make_source(mfd=mfd, aspect_ratio=4.0))
def test_4(self): # rupture width greater than fault width, number of nodes along # length is even, along width is odd mfd = TruncatedGRMFD(a_val=0.5, b_val=1.0, min_mag=5.4, max_mag=5.5, bin_width=0.1) self._test_ruptures(test_data.TEST4_RUPTURES, self._make_source(mfd=mfd, aspect_ratio=0.5))
def test02(self): """ Simplest test """ profiles = [ Line([Point(0.0, 0.0, 0.0), Point(0.0, 0.001, 15.0)]), Line([Point(0.1, 0.0, 0.0), Point(0.1, 0.010, 12.0)]), Line([Point(0.2, 0.0, 0.0), Point(0.2, 0.020, 9.0)]), Line([Point(0.3, 0.0, 0.0), Point(0.3, 0.030, 6.0)]) ] mfd = TruncatedGRMFD(a_val=0.5, b_val=1.0, min_mag=5.8, max_mag=6.2, bin_width=0.1) source = self._make_source(mfd=mfd, aspect_ratio=1.5, profiles=profiles) msg = 'Wrong number of ruptures' self.assertEqual(source.count_ruptures(), 28, msg) if MAKE_MOVIES: self._ruptures_animation('test02', source.surface, self.ruptures, source.profiles)
def setUp(self): min_mag = 6.5 max_mag = 7.0 bin_width = 0.1 a_val = 3.0 b_val = 1.0 self.mfd = TruncatedGRMFD(min_mag, max_mag, bin_width, a_val, b_val)
def test_set_max_mag_check_constraints(self): mfd = TruncatedGRMFD(min_mag=3.5, max_mag=5.5, bin_width=0.5, a_val=1, b_val=1.3) self.assert_mfd_error(mfd.modify, 'set_max_mag', {'value': 3.6})
def test_2(self): # rupture dimensions are larger then mesh_spacing, number of nodes # along strike and dip is even mfd = TruncatedGRMFD(a_val=0.5, b_val=1.0, min_mag=3.0, max_mag=4.0, bin_width=1.0) self._test_ruptures(test_data.TEST2_RUPTURES, self._make_source(mfd=mfd, aspect_ratio=1.0))
def test_set_ab_check_constraints(self): mfd = TruncatedGRMFD(min_mag=6.0, max_mag=7.0, bin_width=0.1, a_val=1, b_val=1) self.assert_mfd_error(mfd.modify, 'set_ab', {'a_val': 0, 'b_val': 0})
def main(fname_config, label, edges_folder, out_file, *, resampling=None): """ Creates the .xml input for the interface sources """ create_folder(os.path.dirname(out_file)) # check edges folder assert os.path.exists(edges_folder) # Read the config file config = toml.load(fname_config) # Create .xml es = EdgesSet.from_files(edges_folder) src = es.get_complex_fault(section_length=float(resampling)) binw = config['bin_width'] agr = config['sources'][label]['agr'] bgr = config['sources'][label]['bgr'] mmin = config['mmin'] mmax = config['sources'][label]['mmax'] mfd = TruncatedGRMFD(min_mag=mmin, max_mag=mmax, bin_width=binw, a_val=agr, b_val=bgr) src.mfd = mfd src.rupture_mesh_spacing = 10.0 write_source_model(out_file, [src], 'Name')
def test_set_a_and_get_total_moment_rate_when_b_equal_to_1_5(self): mfd = TruncatedGRMFD(min_mag=2.4, max_mag=5.6, bin_width=0.4, a_val=-0.44, b_val=1.5) tmr = mfd._get_total_moment_rate() mfd._set_a(tmr) self.assertAlmostEqual(mfd.a_val, -0.44) self.assertEqual(mfd._get_total_moment_rate(), tmr)
def test_get_total_moment_rate_when_b_equal_to_1_5(self): mfd = TruncatedGRMFD(min_mag=6.0, max_mag=8.0, bin_width=0.1, a_val=-9.4, b_val=1.5) self.assertAlmostEqual(mfd._get_total_moment_rate(), 1.3400508)
def test_set_a_and_get_total_moment_rate(self): mfd = TruncatedGRMFD(min_mag=3.0, max_mag=4.0, bin_width=0.1, a_val=4.4, b_val=0.5) tmr = mfd._get_total_moment_rate() mfd._set_a(tmr) self.assertAlmostEqual(mfd.a_val, 4.4) self.assertEqual(mfd._get_total_moment_rate(), tmr)
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_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_get_total_moment_rate(self): mfd = TruncatedGRMFD(min_mag=6.0, max_mag=8.0, bin_width=0.1, a_val=-17.2, b_val=0.4) self.assertAlmostEqual(mfd._get_total_moment_rate(), 1.6140553)
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 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): 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) pol = Polygon([Point(longitude=0.0, latitude=0.0), Point(longitude=1.0, latitude=0.0), Point(longitude=1.0, latitude=1.0), Point(longitude=0.0, latitude=1.0)]) npd = PMF([(1.0, NodalPlane(0.0, 90.0, 0.0))]) hpd = PMF([(0.7, 10.), (0.3, 20.0)]) self.src1 = AreaSource(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., nodal_plane_distribution=npd, hypocenter_distribution=hpd, polygon=pol, area_discretization=10.)
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) return rupture
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_set_a_when_b_equal_to_1_5(self): mfd = TruncatedGRMFD(min_mag=6.0, max_mag=8.0, bin_width=0.1, a_val=1.5, b_val=1.5) mfd._set_a(12.45) self.assertAlmostEqual(mfd.a_val, -8.4319519)
def test_set_a(self): mfd = TruncatedGRMFD(min_mag=6.0, max_mag=8.0, bin_width=0.1, a_val=1.5, b_val=0.5) mfd._set_a(123.45) self.assertAlmostEqual(mfd.a_val, -14.6531141)
def test_increment_max_mag_check_constraints(self): # pylint: disable=invalid-name mfd = TruncatedGRMFD(min_mag=6.0, max_mag=7.0, bin_width=0.1, a_val=1, b_val=1) self.assert_mfd_error(mfd.modify, 'increment_max_mag', {'value': -1})
def test_mesh_spacing_too_small(self): mfd = TruncatedGRMFD(a_val=0.5, b_val=1.0, min_mag=0.5, max_mag=1.5, bin_width=1.0) with self.assertRaises(ValueError) as ar: self._make_source(mfd=mfd, aspect_ratio=1.0) self.assertEqual(str(ar.exception), 'mesh spacing 1 is too high to represent ' 'ruptures of magnitude 1.5')
def test_set_ab(self): mfd = TruncatedGRMFD(min_mag=2.5, max_mag=3.5, bin_width=0.25, a_val=1, b_val=1.3) mfd.modify('set_ab', {'a_val': -4.2, 'b_val': 1.45}) self.assertEqual(mfd.max_mag, 3.5) self.assertEqual(mfd.a_val, -4.2) self.assertEqual(mfd.b_val, 1.45) self.assertEqual(mfd.min_mag, 2.5)
def test_fault_trace_intersects_itself(self): mfd = TruncatedGRMFD(a_val=0.5, b_val=1.0, min_mag=10, max_mag=20, bin_width=1.0) fault_trace = Line([Point(0, 0), Point(0, 1), Point(1, 1), Point(0, 0.5)]) with self.assertRaises(ValueError) as ar: self._make_source(mfd=mfd, aspect_ratio=1, fault_trace=fault_trace) self.assertEqual(str(ar.exception), 'fault trace intersects itself')
def test_set_max_mag(self): mfd = TruncatedGRMFD(min_mag=3.5, max_mag=5.5, bin_width=0.5, a_val=1, b_val=1.3) mfd.modify('set_max_mag', {'value': 4.2}) self.assertEqual(mfd.max_mag, 4.2) self.assertEqual(mfd.a_val, 1) self.assertEqual(mfd.b_val, 1.3) self.assertEqual(mfd.min_mag, 3.5)
def setUp(self): super(AreaSourceFilterSitesBySourceTestCase, self).setUp() mfd = TruncatedGRMFD(a_val=3, b_val=1, min_mag=1, max_mag=2, bin_width=1) self.source = make_area_source(self.POLYGON, discretization=1, mfd=mfd)