Exemplo n.º 1
0
    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 = TensorMesh([hx, hy], x0="CN")
        sighalf = 1e-2
        sigma = np.ones(mesh.nC) * sighalf
        x = np.linspace(-135, 250.0, 20)
        M = utils.ndgrid(x - 12.5, np.r_[0.0])
        N = utils.ndgrid(x + 12.5, np.r_[0.0])
        A0loc = np.r_[-150, 0.0]
        # A1loc = np.r_[-130, 0.]
        rxloc = [np.c_[M, np.zeros(20)], np.c_[N, np.zeros(20)]]
        data_ana = analytics.DCAnalytic_Pole_Dipole(np.r_[A0loc, 0.0],
                                                    rxloc,
                                                    sighalf,
                                                    earth_type="halfspace")

        rx = dc.receivers.Dipole(M, N)
        src0 = dc.sources.Pole([rx], A0loc)
        survey = dc.Survey([src0])

        self.survey = survey
        self.mesh = mesh
        self.sigma = sigma
        self.data_ana = data_ana
        self.plotIt = False

        try:
            from pymatsolver import Pardiso

            self.Solver = Pardiso
        except ImportError:
            self.Solver = SolverLU
Exemplo n.º 2
0
    def setUp(self):

        cs = 12.5
        npad = 2
        hx = [(cs, npad, -1.3), (cs, 21), (cs, npad, 1.3)]
        hy = [(cs, npad, -1.3), (cs, 21), (cs, npad, 1.3)]
        hz = [(cs, npad, -1.3), (cs, 20)]
        mesh = discretize.TensorMesh([hx, hy, hz], x0="CCN")

        x = mesh.vectorCCx[(mesh.vectorCCx > -80.0) & (mesh.vectorCCx < 80.0)]
        y = mesh.vectorCCy[(mesh.vectorCCy > -80.0) & (mesh.vectorCCy < 80.0)]
        Aloc = np.r_[-100.0, 0.0, 0.0]
        Bloc = np.r_[100.0, 0.0, 0.0]
        M = utils.ndgrid(x - 12.5, y, np.r_[0.0])
        N = utils.ndgrid(x + 12.5, y, np.r_[0.0])
        radius = 50.0
        xc = np.r_[0.0, 0.0, -100]
        blkind = utils.model_builder.getIndicesSphere(xc, radius, mesh.gridCC)
        sigmaInf = np.ones(mesh.nC) * 1e-2
        eta = np.zeros(mesh.nC)
        eta[blkind] = 0.1
        sigma0 = sigmaInf * (1.0 - eta)

        rx = dc.receivers.Dipole(M, N)
        src = dc.sources.Dipole([rx], Aloc, Bloc)
        surveyDC = dc.survey.Survey([src])

        self.surveyDC = surveyDC
        self.mesh = mesh
        self.sigmaInf = sigmaInf
        self.sigma0 = sigma0
        self.src = src
        self.eta = eta
Exemplo n.º 3
0
    def setUp(self):

        npad = 10
        cs = 12.5
        hx = [(cs, npad, -1.4), (cs, 61), (cs, npad, 1.4)]
        hy = [(cs, npad, -1.4), (cs, 20)]
        mesh = TensorMesh([hx, hy], x0="CN")
        sighalf = 1e-2
        sigma = np.ones(mesh.nC) * sighalf
        x = mesh.cell_centers_x[
            np.logical_and(mesh.cell_centers_x > -150, mesh.cell_centers_x < 250)
        ]
        M = utils.ndgrid(x, np.r_[0.0])
        N = utils.ndgrid(x + 12.5 * 4, np.r_[0.0])
        A0loc = np.r_[-200, 0.0]
        A1loc = np.r_[-250, 0.0]
        rx = dc.receivers.Dipole(M, N, data_type="apparent_resistivity")
        src0 = dc.sources.Dipole([rx], A0loc, A1loc)
        survey = dc.Survey([src0])

        self.survey = survey
        self.mesh = mesh
        self.sigma = sigma
        self.sigma_half = sighalf
        self.plotIt = False

        try:
            from pymatsolver import Pardiso

            self.solver = Pardiso
        except ImportError:
            self.solver = SolverLU
Exemplo n.º 4
0
    def setUp(self):

        cs = 25.0
        npad = 7
        hx = [(cs, npad, -1.3), (cs, 21), (cs, npad, 1.3)]
        hy = [(cs, npad, -1.3), (cs, 21), (cs, npad, 1.3)]
        hz = [(cs, npad, -1.3), (cs, 20)]
        mesh = discretize.TensorMesh([hx, hy, hz], x0="CCN")
        sigma = np.ones(mesh.nC) * 1e-2

        x = mesh.vectorCCx[(mesh.vectorCCx > -100) & (mesh.vectorCCx < 100)]
        y = mesh.vectorCCy[(mesh.vectorCCy > -100) & (mesh.vectorCCy < 100)]

        Aloc = np.r_[-200.0, 0.0, 0.0]
        Bloc = np.r_[200.0, 0.0, 0.0]
        M = utils.ndgrid(x - 25.0, y, np.r_[0.0])
        N = utils.ndgrid(x + 25.0, y, np.r_[0.0])
        phiA = analytics.DCAnalytic_Pole_Dipole(Aloc, [M, N],
                                                1e-2,
                                                earth_type="halfspace")
        phiB = analytics.DCAnalytic_Pole_Dipole(Bloc, [M, N],
                                                1e-2,
                                                earth_type="halfspace")
        data_ana = phiA - phiB

        rx = dc.receivers.Dipole(M, N)
        src = dc.sources.Dipole([rx], Aloc, Bloc)
        survey = dc.survey.Survey([src])

        self.survey = survey
        self.mesh = mesh
        self.sigma = sigma
        self.data_ana = data_ana
Exemplo n.º 5
0
    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 = TensorMesh([hx, hy], x0="CN")
        sighalf = 1e-2
        sigma = np.ones(mesh.nC) * sighalf
        x = np.linspace(-135, 250.0, 20)
        M = utils.ndgrid(x - 12.5, np.r_[0.0])
        N = utils.ndgrid(x + 12.5, np.r_[0.0])
        A0loc = np.r_[-150, 0.0]
        A1loc = np.r_[-130, 0.0]

        rx = dc.receivers.Dipole(M, N, data_type="apparent_resistivity")
        src0 = dc.sources.Dipole([rx], A0loc, A1loc)
        survey = dc.Survey([src0])

        self.survey = survey
        self.mesh = mesh
        self.sigma = sigma
        self.sigma_half = sighalf
        self.plotIt = False

        try:
            from pymatsolver import Pardiso

            self.Solver = Pardiso
        except ImportError:
            self.Solver = SolverLU
Exemplo n.º 6
0
    def getSlices(self,
                  mesh,
                  vec,
                  itime,
                  normal="Z",
                  loc=0.0,
                  isz=False,
                  isy=False):
        VEC = vec[:, itime].reshape((mesh.nC, 3), order="F")
        if normal == "Z":
            ind = np.argmin(abs(mesh.vectorCCz - loc))
            vx = VEC[:, 0].reshape((mesh.nCx, mesh.nCy, mesh.nCz),
                                   order="F")[:, :, ind]
            vy = VEC[:, 1].reshape((mesh.nCx, mesh.nCy, mesh.nCz),
                                   order="F")[:, :, ind]
            vz = VEC[:, 2].reshape((mesh.nCx, mesh.nCy, mesh.nCz),
                                   order="F")[:, :, ind]
            xy = utils.ndgrid(mesh.vectorCCx, mesh.vectorCCy)
            if isz:
                return utils.mkvc(vz), xy
            else:
                return np.c_[utils.mkvc(vx), utils.mkvc(vy)], xy

        elif normal == "Y":
            ind = np.argmin(abs(mesh.vectorCCx - loc))
            vx = VEC[:, 0].reshape((mesh.nCx, mesh.nCy, mesh.nCz),
                                   order="F")[:, ind, :]
            vy = VEC[:, 1].reshape((mesh.nCx, mesh.nCy, mesh.nCz),
                                   order="F")[:, ind, :]
            vz = VEC[:, 2].reshape((mesh.nCx, mesh.nCy, mesh.nCz),
                                   order="F")[:, ind, :]
            xz = utils.ndgrid(mesh.vectorCCx, mesh.vectorCCz)
            if isz:
                return utils.mkvc(vz), xz
            elif isy:
                return utils.mkvc(vy), xz
            else:
                return np.c_[utils.mkvc(vx), utils.mkvc(vz)], xz

        elif normal == "X":
            ind = np.argmin(abs(mesh.vectorCCy - loc))
            vx = VEC[:, 0].reshape((mesh.nCx, mesh.nCy, mesh.nCz),
                                   order="F")[ind, :, :]
            vy = VEC[:, 1].reshape((mesh.nCx, mesh.nCy, mesh.nCz),
                                   order="F")[ind, :, :]
            vz = VEC[:, 2].reshape((mesh.nCx, mesh.nCy, mesh.nCz),
                                   order="F")[ind, :, :]
            yz = utils.ndgrid(mesh.vectorCCy, mesh.vectorCCz)
            if isz:
                return utils.mkvc(vy), yz
            elif isy:
                return utils.mkvc(vy), yz
            else:
                return np.c_[utils.mkvc(vy), utils.mkvc(vz)], yz
Exemplo n.º 7
0
    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 = discretize.TensorMesh([hx, hy], x0="CN")

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

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

        rx = dc.Rx.Dipole(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.0
        problem = ip.Simulation2DCellCentered(
            mesh,
            survey=survey,
            sigma=sigma,
            etaMap=maps.IdentityMap(mesh),
            verbose=False,
        )

        mSynth = np.ones(mesh.nC) * 0.1
        dobs = problem.make_synthetic_data(mSynth, add_noise=True)
        # Now set up the problem to do some minimization
        dmis = data_misfit.L2DataMisfit(data=dobs, simulation=problem)
        reg = regularization.Tikhonov(mesh)
        opt = optimization.InexactGaussNewton(maxIterLS=20,
                                              maxIter=10,
                                              tolF=1e-6,
                                              tolX=1e-6,
                                              tolG=1e-6,
                                              maxIterCG=6)
        invProb = inverse_problem.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
Exemplo n.º 8
0
    def setUp(self):
        print("\n  ---- Testing {} ---- \n".format(self.formulation))
        cs = 12.5
        hx = [(cs, 2, -1.3), (cs, 61), (cs, 2, 1.3)]
        hy = [(cs, 2, -1.3), (cs, 20)]
        mesh = discretize.TensorMesh([hx, hy], x0="CN")
        x = np.linspace(-135, 250.0, 20)
        M = utils.ndgrid(x - 12.5, np.r_[0.0])
        N = utils.ndgrid(x + 12.5, np.r_[0.0])
        A0loc = np.r_[-150, 0.0]
        A1loc = np.r_[-130, 0.0]
        # rxloc = [np.c_[M, np.zeros(20)], np.c_[N, np.zeros(20)]]
        rx1 = dc.receivers.Dipole(M, N)
        rx2 = dc.receivers.Dipole(M, N, data_type="apparent_resistivity")
        src0 = dc.sources.Pole([rx1, rx2], A0loc)
        src1 = dc.sources.Pole([rx1, rx2], A1loc)
        survey = dc.survey.Survey([src0, src1])
        survey.set_geometric_factor()
        simulation = getattr(dc, self.formulation)(
            mesh,
            rhoMap=maps.IdentityMap(mesh),
            storeJ=self.storeJ,
            solver=Solver,
            survey=survey,
            bc_type=self.bc_type,
        )
        mSynth = np.ones(mesh.nC) * 1.0
        data = simulation.make_synthetic_data(mSynth, add_noise=True)

        # Now set up the problem to do some minimization
        dmis = data_misfit.L2DataMisfit(simulation=simulation, data=data)
        reg = regularization.Tikhonov(mesh)
        opt = optimization.InexactGaussNewton(maxIterLS=20,
                                              maxIter=10,
                                              tolF=1e-6,
                                              tolX=1e-6,
                                              tolG=1e-6,
                                              maxIterCG=6)
        invProb = inverse_problem.BaseInvProblem(dmis, reg, opt, beta=1e0)
        inv = inversion.BaseInversion(invProb)

        self.inv = inv
        self.reg = reg
        self.p = simulation
        self.mesh = mesh
        self.m0 = mSynth
        self.survey = survey
        self.dmis = dmis
        self.data = data
Exemplo n.º 9
0
 def setUp(self):
     mesh = discretize.TensorMesh([np.ones(n) * 5 for n in [10, 11, 12]],
                                  [0, 0, -30])
     x = np.linspace(5, 10, 3)
     XYZ = utils.ndgrid(x, x, np.r_[0.0])
     srcLoc = np.r_[0, 0, 0.0]
     rxList0 = survey.BaseRx(XYZ)
     Src0 = survey.BaseSrc([rxList0], location=srcLoc)
     rxList1 = survey.BaseRx(XYZ)
     Src1 = survey.BaseSrc([rxList1], location=srcLoc)
     rxList2 = survey.BaseRx(XYZ)
     Src2 = survey.BaseSrc([rxList2], location=srcLoc)
     rxList3 = survey.BaseRx(XYZ)
     Src3 = survey.BaseSrc([rxList3], location=srcLoc)
     Src4 = survey.BaseSrc([rxList0, rxList1, rxList2, rxList3],
                           location=srcLoc)
     source_list = [Src0, Src1, Src2, Src3, Src4]
     mysurvey = survey.BaseSurvey(source_list=source_list)
     sim = simulation.BaseTimeSimulation(mesh,
                                         time_steps=[(10.0, 3), (20.0, 2)],
                                         survey=mysurvey)
     self.F = fields.TimeFields(simulation=sim,
                                knownFields={
                                    "phi": "CC",
                                    "e": "E",
                                    "b": "F"
                                })
     self.Src0 = Src0
     self.Src1 = Src1
     self.mesh = mesh
     self.XYZ = XYZ
Exemplo n.º 10
0
    def setUp(self):
        mesh = discretize.TensorMesh([np.ones(n) * 5 for n in [10, 11, 12]],
                                     [0, 0, -30])
        x = np.linspace(5, 10, 3)
        XYZ = utils.ndgrid(x, x, np.r_[0.0])
        srcLoc = np.r_[0, 0, 0.0]
        rxList0 = survey.BaseRx(XYZ)
        Src0 = survey.BaseSrc([rxList0], location=srcLoc)

        rxList1 = survey.BaseRx(XYZ)
        Src1 = survey.BaseSrc([rxList1], location=srcLoc)

        rxList2 = survey.BaseRx(XYZ)
        Src2 = survey.BaseSrc([rxList2], location=srcLoc)

        rxList3 = survey.BaseRx(XYZ)
        Src3 = survey.BaseSrc([rxList3], location=srcLoc)
        Src4 = survey.BaseSrc([rxList0, rxList1, rxList2, rxList3],
                              location=srcLoc)

        source_list = [Src0, Src1, Src2, Src3, Src4]
        mysurvey = survey.BaseSurvey(source_list=source_list)
        sim = simulation.BaseSimulation(mesh=mesh, survey=mysurvey)
        self.F = fields.Fields(
            sim,
            knownFields={"e": "E"},
            aliasFields={
                "b": ["e", "F", (lambda e, ind: self.F.mesh.edgeCurl * e)]
            },
        )
        self.Src0 = Src0
        self.Src1 = Src1
        self.mesh = mesh
        self.XYZ = XYZ
        self.simulation = sim
Exemplo n.º 11
0
    def setUp(self):
        # Note: Pole-Pole requires bigger boundary to obtain good accuracy.
        # One can use greater padding rate. Here 1.5 is used.
        cs = 12.5
        hx = [(cs, 7, -1.5), (cs, 61), (cs, 7, 1.5)]
        hy = [(cs, 7, -1.5), (cs, 20)]
        mesh = TensorMesh([hx, hy], x0="CN")
        sighalf = 1e-2
        sigma = np.ones(mesh.nC) * sighalf
        x = np.linspace(0, 250.0, 20)
        M = utils.ndgrid(x - 12.5, np.r_[0.0])
        A0loc = np.r_[-150, 0.0]
        rxloc = np.c_[M, np.zeros(20)]
        data_ana = analytics.DCAnalytic_Pole_Pole(np.r_[A0loc, 0.0],
                                                  rxloc,
                                                  sighalf,
                                                  earth_type="halfspace")

        rx = dc.receivers.Pole(M)
        src0 = dc.sources.Pole([rx], A0loc)
        survey = dc.survey.Survey([src0])

        self.survey = survey
        self.mesh = mesh
        self.sigma = sigma
        self.data_ana = data_ana

        try:
            from pymatsolver import PardisoSolver

            self.Solver = PardisoSolver
        except ImportError:
            self.Solver = SolverLU
Exemplo n.º 12
0
    def test_Transect(self, plotIt=plotIt):

        for src in self.prb.survey.source_list:
            print(" --- testing {} --- ".format(src.__class__.__name__))
            x = np.linspace(-55, 55, 12)
            XYZ = utils.ndgrid(x, np.r_[0], np.r_[0])

            P = self.mesh.getInterpolationMat(XYZ, "Fz")

            ana = mu_0 * np.imag(
                analytics.FDEM.hzAnalyticDipoleF(x, src.frequency, self.sig))
            num = P * np.imag(self.u[src, "b"])

            diff = np.linalg.norm(num - ana)

            if plotIt:
                import matplotlib.pyplot as plt

                plt.plot(x, np.log10(np.abs(num)))
                plt.plot(x, np.log10(np.abs(ana)), "r")
                plt.plot(x, diff, "g")
                plt.show()

            norm_num = np.linalg.norm(num)
            norm_ana = np.linalg.norm(ana)
            tol = tol_Transect * (norm_num + norm_ana) / 2.0

            passed = diff < tol
            print("analytic: {}, numeric {}, difference {} < tolerance {} ? "
                  " {}".format(norm_ana, norm_num, diff, tol, passed))

            self.assertTrue(passed)
Exemplo n.º 13
0
    def setUp(self):
        mesh = discretize.TensorMesh([np.ones(n) * 5 for n in [10, 11, 12]],
                                     [0, 0, -30])
        x = np.linspace(5, 10, 3)
        XYZ = utils.ndgrid(x, x, np.r_[0.0])
        srcLoc = np.r_[0, 0, 0.0]
        rxList0 = survey.BaseRx(XYZ)
        Src0 = survey.BaseSrc(receiver_list=[rxList0], location=srcLoc)
        rxList1 = survey.BaseRx(XYZ)
        Src1 = survey.BaseSrc(receiver_list=[rxList1], location=srcLoc)
        rxList2 = survey.BaseRx(XYZ)
        Src2 = survey.BaseSrc(receiver_list=[rxList2], location=srcLoc)
        rxList3 = survey.BaseRx(XYZ)
        Src3 = survey.BaseSrc(receiver_list=[rxList3], location=srcLoc)
        Src4 = survey.BaseSrc(
            receiver_list=[rxList0, rxList1, rxList2, rxList3],
            location=srcLoc)
        source_list = [Src0, Src1, Src2, Src3, Src4]
        mysurvey = survey.BaseSurvey(source_list=source_list)
        sim = simulation.BaseTimeSimulation(mesh,
                                            time_steps=[(10.0, 3), (20.0, 2)],
                                            survey=mysurvey)

        def alias(b, srcInd, timeInd):
            return self.F.mesh.edgeCurl.T * b + timeInd

        self.F = fields.TimeFields(sim,
                                   knownFields={"b": "F"},
                                   aliasFields={"e": ["b", "E", alias]})
        self.Src0 = Src0
        self.Src1 = Src1
        self.mesh = mesh
        self.XYZ = XYZ
        self.simulation = sim
Exemplo n.º 14
0
    def setUp(self):

        cs = 25.0
        hx = [(cs, 7, -1.5), (cs, 21), (cs, 7, 1.5)]
        hy = [(cs, 7, -1.5), (cs, 21), (cs, 7, 1.5)]
        hz = [(cs, 7, -1.5), (cs, 20)]
        mesh = discretize.TensorMesh([hx, hy, hz], x0="CCN")
        sigma = np.ones(mesh.nC) * 1e-2

        x = mesh.vectorCCx[(mesh.vectorCCx > -155.0)
                           & (mesh.vectorCCx < 155.0)]
        y = mesh.vectorCCy[(mesh.vectorCCy > -155.0)
                           & (mesh.vectorCCy < 155.0)]

        Aloc = np.r_[-200.0, 0.0, 0.0]

        M = utils.ndgrid(x, y, np.r_[0.0])
        phiA = analytics.DCAnalytic_Pole_Pole(Aloc,
                                              M,
                                              1e-2,
                                              earth_type="halfspace")
        data_ana = phiA

        rx = dc.receivers.Pole(M)
        src = dc.sources.Pole([rx], Aloc)
        survey = dc.survey.Survey([src])

        self.survey = survey
        self.mesh = mesh
        self.sigma = sigma
        self.data_ana = data_ana
Exemplo n.º 15
0
    def setUp(self):
        mesh = Mesh.TensorMesh([30, 30], x0=[-0.5, -1.0])
        sigma = np.ones(mesh.nC)
        model = np.log(sigma)

        prob = DC.Problem3D_CC(mesh, rhoMap=Maps.ExpMap(mesh))

        rx = DC.Rx.Pole(Utils.ndgrid([mesh.vectorCCx, np.r_[mesh.vectorCCy.max()]]))
        src = DC.Src.Dipole(
            [rx], np.r_[-0.25, mesh.vectorCCy.max()], np.r_[0.25, mesh.vectorCCy.max()]
        )
        survey = DC.Survey([src])

        prob.pair(survey)

        self.std = 0.01
        survey.std = self.std
        dobs = survey.makeSyntheticData(model)
        self.eps = 1e-8 * np.min(np.abs(dobs))
        survey.eps = self.eps
        dmis = DataMisfit.l2_DataMisfit(survey)

        self.model = model
        self.mesh = mesh
        self.survey = survey
        self.prob = prob
        self.dobs = dobs
        self.dmis = dmis
 def plot_data_inversion(self, ii, pred, fixed=False):
     titles = ["Observed", "Predicted", "Normalized misfit"]
     x = np.arange(10) + 1
     y = np.arange(10) + 1
     xy = utils.ndgrid(x, y)
     fig, axs = plt.subplots(1, 3, figsize=(10, 3))
     if fixed:
         clim = (self.dobs.min(), self.dobs.max())
     else:
         clim = None
     out = utils.plot2Ddata(xy, self.dobs, ax=axs[0], clim=clim)
     plt.colorbar(out[0], ax=axs[0], fraction=0.02)
     out = utils.plot2Ddata(xy, pred[ii], ax=axs[1], clim=clim)
     plt.colorbar(out[0], ax=axs[1], fraction=0.02)
     out = utils.plot2Ddata(xy, (pred[ii] - self.dobs) / self.uncertainty,
                            ax=axs[2],
                            clim=(-3, 3))
     plt.colorbar(out[0], ax=axs[2], fraction=0.02, ticks=[-2, -1, 0, 1, 2])
     for ii, ax in enumerate(axs):
         ax.set_aspect(1)
         ax.set_title(titles[ii])
         ax.set_xlabel("Rx")
         ax.set_ylabel("Tx")
     plt.tight_layout()
     plt.show()
Exemplo n.º 17
0
    def test_ndgrid_2D(self):
        XY = ndgrid([self.a, self.b])

        X1_test = np.array([1, 2, 3, 1, 2, 3])
        X2_test = np.array([1, 1, 1, 2, 2, 2])

        self.assertTrue(np.all(XY[:, 0] == X1_test))
        self.assertTrue(np.all(XY[:, 1] == X2_test))
Exemplo n.º 18
0
    def setUp(self):
        print("\nTesting Transect for analytic")

        cs = 10.0
        ncx, ncy, ncz = 10, 10, 10
        npad = 5
        freq = 1e2

        hx = [(cs, npad, -1.3), (cs, ncx), (cs, npad, 1.3)]
        hy = [(cs, npad, -1.3), (cs, ncy), (cs, npad, 1.3)]
        hz = [(cs, npad, -1.3), (cs, ncz), (cs, npad, 1.3)]
        mesh = discretize.TensorMesh([hx, hy, hz], "CCC")

        x = np.linspace(-10, 10, 5)
        XYZ = utils.ndgrid(x, np.r_[0], np.r_[0])
        rxList = fdem.Rx.PointElectricField(XYZ,
                                            orientation="x",
                                            component="imag")
        SrcList = [
            fdem.Src.MagDipole([rxList],
                               location=np.r_[0.0, 0.0, 0.0],
                               frequency=freq),
            fdem.Src.CircularLoop(
                [rxList],
                location=np.r_[0.0, 0.0, 0.0],
                frequency=freq,
                radius=np.sqrt(1.0 / np.pi),
            ),
            # fdem.Src.MagDipole_Bfield(
            #     [rxList], loc=np.r_[0., 0., 0.],
            #     freq=freq
            # ), # less accurate
        ]

        survey = fdem.Survey(SrcList)

        sig = 1e-1
        sigma = np.ones(mesh.nC) * sig
        sigma[mesh.gridCC[:, 2] > 0] = 1e-8

        prb = fdem.Simulation3DMagneticFluxDensity(mesh, sigma=sigma)
        prb.pair(survey)

        try:
            from pymatsolver import Pardiso

            prb.Solver = Pardiso
        except ImportError:
            prb.Solver = SolverLU

        self.prb = prb
        self.mesh = mesh
        self.sig = sig

        print(" starting solve ...")
        u = self.prb.fields()
        print(" ... done")
        self.u = u
Exemplo n.º 19
0
    def setUp(self):
        mesh = discretize.TensorMesh([30, 30], x0=[-0.5, -1.0])
        sigma = np.random.rand(mesh.nC)
        model = np.log(sigma)

        # prob = DC.Simulation3DCellCentered(mesh, rhoMap=maps.ExpMap(mesh))
        # prob1 = DC.Simulation3DCellCentered(mesh, rhoMap=maps.ExpMap(mesh))

        rx = DC.Rx.Pole(utils.ndgrid([mesh.vectorCCx, np.r_[mesh.vectorCCy.max()]]))
        rx1 = DC.Rx.Pole(utils.ndgrid([mesh.vectorCCx, np.r_[mesh.vectorCCy.min()]]))
        src = DC.Src.Dipole(
            [rx], np.r_[-0.25, mesh.vectorCCy.max()], np.r_[0.25, mesh.vectorCCy.max()]
        )
        src1 = DC.Src.Dipole(
            [rx1], np.r_[-0.25, mesh.vectorCCy.max()], np.r_[0.25, mesh.vectorCCy.max()]
        )
        survey = DC.Survey([src])
        simulation0 = DC.simulation.Simulation3DCellCentered(
            mesh=mesh, survey=survey, rhoMap=maps.ExpMap(mesh)
        )

        survey1 = DC.Survey([src1])
        simulation1 = DC.simulation.Simulation3DCellCentered(
            mesh=mesh, survey=survey1, rhoMap=maps.ExpMap(mesh)
        )

        dobs0 = simulation0.make_synthetic_data(model)
        dobs1 = simulation1.make_synthetic_data(model)

        self.mesh = mesh
        self.model = model

        self.survey0 = survey
        self.sim0 = simulation0

        self.survey1 = survey1
        self.sim1 = simulation1

        # self.dmis0 = data_misfit.L2DataMisfit(self.survey0)
        self.dmis0 = data_misfit.L2DataMisfit(data=dobs0, simulation=simulation0)
        self.dmis1 = data_misfit.L2DataMisfit(data=dobs1, simulation=simulation1)

        self.dmiscombo = self.dmis0 + self.dmis1
Exemplo n.º 20
0
    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 = discretize.TensorMesh([hx, hy], x0="CN")

        x = np.linspace(-200, 200.0, 20)
        M = utils.ndgrid(x - 12.5, np.r_[0.0])
        N = utils.ndgrid(x + 12.5, np.r_[0.0])
        A0loc = np.r_[-150, 0.0]
        A1loc = np.r_[-130, 0.0]
        B0loc = np.r_[-130, 0.0]
        B1loc = np.r_[-110, 0.0]

        rx = dc.Rx.Dipole(M, N)
        src0 = dc.Src.Dipole([rx], A0loc, B0loc)
        src1 = dc.Src.Dipole([rx], A1loc, B1loc)

        src0_ip = dc.Src.Dipole([rx], A0loc, B0loc)
        src1_ip = dc.Src.Dipole([rx], A1loc, B1loc)

        source_lists = [src0, src1]
        source_lists_ip = [src0_ip, src1_ip]
        surveyDC = dc.Survey([src0, src1])

        sigmaInf = np.ones(mesh.nC) * 1.0
        blkind = utils.model_builder.getIndicesSphere(np.r_[0, -150], 40,
                                                      mesh.gridCC)

        eta = np.zeros(mesh.nC)
        eta[blkind] = 0.1
        sigma0 = sigmaInf * (1.0 - eta)

        self.surveyDC = surveyDC
        self.mesh = mesh
        self.sigmaInf = sigmaInf
        self.sigma0 = sigma0
        self.source_lists = source_lists
        self.source_lists_ip = source_lists_ip
        self.eta = eta
Exemplo n.º 21
0
    def setUp(self):

        npad = 10
        cs = 12.5
        hx = [(cs, npad, -1.4), (cs, 61), (cs, npad, 1.4)]
        hy = [(cs, npad, -1.4), (cs, 20)]
        mesh = TensorMesh([hx, hy], x0="CN")
        sighalf = 1e-2
        sigma = np.ones(mesh.nC) * sighalf
        x = mesh.cell_centers_x[
            np.logical_and(mesh.cell_centers_x > -150, mesh.cell_centers_x < 250)
        ]
        M = utils.ndgrid(x, np.r_[0.0])
        N = utils.ndgrid(x + 12.5 * 4, np.r_[0.0])
        A0loc = np.r_[-200, 0.0]
        A1loc = np.r_[-250, 0.0]
        rxloc = [np.c_[M, np.zeros(x.size)], np.c_[N, np.zeros(x.size)]]
        data_ana_A = analytics.DCAnalytic_Pole_Dipole(
            np.r_[A0loc, 0.0], rxloc, sighalf, earth_type="halfspace"
        )
        data_ana_b = analytics.DCAnalytic_Pole_Dipole(
            np.r_[A1loc, 0.0], rxloc, sighalf, earth_type="halfspace"
        )
        data_ana = data_ana_A - data_ana_b

        rx = dc.receivers.Dipole(M, N)
        src0 = dc.sources.Dipole([rx], A0loc, A1loc)
        survey = dc.Survey([src0])

        self.survey = survey
        self.mesh = mesh
        self.sigma = sigma
        self.data_ana = data_ana
        self.plotIt = False

        try:
            from pymatsolver import Pardiso

            self.solver = Pardiso
        except ImportError:
            self.solver = SolverLU
Exemplo n.º 22
0
    def setUp(self):
        mesh = discretize.TensorMesh([np.ones(n) * 5 for n in [10, 11, 12]],
                                     [0, 0, -30])
        x = np.linspace(5, 10, 3)
        XYZ = utils.ndgrid(x, x, np.r_[0.0])
        srcLoc = np.r_[0.0, 0.0, 0.0]
        receiver_list0 = survey.BaseRx(XYZ)
        Src0 = survey.BaseSrc([receiver_list0], location=srcLoc)

        receiver_list1 = survey.BaseRx(XYZ)
        Src1 = survey.BaseSrc([receiver_list1], location=srcLoc)

        receiver_list2 = survey.BaseRx(XYZ)
        Src2 = survey.BaseSrc([receiver_list2], location=srcLoc)

        receiver_list3 = survey.BaseRx(XYZ)
        Src3 = survey.BaseSrc([receiver_list3], location=srcLoc)
        Src4 = survey.BaseSrc(
            [receiver_list0, receiver_list1, receiver_list2, receiver_list3],
            location=srcLoc,
        )
        source_list = [Src0, Src1, Src2, Src3, Src4]

        mysurvey = survey.BaseSurvey(source_list=source_list)
        sim = simulation.BaseSimulation(mesh=mesh, survey=mysurvey)
        self.D = data.Data(mysurvey)
        self.F = fields.Fields(
            sim,
            knownFields={
                "phi": "CC",
                "e": "E",
                "b": "F"
            },
            dtype={
                "phi": float,
                "e": complex,
                "b": complex
            },
        )
        self.Src0 = Src0
        self.Src1 = Src1
        self.mesh = mesh
        self.XYZ = XYZ
        self.simulation = sim
    def plot_survey_data(self, percentage, floor, seed, add_noise, plot_type,
                         update):
        self._percentage = percentage
        self._floor = floor
        self._seed = seed
        self._dobs = self.add_noise()
        self._data_prop.dobs = self._dobs.copy()

        fig, axs = plt.subplots(1, 2, figsize=(8, 4))
        out = self.mesh_prop.plotImage(1.0 / self.slowness_prop, ax=axs[0])
        cb = plt.colorbar(out[0], ax=axs[0], fraction=0.02)
        cb.set_label("Velocity (m/s)")
        self.survey_prop.plot(ax=axs[0])
        axs[0].set_title("Survey")
        axs[0].set_xlabel("x (m)")
        axs[0].set_ylabel("z (m)")

        x = np.arange(10) + 1
        y = np.arange(10) + 1
        xy = utils.ndgrid(x, y)
        if plot_type == "tx_rx_plane":
            if add_noise:
                out = utils.plot2Ddata(xy, self.dobs, ax=axs[1])
            else:
                out = utils.plot2Ddata(xy, self.pred, ax=axs[1])
            axs[1].set_xlabel("Rx")
            axs[1].set_ylabel("Tx")
            axs[1].set_xticks(x)
            axs[1].set_yticks(y)
            cb = plt.colorbar(out[0], ax=axs[1], fraction=0.02)
            cb.set_label("Traveltime (s)")
            for ax in axs:
                ax.set_aspect(1)
        else:
            if add_noise:
                out = axs[1].hist(self.pred, edgecolor="k")
            else:
                out = axs[1].hist(self.dobs, edgecolor="k")
            axs[1].set_ylabel("Count")
            axs[1].set_xlabel("Travel time (s)")
            axs[0].set_aspect(1)
        plt.tight_layout()
        plt.show()
Exemplo n.º 24
0
 def setUp(self):
     mesh = discretize.TensorMesh([np.ones(n) * 5 for n in [10, 11, 12]],
                                  [0, 0, -30])
     x = np.linspace(5, 10, 3)
     XYZ = utils.ndgrid(x, x, np.r_[0.0])
     srcLoc = np.r_[0, 0, 0.0]
     rxList0 = survey.BaseRx(XYZ)
     Src0 = survey.BaseSrc([rxList0], location=srcLoc)
     rxList1 = survey.BaseRx(XYZ)
     Src1 = survey.BaseSrc([rxList1], location=srcLoc)
     rxList2 = survey.BaseRx(XYZ)
     Src2 = survey.BaseSrc([rxList2], location=srcLoc)
     rxList3 = survey.BaseRx(XYZ)
     Src3 = survey.BaseSrc([rxList3], location=srcLoc)
     Src4 = survey.BaseSrc([rxList0, rxList1, rxList2, rxList3],
                           location=srcLoc)
     srcList = [Src0, Src1, Src2, Src3, Src4]
     mysurvey = survey.BaseSurvey(source_list=srcList)
     self.D = data.Data(mysurvey)
Exemplo n.º 25
0
    def test_ndgrid_3D(self):
        XYZ = ndgrid([self.a, self.b, self.c])

        X1_test = np.array([
            1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1,
            2, 3
        ])
        X2_test = np.array([
            1, 1, 1, 2, 2, 2, 1, 1, 1, 2, 2, 2, 1, 1, 1, 2, 2, 2, 1, 1, 1, 2,
            2, 2
        ])
        X3_test = np.array([
            1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4,
            4, 4
        ])

        self.assertTrue(np.all(XYZ[:, 0] == X1_test))
        self.assertTrue(np.all(XYZ[:, 1] == X2_test))
        self.assertTrue(np.all(XYZ[:, 2] == X3_test))
Exemplo n.º 26
0
    def setUp(self):
        cs = 10
        nc = 20
        npad = 10
        mesh = discretize.CylMesh([
            [(cs, nc), (cs, npad, 1.3)],
            np.r_[2 * np.pi],
            [(cs, npad, -1.3), (cs, nc), (cs, npad, 1.3)],
        ])

        mesh.x0 = np.r_[0.0, 0.0, -mesh.hz[:npad + nc].sum()]

        # receivers
        rx_x = np.linspace(10, 200, 20)
        rx_z = np.r_[-5]
        rx_locs = utils.ndgrid([rx_x, np.r_[0], rx_z])
        rx_list = [
            dc.receivers.BaseRx(rx_locs, projField="e", orientation="x")
        ]

        # sources
        src_a = np.r_[0.0, 0.0, -5.0]
        src_b = np.r_[55.0, 0.0, -5.0]

        src_list = [
            dc.sources.Dipole(rx_list, locationA=src_a, locationB=src_b)
        ]

        self.mesh = mesh
        self.survey = dc.survey.Survey(src_list)
        self.sigma_map = maps.ExpMap(mesh) * maps.InjectActiveCells(
            mesh, mesh.gridCC[:, 2] <= 0, np.log(1e-8))
        self.prob = dc.simulation.Simulation3DCellCentered(
            mesh=mesh,
            survey=self.survey,
            sigmaMap=self.sigma_map,
            Solver=Pardiso,
            bc_type="Dirichlet",
        )
Exemplo n.º 27
0
    def setUp(self):
        # Note: Pole-Pole requires bigger boundary to obtain good accuracy.
        # One can use greater padding rate. Here 2 is used.
        npad = 10
        cs = 12.5
        hx = [(cs, npad, -2), (cs, 61), (cs, npad, 2)]
        hy = [(cs, npad, -2), (cs, 20)]
        mesh = TensorMesh([hx, hy], x0="CN")
        sighalf = 1e-2
        sigma = np.ones(mesh.nC) * sighalf
        x = mesh.cell_centers_x[
            np.logical_and(mesh.cell_centers_x > -150, mesh.cell_centers_x < 250)
        ]
        M = utils.ndgrid(x, np.r_[0.0])
        # N = utils.ndgrid(x + 12.5*4, np.r_[0.0])
        A0loc = np.r_[-200, 0.0]
        # A1loc = np.r_[-250, 0.0]
        rxloc = np.c_[M, np.zeros(x.size)]
        data_ana = analytics.DCAnalytic_Pole_Pole(
            np.r_[A0loc, 0.0], rxloc, sighalf, earth_type="halfspace"
        )

        rx = dc.receivers.Pole(M)
        src0 = dc.sources.Pole([rx], A0loc)
        survey = dc.survey.Survey([src0])

        self.survey = survey
        self.mesh = mesh
        self.sigma = sigma
        self.data_ana = data_ana

        try:
            from pymatsolver import PardisoSolver

            self.solver = PardisoSolver
        except ImportError:
            self.solver = SolverLU
Exemplo n.º 28
0
    def simulate_dipole(
        self,
        component,
        target,
        inclination,
        declination,
        length,
        dx,
        moment,
        depth,
        profile,
        fixed_scale,
        show_halfwidth,
    ):
        self.component = component
        self.target = target
        self.inclination = inclination
        self.declination = declination
        self.length = length
        self.dx = dx
        self.moment = moment
        self.depth = depth
        self.profile = profile
        self.fixed_scale = fixed_scale
        self.show_halfwidth = show_halfwidth

        nT = 1e9
        nx = ny = int(length / dx)
        hx = np.ones(nx) * dx
        hy = np.ones(ny) * dx
        self.mesh = TensorMesh((hx, hy), "CC")
        z = np.r_[1.0]
        orientation = self.id_to_cartesian(inclination, declination)
        if self.target == "Dipole":
            md = em.static.MagneticDipoleWholeSpace(location=np.r_[0, 0,
                                                                   -depth],
                                                    orientation=orientation,
                                                    moment=moment)
            xyz = utils.ndgrid(self.mesh.vectorCCx, self.mesh.vectorCCy, z)
            b_vec = md.magnetic_flux_density(xyz)

        elif self.target == "Monopole (+)":
            md = em.static.MagneticPoleWholeSpace(location=np.r_[0, 0, -depth],
                                                  orientation=orientation,
                                                  moment=moment)
            xyz = utils.ndgrid(self.mesh.vectorCCx, self.mesh.vectorCCy, z)
            b_vec = md.magnetic_flux_density(xyz)

        elif self.target == "Monopole (-)":
            md = em.static.MagneticPoleWholeSpace(location=np.r_[0, 0, -depth],
                                                  orientation=orientation,
                                                  moment=moment)
            xyz = utils.ndgrid(self.mesh.vectorCCx, self.mesh.vectorCCy, z)
            b_vec = -md.magnetic_flux_density(xyz)

        # Project to the direction  of earth field
        if component == "Bt":
            rx_orientation = orientation.copy()
        elif component == "Bg":
            rx_orientation = orientation.copy()
            xyz_up = utils.ndgrid(self.mesh.vectorCCx, self.mesh.vectorCCy,
                                  z + 1.0)
            b_vec -= md.magnetic_flux_density(xyz_up)

        elif component == "Bx":
            rx_orientation = self.id_to_cartesian(0, 0)
        elif component == "By":
            rx_orientation = self.id_to_cartesian(0, 90)
        elif component == "Bz":
            rx_orientation = self.id_to_cartesian(90, 0)

        self.data = self.dot_product(b_vec, rx_orientation) * nT

        # Compute profile
        if (profile == "North") or (profile == "None"):
            self.xy_profile = np.c_[np.zeros(self.mesh.nCx),
                                    self.mesh.vectorCCx]

        elif profile == "East":
            self.xy_profile = np.c_[self.mesh.vectorCCx,
                                    np.zeros(self.mesh.nCx)]
        self.inds_profile = utils.closestPoints(self.mesh, self.xy_profile)
        self.data_profile = self.data[self.inds_profile]
Exemplo n.º 29
0
    def simulate_prism(
        self,
        component,
        inclination,
        declination,
        length,
        dx,
        B0,
        kappa,
        depth,
        profile,
        fixed_scale,
        show_halfwidth,
        prism_dx,
        prism_dy,
        prism_dz,
        prism_inclination,
        prism_declination,
    ):
        self.component = component
        self.inclination = -inclination  # -ve accounts for LH modeling in SimPEG
        self.declination = declination
        self.length = length
        self.dx = dx
        self.B0 = B0
        self.kappa = kappa
        self.depth = depth
        self.profile = profile
        self.fixed_scale = fixed_scale
        self.show_halfwidth = show_halfwidth

        # prism parameter
        self.prism = self.get_prism(
            prism_dx,
            prism_dy,
            prism_dz,
            0,
            0,
            -depth,
            prism_inclination,
            prism_declination,
        )

        nx = ny = int(length / dx)
        hx = np.ones(nx) * dx
        hy = np.ones(ny) * dx
        self.mesh = TensorMesh((hx, hy), "CC")

        z = np.r_[1.0]
        B = np.r_[B0, -inclination,
                  declination]  # -ve accounts for LH modeling in SimPEG

        # Project to the direction  of earth field
        if component == "Bt":
            uType = "tf"
        elif component == "Bx":
            uType = "bx"
        elif component == "By":
            uType = "by"
        elif component == "Bz":
            uType = "bz"

        xyz = utils.ndgrid(self.mesh.vectorCCx, self.mesh.vectorCCy, z)
        out = createMagSurvey(np.c_[xyz, np.ones(self.mesh.nC)], B)
        self.survey = out[0]
        self.dobs = out[1]
        self.sim = Simulation()

        self.sim.prism = self.prism
        self.sim.survey = self.survey
        self.sim.susc = kappa
        self.sim.uType, self.sim.mType = uType, "induced"

        self.data = self.sim.fields()[0]

        # Compute profile
        if (profile == "North") or (profile == "None"):
            self.xy_profile = np.c_[np.zeros(self.mesh.nCx),
                                    self.mesh.vectorCCx]

        elif profile == "East":
            self.xy_profile = np.c_[self.mesh.vectorCCx,
                                    np.zeros(self.mesh.nCx)]
        self.inds_profile = utils.closestPoints(self.mesh, self.xy_profile)
        self.data_profile = self.data[self.inds_profile]
Exemplo n.º 30
0
              np.mean(block_z),
              np.diff(block_z),
              np.mean(block_x),
              np.diff(block_x),
              np.mean(block_y),
              np.diff(block_y), ]

# source
src_loc = np.r_[0.0, 0.0, 0.0]
freq = 10

# receivers
rx_x = np.linspace(-175.0, 175.0, 8)
rx_y = rx_x.copy()
rx_z = np.r_[175.0]
rx_locs = utils.ndgrid(rx_x, rx_y, rx_z)

# mesh
csx, ncx, npadx = 25.0, 16, 10
csz, ncz, npadz = 25.0, 8, 10
pf = 1.5

# primary mesh
hx = [(csx, ncx), (csx, npadx, pf)]
hz = [(csz, npadz, -pf), (csz, ncz), (csz, npadz, pf)]
meshp = discretize.CylMesh([hx, 1.0, hz], x0="0CC")

# secondary mesh
h = [(csz, npadz - 4, -pf), (csz, ncz), (csz, npadz - 4, pf)]
meshs = discretize.TensorMesh(3 * [h], x0="CCC")