Пример #1
0
 def test(self):
     evenly_discretized = EvenlyDiscretizedMFD(
         min_mag=0.2, bin_width=0.3, occurrence_rates=[2.1, 2.4, 5.3]
     )
     self.assertEqual(evenly_discretized.get_annual_occurrence_rates(),
                      [(0.2, 2.1), (0.5, 2.4), (0.8, 5.3)])
     self.assertEqual(evenly_discretized.get_min_mag(), 0.2)
Пример #2
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),
        )
 def test(self):
     evenly_discretized = EvenlyDiscretizedMFD(
         min_mag=0.2, bin_width=0.3, occurrence_rates=[2.1, 2.4, 5.3]
     )
     self.assertEqual(evenly_discretized.get_annual_occurrence_rates(),
                      [(0.2, 2.1), (0.5, 2.4), (0.8, 5.3)])
     self.assertEqual(evenly_discretized.get_min_max_mag(), (0.2, 0.8))
 def test_modify_mfd(self):
     mfd = EvenlyDiscretizedMFD(min_mag=4.0, bin_width=0.1,
                                occurrence_rates=[1, 2, 3])
     mfd.modify(
         "set_mfd",
         {"min_mag": 4.5, "bin_width": 0.2, "occurrence_rates": [4, 5, 6]})
     self.assertAlmostEqual(mfd.min_mag, 4.5)
     self.assertAlmostEqual(mfd.bin_width, 0.2)
     self.assertListEqual(mfd.occurrence_rates, [4, 5, 6])
 def test_modify_mfd(self):
     mfd = EvenlyDiscretizedMFD(min_mag=4.0, bin_width=0.1,
                                occurrence_rates=[1, 2, 3])
     mfd.modify(
         "set_mfd",
         {"min_mag": 4.5, "bin_width": 0.2, "occurrence_rates": [4, 5, 6]})
     self.assertAlmostEqual(mfd.min_mag, 4.5)
     self.assertAlmostEqual(mfd.bin_width, 0.2)
     self.assertListEqual(mfd.occurrence_rates, [4, 5, 6])
Пример #6
0
    def setUp(self):
        self.mfd = EvenlyDiscretizedMFD(4.4, 0.1, [0.5, 0.4, 0.3, 0.2])
        self.mfd1 = EvenlyDiscretizedMFD(4.4, 0.1, [0.5, 0.4])
        self.mfd2 = EvenlyDiscretizedMFD(4.05, 0.1, [0.5, 0.4])

        # This is the MFD for source HUAS082 in the SHARE (2013) model
        # with just area sources
        rates = [0.000890073609248, 0.000561598480883, 0.000354344686162,
                 0.000223576382212, 0.000141067160409, 8.90073609248e-05,
                 5.61598480883e-05, 3.54344686162e-05, 2.23576382212e-05,
                 1.41067160409e-05, 8.90073609248e-06, 2.8088205502e-06,
                 3.54240181229e-07, 2.23510444056e-07]
        self.mfd3 = EvenlyDiscretizedMFD(4.7, 0.2, rates)
Пример #7
0
def _setup_fault_source():
    """
    Builds a fault source using the PEER Bending Fault case.
    """
    point_order_dipping_east = [
        Point(-64.78365, -0.45236),
        Point(-64.80164, -0.45236),
        Point(-64.90498, -0.36564),
        Point(-65.0000, -0.16188),
        Point(-65.0000, 0.0000)
    ]
    trace_dip_east = Line(point_order_dipping_east)
    fault_surface1 = SimpleFaultSurface.from_fault_data(
        trace_dip_east, 0.0, 12.0, 60., 1.0)
    # Activity Rates
    # cm per km2
    area = 60. * 12.0 / np.sin(np.radians(60.))
    cm2perkm2 = (100. * 1000.)**2.
    mo1 = 3.0E11 * 0.2 * (area * cm2perkm2)
    mo_m6p75 = 10.0**(16.05 + 1.5 * 6.75)
    rate1 = mo1 / mo_m6p75
    mfd1 = EvenlyDiscretizedMFD(6.75, 0.01, [rate1])
    tom = PoissonTOM(1.0)
    aspect = 2.0
    rake = 90.0
    src = SimpleFaultSource("PEER_FLT_EAST", "PEER Bending Fault Dipping East",
                            "Active Shallow Crust", mfd1, 1.0, PeerMSR(), 2.0,
                            tom, 0.0, 12.0, trace_dip_east, 60.0, rake)
    src.num_ruptures = src.count_ruptures()
    return src
Пример #8
0
    def get_background_sources(self, src_filter):
        """
        Turn the background model of a given branch into a set of point sources

        :param src_filter:
            SourceFilter instance
        """
        background_sids = self.get_background_sids(src_filter)
        with h5py.File(self.source_file, "r") as hdf5:
            grid_loc = "/".join(["Grid", self.idx_set["grid_key"]])
            mags = hdf5[grid_loc + "/Magnitude"].value
            mmax = hdf5[grid_loc + "/MMax"][background_sids]
            rates = hdf5[grid_loc + "/RateArray"][background_sids, :]
            locations = hdf5["Grid/Locations"][background_sids, :]
            sources = []
            for i, bg_idx in enumerate(background_sids):
                src_id = "_".join([self.idx_set["grid_key"], str(bg_idx)])
                src_name = "|".join([self.idx_set["total_key"], str(bg_idx)])
                # Get MFD
                mag_idx = numpy.logical_and(mags >= self.min_mag,
                                            mags < mmax[i])
                src_mags = mags[mag_idx]
                src_rates = rates[i, :]
                src_mfd = EvenlyDiscretizedMFD(src_mags[0],
                                               src_mags[1] - src_mags[0],
                                               src_rates[mag_idx].tolist())
                ps = PointSource(src_id, src_name, self.tectonic_region_type,
                                 src_mfd, self.mesh_spacing, self.msr,
                                 self.aspect, self.tom, self.usd, self.lsd,
                                 Point(locations[i, 0],
                                       locations[i, 1]), self.npd, self.hdd)
                ps.src_group_id = self.src_group_id
                sources.append(ps)
        return sources
Пример #9
0
 def get_background_sources(self):
     """
     Turn the background model of a given branch into a set of point sources
     """
     background_sids = self.get_background_sids()
     with h5py.File(self.source_file, "r") as hdf5:
         grid_loc = "/".join(["Grid", self.ukey["grid_key"]])
         # for instance Grid/FM0_0_MEANFS_MEANMSR_MeanRates
         mags = hdf5[grid_loc + "/Magnitude"][()]
         mmax = hdf5[grid_loc + "/MMax"][background_sids]
         rates = hdf5[grid_loc + "/RateArray"][background_sids, :]
         locations = hdf5["Grid/Locations"][background_sids, :]
         sources = []
         for i, bg_idx in enumerate(background_sids):
             src_id = "_".join([self.ukey["grid_key"], str(bg_idx)])
             src_name = "|".join([self.ukey["total_key"], str(bg_idx)])
             mag_idx = (self.min_mag <= mags) & (mags < mmax[i])
             src_mags = mags[mag_idx]
             src_mfd = EvenlyDiscretizedMFD(src_mags[0],
                                            src_mags[1] - src_mags[0],
                                            rates[i, mag_idx].tolist())
             ps = PointSource(src_id, src_name, self.tectonic_region_type,
                              src_mfd, self.mesh_spacing, self.msr,
                              self.aspect, self.tom, self.usd, self.lsd,
                              Point(locations[i, 0],
                                    locations[i, 1]), self.npd, self.hdd)
             ps.checksum = zlib.adler32(pickle.dumps(vars(ps), protocol=4))
             ps._wkt = ps.wkt()
             ps.id = self.id
             ps.et_id = self.et_id
             ps.num_ruptures = ps.count_ruptures()
             ps.nsites = 1  # anything <> 0 goes
             sources.append(ps)
     return sources
    def test_Pago_VeianoMontaguto(self):
        # regression test
        fault_trace = Line([
            Point(15.2368, 41.1594),
            Point(15.1848, 41.1644),
            Point(15.1327, 41.1694),
            Point(15.0807, 41.1745),
            Point(15.0286, 41.1795),
            Point(14.9765, 41.1846),
            Point(14.9245, 41.1896),
            Point(14.8724, 41.1946),
            Point(14.8204, 41.1997)
        ])
        mfd = EvenlyDiscretizedMFD(min_mag=6.9,
                                   bin_width=0.2,
                                   occurrence_rates=[1.0])
        dip = 70.0
        upper_seismogenic_depth = 11.0
        lower_seismogenic_depth = 25.0
        rake = -130
        scalerel = WC1994()
        rupture_mesh_spacing = 5
        rupture_aspect_ratio = 1
        tom = PoissonTOM(10)

        fault = SimpleFaultSource(
            'ITCS057', 'Pago Veiano-Montaguto', TRT.ACTIVE_SHALLOW_CRUST, mfd,
            rupture_mesh_spacing, scalerel, rupture_aspect_ratio, tom,
            upper_seismogenic_depth, lower_seismogenic_depth, fault_trace, dip,
            rake)

        self.assertEqual(len(list(fault.iter_ruptures())), 1)
def build_fault_model(area, slip, mmax, config={}, mu=30.0, coupling=1.0):
    """
    
    """
    if not config:
        # Simple Dirac function
        geological_moment = coupling * (mu * 1.0E9) * (area * 1.0E6) * (slip *
                                                                        1.0E-3)
        mmax_moment = moment_function(mmax)
        rate = geological_moment / mmax_moment
        mf_dist = EvenlyDiscretizedMFD(mmax, 0.1, [rate])
        return get_incremental_cumulative(mf_dist)

    d_m = config["MFD_spacing"]
    config["Model_Weight"] = 1.0

    if config["model"] == "Characteristic":
        # Try characteristic
        for key in ["MFD_spacing", "Lower_Bound", "Upper_Bound", "Sigma"]:
            # Verify everything is present
            assert key in config and config[key] is not None
        rec_model = Characteristic()
        rec_model.setUp(config)
        rec_model.mmax = mmax
    elif config["model"] == "Hybrid":
        # Try Hybrid
        for key in ["Minimum_Magnitude", "b_value"]:
            # Verify everything is present
            assert key in config and config[key] is not None
        rec_model = YoungsCoppersmithCharacteristic()
        rec_model.setUp(config)
        rec_model.mmax = mmax
    elif config["model"] == "Exponential":
        # Try exponential
        for key in ["Minimum_Magnitude", "b_value"]:
            # Verify everything is present
            assert key in config and config[key] is not None
        rec_model = YoungsCoppersmithExponential()
        rec_model.setUp(config)
        rec_model.mmax = mmax
        rec_model.mmin += (config["MFD_spacing"] / 2.)
    else:
        raise ValueError("Model %s not recognised" % config["model"])

    mmin, bin_width, rate = rec_model.get_mfd(slip, area, mu)
    mf_dist = EvenlyDiscretizedMFD(mmin, bin_width, rate.tolist())
    return get_incremental_cumulative(mf_dist)
 def setUp(self):
     self.basic_trace = Line([Point(30.0, 30.0), Point(30.0, 32.0)])
     self.mfd = EvenlyDiscretizedMFD(7.0, 0.1, [1.0])
     self.aspect = 1.0
     self.dip = 45.0
     self.fault = self._make_source(self.mfd, self.aspect, self.basic_trace,
                                    self.dip)
     self.fault.lower_seismogenic_depth = 10.0
    def test_modify_mfd_constraints(self):
        mfd = EvenlyDiscretizedMFD(min_mag=4.0, bin_width=0.1,
                                   occurrence_rates=[1, 2, 3])
        exc = self.assert_mfd_error(
            mfd.modify,
            "set_mfd",
            {"min_mag": 4.0, "bin_width": 0.1, "occurrence_rates": [-1, 2, 3]})

        self.assertEqual(str(exc), 'all occurrence rates must not be negative')
Пример #14
0
 def setUp(self):
     top_edge_1 = Line([Point(30.0, 30.0, 1.0), Point(31.0, 30.0, 1.0)])
     bottom_edge_1 = Line([Point(29.7, 29.9, 30.0),
                           Point(31.3, 29.9, 32.0)])
     self.edges = [top_edge_1, bottom_edge_1]
     self.mfd = EvenlyDiscretizedMFD(7.0, 0.1, [1.0])
     self.aspect = 1.0
     self.spacing = 5.0
     self.rake = 90.
Пример #15
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)
Пример #16
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())
     self.assertEqual(len(ruptures), 8)
     for rupture in ruptures:
         self.assertNotEqual(rupture.occurrence_rate, 3)
         self.assertEqual(rupture.occurrence_rate, 3.0 / 8.0)
Пример #17
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)
Пример #18
0
    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)
Пример #19
0
 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)
Пример #20
0
def get_evenlyDiscretizedMFD_from_truncatedGRMFD(mfd, bin_width=None):
    """
    This function converts a double truncated Gutenberg Richter distribution
    into an almost equivalent discrete representation.

    :parameter:
        A instance of :class:`~openquake.hazardlib.mfd.TruncatedGRMFD`
    :return:
        An instance of :class:`~openquake.hazardlib.mfd.EvenlyDiscretizedMFD`
    """
    assert isinstance(mfd, TruncatedGRMFD)
    agr = mfd.a_val
    bgr = mfd.b_val
    bin_width = mfd.bin_width
    left = np.arange(mfd.min_mag, mfd.max_mag, bin_width)
    rates = 10.**(agr-bgr*left)-10.**(agr-bgr*(left+bin_width))
    return EvenlyDiscretizedMFD(mfd.min_mag+bin_width/2.,
                                bin_width,
                                list(rates))
Пример #21
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)
Пример #22
0
    def get_background_sources(self, sample_factor=None):
        """
        Turn the background model of a given branch into a set of point sources

        :param sample_factor:
            Used to reduce the sources if OQ_SAMPLE_SOURCES is set
        """
        background_sids = self.get_background_sids()
        if sample_factor is not None:  # hack for use in the mosaic
            background_sids = random_filter(
                background_sids, sample_factor, seed=42)
        with h5py.File(self.source_file, "r") as hdf5:
            grid_loc = "/".join(["Grid", self.idx_set["grid_key"]])
            # for instance Grid/FM0_0_MEANFS_MEANMSR_MeanRates
            mags = hdf5[grid_loc + "/Magnitude"][()]
            mmax = hdf5[grid_loc + "/MMax"][background_sids]
            rates = hdf5[grid_loc + "/RateArray"][background_sids, :]
            locations = hdf5["Grid/Locations"][background_sids, :]
            sources = []
            for i, bg_idx in enumerate(background_sids):
                src_id = "_".join([self.idx_set["grid_key"], str(bg_idx)])
                src_name = "|".join([self.idx_set["total_key"], str(bg_idx)])
                mag_idx = (self.min_mag <= mags) & (mags < mmax[i])
                src_mags = mags[mag_idx]
                src_mfd = EvenlyDiscretizedMFD(
                    src_mags[0],
                    src_mags[1] - src_mags[0],
                    rates[i, mag_idx].tolist())
                ps = PointSource(
                    src_id, src_name, self.tectonic_region_type, src_mfd,
                    self.mesh_spacing, self.msr, self.aspect, self.tom,
                    self.usd, self.lsd,
                    Point(locations[i, 0], locations[i, 1]),
                    self.npd, self.hdd)
                ps.checksum = zlib.adler32(pickle.dumps(vars(ps), protocol=4))
                ps._wkt = ps.wkt()
                ps.id = self.id
                ps.grp_id = self.grp_id
                ps.num_ruptures = ps.count_ruptures()
                sources.append(ps)
        return sources
Пример #23
0
    def setUp(self):
        self.mfd1 = EEvenlyDiscretizedMFD(4.5, 0.1, [0.5, 0.4, 0.3, 0.2])
        self.mfd2 = EEvenlyDiscretizedMFD(4.4, 0.1, [0.5, 0.4, 0.3, 0.2])
        self.mfd3 = EvenlyDiscretizedMFD(4.4, 0.05, [0.5, 0.4, 0.3, 0.2])
        self.mfd4 = EvenlyDiscretizedMFD(4.4, 0.1, [0.5, 0.4, 0.3, 0.2,
                                                    0.1, 0.05, 0.025, 0.01])
        self.mfd5 = EvenlyDiscretizedMFD(4.6, 0.1, [0.5, 0.4, 0.3, 0.2,
                                                    0.1, 0.05, 0.025, 0.01])

        self.base = EEvenlyDiscretizedMFD(6.0, 0.1, [1e-20])
        self.huas082 = EvenlyDiscretizedMFD(4.7, 0.2, [
            0.000890073609248, 0.000561598480883, 0.000354344686162,
            0.000223576382212, 0.000141067160409, 8.90073609248e-05,
            5.61598480883e-05, 3.54344686162e-05, 2.23576382212e-05,
            1.41067160409e-05, 8.90073609248e-06, 2.8088205502e-06,
            3.54240181229e-07, 2.23510444056e-07])

        self.mfd6 = EvenlyDiscretizedMFD(4.7, 0.01, [0.5])
        self.mfd7 = EvenlyDiscretizedMFD(5.5, 0.01, [0.5])
Пример #24
0
 def setUp(self):
     super(SeismicSourceGetAnnOccRatesTestCase, self).setUp()
     self.source.mfd = EvenlyDiscretizedMFD(min_mag=3,
                                            bin_width=1,
                                            occurrence_rates=[5, 0, 7, 0])
Пример #25
0
 def test_zero_rate(self):
     evenly_discretized = EvenlyDiscretizedMFD(min_mag=1,
                                               bin_width=2,
                                               occurrence_rates=[4, 0, 5])
     self.assertEqual(evenly_discretized.get_annual_occurrence_rates(),
                      [(1, 4), (3, 0), (5, 5)])
Пример #26
0
 def test_zero_min_mag(self):
     mfd = EvenlyDiscretizedMFD(min_mag=0,
                                bin_width=1,
                                occurrence_rates=[1])
     self.assertEqual(mfd.get_annual_occurrence_rates(), [(0, 1)])
     self.assertEqual(mfd.get_min_max_mag(), (0, 0))
Пример #27
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)
Пример #28
0
def mfd_upsample(bin_width, mfd):
    """
    This is upsampling an MFD i.e. creating a new MFD with a larger
    bin width.

    :param bin_width:
    :param mfd:
    """
    #
    # computing the min and max values of magnitude
    ommin = mfd.min_mag
    ommax = mfd.min_mag + len(mfd.occurrence_rates) * mfd.bin_width
    #
    # rounding the lower and upper magnitude limits to the new
    # bin width
    min_mag = np.floor(ommin / bin_width) * bin_width
    max_mag = np.ceil(ommax / bin_width) * bin_width
    #
    # prepare the new array for occurrences
    nocc = np.zeros((int((max_mag-min_mag)/bin_width+1), 4))
    # set the new array
    for idx, mag in enumerate(np.arange(min_mag, max_mag, bin_width)):
        nocc[idx, 0] = mag
        nocc[idx, 1] = mag-bin_width/2
        nocc[idx, 2] = mag+bin_width/2
    #
    # create he arrays with magnitudes and occurrences
    """
    mago = []
    occo = []
    for mag, occ in mfd.get_annual_occurrence_rates():
        mago.append(mag)
        occo.append(occo)
    mago = np.array(mago)
    occo = np.array(occo)
    """
    #
    # assigning occurrences
    dlt = bin_width * 1e-5
    for mag, occ in mfd.get_annual_occurrence_rates():
        print(mag, occ)
        #
        # find indexes of lower bin limits lower than mag
        idx = np.nonzero(mag+dlt-mfd.bin_width/2 > nocc[:, 1])[0]
        idxa = None
        idxb = None
        # idxa is the index of the lower limit
        if len(idx):
            idxa = np.amax(idx)
        else:
            raise ValueError('Error in computing lower mag limit')
        # find indexes of the bin centers with magnitude larger than mag
        # idx = np.nonzero((mag+mfd.bin_width/2) > nocc[:, 2])[0]
        idx = np.nonzero(mag-dlt+mfd.bin_width/2 < nocc[:, 2])[0]
        if len(idx):
            # idxb = np.amax(idx)
            idxb = np.amin(idx)
        #
        #
        print(idxa, idxb)
        if idxb is not None and idxa == idxb:
            nocc[idxa, 3] += occ
        else:
            # ratio of occurrences in the lower bin
            ra = (nocc[idxa, 2] - (mag-mfd.bin_width/2)) / mfd.bin_width
            nocc[idxa, 3] += occ*ra
            if (1.0-ra) > 1e-10:
                nocc[idxa+1, 3] += occ*(1-ra)
        print(nocc)
    #
    # check that the the MFDs have the same total occurrence rate
    smmn = sum(nocc[:, 3])
    smmo = sum(mfd.occurrence_rates)
    print(smmn, smmo)
    #
    # check that the total number of occurrences in the original and
    # resampled MFDs are the same
    assert abs(smmn-smmo) < 1e-5

    idxs = set(np.arange(0, len(nocc[:, 3])))
    iii = len(nocc[:, 3])-1
    while nocc[iii, 3] < 1e-10:
        idxs = idxs - set([iii])
        iii -= 1

    return EvenlyDiscretizedMFD(nocc[0, 0], bin_width,
                                list(nocc[list(idxs), 3]))
Пример #29
0
def mfd_downsample(bin_width, mfd):
    """
    :parameter float bin_width:
    :parameter mfd:
    """

    ommin = mfd.min_mag
    ommax = mfd.min_mag + len(mfd.occurrence_rates) * mfd.bin_width

    if log:
        print('ommax     ', ommax)
        print('bin_width ', mfd.bin_width)

    # check that the new min_mag is a multiple of the bin width
    min_mag = np.floor(ommin / bin_width) * bin_width
    # lower min mag to make sure we cover the entire magnitude range
    while min_mag-bin_width/2 > mfd.min_mag-mfd.bin_width/2:
        min_mag -= bin_width
    # preparing the list wchi will collect data
    dummy = []
    mgg = min_mag + bin_width / 2
    while mgg < (ommax + 0.51 * mfd.bin_width):
        if log:
            print(mgg, ommax + mfd.bin_width/2)
        dummy.append(mgg)
        mgg += bin_width

    # prepare the new array for occurrences
    nocc = np.zeros((len(dummy), 4))

    if log:
        print('CHECK', len(nocc), len(dummy))
        print(dummy)

    #
    boun = np.zeros((len(mfd.occurrence_rates), 4))
    for idx, (mag, occ) in enumerate(mfd.get_annual_occurrence_rates()):
        boun[idx, 0] = mag
        boun[idx, 1] = mag-mfd.bin_width/2
        boun[idx, 2] = mag+mfd.bin_width/2
        boun[idx, 3] = occ
    # init
    for idx in range(0, len(nocc)):
        mag = min_mag+bin_width*idx
        nocc[idx, 0] = mag
        nocc[idx, 1] = mag-bin_width/2
        nocc[idx, 2] = mag+bin_width/2

    rat = bin_width/mfd.bin_width
    tol = 1e-10

    for iii, mag in enumerate(list(nocc[:, 0])):
        idx = np.nonzero(nocc[iii, 1] > (boun[:, 1]-tol))[0]
        idxa = None
        if len(idx):
            idxa = np.amax(idx)
        idx = np.nonzero(nocc[iii, 2] > boun[:, 2]-tol)[0]
        idxb = None
        if len(idx):
            idxb = np.amax(idx)

        if idxa is None and idxb is None and nocc[iii, 2] > boun[0, 1]:
            nocc[0, 3] = ((nocc[iii, 2] - boun[0, 1]) / mfd.bin_width *
                          boun[0, 3])
        elif idxa is None and idxb is None:
            pass
        elif idxa == 0 and idxb is None:
            # This is the first bin when the lower limit of the two FMDs is
            # not the same
            nocc[iii, 3] += rat * boun[idxa, 3]
        elif nocc[iii, 1] > boun[-1, 2]:
            # Empty bin
            pass
        elif idxa > idxb:
            # Bin entirely included in a bin of the original MFD
            nocc[iii, 3] += rat * boun[idxa, 3]
        else:
            dff = (boun[idxa, 2] - nocc[iii, 1])
            ra = dff / mfd.bin_width
            nocc[iii, 3] += ra * boun[idxb, 3]

            if len(boun) > 1 and nocc[iii, 1] < boun[-2, 2]:
                dff = (nocc[iii, 2] - boun[idxa, 2])
                ra = dff / mfd.bin_width
                nocc[iii, 3] += ra * boun[idxa+1, 3]

    idx0 = np.nonzero(nocc[:, 3] < 1e-20)
    idx1 = np.nonzero(nocc[:, 3] > 1e-20)
    if np.any(idx0 == 0):
        raise ValueError('Rates in the first bin are equal to 0')
    elif len(idx0):
        nocc = nocc[idx1[0], :]
    else:
        pass

    smmn = sum(nocc[:, 3])
    smmo = sum(mfd.occurrence_rates)

    if log:
        print(nocc)
        print('SUMS:', smmn, smmo)
    assert abs(smmn-smmo) < 1e-5
    return EvenlyDiscretizedMFD(nocc[0, 0], bin_width, list(nocc[:, 3]))
Пример #30
0
 def setUp(self):
     super().setUp()
     self.source.mfd = EvenlyDiscretizedMFD(min_mag=3, bin_width=1,
                                            occurrence_rates=[5, 0, 7, 0])
Пример #31
0
 def setUp(self):
     """
     Builds a simple dipping/bending fault source with a characteristic
     source model. Compares the curves for four sites, two on the hanging
     wall and two on the footwall.
     The source model is taken from the PEER Tests
     """
     point_order_dipping_east = [
         Point(-64.78365, -0.45236),
         Point(-64.80164, -0.45236),
         Point(-64.90498, -0.36564),
         Point(-65.0000, -0.16188),
         Point(-65.0000, 0.0000)
     ]
     trace_dip_east = Line(point_order_dipping_east)
     site_1 = Site(Point(-64.98651, -0.15738), 760.0, True, 48.0, 0.607)
     site_2 = Site(Point(-64.77466, -0.45686), 760.0, True, 48.0, 0.607)
     site_3 = Site(Point(-64.92747, -0.38363), 760.0, True, 48.0, 0.607)
     site_4 = Site(Point(-65.05396, -0.17088), 760.0, True, 48.0, 0.607)
     self.sites = SiteCollection([site_1, site_2, site_3, site_4])
     self.imtls = {
         "PGA": [
             0.001, 0.01, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45,
             0.5, 0.55, 0.6, 0.7, 0.8, 0.9, 1.0
         ]
     }
     fault_surface1 = SimpleFaultSurface.from_fault_data(
         trace_dip_east, 0.0, 12.0, 60., 0.5)
     mfd1 = EvenlyDiscretizedMFD(6.75, 0.01, [0.01])
     tom = PoissonTOM(1.0)
     self.sources = [
         CharacteristicFaultSource(
             "PEER_CHAR_FLT_EAST",
             "Peer Bending Fault Dipping East - Characteristic",
             "Active Shallow Crust", mfd1, tom, fault_surface1, 90.0)
     ]
     # We will check all the GMPEs
     self.gsim_set = {
         "ASK": [
             AbrahamsonEtAl2014NSHMPMean(),
             (0.185, AbrahamsonEtAl2014NSHMPLower()),
             (0.63, AbrahamsonEtAl2014()),
             (0.185, AbrahamsonEtAl2014NSHMPUpper())
         ],
         "BSSA": [
             BooreEtAl2014NSHMPMean(), (0.185, BooreEtAl2014NSHMPLower()),
             (0.63, BooreEtAl2014()), (0.185, BooreEtAl2014NSHMPUpper())
         ],
         "CB": [
             CampbellBozorgnia2014NSHMPMean(),
             (0.185, CampbellBozorgnia2014NSHMPLower()),
             (0.63, CampbellBozorgnia2014()),
             (0.185, CampbellBozorgnia2014NSHMPUpper())
         ],
         "CY": [
             ChiouYoungs2014NSHMPMean(),
             (0.185, ChiouYoungs2014NSHMPLower()),
             (0.63, ChiouYoungs2014()), (0.185, ChiouYoungs2014NSHMPUpper())
         ],
         "ID": [
             Idriss2014NSHMPMean(), (0.185, Idriss2014NSHMPLower()),
             (0.63, Idriss2014()), (0.185, Idriss2014NSHMPUpper())
         ]
     }
Пример #32
0
# fault_length = 25.0 * 1e3 # m
# fault_width = 12.0 * 1e3 # m
#
# The total seismic moment rate can be computed as:
#
# seismic_moment_rate = rigidity * fault_length * fault_width * slip_rate
#
# From which we can derived the incremental a value:
#
# a_incremental = log10(seismic_moment_rate) - (1.5 + b_value) * magnitude - 9.05
#
# and finally the rate:
#
# rate = 10 ** (a_incremental + b_value * magnitude)
SET1_CASE2_MFD = EvenlyDiscretizedMFD(min_mag=6.0,
                                      bin_width=0.01,
                                      occurrence_rates=[0.0160425168864])
SET1_CASE1TO9_RAKE = 0

# page A-3
SET1_CASE1TO9_FAULT_TRACE = Line(
    [Point(-122.0, 38.0), Point(-122.0, 38.22480)])

# page A-17
SET1_CASE1TO9_UPPER_SEISMOGENIC_DEPTH = 0.0
SET1_CASE1TO9_LOWER_SEISMOGENIC_DEPTH = 12.0
SET1_CASE1TO9_DIP = 90

# page A-3
SET1_CASE1TO9_SITE1 = Site(location=Point(-122.000, 38.113),
                           vs30=800.0,
 def test_zero_rate(self):
     evenly_discretized = EvenlyDiscretizedMFD(
         min_mag=1, bin_width=2, occurrence_rates=[4, 0, 5]
     )
     self.assertEqual(evenly_discretized.get_annual_occurrence_rates(),
                      [(1, 4), (3, 0), (5, 5)])
 def test_zero_min_mag(self):
     mfd = EvenlyDiscretizedMFD(min_mag=0, bin_width=1,
                                occurrence_rates=[1])
     self.assertEqual(mfd.get_annual_occurrence_rates(), [(0, 1)])
     self.assertEqual(mfd.get_min_max_mag(), (0, 0))