def test_hyperbolic2d(par): """Create small dataset with a hyperbolic event and check that output contains the event apex at correct time and correct amplitude """ # Data creation t0 = 50 vrms = 1 amp = 0.6 # Create axes t, _, x, _ = makeaxis(par) # Create data d, dwav = hyperbolic2d(x, t, t0, vrms, amp, wav) # Assert shape assert d.shape[0] == par['nx'] assert d.shape[1] == par['nt'] assert dwav.shape[0] == par['nx'] assert dwav.shape[1] == par['nt'] # Assert correct position of event assert_array_equal(d[par['nx'] // 2, t0], amp) assert_array_equal(dwav[par['nx'] // 2, t0], amp)
def test_hyperbolic3d(par): """Create small dataset with several hyperbolic events and check output contains the events at correct time and correct amplitude """ # Data creation t0 = 50 vrms_x = 1. vrms_y = 1. amp = 0.6 # Create axes t, _, x, y = makeaxis(par) # Create data d, dwav = hyperbolic3d(x, y, t, t0, vrms_x, vrms_y, amp, wav) #Assert shape assert d.shape[0] == par['ny'] assert d.shape[1] == par['nx'] assert d.shape[2] == par['nt'] assert dwav.shape[0] == par['ny'] assert dwav.shape[1] == par['nx'] assert dwav.shape[2] == par['nt'] # Assert correct position of event assert_array_equal(d[par['ny'] // 2, par['nx'] // 2, t0], amp)
def test_parabolic2d(par): """Create small dataset with a parabolic event and check that output contains the event apex at correct time and correct amplitude """ # Data creation t0 = 50 px = 0 pxx = 1e-1 amp = 0.6 # Create axes t, _, x, _ = makeaxis(par) # Create data d, dwav = parabolic2d(x, t, t0, px, pxx, amp, np.ones(1)) # Assert shape assert d.shape[0] == par['nx'] assert d.shape[1] == par['nt'] assert dwav.shape[0] == par['nx'] assert dwav.shape[1] == par['nt'] # Assert correct position of event assert_array_equal(d[par['nx'] // 2, t0], amp)
def test_linear2d(par): """Create small dataset with an horizontal event and check that output contains the event at correct time and correct amplitude """ # Data creation v = 1 t0 = 50 theta = 0. amp = 0.6 # Create axes t, _, x, _ = makeaxis(par) # Create data d, dwav = linear2d(x, t, v, t0, theta, amp, wav) # Assert shape assert d.shape[0] == par['nx'] assert d.shape[1] == par['nt'] assert dwav.shape[0] == par['nx'] assert dwav.shape[1] == par['nt'] # Assert correct position of event assert_array_equal(d[:, t0], amp * np.ones(par['nx']))
def test_multilinear2d(par): """Create small dataset with several horizontal events and check that output contains the events at correct time and correct amplitude """ # Data creation v = 1 t0 = (50, 130) theta = (0., 0.) amp = (0.6, 1) # Create axes t, _, x, _ = makeaxis(par) # Create data d, dwav = linear2d(x, t, v, t0, theta, amp, wav) # Assert shape assert d.shape[0] == par['nx'] assert d.shape[1] == par['nt'] assert dwav.shape[0] == par['nx'] assert dwav.shape[1] == par['nt'] # Assert correct position of event assert_array_equal(d[:, t0[0]], amp[0] * np.ones(par['nx'])) assert_array_equal(d[:, t0[1]], amp[1] * np.ones(par['nx']))
def test_MDC_Nvirtualsources(par): """Dot-test and comparison with pylops for MDC operator of N virtual source """ if par['twosided']: par['nt2'] = 2*par['nt'] - 1 else: par['nt2'] = par['nt'] v = 1500 it0_m = 25 t0_m = it0_m * par['dt'] theta_m = 0 phi_m = 0 amp_m = 1. it0_G = np.array([25, 50, 75]) t0_G = it0_G * par['dt'] theta_G = (0, 0, 0) phi_G = (0, 0, 0) amp_G = (1., 0.6, 2.) # Create axis t, _, x, y = makeaxis(par) # Create wavelet wav = ricker(t[:41], f0=par['f0'])[0] # Generate model _, mwav = linear3d(x, x, t, v, t0_m, theta_m, phi_m, amp_m, wav) # Generate operator _, Gwav = linear3d(x, y, t, v, t0_G, theta_G, phi_G, amp_G, wav) # Add negative part to data and model if par['twosided']: mwav = np.concatenate((np.zeros((par['nx'], par['nx'], par['nt'] - 1)), mwav), axis=-1) Gwav = np.concatenate((np.zeros((par['ny'], par['nx'], par['nt'] - 1)), Gwav), axis=-1) # Define MDC linear operator Gwav_fft = np.fft.fft(Gwav, par['nt2'], axis=-1) Gwav_fft = Gwav_fft[..., :par['nfmax']] dMDCop = dMDC(da.from_array(Gwav_fft.transpose(2, 0, 1)), nt=par['nt2'], nv=par['nx'], dt=par['dt'], dr=par['dx'], twosided=par['twosided']) MDCop = MDC(Gwav_fft.transpose(2, 0, 1), nt=par['nt2'], nv=par['nx'], dt=par['dt'], dr=par['dx'], twosided=par['twosided'], transpose=False, dtype='float32') dottest(dMDCop, par['nt2'] * par['ny'] * par['nx'], par['nt2'] * par['nx'] * par['nx'], chunks=((par['nt2'] * par['ny'] * par['nx'], par['nt2'] * par['nx'] * par['nx']))) mwav = mwav.T dy = (dMDCop * da.from_array(mwav.flatten())).compute() y = MDCop * mwav.flatten() assert_array_almost_equal(dy, y, decimal=5)
def MakeSeismic_paper(samples, img_size=128, freq_low=5, freq_high=30, num_events=6): """Simple generation of noisy synthetic linear seismic events. Input: samples = Number of samples in your dataset you want Output: clean_signal, noise, noisy_signal""" random.seed(101) # empty list to be filled with numpy arrays clean_signal = [] noise = [] noisy_signal = [] # Parameters for the seismic canvas par = { 'ox': 0, 'dx': 12.5, 'nx': img_size, # offsets 'ot': 0, 'dt': 0.004, 'nt': img_size, # time 'f0': 20, 'nfmax': 50 } # Make canvas t, t2, x, y = makeaxis(par) # Make wavelet wav = ricker(np.arange(41) * par['dt'], f0=par['f0'])[0] # Parameters for events v = 1500 ang_range = 50 amp_range = 2 i = 0 amp_lim = 0.2 t0 = [0.2, 0.3, 0.5, 0.8] amp = [-0.5, 1.2, -1.5, 0.8] theta = [10, -10, 5, -30] while i < samples: # Making events mlin, mlinwav = linear2d(x, t, v, t0, theta, amp, wav) # Creating noise n = np.random.normal(loc=0, scale=0.25, size=( img_size, img_size)) * random.uniform(-2, 2) # Adding noise s = mlinwav ns = s + n clean_signal.append(s) noise.append(n) noisy_signal.append(ns) i += 1 return np.array(clean_signal).reshape( samples, img_size, img_size, 1), np.array(noise).reshape( samples, img_size, img_size, 1), np.array(noisy_signal).reshape(samples, img_size, img_size, 1)
def test_MDC_1virtualsource(par): """Dot-test and inversion for MDC operator of 1 virtual source """ if par['twosided']: par['nt2'] = 2*par['nt'] - 1 else: par['nt2'] = par['nt'] v = 1500 t0_m = 0.2 theta_m = 0 amp_m = 1. t0_G = (0.1, 0.2, 0.3) theta_G = (0, 0, 0) phi_G = (0, 0, 0) amp_G = (1., 0.6, 2.) # Create axis t, _, x, y = makeaxis(par) # Create wavelet wav = ricker(t[:41], f0=par['f0'])[0] # Generate model _, mwav = linear2d(x, t, v, t0_m, theta_m, amp_m, wav) # Generate operator _, Gwav = linear3d(x, y, t, v, t0_G, theta_G, phi_G, amp_G, wav) # Add negative part to data and model if par['twosided']: mwav = np.concatenate((np.zeros((par['nx'], par['nt'] - 1)), mwav), axis=-1) Gwav = np.concatenate((np.zeros((par['ny'], par['nx'], par['nt'] - 1)), Gwav), axis=-1) # Define MDC linear operator Gwav_fft = np.fft.fft(Gwav, par['nt2'], axis=-1) Gwav_fft = Gwav_fft[..., :par['nfmax']] MDCop = MDC(Gwav_fft, nt=par['nt2'], nv=1, dt=par['dt'], dr=par['dx'], twosided=par['twosided'], dtype='float32') dottest(MDCop, par['nt2']*par['ny'], par['nt2']*par['nx']) # Create data d = MDCop * mwav.flatten() d = d.reshape(par['ny'], par['nt2']) # Apply mdd function minv = MDD(Gwav[:, :, par['nt']-1:] if par['twosided'] else Gwav, d[:, par['nt']-1:] if par['twosided'] else d, dt=par['dt'], dr=par['dx'], nfmax=par['nfmax'], twosided=par['twosided'], adjoint=False, psf=False, dtype='complex64', dottest=False, **dict(damp=1e-10, iter_lim=50, show=1)) assert_array_almost_equal(mwav, minv, decimal=2)
def test_makeaxis(par): """Verify makeaxis creation """ # Create t, x, and y axis t, _, x, y = makeaxis(par) # Check axis lenght assert len(t) == par['nt'] assert len(x) == par['nx'] assert len(y) == par['ny'] # Check axis initial and end values assert t[0] == par['ot'] assert t[-1] == par['ot'] + par['dt'] * (par['nt'] - 1) assert x[0] == par['ox'] assert x[-1] == par['ox'] + par['dx'] * (par['nx'] - 1) assert y[0] == par['oy'] assert y[-1] == par['oy'] + par['dy'] * (par['ny'] - 1)
def test_MDC_compute(par): """Ensure that forward and adjoint of MDC return numpy array when compute=True """ par['nt2'] = par['nt'] v = 1500 it0_m = 25 t0_m = it0_m * par['dt'] theta_m = 0 amp_m = 1. it0_G = np.array([25, 50, 75]) t0_G = it0_G * par['dt'] theta_G = (0, 0, 0) phi_G = (0, 0, 0) amp_G = (1., 0.6, 2.) # Create axis t, _, x, y = makeaxis(par) # Create wavelet wav = ricker(t[:41], f0=par['f0'])[0] # Generate model _, mwav = linear2d(x, t, v, t0_m, theta_m, amp_m, wav) # Generate operator _, Gwav = linear3d(x, y, t, v, t0_G, theta_G, phi_G, amp_G, wav) # Define MDC linear operator Gwav_fft = np.fft.fft(Gwav, par['nt2'], axis=-1) Gwav_fft = Gwav_fft[..., :par['nfmax']] dMDCop = dMDC(da.from_array(Gwav_fft.transpose(2, 0, 1)), nt=par['nt2'], nv=1, dt=par['dt'], dr=par['dx'], twosided=par['twosided'], todask=(True, True), compute=(True, True)) assert isinstance(dMDCop.matvec(np.ones(dMDCop.shape[1])), np.ndarray) assert isinstance(dMDCop.rmatvec(np.ones(dMDCop.shape[0])), np.ndarray)
def PlotSeis(data, num=0, save=False): size = np.array(data[0]).shape[1] # Parameters for the seismic canvas par = { 'ox': 0, 'dx': 12.5, 'nx': size, # offsets 'ot': 0, 'dt': 0.004, 'nt': size, # time 'f0': random.randint(5, 30), 'nfmax': 50 } # Make canvas t, t2, x, y = makeaxis(par) fig, axs = plt.subplots(1, len(data), figsize=(len(data * 4), 7)) vmin = -np.max(data[0][num]) vmax = np.max(data[0][num]) # Looping over datasets to compare for j in range(len(data)): im = axs[j].imshow(data[j][num].reshape(size, size).T, aspect='auto', interpolation='nearest', vmin=vmin, vmax=vmax, cmap='gray', extent=(x.min(), x.max(), t.max(), t.min())).set_cmap('Greys') # fig.colorbar(axs[-1], im) if save: file_name = input("file name:") plt.savefig('./results/images/%s_start%s.png' % (file_name, start))
par1 = PAR.copy() # analytical par1['kind'] = 'analytical' par2 = PAR.copy() # inverse par2['kind'] = 'inverse' # separation params vel_sep = 1000.0 # velocity at separation level rho_sep = 1000.0 # density at separation level critical = 0.9 ntaper = 41 nfftf = 2**8 nfftk = 2**7 # axes and wavelet t, t2, x, y = makeaxis(PAR) wav = ricker(t[:41], f0=PAR['f0'])[0] @pytest.fixture(scope="module") def create_data2D(): """Create 2d dataset """ t0_plus = np.array([0.05, 0.12]) t0_minus = t0_plus + 0.04 vrms = np.array([1400., 1800.]) amp = np.array([1., -0.6]) _, p2d_minus = hyperbolic2d(x, t, t0_minus, vrms, amp, wav) _, p2d_plus = hyperbolic2d(x, t, t0_plus, vrms, amp, wav)
'ny': 11, 'ot': 0, 'dt': 0.004, 'nt': 50, 'f0': 40 } par1 = {'ny': 8, 'nx': 10, 'nt': 20, 'dtype': 'float32'} # even par2 = {'ny': 9, 'nx': 11, 'nt': 21, 'dtype': 'complex64'} # odd # deghosting params vel_sep = 1000.0 # velocity at separation level zrec = 20.0 # depth of receivers # axes and wavelet t, t2, x, y = makeaxis(parmod) wav = ricker(t[:41], f0=parmod['f0'])[0] @pytest.fixture(scope="module") def create_data2D(): """Create 2d dataset """ t0_plus = np.array([0.02, 0.08]) t0_minus = t0_plus + 0.04 vrms = np.array([1400., 1800.]) amp = np.array([1., -0.6]) p2d_minus = hyperbolic2d(x, t, t0_minus, vrms, amp, wav)[1].T kx = np.fft.ifftshift(np.fft.fftfreq(parmod['nx'], parmod['dx']))
def test_MDC_Nvirtualsources(par): """Dot-test and inversion for MDC operator of N virtual source """ if par['twosided']: par['nt2'] = 2 * par['nt'] - 1 else: par['nt2'] = par['nt'] v = 1500 it0_m = 25 t0_m = it0_m * par['dt'] theta_m = 0 phi_m = 0 amp_m = 1. it0_G = np.array([25, 50, 75]) t0_G = it0_G * par['dt'] theta_G = (0, 0, 0) phi_G = (0, 0, 0) amp_G = (1., 0.6, 2.) # Create axis t, _, x, y = makeaxis(par) # Create wavelet wav = ricker(t[:41], f0=par['f0'])[0] # Generate model _, mwav = linear3d(x, x, t, v, t0_m, theta_m, phi_m, amp_m, wav) # Generate operator _, Gwav = linear3d(x, y, t, v, t0_G, theta_G, phi_G, amp_G, wav) # Add negative part to data and model if par['twosided']: mwav = np.concatenate((np.zeros( (par['nx'], par['nx'], par['nt'] - 1)), mwav), axis=-1) Gwav = np.concatenate((np.zeros( (par['ny'], par['nx'], par['nt'] - 1)), Gwav), axis=-1) # Define MDC linear operator Gwav_fft = np.fft.fft(Gwav, par['nt2'], axis=-1) Gwav_fft = Gwav_fft[..., :par['nfmax']] MDCop = MDC(Gwav_fft, nt=par['nt2'], nv=par['nx'], dt=par['dt'], dr=par['dx'], twosided=par['twosided'], dtype='float32') dottest(MDCop, par['nt2'] * par['ny'] * par['nx'], par['nt2'] * par['nx'] * par['nx']) # Create data d = MDCop * mwav.flatten() d = d.reshape(par['ny'], par['nx'], par['nt2']) # Check that events are at correct time for it, amp in zip(it0_G, amp_G): ittot = it0_m + it if par['twosided']: ittot += par['nt'] - 1 assert d[par['ny'] // 2, par['nx'] // 2, ittot] > \ d[par['ny'] // 2, par['nx'] // 2, ittot - 1] assert d[par['ny'] // 2, par['nx'] // 2, ittot] > \ d[par['ny'] // 2, par['nx'] // 2, ittot + 1] # Apply mdd function minv = MDD(Gwav[:, :, par['nt'] - 1:] if par['twosided'] else Gwav, d[:, :, par['nt'] - 1:] if par['twosided'] else d, dt=par['dt'], dr=par['dx'], nfmax=par['nfmax'], twosided=par['twosided'], adjoint=False, psf=False, dtype='complex64', dottest=False, **dict(damp=1e-10, iter_lim=50, show=1)) assert_array_almost_equal(mwav, minv, decimal=2) # Same tests for future behaviour (remove tests above in v2.0.0) MDCop = MDC(Gwav_fft.transpose(2, 0, 1), nt=par['nt2'], nv=par['nx'], dt=par['dt'], dr=par['dx'], twosided=par['twosided'], transpose=False, dtype='float32') dottest(MDCop, par['nt2'] * par['ny'] * par['nx'], par['nt2'] * par['nx'] * par['nx']) mwav = mwav.transpose(2, 0, 1) d = MDCop * mwav.flatten() d = d.reshape(par['nt2'], par['ny'], par['nx']) for it, amp in zip(it0_G, amp_G): ittot = it0_m + it if par['twosided']: ittot += par['nt'] - 1 assert d[ittot, par['ny'] // 2, par['nx'] // 2] > \ d[ittot - 1, par['ny'] // 2, par['nx'] // 2] assert d[ittot, par['ny'] // 2, par['nx'] // 2] > \ d[ittot + 1, par['ny'] // 2, par['nx'] // 2] minv = MDD( Gwav[:, :, par['nt'] - 1:] if par['twosided'] else Gwav, d[par['nt'] - 1:].transpose(1, 2, 0) if par['twosided'] else d.transpose(1, 2, 0), dt=par['dt'], dr=par['dx'], nfmax=par['nfmax'], twosided=par['twosided'], add_negative=True, adjoint=False, psf=False, dtype='complex64', dottest=False, **dict(damp=1e-10, iter_lim=50, show=1)) assert_array_almost_equal(mwav, minv.transpose(2, 0, 1), decimal=2)
np.random.seed(0) plt.close('all') ############################################################################### # Let's start by creating a very simple 2d data composed of 3 linear events # input parameters par = {'ox': 0, 'dx': 2, 'nx': 70, 'ot': 0, 'dt': 0.004, 'nt': 80, 'f0': 20} v = 1500 t0_m = [0.1, 0.2, 0.28] theta_m = [0, 30, -80] phi_m = [0] amp_m = [1., -2, 0.5] # axis taxis, t2, xaxis, y = makeaxis(par) # wavelet wav = ricker(taxis[:41], f0=par['f0'])[0] # model _, x = linear2d(xaxis, taxis, v, t0_m, theta_m, amp_m, wav) ############################################################################### # We can now define the spatial locations along which the data has been # sampled. In this specific example we will assume that we have access only to # 40% of the 'original' locations. perc_subsampling = 0.6 nxsub = int(np.round(par['nx'] * perc_subsampling)) iava = np.sort(np.random.permutation(np.arange(par['nx']))[:nxsub])
def MakeSeismic_VN(samples, img_size=256, num_events=10): """Simple generation of noisy synthetic linear seismic events. Input: samples = Number of samples in your dataset you want Output: clean_signal, noise, noisy_signal""" random.seed(101) # empty list to be filled with numpy arrays clean_signal = [] noise = [] noisy_signal = [] # Parameters for the seismic canvas par = { 'ox': 0, 'dx': 12.5, 'nx': img_size, # offsets 'ot': 0, 'dt': 0.004, 'nt': img_size, # time 'f0': random.randint(5, 70), 'nfmax': 50 } # initial tests, max freq was 50 # Make canvas t, t2, x, y = makeaxis(par) # Make wavelet wav = ricker(np.arange(41) * par['dt'], f0=par['f0'])[0] # Parameters for events v = 1500 # orig amp range was 50 ang_range = 80 amp_range = 2 i = 0 amp_lim = 0.8 lv = 1500 hv = 5000 while i < samples: iEv_l = 0 iEv_h = 0 t0_l = [] t0_h = [] theta_l = [] amp_l = [] amp_h = [] vel_h = [] num_lin = random.randint(2, num_events) num_hyp = num_events - num_lin while iEv_l <= num_lin: # Time of events t0_l.append(random.uniform(t.min(), t.max()) * 0.7) # Angle of events theta_l.append(random.uniform(-ang_range, ang_range)) # Amplitude of events amp_l.append(random.uniform(-amp_range, amp_range)) # clipping events to be above -0.2 and 0.2 if amp_l[iEv_l] < 0: amp_l[iEv_l] = np.min([-amp_lim, amp_l[iEv_l]]) else: amp_l[iEv_l] = np.max([amp_lim, amp_l[iEv_l]]) iEv_l += 1 while iEv_h <= num_hyp: # Time of events t0_h.append(random.uniform(t.min(), t.max()) * 0.7) # Amplitude of events amp_h.append(random.uniform(-amp_range, amp_range)) # velocity of hyperbolic events vel_h.append(random.uniform(lv, hv)) # clipping events to be above -0.2 and 0.2 if amp_h[iEv_h] < 0: amp_h[iEv_h] = np.min([-amp_lim, amp_h[iEv_h]]) else: amp_h[iEv_h] = np.max([amp_lim, amp_h[iEv_h]]) iEv_h += 1 # Making events mlin, mlinwav = linear2d(x, t, v, t0_l, theta_l, amp_l, wav) # print (t0_h, vel_h, amp_h) # Generate model m, mwav = hyperbolic2d(x, t, t0_h, vel_h, amp_h, wav) s = mwav + mlinwav # Creating and adding noise ns1 = random_noise(s, 'speckle', clip=False, var=random.uniform(0.2, 2)) ns2 = random_noise(s, 'gaussian', clip=False, var=random.uniform(0.05, 0.5)) ns3 = random_noise(s, 's&p', clip=False, amount=random.uniform(0.05, 0.2)) # Noise n1 = ns1 - s n2 = ns2 - s n3 = ns3 - s clean_signal.append(s) clean_signal.append(s) clean_signal.append(s) noise.append(n1) noise.append(n2) noise.append(n3) noisy_signal.append(ns1) noisy_signal.append(ns2) noisy_signal.append(ns3) i += 1 return np.array(clean_signal).reshape( samples * 3, img_size, img_size, 1), np.array(noise).reshape( samples * 3, img_size, img_size, 1), np.array(noisy_signal).reshape(samples * 3, img_size, img_size, 1)
def MakeSeismic(samples, img_size=128, freq_low=5, freq_high=30, num_events=6): """Simple generation of noisy synthetic linear seismic events. Input: samples = Number of samples in your dataset you want Output: clean_signal, noise, noisy_signal""" random.seed(101) # empty list to be filled with numpy arrays clean_signal = [] noise = [] noisy_signal = [] # Parameters for the seismic canvas par = { 'ox': 0, 'dx': 12.5, 'nx': img_size, # offsets 'ot': 0, 'dt': 0.004, 'nt': img_size, # time 'f0': random.randint(5, 70), 'nfmax': 50 } # initial tests, max freq was 30 # Make canvas t, t2, x, y = makeaxis(par) # Make wavelet wav = ricker(np.arange(41) * par['dt'], f0=par['f0'])[0] # Parameters for events v = 1500 ang_range = 50 amp_range = 2 i = 0 amp_lim = 0.2 while i < samples: iEv = 0 t0 = [] theta = [] amp = [] while iEv <= num_events: # Time of events t0.append(random.uniform(t.min(), t.max()) * 0.7) # Angle of events theta.append(random.uniform(-ang_range, ang_range)) # Amplitude of events amp.append(random.uniform(-amp_range, amp_range)) # clipping events to be above -0.2 and 0.2 if amp[iEv] < 0: amp[iEv] = np.min([-amp_lim, amp[iEv]]) else: amp[iEv] = np.max([amp_lim, amp[iEv]]) iEv += 1 # Making events mlin, mlinwav = linear2d(x, t, v, t0, theta, amp, wav) # Creating noise n = np.random.normal(loc=0, scale=0.25, size=(img_size, img_size)) # Adding noise s = mlinwav ns = s + n clean_signal.append(s) noise.append(n) noisy_signal.append(ns) i += 1 return np.array(clean_signal).reshape( samples, img_size, img_size, 1), np.array(noise).reshape( samples, img_size, img_size, 1), np.array(noisy_signal).reshape(samples, img_size, img_size, 1)
############################################################################### # Given a common-shot or common-midpoint (CMP) record, the objective of NMO # correction is to "flatten" events, that is, align events at later offsets # to that of the zero offset. NMO has long been a staple of seismic data # processing, used even today for initial velocity analysis and QC purposes. # In addition, it can be the domain of choice for many useful processing # steps, such as angle muting. # # To get started, let us create a 2D seismic dataset containing some hyperbolic # events representing reflections from flat reflectors. # Events are created with a true RMS velocity, which we will be using as if we # picked them from, for example, a semblance panel. par = dict(ox=0, dx=40, nx=80, ot=0, dt=0.004, nt=520) t, _, x, _ = makeaxis(par) t0s_true = np.array([0.5, 1.22, 1.65]) vrms_true = np.array([2000.0, 2400.0, 2500.0]) amps = np.array([1, 0.2, 0.5]) freq = 10 # Hz wav, *_ = ricker(t[:41], f0=freq) _, data = hyperbolic2d(x, t, t0s_true, vrms_true, amp=amps, wav=wav) ############################################################################### # NMO correction plot pclip = 0.5
def test_MDC_1virtualsource(par): """Dot-test and inversion for MDC operator of 1 virtual source""" if par["twosided"]: par["nt2"] = 2 * par["nt"] - 1 else: par["nt2"] = par["nt"] v = 1500 it0_m = 25 t0_m = it0_m * par["dt"] theta_m = 0 amp_m = 1.0 it0_G = np.array([25, 50, 75]) t0_G = it0_G * par["dt"] theta_G = (0, 0, 0) phi_G = (0, 0, 0) amp_G = (1.0, 0.6, 2.0) # Create axis t, _, x, y = makeaxis(par) # Create wavelet wav = ricker(t[:41], f0=par["f0"])[0] # Generate model _, mwav = linear2d(x, t, v, t0_m, theta_m, amp_m, wav) # Generate operator _, Gwav = linear3d(x, y, t, v, t0_G, theta_G, phi_G, amp_G, wav) # Add negative part to data and model if par["twosided"]: mwav = np.concatenate((np.zeros((par["nx"], par["nt"] - 1)), mwav), axis=-1) Gwav = np.concatenate((np.zeros( (par["ny"], par["nx"], par["nt"] - 1)), Gwav), axis=-1) # Define MDC linear operator Gwav_fft = np.fft.fft(Gwav, par["nt2"], axis=-1) Gwav_fft = Gwav_fft[..., :par["nfmax"]] MDCop = MDC( Gwav_fft, nt=par["nt2"], nv=1, dt=par["dt"], dr=par["dx"], fftengine="fftw", twosided=par["twosided"], dtype="float32", ) dottest(MDCop, par["nt2"] * par["ny"], par["nt2"] * par["nx"]) # Create data d = MDCop * mwav.ravel() d = d.reshape(par["ny"], par["nt2"]) # Check that events are at correct time and correct amplitude for it, amp in zip(it0_G, amp_G): ittot = it0_m + it if par["twosided"]: ittot += par["nt"] - 1 assert (np.abs(d[par["ny"] // 2, ittot] - np.abs(wav**2).sum() * amp_m * amp * par["nx"] * par["dx"] * par["dt"] * np.sqrt(par["nt2"])) < 1e-2) # Check that MDC with prescaled=True gives same result MDCpreop = MDC( np.sqrt(par["nt2"]) * par["dt"] * par["dx"] * Gwav_fft, nt=par["nt2"], nv=1, dt=par["dt"], dr=par["dx"], fftengine="fftw", twosided=par["twosided"], prescaled=True, dtype="float32", ) dottest(MDCpreop, par["nt2"] * par["ny"], par["nt2"] * par["nx"]) dpre = MDCpreop * mwav.ravel() dpre = dpre.reshape(par["ny"], par["nt2"]) assert_array_equal(d, dpre) # Apply mdd function minv = MDD(Gwav[:, :, par["nt"] - 1:] if par["twosided"] else Gwav, d[:, par["nt"] - 1:] if par["twosided"] else d, dt=par["dt"], dr=par["dx"], nfmax=par["nfmax"], twosided=par["twosided"], adjoint=False, psf=False, dtype="complex64", dottest=False, **dict(damp=1e-10, iter_lim=50, show=0)) assert_array_almost_equal(mwav, minv, decimal=2) # Same tests for future behaviour (remove tests above in v2.0.0) MDCop = MDC( Gwav_fft.transpose(2, 0, 1), nt=par["nt2"], nv=1, dt=par["dt"], dr=par["dx"], twosided=par["twosided"], transpose=False, dtype="float32", ) dottest(MDCop, par["nt2"] * par["ny"], par["nt2"] * par["nx"]) mwav = mwav.T d = MDCop * mwav.ravel() d = d.reshape(par["nt2"], par["ny"]) for it, amp in zip(it0_G, amp_G): ittot = it0_m + it if par["twosided"]: ittot += par["nt"] - 1 assert (np.abs(d[ittot, par["ny"] // 2] - np.abs(wav**2).sum() * amp_m * amp * par["nx"] * par["dx"] * par["dt"] * np.sqrt(par["nt2"])) < 1e-2) minv = MDD(Gwav[:, :, par["nt"] - 1:] if par["twosided"] else Gwav, d[par["nt"] - 1:].T if par["twosided"] else d.T, dt=par["dt"], dr=par["dx"], nfmax=par["nfmax"], twosided=par["twosided"], add_negative=True, adjoint=False, psf=False, dtype="complex64", dottest=False, **dict(damp=1e-10, iter_lim=50, show=0)) assert_array_almost_equal(mwav, minv.T, decimal=2)
"dt": 0.004, "nt": 40, "f0": 25, } v = 1500 t0 = [0.05, 0.1, 0.12] theta = [0, 30, -60] phi = [0, 50, 30] amp = [1.0, -2, 0.5] perc_subsampling = 0.7 nysub = int(np.round(par["ny"] * perc_subsampling)) iava = np.sort(np.random.permutation(np.arange(par["ny"]))[:nysub]) taxis, taxis2, xaxis, yaxis = makeaxis(par) wav = ricker(taxis[:41], f0=par["f0"])[0] # 2d model _, x2d = linear2d(yaxis, taxis, v, t0, theta, amp, wav) _, x3d = linear3d(xaxis, yaxis, taxis, v, t0, theta, phi, amp, wav) # Create restriction operator Rop2d = Restriction(par["ny"] * par["nt"], iava, dims=(par["ny"], par["nt"]), dir=0, dtype="float64") y2d = Rop2d * x2d.ravel() y2d = y2d.reshape(nysub, par["nt"]) Rop3d = Restriction(
'nx': 89, 'ot': 0, 'dt': 0.004, 'nt': 200, 'f0': 40 } t0_plus = np.array([0.2, 0.5, 0.7]) t0_minus = t0_plus + 0.04 vrms = np.array([1400., 1500., 2000.]) amp = np.array([1., -0.6, 0.5]) vel_sep = 1000.0 # velocity at separation level rho_sep = 1000.0 # density at separation level # Create axis t, t2, x, y = makeaxis(par) # Create wavelet wav = ricker(t[:41], f0=par['f0'])[0] # Create data _, p_minus = hyperbolic2d(x, t, t0_minus, vrms, amp, wav) _, p_plus = hyperbolic2d(x, t, t0_plus, vrms, amp, wav) ############################################################################### # We can now combine them to create pressure and particle velocity data critical = 1.1 ntaper = 51 nfft = 2**10 # 2d fft operator
def test_MDC_1virtualsource(par): """Dot-test and comparison with pylops for MDC operator of 1 virtual source """ if par['twosided']: par['nt2'] = 2 * par['nt'] - 1 else: par['nt2'] = par['nt'] v = 1500 it0_m = 25 t0_m = it0_m * par['dt'] theta_m = 0 amp_m = 1. it0_G = np.array([25, 50, 75]) t0_G = it0_G * par['dt'] theta_G = (0, 0, 0) phi_G = (0, 0, 0) amp_G = (1., 0.6, 2.) # Create axis t, _, x, y = makeaxis(par) # Create wavelet wav = ricker(t[:41], f0=par['f0'])[0] # Generate model _, mwav = linear2d(x, t, v, t0_m, theta_m, amp_m, wav) # Generate operator _, Gwav = linear3d(x, y, t, v, t0_G, theta_G, phi_G, amp_G, wav) # Add negative part to data and model if par['twosided']: mwav = np.concatenate((np.zeros((par['nx'], par['nt'] - 1)), mwav), axis=-1) Gwav = np.concatenate((np.zeros( (par['ny'], par['nx'], par['nt'] - 1)), Gwav), axis=-1) # Define MDC linear operator Gwav_fft = np.fft.fft(Gwav, par['nt2'], axis=-1) Gwav_fft = Gwav_fft[..., :par['nfmax']] dGwav_fft = da.from_array(Gwav_fft.transpose(2, 0, 1)) dMDCop = dMDC(dGwav_fft, nt=par['nt2'], nv=1, dt=par['dt'], dr=par['dx'], twosided=par['twosided']) MDCop = MDC(Gwav_fft.transpose(2, 0, 1), nt=par['nt2'], nv=1, dt=par['dt'], dr=par['dx'], twosided=par['twosided'], transpose=False, dtype='float32') dottest(dMDCop, par['nt2'] * par['ny'], par['nt2'] * par['nx'], chunks=((par['nt2'] * par['ny'], par['nt2'] * par['nx']))) # Compare results with pylops implementation mwav = mwav.T dy = dMDCop * da.from_array(mwav.flatten()) y = MDCop * mwav.flatten() assert_array_almost_equal(dy.compute(), y, decimal=5) # Apply mdd function dy = dy.reshape(par['nt2'], par['ny']) print(dy) minv = MDD(dGwav_fft, dy[par['nt'] - 1:] if par['twosided'] else dy, dt=par['dt'], dr=par['dx'], nfmax=par['nfmax'], twosided=par['twosided'], adjoint=False, dottest=False, **dict(niter=50)) print('minv', minv) assert_array_almost_equal(mwav, minv.compute(), decimal=2)