예제 #1
0
 def test_prem(self):
     model_data = TestFunctionTaup.gen_test_model("prem")
     model_prem = SeisModel(model=model_data)
     source_prem = SourceModel(sdep=16.5)
     # * note, use larger distance will integrate more, the waveform of only calculating 10km and calculating to 100km will be grealy different
     config_prem = Config(model=model_prem,
                          source=source_prem,
                          npt=512,
                          dt=0.1,
                          receiver_distance=np.arange(10, 20, 10))
     gf = calculate_gf(config_prem)
     # # * calculate sync_prem_gcmt for the event
     event = obspy.read_events(
         join(dirname(__file__), "../data/sync_prem_gcmt/test_gcmt"))[0]
     source_prem.update_source_mechanism(event)
     # # * generate a source time function
     source_time_function = generate_source_time_function(
         4, 0.5, gf[0][0].stats.delta)
     sync_result = calculate_sync(gf, config_prem, 30, source_time_function)
     # * test if the cc value is large enough
     for index, component in enumerate(["z", "r", "t"]):
         sac_path = join(dirname(__file__),
                         f"../data/sync_prem_gcmt/prem.{component}")
         sac_wave = obspy.read(sac_path)[0].data
         coef = np.corrcoef(
             sac_wave,
             sync_result[0][index].data,
         )[0, 1]
         assert coef > 0.9999
예제 #2
0
파일: test_gf.py 프로젝트: ziyixi/pyfk
    def test_hk():
        # * perl fk.pl -Mhk/15/k -N512/0.1 10 20 30
        model_path = join(dirname(__file__), f"../data/hk")
        model_data = np.loadtxt(model_path)
        model_hk = SeisModel(model=model_data, use_kappa=True)
        source_hk = SourceModel(sdep=15)
        config_hk = Config(model=model_hk,
                           source=source_hk,
                           npt=512,
                           dt=0.1,
                           receiver_distance=[10, 20, 30])

        result = calculate_gf(config_hk)
        # * for all the gf in data/hk_gf, test if the results are close (in FK, it uses float but we are using double)
        for irec, each_rec in enumerate([10, 20, 30]):
            for icomn in range(9):
                hk_gf_data = obspy.read(
                    join(dirname(__file__),
                         f"../data/hk_gf/{each_rec}.grn.{icomn}"))[0]
                coef = np.corrcoef(
                    hk_gf_data.data,
                    result[irec][icomn].data,
                )[0, 1]
                if np.isnan(coef):
                    coef = 1.0
                assert coef > 0.99
예제 #3
0
파일: test_gf.py 프로젝트: ziyixi/pyfk
 def test_big_array(self):
     # model_data = TestFunctionTaup.gen_test_model("prem")
     # there is a possibility that we write x=f(x) where x is a memoryview in the code
     # this might cause segmentation fault
     model_data = np.loadtxt(join(dirname(__file__), f"../data/hk"))
     model_hk = SeisModel(model=model_data)
     source_hk = SourceModel(sdep=16.5)
     config_hk = Config(model=model_hk,
                        source=source_hk,
                        npt=512,
                        dt=0.1,
                        receiver_distance=np.arange(10, 40, 10))
     _ = calculate_gf(config_hk)
예제 #4
0
파일: test_gf.py 프로젝트: ziyixi/pyfk
 def test_static_source(self):
     model_data = TestFunctionTaup.gen_test_model("prem")
     model_prem = SeisModel(model=model_data)
     source_prem = SourceModel(sdep=16.5, srcType="dc")
     config_prem = Config(model=model_prem,
                          source=source_prem,
                          npt=1,
                          dt=1,
                          receiver_distance=[50])
     gf = calculate_gf(config_prem)
     ref_gf = [
         -0.242E-06, -0.103E-05, 0.000E+00, 0.236E-06, 0.118E-05,
         -0.548E-07, -0.942E-07, -0.156E-05, 0.285E-06
     ]
     coef = np.corrcoef(
         gf,
         ref_gf,
     )[0, 1]
     assert coef > 0.99999
예제 #5
0
파일: test_gf.py 프로젝트: ziyixi/pyfk
 def test_prem_sf(self):
     model_data = TestFunctionTaup.gen_test_model("prem")
     model_prem = SeisModel(model=model_data)
     source_prem = SourceModel(sdep=16.5, srcType="sf")
     config_prem = Config(model=model_prem,
                          source=source_prem,
                          npt=512,
                          dt=1,
                          receiver_distance=[50])
     gf = calculate_gf(config_prem)
     for index, comnname in enumerate(range(6)):
         gf_data = obspy.read(
             join(dirname(__file__),
                  f"../data/sync_prem_sf/50.grn.{comnname}"))[0]
         coef = np.corrcoef(
             gf_data.data,
             gf[0][index].data,
         )[0, 1]
         if np.isnan(coef):
             coef = 1.
         assert coef > 0.99
예제 #6
0
 def test_exceptions(self):
     model_data = TestFunctionTaup.gen_test_model("prem")
     model_prem = SeisModel(model=model_data)
     source_prem = SourceModel(sdep=16.5)
     # * note, use larger distance will integrate more, the waveform of only calculating 10km and calculating to 100km will be grealy different
     # ! note receiver_distance can not be 0
     config_prem = Config(model=model_prem,
                          source=source_prem,
                          npt=512,
                          dt=0.1,
                          receiver_distance=np.arange(1, 10))
     gf = calculate_gf(config_prem)
     event = obspy.read_events(
         join(dirname(__file__), "../data/sync_prem_gcmt/test_gcmt"))[0]
     source_prem.update_source_mechanism(event)
     source_time_function = generate_source_time_function(
         4, 0.5, gf[0][0].stats.delta)
     # * the main tests
     with pytest.raises(PyfkError) as execinfo:
         _ = calculate_sync(gf, config_prem, [30], source_time_function)
     assert str(execinfo.value) == "az must be a number"
     with pytest.raises(PyfkError) as execinfo:
         _ = calculate_sync(gf, config_prem, 30, None)
     assert str(execinfo.value) == "must provide a source time function"
     with pytest.raises(PyfkError) as execinfo:
         source_time_function_abnormal = generate_source_time_function(
             4, 0.5, 1.2)
         _ = calculate_sync(None, config_prem, 30,
                            source_time_function_abnormal)
     assert str(execinfo.value) == "check input Green's function"
     with pytest.raises(PyfkError) as execinfo:
         source_time_function_abnormal = generate_source_time_function(
             4, 0.5, 1.2)
         _ = calculate_sync(gf, config_prem, 30,
                            source_time_function_abnormal)
     assert str(
         execinfo.value
     ) == "delta for the source time function and the Green's function should be the same"