Exemplo n.º 1
0
def model_fields(A, B, zcLayer, dzLayer, xc, zc, r, sigLayer, sigTarget, sigHalf):
    # Create halfspace model
    mhalf = sigHalf * np.ones([mesh.nC])
    # Add layer to model
    mLayer = addLayer2Mod(zcLayer, dzLayer, mhalf, sigLayer)
    # Add plate or cylinder
    # fullMod = addPlate2Mod(xc,zc,dx,dz,rotAng,LayerMod,sigTarget)
    mtrue = addCylinder2Mod(xc, zc, r, mLayer, sigTarget)

    Mx = np.empty(shape=(0, 2))
    Nx = np.empty(shape=(0, 2))
    rx = DC.Rx.Dipole(Mx, Nx)
    if B == []:
        src = DC.Src.Pole([rx], np.r_[A, 0.0])
    else:
        src = DC.Src.Dipole([rx], np.r_[A, 0.0], np.r_[B, 0.0])

    survey = DC.Survey([src])
    survey_prim = DC.Survey([src])

    problem = DC.Problem3D_CC(mesh, sigmaMap=sigmaMap)
    problem_prim = DC.Problem3D_CC(mesh, sigmaMap=sigmaMap)
    problem.Solver = SolverLU
    problem_prim.Solver = SolverLU
    problem.pair(survey)
    problem_prim.pair(survey_prim)

    primary_field = problem_prim.fields(mhalf)

    total_field = problem.fields(mtrue)

    return mtrue, mhalf, src, primary_field, total_field
Exemplo n.º 2
0
def plate_fields(A, B, dx, dz, xc, zc, rotAng, sigplate, sighalf):
    # Create halfspace model
    mhalf = np.log(sighalf * np.ones([mesh.nC]))

    # Create true model with plate
    mtrue = createPlateMod(xc, zc, dx, dz, rotAng, sigplate, sighalf)

    Mx = np.empty(shape=(0, 2))
    Nx = np.empty(shape=(0, 2))
    rx = DC.Rx.Dipole(Mx, Nx)
    if B == []:
        src = DC.Src.Pole([rx], np.r_[A, 0.0])
    else:
        src = DC.Src.Dipole([rx], np.r_[A, 0.0], np.r_[B, 0.0])

    survey = DC.Survey([src])
    survey_prim = DC.Survey([src])

    problem = DC.Problem3D_CC(mesh, sigmaMap=mapping)
    problem_prim = DC.Problem3D_CC(mesh, sigmaMap=mapping)
    problem.Solver = SolverLU
    problem_prim.Solver = SolverLU
    problem.pair(survey)
    problem_prim.pair(survey_prim)

    primary_field = problem_prim.fields(mhalf)

    total_field = problem.fields(mtrue)

    return mtrue, mhalf, src, primary_field, total_field
Exemplo n.º 3
0
    def simpeg_survey(self):
        """
        Create the measurement setup as an instance of DC Survey.
        :return: DC.Survey instance
        """
        if self._simpeg_survey is None:
            probe_points = self.points.all_points

            group_by_cc = {}
            for ca, cb, pa, pb in self.measurements:
                group_by_cc.setdefault((ca, cb), [])
                group_by_cc[(ca, cb)].append((pa, pb))

            src_list = []
            sorted = [(cc, pp) for cc, pp in group_by_cc.items()]
            sorted.sort()
            for cc, pp_list in sorted:
                rx_list = [
                    DC.Rx.Dipole(probe_points[pp[0], :],
                                 probe_points[pp[1], :]) for pp in pp_list
                ]
                I = 1.0
                src = DC.Src.Dipole(rx_list,
                                    probe_points[cc[0], :],
                                    probe_points[cc[1], :],
                                    current=I)
                src_list.append(src)
            self._simpeg_survey = DC.Survey(src_list)

        if self._values is not None:
            self._simpeg_survey.dobs = self._values
            self._simpeg_survey.std = self._errors

        return self._simpeg_survey
Exemplo n.º 4
0
    def setUp(self):
        mesh = Mesh.TensorMesh([30, 30], x0=[-0.5, -1.])
        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
Exemplo n.º 5
0
    def setUp(self):
        cs = 10
        nc = 20
        npad = 10
        mesh = Mesh.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., -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.Rx.BaseRx(rx_locs, 'ex')]

        # sources
        src_a = np.r_[0., 0., -5.]
        src_b = np.r_[55., 0., -5.]

        src_list = [DC.Src.Dipole(rx_list, locA=src_a, locB=src_b)]

        self.mesh = mesh
        self.sigma_map = Maps.ExpMap(mesh) * Maps.InjectActiveCells(
            mesh, mesh.gridCC[:, 2] <= 0, np.log(1e-8))
        self.prob = DC.Problem3D_CC(mesh,
                                    sigmaMap=self.sigma_map,
                                    Solver=Pardiso,
                                    bc_type="Dirichlet")
        self.survey = DC.Survey(src_list)
        self.prob.pair(self.survey)
Exemplo n.º 6
0
    def setUp(self):

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

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

        Aloc = np.r_[-200., 0., 0.]
        Bloc = np.r_[200., 0., 0.]
        M = Utils.ndgrid(x-25., y, np.r_[0.])
        N = Utils.ndgrid(x+25., y, np.r_[0.])
        phiA = EM.Analytics.DCAnalytic_Pole_Dipole(
            Aloc, [M, N], 1e-2, earth_type="wholespace"
        )
        phiB = EM.Analytics.DCAnalytic_Pole_Dipole(
            Bloc, [M, N], 1e-2, earth_type="wholespace"
        )
        data_anal = phiA-phiB

        rx = DC.Rx.Dipole(M, N)
        src = DC.Src.Dipole([rx], Aloc, Bloc)
        survey = DC.Survey([src])

        self.survey = survey
        self.mesh = mesh
        self.sigma = sigma
        self.data_anal = data_anal
Exemplo n.º 7
0
    def setUp(self):

        cs = 25.
        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 = Mesh.TensorMesh([hx, hy, hz], x0="CCN")
        sigma = np.ones(mesh.nC) * 1e-2

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

        Aloc = np.r_[-200., 0., 0.]

        M = Utils.ndgrid(x, y, np.r_[0.])
        phiA = EM.Analytics.DCAnalytic_Pole_Pole(Aloc,
                                                 M,
                                                 1e-2,
                                                 earth_type="halfspace")
        data_ana = phiA

        rx = DC.Rx.Pole(M)
        src = DC.Src.Pole([rx], Aloc)
        survey = DC.Survey([src])

        self.survey = survey
        self.mesh = mesh
        self.sigma = sigma
        self.data_ana = data_ana
Exemplo n.º 8
0
def getSensitivity(survey, A, B, M, N, model):

    if survey == "Dipole-Dipole":
        rx = DC.Rx.Dipole(np.r_[M, 0.0], np.r_[N, 0.0])
        src = DC.Src.Dipole([rx], np.r_[A, 0.0], np.r_[B, 0.0])
    elif survey == "Pole-Dipole":
        rx = DC.Rx.Dipole(np.r_[M, 0.0], np.r_[N, 0.0])
        src = DC.Src.Pole([rx], np.r_[A, 0.0])
    elif survey == "Dipole-Pole":
        rx = DC.Rx.Pole(np.r_[M, 0.0])
        src = DC.Src.Dipole([rx], np.r_[A, 0.0], np.r_[B, 0.0])
    elif survey == "Pole-Pole":
        rx = DC.Rx.Pole(np.r_[M, 0.0])
        src = DC.Src.Pole([rx], np.r_[A, 0.0])

    # Model mappings
    expmap = Maps.ExpMap(mesh)
    mapping = expmap

    survey = DC.Survey([src])
    problem = DC.Problem3D_CC(mesh, sigmaMap=mapping)
    problem.Solver = SolverLU
    problem.pair(survey)
    fieldObj = problem.fields(model)

    J = problem.Jtvec(model, np.array([1.0]), f=fieldObj)

    return J
Exemplo n.º 9
0
def readReservoirDC(fname):
    f = open(fname, 'r')
    data = f.readlines()
    temp = data[3].split()
    nelec, ndata, aspacing = int(temp[0]), int(temp[1]), float(temp[2])
    height_water = float(data[4 + ndata + 3].split()[0])
    height_dam = float(data[4 + ndata + 4].split()[0])
    ntx = nelec - 2
    datalist = []
    for iline, line in enumerate(data[4:4 + ndata]):
        #     line = line.replace(ignorevalue, 'nan')
        linelist = line.split()
        datalist.append(np.array(map(float, linelist)))
    DAT = np.vstack(datalist)
    datalistSRC = []
    srcList = []
    #     for i in range(ntx-1):
    for i in range(ntx - 1):
        txloc = np.array([i + 2, i + 1.])
        ind = (DAT[:, :2] == txloc).sum(axis=1) == 2.
        temp = DAT[ind, :]
        datalistSRC.append(temp)
        e = np.zeros_like(temp[:, 2])
        rxtemp = DC.Rx.Dipole(np.c_[temp[:, 2] * aspacing, e, e],
                              np.c_[temp[:, 3] * aspacing, e, e])
        srctemp = DC.Src.Dipole([rxtemp], np.r_[txloc[1] * aspacing, 0., 0.],
                                np.r_[txloc[0] * aspacing, 0., 0.])
        srcList.append(srctemp)
    DAT_src = np.vstack(datalistSRC)
    survey = DC.Survey(srcList)
    survey.dobs = DAT_src[:, -1]
    survey.height_water = height_water
    survey.height_dam = height_dam
    return survey
Exemplo n.º 10
0
def run(plotIt=True):
    cs = 25.
    hx = [(cs, 7, -1.3), (cs, 21), (cs, 7, 1.3)]
    hy = [(cs, 7, -1.3), (cs, 21), (cs, 7, 1.3)]
    hz = [(cs, 7, -1.3), (cs, 20)]
    mesh = Mesh.TensorMesh([hx, hy, hz], 'CCN')
    sighalf = 1e-2
    sigma = np.ones(mesh.nC) * sighalf
    xtemp = np.linspace(-150, 150, 21)
    ytemp = np.linspace(-150, 150, 21)
    xyz_rxP = Utils.ndgrid(xtemp - 10., ytemp, np.r_[0.])
    xyz_rxN = Utils.ndgrid(xtemp + 10., ytemp, np.r_[0.])
    xyz_rxM = Utils.ndgrid(xtemp, ytemp, np.r_[0.])

    # if plotIt:
    #     fig, ax = plt.subplots(1,1, figsize = (5,5))
    #     mesh.plotSlice(sigma, grid=True, ax = ax)
    #     ax.plot(xyz_rxP[:,0],xyz_rxP[:,1], 'w.')
    #     ax.plot(xyz_rxN[:,0],xyz_rxN[:,1], 'r.', ms = 3)

    rx = DC.Rx.Dipole(xyz_rxP, xyz_rxN)
    src = DC.Src.Dipole([rx], np.r_[-200, 0, -12.5], np.r_[+200, 0, -12.5])
    survey = DC.Survey([src])
    problem = DC.Problem3D_CC(mesh)
    problem.pair(survey)
    try:
        from pymatsolver import MumpsSolver
        problem.Solver = MumpsSolver
    except Exception, e:
        pass
Exemplo n.º 11
0
def run(plotIt=True):

    cs = 25.
    hx = [(cs, 7, -1.3), (cs, 21), (cs, 7, 1.3)]
    hy = [(cs, 7, -1.3), (cs, 21), (cs, 7, 1.3)]
    hz = [(cs, 7, -1.3), (cs, 20)]
    mesh = Mesh.TensorMesh([hx, hy, hz], 'CCN')
    sighalf = 1e-2
    sigma = np.ones(mesh.nC)*sighalf
    xtemp = np.linspace(-150, 150, 21)
    ytemp = np.linspace(-150, 150, 21)
    xyz_rxP = Utils.ndgrid(xtemp-10., ytemp, np.r_[0.])
    xyz_rxN = Utils.ndgrid(xtemp+10., ytemp, np.r_[0.])
    xyz_rxM = Utils.ndgrid(xtemp, ytemp, np.r_[0.])

    # if plotIt:
    #     fig, ax = plt.subplots(1,1, figsize = (5,5))
    #     mesh.plotSlice(sigma, grid=True, ax = ax)
    #     ax.plot(xyz_rxP[:,0],xyz_rxP[:,1], 'w.')
    #     ax.plot(xyz_rxN[:,0],xyz_rxN[:,1], 'r.', ms = 3)

    rx = DC.Rx.Dipole(xyz_rxP, xyz_rxN)
    src = DC.Src.Dipole([rx], np.r_[-200, 0, -12.5], np.r_[+200, 0, -12.5])
    survey = DC.Survey([src])
    problem = DC.Problem3D_CC(mesh, Solver=Solver, sigma=sigma)
    problem.pair(survey)

    data = survey.dpred()

    def DChalf(srclocP, srclocN, rxloc, sigma, I=1.):
        rp = (srclocP.reshape([1, -1])).repeat(rxloc.shape[0], axis=0)
        rn = (srclocN.reshape([1, -1])).repeat(rxloc.shape[0], axis=0)
        rP = np.sqrt(((rxloc-rp)**2).sum(axis=1))
        rN = np.sqrt(((rxloc-rn)**2).sum(axis=1))
        return I/(sigma*2.*np.pi)*(1/rP-1/rN)

    data_anaP = DChalf(
        np.r_[-200, 0, 0.], np.r_[+200, 0, 0.], xyz_rxP, sighalf
    )
    data_anaN = DChalf(
        np.r_[-200, 0, 0.], np.r_[+200, 0, 0.], xyz_rxN, sighalf
    )
    data_ana = data_anaP - data_anaN
    Data_ana = data_ana.reshape((21, 21), order='F')
    Data = data.reshape((21, 21), order='F')
    X = xyz_rxM[:, 0].reshape((21, 21), order='F')
    Y = xyz_rxM[:, 1].reshape((21, 21), order='F')

    if plotIt:
        fig, ax = plt.subplots(1, 2, figsize=(12, 5))
        vmin = np.r_[data, data_ana].min()
        vmax = np.r_[data, data_ana].max()
        dat0 = ax[0].contourf(X, Y, Data_ana, 60, vmin=vmin, vmax=vmax)
        dat1 = ax[1].contourf(X, Y, Data, 60, vmin=vmin, vmax=vmax)
        plt.colorbar(dat0, orientation='horizontal', ax=ax[0])
        plt.colorbar(dat1, orientation='horizontal', ax=ax[1])
        ax[1].set_title('Analytic')
        ax[0].set_title('Computed')

    return np.linalg.norm(data-data_ana)/np.linalg.norm(data_ana)
Exemplo n.º 12
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 = Mesh.TensorMesh([hx, hy, hz], x0="CCN")

        x = mesh.vectorCCx[(mesh.vectorCCx > -80.) & (mesh.vectorCCx < 80.)]
        y = mesh.vectorCCx[(mesh.vectorCCy > -80.) & (mesh.vectorCCy < 80.)]
        Aloc = np.r_[-100., 0., 0.]
        Bloc = np.r_[100., 0., 0.]
        M = Utils.ndgrid(x-12.5, y, np.r_[0.])
        N = Utils.ndgrid(x+12.5, y, np.r_[0.])
        radius = 50.
        xc = np.r_[0., 0., -100]
        blkind = Utils.ModelBuilder.getIndicesSphere(xc, radius, mesh.gridCC)
        sigmaInf = np.ones(mesh.nC)*1e-2
        eta = np.zeros(mesh.nC)
        eta[blkind] = 0.1
        sigma0 = sigmaInf*(1.-eta)

        rx = DC.Rx.Dipole(M, N)
        src = DC.Src.Dipole([rx], Aloc, Bloc)
        surveyDC = DC.Survey([src])

        self.surveyDC = surveyDC
        self.mesh = mesh
        self.sigmaInf = sigmaInf
        self.sigma0 = sigma0
        self.src = src
        self.eta = eta
Exemplo n.º 13
0
def generateSurvey(rx, tx, min_dipole_size, max_dipole_size):
    """
     Generates a survey to through into a forward model
     INPUT:
          rx_dx = array of Rx x spacings
          rx_dy = array of Rx y spacings
          Tx_dx = array of Tx x spacings
          Tx_dy = array of Tx y spacings
    """
    SrcList = []
    rx_length = rx.shape[0]
    for idk in range(tx.shape[0]):
        rx1 = []
        rx2 = []
        for idx in range(rx_length):
            node1 = rx[idx, :]
            for idj in range(idx, rx_length):
                node2 = rx[idj, :]
                dist = np.sqrt(np.sum((node1 - node2)**2))
                distE = np.abs(node1[0] - tx[idk, 0])
                if distE < 80:
                    if (min_dipole_size) < dist < (max_dipole_size):
                        rx1.append(node1)
                        rx2.append(node2)
                    # print(dist)
        rx1 = np.asarray(rx1)
        rx2 = np.asarray(rx2)
        rxClass = DC.Rx.Dipole(rx1, rx2)
        srcClass = DC.Src.Pole([rxClass], tx[idk, :])
        SrcList.append(srcClass)

    survey = DC.Survey(SrcList)

    return survey
Exemplo n.º 14
0
 def _setupSurvey(self):
     epp = self.tunnelParams.getSingleArrayTunnelCelingEnds()
     p1, s1 = Tunnel_SurveyTools.getLinearArraySurvey(epp, 5, self.surveyType)
     epp = self.tunnelParams.getSingleArrayFloorEnds()
     p2, s2 = Tunnel_SurveyTools.getLinearArraySurvey(epp, 5, self.surveyType)
     epp = self.tunnelParams.getSingleArrayRightSideEnds()
     p3, s3 = Tunnel_SurveyTools.getLinearArraySurvey(epp, 5, self.surveyType)
     epp = self.tunnelParams.getSingleArrayLeftSideEnds()
     p4, s4 = Tunnel_SurveyTools.getLinearArraySurvey(epp, 5, self.surveyType)
     self.allSurveyPoints = numpy.vstack((p1, p2, p3, p4))
     self.survey = DC.Survey(s1.srcList + s2.srcList + s3.srcList + s4.srcList)
     pass
Exemplo n.º 15
0
def cylinder_fields(A, B, r, sigcyl, sighalf, xc=0.0, zc=-20.0):

    circhalf = np.r_[np.log(sighalf), np.log(sighalf), xc, zc, r]
    circtrue = np.r_[np.log(sigcyl), np.log(sighalf), xc, zc, r]

    mhalf = circmap * circhalf
    mtrue = circmap * circtrue

    Mx = np.empty(shape=(0, 2))
    Nx = np.empty(shape=(0, 2))
    # rx = DC.Rx.Dipole_ky(Mx,Nx)
    rx = DC.Rx.Dipole(Mx, Nx)
    if B == []:
        src = DC.Src.Pole([rx], np.r_[A, 0.0])
    else:
        src = DC.Src.Dipole([rx], np.r_[A, 0.0], np.r_[B, 0.0])
    # survey = DC.Survey_ky([src])
    survey = DC.Survey([src])
    survey_prim = DC.Survey([src])
    # problem = DC.Problem2D_CC(mesh, sigmaMap = sigmaMap)
    problem = DC.Problem3D_CC(mesh, sigmaMap=sigmaMap)
    problem_prim = DC.Problem3D_CC(mesh, sigmaMap=sigmaMap)
    problem.Solver = SolverLU
    problem_prim.Solver = SolverLU
    problem.pair(survey)
    problem_prim.pair(survey_prim)

    primary_field = problem_prim.fields(mhalf)
    # phihalf = f[src, 'phi', 15]
    # ehalf = f[src, 'e']
    # jhalf = f[src, 'j']
    # charge = f[src, 'charge']

    total_field = problem.fields(mtrue)
    # phi = f[src, 'phi', 15]
    # e = f[src, 'e']
    # j = f[src, 'j']
    # charge = f[src, 'charge']

    return mtrue, mhalf, src, total_field, primary_field
Exemplo n.º 16
0
def _getSimpleLinearArraySurvey(points):
    sources = []
    for ii in range(points.shape[0] - 3):
        Apos = points[ii]
        Bpos = points[ii + 1]
        Mpos = points[ii + 2:-1]
        Npos = points[ii + 3:]
        receiver = DC.Rx.Dipole(Mpos, Npos)
        source = DC.Src.Dipole([receiver], Apos, Bpos)
        sources.append(source)
    survey = DC.Survey(sources)
    return survey
    pass
Exemplo n.º 17
0
    def __init__(self, **kwargs):
        super(SimulationDC, self).__init__(**kwargs)

        self._prob = DC.Problem3D_CC(
            self.meshGenerator.mesh,
            sigmaMap=self.physprops.wires.sigma,
            bc_type='Dirichlet',
            Solver=Pardiso
        )
        self._src = DC.Src.Dipole([], self.src_a, self.src_b)
        self._survey = DC.Survey([self._src])

        self._prob.pair(self._survey)
Exemplo n.º 18
0
    def setUp(self):
        mesh = Mesh.TensorMesh([30, 30], x0=[-0.5, -1.])
        sigma = np.random.rand(mesh.nC)
        model = np.log(sigma)

        prob = DC.Problem3D_CC(mesh, rhoMap=Maps.ExpMap(mesh))
        prob1 = DC.Problem3D_CC(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])
        prob.pair(survey)

        survey1 = DC.Survey([src1])
        prob1.pair(survey1)

        dobs0 = survey.makeSyntheticData(model)
        dobs1 = survey1.makeSyntheticData(model)

        self.mesh = mesh
        self.model = model

        self.survey0 = survey
        self.prob0 = prob

        self.survey1 = survey1
        self.prob1 = prob1

        self.dmis0 = DataMisfit.l2_DataMisfit(self.survey0)
        self.dmis1 = DataMisfit.l2_DataMisfit(self.survey1)

        self.dmiscobmo = self.dmis0 + self.dmis1
Exemplo n.º 19
0
    def __init__(self, **kwargs):
        super(SimulationDC, self).__init__(**kwargs)

        self._prob = DC.Problem3D_CC(self.meshGenerator.mesh,
                                     sigmaMap=self.physprops.wires.sigma,
                                     bc_type='Dirichlet',
                                     Solver=Solver)
        self._srcList = [
            DC.Src.Dipole([], self.src_a[i, :], self.src_b[i, :])
            for i in range(self.src_a.shape[0])
        ]
        # self._src = DC.Src.Dipole([], self.src_a, self.src_b)
        self._survey = DC.Survey(self._srcList)

        self._prob.pair(self._survey)
Exemplo n.º 20
0
def _getDipoleDipoleConfigurationSurvey(points):
    sources = []
    pb = points.shape[0]
    for ii in range(pb - 3):
        Apos = points[ii]
        Bpos = points[ii + 1]
        Mpos = points[ii + 2:-1]
        Npos = points[ii + 3:]
        if ii < pb - 4:
            Mpos = numpy.vstack([Mpos, points[pb - 3]])
            Npos = numpy.vstack([Npos, points[pb - 1]])
        receiver = DC.Rx.Dipole(Mpos, Npos)
        source = DC.Src.Dipole([receiver], Apos, Bpos)
        sources.append(source)
    survey = DC.Survey(sources)
    return survey
    pass
Exemplo n.º 21
0
    def setUp(self):

        aSpacing = 2.5
        nElecs = 10

        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 = DC.Survey(srcList)
        problem = DC.Problem3D_N(mesh,
                                 rhoMap=Maps.IdentityMap(mesh),
                                 storeJ=True)
        problem.pair(survey)

        mSynth = np.ones(mesh.nC)
        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
Exemplo n.º 22
0
    def setUp(self):

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

        x = mesh.vectorCCx[(mesh.vectorCCx > -155.) & (mesh.vectorCCx < 155.)]
        y = mesh.vectorCCx[(mesh.vectorCCy > -155.) & (mesh.vectorCCy < 155.)]
        Aloc = np.r_[-200., 0., 0.]
        Bloc = np.r_[200., 0., 0.]
        M = Utils.ndgrid(x - 25., y, np.r_[0.])
        N = Utils.ndgrid(x + 25., y, np.r_[0.])
        phiA = EM.Analytics.DCAnalyticHalf(Aloc, [M, N],
                                           1e-2,
                                           earth_type="halfspace")
        phiB = EM.Analytics.DCAnalyticHalf(Bloc, [M, N],
                                           1e-2,
                                           earth_type="halfspace")
        data_anal = phiA - phiB

        rx = DC.Rx.Dipole(M, N)
        src = DC.Src.Dipole([rx], Aloc, Bloc)
        survey = DC.Survey([src])

        self.survey = survey
        self.mesh = mesh
        self.sigma = sigma
        self.data_anal = data_anal

        try:
            from pymatsolver import MumpsSolver
            self.Solver = MumpsSolver
        except ImportError, e:
            self.Solver = SolverLU
Exemplo n.º 23
0
def getSensitivity(survey, A, B, M, N, model):

    if (survey == "Dipole-Dipole"):
        rx = DC.Rx.Dipole(np.r_[M, 0.], np.r_[N, 0.])
        src = DC.Src.Dipole([rx], np.r_[A, 0.], np.r_[B, 0.])
    elif (survey == "Pole-Dipole"):
        rx = DC.Rx.Dipole(np.r_[M, 0.], np.r_[N, 0.])
        src = DC.Src.Pole([rx], np.r_[A, 0.])
    elif (survey == "Dipole-Pole"):
        rx = DC.Rx.Pole(np.r_[M, 0.])
        src = DC.Src.Dipole([rx], np.r_[A, 0.], np.r_[B, 0.])
    elif (survey == "Pole-Pole"):
        rx = DC.Rx.Pole(np.r_[M, 0.])
        src = DC.Src.Pole([rx], np.r_[A, 0.])

    Srv = DC.Survey([src])
    problem = DC.Problem3D_CC(mesh, sigmaMap=sigmaMap)
    problem.Solver = SolverLU
    problem.pair(Srv)
    fieldObj = problem.fields(model)

    J = problem.Jtvec(model, np.array([1.]), f=fieldObj)

    return J
Exemplo n.º 24
0
                                 n=8)

# Line 3
xmin, xmax = -15., 15.
ymin, ymax = -5., -5.
zmin, zmax = 0, 0
endl = np.array([[xmin, ymin, zmin], [xmax, ymax, zmax]])
survey3 = DCUtils.gen_DCIPsurvey(endl,
                                 "dipole-dipole",
                                 dim=mesh.dim,
                                 a=3,
                                 b=3,
                                 n=8)

# Concatenate lines
survey = DC.Survey(survey1.srcList + survey2.srcList + survey3.srcList)

# Setup Problem with exponential mapping and Active cells only in the core mesh
expmap = Maps.ExpMap(mesh)
mapactive = Maps.InjectActiveCells(mesh=mesh,
                                   indActive=actind,
                                   valInactive=-5.)
mapping = expmap * mapactive
problem = DC.Problem3D_CC(mesh, sigmaMap=mapping)
problem.pair(survey)
problem.Solver = Solver

survey.dpred(mtrue[actind])
survey.makeSyntheticData(mtrue[actind], std=0.05, force=True)

# Tikhonov Inversion
Exemplo n.º 25
0
            locB = np.r_[14. - 1., z]
            #M = np.c_[np.arange(locA[0]+1.,12.,2),np.ones(nSrc-i)*z]
            #N = np.c_[np.arange(locA[0]+3.,14.,2),np.ones(nSrc-i)*z]
            M = np.c_[np.arange(-12., 10 + 1, 2), np.ones(12) * z]
            N = np.c_[np.arange(-10., 12 + 1, 2), np.ones(12) * z]
            rx = DC.Rx.Dipole(M, N)
            src = DC.Src.Dipole([rx], locA, locB)
            srclist.append(src)
            #print "line2",locA,locB,"\n",[M,N],"\n"

            #rx = DC.Rx.Dipole(-M,-N)
            #src= DC.Src.Dipole([rx],-locA,-locB)
            #srclist.append(src)

mapping = Maps.ExpMap(mesh)
survey = DC.Survey(srclist)
problem = DC.Problem3D_CC(mesh, sigmaMap=mapping)
problem.pair(survey)
problem.Solver = PardisoSolver

survey.dpred(mtrue)
survey.makeSyntheticData(mtrue, std=0.05, force=True)

print '# of data: ', survey.dobs.shape

#Simple Inversion
regmesh = mesh
m0 = (-5.) * np.ones(mapping.nP)
dmis = DataMisfit.l2_DataMisfit(survey)
reg = Regularization.Tikhonov(regmesh)  #,mapping = mapping)#,indActive=actind)
reg.mref = m0
Exemplo n.º 26
0
            locB = np.r_[14. - 1., z]
            #M = np.c_[np.arange(locA[0]+1.,12.,2),np.ones(nSrc-i)*z]
            #N = np.c_[np.arange(locA[0]+3.,14.,2),np.ones(nSrc-i)*z]
            M = np.c_[np.arange(-12., 10 + 1, 2), np.ones(12) * z]
            N = np.c_[np.arange(-10., 12 + 1, 2), np.ones(12) * z]
            rx = DC.Rx.Dipole(M, N)
            src = DC.Src.Dipole([rx], locA, locB)
            srclist.append(src)
            #print "line2",locA,locB,"\n",[M,N],"\n"

            #rx = DC.Rx.Dipole(-M,-N)
            #src= DC.Src.Dipole([rx],-locA,-locB)
            #srclist.append(src)

mapping = Maps.ExpMap(mesh)
survey = DC.Survey(srclist)
problem = DC.Problem3D_CC(mesh, sigmaMap=mapping)
problem.pair(survey)
problem.Solver = PardisoSolver
survey.dobs = survey.dpred(mtrue)
survey.std = 0.05 * np.ones_like(survey.dobs)
survey.eps = 1e-5 * np.linalg.norm(survey.dobs)
dmisAll = DataMisfit.l2_DataMisfit(survey)

print '# of data: ', survey.dobs.shape


class SimultaneousSrc(DC.Src.BaseSrc):
    """
    Dipole source
    """
Exemplo n.º 27
0
def gen_DCIPsurvey(endl, mesh, surveyType, a, b, n):
    """
        Load in endpoints and survey specifications to generate Tx, Rx location
        stations.

        Assumes flat topo for now...

        Input:
        :param endl -> input endpoints [x1, y1, z1, x2, y2, z2]
        :object mesh -> SimPEG mesh object
        :switch surveyType -> "dipole-dipole" (dipole-dipole) | "pole-dipole" (pole-dipole) | 'gradient'
        : param a, n -> pole seperation, number of rx dipoles per tx

        Output:
        :param Tx, Rx -> List objects for each tx location
            Lines: P1x, P1y, P1z, P2x, P2y, P2z

        Created on Wed December 9th, 2015

        @author: dominiquef
        !! Require clean up to deal with DCsurvey
    """
    def xy_2_r(x1, x2, y1, y2):
        r = np.sqrt(np.sum((x2 - x1)**2 + (y2 - y1)**2))
        return r

    # Evenly distribute electrodes and put on surface
    # Mesure survey length and direction
    dl_len = xy_2_r(endl[0, 0], endl[1, 0], endl[0, 1], endl[1, 1])

    dl_x = (endl[1, 0] - endl[0, 0]) / dl_len
    dl_y = (endl[1, 1] - endl[0, 1]) / dl_len

    nstn = int(np.floor(dl_len / a))

    # Compute discrete pole location along line
    stn_x = endl[0, 0] + np.array(range(int(nstn))) * dl_x * a
    stn_y = endl[0, 1] + np.array(range(int(nstn))) * dl_y * a

    if mesh.dim == 2:
        ztop = mesh.vectorNy[-1]
        # Create line of P1 locations
        M = np.c_[stn_x, np.ones(nstn).T * ztop]
        # Create line of P2 locations
        N = np.c_[stn_x + a * dl_x, np.ones(nstn).T * ztop]

    elif mesh.dim == 3:
        ztop = mesh.vectorNz[-1]
        # Create line of P1 locations
        M = np.c_[stn_x, stn_y, np.ones(nstn).T * ztop]
        # Create line of P2 locations
        N = np.c_[stn_x + a * dl_x, stn_y + a * dl_y, np.ones(nstn).T * ztop]

    # Build list of Tx-Rx locations depending on survey type
    # Dipole-dipole: Moving tx with [a] spacing -> [AB a MN1 a MN2 ... a MNn]
    # Pole-dipole: Moving pole on one end -> [A a MN1 a MN2 ... MNn a B]
    SrcList = []

    if surveyType != 'gradient':

        for ii in range(0, int(nstn) - 1):

            if surveyType == 'dipole-dipole':
                tx = np.c_[M[ii, :], N[ii, :]]
            elif surveyType == 'pole-dipole':
                tx = np.c_[M[ii, :], M[ii, :]]
            else:
                raise Exception(
                    'The surveyType must be "dipole-dipole" or "pole-dipole"')

            # Rx.append(np.c_[M[ii+1:indx, :], N[ii+1:indx, :]])

            # Current elctrode seperation
            AB = xy_2_r(tx[0, 1], endl[1, 0], tx[1, 1], endl[1, 1])

            # Number of receivers to fit
            nstn = int(np.min([np.floor((AB - b) / a), n]))

            # Check if there is enough space, else break the loop
            if nstn <= 0:
                continue

            # Compute discrete pole location along line
            stn_x = N[ii, 0] + dl_x * b + np.array(range(int(nstn))) * dl_x * a
            stn_y = N[ii, 1] + dl_y * b + np.array(range(int(nstn))) * dl_y * a

            # Create receiver poles

            if mesh.dim == 3:
                # Create line of P1 locations
                P1 = np.c_[stn_x, stn_y, np.ones(nstn).T * ztop]
                # Create line of P2 locations
                P2 = np.c_[stn_x + a * dl_x, stn_y + a * dl_y,
                           np.ones(nstn).T * ztop]
                rxClass = DC.Rx.Dipole(P1, P2)

            elif mesh.dim == 2:
                # Create line of P1 locations
                P1 = np.c_[stn_x, np.ones(nstn).T * ztop]
                # Create line of P2 locations
                P2 = np.c_[stn_x + a * dl_x, np.ones(nstn).T * ztop]
                rxClass = DC.Rx.Dipole_ky(P1, P2)

            if surveyType == 'dipole-dipole':
                srcClass = DC.Src.Dipole([rxClass], M[ii, :], N[ii, :])
            elif surveyType == 'pole-dipole':
                srcClass = DC.Src.Pole([rxClass], M[ii, :])
            SrcList.append(srcClass)

    elif surveyType == 'gradient':

        # Gradient survey takes the "b" parameter to define the limits of a
        # square survey grid. The pole seperation within the receiver grid is
        # define the "a" parameter.

        # Get the edge limit of survey area
        min_x = endl[0, 0] + dl_x * b
        min_y = endl[0, 1] + dl_y * b

        max_x = endl[1, 0] - dl_x * b
        max_y = endl[1, 1] - dl_y * b

        # Define the size of the survey grid (square for now)
        box_l = np.sqrt((min_x - max_x)**2 + (min_y - max_y)**2)
        box_w = box_l / 2.

        nstn = int(np.floor(box_l / a))

        # Compute discrete pole location along line
        stn_x = min_x + np.array(range(int(nstn))) * dl_x * a
        stn_y = min_y + np.array(range(int(nstn))) * dl_y * a

        # Define number of cross lines
        nlin = int(np.floor(box_w / a))
        lind = range(-nlin, nlin + 1)

        npoles = int(nstn * len(lind))

        rx = np.zeros([npoles, 6])
        for ii in range(len(lind)):

            # Move station location to current survey line This is a
            # perpendicular move then line survey orientation, hence the y, x
            # switch
            lxx = stn_x - lind[ii] * a * dl_y
            lyy = stn_y + lind[ii] * a * dl_x

            M = np.c_[lxx, lyy, np.ones(nstn).T * ztop]
            N = np.c_[lxx + a * dl_x, lyy + a * dl_y, np.ones(nstn).T * ztop]
            rx[(ii * nstn):((ii + 1) * nstn), :] = np.c_[M, N]

            if mesh.dim == 3:
                rxClass = DC.Rx.Dipole(rx[:, :3], rx[:, 3:])
            elif mesh.dim == 2:
                M = M[:, [0, 2]]
                N = N[:, [0, 2]]
                rxClass = DC.Rx.Dipole_ky(rx[:, [0, 2]], rx[:, [3, 5]])
            srcClass = DC.Src.Dipole([rxClass], (endl[0, :]), (endl[1, :]))
        SrcList.append(srcClass)
    else:
        print(
            """surveyType must be either 'pole-dipole', 'dipole-dipole' or 'gradient'. """
        )

    survey = DC.Survey(SrcList)

    return survey
def DC2Dsurvey(mtrue, 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(mtrue, Mx)
                Nx = xr[i + 2:i + 2 + nmax]
                _, Nz = get_Surface(mtrue, Nx)

                M = np.c_[Mx, Mz]
                N = np.c_[Nx, Nz]
            else:
                Mx = xr[i + 1:ntx + 1]
                _, Mz = get_Surface(mtrue, Mx)
                Nx = xr[i + 2:i + 2 + nmax]
                _, Nz = get_Surface(mtrue, 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(mtrue, Mx)
                Nx = np.ones(nmax) * mesh.vectorCCx.max()
                _, Nz = get_Surface(mtrue, Nx)

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

            else:
                Mx = xr[i + 2:ntx + 2]
                _, Mz = get_Surface(mtrue, Mx)
                Nx = np.ones(ntx - i) * mesh.vectorCCx.max()
                _, Nz = get_Surface(mtrue, 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(mtrue, Mx)
                Nx = xr[i + 3:i + 3 + nmax]
                _, Nz = get_Surface(mtrue, Nx)
                M = np.c_[Mx, Mz]
                N = np.c_[Nx, Nz]

            else:
                Mx = xr[i + 2:len(xr) - 1]
                _, Mz = get_Surface(mtrue, Mx)
                Nx = xr[i + 3:len(xr)]
                _, Nz = get_Surface(mtrue, 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 = DC.Survey(txList)
    problem = DC.Problem3D_CC(mesh, sigmaMap=mapping)
    problem.pair(survey)

    return survey, xzlocs
def model_fields(A, B, mtrue, mhalf, mair, mover, whichprimary="overburden"):

    idA, surfaceA = get_Surface(mtrue, A)
    idB, surfaceB = get_Surface(mtrue, B)

    Mx = mesh.gridCC
    # Nx = np.empty(shape =(mesh.nC, 2))
    rx = DC.Rx.Pole(Mx)
    # rx = DC.Rx.Dipole(Mx, Nx)
    if B == []:
        src = DC.Src.Pole([rx], np.r_[A, surfaceA])
    else:
        src = DC.Src.Dipole([rx], np.r_[A, surfaceA], np.r_[B, surfaceB])
    # src = DC.Src.Dipole([rx], np.r_[A, 0.], np.r_[B, 0.])
    survey = DC.Survey([src])
    # survey = DC.Survey([src])
    # survey_prim = DC.Survey([src])
    survey_prim = DC.Survey([src])
    survey_air = DC.Survey([src])
    # problem = DC.Problem3D_CC(mesh, sigmaMap = mapping)
    problem = DC.Problem3D_CC(mesh, sigmaMap=mapping)
    # problem_prim = DC.Problem3D_CC(mesh, sigmaMap = mapping)
    problem_prim = DC.Problem3D_CC(mesh, sigmaMap=mapping)
    problem_air = DC.Problem3D_CC(mesh, sigmaMap=mapping)

    problem.Solver = SolverLU
    problem_prim.Solver = SolverLU
    problem_air.Solver = SolverLU

    problem.pair(survey)
    problem_prim.pair(survey_prim)
    problem_air.pair(survey_air)

    mesh.setCellGradBC("neumann")
    cellGrad = mesh.cellGrad
    faceDiv = mesh.faceDiv

    if whichprimary == "air":
        phi_primary = survey_prim.dpred(mair)
    elif whichprimary == "half":
        phi_primary = survey_prim.dpred(mhalf)
    elif whichprimary == "overburden":
        phi_primary = survey_prim.dpred(mover)
    e_primary = -cellGrad * phi_primary
    j_primary = problem_prim.MfRhoI * problem_prim.Grad * phi_primary
    q_primary = epsilon_0 * problem_prim.Vol * (faceDiv * e_primary)
    primary_field = {
        "phi": phi_primary,
        "e": e_primary,
        "j": j_primary,
        "q": q_primary
    }

    phi_total = survey.dpred(mtrue)
    e_total = -cellGrad * phi_total
    j_total = problem.MfRhoI * problem.Grad * phi_total
    q_total = epsilon_0 * problem.Vol * (faceDiv * e_total)
    total_field = {"phi": phi_total, "e": e_total, "j": j_total, "q": q_total}

    phi_air = survey.dpred(mair)
    e_air = -cellGrad * phi_air
    j_air = problem.MfRhoI * problem.Grad * phi_air
    q_air = epsilon_0 * problem.Vol * (faceDiv * e_air)
    air_field = {"phi": phi_air, "e": e_air, "j": j_air, "q": q_air}

    return src, primary_field, air_field, total_field
Exemplo n.º 30
0
def gen_DCIPsurvey(endl, survey_type, a, b, n, dim=3, d2flag='2.5D'):
    """
        Load in endpoints and survey specifications to generate Tx, Rx location
        stations.

        Assumes flat topo for now...

        Input:
        :param numpy.ndarray endl: input endpoints [x1, y1, z1, x2, y2, z2]
        :param discretize.BaseMesh mesh: discretize mesh object
        :param str survey_type: 'dipole-dipole' | 'pole-dipole' |
            'dipole-pole' | 'pole-pole' | 'gradient'
        :param int a: pole seperation
        :param int b: dipole separation
        :param int n: number of rx dipoles per tx
        :param str d2flag: choose for 2D mesh between a '2D' or a '2.5D' survey

        Output:
        :return SimPEG.EM.Static.DC.SurveyDC.Survey dc_survey: DC survey object
    """
    def xy_2_r(x1, x2, y1, y2):
        r = np.sqrt(np.sum((x2 - x1)**2. + (y2 - y1)**2.))
        return r

    # Evenly distribute electrodes and put on surface
    # Mesure survey length and direction
    dl_len = xy_2_r(endl[0, 0], endl[1, 0], endl[0, 1], endl[1, 1])

    dl_x = (endl[1, 0] - endl[0, 0]) / dl_len
    dl_y = (endl[1, 1] - endl[0, 1]) / dl_len

    nstn = int(np.floor(dl_len / a))

    # Compute discrete pole location along line
    stn_x = endl[0, 0] + np.array(range(int(nstn))) * dl_x * a
    stn_y = endl[0, 1] + np.array(range(int(nstn))) * dl_y * a

    if dim == 2:
        ztop = np.linspace(endl[0, 1], endl[0, 1], nstn)
        # Create line of P1 locations
        M = np.c_[stn_x, ztop]
        # Create line of P2 locations
        N = np.c_[stn_x + a * dl_x, ztop]

    elif dim == 3:
        stn_z = np.linspace(endl[0, 2], endl[0, 2], nstn)
        # Create line of P1 locations
        M = np.c_[stn_x, stn_y, stn_z]
        # Create line of P2 locations
        N = np.c_[stn_x + a * dl_x, stn_y + a * dl_y, stn_z]

    # Build list of Tx-Rx locations depending on survey type
    # Dipole-dipole: Moving tx with [a] spacing -> [AB a MN1 a MN2 ... a MNn]
    # Pole-dipole: Moving pole on one end -> [A a MN1 a MN2 ... MNn a B]
    SrcList = []

    if survey_type != 'gradient':

        for ii in range(0, int(nstn) - 1):

            if survey_type == 'dipole-dipole' or survey_type == 'dipole-pole':
                tx = np.c_[M[ii, :], N[ii, :]]
                # Current elctrode separation
                AB = xy_2_r(tx[0, 1], endl[1, 0], tx[1, 1], endl[1, 1])
            elif survey_type == 'pole-dipole' or survey_type == 'pole-pole':
                tx = np.r_[M[ii, :]]
                # Current elctrode separation
                AB = xy_2_r(tx[0], endl[1, 0], tx[1], endl[1, 1])
            else:
                raise Exception(
                    """survey_type must be 'dipole-dipole' | 'pole-dipole' |
                    'dipole-pole' | 'pole-pole'"""
                    " not {}".format(survey_type))

            # Rx.append(np.c_[M[ii+1:indx, :], N[ii+1:indx, :]])

            # Number of receivers to fit
            nstn = int(np.min([np.floor((AB - b) / a), n]))

            # Check if there is enough space, else break the loop
            if nstn <= 0:
                continue

            # Compute discrete pole location along line
            stn_x = N[ii, 0] + dl_x * b + np.array(range(int(nstn))) * dl_x * a
            stn_y = N[ii, 1] + dl_y * b + np.array(range(int(nstn))) * dl_y * a

            # Create receiver poles

            if dim == 3:
                stn_z = np.linspace(endl[0, 2], endl[0, 2], nstn)

                # Create line of P1 locations
                P1 = np.c_[stn_x, stn_y, stn_z]
                # Create line of P2 locations
                P2 = np.c_[stn_x + a * dl_x, stn_y + a * dl_y, stn_z]
                if survey_type == 'dipole-dipole' or survey_type == 'pole-dipole':
                    rxClass = DC.Rx.Dipole(P1, P2)
                elif survey_type == 'dipole-pole' or survey_type == 'pole-pole':
                    rxClass = DC.Rx.Pole(P1)

            elif dim == 2:
                ztop = np.linspace(endl[0, 1], endl[0, 1], nstn)
                # Create line of P1 locations
                P1 = np.c_[stn_x, np.ones(nstn).T * ztop]
                # Create line of P2 locations
                P2 = np.c_[stn_x + a * dl_x, np.ones(nstn).T * ztop]
                if survey_type == 'dipole-dipole' or survey_type == 'pole-dipole':
                    if d2flag == '2.5D':
                        rxClass = DC.Rx.Dipole_ky(P1, P2)
                    elif d2flag == '2D':
                        rxClass = DC.Rx.Dipole(P1, P2)
                elif survey_type == 'dipole-pole' or survey_type == 'pole-pole':
                    if d2flag == '2.5D':
                        rxClass = DC.Rx.Pole_ky(P1)
                    elif d2flag == '2D':
                        rxClass = DC.Rx.Pole(P1)

            if survey_type == 'dipole-dipole' or survey_type == 'dipole-pole':
                srcClass = DC.Src.Dipole([rxClass], M[ii, :], N[ii, :])
            elif survey_type == 'pole-dipole' or survey_type == 'pole-pole':
                srcClass = DC.Src.Pole([rxClass], M[ii, :])
            SrcList.append(srcClass)

    elif survey_type == 'gradient':

        # Gradient survey takes the "b" parameter to define the limits of a
        # square survey grid. The pole seperation within the receiver grid is
        # define the "a" parameter.

        # Get the edge limit of survey area
        min_x = endl[0, 0] + dl_x * b
        min_y = endl[0, 1] + dl_y * b

        max_x = endl[1, 0] - dl_x * b
        max_y = endl[1, 1] - dl_y * b

        # Define the size of the survey grid (square for now)
        box_l = np.sqrt((min_x - max_x)**2. + (min_y - max_y)**2.)
        box_w = box_l / 2.

        nstn = int(np.floor(box_l / a))

        # Compute discrete pole location along line
        stn_x = min_x + np.array(range(int(nstn))) * dl_x * a
        stn_y = min_y + np.array(range(int(nstn))) * dl_y * a

        # Define number of cross lines
        nlin = int(np.floor(box_w / a))
        lind = range(-nlin, nlin + 1)

        npoles = int(nstn * len(lind))

        rx = np.zeros([npoles, 6])
        for ii in range(len(lind)):

            # Move station location to current survey line This is a
            # perpendicular move then line survey orientation, hence the y, x
            # switch
            lxx = stn_x - lind[ii] * a * dl_y
            lyy = stn_y + lind[ii] * a * dl_x

            M = np.c_[lxx, lyy, np.ones(nstn).T * ztop]
            N = np.c_[lxx + a * dl_x, lyy + a * dl_y, np.ones(nstn).T * ztop]
            rx[(ii * nstn):((ii + 1) * nstn), :] = np.c_[M, N]

            if mesh.dim == 3:
                rxClass = DC.Rx.Dipole(rx[:, :3], rx[:, 3:])
            elif mesh.dim == 2:
                M = M[:, [0, 2]]
                N = N[:, [0, 2]]
                if d2flag == '2.5D':
                    rxClass = DC.Rx.Dipole_ky(rx[:, [0, 2]], rx[:, [3, 5]])
                elif d2flag == '2D':
                    rxClass = DC.Rx.Dipole(rx[:, [0, 2]], rx[:, [3, 5]])
            srcClass = DC.Src.Dipole([rxClass], (endl[0, :]), (endl[1, :]))
        SrcList.append(srcClass)
    else:
        raise Exception(
            """survey_type must be either 'pole-dipole', 'dipole-dipole',
            'dipole-pole','pole-pole' or 'gradient'"""
            " not {}".format(survey_type))
    if (d2flag == '2.5D') and (dim == 2):
        survey = DC.Survey_ky(SrcList)
    else:
        survey = DC.Survey(SrcList)

    return survey