def test_transforms_logMap_reciprocalMap(self): # Note that log/reciprocal maps can be kinda finicky, so we are being # explicit about the random seed. v2 = np.r_[0.40077291, 0.1441044, 0.58452314, 0.96323738, 0.01198519, 0.79754415] dv2 = np.r_[0.80653921, 0.13132446, 0.4901117, 0.03358737, 0.65473762, 0.44252488] v3 = np.r_[0.96084865, 0.34385186, 0.39430044, 0.81671285, 0.65929109, 0.2235217, 0.87897526, 0.5784033, 0.96876393, 0.63535864, 0.84130763, 0.22123854] dv3 = np.r_[0.96827838, 0.26072111, 0.45090749, 0.10573893, 0.65276365, 0.15646586, 0.51679682, 0.23071984, 0.95106218, 0.14201845, 0.25093564, 0.3732866] maps = Maps.LogMap(self.mesh2) self.assertTrue(maps.test(v2, dx=dv2)) maps = Maps.LogMap(self.mesh3) self.assertTrue(maps.test(v3, dx=dv3)) maps = Maps.ReciprocalMap(self.mesh2) self.assertTrue(maps.test(v2, dx=dv2)) maps = Maps.ReciprocalMap(self.mesh3) self.assertTrue(maps.test(v3, dx=dv3))
def run(plotIt=True): nC = 40 de = 1. h = np.ones(nC) * de / nC M = Mesh.TensorMesh([h, h]) y = np.linspace(M.vectorCCy[0], M.vectorCCx[-1], int(np.floor(nC / 4))) rlocs = np.c_[0 * y + M.vectorCCx[-1], y] rx = StraightRay.Rx(rlocs, None) srcList = [ StraightRay.Src(loc=np.r_[M.vectorCCx[0], yi], rxList=[rx]) for yi in y ] # phi model phi0 = 0 phi1 = 0.65 phitrue = Utils.ModelBuilder.defineBlock(M.gridCC, [0.4, 0.6], [0.6, 0.4], [phi1, phi0]) knownVolume = np.sum(phitrue * M.vol) print('True Volume: {}'.format(knownVolume)) # Set up true conductivity model and plot the model transform sigma0 = np.exp(1) sigma1 = 1e4 if plotIt: fig, ax = plt.subplots(1, 1) sigmaMapTest = Maps.SelfConsistentEffectiveMedium(nP=1000, sigma0=sigma0, sigma1=sigma1, rel_tol=1e-1, maxIter=150) testphis = np.linspace(0., 1., 1000) sigetest = sigmaMapTest * testphis ax.semilogy(testphis, sigetest) ax.set_title('Model Transform') ax.set_xlabel('$\\varphi$') ax.set_ylabel('$\sigma$') sigmaMap = Maps.SelfConsistentEffectiveMedium(M, sigma0=sigma0, sigma1=sigma1) # scale the slowness so it is on a ~linear scale slownessMap = Maps.LogMap(M) * sigmaMap # set up the true sig model and log model dobs sigtrue = sigmaMap * phitrue # modt = Model.BaseModel(M); slownesstrue = slownessMap * phitrue # true model (m = log(sigma)) # set up the problem and survey survey = StraightRay.Survey(srcList) problem = StraightRay.Problem(M, slownessMap=slownessMap) problem.pair(survey) if plotIt: fig, ax = plt.subplots(1, 1) cb = plt.colorbar(M.plotImage(phitrue, ax=ax)[0], ax=ax) survey.plot(ax=ax) cb.set_label('$\\varphi$') # get observed data dobs = survey.makeSyntheticData(phitrue, std=0.03, force=True) dpred = survey.dpred(np.zeros(M.nC)) # objective function pieces reg = Regularization.Tikhonov(M) dmis = DataMisfit.l2_DataMisfit(survey) dmisVol = Volume(mesh=M, knownVolume=knownVolume) beta = 0.25 maxIter = 15 # without the volume regularization opt = Optimization.ProjectedGNCG(maxIter=maxIter, lower=0.0, upper=1.0) opt.remember('xc') invProb = InvProblem.BaseInvProblem(dmis, reg, opt, beta=beta) inv = Inversion.BaseInversion(invProb) mopt1 = inv.run(np.zeros(M.nC) + 1e-16) print('\nTotal recovered volume (no vol misfit term in inversion): ' '{}'.format(dmisVol(mopt1))) # with the volume regularization vol_multiplier = 9e4 reg2 = reg dmis2 = dmis + vol_multiplier * dmisVol opt2 = Optimization.ProjectedGNCG(maxIter=maxIter, lower=0.0, upper=1.0) opt2.remember('xc') invProb2 = InvProblem.BaseInvProblem(dmis2, reg2, opt2, beta=beta) inv2 = Inversion.BaseInversion(invProb2) mopt2 = inv2.run(np.zeros(M.nC) + 1e-16) print('\nTotal volume (vol misfit term in inversion): {}'.format( dmisVol(mopt2))) # plot results if plotIt: fig, ax = plt.subplots(1, 1) ax.plot(dobs) ax.plot(dpred) ax.plot(survey.dpred(mopt1), 'o') ax.plot(survey.dpred(mopt2), 's') ax.legend(['dobs', 'dpred0', 'dpred w/o Vol', 'dpred with Vol']) fig, ax = plt.subplots(1, 3, figsize=(16, 4)) cb0 = plt.colorbar(M.plotImage(phitrue, ax=ax[0])[0], ax=ax[0]) cb1 = plt.colorbar(M.plotImage(mopt1, ax=ax[1])[0], ax=ax[1]) cb2 = plt.colorbar(M.plotImage(mopt2, ax=ax[2])[0], ax=ax[2]) for cb in [cb0, cb1, cb2]: cb.set_clim([0., phi1]) ax[0].set_title('true, vol: {:1.3e}'.format(knownVolume)) ax[1].set_title('recovered(no Volume term), vol: {:1.3e} '.format( dmisVol(mopt1))) ax[2].set_title('recovered(with Volume term), vol: {:1.3e} '.format( dmisVol(mopt2))) plt.tight_layout()
# Create a flat topo topoXYZ = Utils.ndgrid(mesh.vectorNx, mesh.vectorNy, np.r_[-1.]) actv = sigma != 1e-8 nC = int(actv.sum()) midLocs = survey.srcList[0].rxList[0].locs[0] + survey.srcList[0].rxList[ 0].locs[1] midLocs /= 2 idenMap = Maps.IdentityMap(nP=nC) expmap = Maps.ExpMap(mesh) actmap = Maps.InjectActiveCells(mesh, actv, np.log(1e-8)) mapping = expmap * actmap logmap = Maps.LogMap(mesh) m0 = np.log(np.ones_like(sigma) * 1e-3)[actv] mref = np.log(np.ones_like(sigma) * mref_val) problem = DC.Problem3D_N(mesh, sigmaMap=mapping, storeJ=True) problem.Solver = PardisoSolver problem.pair(survey) mtrue = np.log(sigma[actv]) # Depth weight #depth = 1./(abs(mesh.gridCC[:,2]))**1.5 #depth = depth/depth.max() d0 = survey.dpred(m0) dobs = survey.makeSyntheticData(mtrue, std=0.02)