コード例 #1
0
ファイル: planar_test.py プロジェクト: angri/nhlib
 def test_dip_out_of_range(self):
     corners = [Point(0, -1, 1), Point(0, 1, 1),
                Point(0, 1, 2), Point(0, -1, 2)]
     msg = 'dip is out of range (0, 90]'
     self.assert_failed_creation(10, 0, 0, corners, ValueError, msg)
     self.assert_failed_creation(10, 0, 91, corners, ValueError, msg)
     self.assert_failed_creation(10, 0, -1, corners, ValueError, msg)
コード例 #2
0
ファイル: planar_test.py プロジェクト: angri/nhlib
 def test4_site_along_strike(self):
     surface = self._test1to7surface()
     sites = Mesh.from_points_list([Point(0.2, 0), Point(67.6, 0),
                                    Point(90.33, 0)])
     dists = surface.get_rx_distance(sites)
     expected_dists = [0] * 3
     self.assertTrue(numpy.allclose(dists, expected_dists))
コード例 #3
0
    def test_5_vertical_rupture(self):
        rupture = self._get_rupture(min_mag=5,
                                    max_mag=6,
                                    hypocenter_depth=9,
                                    aspect_ratio=2,
                                    dip=90,
                                    rupture_mesh_spacing=4)
        self.assertEqual(rupture.hypocenter, Point(0, 0, 9))

        surface = rupture.surface
        self._check_dimensions(surface,
                               7.9527072876705063,
                               3.9763536438352536,
                               delta=0.02)

        self.assertAlmostEqual(0,
                               surface.top_left.distance(
                                   Point(-0.0252862987308, -0.0252862962683,
                                         7.01182317808)),
                               places=5)
        self.assertAlmostEqual(0,
                               surface.top_right.distance(
                                   Point(0.0252862987308, 0.0252862962683,
                                         7.01182317808)),
                               places=5)
        self.assertAlmostEqual(0,
                               surface.bottom_left.distance(
                                   Point(-0.0252862987308, -0.0252862962683,
                                         10.9881768219)),
                               places=5)
        self.assertAlmostEqual(0,
                               surface.bottom_right.distance(
                                   Point(0.0252862987308, 0.0252862962683,
                                         10.9881768219)),
                               places=5)
コード例 #4
0
    def test_4_rupture_wider_than_seismogenic_layer(self):
        rupture = self._get_rupture(min_mag=7,
                                    max_mag=8,
                                    hypocenter_depth=9,
                                    aspect_ratio=1,
                                    dip=30,
                                    rupture_mesh_spacing=10)
        self.assertEqual(rupture.mag, 7.5)
        self.assertEqual(rupture.hypocenter, Point(0, 0, 9))

        surface = rupture.surface
        # in this test we need to increase the tolerance because the rupture
        # created is rather big and float imprecision starts to be noticeable
        self._check_dimensions(surface, 112.93848786315641, 28, delta=0.2)

        self.assertAlmostEqual(
            0,
            surface.top_left.distance(
                Point(-0.436201680751, -0.281993828512, 2.0)),
            delta=0.003)  # actual to expected distance is 296 cm
        self.assertAlmostEqual(0,
                               surface.top_right.distance(
                                   Point(0.282002000777, 0.43619639753, 2.0)),
                               delta=0.003)  # 52 cm
        self.assertAlmostEqual(0,
                               surface.bottom_left.distance(
                                   Point(-0.282002000777, -0.43619639753,
                                         16.0)),
                               delta=0.003)  # 133 cm
        self.assertAlmostEqual(0,
                               surface.bottom_right.distance(
                                   Point(0.436201680751, 0.281993828512,
                                         16.0)),
                               delta=0.003)  # 23 cm
コード例 #5
0
    def test_3_rupture_deeper_than_lower_seismogenic_depth(self):
        rupture = self._get_rupture(min_mag=5,
                                    max_mag=6,
                                    hypocenter_depth=15,
                                    aspect_ratio=1,
                                    dip=30,
                                    rupture_mesh_spacing=10)
        self.assertEqual(rupture.hypocenter, Point(0, 0, 15))

        surface = rupture.surface
        self._check_dimensions(surface, 5.623413252, 5.623413252, delta=0.02)
        self.assertAlmostEqual(0,
                               surface.top_left.distance(
                                   Point(-0.0378349744035, 0.00207474995049,
                                         13.188293374)),
                               places=5)
        self.assertAlmostEqual(0,
                               surface.top_right.distance(
                                   Point(-0.00207475040284, 0.0378349743787,
                                         13.188293374)),
                               places=5)
        self.assertAlmostEqual(0,
                               surface.bottom_left.distance(
                                   Point(-0.00686571229256, -0.028894512506,
                                         16.0)),
                               places=5)
        self.assertAlmostEqual(0,
                               surface.bottom_right.distance(
                                   Point(0.0288945127134, 0.0068657114195,
                                         16.0)),
                               places=5)
コード例 #6
0
    def test_1_rupture_is_inside(self):
        rupture = self._get_rupture(min_mag=5,
                                    max_mag=6,
                                    hypocenter_depth=8,
                                    aspect_ratio=1,
                                    dip=30,
                                    rupture_mesh_spacing=1)
        self.assertEqual(rupture.mag, 5.5)
        self.assertEqual(rupture.hypocenter, Point(0, 0, 8))
        self.assertAlmostEqual(rupture.occurrence_rate, 0.0009)

        surface = rupture.surface
        self._check_dimensions(surface, 5.623413252, 5.623413252, delta=0.01)
        self.assertAlmostEqual(0,
                               surface.top_left.distance(
                                   Point(-0.0333647435005, -0.00239548066924,
                                         6.59414668702)),
                               places=5)
        self.assertAlmostEqual(0,
                               surface.top_right.distance(
                                   Point(0.00239548107539, 0.0333647434713,
                                         6.59414668702)),
                               places=5)
        self.assertAlmostEqual(0,
                               surface.bottom_left.distance(
                                   Point(-0.00239548107539, -0.0333647434713,
                                         9.40585331298)),
                               places=5)
        self.assertAlmostEqual(0,
                               surface.bottom_right.distance(
                                   Point(0.0333647435005, 0.00239548066924,
                                         9.40585331298)),
                               places=5)
コード例 #7
0
    def test_2_rupture_shallower_than_upper_seismogenic_depth(self):
        rupture = self._get_rupture(min_mag=5,
                                    max_mag=6,
                                    hypocenter_depth=3,
                                    aspect_ratio=1,
                                    dip=30,
                                    rupture_mesh_spacing=10)
        self.assertEqual(rupture.mag, 5.5)
        self.assertEqual(rupture.hypocenter, Point(0, 0, 3))
        self.assertAlmostEqual(rupture.occurrence_rate, 0.0009)

        surface = rupture.surface
        self._check_dimensions(surface, 5.623413252, 5.623413252, delta=0.01)
        self.assertAlmostEqual(0,
                               surface.top_left.distance(
                                   Point(-0.0288945127134, -0.0068657114195,
                                         2.0)),
                               places=5)
        self.assertAlmostEqual(0,
                               surface.top_right.distance(
                                   Point(0.00686571229256, 0.028894512506,
                                         2.0)),
                               places=5)
        self.assertAlmostEqual(0,
                               surface.bottom_left.distance(
                                   Point(0.00207475040284, -0.0378349743787,
                                         4.81170662595)),
                               places=5)
        self.assertAlmostEqual(0,
                               surface.bottom_right.distance(
                                   Point(0.0378349744035, -0.00207474995049,
                                         4.81170662595)),
                               places=5)
コード例 #8
0
 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)
コード例 #9
0
def get_polygon_area_from_complex_fault_data(fault_top_edge,
                                             fault_bottom_edge):

    fault_top_edge = fault_top_edge.split()
    fault_top_edge = numpy.array(fault_top_edge, dtype=float).reshape(
        len(fault_top_edge) / 3, 3)
    fault_top_edge = Line([Point(v1, v2, v3) for v1, v2, v3 in fault_top_edge])

    fault_bottom_edge = fault_bottom_edge.split()
    fault_bottom_edge = numpy.array(fault_bottom_edge, dtype=float).reshape(
        len(fault_bottom_edge) / 3, 3)
    fault_bottom_edge = Line(
        [Point(v1, v2, v3) for v1, v2, v3 in fault_bottom_edge])

    # create complex fault surface
    surf = ComplexFaultSurface.from_fault_data(
        [fault_top_edge, fault_bottom_edge], mesh_spacing=10)

    # extract fault boundary
    polygon = []
    surf_mesh = surf.get_mesh()
    fault_boundary = surf_mesh._get_bounding_mesh()
    for lon, lat in zip(fault_boundary.lons, fault_boundary.lats):
        polygon.append([lon, lat])

    # compute surface area
    _, _, _, cell_area = (surf_mesh.get_cell_dimensions())
    area = numpy.sum(cell_area)

    return polygon, area
コード例 #10
0
    def setUp(self):
        super(PointSourceSourceFilterTestCase, self).setUp()
        self.sitecol = SiteCollection(self.SITES)

        self.source1 = make_point_source(
            mfd=EvenlyDiscretizedMFD(min_mag=5,
                                     bin_width=1,
                                     occurrence_rates=[1]),
            rupture_aspect_ratio=1.9,
            upper_seismogenic_depth=0,
            lower_seismogenic_depth=18.5,
            magnitude_scaling_relationship=PeerMSR(),
            nodal_plane_distribution=PMF([
                (0.5, NodalPlane(strike=1, dip=2, rake=3)),
                (0.5, NodalPlane(strike=1, dip=20, rake=3)),
            ]),
            location=Point(2.0, 0.0),
        )
        self.source2 = make_point_source(
            mfd=EvenlyDiscretizedMFD(min_mag=6.5,
                                     bin_width=1,
                                     occurrence_rates=[1]),
            rupture_aspect_ratio=0.5,
            upper_seismogenic_depth=0,
            lower_seismogenic_depth=18.5,
            magnitude_scaling_relationship=PeerMSR(),
            nodal_plane_distribution=PMF([
                (0.5, NodalPlane(strike=1, dip=10, rake=3)),
                (0.5, NodalPlane(strike=1, dip=20, rake=3)),
            ]),
            location=Point(2.0, 0.0),
        )
コード例 #11
0
 def test_dilated(self):
     source = make_area_source(Polygon(
         [Point(4, 6), Point(5, 6), Point(4, 5)]),
                               discretization=100)
     polygon = source.get_rupture_enclosing_polygon(dilation=5)
     elons = [
         3.8387562, 3.8395259, 3.8418396, 3.8456751, 3.8509956, 3.8577500,
         3.8658734, 3.8752878, 3.8859026, 3.8976158, 3.9103145, 3.9238767,
         3.9381718, 3.9530621, 3.9684044, 3.9840509, 3.9998509, 5.0001491,
         5.0159419, 5.0315815, 5.0469172, 5.0618016, 5.0760915, 5.0896495,
         5.1023453, 5.1140566, 5.1246711, 5.1340866, 5.1422127, 5.1489714,
         5.1542977, 5.1581407, 5.1604635, 5.1612438, 5.1604744, 5.1581627,
         5.1543311, 5.1490166, 5.1422703, 5.1341571, 5.1247551, 5.1141547,
         4.1141530, 4.1024651, 4.0897882, 4.0762448, 4.0619656, 4.0470884,
         4.0317568, 4.0161187, 4.0003251, 3.9845284, 3.9688809, 3.9535336,
         3.9386348, 3.9243281, 3.9107516, 3.8980364, 3.8863052, 3.8756714,
         3.8662375, 3.8580948, 3.8513218, 3.8459842, 3.8421334, 3.8398068,
         3.8390269
     ]
     elats = [
         5.9999784, 6.0156881, 6.0312472, 6.0465059, 6.0613173, 6.0755391,
         6.0890342, 6.1016728, 6.1133333, 6.1239034, 6.1332813, 6.1413768,
         6.1481120, 6.1534219, 6.1572555, 6.1595758, 6.1603605, 6.1603605,
         6.1595765, 6.1572583, 6.1534281, 6.1481229, 6.1413937, 6.1333052,
         6.1239352, 6.1133738, 6.1017226, 6.0890937, 6.0756085, 6.0613967,
         6.0465949, 6.0313455, 6.0157950, 6.0000929, 5.9843902, 5.9688377,
         5.9535850, 5.9387786, 5.9245607, 5.9110681, 5.8984302, 5.8867686,
         4.8869567, 4.8763401, 4.8669175, 4.8587797, 4.8520053, 4.8466598,
         4.8427945, 4.8404470, 4.8396398, 4.8403806, 4.8426625, 4.8464633,
         4.8517463, 4.8584606, 4.8665414, 4.8759108, 4.8864782, 4.8981417,
         4.9107887, 4.9242972, 4.9385367, 4.9533698, 4.9686533, 4.9842397,
         4.9999784
     ]
     numpy.testing.assert_allclose(polygon.lons, elons)
     numpy.testing.assert_allclose(polygon.lats, elats)
コード例 #12
0
ファイル: planar_test.py プロジェクト: angri/nhlib
 def test5_site_opposite_to_strike_direction(self):
     surface = self._test1to7surface()
     sites = Mesh.from_points_list([Point(-0.2, 0), Point(-67.6, 0),
                                    Point(-90.33, 0)])
     dists = surface.get_rx_distance(sites)
     expected_dists = [0] * 3
     self.assertTrue(numpy.allclose(dists, expected_dists))
コード例 #13
0
    def test_no_correlation_mean_and_intra_respected(self):
        mean1 = 10
        mean2 = 14
        inter = 1e-300
        intra1 = 0.2
        intra2 = 1.6
        p1 = Point(0, 0)
        p2 = Point(0, 0.3)
        sites = [Site(p1, mean1, False, inter, intra1),
                 Site(p2, mean2, False, inter, intra2)]
        self.sites = SiteCollection(sites)

        numpy.random.seed(41)
        cormo = JB2009CorrelationModel(vs30_clustering=False)
        lt_corma = cormo.get_lower_triangle_correlation_matrix(self.sites,
                                                               self.imt1)
        s1_intensity, s2_intensity = ground_motion_fields(
            self.rupture, self.sites, [self.imt1], self.gsim,
            truncation_level=None, realizations=6000,
            lt_correlation_matrices={self.imt1: lt_corma}
        )[self.imt1]

        self.assertAlmostEqual(s1_intensity.mean(), mean1, delta=1e-3)
        self.assertAlmostEqual(s2_intensity.mean(), mean2, delta=1e-3)
        self.assertAlmostEqual(s1_intensity.std(), intra1, delta=2e-3)
        self.assertAlmostEqual(s2_intensity.std(), intra2, delta=1e-2)
コード例 #14
0
ファイル: planar_test.py プロジェクト: angri/nhlib
 def test8_strike_of_45_degrees(self):
     corners = [Point(-0.05, -0.05, 8), Point(0.05, 0.05, 8),
                Point(0.05, 0.05, 9), Point(-0.05, -0.05, 9)]
     surface = PlanarSurface(1, 45, 60, *corners)
     sites = Mesh.from_points_list([Point(0.05, 0)])
     self.assertAlmostEqual(surface.get_rx_distance(sites)[0],
                            3.9313415355436705, places=4)
コード例 #15
0
ファイル: planar_test.py プロジェクト: angri/nhlib
class PlanarSurfaceGetClosestPointsTestCase(unittest.TestCase):
    corners = [Point(-0.1, -0.1, 0), Point(0.1, -0.1, 0),
               Point(0.1, 0.1, 2), Point(-0.1, 0.1, 2)]
    surface = PlanarSurface(10, 90, 45, *corners)

    def test_point_above_surface(self):
        sites = Mesh.from_points_list([Point(0, 0), Point(-0.03, 0.05, 0.5)])
        res = self.surface.get_closest_points(sites)
        self.assertIsInstance(res, Mesh)
        aae = numpy.testing.assert_almost_equal
        aae(res.lons, [0, -0.03], decimal=4)
        aae(res.lats, [-0.00081824,  0.04919223])
        aae(res.depths, [1.0113781, 1.50822185])

    def test_corner_is_closest(self):
        sites = Mesh.from_points_list(
            [Point(-0.11, 0.11), Point(0.14, -0.12, 10),
             Point(0.3, 0.2, 0.5), Point(-0.6, -0.6, 0.3)]
        )
        res = self.surface.get_closest_points(sites)
        aae = numpy.testing.assert_almost_equal
        aae(res.lons, [-0.1, 0.1, 0.1, -0.1], decimal=4)
        aae(res.lats, [0.1, -0.1, 0.1, -0.1])
        aae(res.depths, [2, 0, 2, 0], decimal=5)

    def test_top_or_bottom_edge_is_closest(self):
        sites = Mesh.from_points_list([Point(-0.04, -0.28, 0),
                                       Point(0.033, 0.15, 0)])
        res = self.surface.get_closest_points(sites)
        aae = numpy.testing.assert_almost_equal
        aae(res.lons, [-0.04, 0.033], decimal=5)
        aae(res.lats, [-0.1, 0.1], decimal=5)
        aae(res.depths, [0, 2], decimal=2)

    def test_left_or_right_edge_is_closest(self):
        sites = Mesh.from_points_list([Point(-0.24, -0.08, 0.55),
                                       Point(0.17, 0.07, 0)])
        res = self.surface.get_closest_points(sites)
        aae = numpy.testing.assert_almost_equal
        aae(res.lons, [-0.1, 0.1], decimal=5)
        aae(res.lats, [-0.08, 0.07], decimal=3)
        aae(res.depths, [0.20679306, 1.69185737])

    def test_against_mesh_to_mesh(self):
        corners = [Point(2.6, 3.7, 20), Point(2.90102155, 3.99961567, 20),
                   Point(3.2, 3.7, 75), Point(2.89905849, 3.40038407, 75)]
        surface = PlanarSurface(0.5, 45, 70, *corners)
        lons, lats = numpy.meshgrid(numpy.linspace(2.2, 3.6, 7),
                                    numpy.linspace(3.4, 4.2, 7))
        sites = Mesh(lons, lats, depths=None)

        res1 = surface.get_closest_points(sites)
        res2 = super(PlanarSurface, surface).get_closest_points(sites)

        aae = numpy.testing.assert_almost_equal
        # precision up to ~1 km
        aae(res1.lons, res2.lons, decimal=2)
        aae(res1.lats, res2.lats, decimal=2)
        aae(res1.depths, res2.depths, decimal=0)
コード例 #16
0
ファイル: planar_test.py プロジェクト: angri/nhlib
 def test_point_above_surface(self):
     sites = Mesh.from_points_list([Point(0, 0), Point(-0.03, 0.05, 0.5)])
     res = self.surface.get_closest_points(sites)
     self.assertIsInstance(res, Mesh)
     aae = numpy.testing.assert_almost_equal
     aae(res.lons, [0, -0.03], decimal=4)
     aae(res.lats, [-0.00081824,  0.04919223])
     aae(res.depths, [1.0113781, 1.50822185])
コード例 #17
0
ファイル: planar_test.py プロジェクト: angri/nhlib
 def test_top_or_bottom_edge_is_closest(self):
     sites = Mesh.from_points_list([Point(-0.04, -0.28, 0),
                                    Point(0.033, 0.15, 0)])
     res = self.surface.get_closest_points(sites)
     aae = numpy.testing.assert_almost_equal
     aae(res.lons, [-0.04, 0.033], decimal=5)
     aae(res.lats, [-0.1, 0.1], decimal=5)
     aae(res.depths, [0, 2], decimal=2)
コード例 #18
0
ファイル: planar_test.py プロジェクト: angri/nhlib
 def test_left_or_right_edge_is_closest(self):
     sites = Mesh.from_points_list([Point(-0.24, -0.08, 0.55),
                                    Point(0.17, 0.07, 0)])
     res = self.surface.get_closest_points(sites)
     aae = numpy.testing.assert_almost_equal
     aae(res.lons, [-0.1, 0.1], decimal=5)
     aae(res.lats, [-0.08, 0.07], decimal=3)
     aae(res.depths, [0.20679306, 1.69185737])
コード例 #19
0
ファイル: area.py プロジェクト: angri/nhlib
    def iter_ruptures(self, temporal_occurrence_model):
        """
        See :meth:`nhlib.source.base.SeismicSource.iter_ruptures`
        for description of parameters and return value.

        Area sources are treated as a collection of point sources
        (see :mod:`nhlib.source.point`) with uniform parameters.
        Ruptures of area source are just a union of ruptures
        of those point sources. The actual positions of the implied
        point sources form a uniformly spaced mesh on the polygon.
        Polygon's method :meth:`~nhlib.geo.polygon.Polygon.discretize`
        is used for creating a mesh of points on the source's area.
        Constructor's parameter ``area_discretization`` is used as
        polygon's discretization spacing (not to be confused with
        rupture surface's mesh spacing which is as well provided
        to the constructor).

        The ruptures' occurrence rates are rescaled with respect to number
        of points the polygon discretizes to.
        """
        polygon_mesh = self.polygon.discretize(self.area_discretization)
        rate_scaling_factor = 1.0 / len(polygon_mesh)

        # take the very first point of the polygon mesh
        [epicenter0] = polygon_mesh[0:1]
        # generate "reference ruptures" -- all the ruptures that have the same
        # epicenter location (first point of the polygon's mesh) but different
        # magnitudes, nodal planes, hypocenters' depths and occurrence rates
        ref_ruptures = []
        for (mag, mag_occ_rate) in self.get_annual_occurrence_rates():
            for (np_prob, np) in self.nodal_plane_distribution.data:
                for (hc_prob, hc_depth) in self.hypocenter_distribution.data:
                    hypocenter = Point(latitude=epicenter0.latitude,
                                       longitude=epicenter0.longitude,
                                       depth=hc_depth)
                    occurrence_rate = (mag_occ_rate
                                       * float(np_prob) * float(hc_prob))
                    occurrence_rate *= rate_scaling_factor
                    surface = self._get_rupture_surface(mag, np, hypocenter)
                    ref_ruptures.append((mag, np.rake, hc_depth,
                                         surface, occurrence_rate))

        # for each of the epicenter positions generate as many ruptures
        # as we generated "reference" ones: new ruptures differ only
        # in hypocenter and surface location
        for epicenter in polygon_mesh:
            for mag, rake, hc_depth, surface, occ_rate in ref_ruptures:
                # translate the surface from first epicenter position
                # to the target one preserving it's geometry
                surface = surface.translate(epicenter0, epicenter)
                hypocenter = epicenter
                hypocenter.depth = hc_depth
                rupture = ProbabilisticRupture(
                    mag, rake, self.tectonic_region_type, hypocenter,
                    surface, type(self), occ_rate, temporal_occurrence_model
                )
                yield rupture
コード例 #20
0
ファイル: area.py プロジェクト: pslh/nhlib
    def iter_ruptures(self, temporal_occurrence_model):
        """
        See :meth:`nhlib.source.base.SeismicSource.iter_ruptures`
        for description of parameters and return value.

        Area sources are treated as a collection of point sources
        (see :mod:`nhlib.source.point`) with uniform parameters.
        Ruptures of area source are just a union of ruptures
        of those point sources. The actual positions of the implied
        point sources form a uniformly spaced mesh on the polygon.
        Polygon's method :meth:`~nhlib.geo.polygon.Polygon.discretize`
        is used for creating a mesh of points on the source's area.
        Constructor's parameter ``area_discretization`` is used as
        polygon's discretization spacing (not to be confused with
        rupture surface's mesh spacing which is as well provided
        to the constructor).

        The ruptures' occurrence rates are rescaled with respect to number
        of points the polygon discretizes to.
        """
        polygon_mesh = self.polygon.discretize(self.area_discretization)
        rate_scaling_factor = 1.0 / len(polygon_mesh)

        # take the very first point of the polygon mesh
        [epicenter0] = polygon_mesh[0:1]
        # generate "reference ruptures" -- all the ruptures that have the same
        # epicenter location (first point of the polygon's mesh) but different
        # magnitudes, nodal planes, hypocenters' depths and occurrence rates
        ref_ruptures = []
        for (mag, mag_occ_rate) in self.get_annual_occurrence_rates():
            for (np_prob, np) in self.nodal_plane_distribution.data:
                for (hc_prob, hc_depth) in self.hypocenter_distribution.data:
                    hypocenter = Point(latitude=epicenter0.latitude,
                                       longitude=epicenter0.longitude,
                                       depth=hc_depth)
                    occurrence_rate = (mag_occ_rate
                                       * float(np_prob) * float(hc_prob))
                    occurrence_rate *= rate_scaling_factor
                    surface = self._get_rupture_surface(mag, np, hypocenter)
                    ref_ruptures.append((mag, np.rake, hc_depth,
                                         surface, occurrence_rate))

        # for each of the epicenter positions generate as many ruptures
        # as we generated "reference" ones: new ruptures differ only
        # in hypocenter and surface location
        for epicenter in polygon_mesh:
            for mag, rake, hc_depth, surface, occ_rate in ref_ruptures:
                # translate the surface from first epicenter position
                # to the target one preserving it's geometry
                surface = surface.translate(epicenter0, epicenter)
                hypocenter = epicenter
                hypocenter.depth = hc_depth
                rupture = ProbabilisticRupture(
                    mag, rake, self.tectonic_region_type, hypocenter,
                    surface, occ_rate, temporal_occurrence_model
                )
                yield rupture
コード例 #21
0
ファイル: base_test.py プロジェクト: angri/nhlib
 def test_source_filter_filter_all_out(self):
     col = SiteCollection([
         Site(Point(10, 10), 1, True, 2, 3),
         Site(Point(11, 12), 2, True, 2, 3),
         Site(Point(13, 14), 1, True, 2, 3)
     ])
     for int_dist in (0, 1, 10, 100, 1000):
         filtered = self.source.filter_sites_by_distance_to_source(
             integration_distance=int_dist, sites=col)
         self.assertIs(filtered, None)
コード例 #22
0
ファイル: planar_test.py プロジェクト: angri/nhlib
 def test_corner_is_closest(self):
     sites = Mesh.from_points_list(
         [Point(-0.11, 0.11), Point(0.14, -0.12, 10),
          Point(0.3, 0.2, 0.5), Point(-0.6, -0.6, 0.3)]
     )
     res = self.surface.get_closest_points(sites)
     aae = numpy.testing.assert_almost_equal
     aae(res.lons, [-0.1, 0.1, 0.1, -0.1], decimal=4)
     aae(res.lats, [0.1, -0.1, 0.1, -0.1])
     aae(res.depths, [2, 0, 2, 0], decimal=5)
コード例 #23
0
class JB2009LowerTriangleCorrelationMatrixTestCase(unittest.TestCase):
    SITECOL = SiteCollection([
        Site(Point(2, -40), 1, True, 1, 1),
        Site(Point(2, -40.1), 1, True, 1, 1),
        Site(Point(2, -39.9), 1, True, 1, 1)
    ])

    def test(self):
        cormo = JB2009CorrelationModel(vs30_clustering=False)
        lt = cormo.get_lower_triangle_correlation_matrix(self.SITECOL, PGA())
        aaae(lt, [[1.0, 0.0, 0.0], [1.97514806e-02, 9.99804920e-01, 0.0],
                  [1.97514806e-02, 5.42206860e-20, 9.99804920e-01]])
コード例 #24
0
ファイル: planar_test.py プロジェクト: angri/nhlib
 def test2(self):
     surface = PlanarSurface(
         10, 20, 30,
         Point(3.9, 2.2, 10), Point(4.90402718, 3.19634248, 10),
         Point(5.9, 2.2, 90), Point(4.89746275, 1.20365263, 90)
     )
     plons, plats, pdepths = [[4., 4.3, 3.1], [1.5, 1.7, 3.5],
                              [11., 12., 13.]]
     dists, xx, yy =  surface._project(plons, plats, pdepths)
     lons, lats, depths = surface._project_back(dists, xx, yy)
     aaae = numpy.testing.assert_array_almost_equal
     aaae(lons, plons)
     aaae(lats, plats)
     aaae(depths, pdepths)
コード例 #25
0
ファイル: point.py プロジェクト: angri/nhlib
 def filter_sites_by_distance_to_rupture(cls, rupture, integration_distance,
                                         sites):
     """
     Filter sites that are closer than rupture's projection radius
     plus integration distance along the great circle arc from rupture's
     epicenter location. Overrides the :meth:`base class' method
     <nhlib.source.base.SeismicSource.filter_sites_by_distance_to_rupture>`.
     """
     rup_length, rup_width = rupture.surface.length, rupture.surface.width
     rup_width = rup_width * math.cos(math.radians(rupture.surface.dip))
     radius = math.sqrt(rup_length ** 2 + rup_width ** 2) / 2.0
     radius += integration_distance
     epicenter = Point(rupture.hypocenter.longitude,
                       rupture.hypocenter.latitude)
     return sites.filter(epicenter.closer_than(sites.mesh, radius))
コード例 #26
0
 def filter_sites_by_distance_to_rupture(cls, rupture, integration_distance,
                                         sites):
     """
     Filter sites that are closer than rupture's projection radius
     plus integration distance along the great circle arc from rupture's
     epicenter location. Overrides the :meth:`base class' method
     <nhlib.source.base.SeismicSource.filter_sites_by_distance_to_rupture>`.
     """
     rup_length, rup_width = rupture.surface.length, rupture.surface.width
     rup_width = rup_width * math.cos(math.radians(rupture.surface.dip))
     radius = math.sqrt(rup_length**2 + rup_width**2) / 2.0
     radius += integration_distance
     epicenter = Point(rupture.hypocenter.longitude,
                       rupture.hypocenter.latitude)
     return sites.filter(epicenter.closer_than(sites.mesh, radius))
コード例 #27
0
ファイル: planar_test.py プロジェクト: angri/nhlib
    def test_against_mesh_to_mesh(self):
        corners = [Point(2.6, 3.7, 20), Point(2.90102155, 3.99961567, 20),
                   Point(3.2, 3.7, 75), Point(2.89905849, 3.40038407, 75)]
        surface = PlanarSurface(0.5, 45, 70, *corners)
        lons, lats = numpy.meshgrid(numpy.linspace(2.2, 3.6, 7),
                                    numpy.linspace(3.4, 4.2, 7))
        sites = Mesh(lons, lats, depths=None)

        res1 = surface.get_closest_points(sites)
        res2 = super(PlanarSurface, surface).get_closest_points(sites)

        aae = numpy.testing.assert_almost_equal
        # precision up to ~1 km
        aae(res1.lons, res2.lons, decimal=2)
        aae(res1.lats, res2.lats, decimal=2)
        aae(res1.depths, res2.depths, decimal=0)
コード例 #28
0
 def test_occurrence_rate_rescaling(self):
     mfd = EvenlyDiscretizedMFD(min_mag=4,
                                bin_width=1,
                                occurrence_rates=[3])
     polygon = Polygon([
         Point(0, 0),
         Point(0, -0.2248),
         Point(-0.2248, -0.2248),
         Point(-0.2248, 0)
     ])
     source = self.make_area_source(polygon, discretization=10, mfd=mfd)
     self.assertIs(source.mfd, mfd)
     ruptures = list(source.iter_ruptures(PoissonTOM(1)))
     self.assertEqual(len(ruptures), 4)
     for rupture in ruptures:
         self.assertNotEqual(rupture.occurrence_rate, 3)
         self.assertEqual(rupture.occurrence_rate, 3.0 / 4.0)
コード例 #29
0
ファイル: planar_test.py プロジェクト: angri/nhlib
 def test_edges_azimuths_cross_north_direction(self):
     self.assert_successfull_creation(
         10, 150, 45,
         Point(-0.0001, 0, 1), Point(0.0001, -1, 1),
         Point(-0.0001, -1, 2), Point(0.0001, 0, 2)
     )
     self.assert_successfull_creation(
         1, 2, 3,
         Point(0.0001, 0, 1), Point(-0.0001, -1, 1),
         Point(0.0001, -1, 2), Point(-0.0001, 0, 2)
     )
コード例 #30
0
ファイル: planar_test.py プロジェクト: angri/nhlib
 def test_point_inside(self):
     corners = [Point(-1, -1, 1), Point(1, -1, 1),
                Point(1, 1, 2), Point(-1, 1, 2)]
     surface = PlanarSurface(10, 90, 45, *corners)
     sites = Mesh.from_points_list([Point(0, 0), Point(0, 0, 20),
                                    Point(0.1, 0.3)])
     dists = surface.get_joyner_boore_distance(sites)
     expected_dists = [0] * 3
     self.assertTrue(numpy.allclose(dists, expected_dists))
コード例 #31
0
ファイル: complex_fault_test.py プロジェクト: angri/nhlib
 def _make_source(self, mfd, aspect_ratio, rupture_mesh_spacing, edges):
     source_id = name = 'test-source'
     trt = self.TRT
     rake = self.RAKE
     magnitude_scaling_relationship = PeerMSR()
     rupture_aspect_ratio = aspect_ratio
     edges = [Line([Point(*coords) for coords in edge]) for edge in edges]
     return ComplexFaultSource(source_id, name, trt, mfd,
                               rupture_mesh_spacing,
                               magnitude_scaling_relationship,
                               rupture_aspect_ratio, edges, rake)
コード例 #32
0
ファイル: planar.py プロジェクト: angri/nhlib
 def _get_top_edge_centroid(self):
     """
     Overrides :meth:`superclass' method
     <nhlib.geo.surface.base.BaseSurface._get_top_edge_centroid>`
     in order to avoid creating a mesh.
     """
     lon, lat = geo_utils.get_middle_point(
         self.corner_lons[0], self.corner_lats[0],
         self.corner_lons[1], self.corner_lats[1]
     )
     return Point(lon, lat, self.corner_depths[0])
コード例 #33
0
ファイル: point_test.py プロジェクト: angri/nhlib
class PointSourceRuptureFilterTestCase(unittest.TestCase):
    SITES = PointSourceSourceFilterTestCase.SITES

    def setUp(self):
        super(PointSourceRuptureFilterTestCase, self).setUp()
        self.hypocenter = Point(2, 0, 50)
        self.sitecol = SiteCollection(self.SITES)

    def _make_rupture(self, width, length, dip):
        mid_left = self.hypocenter.point_at(length / 2.0, 0, azimuth=270)
        mid_right = self.hypocenter.point_at(length / 2.0, 0, azimuth=90)
        hwidth = width * numpy.cos(numpy.radians(dip)) / 2.0
        vwidth = width * numpy.sin(numpy.radians(dip)) / 2.0
        top_left = mid_left.point_at(hwidth, -vwidth, azimuth=0)
        bottom_left = mid_left.point_at(hwidth, vwidth, azimuth=180)
        top_right = mid_right.point_at(hwidth, -vwidth, azimuth=0)
        bottom_right = mid_right.point_at(hwidth, vwidth, azimuth=180)
        surface = PlanarSurface(1, 2, dip, top_left, top_right,
                                bottom_right, bottom_left)
        rupture = ProbabilisticRupture(
            mag=1, rake=2, tectonic_region_type=TRT.VOLCANIC,
            hypocenter=self.hypocenter, surface=surface,
            source_typology=PointSource, occurrence_rate=3,
            temporal_occurrence_model=PoissonTOM(1)
        )
        return rupture

    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])

    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)

    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)
コード例 #34
0
ファイル: point_test.py プロジェクト: angri/nhlib
 def setUp(self):
     super(PointSourceRuptureFilterTestCase, self).setUp()
     self.hypocenter = Point(2, 0, 50)
     self.sitecol = SiteCollection(self.SITES)