def model_grad_rand_2d(c=2000, randc=100, dc=1, freq=25, dx=5, dt=0.0001, nx=[20, 20], propagator=None, prop_kwargs=None): """Create a point scatterer model, and the gradient. """ nt = int((3 * nx[0] * dx / c + 0.1) / dt) middle = int(nx[1] / 2) x_s, x_s_idx = _set_coords([[1, middle]], dx) x_r, x_r_idx = _set_coords([[1, middle]], dx) x_p, x_p_idx = _set_coords([[nx[0] - 5, middle]], dx) f = ricker(freq, nt, dt, 0.05) model_init = (np.random.rand(nx[0], nx[1]).astype(np.float32) * randc) + c model_true = model_init.copy() model_true += np.random.rand(nx[0], nx[1]).astype(np.float32) * dc fwi_grad, true_grad = grad_2d_fd(model_true, model_init, x_r, x_s, dx, dt, dc, f, propagator, prop_kwargs) return fwi_grad, true_grad
def model_grad_const_2d(c=1500, dc=1, freq=25, dx=5, dt=0.0001, nx=[20, 20], propagator=None, prop_kwargs=None): """Create a point scatterer model, and the gradient. """ nt = int((3 * nx[0] * dx / c + 0.1) / dt) middle = int(nx[1] / 2) x_s, x_s_idx = _set_coords([[1, middle]], dx) x_r, x_r_idx = _set_coords([[1, middle]], dx) x_p, x_p_idx = _set_coords([[nx[0] - 5, middle]], dx) f = ricker(freq, nt, dt, 0.05) model_init = np.ones(nx, dtype=np.float32) * c model_true = model_init.copy() model_true[x_p_idx[0, 0], x_p_idx[0, 1]] += dc expected = grad_2d(nx, x_r, x_s, x_p, dx, dt, c, dc, f) fwi_grad, true_grad = grad_2d_fd(model_true, model_init, x_r, x_s, dx, dt, dc, f, propagator, prop_kwargs) return expected, fwi_grad, true_grad
def model_direct_2d(c=1500, freq=25, dx=5, dt=0.0001, nx=[50, 50], propagator=None, prop_kwargs=None): """Create a constant model, and the expected waveform at point, and the forward propagated wave. """ model = np.ones(nx, dtype=np.float32) * c nt = int(2 * nx[0] * dx / c / dt) middle = int(nx[1] / 2) x_s, x_s_idx = _set_coords([[1, middle]], dx) x_r, x_r_idx = _set_coords([[nx[0] - 1, middle]], dx) #x_r, x_r_idx = _set_coords([[1, middle]], dx) f = ricker(freq, nt, dt, 0.05) expected = direct_2d_approx(x_r, x_s, dx, dt, c, f) source, receiver_locations = _make_source_receiver(x_s_idx, x_r_idx, f) if propagator is None: propagator = Scalar2D if prop_kwargs is None: prop_kwargs = {} prop = propagator(model, dx, dt, source, **prop_kwargs) actual, _ = forward_model(prop, receiver_locations) return expected, actual.receivers.ravel()
def model_scatter_2d(c=1500, dc=150, freq=25, dx=5, dt=0.0001, nx=[50, 50], propagator=None, prop_kwargs=None): """Create a point scatterer model, and the expected waveform at point, and the forward propagated wave. """ nx = np.array(nx) model = np.ones(nx, dtype=np.float32) * c nt = int((3 * nx[0] * dx / c + 0.05) / dt) middle = int(nx[1] / 2) x_s, x_s_idx = _set_coords([[1, middle]], dx) x_r, x_r_idx = _set_coords([[1, middle]], dx) x_p, x_p_idx = _set_coords([[nx[0] - 10, middle]], dx) f = ricker(freq, nt, dt, 0.05) model[x_p_idx[0, 0], x_p_idx[0, 1]] += dc expected = scattered_2d(x_r, x_s, x_p, dx, dt, c, dc, f) source, receiver_locations = _make_source_receiver(x_s_idx, x_r_idx, f) if propagator is None: propagator = Scalar2D if prop_kwargs is None: prop_kwargs = {} prop = propagator(model, dx, dt, source, **prop_kwargs) actual, _ = forward_model(prop, receiver_locations) return expected, actual.receivers.ravel()
def _setup_propagator(c, freq, dx, dt, nt, nx, num_shots, num_sources_per_shot, num_receivers_per_shot, prop_kwargs): model = np.ones(nx, np.float32) * c x_s_idx = np.ones([num_shots, num_sources_per_shot, 2], np.int) x_s_idx[:, :, 1] = np.tile(np.linspace(1, nx[1] - 1, num_sources_per_shot), [num_shots, 1]) f = ricker(freq, nt, dt, 0.05) source = {} source['amplitude'] = np.tile(f, [num_shots, num_sources_per_shot, 1]) source['locations'] = x_s_idx x_r_idx = np.ones([num_shots, num_receivers_per_shot, 2], np.int) x_r_idx[:, :, 1] = np.tile(np.linspace(1, nx[1] - 1, num_receivers_per_shot), [num_shots, 1]) x_r_idx[:, :, 0] = nx[0] - 1 prop_args = (model, dx, dt, source) if len(prop_kwargs) == 0: prop_kwargs = {'pml_width': 30} return prop_args, prop_kwargs, x_r_idx