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))
 def test_amplify_by_tf__case_1_an_artificial_transfer_function(self):
     gm = GM(_join(f_dir, '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))
    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))