Пример #1
0
    def test_6_rlzs(self):
        # test with 2x3 realizations and TRTA, TRTB
        # rlzs_by_g = 012, 345, 03, 14, 25
        inp = read_input(PARAM,
                         source_model_file=os.path.join(
                             CWD, 'data', 'sm02.xml'))
        R = inp.gsim_lt.get_num_paths()

        # compute the contributions by trt
        tot = AccumDict()  # g_ -> key -> array
        for src_group in inp.groups:
            cmaker = inp.cmakerdict[src_group.trt]
            ctxs = cmaker.from_srcs(src_group, inp.sitecol)
            tot += cmaker.get_cs_contrib(ctxs, imti, imls)

        # compose the contributions by rlz, 0+2, 0+3, 0+4, 1+2, 1+3, 1+4
        rlzs_by_g = inp.gsim_lt.get_rlzs_by_g()
        csdic = contexts.csdict(len(cmaker.imts), 1, 1, 0, R)
        for g_, rlz_ids in enumerate(rlzs_by_g):
            for r in rlz_ids:
                csdic[r] += tot[g_]
        df = csdic_to_dframe(csdic, cmaker.imts, 0, 0)

        # check the results
        expected = os.path.join(CWD, 'expected', 'spectra6.csv')
        if OVERWRITE_EXPECTED:
            df.to_csv(expected,
                      index=False,
                      line_terminator='\r\n',
                      float_format='%.6f')
        expdf = pandas.read_csv(expected)
        pandas.testing.assert_frame_equal(df, expdf, atol=1E-6)
Пример #2
0
 def test(self):
     inp = read_input(JOB)
     [[trt, cmaker]] = inp.cmakerdict.items()
     [[area]] = inp.groups  # there is a single AreaSource
     srcs = list(area)  # split in 3+3 PointSources
     cmaker.set_weight(srcs, inp.sitecol)
     weights = [src.weight for src in srcs]  # 3 within, 3 outside
     numpy.testing.assert_allclose(weights, [3.04, 3.04, 3.04, 1, 1, 1])
Пример #3
0
    def test_1_rlz(self):
        # test with one GMPE, 1 TRT, checking additivity
        inp = read_input(
            PARAM, gsim_logic_tree_file=os.path.join(CWD, 'data', 'lt01.xml'))
        [cmaker] = inp.cmakerdict.values()
        [src_group] = inp.groups
        ctxs = cmaker.from_srcs(src_group, inp.sitecol)
        assert len(ctxs) == 100
        ctxs1 = ctxs[:50]
        ctxs2 = ctxs[50:]

        c1, s1 = cmaker.get_cs_contrib(ctxs1, imti, imls)
        c2, s2 = cmaker.get_cs_contrib(ctxs2, imti, imls)
        c, s = cmaker.get_cs_contrib(ctxs, imti, imls)
        aac((c1 + c2) / (s1 + s2), c / s)
Пример #4
0
def main(params):
    # example with 2x2=4 realizations with weights .36, .24, .24, .16
    inp = read_input(params)
    print(inp)
    print(inp.gsim_lt.get_rlzs_by_gsim_trt())
    acc = AccumDict(accum=[])
    ebrs = sample_ebruptures(inp.groups, inp.cmakerdict)
    ne = sum(ebr.n_occ for ebr in ebrs)
    print('There are %d ruptures and %d events' % (len(ebrs), ne))
    df = get_ebr_df(ebrs, inp.cmakerdict)
    print(df.groupby('rlz').count())  # there are 8, 9, 11, 8 events per rlz
    for ebr in ebrs:
        cmaker = inp.cmakerdict[ebr.rupture.tectonic_region_type]
        gmf_dict, _ = GmfComputer(ebr, inp.sitecol, cmaker).compute_all()
        acc += gmf_dict
    print(pandas.DataFrame(acc))
Пример #5
0
    def test_1_rlz(self):
        # test with one GMPE, 1 TRT, checking additivity
        inp = read_input(PARAM,
                         gsim_logic_tree_file=os.path.join(
                             CWD, 'data', 'lt01.xml'))
        [cmaker] = inp.cmakerdict.values()
        [src_group] = inp.groups
        ctxs = cmaker.from_srcs(src_group, inp.sitecol)
        assert len(ctxs) == 100
        ctxs1 = ctxs[:50]
        ctxs2 = ctxs[50:]

        dic1 = cmaker.get_cs_contrib(ctxs1, imti, imls)[0]
        dic2 = cmaker.get_cs_contrib(ctxs2, imti, imls)[0]
        dic = cmaker.get_cs_contrib(ctxs, imti, imls)[0]
        aac((dic1['_c'] + dic2['_c']) / (dic1['_s'] + dic2['_s']),
            dic['_c'] / dic['_s'])
Пример #6
0
    def test_2_rlzs(self):
        # test with two GMPEs, 1 TRT
        inp = read_input(PARAM)
        [cmaker] = inp.cmakerdict.values()
        [src_group] = inp.groups
        ctxs = cmaker.from_srcs(src_group, inp.sitecol)
        csdic = cmaker.get_cs_contrib(ctxs, imti, imls)
        df = csdic_to_dframe(csdic, cmaker.imts, 0, 0)

        # check the result
        expected = os.path.join(CWD, 'expected', 'spectra2.csv')
        if OVERWRITE_EXPECTED:
            df.to_csv(expected,
                      index=False,
                      line_terminator='\r\n',
                      float_format='%.6f')
        expdf = pandas.read_csv(expected)
        pandas.testing.assert_frame_equal(df, expdf, atol=1E-6)
Пример #7
0
 def test1rup(self):
     param = dict(rupture_model_file=RUP_XML,
                  number_of_ground_motion_fields=10,
                  gsim='AtkinsonBoore2006',
                  ses_seed=42,
                  sites=[(0, 1), (0, 0)],
                  reference_vs30_value="760",
                  maximum_distance=IntegrationDistance.new('200'),
                  imtls={'PGA': [0]})
     inp = read_input(param)
     [grp] = inp.groups
     [ebr] = grp
     cmaker = inp.cmakerdict[grp.trt]
     gc = gmf.GmfComputer(ebr, inp.sitecol, cmaker)
     gmfdata = gc.compute_all()
     self.assertIn('sid', gmfdata)
     self.assertIn('eid', gmfdata)
     self.assertIn('rlz', gmfdata)
     self.assertIn('gmv_0', gmfdata)
Пример #8
0
    def test_point(self):
        # point source with 3 ruptures, checking additivity
        inp = read_input(
            PARAM, source_model_file=os.path.join(CWD, 'data', 'point.xml'),
            gsim_logic_tree_file=os.path.join(CWD, 'data', 'lt01.xml'))
        [cmaker] = inp.cmakerdict.values()
        [src_group] = inp.groups
        ctxs = cmaker.from_srcs(src_group, inp.sitecol)
        aac([ctx.occurrence_rate for ctx in ctxs], [0.00018, 0.00018, 0.00054])
        ctxs1 = ctxs[:2]
        ctxs2 = ctxs[2:]

        # check that the total spectra is a weighted mean of the two
        # rupture spectra; the weight is the same for all IMTs
        c1, s1 = cmaker.get_cs_contrib(ctxs1, imti, imls)
        c2, s2 = cmaker.get_cs_contrib(ctxs2, imti, imls)
        comp_spectra = (c1 + c2) / (s1 + s2)
        c, s = cmaker.get_cs_contrib(ctxs, imti, imls)
        aac(comp_spectra, c / s)
Пример #9
0
    def test_2_rlzs(self):
        # test with two GMPEs, 1 TRT
        inp = read_input(PARAM)
        [cmaker] = inp.cmakerdict.values()
        [src_group] = inp.groups
        ctxs = cmaker.from_srcs(src_group, inp.sitecol)
        [c_], [s_] = cmaker.get_cs_contrib(ctxs, imti, imls)
        spectra = [c / s for c, s in zip(c_, s_)]

        # check the result
        expected = os.path.join(CWD, 'expected', 'spectra2.csv')
        if OVERWRITE_EXPECTED:
            rlzs = list(inp.gsim_lt)
            spectra_to_df(spectra, cmaker.imts, rlzs).to_csv(
                expected, index=False, line_terminator='\r\n',
                float_format='%.6f')
        df = pandas.read_csv(expected)
        for g, gsim in enumerate(cmaker.gsims):
            dfg = df[df.rlz_id == g]
            aac(dfg.cs_exp, np.exp(spectra[g][0]), atol=1e-6)
            aac(dfg.cs_std, np.sqrt(spectra[g][1]), atol=1e-6)
Пример #10
0
    def test_6_rlzs(self):
        # test with 2x3 realizations and TRTA, TRTB
        # rlzs_by_g = 012, 345, 03, 14, 25
        inp = read_input(
            PARAM, source_model_file=os.path.join(CWD, 'data', 'sm02.xml'))
        rlzs = list(inp.gsim_lt)
        R = len(rlzs)

        # compute the contributions by trt
        all_cs = []
        for src_group in inp.groups:
            cmaker = inp.cmakerdict[src_group.trt]
            ctxs = cmaker.from_srcs(src_group, inp.sitecol)
            [c], [s] = cmaker.get_cs_contrib(ctxs, imti, imls)
            for cs in zip(c, s):
                all_cs.append(cs)

        # compose the contributions by rlz, 0+2, 0+3, 0+4, 1+2, 1+3, 1+4
        rlzs_by_g = inp.gsim_lt.get_rlzs_by_g()
        nums = np.zeros((R, 2, len(cmaker.imts)))
        denums = np.zeros(R)
        for g, rlz_ids in enumerate(rlzs_by_g):
            c, s = all_cs[g]
            for r in rlz_ids:
                nums[r] += c
                denums[r] += s
        spectra = [nums[r] / denums[r] for r in range(R)]

        # check the results
        expected = os.path.join(CWD, 'expected', 'spectra6.csv')
        if OVERWRITE_EXPECTED:
            spectra_to_df(spectra, cmaker.imts, rlzs).to_csv(
                expected, index=False, line_terminator='\r\n',
                float_format='%.6f')
        df = pandas.read_csv(expected)
        for rlz in rlzs:
            r = rlz.ordinal
            df_rlz = df[df.rlz_id == r]
            aac(df_rlz.cs_exp, np.exp(spectra[r][0]), atol=1e-6)
            aac(df_rlz.cs_std, np.sqrt(spectra[r][1]), atol=1e-6)