def test_calculation_addition_args(self):
        avg_periods = [0.05, 0.15, 1.0, 2.0, 4.0]
        gmm = GenericGmpeAvgSA(gmpe_name="KothaEtAl2020ESHM20",
                               avg_periods=avg_periods,
                               corr_func="akkar",
                               sigma_mu_epsilon=1.0)

        rctx = RuptureContext()
        rctx.mag = 6.
        rctx.hypo_depth = 15.
        dctx = DistancesContext()
        dctx.rjb = np.array([1., 10., 30., 70.])

        sctx = SitesContext()
        sctx.vs30 = 500.0 * np.ones(4)
        sctx.vs30measured = np.ones(4, dtype="bool")
        sctx.region = np.zeros(4, dtype=int)
        stdt = [const.StdDev.TOTAL]
        expected_mean = np.array(
            [-1.72305707, -2.2178751, -3.20100306, -4.19948242])
        expected_stddev = np.array(
            [0.5532021, 0.5532021, 0.5532021, 0.5532021])
        imtype = imt.AvgSA()
        mean, [stddev] = gmm.get_mean_and_stddevs(sctx, rctx, dctx, imtype,
                                                  stdt)
        np.testing.assert_almost_equal(mean, expected_mean)
        np.testing.assert_almost_equal(stddev, expected_stddev)
    def test_calculation_addition_args(self):
        avg_periods = [0.05, 0.15, 1.0, 2.0, 4.0]
        gmm = GenericGmpeAvgSA(gmpe_name="KothaEtAl2019SERA",
                               avg_periods=avg_periods,
                               corr_func="akkar",
                               sigma_mu_epsilon=1.0)

        rctx = RuptureContext()
        rctx.mag = 6.
        rctx.hypo_depth = 15.
        dctx = DistancesContext()
        dctx.rjb = np.array([1., 10., 30., 70.])

        sctx = SitesContext()
        sctx.vs30 = 500.0 * np.ones(4)
        sctx.vs30measured = np.ones(4, dtype="bool")
        stdt = [const.StdDev.TOTAL]
        expected_mean = np.array(
            [-1.45586338, -1.94419233, -2.91884965, -3.91919928])
        expected_stddev = np.array(
            [0.58317566, 0.58317566, 0.58317566, 0.58317566])
        imtype = imt.AvgSA()
        mean, [stddev] = gmm.get_mean_and_stddevs(sctx, rctx, dctx, imtype,
                                                  stdt)
        np.testing.assert_almost_equal(mean, expected_mean)
        np.testing.assert_almost_equal(stddev, expected_stddev)
    def test_calculation_Baker_Jayaram(self):

        DATA_FILE = data / 'GENERIC_GMPE_AVGSA_MEAN_STD_TOTAL_BAKER_JAYARAM.csv'

        # Initialise meta-GMPE
        mgmpe = gsim.mgmpe.generic_gmpe_avgsa.GenericGmpeAvgSA(
            gmpe_name='BooreAtkinson2008',
            avg_periods=[0.05, 0.15, 1.0, 2.0, 4.0],
            corr_func='baker_jayaram')

        ctx = RuptureContext()
        ctx.sids = [0]
        P = imt.AvgSA
        S = [const.StdDev.TOTAL]

        with open(DATA_FILE, 'r') as f:

            # Skip header
            for i in [1, 2, 3]:
                f.readline()

            for line in f:
                arr = np.float_(line.strip().split(','))

                # Setting ground motion attributes
                ctx.mag = arr[0]
                ctx.rjb = np.array([arr[1]])
                ctx.rake = arr[2]
                ctx.hypo_depth = arr[3]
                ctx.vs30 = np.array([arr[4]])

                # Compute ground motion
                mean, stdv = mgmpe.get_mean_and_stddevs(ctx, ctx, ctx, P, S)
                np.testing.assert_almost_equal(mean, arr[6])
                np.testing.assert_almost_equal(stdv, arr[7])
Beispiel #4
0
 def test_make_pmap(self):
     trunclevel = 3
     imtls = DictArray({'PGA': [0.01]})
     gsims = [valid.gsim('AkkarBommer2010')]
     ctxs = []
     for occ_rate in (.001, .002):
         ctx = RuptureContext()
         ctx.mag = 5.5
         ctx.rake = 90
         ctx.occurrence_rate = occ_rate
         ctx.sids = numpy.array([0.])
         ctx.vs30 = numpy.array([760.])
         ctx.rrup = numpy.array([100.])
         ctx.rjb = numpy.array([99.])
         ctxs.append(ctx)
     pmap = make_pmap(ctxs, gsims, imtls, trunclevel, 50.)
     numpy.testing.assert_almost_equal(pmap[0].array, 0.066381)
Beispiel #5
0
 def test_get_pmap(self):
     truncation_level = 3
     imtls = DictArray({'PGA': [0.01]})
     gsims = [valid.gsim('AkkarBommer2010')]
     ctxs = []
     for occ_rate in (.001, .002):
         ctx = RuptureContext()
         ctx.mag = 5.5
         ctx.rake = 90
         ctx.occurrence_rate = occ_rate
         ctx.sids = numpy.array([0.])
         ctx.vs30 = numpy.array([760.])
         ctx.rrup = numpy.array([100.])
         ctx.rjb = numpy.array([99.])
         ctxs.append(ctx)
     cmaker = ContextMaker(
         'TRT', gsims, dict(imtls=imtls, truncation_level=truncation_level))
     cmaker.tom = PoissonTOM(time_span=50)
     pmap = cmaker.get_pmap(ctxs)
     numpy.testing.assert_almost_equal(pmap[0].array, 0.066381)
Beispiel #6
0
 def _get_stds(self, within_absolute=None, between_absolute=None):
     if within_absolute is not None:
         gmm = SplitSigmaGMPE(gmpe_name='Campbell2003',
                              within_absolute=within_absolute)
     elif between_absolute is not None:
         gmm = SplitSigmaGMPE(gmpe_name='Campbell2003',
                              between_absolute=between_absolute)
     else:
         raise ValueError('Unknown option')
     # Set parameters
     ctx = RuptureContext()
     ctx.mag = 6.0
     ctx.sids = [0, 1, 2, 3]
     ctx.vs30 = [760.] * 4
     ctx.rrup = np.array([1., 10., 30., 70.])
     ctx.occurrence_rate = .0001
     imt = PGA()
     stds_types = [const.StdDev.TOTAL, const.StdDev.INTER_EVENT,
                   const.StdDev.INTRA_EVENT]
     # Compute results
     mean, stds = gmm.get_mean_and_stddevs(ctx, ctx, ctx, imt, stds_types)
     return stds, stds_types
Beispiel #7
0
    def pt_src_are(self, pt_src, gsim, weight, lnSA, monitor):
        """
        Returns the vector-valued Annual Rate of Exceedance for one single point-source

        :param pt_src: single instance of class "openquake.hazardlib.source.area.PointSource"
        :param gsim: tuple, containing (only one?) instance of Openquake GSIM class
        :param: weight, weight to be multiplied to ARE estimate
        :param lnSA: list, natural logarithm of acceleration values for each spectral period.
            Note : Values should be ordered in the same order than self.periods
        """
        annual_rate = 0

        # Loop over ruptures:
        # i.e. one rupture for each combination of (mag, nodal plane, hypocentral depth):
        for r in pt_src.iter_ruptures():
        # NOTE: IF ACCOUNTING FOR "pointsource_distance" IN THE INI FILE, ONE SHOULD USE THE
        # "point_ruptures()" METHOD BELOW:
        # Loop over ruptures, one rupture for each magnitude ( neglect floating and combination on
        # nodal plane and hypocentral depth):
        ## for r in pt_src.point_ruptures():
            # Note: Seismicity rate evenly distributed over all point sources
            #       Seismicity rate also accounts for FMD (i.e. decreasing for
            #         increasing magnitude value)

            # Filter the site collection with respect to the rupture and prepare context objects:
            context_maker = ContextMaker(r.tectonic_region_type, gsim)
            site_ctx, dist_ctx = context_maker.make_contexts(self.sites, r)
            rup_ctx = RuptureContext()
            rup_ctx.mag = r.mag
            rup_ctx.rake = r.rake
            assert len(gsim)==1

            annual_rate += r.occurrence_rate * weight * self.gm_poe(gsim[0],
                                                                    dist_ctx,
                                                                    rup_ctx,
                                                                    site_ctx,
                                                                    lnSA)
        return annual_rate