def mask_time(D,shot,dt,dx,vel): # setup # dt = 4e-3 # dx = 10 # vel_ocean = 1490 nt,nr = D.size shot = shot - 1 # python stuffs start with zero x1 = np.arange(shot) x2 = np.arange(shot,nr) t1 = (shot-x1)*dx/(vel*dt) t2 = (x2-shot)*dx/(vel*dt) t_vec = np.concatenate((t1,t2),axis=None) + 140 # mask for sediment reflection t3 = np.sqrt(830**2 + ((shot-x1)*dx)**2/((vel*dt)**2)) t4 = np.sqrt(830**2 + ((x2-shot)*dx)**2/((vel*dt)**2)) t_vec2 = np.concatenate((t3,t4),axis=None) mask_t2 = np.zeros((nt,nr)) for i in np.arange(nr): mask_t2[int(t_vec[i]):int(t_vec2[i]),i] = 1 Sop_t = pylops.Smoothing2D(nsmooth=[11,3], dims=[nt, nr]) mask_2 = pylops.Diagonal(Sop_t*mask_t2.flatten()) D_mask = (mask_2*D.flatten()).reshape(nt,nr) return D_mask,mask_2
def mask_fre(D,shot,dt,dx,vel): """ Under construction, need to pratice on different data with different shot locations """ kn=1/(2*dx) dk=2*kn/nr mask_fre_loc = np.zeros((nt,nr)) v = np.zeros(nt) k1 = np.zeros(nt) k2 = np.zeros(nt) for i in np.arange(350,540): # v[i] = -vn + i*dv k1[i] = ((-vn + i*dv)/(vel)) /dk +shot k2[i] = ((-vn + i*dv)/(-1*vel)) /dk +shot mask_fre_loc[i,int(k1[i]):int(k2[i])] = 1 for i in np.arange(540,730): k1[i] = ((-vn + i*dv)/(vel) ) /dk +shot k2[i] = ((-vn + i*dv)/(-1*vel) ) /dk +shot mask_fre_loc[i,int(k2[i]):int(k1[i])] = 1 mask_fre_loc[530:550,140:160] = 1 mask_fre_iff = np.fft.ifftshift(mask_fre_loc.reshape(nt,nr)) mask_fre = pylops.Diagonal(mask_fre_iff) fre_dec = np.fft.fftshift(np.fft.fft2(D_dec_mask)) return mask_fre
def from_data_mapper_and_regularization( cls, visibilities: vis.Visibilities, noise_map: vis.VisibilitiesNoiseMap, transformer: trans.TransformerNUFFT, mapper: typing.Union[mappers.MapperRectangular, mappers.MapperVoronoi], regularization: reg.Regularization, settings=SettingsInversion(), ): regularization_matrix = regularization.regularization_matrix_from_mapper( mapper=mapper ) Aop = pylops.MatrixMult(sparse.bsr_matrix(mapper.mapping_matrix)) Fop = transformer Op = Fop * Aop curvature_matrix_approx = np.multiply( np.sum(noise_map.weight_list_ordered_1d), mapper.mapping_matrix.T @ mapper.mapping_matrix, ) preconditioner_matrix = np.add(curvature_matrix_approx, regularization_matrix) preconditioner_inverse_matrix = np.linalg.inv(preconditioner_matrix) MOp = pylops.MatrixMult(sparse.bsr_matrix(preconditioner_inverse_matrix)) log_det_curvature_reg_matrix_term = 2.0 * np.sum( np.log(np.diag(np.linalg.cholesky(preconditioner_matrix))) ) reconstruction = pylops.NormalEquationsInversion( Op=Op, Regs=None, epsNRs=[1.0], data=visibilities.ordered_1d, Weight=pylops.Diagonal(diag=noise_map.weight_list_ordered_1d), NRegs=[pylops.MatrixMult(sparse.bsr_matrix(regularization_matrix))], M=MOp, tol=settings.tolerance, atol=settings.tolerance, **dict(maxiter=settings.maxiter), ) return InversionInterferometerLinearOperator( visibilities=visibilities, noise_map=noise_map, transformer=transformer, mapper=mapper, regularization=regularization, regularization_matrix=regularization_matrix, reconstruction=np.real(reconstruction), settings=settings, log_det_curvature_reg_matrix_term=log_det_curvature_reg_matrix_term, )
def deriv(D, dx): fre = np.fft.fft2(D) kn = 1 / (2 * dx) ks = np.fft.fftfreq(nr, d=dx) coeff1 = 1j * 2 * np.pi * ks coeff2 = -(2 * np.pi * ks)**2 coeff1_m = np.tile(coeff1, nt) coeff2_m = np.tile(coeff2, nt) D1op_hand = pylops.Diagonal(coeff1_m) D2op_hand = pylops.Diagonal(coeff2_m) D1_hand_fre = D1op_hand * fre.flatten() D2_hand_fre = D2op_hand * fre.flatten() D1_hand = F.H * D1_hand_fre D2_hand = F.H * D2_hand_fre return D1_hand, D2_hand, D1op_hand, D2op_hand
ax.grid(linewidth=3, color='white') ax.xaxis.set_ticklabels([]) ax.yaxis.set_ticklabels([]) ############################################################################### # From now on, we can simply use the :py:func:`pylops.utils.dottest` implementation # of the dot-test and pass the operator we would like to validate, # its size in the model and data spaces and optionally the tolerance we will be # accepting for the dot-test to be considered succesfull. Finally we need to # specify if our data or/and model vectors contain complex numbers using the # ``complexflag`` parameter. While the dot-test will return ``True`` when # succesfull and ``False`` otherwise, we can also ask to print its outcome putting the # ``verb`` parameters to ``True``. N = 10 d = np.arange(N) Dop = pylops.Diagonal(d) dottest(Dop, N, N, tol=1e-6, complexflag=0, verb=True) ############################################################################### # We move now to a more complicated operator, the :py:func:`pylops.signalprocessing.FFT` # operator. We use once again the :py:func:`pylops.utils.dottest` to verify its implementation # and since we are dealing with a transform that can be applied to both real and complex # array, we try different combinations using the ``complexflag`` input. dt = 0.005 nt = 100 nfft = 2**10 FFTop = pylops.signalprocessing.FFT(dims=(nt, ), nfft=nfft, sampling=dt) dottest(FFTop, nfft, nt, complexflag=2, verb=True)
t1 = (loc - x1) * dx / (vel * dt) t2 = (x2 - loc) * dx / (vel * dt) t_vec = np.concatenate((t1, t2), axis=None) + 140 # mask for sediment reflection t3 = np.sqrt(830**2 + ((loc - x1) * dx)**2 / ((vel * dt)**2)) t4 = np.sqrt(830**2 + ((x2 - loc) * dx)**2 / ((vel * dt)**2)) t_vec2 = np.concatenate((t3, t4), axis=None) for k in np.arange(nr): mask_t[int(t_vec[k]):int(t_vec2[k]), k, i] = 1 Sop_t = pylops.Smoothing2D(nsmooth=[11, 3], dims=[nt, nr]) mask_t[:, :, i] = (Sop_t * mask_t[:, :, i].flatten()).reshape(nt, nr) mask_tt = pylops.Diagonal(mask_t.flatten()) D = (mask_tt * D.flatten()).reshape(nt, nr, ns) # mask on Fourier domain kn = 1 / (2 * dx) dk = 2 * kn / nr mask_fre_loc = np.zeros((nt, nr, ns)) vel = 1450 vn = 1 / (2 * dt) dv = 2 * vn / nt vs = np.arange(-vn, vn, dv) k1 = np.zeros(nt) k2 = np.zeros(nt)
t_vec = np.concatenate((t1, t2), axis=None) + 140 # mask for sediment reflection t3 = np.sqrt(830**2 + ((150 - x1) * dx)**2 / ((vel_ocean * dt)**2)) t4 = np.sqrt(830**2 + ((x2 - 150) * dx)**2 / ((vel_ocean * dt)**2)) t_vec2 = np.concatenate((t3, t4), axis=None) mask_t2 = np.zeros((nt, nr)) for i in np.arange(nr): mask_t2[int(t_vec[i]):int(t_vec2[i]), i] = 1 Sop_t = pylops.Smoothing2D(nsmooth=[11, 3], dims=[nt, nr]) mask_ts = (Sop_t * mask_t2.flatten()).reshape(nt, nr) mask_2 = pylops.Diagonal(mask_ts.T) D_adj_mask = (mask_2 * D_adj.flatten()).reshape(nr, nt) D_dec_mask = (R * D_adj_mask.flatten()).reshape(idr.size, nt) D_mask2 = mask_2 * D.flatten() D_aft = D_mask2.reshape(nr, nt) scail = abs((D_aft).max()) ND = (D_aft) / scail nwins = 10 winsize = 40 overlap = (nwins * winsize - nr) / (nwins - 1) pmax = 1e-4 npx = 100 px = np.linspace(-pmax, pmax, npx)
import numpy as np import matplotlib.pyplot as plt import matplotlib.gridspec as pltgs import pylops plt.close('all') ############################################################################### # Let's define a diagonal operator :math:`\mathbf{d}` with increasing numbers from # ``0`` to ``N`` and a unitary model :math:`\mathbf{x}`. N = 10 d = np.arange(N) x = np.ones(10) Dop = pylops.Diagonal(d) y = Dop * x y1 = Dop.H * x gs = pltgs.GridSpec(1, 6) fig = plt.figure(figsize=(7, 3)) ax = plt.subplot(gs[0, 0:3]) im = ax.imshow(Dop.matrix(), cmap='rainbow', vmin=0, vmax=N) ax.set_title('A', size=20, fontweight='bold') ax.set_xticks(np.arange(N - 1) + 0.5) ax.set_yticks(np.arange(N - 1) + 0.5) ax.grid(linewidth=3, color='white') ax.xaxis.set_ticklabels([]) ax.yaxis.set_ticklabels([]) ax = plt.subplot(gs[0, 3])