Ejemplo n.º 1
0
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']))
Ejemplo n.º 2
0
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']))
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
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_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']]

    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'])
    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'])))

    mwav = mwav.T
    dy = (dMDCop * da.from_array(mwav.flatten())).compute()
    y = MDCop * mwav.flatten()
    assert_array_almost_equal(dy, y, decimal=5)
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)
Ejemplo n.º 7
0
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)
Ejemplo n.º 8
0
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])

# restriction operator
Rop = pylops.Restriction(par['nx'] * par['nt'],
                         iava,
                         dims=(par['nx'], par['nt']),
                         dir=0,
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)
Ejemplo n.º 11
0
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(
    par["ny"] * par["nx"] * par["nt"],
    iava,
    dims=(par["ny"], par["nx"], par["nt"]),
    dir=0,