示例#1
0
    def setUp(self):

        aSpacing=2.5
        nElecs=5

        surveySize = nElecs*aSpacing - aSpacing
        cs = surveySize/nElecs/4

        mesh = Mesh.TensorMesh([
                [(cs,10, -1.3),(cs,surveySize/cs),(cs,10, 1.3)],
                [(cs,3, -1.3),(cs,3,1.3)],
                # [(cs,5, -1.3),(cs,10)]
            ],'CN')

        srcList = DC.Utils.WennerSrcList(nElecs, aSpacing, in2D=True)
        survey = IP.Survey(srcList)
        sigma = np.ones(mesh.nC)
        problem = IP.Problem3D_CC(mesh, rho=1./sigma)
        problem.pair(survey)
        mSynth = np.ones(mesh.nC)*0.1
        survey.makeSyntheticData(mSynth)
        # Now set up the problem to do some minimization
        dmis = DataMisfit.l2_DataMisfit(survey)
        reg = Regularization.Tikhonov(mesh)
        opt = Optimization.InexactGaussNewton(maxIterLS=20, maxIter=10, tolF=1e-6, tolX=1e-6, tolG=1e-6, maxIterCG=6)
        invProb = InvProblem.BaseInvProblem(dmis, reg, opt, beta=1e4)
        inv = Inversion.BaseInversion(invProb)

        self.inv = inv
        self.reg = reg
        self.p =     problem
        self.mesh = mesh
        self.m0 = mSynth
        self.survey = survey
        self.dmis = dmis
示例#2
0
    def test_Problem2D_CC(self):

        problemDC = DC.Problem2D_CC(self.mesh,
                                    rhoMap=Maps.IdentityMap(self.mesh))
        problemDC.Solver = Solver
        problemDC.pair(self.surveyDC)
        data0 = self.surveyDC.dpred(1. / self.sigma0)
        finf = problemDC.fields(1. / self.sigmaInf)
        datainf = self.surveyDC.dpred(1. / self.sigmaInf, f=finf)
        problemIP = IP.Problem2D_CC(self.mesh,
                                    rho=1. / self.sigmaInf,
                                    etaMap=Maps.IdentityMap(self.mesh))
        problemIP.Solver = Solver
        surveyIP = IP.Survey(self.srcLists_ip)
        problemIP.pair(surveyIP)
        data_full = data0 - datainf
        data = surveyIP.dpred(self.eta)
        err = np.linalg.norm(
            (data - data_full) / data_full)**2 / data_full.size
        if err < 0.05:
            passed = True
            print(">> IP forward test for Problem2D_CC is passed")
        else:
            import matplotlib.pyplot as plt
            passed = False
            print(">> IP forward test for Problem2D_CC is failed")
            print(err)
            plt.plot(data_full)
            plt.plot(data, 'k.')
            plt.show()

        self.assertTrue(passed)
示例#3
0
    def test_Problem2D_N(self):

        problemDC = DC.Problem2D_N(self.mesh,
                                   sigmaMap=Maps.IdentityMap(self.mesh))
        problemDC.Solver = Solver
        problemDC.pair(self.surveyDC)
        data0 = self.surveyDC.dpred(self.sigma0)
        datainf = self.surveyDC.dpred(self.sigmaInf)
        problemIP = IP.Problem2D_N(
            self.mesh,
            sigma=self.sigmaInf,
            etaMap=Maps.IdentityMap(self.mesh),
        )
        problemIP.Solver = Solver
        surveyIP = IP.Survey(self.srcLists_ip)
        problemIP.pair(surveyIP)
        data_full = data0 - datainf
        data = surveyIP.dpred(self.eta)
        err = np.linalg.norm(
            (data - data_full) / data_full)**2 / data_full.size
        if err < 0.05:
            passed = True
            print(">> IP forward test for Problem2D_N is passed")
            print(err)
        else:
            passed = False
            print(">> IP forward test for Problem2D_N is failed")
        self.assertTrue(passed)
示例#4
0
    def test_Problem3D_CC(self):

        problemDC = DC.Problem3D_CC(self.mesh)
        problemDC.Solver = self.Solver
        problemDC.pair(self.surveyDC)
        data0 = self.surveyDC.dpred(self.sigma0)
        finf = problemDC.fields(self.sigmaInf)
        datainf = self.surveyDC.dpred(self.sigmaInf, f=finf)
        problemIP = IP.Problem3D_CC(self.mesh,
                                    rho=1. / self.sigmaInf,
                                    Ainv=problemDC.Ainv,
                                    f=finf)
        problemIP.Solver = self.Solver
        surveyIP = IP.Survey([self.src])
        problemIP.pair(surveyIP)
        data_full = data0 - datainf
        data = surveyIP.dpred(self.eta)
        err = np.linalg.norm(
            (data - data_full) / data_full)**2 / data_full.size
        if err < 0.05:
            passed = True
            print ">> IP forward test for Problem3D_CC is passed"
        else:
            passed = False
            print ">> IP forward test for Problem3D_CC is failed"
        self.assertTrue(passed)
    def setUp(self):

        cs = 12.5
        hx = [(cs, 7, -1.3), (cs, 61), (cs, 7, 1.3)]
        hy = [(cs, 7, -1.3), (cs, 20)]
        mesh = Mesh.TensorMesh([hx, hy], x0="CN")

        # x = np.linspace(-200, 200., 20)
        x = np.linspace(-200, 200., 2)
        M = Utils.ndgrid(x - 12.5, np.r_[0.])
        N = Utils.ndgrid(x + 12.5, np.r_[0.])

        A0loc = np.r_[-150, 0.]
        A1loc = np.r_[-130, 0.]
        B0loc = np.r_[-130, 0.]
        B1loc = np.r_[-110, 0.]

        rx = DC.Rx.Dipole_ky(M, N)
        src0 = DC.Src.Dipole([rx], A0loc, B0loc)
        src1 = DC.Src.Dipole([rx], A1loc, B1loc)
        survey = IP.Survey([src0, src1])

        sigma = np.ones(mesh.nC) * 1.
        problem = IP.Problem2D_CC(mesh,
                                  sigma=sigma,
                                  etaMap=Maps.IdentityMap(mesh),
                                  verbose=False)
        problem.pair(survey)

        mSynth = np.ones(mesh.nC) * 0.1
        survey.makeSyntheticData(mSynth)
        # Now set up the problem to do some minimization
        dmis = DataMisfit.l2_DataMisfit(survey)
        reg = Regularization.Tikhonov(mesh)
        opt = Optimization.InexactGaussNewton(maxIterLS=20,
                                              maxIter=10,
                                              tolF=1e-6,
                                              tolX=1e-6,
                                              tolG=1e-6,
                                              maxIterCG=6)
        invProb = InvProblem.BaseInvProblem(dmis, reg, opt, beta=1e4)
        inv = Inversion.BaseInversion(invProb)

        self.inv = inv
        self.reg = reg
        self.p = problem
        self.mesh = mesh
        self.m0 = mSynth
        self.survey = survey
        self.dmis = dmis
def IP2Dsurvey(miptrue, sigmadc, flag="PoleDipole", nmax=8):

    if flag == "PoleDipole":
        ntx = xr.size - 2
    elif flag == "DipolePole":
        ntx = xr.size - 2
    elif flag == "DipoleDipole":
        ntx = xr.size - 3
    else:
        raise Exception("Not Implemented")
    xzlocs = getPseudoLocs(xr, ntx, nmax, flag)

    txList = []
    zloc = -cs / 2.0
    for i in range(ntx):
        if flag == "PoleDipole":
            A = np.r_[xr[i], zloc]
            B = np.r_[mesh.vectorCCx.min(), zloc]
            if i < ntx - nmax + 1:
                Mx = xr[i + 1:i + 1 + nmax]
                _, Mz = get_Surface(miptrue, Mx)
                Nx = xr[i + 2:i + 2 + nmax]
                _, Nz = get_Surface(miptrue, Nx)

                M = np.c_[Mx, Mz]
                N = np.c_[Nx, Nz]
            else:
                Mx = xr[i + 1:ntx + 1]
                _, Mz = get_Surface(miptrue, Mx)
                Nx = xr[i + 2:i + 2 + nmax]
                _, Nz = get_Surface(miptrue, Nx)

                M = np.c_[Mx, Mz]
                N = np.c_[Nx, Nz]

        elif flag == "DipolePole":
            A = np.r_[xr[i], zloc]
            B = np.r_[xr[i + 1], zloc]
            if i < ntx - nmax + 1:
                Mx = xr[i + 2:i + 2 + nmax]
                _, Mz = get_Surface(miptrue, Mx)
                Nx = np.ones(nmax) * mesh.vectorCCx.max()
                _, Nz = get_Surface(miptrue, Nx)

                M = np.c_[Mx, Mz]
                N = np.c_[Nx, Nz]

            else:
                Mx = xr[i + 2:ntx + 2]
                _, Mz = get_Surface(miptrue, Mx)
                Nx = np.ones(ntx - i) * mesh.vectorCCx.max()
                _, Nz = get_Surface(miptrue, Nx)
                M = np.c_[Mx, Mz]
                N = np.c_[Nx, Nz]

        elif flag == "DipoleDipole":
            A = np.r_[xr[i], zloc]
            B = np.r_[xr[i + 1], zloc]
            if i < ntx - nmax:
                Mx = xr[i + 2:i + 2 + nmax]
                _, Mz = get_Surface(miptrue, Mx)
                Nx = xr[i + 3:i + 3 + nmax]
                _, Nz = get_Surface(miptrue, Nx)
                M = np.c_[Mx, Mz]
                N = np.c_[Nx, Nz]

            else:
                Mx = xr[i + 2:len(xr) - 1]
                _, Mz = get_Surface(miptrue, Mx)
                Nx = xr[i + 3:len(xr)]
                _, Nz = get_Surface(miptrue, Nx)
                M = np.c_[Mx, Mz]
                N = np.c_[Nx, Nz]

        rx = DC.Rx.Dipole(M, N)
        src = DC.Src.Dipole([rx], A, B)
        txList.append(src)

    survey = IP.Survey(txList)
    problem = IP.Problem3D_CC(mesh,
                              sigma=sigmadc,
                              etaMap=Maps.IdentityMap(mesh))
    problem.pair(survey)

    return survey, xzlocs