def test_shift_con_P(self): v = np.zeros((200, )) # pre-event noise v[:50] = np.random.random((50, )) * .5 v[50:] = np.random.random((150, )) * 10 qrf, lrf = spectraldivision(v, v, .1, 5, 'con', 'P') np.testing.assert_allclose(qrf, lrf) self.assertEqual(np.argmax(qrf), 50)
def decon_test(PSS_file, phase, method): """ Function to test a given deconvolution method with synthetic data created with raysum. Parameters ---------- PSS_file : str Filename of raysum file containing P-Sv-Sh traces. phase : str "S" or "P". method : str Deconvolution method: use 1. "fqd", "wat", or "con for frequency-dependent damped, waterlevel damped, constantly damped spectraldivision. 2. "it" for iterative deconvolution, and 3. "multit_con" or "multitap_fqd" for constantly or frequency-dependent damped multitaper deconvolution. Returns ------- RF : np.array Matrix containing all receiver functions. dt : float Sampling interval. """ PSS, dt, M, N, shift = read_raysum(phase, PSS_file=PSS_file) # Create receiver functions RF = [] for i in range(M): if phase == "P": u = PSS[i, 0, :] v = PSS[i, 1, :] elif phase == "S": u = PSS[i, 1, :] v = PSS[i, 0, :] if method == "it": data, _, _ = it(u, v, dt, shift=shift) lrf = None # elif method == "gen_it": # data, IR, iters, rej = gen_it(u, v, dt, phase=phase, shift=shift) # lrf = None elif method == "fqd" or method == "wat" or method == "con": data, lrf = spectraldivision(v, u, dt, shift, phase=phase, regul=method, test=True) elif method == "multit_fqd": data, lrf, _, _ = multitaper(u, v, dt, shift, 'fqd') data = lowpass(data, 4.99, 1 / dt, zerophase=True) elif method == "multit_con": data, lrf, _, data2 = multitaper(u, v, dt, shift, 'con') data = lowpass(data, 4.99, 1 / dt, zerophase=True) else: raise NameError # if lrf is not None: # # Normalisation for spectral division and multitaper # # In order to do that, we have to find the factor that is # necessary to # # bring the zero-time pulse to 1 # fact = abs(lrf).max() #[round(shift/dt)] # data = data/fact RF.append(RFTrace(data)) RF[-1].stats.delta = dt RF[-1].stats.starttime = UTCDateTime(0) RF[-1].stats.onset = UTCDateTime(0) + shift RF[-1].stats.type = 'time' RF[-1].stats.phase = phase RF[-1].stats.channel = phase + 'RF' RF[-1].stats.network = 'RS' RF = RFStream(RF) return RF, dt
def test_unknown_phase(self): with self.assertRaises(ValueError): spectraldivision(np.empty((25, )), np.empty((25, )), 1, 0, 'wat', 'XX')
def test_unknown_regul(self): with self.assertRaises(ValueError): spectraldivision(np.empty((25, )), np.empty((25, )), 1, 0, 'blabla', 'P')
def test_by_self_fqd_S(self): v = np.zeros((200, )) v[50:] = np.random.random((150, )) qrf, _ = spectraldivision(v, v, 2, 16, 'fqd', 'S') self.assertEqual(np.argmax(qrf), 8)
def test_by_self_wat_S(self): v = np.zeros((200, )) v[50:] = np.random.random((150, )) qrf, lrf = spectraldivision(v, v, 0.1, 5, 'wat', 'S') np.testing.assert_allclose(qrf, lrf) self.assertEqual(np.argmax(qrf), 50)