def test_decon(self): """ Convolution with subsequent deconvolution. """ # The incoming wavelet g = gaussian(51, 2.5) # Impulse response r = np.zeros_like(g) r[0] = 1 r[15] = .25 # convolve the two to a signal s = np.convolve(g, r)[:len(g)] # Deconvolve _, _, r2 = it(g, s, 1, omega_min=0.5) # test result self.assertTrue(np.allclose(r, r2[0:len(r)], atol=0.0001))
def test_it_max(self): """ Convolution with subsequent deconvolution. One Iteration should only recover the largest peak. """ # The incoming wavelet g = gaussian(51, 2.5) # Impulse response r = np.zeros_like(g) r[0] = 1 r[15] = .25 # convolve the two to a signal s = np.convolve(g, r)[:len(g)] # Deconvolve _, _, r2 = it(g, s, 1, it_max=1, omega_min=0.5) # test result self.assertFalse(np.allclose(r, r2[0:len(r)], atol=0.1)) self.assertAlmostEqual(r[0], r2[0], places=4)
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 moveout_test(PSS_file, q, phase): """ Creates synthetic PRFs and stacks them after depth migration. Parameters ---------- PSS_file : str Filename of raysum file containing P-Sv-Sh traces. q : float Slowness [s/m]. phase : str Either "P" for Ps or "S" for Sp. Returns ------- z : np.array Depth vector. stack : np.array Receiver function stack. RF_mo : np.array Matrix containing all depth migrated RFs. RF : np.array Matrix containing all RFs. dt : float Sampling interval. PSS : np.array Matrix containing all traces in P-Sv-Sh. """ rayp = q * 1.111949e5 PSS, dt, M, N, shift = read_raysum(phase, PSS_file=PSS_file) # Create receiver functions RF = [] RF_mo = [] stats = Stats() stats.npts = N stats.delta = dt stats.starttime = UTCDateTime(0) for i in range(M): if phase == "P": data, _, IR = it(PSS[i, 0, :], PSS[i, 1, :], dt, shift=shift, width=4) elif phase == "S": data, _, _ = it(PSS[i, 1, :], PSS[i, 0, :], dt, shift=shift, width=4) RF.append(data) z, rfc = moveout(data, stats, UTCDateTime(shift), rayp[i], phase, fname="raysum.dat") RF_mo.append(rfc) stack = np.average(RF_mo, axis=0) plt.close('all') plt.figure() for mo in RF_mo: plt.plot(z, mo) return z, stack, RF_mo, RF, dt, PSS