def raytrace(self, slowness, Tx, Rx, t0=()): nout = nargout() if nout != 1 and nout != 3 and nout != 4: raise SyntaxError('MeshTetrahedra.raytrace: 1, 3 or 4 output arguments allowed') # check input data consistency if Tx.ndim != 2 or Rx.ndim != 2: raise ValueError('Tx and Rx should be 2D arrays') if Tx.shape[1] != 3 or Rx.shape[1] != 3: raise ValueError('Tx and Rx should be ndata x 3') if Tx.shape != Rx.shape: raise ValueError('Tx and Rx should be of equal size') if len(slowness) != self.getNumberOfNodes(): raise ValueError('Length of slowness vector should equal number of nodes') if len(t0) == 0: t0 = np.zeros([Tx.shape[0],]) elif len(t0) != Tx.shape[0]: raise ValueError('Length of t0 should equal number of Tx') if self.cmesh == None: eps = 1.0e-15 rp_method = 1 maxit = 20 self.cmesh = cmesh3d.Mesh3Dcpp(self.nodes, self.cells, eps, maxit, rp_method, self.nthreads) if nout == 1: tt = self.cmesh.raytrace(slowness, Tx, Rx, t0) return tt elif nout == 3: tt, rays, v0 = self.cmesh.raytrace(slowness, Tx, Rx, t0) return tt, rays, v0
def raytrace(self, slowness, Tx, Rx, t0=()): nout = nargout() if nout != 1 and nout != 3 and nout != 4: raise SyntaxError( 'MeshTetrahedra.raytrace: 1, 3 or 4 output arguments allowed') # check input data consistency if Tx.ndim != 2 or Rx.ndim != 2: raise ValueError('Tx and Rx should be 2D arrays') if Tx.shape[1] != 3 or Rx.shape[1] != 3: raise ValueError('Tx and Rx should be ndata x 3') if Tx.shape != Rx.shape: raise ValueError('Tx and Rx should be of equal size') if len(slowness) != self.getNumberOfNodes(): raise ValueError( 'Length of slowness vector should equal number of nodes') if len(t0) == 0: t0 = np.zeros([ Tx.shape[0], ]) elif len(t0) != Tx.shape[0]: raise ValueError('Length of t0 should equal number of Tx') if self.cmesh == None: eps = 1.0e-15 rp_ho = True maxit = 20 self.cmesh = cmesh3d.Mesh3Dcpp(self.nodes, self.cells, eps, maxit, rp_ho, self.nthreads) if nout == 1: tt = self.cmesh.raytrace(slowness, Tx, Rx, t0) return tt elif nout == 3: tt, rays, v0 = self.cmesh.raytrace(slowness, Tx, Rx, t0) return tt, rays, v0 elif nout == 4: tt, rays, v0, M = self.cmesh.raytrace(slowness, Tx, Rx, t0) return tt, rays, v0, M
def lsplane(X): """ Least-squares plane (orthogonal distance regression) to a cloud of points Usages: x0,a = lsplane(x) x0,a,d,normd = lsplane(x) Input: x: cloud of points (n x 3) Output: x0: point on plane (3,) a: direction cosine of normal to plane (1x3) d: residuals normd: norm of residuals translation of the matlab function lsplane.m by I M Smith """ nout = nargout() m = X.shape[0] if m < 3: raise ValueError('At least 3 data points required') x0 = np.mean(X, axis=0).T A = np.vstack([X[:, 0] - x0[0], X[:, 1] - x0[1], X[:, 2] - x0[2]]).T (U, S, V) = np.linalg.svd(A) i = np.argmin(S) a = V[i, :].T if nout == 4: s = np.amin(S) d = U[:, i] * s normd = np.linalg.norm(d) return (x0, a, d, normd) elif nout == 2: return (x0, a)
def lsplane(X): """ Least-squares plane (orthogonal distance regression) to a cloud of points Usages: x0,a = lsplane(x) x0,a,d,normd = lsplane(x) Input: x: cloud of points (n x 3) Output: x0: point on plane (3,) a: direction cosine of normal to plane (1x3) d: residuals normd: norm of residuals translation of the matlab function lsplane.m by I M Smith """ nout = nargout() m = X.shape[0] if m < 3: raise ValueError('At least 3 data points required') x0 = np.mean(X, axis=0).T A = np.vstack([X[:,0]-x0[0], X[:,1]-x0[1], X[:,2]-x0[2]]).T (U,S,V) = np.linalg.svd(A) i = np.argmin(S) a = V[i,:].T if nout==4: s = np.amin(S) d = U[:,i]*s normd = np.linalg.norm(d) return (x0, a, d, normd) elif nout==2: return (x0, a)
def raytrace(self, slowness, Tx, Rx, t0=(), xi=(), theta=()): """ Compute traveltimes, raypaths and build ray projection matrix Usages: tt,L,rays = grid.raytrace(slowness,Tx,Rx,t0,xi,theta) tt,L = grid.raytrace(slowness,Tx,Rx,t0,xi,theta) {Note: rays can be omitted from output} Input: slowness: vector of slowness values at grid cells (ncell x 1) Tx: coordinates of sources points (ndata x 3) Rx: coordinates of receivers (ndata x 3) t0 (optional): initial time at sources points (ndata x 1) xi (optional): anisotropy ratio vector ( ncell x 1 ) values are ratio of slowness in Z over slowness in X theta (optional): angle of rotation of the ellipse of anisotropy ( ncell x 1 ), counter-clockwise from horizontal, units in radian Output: tt: vector of traveltimes, ndata by 1 L: ray projection matrix, ndata by ncell (ndata x 2*ncell for anisotropic media) rays: tuple containing the matrices of coordinates of the ray paths, ndata by 1. Each matrix is nPts by 2 """ nout = nargout() # check input data consistency if Tx.ndim != 2 or Rx.ndim != 2: raise ValueError('Tx and Rx should be 2D arrays') if Tx.shape[1] != 3 or Rx.shape[1] != 3: raise ValueError('Tx and Rx should be ndata x 3') if Tx.shape != Rx.shape: raise ValueError('Tx and Rx should be of equal size') if len(slowness) != self.getNumberOfCells(): raise ValueError( 'Length of slowness vector should equal number of cells') if len(xi) != 0 and len(xi) != len(slowness): raise ValueError('Length of xi should equal length of slowness') if len(theta) != 0 and len(theta) != len(slowness): raise ValueError('Length of theta should equal length of slowness') if len(t0) == 0: t0 = np.zeros([ Tx.shape[0], ]) elif len(t0) != Tx.shape[0]: raise ValueError('Length of t0 should equal number of Tx') if self.cgrid == None: nx = len(self.grx) - 1 nz = len(self.grz) - 1 dx = self.grx[1] - self.grx[0] dz = self.grz[1] - self.grz[0] typeG = b'iso' if len(xi) != 0: if len(theta) != 0: typeG = b'tilted' else: typeG = b'elliptical' self.cgrid = cgrid2d.Grid2Dcpp( typeG, nx, nz, dx, dz, self.grx[0], self.grz[0], # @UndefinedVariable self.nsnx, self.nsnz, self.nthreads) if nout == 2: tt, L = self.cgrid.raytrace(slowness, xi, theta, Tx, Rx, t0, nout) return tt, L elif nout == 3: tt, L, rays = self.cgrid.raytrace(slowness, xi, theta, Tx, Rx, t0, nout) return tt, L, rays
def raytrace(self, slowness, Tx, Rx, t0=(), xi=(), theta=()): """ Compute traveltimes, raypaths and build ray projection matrix Usages: tt,L,rays = grid.raytrace(slowness,Tx,Rx,t0,xi,theta) tt,L = grid.raytrace(slowness,Tx,Rx,t0,xi,theta) {Note: rays can be omitted from output} Input: slowness: vector of slowness values at grid cells (ncell x 1) Tx: coordinates of sources points (ndata x 3) Rx: coordinates of receivers (ndata x 3) t0 (optional): initial time at sources points (ndata x 1) xi (optional): anisotropy ratio vector ( ncell x 1 ) values are ratio of slowness in Z over slowness in X theta (optional): angle of rotation of the ellipse of anisotropy ( ncell x 1 ), counter-clockwise from horizontal, units in radian Output: tt: vector of traveltimes, ndata by 1 L: ray projection matrix, ndata by ncell (ndata x 2*ncell for anisotropic media) rays: tuple containing the matrices of coordinates of the ray paths, ndata by 1. Each matrix is nPts by 2 """ nout = nargout() # check input data consistency if Tx.ndim != 2 or Rx.ndim != 2: raise ValueError('Tx and Rx should be 2D arrays') if Tx.shape[1] !=3 or Rx.shape[1] != 3: raise ValueError('Tx and Rx should be ndata x 3') if Tx.shape != Rx.shape: raise ValueError('Tx and Rx should be of equal size') if len(slowness) != self.getNumberOfCells(): raise ValueError('Length of slowness vector should equal number of cells') if len(xi) != 0 and len(xi) != len(slowness): raise ValueError('Length of xi should equal length of slowness') if len(theta) != 0 and len(theta) != len(slowness): raise ValueError('Length of theta should equal length of slowness') if len(t0) == 0: t0 = np.zeros([Tx.shape[0],]) elif len(t0) != Tx.shape[0]: raise ValueError('Length of t0 should equal number of Tx') if self.cgrid == None: nx = len(self.grx)-1 nz = len(self.grz)-1 dx = self.grx[1]-self.grx[0] dz = self.grz[1]-self.grz[0] typeG = b'iso' if len(xi)!=0: if len(theta)!=0: typeG = b'tilted' else: typeG = b'elliptical' self.cgrid = cgrid2d.Grid2Dcpp(typeG,nx,nz,dx,dz,self.grx[0],self.grz[0], # @UndefinedVariable self.nsnx,self.nsnz,self.nthreads) if nout==2: tt,L = self.cgrid.raytrace(slowness,xi,theta,Tx,Rx,t0,nout) return tt,L elif nout==3: tt,L,rays = self.cgrid.raytrace(slowness,xi,theta,Tx,Rx,t0,nout) return tt,L,rays