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_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))
def test_deconvolution(self): ''' Test that `deconvolve()` and `amplify()` are reverse operations to each other. ''' gm = GM(_join(f_dir, 'sample_accel.txt'), unit='m') vs_prof = Vs_Profile(_join(f_dir, 'profile_FKSH14.txt')) for boundary in ['elastic', 'rigid']: deconv_motion = gm.deconvolve(vs_prof, boundary=boundary) output_motion = deconv_motion.amplify(vs_prof, boundary=boundary) self.assertTrue(self.nearly_identical(gm.accel, output_motion.accel)) amplified_motion = gm.amplify(vs_prof, boundary=boundary) output_motion = amplified_motion.deconvolve(vs_prof, boundary=boundary) self.assertTrue(self.nearly_identical(gm.accel, output_motion.accel))
def test_amplify_via_profile(self): gm = GM(_join(f_dir, 'sample_accel.txt'), unit='m') vs_prof = Vs_Profile(_join(f_dir, 'profile_FKSH14.txt')) output_motion = gm.amplify(vs_prof, boundary='elastic') self.assertTrue(isinstance(output_motion, GM))