def test_surface2ind_topo(self): file_url = "https://storage.googleapis.com/simpeg/tests/utils/vancouver_topo.xyz" file2load = download(file_url) vancouver_topo = np.loadtxt(file2load) mesh_topo = Mesh.TensorMesh([ [(500., 24)], [(500., 20)], [(10., 30)] ], x0='CCC') indtopoCC = surface2ind_topo(mesh_topo, vancouver_topo, gridLoc='CC', method='nearest') indtopoN = surface2ind_topo(mesh_topo, vancouver_topo, gridLoc='N', method='nearest') assert len(np.where(indtopoCC)[0]) == 8729 assert len(np.where(indtopoN)[0]) == 8212
def run(plotIt=True, nx=5, ny=5): """ Utils: surface2ind_topo ======================= Here we show how to use :code:`Utils.surface2ind_topo` to identify cells below a topographic surface. """ mesh = Mesh.TensorMesh([nx,ny], x0='CC') # 2D mesh xtopo = np.linspace(mesh.gridN[:,0].min(), mesh.gridN[:,0].max()) topo = 0.4*np.sin(xtopo*5) # define a topographic surface Topo = np.hstack([Utils.mkvc(xtopo,2), Utils.mkvc(topo,2)]) #make it an array indcc = surface2ind_topo(mesh, Topo, 'CC') if plotIt: from matplotlib.pylab import plt from scipy.interpolate import interp1d fig, ax = plt.subplots(1,1, figsize=(6,6)) mesh.plotGrid(ax=ax, nodes=True, centers=True) ax.plot(xtopo,topo,'k',linewidth=1) ax.plot(mesh.vectorCCx, interp1d(xtopo,topo)(mesh.vectorCCx),'--k',linewidth=3) aveN2CC = Utils.sdiag(mesh.aveN2CC.T.sum(1))*mesh.aveN2CC.T a = aveN2CC * indcc a[a > 0] = 1. a[a < 0.25] = np.nan a = a.reshape(mesh.vnN, order='F') masked_array = np.ma.array(a, mask=np.isnan(a)) ax.pcolor(mesh.vectorNx,mesh.vectorNy,masked_array.T, cmap=plt.cm.gray, alpha=0.2) plt.show()
def run(plotIt=True, nx=5, ny=5): # 2D mesh mesh = Mesh.TensorMesh([nx, ny], x0='CC') xtopo = np.linspace(mesh.gridN[:, 0].min(), mesh.gridN[:, 0].max()) # define a topographic surface topo = 0.4 * np.sin(xtopo * 5) # make it an array Topo = np.hstack([Utils.mkvc(xtopo, 2), Utils.mkvc(topo, 2)]) indcc = surface2ind_topo(mesh, Topo, 'CC') if plotIt: fig, ax = plt.subplots(1, 1, figsize=(6, 6)) mesh.plotGrid(ax=ax, nodes=True, centers=True) ax.plot(xtopo, topo, 'k', linewidth=1) ax.plot(mesh.vectorCCx, interp1d(xtopo, topo)(mesh.vectorCCx), '--k', linewidth=3) aveN2CC = Utils.sdiag(mesh.aveN2CC.T.sum(1)) * mesh.aveN2CC.T a = aveN2CC * indcc a[a > 0] = 1. a[a < 0.25] = np.nan a = a.reshape(mesh.vnN, order='F') masked_array = np.ma.array(a, mask=np.isnan(a)) ax.pcolor(mesh.vectorNx, mesh.vectorNy, masked_array.T, cmap=plt.cm.gray, alpha=0.2)
def run(plotIt=True, nx=5, ny=5): # 2D mesh mesh = Mesh.TensorMesh([nx, ny], x0='CC') xtopo = mesh.vectorNx # define a topographic surface topo = 0.4*np.sin(xtopo*5) # make it an array Topo = np.hstack([Utils.mkvc(xtopo, 2), Utils.mkvc(topo, 2)]) # Compare the different options indtopoCC_near = surface2ind_topo(mesh, Topo, gridLoc='CC', method='nearest') indtopoN_near = surface2ind_topo(mesh, Topo, gridLoc='N', method='nearest') indtopoCC_linear = surface2ind_topo(mesh, Topo, gridLoc='CC', method='linear') indtopoN_linear = surface2ind_topo(mesh, Topo, gridLoc='N', method='linear') indtopoCC_cubic = surface2ind_topo(mesh, Topo, gridLoc='CC', method='cubic') indtopoN_cubic = surface2ind_topo(mesh, Topo, gridLoc='N', method='cubic') if plotIt: fig, ax = plt.subplots(2, 3, figsize=(9, 6)) ax = mkvc(ax) xinterpolate = np.linspace(mesh.gridN[:, 0].min(), mesh.gridN[:, 0].max(),100) listindex = [indtopoCC_near,indtopoN_near,indtopoCC_linear,indtopoN_linear,indtopoCC_cubic,indtopoN_cubic] listmethod = ['nearest','nearest', 'linear', 'linear', 'cubic', 'cubic'] for i in range(6): mesh.plotGrid(ax=ax[i], nodes=True, centers=True) mesh.plotImage(listindex[i], ax=ax[i], pcolorOpts = {"alpha":0.5, "cmap":plt.cm.gray}) ax[i].scatter(Topo[:,0], Topo[:,1], color = 'black', marker = 'o',s = 50) ax[i].plot( xinterpolate, interp1d(Topo[:, 0], Topo[:, 1], kind=listmethod[i])(xinterpolate), '--k', linewidth=3 ) ax[i].xaxis.set_ticklabels([]) ax[i].yaxis.set_ticklabels([]) ax[i].set_aspect('equal') ax[i].set_xlabel('') ax[i].set_ylabel('') ax[0].set_xlabel('Nearest Interpolation', fontsize=16) ax[2].set_xlabel('Linear Interpolation', fontsize=16) ax[4].set_xlabel('Cubic Interpolation', fontsize=16) ax[0].set_ylabel('Cells Center \n based selection', fontsize=16) ax[1].set_ylabel('Nodes \n based selection', fontsize=16) plt.tight_layout()
def run(plotIt=True, nx=5, ny=5): """ Utils: surface2ind_topo ======================= Here we show how to use :code:`Utils.surface2ind_topo` to identify cells below a topographic surface. """ mesh = Mesh.TensorMesh([nx, ny], x0='CC') # 2D mesh xtopo = np.linspace(mesh.gridN[:, 0].min(), mesh.gridN[:, 0].max()) topo = 0.4 * np.sin(xtopo * 5) # define a topographic surface Topo = np.hstack([Utils.mkvc(xtopo, 2), Utils.mkvc(topo, 2)]) #make it an array indcc = surface2ind_topo(mesh, Topo, 'CC') if plotIt: from matplotlib.pylab import plt from scipy.interpolate import interp1d fig, ax = plt.subplots(1, 1, figsize=(6, 6)) mesh.plotGrid(ax=ax, nodes=True, centers=True) ax.plot(xtopo, topo, 'k', linewidth=1) ax.plot(mesh.vectorCCx, interp1d(xtopo, topo)(mesh.vectorCCx), '--k', linewidth=3) aveN2CC = Utils.sdiag(mesh.aveN2CC.T.sum(1)) * mesh.aveN2CC.T a = aveN2CC * indcc a[a > 0] = 1. a[a < 0.25] = np.nan a = a.reshape(mesh.vnN, order='F') masked_array = np.ma.array(a, mask=np.isnan(a)) ax.pcolor(mesh.vectorNx, mesh.vectorNy, masked_array.T, cmap=plt.cm.gray, alpha=0.2) plt.show()
def run(plotIt=True, nx=5, ny=5): # 2D mesh mesh = Mesh.TensorMesh([nx, ny], x0='CC') xtopo = mesh.vectorNx # define a topographic surface topo = 0.4 * np.sin(xtopo * 5) # make it an array Topo = np.hstack([Utils.mkvc(xtopo, 2), Utils.mkvc(topo, 2)]) # Compare the different options indtopoCC_near = surface2ind_topo(mesh, Topo, gridLoc='CC', method='nearest') indtopoN_near = surface2ind_topo(mesh, Topo, gridLoc='N', method='nearest') indtopoCC_linear = surface2ind_topo(mesh, Topo, gridLoc='CC', method='linear') indtopoN_linear = surface2ind_topo(mesh, Topo, gridLoc='N', method='linear') indtopoCC_cubic = surface2ind_topo(mesh, Topo, gridLoc='CC', method='cubic') indtopoN_cubic = surface2ind_topo(mesh, Topo, gridLoc='N', method='cubic') if plotIt: fig, ax = plt.subplots(2, 3, figsize=(9, 6)) ax = mkvc(ax) xinterpolate = np.linspace(mesh.gridN[:, 0].min(), mesh.gridN[:, 0].max(), 100) listindex = [ indtopoCC_near, indtopoN_near, indtopoCC_linear, indtopoN_linear, indtopoCC_cubic, indtopoN_cubic ] listmethod = [ 'nearest', 'nearest', 'linear', 'linear', 'cubic', 'cubic' ] for i in range(6): mesh.plotGrid(ax=ax[i], nodes=True, centers=True) mesh.plotImage(listindex[i], ax=ax[i], pcolorOpts={ "alpha": 0.5, "cmap": plt.cm.gray }) ax[i].scatter(Topo[:, 0], Topo[:, 1], color='black', marker='o', s=50) ax[i].plot(xinterpolate, interp1d(Topo[:, 0], Topo[:, 1], kind=listmethod[i])(xinterpolate), '--k', linewidth=3) ax[i].xaxis.set_ticklabels([]) ax[i].yaxis.set_ticklabels([]) ax[i].set_aspect('equal') ax[i].set_xlabel('') ax[i].set_ylabel('') ax[0].set_xlabel('Nearest Interpolation', fontsize=16) ax[2].set_xlabel('Linear Interpolation', fontsize=16) ax[4].set_xlabel('Cubic Interpolation', fontsize=16) ax[0].set_ylabel('Cells Center \n based selection', fontsize=16) ax[1].set_ylabel('Nodes \n based selection', fontsize=16) plt.tight_layout()
mesh = refine_box(mesh) mesh.finalize() background_value = 100. dyke_value = 40. block_value = 70. # Define surface topography as an (N, 3) np.array. You could also load a file # containing the xyz points [xx, yy] = np.meshgrid(mesh.vectorNx, mesh.vectorNy) zz = -3 * np.exp((xx**2 + yy**2) / 60**2) + 45. topo = np.c_[mkvc(xx), mkvc(yy), mkvc(zz)] # Find cells below topography and define mapping air_value = 0. ind_active = surface2ind_topo(mesh, topo) model_map = Maps.InjectActiveCells(mesh, ind_active, air_value) # Define the model on subsurface cells model = background_value * np.ones(ind_active.sum()) ind_dyke = (mesh.gridCC[ind_active, 0] > 20.) & (mesh.gridCC[ind_active, 0] < 40.) model[ind_dyke] = dyke_value ind_block = ((mesh.gridCC[ind_active, 0] > -40.) & (mesh.gridCC[ind_active, 0] < -10.) & (mesh.gridCC[ind_active, 1] > -30.) & (mesh.gridCC[ind_active, 1] < 30.) & (mesh.gridCC[ind_active, 2] > -40.) & (mesh.gridCC[ind_active, 2] < 0.)) model[ind_block] = block_value