def test_amplify_by_tf(self):
        #---------- Case 1: An artificial transfer function -------------------
        gm = GM('./files/sample_accel.txt', unit='gal')
        ratio_benchmark = 2.76
        freq = np.arange(0.01, 50, step=0.01)
        tf = ratio_benchmark * np.ones_like(freq)
        transfer_function = Frequency_Spectrum(np.column_stack((freq, tf)))
        new_gm = gm.amplify_by_tf(transfer_function, show_fig=False)
        ratio = new_gm.accel[:, 1] / gm.accel[:, 1]
        self.assertTrue(np.allclose(ratio, ratio_benchmark))

        #---------- Case 2: A transfer function from a Vs profile -------------
        vs_prof = Vs_Profile('./files/profile_FKSH14.txt')
        tf_RO, tf_BH, _ = vs_prof.get_transfer_function()
        gm_with_tf_RO = gm.amplify_by_tf(tf_RO)
        gm_with_tf_BH = gm.amplify_by_tf(tf_BH)

        gm_with_tf_RO_ = gm.amplify(vs_prof, boundary='elastic')
        gm_with_tf_BH_ = gm.amplify(vs_prof, boundary='rigid')

        # Assert that `amplify_by_tf()` and `amplify()` can generate
        # nearly identical results
        self.assertTrue(
            self.nearly_identical(gm_with_tf_RO.accel, gm_with_tf_RO_.accel))
        self.assertTrue(
            self.nearly_identical(gm_with_tf_BH.accel, gm_with_tf_BH_.accel))
Exemplo n.º 2
0
    def test_plot(self):
        # Test that the desired data are correctly imported to the object
        accel_in = Ground_Motion(_join(f_dir, 'sample_accel.txt'),
                                 unit='m/s/s')
        accel_tmp = accel_in.accel.copy()
        accel_tmp[:, 1] *= 5.0
        accel_out = Ground_Motion(accel_tmp, unit='m/s/s')
        vs_profile = Vs_Profile(_join(f_dir, 'profile_FKSH14.txt'))
        thk = vs_profile._thk
        depth_bound = sr.thk2dep(thk, midpoint=False)
        depth_midpoint = sr.thk2dep(thk, midpoint=True)
        max_a_v_d = np.column_stack(
            (depth_bound, depth_bound * 1, depth_bound * 2, depth_bound * 3))
        max_gamma_tau = np.column_stack(
            (depth_midpoint, depth_midpoint * 1, depth_midpoint * 2))
        tf_RO, _, _ = vs_profile.get_transfer_function()
        sim_results = Simulation_Results(accel_in,
                                         accel_out,
                                         vs_profile,
                                         max_a_v_d=max_a_v_d,
                                         max_strain_stress=max_gamma_tau,
                                         trans_func=tf_RO)
        sim_results.plot(save_fig=False)

        # Test that it can produce a plot without max profiles and trans. func.
        sim_results_ = Simulation_Results(accel_in, accel_out, vs_profile)
        sim_results_.plot(save_fig=False)
    def test_amplify_by_tf__case_2_a_transfer_function_from_a_Vs_profile(self):
        gm = GM(_join(f_dir, 'sample_accel.txt'), unit='gal')
        vs_prof = Vs_Profile(_join(f_dir, 'profile_FKSH14.txt'))
        tf_RO, tf_BH, _ = vs_prof.get_transfer_function()
        gm_with_tf_RO = gm.amplify_by_tf(tf_RO)
        gm_with_tf_BH = gm.amplify_by_tf(tf_BH)

        gm_with_tf_RO_ = gm.amplify(vs_prof, boundary='elastic')
        gm_with_tf_BH_ = gm.amplify(vs_prof, boundary='rigid')

        # Assert that `amplify_by_tf()` and `amplify()` can generate
        # nearly identical results
        self.assertTrue(self.nearly_identical(gm_with_tf_RO.accel,
                                              gm_with_tf_RO_.accel))
        self.assertTrue(self.nearly_identical(gm_with_tf_BH.accel,
                                              gm_with_tf_BH_.accel))