Esempio n. 1
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),
        )
Esempio n. 2
0
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
Esempio n. 3
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
     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
Esempio n. 4
0
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 _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
Esempio n. 6
0
 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)
Esempio n. 7
0
    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.grp_id, mps.grp_id)

        got = obj_to_node(mps).to_str()
        print(got)
        exp = '''\
multiPointSource{id='mp1', name='multi point source'}
  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]

        # test the bounding box
        bbox = mps.get_bounding_box(maxdist=100)
        numpy.testing.assert_almost_equal(
            (-0.8994569916564479, -0.39932, 1.8994569916564479, 1.89932),
            bbox)
 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]
     cfs = ComplexFaultSource(source_id, name, trt, mfd,
                              rupture_mesh_spacing,
                              magnitude_scaling_relationship,
                              rupture_aspect_ratio, edges, rake)
     assert_pickleable(cfs)
     return cfs
Esempio n. 9
0
    def setUp(self):
        class FakeSource(SeismicSource):
            iter_ruptures = None
            get_rupture_enclosing_polygon = None

        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)
        self.sitecol = SiteCollection(self.SITES)
Esempio n. 10
0
    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}
''')
Esempio n. 11
0
    def setUp(self):
        class FakeSource(ParametricSeismicSource):
            MODIFICATIONS = set(())
            iter_ruptures = None
            count_ruptures = None
            get_rupture_enclosing_polygon = None

        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)
Esempio n. 12
0
                         1.0,
                         PoissonTOM(1.0),
                         0.,
                         40.,
                         PMF([(1.0, NodalPlane(0.0, 90.0, 0.0))]),
                         PMF([(0.5, 5.0), (0.5, 15.0)]),
                         AREA_POLY,
                         4.0)

SIMPLE_TRACE = Line([Point(14.975, 15.0, 0.0), Point(15.025, 15.0, 0.0)])

SIMPLE_FAULT = SimpleFaultSource("SFLT000", "Simple Fault Source",
                                 "Active Shallow Crust",
                                 EvenlyDiscretizedMFD(7.0, 0.1, [1.0]),
                                 1.0,
                                 PeerMSR(),
                                 1.0,
                                 PoissonTOM(1.0),
                                 0.0,
                                 20.0,
                                 SIMPLE_TRACE,
                                 90.,
                                 0.0)

COMPLEX_EDGES = [SIMPLE_TRACE,
                 Line([Point(14.975, 15.0, 20.0),
                       Point(15.025, 15.0, 20.0)])]

COMPLEX_FAULT = ComplexFaultSource("CFLT000", "Complex Fault Source",
                                   "Active Shallow Crust",
                                   EvenlyDiscretizedMFD(7.0, 0.1, [1.0]),
Esempio n. 13
0
    Point(15.05, 14.95),
    Point(14.95, 14.95)
])

AREA_SOURCE = AreaSource("AREA000", "Area 000", "Active Shallow Crust",
                         EvenlyDiscretizedMFD(5.0, 0.1, [1.0]), 1.0,
                         PointMSR(), 1.0, PoissonTOM(1.0), 0., 40.,
                         PMF([(1.0, NodalPlane(0.0, 90.0, 0.0))]),
                         PMF([(0.5, 5.0), (0.5, 15.0)]), AREA_POLY, 4.0)

SIMPLE_TRACE = Line([Point(14.975, 15.0, 0.0), Point(15.025, 15.0, 0.0)])

SIMPLE_FAULT = SimpleFaultSource("SFLT000", "Simple Fault Source",
                                 "Active Shallow Crust",
                                 EvenlyDiscretizedMFD(7.0, 0.1, [1.0]), 1.0,
                                 PeerMSR(), 1.0, PoissonTOM(1.0), 0.0, 20.0,
                                 SIMPLE_TRACE, 90., 0.0)

COMPLEX_EDGES = [
    SIMPLE_TRACE,
    Line([Point(14.975, 15.0, 20.0),
          Point(15.025, 15.0, 20.0)])
]

COMPLEX_FAULT = ComplexFaultSource("CFLT000", "Complex Fault Source",
                                   "Active Shallow Crust",
                                   EvenlyDiscretizedMFD(7.0, 0.1, [1.0]), 1.0,
                                   PeerMSR(), 1.0, PoissonTOM(1.0),
                                   COMPLEX_EDGES, 0.0)

SIMPLE_FAULT_SURFACE = SimpleFaultSurface.from_fault_data(
Esempio n. 14
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, tom,
            upper_seismogenic_depth, lower_seismogenic_depth, location,
            nodal_plane_distribution, hypocenter_distribution)
        actual_ruptures = list(point_source.iter_ruptures())
        self.assertEqual(len(actual_ruptures), point_source.count_ruptures())
        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, ParametricProbabilisticRupture))
            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)
Esempio n. 15
0
    "NS": 70.,  # Normal with strike-slip component
    "TS": 45.,  # Reverse with strike-slip component
    "O": 90.0
}


# mean utilities (geometric, arithmetic, ...):
SCALAR_XY = {
    "Geometric": lambda x, y: np.sqrt(x * y),
    "Arithmetic": lambda x, y: (x + y) / 2.,
    "Larger": lambda x, y: np.max(np.array([x, y]), axis=0),
    "Vectorial": lambda x, y: np.sqrt(x ** 2. + y ** 2.)
}


DEFAULT_MSR = PeerMSR()


def get_interpolated_period(target_period, periods, values):
    """
    Returns the spectra interpolated in loglog space

    :param float target_period: Period required for interpolation
    :param np.ndarray periods: Spectral Periods
    :param np.ndarray values: Ground motion values
    """
    if (target_period < np.min(periods)) or (target_period > np.max(periods)):
        raise ValueError("Period not within calculated range: %s" %
                         str(target_period))
    lval = np.where(periods <= target_period)[0][-1]
    uval = np.where(periods >= target_period)[0][0]