def test_ParametricBlock2D(self): mesh = Mesh.TensorMesh( [np.ones(30), np.ones(20)], x0=np.array([-15, -5]) ) mapping = Maps.ParametricBlock(mesh) # val_background,val_block, block_x0, block_dx, block_y0, block_dy m = np.r_[-2., 1., -5, 10, 5, 4] self.assertTrue(mapping.test(m))
def test_parametric_block(self): M1 = Mesh.TensorMesh([np.ones(10)], "C") block = Maps.ParametricBlock(M1) self.assertTrue( block.test( m=np.hstack( [np.random.rand(2), np.r_[M1.x0, 2*M1.hx.min()]] ) ) ) M2 = Mesh.TensorMesh([np.ones(10), np.ones(20)], "CC") block = Maps.ParametricBlock(M2) self.assertTrue( block.test( m=np.hstack( [ np.random.rand(2), np.r_[M2.x0[0], 2*M2.hx.min()], np.r_[M2.x0[1], 4*M2.hy.min()] ] ) ) ) M3 = Mesh.TensorMesh([np.ones(10), np.ones(20), np.ones(30)], "CCC") block = Maps.ParametricBlock(M3) self.assertTrue( block.test( m=np.hstack( [ np.random.rand(2), np.r_[M3.x0[0], 2*M3.hx.min()], np.r_[M3.x0[1], 4*M3.hy.min()], np.r_[M3.x0[2], 5*M3.hz.min()] ] ) ) )
background_value = 100. # background value pipe_value = 40. # pipe value rc, zc = 0., -25. # center of pipe dr, dz = 20., 50. # dimensions in r, z # Find cells below topography and define mapping air_value = 0. ind_active = mesh.gridCC[:, 2] < 0. active_map = Maps.InjectActiveCells(mesh, ind_active, air_value) # Define the model on subsurface cells model = np.r_[background_value, pipe_value, rc, dr, 0., 1., zc, dz] # add dummy values for phi parametric_map = Maps.ParametricBlock(mesh, indActive=ind_active, epsilon=1e-10, p=8.) # Define a single mapping from model to mesh model_map = Maps.ComboMap([active_map, parametric_map]) # Plotting fig = plt.figure(figsize=(5, 5)) ax = fig.add_subplot(111) mesh.plotImage(model_map * model, ax=ax, grid=True) ax.set_title('Cylindrically Symmetric Model') ############################################# # Using Wire Maps # --------------- #
def run(plotIt=True, survey_type="dipole-dipole", rho_background=1e3, rho_block=1e2, block_x0=100, block_dx=10, block_y0=-10, block_dy=5): np.random.seed(1) # Initiate I/O class for DC IO = DC.IO() # Obtain ABMN locations xmin, xmax = 0., 200. ymin, ymax = 0., 0. zmin, zmax = 0, 0 endl = np.array([[xmin, ymin, zmin], [xmax, ymax, zmax]]) # Generate DC survey object survey = DC.Utils.gen_DCIPsurvey(endl, survey_type=survey_type, dim=2, a=10, b=10, n=10) survey.getABMN_locations() survey = IO.from_ambn_locations_to_survey(survey.a_locations, survey.b_locations, survey.m_locations, survey.n_locations, survey_type, data_dc_type='volt') # Obtain 2D TensorMesh mesh, actind = IO.set_mesh() # Flat topography actind = Utils.surface2ind_topo(mesh, np.c_[mesh.vectorCCx, mesh.vectorCCx * 0.]) survey.drapeTopo(mesh, actind, option="top") # Use Exponential Map: m = log(rho) actmap = Maps.InjectActiveCells(mesh, indActive=actind, valInactive=np.log(1e8)) parametric_block = Maps.ParametricBlock(mesh, slopeFact=1e2) mapping = Maps.ExpMap(mesh) * parametric_block # Set true model # val_background,val_block, block_x0, block_dx, block_y0, block_dy mtrue = np.r_[np.log(1e3), np.log(10), 100, 10, -20, 10] # Set initial model m0 = np.r_[np.log(rho_background), np.log(rho_block), block_x0, block_dx, block_y0, block_dy] rho = mapping * mtrue rho0 = mapping * m0 # Show the true conductivity model fig = plt.figure(figsize=(12, 3)) ax = plt.subplot(111) temp = rho.copy() temp[~actind] = np.nan out = mesh.plotImage(temp, grid=False, ax=ax, gridOpts={'alpha': 0.2}, clim=(10, 1000), pcolorOpts={ "cmap": "viridis", "norm": colors.LogNorm() }) ax.plot(survey.electrode_locations[:, 0], survey.electrode_locations[:, 1], 'k.') ax.set_xlim(IO.grids[:, 0].min(), IO.grids[:, 0].max()) ax.set_ylim(-IO.grids[:, 1].max(), IO.grids[:, 1].min()) cb = plt.colorbar(out[0]) cb.set_label("Resistivity (ohm-m)") ax.set_aspect('equal') ax.set_title("True resistivity model") plt.show() # Show the true conductivity model fig = plt.figure(figsize=(12, 3)) ax = plt.subplot(111) temp = rho0.copy() temp[~actind] = np.nan out = mesh.plotImage(temp, grid=False, ax=ax, gridOpts={'alpha': 0.2}, clim=(10, 1000), pcolorOpts={ "cmap": "viridis", "norm": colors.LogNorm() }) ax.plot(survey.electrode_locations[:, 0], survey.electrode_locations[:, 1], 'k.') ax.set_xlim(IO.grids[:, 0].min(), IO.grids[:, 0].max()) ax.set_ylim(-IO.grids[:, 1].max(), IO.grids[:, 1].min()) cb = plt.colorbar(out[0]) cb.set_label("Resistivity (ohm-m)") ax.set_aspect('equal') ax.set_title("Initial resistivity model") plt.show() # Generate 2.5D DC problem # "N" means potential is defined at nodes prb = DC.Problem2D_N(mesh, rhoMap=mapping, storeJ=True, Solver=Solver) # Pair problem with survey try: prb.pair(survey) except: survey.unpair() prb.pair(survey) # Make synthetic DC data with 5% Gaussian noise dtrue = survey.makeSyntheticData(mtrue, std=0.05, force=True) # Show apparent resisitivty pseudo-section IO.plotPseudoSection(data=survey.dobs / IO.G, data_type='apparent_resistivity') # Show apparent resisitivty histogram fig = plt.figure() out = hist(survey.dobs / IO.G, bins=20) plt.show() # Set uncertainty # floor eps = 10**(-3.2) # percentage std = 0.05 dmisfit = DataMisfit.l2_DataMisfit(survey) uncert = abs(survey.dobs) * std + eps dmisfit.W = 1. / uncert # Map for a regularization mesh_1d = Mesh.TensorMesh([parametric_block.nP]) # Related to inversion reg = Regularization.Simple(mesh_1d, alpha_x=0.) opt = Optimization.InexactGaussNewton(maxIter=10) invProb = InvProblem.BaseInvProblem(dmisfit, reg, opt) beta = Directives.BetaSchedule(coolingFactor=5, coolingRate=2) betaest = Directives.BetaEstimate_ByEig(beta0_ratio=1e0) target = Directives.TargetMisfit() updateSensW = Directives.UpdateSensitivityWeights() update_Jacobi = Directives.UpdatePreconditioner() invProb.beta = 0. inv = Inversion.BaseInversion(invProb, directiveList=[target]) prb.counter = opt.counter = Utils.Counter() opt.LSshorten = 0.5 opt.remember('xc') # Run inversion mopt = inv.run(m0) # Convert obtained inversion model to resistivity # rho = M(m), where M(.) is a mapping rho_est = mapping * mopt rho_true = rho.copy() # show recovered conductivity vmin, vmax = rho.min(), rho.max() fig, ax = plt.subplots(2, 1, figsize=(20, 6)) out1 = mesh.plotImage(rho_true, clim=(10, 1000), pcolorOpts={ "cmap": "viridis", "norm": colors.LogNorm() }, ax=ax[0]) out2 = mesh.plotImage(rho_est, clim=(10, 1000), pcolorOpts={ "cmap": "viridis", "norm": colors.LogNorm() }, ax=ax[1]) out = [out1, out2] for i in range(2): ax[i].plot(survey.electrode_locations[:, 0], survey.electrode_locations[:, 1], 'kv') ax[i].set_xlim(IO.grids[:, 0].min(), IO.grids[:, 0].max()) ax[i].set_ylim(-IO.grids[:, 1].max(), IO.grids[:, 1].min()) cb = plt.colorbar(out[i][0], ax=ax[i]) cb.set_label("Resistivity ($\Omega$m)") ax[i].set_xlabel("Northing (m)") ax[i].set_ylabel("Elevation (m)") ax[i].set_aspect('equal') ax[0].set_title("True resistivity model") ax[1].set_title("Recovered resistivity model") plt.tight_layout() plt.show()
from pymatsolver import PardisoSolver from SimPEG import Maps cs, ncx, ncy, ncz, = 50., 20, 1, 20 npad_x, npad_y, npad_z = 10, 10, 10 pad_rate = 1.3 hx = [(cs,npad_x,-pad_rate), (cs,ncx), (cs,npad_x,pad_rate)] hy = [(cs,npad_y,-pad_rate), (cs,ncy), (cs,npad_y,pad_rate)] hz = [(cs,npad_z,-pad_rate), (cs,ncz), (cs,npad_z,pad_rate)] mesh_3d = Mesh.TensorMesh([hx,hy,hz], 'CCC') mesh_2d = Mesh.TensorMesh([hx,hz], 'CC') inds = mesh_2d.vectorCCy<0. mesh_2d_inv = Mesh.TensorMesh([hx,mesh_2d.hy[inds]], 'CN') actind = mesh_2d.gridCC[:,1]<0. map_2Dto3D = Maps.Surject2Dto3D(mesh_3d) parametric_block = Maps.ParametricBlock(mesh_2d_inv) #, slopeFact=1 expmap = Maps.ExpMap(mesh_2d) actmap = Maps.InjectActiveCells(mesh_2d, indActive=actind, valInactive=np.log(1e-8)) mapping = map_2Dto3D* expmap * actmap * parametric_block x = mesh_3d.vectorCCx[np.logical_and(mesh_3d.vectorCCx>-450, mesh_3d.vectorCCx<450)] time = np.logspace(np.log10(5e-5), np.log10(2.5e-3), 21) srcList = [] ind_start=0 for xloc in x: location = np.array([[xloc, 0., 30.]]) rx_z = EM.TDEM.Rx.Point_dbdt(location, time[ind_start:], 'z') rx_x = EM.TDEM.Rx.Point_dbdt(location, time[ind_start:], 'x') src = EM.TDEM.Src.CircularLoop([rx_z], orientation='z', loc=location) srcList.append(src) prb = EM.TDEM.Problem3D_e(mesh_3d, sigmaMap=mapping, Solver=PardisoSolver, verbose=False)