|
| 1 | +r""" |
| 2 | +Acoustic Wave Equation modelling |
| 3 | +================================ |
| 4 | +
|
| 5 | +This example shows how to perform acoustic wave equation modelling |
| 6 | +using the :class:`pylops.waveeqprocessing.AcousticWave2D` operator, |
| 7 | +which brings the power of finite-difference modelling via the Devito |
| 8 | +modelling engine to PyLops. |
| 9 | +""" |
| 10 | +import matplotlib.pyplot as plt |
| 11 | +import numpy as np |
| 12 | +from scipy.ndimage import gaussian_filter |
| 13 | + |
| 14 | +import pylops |
| 15 | + |
| 16 | +plt.close("all") |
| 17 | +np.random.seed(0) |
| 18 | + |
| 19 | + |
| 20 | +############################################################################### |
| 21 | +# To begin with, we will create a simple layered velocity model. We will also |
| 22 | +# define a background velocity model by smoothing the original velocity model |
| 23 | +# which will be responsible of the kinematic of the wavefield modelled via |
| 24 | +# Born modelling, and the perturbation velocity model which will lead to |
| 25 | +# scattering effects and therefore guide the dynamic of the modelled wavefield. |
| 26 | + |
| 27 | +# Velocity Model |
| 28 | +nx, nz = 61, 40 |
| 29 | +dx, dz = 4, 4 |
| 30 | +x, z = np.arange(nx) * dx, np.arange(nz) * dz |
| 31 | +vel = 1000 * np.ones((nx, nz)) |
| 32 | +vel[:, 15:] = 1200 |
| 33 | +vel[:, 35:] = 1600 |
| 34 | + |
| 35 | +# Smooth velocity model |
| 36 | +v0 = gaussian_filter(vel, sigma=10) |
| 37 | + |
| 38 | +# Born perturbation from m - m0 |
| 39 | +dv = vel ** (-2) - v0 ** (-2) |
| 40 | + |
| 41 | +# Receivers |
| 42 | +nr = 101 |
| 43 | +rx = np.linspace(0, x[-1], nr) |
| 44 | +rz = 20 * np.ones(nr) |
| 45 | +recs = np.vstack((rx, rz)) |
| 46 | +dr = recs[0, 1] - recs[0, 0] |
| 47 | + |
| 48 | +# Sources |
| 49 | +ns = 3 |
| 50 | +sx = np.linspace(0, x[-1], ns) |
| 51 | +sz = 10 * np.ones(ns) |
| 52 | +sources = np.vstack((sx, sz)) |
| 53 | + |
| 54 | +plt.figure(figsize=(10, 5)) |
| 55 | +im = plt.imshow(vel.T, cmap="summer", extent=(x[0], x[-1], z[-1], z[0])) |
| 56 | +plt.scatter(recs[0], recs[1], marker="v", s=150, c="b", edgecolors="k") |
| 57 | +plt.scatter(sources[0], sources[1], marker="*", s=150, c="r", edgecolors="k") |
| 58 | +cb = plt.colorbar(im) |
| 59 | +cb.set_label("[m/s]") |
| 60 | +plt.axis("tight") |
| 61 | +plt.xlabel("x [m]"), plt.ylabel("z [m]") |
| 62 | +plt.title("Velocity") |
| 63 | +plt.xlim(x[0], x[-1]) |
| 64 | +plt.tight_layout() |
| 65 | + |
| 66 | +plt.figure(figsize=(10, 5)) |
| 67 | +im = plt.imshow(dv.T, cmap="seismic", extent=(x[0], x[-1], z[-1], z[0])) |
| 68 | +plt.scatter(recs[0], recs[1], marker="v", s=150, c="b", edgecolors="k") |
| 69 | +plt.scatter(sources[0], sources[1], marker="*", s=150, c="r", edgecolors="k") |
| 70 | +cb = plt.colorbar(im) |
| 71 | +cb.set_label("[m/s]") |
| 72 | +plt.axis("tight") |
| 73 | +plt.xlabel("x [m]"), plt.ylabel("z [m]") |
| 74 | +plt.title("Velocity perturbation") |
| 75 | +plt.xlim(x[0], x[-1]) |
| 76 | +plt.tight_layout() |
| 77 | + |
| 78 | +############################################################################### |
| 79 | +# Let us now define the Born modelling operator |
| 80 | + |
| 81 | +Aop = pylops.waveeqprocessing.AcousticWave2D( |
| 82 | + (nx, nz), |
| 83 | + (0, 0), |
| 84 | + (dx, dz), |
| 85 | + v0, |
| 86 | + sources[0], |
| 87 | + sources[1], |
| 88 | + recs[0], |
| 89 | + recs[1], |
| 90 | + 0.0, |
| 91 | + 0.5 * 1e3, |
| 92 | + "Ricker", |
| 93 | + space_order=4, |
| 94 | + nbl=100, |
| 95 | + f0=15, |
| 96 | + dtype="float32", |
| 97 | +) |
| 98 | + |
| 99 | +############################################################################### |
| 100 | +# And we use it to model our data |
| 101 | + |
| 102 | +dobs = Aop @ dv |
| 103 | + |
| 104 | +fig, axs = plt.subplots(1, 3, sharey=True, figsize=(10, 6)) |
| 105 | +fig.suptitle("FD modelling with Ricker", y=0.99) |
| 106 | + |
| 107 | +for isrc in range(ns): |
| 108 | + axs[isrc].imshow( |
| 109 | + dobs[isrc].reshape(Aop.geometry.nrec, Aop.geometry.nt).T, |
| 110 | + cmap="gray", |
| 111 | + vmin=-1e-7, |
| 112 | + vmax=1e-7, |
| 113 | + extent=( |
| 114 | + recs[0, 0], |
| 115 | + recs[0, -1], |
| 116 | + Aop.geometry.time_axis.time_values[-1] * 1e-3, |
| 117 | + 0, |
| 118 | + ), |
| 119 | + ) |
| 120 | + axs[isrc].axis("tight") |
| 121 | + axs[isrc].set_xlabel("rec [m]") |
| 122 | +axs[0].set_ylabel("t [s]") |
| 123 | +fig.tight_layout() |
| 124 | + |
| 125 | +############################################################################### |
| 126 | +# Finally, we are going to show how despite the |
| 127 | +# :class:`pylops.waveeqprocessing.AcousticWave2D` operator allows a user to |
| 128 | +# specify a limited number of source wavelets (this is directly borrowed from |
| 129 | +# Devito), a simple modification can be applied to pass any user defined wavelet. |
| 130 | +# We are going to do that with a Ormsby wavelet |
| 131 | + |
| 132 | +# Extract Ricker wavelet |
| 133 | +wav = Aop.geometry.src.data[:, 0] |
| 134 | +wavc = np.argmax(wav) |
| 135 | + |
| 136 | +# Define Ormsby wavelet |
| 137 | +wavest = pylops.utils.wavelets.ormsby( |
| 138 | + Aop.geometry.time_axis.time_values[:wavc] * 1e-3, f=[3, 20, 30, 45] |
| 139 | +)[0] |
| 140 | + |
| 141 | +# Update wavelet in operator and model new data |
| 142 | +Aop.updatesrc(wavest) |
| 143 | + |
| 144 | +dobs1 = Aop @ dv |
| 145 | + |
| 146 | +fig, axs = plt.subplots(1, 3, sharey=True, figsize=(10, 6)) |
| 147 | +fig.suptitle("FD modelling with Ormsby", y=0.99) |
| 148 | + |
| 149 | +for isrc in range(ns): |
| 150 | + axs[isrc].imshow( |
| 151 | + dobs1[isrc].reshape(Aop.geometry.nrec, Aop.geometry.nt).T, |
| 152 | + cmap="gray", |
| 153 | + vmin=-1e-7, |
| 154 | + vmax=1e-7, |
| 155 | + extent=( |
| 156 | + recs[0, 0], |
| 157 | + recs[0, -1], |
| 158 | + Aop.geometry.time_axis.time_values[-1] * 1e-3, |
| 159 | + 0, |
| 160 | + ), |
| 161 | + ) |
| 162 | + axs[isrc].axis("tight") |
| 163 | + axs[isrc].set_xlabel("rec [m]") |
| 164 | +axs[0].set_ylabel("t [s]") |
| 165 | +fig.tight_layout() |
| 166 | + |
| 167 | +fig, axs = plt.subplots(1, 2, figsize=(10, 3)) |
| 168 | +axs[0].plot(wav[: 2 * wavc], "k") |
| 169 | +axs[0].plot(wavest, "r") |
| 170 | +axs[1].plot( |
| 171 | + dobs[isrc].reshape(Aop.geometry.nrec, Aop.geometry.nt)[nr // 2], "k", label="Ricker" |
| 172 | +) |
| 173 | +axs[1].plot( |
| 174 | + dobs1[isrc].reshape(Aop.geometry.nrec, Aop.geometry.nt)[nr // 2], |
| 175 | + "r", |
| 176 | + label="Ormsby", |
| 177 | +) |
| 178 | +axs[1].legend() |
| 179 | +fig.tight_layout() |
0 commit comments