Example #1
0
 def _get_rupture(self, min_mag, max_mag, hypocenter_depth,
                  aspect_ratio, dip, rupture_mesh_spacing):
     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)])
     upper_seismogenic_depth = 2
     lower_seismogenic_depth = 16
     magnitude_scaling_relationship = PeerMSR()
     rupture_aspect_ratio = aspect_ratio
     point_source = PointSource(
         source_id, name, trt, mfd, rupture_mesh_spacing,
         magnitude_scaling_relationship, rupture_aspect_ratio,
         upper_seismogenic_depth, lower_seismogenic_depth,
         location, nodal_plane_distribution, hypocenter_distribution
     )
     tom = PoissonTOM(time_span=50)
     ruptures = list(point_source.iter_ruptures(tom))
     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
Example #2
0
    def test_495_km(self):
        rup = self._make_rupture(5, 8, 5)  # 4.68 km radius
        filtered = PointSource.filter_sites_by_distance_to_rupture(
            rup, integration_distance=495, sites=self.sitecol)
        numpy.testing.assert_array_equal(filtered.indices, [0, 1, 2, 3])

        rup = self._make_rupture(7, 10, 30)  # 5.8 km radius
        filtered = PointSource.filter_sites_by_distance_to_rupture(
            rup, integration_distance=495, sites=self.sitecol)
        self.assertIs(filtered.indices, None)
        self.assertIs(filtered, self.sitecol)
Example #3
0
    def test_zero_integration_distance(self):
        rup = self._make_rupture(10, 15, 45)  # 8 km radius
        filtered = PointSource.filter_sites_by_distance_to_rupture(
            rup, integration_distance=0, sites=self.sitecol)
        self.assertIsInstance(filtered, SiteCollection)
        self.assertIsNot(filtered, self.sitecol)
        numpy.testing.assert_array_equal(filtered.indices, [0])
        numpy.testing.assert_array_equal(filtered.vs30, [0.1])

        rup = self._make_rupture(50, 30, 90)  # 14.8 km radius
        filtered = PointSource.filter_sites_by_distance_to_rupture(
            rup, integration_distance=0, sites=self.sitecol)
        numpy.testing.assert_array_equal(filtered.indices, [0, 1])
Example #4
0
    def test_495_km(self):
        rup = self._make_rupture(5, 8, 5)  # 4.68 km radius
        filtered = PointSource.filter_sites_by_distance_to_rupture(
            rup, integration_distance=495, sites=self.sitecol
        )
        numpy.testing.assert_array_equal(filtered.indices, [0, 1, 2, 3])

        rup = self._make_rupture(7, 10, 30)  # 5.8 km radius
        filtered = PointSource.filter_sites_by_distance_to_rupture(
            rup, integration_distance=495, sites=self.sitecol
        )
        self.assertIs(filtered.indices, None)
        self.assertIs(filtered, self.sitecol)
Example #5
0
    def test_zero_integration_distance(self):
        rup = self._make_rupture(10, 15, 45)  # 8 km radius
        filtered = PointSource.filter_sites_by_distance_to_rupture(
            rup, integration_distance=0, sites=self.sitecol
        )
        self.assertIsInstance(filtered, SiteCollection)
        self.assertIsNot(filtered, self.sitecol)
        numpy.testing.assert_array_equal(filtered.indices, [0])
        numpy.testing.assert_array_equal(filtered.vs30, [0.1])

        rup = self._make_rupture(50, 30, 90)  # 14.8 km radius
        filtered = PointSource.filter_sites_by_distance_to_rupture(
            rup, integration_distance=0, sites=self.sitecol
        )
        numpy.testing.assert_array_equal(filtered.indices, [0, 1])
Example #6
0
 def test_filter_all_out(self):
     rup = self._make_rupture(50, 80, 9)  # 46.64 km radius
     self.hypocenter.longitude = 11.515
     for int_dist in (0, 1, 10, 100, 1000):
         filtered = PointSource.filter_sites_by_distance_to_rupture(
             rup, integration_distance=int_dist, sites=self.sitecol)
         self.assertIs(filtered, None)
Example #7
0
 def test_filter_all_out(self):
     rup = self._make_rupture(50, 80, 9)  # 46.64 km radius
     self.hypocenter.longitude = 11.515
     for int_dist in (0, 1, 10, 100, 1000):
         filtered = PointSource.filter_sites_by_distance_to_rupture(
             rup, integration_distance=int_dist, sites=self.sitecol
         )
         self.assertIs(filtered, None)
Example #8
0
 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
     point_source = PointSource(
         source_id, name, trt, mfd, rupture_mesh_spacing,
         magnitude_scaling_relationship, rupture_aspect_ratio,
         upper_seismogenic_depth, lower_seismogenic_depth, location,
         nodal_plane_distribution, hypocenter_distribution)
     tom = PoissonTOM(time_span=50)
     ruptures = list(point_source.iter_ruptures(tom))
     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
Example #9
0
def make_point_source(**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(1.2, 3.4, 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
    }
    default_arguments.update(kwargs)
    kwargs = default_arguments
    return PointSource(**kwargs)
Example #10
0
    def test_7_many_ruptures(self):
        source_id = name = 'test7-source'
        trt = TRT.VOLCANIC
        mag1 = 4.5
        mag2 = 5.5
        mag1_rate = 9e-3
        mag2_rate = 9e-4
        hypocenter1 = 9.0
        hypocenter2 = 10.0
        hypocenter1_weight = Decimal('0.8')
        hypocenter2_weight = Decimal('0.2')
        nodalplane1 = NodalPlane(strike=45, dip=90, rake=0)
        nodalplane2 = NodalPlane(strike=0, dip=45, rake=10)
        nodalplane1_weight = Decimal('0.3')
        nodalplane2_weight = Decimal('0.7')
        upper_seismogenic_depth = 2
        lower_seismogenic_depth = 16
        rupture_aspect_ratio = 2
        rupture_mesh_spacing = 0.5
        location = Point(0, 0)
        magnitude_scaling_relationship = PeerMSR()
        tom = PoissonTOM(time_span=50)

        mfd = EvenlyDiscretizedMFD(min_mag=mag1,
                                   bin_width=(mag2 - mag1),
                                   occurrence_rates=[mag1_rate, mag2_rate])
        nodal_plane_distribution = PMF([(nodalplane1_weight, nodalplane1),
                                        (nodalplane2_weight, nodalplane2)])
        hypocenter_distribution = PMF([(hypocenter1_weight, hypocenter1),
                                       (hypocenter2_weight, hypocenter2)])
        point_source = PointSource(
            source_id, name, trt, mfd, rupture_mesh_spacing,
            magnitude_scaling_relationship, rupture_aspect_ratio,
            upper_seismogenic_depth, lower_seismogenic_depth, location,
            nodal_plane_distribution, hypocenter_distribution)
        actual_ruptures = list(point_source.iter_ruptures(tom))
        self.assertEqual(len(actual_ruptures), 8)
        expected_ruptures = {
            (mag1, nodalplane1.rake, hypocenter1): (
                # probabilistic rupture's occurrence rate
                9e-3 * 0.3 * 0.8,
                # rupture surface corners
                planar_surface_test_data.TEST_7_RUPTURE_1_CORNERS),
            (mag2, nodalplane1.rake, hypocenter1):
            (9e-4 * 0.3 * 0.8,
             planar_surface_test_data.TEST_7_RUPTURE_2_CORNERS),
            (mag1, nodalplane2.rake, hypocenter1):
            (9e-3 * 0.7 * 0.8,
             planar_surface_test_data.TEST_7_RUPTURE_3_CORNERS),
            (mag2, nodalplane2.rake, hypocenter1):
            (9e-4 * 0.7 * 0.8,
             planar_surface_test_data.TEST_7_RUPTURE_4_CORNERS),
            (mag1, nodalplane1.rake, hypocenter2):
            (9e-3 * 0.3 * 0.2,
             planar_surface_test_data.TEST_7_RUPTURE_5_CORNERS),
            (mag2, nodalplane1.rake, hypocenter2):
            (9e-4 * 0.3 * 0.2,
             planar_surface_test_data.TEST_7_RUPTURE_6_CORNERS),
            (mag1, nodalplane2.rake, hypocenter2):
            (9e-3 * 0.7 * 0.2,
             planar_surface_test_data.TEST_7_RUPTURE_7_CORNERS),
            (mag2, nodalplane2.rake, hypocenter2):
            (9e-4 * 0.7 * 0.2,
             planar_surface_test_data.TEST_7_RUPTURE_8_CORNERS)
        }
        for actual_rupture in actual_ruptures:
            expected_occurrence_rate, expected_corners = expected_ruptures[(
                actual_rupture.mag, actual_rupture.rake,
                actual_rupture.hypocenter.depth)]
            self.assertTrue(isinstance(actual_rupture, ProbabilisticRupture))
            self.assertEqual(actual_rupture.occurrence_rate,
                             expected_occurrence_rate)
            self.assertIs(actual_rupture.temporal_occurrence_model, tom)
            self.assertEqual(actual_rupture.tectonic_region_type, trt)
            surface = actual_rupture.surface

            tl, tr, br, bl = expected_corners
            self.assertEqual(tl, surface.top_left)
            self.assertEqual(tr, surface.top_right)
            self.assertEqual(bl, surface.bottom_left)
            self.assertEqual(br, surface.bottom_right)
Example #11
0
    def test_7_many_ruptures(self):
        source_id = name = 'test7-source'
        trt = TRT.VOLCANIC
        mag1 = 4.5
        mag2 = 5.5
        mag1_rate = 9e-3
        mag2_rate = 9e-4
        hypocenter1 = 9.0
        hypocenter2 = 10.0
        hypocenter1_weight = Decimal('0.8')
        hypocenter2_weight = Decimal('0.2')
        nodalplane1 = NodalPlane(strike=45, dip=90, rake=0)
        nodalplane2 = NodalPlane(strike=0, dip=45, rake=10)
        nodalplane1_weight = Decimal('0.3')
        nodalplane2_weight = Decimal('0.7')
        upper_seismogenic_depth = 2
        lower_seismogenic_depth = 16
        rupture_aspect_ratio = 2
        rupture_mesh_spacing = 0.5
        location = Point(0, 0)
        magnitude_scaling_relationship = PeerMSR()
        tom = PoissonTOM(time_span=50)

        mfd = EvenlyDiscretizedMFD(min_mag=mag1, bin_width=(mag2 - mag1),
                                   occurrence_rates=[mag1_rate, mag2_rate])
        nodal_plane_distribution = PMF([(nodalplane1_weight, nodalplane1),
                                        (nodalplane2_weight, nodalplane2)])
        hypocenter_distribution = PMF([(hypocenter1_weight, hypocenter1),
                                       (hypocenter2_weight, hypocenter2)])
        point_source = PointSource(
            source_id, name, trt, mfd, rupture_mesh_spacing,
            magnitude_scaling_relationship, rupture_aspect_ratio,
            upper_seismogenic_depth, lower_seismogenic_depth,
            location, nodal_plane_distribution, hypocenter_distribution
        )
        actual_ruptures = list(point_source.iter_ruptures(tom))
        self.assertEqual(len(actual_ruptures), 8)
        expected_ruptures = {
            (mag1, nodalplane1.rake, hypocenter1): (
                # probabilistic rupture's occurrence rate
                9e-3 * 0.3 * 0.8,
                # rupture surface corners
                planar_surface_test_data.TEST_7_RUPTURE_1_CORNERS
            ),
            (mag2, nodalplane1.rake, hypocenter1): (
                9e-4 * 0.3 * 0.8,
                planar_surface_test_data.TEST_7_RUPTURE_2_CORNERS
            ),
            (mag1, nodalplane2.rake, hypocenter1): (
                9e-3 * 0.7 * 0.8,
                planar_surface_test_data.TEST_7_RUPTURE_3_CORNERS
            ),
            (mag2, nodalplane2.rake, hypocenter1): (
                9e-4 * 0.7 * 0.8,
                planar_surface_test_data.TEST_7_RUPTURE_4_CORNERS
            ),
            (mag1, nodalplane1.rake, hypocenter2): (
                9e-3 * 0.3 * 0.2,
                planar_surface_test_data.TEST_7_RUPTURE_5_CORNERS
            ),
            (mag2, nodalplane1.rake, hypocenter2): (
                9e-4 * 0.3 * 0.2,
                planar_surface_test_data.TEST_7_RUPTURE_6_CORNERS
            ),
            (mag1, nodalplane2.rake, hypocenter2): (
                9e-3 * 0.7 * 0.2,
                planar_surface_test_data.TEST_7_RUPTURE_7_CORNERS
            ),
            (mag2, nodalplane2.rake, hypocenter2): (
                9e-4 * 0.7 * 0.2,
                planar_surface_test_data.TEST_7_RUPTURE_8_CORNERS
            )
        }
        for actual_rupture in actual_ruptures:
            expected_occurrence_rate, expected_corners = expected_ruptures[
                (actual_rupture.mag, actual_rupture.rake,
                 actual_rupture.hypocenter.depth)
            ]
            self.assertTrue(isinstance(actual_rupture, ProbabilisticRupture))
            self.assertEqual(actual_rupture.occurrence_rate,
                             expected_occurrence_rate)
            self.assertIs(actual_rupture.temporal_occurrence_model, tom)
            self.assertEqual(actual_rupture.tectonic_region_type, trt)
            surface = actual_rupture.surface

            tl, tr, br, bl = expected_corners
            self.assertEqual(tl, surface.top_left)
            self.assertEqual(tr, surface.top_right)
            self.assertEqual(bl, surface.bottom_left)
            self.assertEqual(br, surface.bottom_right)