def setUp(self): dh = 1.0 nx = 16 ny = 16 nz = 16 hx = [(dh, nx)] hy = [(dh, ny)] hz = [(dh, nz)] mesh = TreeMesh([hx, hy, hz], "CNN") mesh.insert_cells([5, 5, 5], [4]) # reg actv = np.ones(len(mesh), dtype=bool) # maps wires = maps.Wires(("m1", mesh.nC), ("m2", mesh.nC)) cross_grad = regularization.CrossGradient(mesh, wire_map=wires, indActive=actv) self.mesh = mesh self.cross_grad = cross_grad
def setUp(self): dh = 1.0 nx = 16 ny = 16 nz = 16 hx = [(dh, nx)] hy = [(dh, ny)] hz = [(dh, nz)] mesh = TreeMesh([hx, hy, hz], "CNN") mesh.insert_cells([5, 5, 5], [4]) # reg actv = np.ones(len(mesh), dtype=bool) # maps wires = maps.Wires(("m1", mesh.nC), ("m2", mesh.nC)) jtv = regularization.JointTotalVariation(mesh, wire_map=wires, indActive=actv) self.mesh = mesh self.jtv = jtv self.x0 = np.random.rand(len(mesh) * 2)
def plotVectorSectionsOctree( mesh, m, normal="X", ind=0, vmin=None, vmax=None, scale=1.0, vec="k", axs=None, actvMap=None, fill=True, ): """ Plot section through a 3D tensor model """ # plot recovered model normalInd = {"X": 0, "Y": 1, "Z": 2}[normal] antiNormalInd = {"X": [1, 2], "Y": [0, 2], "Z": [0, 1]}[normal] h2d = (mesh.h[antiNormalInd[0]], mesh.h[antiNormalInd[1]]) x2d = (mesh.x0[antiNormalInd[0]], mesh.x0[antiNormalInd[1]]) #: Size of the sliced dimension szSliceDim = len(mesh.h[normalInd]) if ind is None: ind = int(szSliceDim // 2) cc_tensor = [None, None, None] for i in range(3): cc_tensor[i] = np.cumsum(np.r_[mesh.x0[i], mesh.h[i]]) cc_tensor[i] = (cc_tensor[i][1:] + cc_tensor[i][:-1]) * 0.5 slice_loc = cc_tensor[normalInd][ind] # Create a temporary TreeMesh with the slice through temp_mesh = TreeMesh(h2d, x2d) level_diff = mesh.max_level - temp_mesh.max_level XS = [None, None, None] XS[antiNormalInd[0]], XS[antiNormalInd[1]] = np.meshgrid( cc_tensor[antiNormalInd[0]], cc_tensor[antiNormalInd[1]]) XS[normalInd] = np.ones_like(XS[antiNormalInd[0]]) * slice_loc loc_grid = np.c_[XS[0].reshape(-1), XS[1].reshape(-1), XS[2].reshape(-1)] inds = np.unique(mesh._get_containing_cell_indexes(loc_grid)) grid2d = mesh.gridCC[inds][:, antiNormalInd] levels = mesh._cell_levels_by_indexes(inds) - level_diff temp_mesh.insert_cells(grid2d, levels) tm_gridboost = np.empty((temp_mesh.nC, 3)) tm_gridboost[:, antiNormalInd] = temp_mesh.gridCC tm_gridboost[:, normalInd] = slice_loc # Interpolate values to mesh.gridCC if not 'CC' mx = actvMap * m[:, 0] my = actvMap * m[:, 1] mz = actvMap * m[:, 2] m = np.c_[mx, my, mz] # Interpolate values from mesh.gridCC to grid2d ind_3d_to_2d = mesh._get_containing_cell_indexes(tm_gridboost) v2d = m[ind_3d_to_2d, :] amp = np.sum(v2d**2.0, axis=1)**0.5 if axs is None: axs = plt.subplot(111) if fill: temp_mesh.plotImage(amp, ax=axs, clim=[vmin, vmax], grid=True) axs.quiver( temp_mesh.gridCC[:, 0], temp_mesh.gridCC[:, 1], v2d[:, antiNormalInd[0]], v2d[:, antiNormalInd[1]], pivot="mid", scale_units="inches", scale=scale, linewidths=(1, ), edgecolors=(vec), headaxislength=0.1, headwidth=10, headlength=30, )