Exemple #1
0
def plot_pseudoSection(Tx,Rx,data,z0, stype):
    
    from SimPEG import np, mkvc
    from scipy.interpolate import griddata
    from matplotlib.colors import LogNorm
    import pylab as plt
    import re
    """
        Read list of 2D tx-rx location and plot a speudo-section of apparent
        resistivity.
        
        Assumes flat topo for now...
    
        Input:
        :param d2D, z0
        :switch stype -> Either 'pdp' (pole-dipole) | 'dpdp' (dipole-dipole)
    
        Output:
        :figure scatter plot overlayed on image
        
        Created on Mon December 7th, 2015
    
        @author: dominiquef
    
    """
    #d2D = np.asarray(d2D)
    
    midl = []
    midz = []
    rho = []
    
    for ii in range(len(Tx)):
        # Get distances between each poles
        rC1P1 = np.abs(Tx[ii][0] - Rx[ii][:,0]) 
        rC2P1 = np.abs(Tx[ii][1] - Rx[ii][:,0])
        rC1P2 = np.abs(Tx[ii][1] - Rx[ii][:,1])
        rC2P2 = np.abs(Tx[ii][0] - Rx[ii][:,1])
        rP1P2 = np.abs(Rx[ii][:,1] - Rx[ii][:,0])    
    
        # Compute apparent resistivity
        if re.match(stype,'pdp'):
            rho = np.hstack([rho, data[ii] * 2*np.pi  * rC1P1 * ( rC1P1 + rP1P2 ) / rP1P2] )
            
        elif re.match(stype,'dpdp'):
            rho = np.hstack([rho, data[ii] * 2*np.pi / ( 1/rC1P1 - 1/rC2P1 - 1/rC1P2 + 1/rC2P2 ) ])
    
        Cmid = (Tx[ii][0] + Tx[ii][1])/2
        Pmid = (Rx[ii][:,0] + Rx[ii][:,1])/2
    
        midl = np.hstack([midl, ( Cmid + Pmid )/2 ])
        midz = np.hstack([midz, -np.abs(Cmid-Pmid)/2 + z0 ])
    
   
    # Grid points
    grid_x, grid_z = np.mgrid[np.min(midl):np.max(midl), np.min(midz):np.max(midz)]
    grid_rho = griddata(np.c_[midl,midz], np.log10(abs(1/rho.T)), (grid_x, grid_z), method='linear')
    
    
    #plt.subplot(2,1,2)
    plt.imshow(grid_rho.T, extent = (np.min(midl),np.max(midl),np.min(midz),np.max(midz)), origin='lower', alpha=0.8)
    cbar = plt.colorbar(format = '%.2f',fraction=0.02)
    cmin,cmax = cbar.get_clim()
    ticks = np.linspace(cmin,cmax,3)
    cbar.set_ticks(ticks)
    
    # Plot apparent resistivity
    plt.scatter(midl,midz,s=50,c=np.log10(abs(1/rho.T)))
Exemple #2
0
def plot_pseudoSection(DCsurvey, axs, stype='dpdp', dtype="appc", clim=None):
    """
        Read list of 2D tx-rx location and plot a speudo-section of apparent
        resistivity.

        Assumes flat topo for now...

        Input:
        :param d2D, z0
        :switch stype -> Either 'pdp' (pole-dipole) | 'dpdp' (dipole-dipole)
        :switch dtype=-> Either 'appr' (app. res) | 'appc' (app. con) | 'volt' (potential)
        Output:
        :figure scatter plot overlayed on image

        Edited Feb 17th, 2016

        @author: dominiquef

    """
    from SimPEG import np
    from scipy.interpolate import griddata
    import pylab as plt

    # Set depth to 0 for now
    z0 = 0.

    # Pre-allocate
    midx = []
    midz = []
    rho = []
    LEG = []
    count = 0  # Counter for data
    for ii in range(DCsurvey.nSrc):

        Tx = DCsurvey.srcList[ii].loc
        Rx = DCsurvey.srcList[ii].rxList[0].locs

        nD = DCsurvey.srcList[ii].rxList[0].nD

        data = DCsurvey.dobs[count:count + nD]
        count += nD

        # Get distances between each poles A-B-M-N
        if stype == 'pdp':
            MA = np.abs(Tx[0] - Rx[0][:, 0])
            NA = np.abs(Tx[0] - Rx[1][:, 0])
            MN = np.abs(Rx[1][:, 0] - Rx[0][:, 0])

            # Create mid-point location
            Cmid = Tx[0]
            Pmid = (Rx[0][:, 0] + Rx[1][:, 0]) / 2
            if DCsurvey.mesh.dim == 2:
                zsrc = Tx[1]
            elif DCsurvey.mesh.dim == 3:
                zsrc = Tx[2]

        elif stype == 'dpdp':
            MA = np.abs(Tx[0][0] - Rx[0][:, 0])
            MB = np.abs(Tx[1][0] - Rx[0][:, 0])
            NA = np.abs(Tx[0][0] - Rx[1][:, 0])
            NB = np.abs(Tx[1][0] - Rx[1][:, 0])

            # Create mid-point location
            Cmid = (Tx[0][0] + Tx[1][0]) / 2
            Pmid = (Rx[0][:, 0] + Rx[1][:, 0]) / 2
            if DCsurvey.mesh.dim == 2:
                zsrc = (Tx[0][1] + Tx[1][1]) / 2
            elif DCsurvey.mesh.dim == 3:
                zsrc = (Tx[0][2] + Tx[1][2]) / 2

        # Change output for dtype
        if dtype == 'volt':

            rho = np.hstack([rho, data])

        else:

            # Compute pant leg of apparent rho
            if stype == 'pdp':

                leg = data * 2 * np.pi * MA * (MA + MN) / MN

            elif stype == 'dpdp':

                leg = data * 2 * np.pi / (1 / MA - 1 / MB + 1 / NB - 1 / NA)
                LEG.append(1. / (2 * np.pi) *
                           (1 / MA - 1 / MB + 1 / NB - 1 / NA))
            else:
                print """dtype must be 'pdp'(pole-dipole) | 'dpdp' (dipole-dipole) """
                break

            if dtype == 'appc':

                leg = np.log10(abs(1. / leg))
                rho = np.hstack([rho, leg])

            elif dtype == 'appr':

                leg = np.log10(abs(leg))
                rho = np.hstack([rho, leg])

            else:
                print """dtype must be 'appr' | 'appc' | 'volt' """
                break

        midx = np.hstack([midx, (Cmid + Pmid) / 2])
        if DCsurvey.mesh.dim == 3:
            midz = np.hstack([midz, -np.abs(Cmid - Pmid) / 2 + zsrc])
        elif DCsurvey.mesh.dim == 2:
            midz = np.hstack([midz, -np.abs(Cmid - Pmid) / 2 + zsrc])
    ax = axs

    # Grid points
    grid_x, grid_z = np.mgrid[np.min(midx):np.max(midx),
                              np.min(midz):np.max(midz)]
    grid_rho = griddata(np.c_[midx, midz],
                        rho.T, (grid_x, grid_z),
                        method='linear')

    if clim == None:
        vmin, vmax = rho.min(), rho.max()
    else:
        vmin, vmax = clim[0], clim[1]

    grid_rho = np.ma.masked_where(np.isnan(grid_rho), grid_rho)
    ph = plt.pcolormesh(grid_x[:, 0],
                        grid_z[0, :],
                        grid_rho.T,
                        clim=(vmin, vmax),
                        vmin=vmin,
                        vmax=vmax)
    cbar = plt.colorbar(format="$10^{%.1f}$",
                        fraction=0.04,
                        orientation="horizontal")

    cmin, cmax = cbar.get_clim()
    ticks = np.linspace(cmin, cmax, 3)
    cbar.set_ticks(ticks)
    cbar.ax.tick_params(labelsize=10)

    if dtype == 'appc':
        cbar.set_label("App.Cond", size=12)
    elif dtype == 'appr':
        cbar.set_label("App.Res.", size=12)
    elif dtype == 'volt':
        cbar.set_label("Potential (V)", size=12)

    # Plot apparent resistivity
    ax.scatter(midx,
               midz,
               s=10,
               c=rho.T,
               vmin=vmin,
               vmax=vmax,
               clim=(vmin, vmax))

    #ax.set_xticklabels([])
    #ax.set_yticklabels([])

    plt.gca().set_aspect('equal', adjustable='box')

    return ph, LEG
Exemple #3
0
def animate(ii):

    #for ii in range(1):
    removeFrame()
    # Grab current line and
    indx = np.where(lineID == ii)[0]

    srcLeft = []
    obs_l = []
    obs = []
    srcRight = []
    obs_r = []
    srcList = []
    # Split the obs file into left and right
    # Split the obs file into left and right
    for jj in range(len(indx)):

        # Grab corresponding data
        obs = np.hstack([obs, DCdobs2D.dobs[dataID == indx[jj]]])
        #std = dobs2D.std[dataID==indx[jj]]

        srcList.append(DCdobs2D.srcList[indx[jj]])

        Tx = DCdobs2D.srcList[indx[jj]].loc
        Rx = DCdobs2D.srcList[indx[jj]].rxList[0].locs

        # Create mid-point location
        Cmid = (Tx[0][0] + Tx[1][0]) / 2
        Pmid = (Rx[0][:, 0] + Rx[1][:, 0]) / 2

        ileft = Pmid < Cmid
        iright = Pmid >= Cmid

        temp = np.zeros(len(ileft))
        temp[ileft] = 1
        obs_l = np.hstack([obs_l, temp])

        temp = np.zeros(len(iright))
        temp[iright] = 1
        obs_r = np.hstack([obs_r, temp])

        if np.any(ileft):
            rx = DC.RxDipole(Rx[0][ileft, :], Rx[1][ileft, :])
            srcLeft.append(DC.SrcDipole([rx], Tx[0], Tx[1]))

            #std_l = np.hstack([std_l,std[ileft]])

        if np.any(iright):
            rx = DC.RxDipole(Rx[0][iright, :], Rx[1][iright, :])
            srcRight.append(DC.SrcDipole([rx], Tx[0], Tx[1]))

            #obs_r = np.hstack([obs_r,iright])
            #std_r = np.hstack([std_r,std[iright]])

    DC2D_full = DC.SurveyDC(srcList)
    DC2D_full.dobs = np.asarray(obs)
    DC2D_full.std = DC2D_full.dobs * 0.
    DC2D_full.std[obs_l ==
                  1] = np.abs(DC2D_full.dobs[obs_l == 1]) * 0.02 + 2e-5
    DC2D_full.std[obs_r ==
                  1] = np.abs(DC2D_full.dobs[obs_r == 1]) * 0.06 + 4e-5

    #    DC2D_l = DC.SurveyDC(srcLeft)
    #    DC2D_l.dobs = np.asarray(obs[obs_l==1])
    #    DC2D_l.std = np.abs(np.asarray(DC2D_l.dobs))*0.05 + 2e-5
    #
    #    DC2D_r = DC.SurveyDC(srcRight)
    #    DC2D_r.dobs = np.asarray(obs[obs_r==1])
    #    DC2D_r.std = np.abs(np.asarray(DC2D_r.dobs))*0.05 + 2e-5

    survey = DC2D_full

    # Export data file
    DC.writeUBC_DCobs(inv_dir + dsep + obsfile2d, survey, '2D', 'SIMPLE')

    # Write input file
    fid = open(inv_dir + dsep + inp_file, 'w')
    fid.write('OBS LOC_X %s \n' % obsfile2d)
    fid.write('MESH FILE %s \n' % mshfile2d)
    fid.write('CHIFACT 1 \n')
    fid.write('TOPO DEFAULT \n')
    fid.write('INIT_MOD VALUE %e\n' % ini_mod)
    fid.write('REF_MOD VALUE %e\n' % ref_mod)
    fid.write('ALPHA VALUE %f %f %F\n' % (1. / dx**4., 1, 1))
    fid.write('WEIGHT DEFAULT\n')
    fid.write('STORE_ALL_MODELS FALSE\n')
    fid.write('INVMODE CG\n')
    #fid.write('CG_PARAM 200 1e-4\n')
    fid.write('USE_MREF FALSE\n')
    #fid.write('BOUNDS VALUE 1e-4 1e+2\n')
    fid.close()

    os.chdir(inv_dir)
    os.system('dcinv2d ' + inp_file)

    #%% Load DC model and predicted data
    minv = DC.readUBC_DC2DModel(inv_dir + dsep + 'dcinv2d.con')
    minv = np.reshape(minv, (mesh2d.nCy, mesh2d.nCx))

    #%% Repeat for IP data
    indx = np.where(IPlineID == ii)[0]

    srcLeft = []
    obs_l = []
    std_l = []

    srcRight = []
    obs_r = []
    std_r = []

    obs_full = []
    std_full = []
    srcList = []

    # Split the obs file into left and right
    for jj in range(len(indx)):

        srcList.append(IPdobs2D.srcList[indx[jj]])
        # Grab corresponding data
        obs = IPdobs2D.dobs[IPdataID == indx[jj]]
        std = IPdobs2D.std[IPdataID == indx[jj]]

        obs_full = np.hstack([obs_full, obs])
        std_full = np.hstack([std_full, std])

        Tx = IPdobs2D.srcList[indx[jj]].loc
        Rx = IPdobs2D.srcList[indx[jj]].rxList[0].locs

        # Create mid-point location
        Cmid = (Tx[0][0] + Tx[1][0]) / 2
        Pmid = (Rx[0][:, 0] + Rx[1][:, 0]) / 2

        ileft = Pmid < Cmid
        iright = Pmid >= Cmid

        temp = np.zeros(len(ileft))
        temp[ileft] = 1
        obs_l = np.hstack([obs_l, temp])

        temp = np.zeros(len(iright))
        temp[iright] = 1
        obs_r = np.hstack([obs_r, temp])

        if np.any(ileft):
            rx = DC.RxDipole(Rx[0][ileft, :], Rx[1][ileft, :])
            srcLeft.append(DC.SrcDipole([rx], Tx[0], Tx[1]))

            #std_l = np.hstack([std_l,std[ileft]])

        if np.any(iright):
            rx = DC.RxDipole(Rx[0][iright, :], Rx[1][iright, :])
            srcRight.append(DC.SrcDipole([rx], Tx[0], Tx[1]))

    IP2D_full = DC.SurveyDC(srcList)
    IP2D_full.dobs = np.asarray(obs_full)
    IP2D_full.std = np.asarray(std_full)

    IP2D_l = DC.SurveyDC(srcLeft)
    IP2D_l.dobs = np.asarray(obs_full[obs_l == 1])
    #IP2D_l.std = np.abs(np.asarray(obs_l))*0.03 + 2e-2

    IP2D_r = DC.SurveyDC(srcRight)
    IP2D_r.dobs = np.asarray(obs_full[obs_r == 1])
    #IP2D_r.std = np.abs(np.asarray(obs_r))*0.03 + 1e-2

    id_lbe = int(IPsurvey.srcList[indx[jj]].loc[0][1])

    mesh3d = Mesh.TensorMesh([hx, np.ones(1) * 100., hz],
                             x0=(-np.sum(padx) + np.min(srcMat[0][:, 0]),
                                 id_lbe - 50,
                                 np.max(srcMat[0][0, 2]) - np.sum(hz)))
    Mesh.TensorMesh.writeUBC(mesh3d,
                             home_dir + dsep + 'Mesh' + str(id_lbe) + '.msh')
    global ax1, ax2, ax3, ax5, ax6, fig

    ax2 = plt.subplot(3, 2, 2)
    ph = DC.plot_pseudoSection(IP2D_r,
                               ax2,
                               stype='pdp',
                               dtype='volt',
                               colorbar=False)
    ax2.set_title('Observed P-DP', fontsize=10)
    plt.xlim([xmin, xmax])
    plt.ylim([zmin, zmax])
    plt.gca().set_aspect('equal', adjustable='box')
    ax2.set_xticklabels([])
    ax2.set_yticklabels([])

    ax1 = plt.subplot(3, 2, 1)
    DC.plot_pseudoSection(IP2D_l,
                          ax1,
                          stype='pdp',
                          dtype='volt',
                          clim=(ph[0].get_clim()[0], ph[0].get_clim()[1]),
                          colorbar=False)
    ax1.set_title('Observed DP-P', fontsize=10)
    plt.xlim([xmin, xmax])
    plt.ylim([zmin, zmax])
    plt.gca().set_aspect('equal', adjustable='box')
    ax1.set_xticklabels([])
    z = np.linspace(np.min(ph[2]), np.max(ph[2]), 5)
    z_label = np.linspace(20, 1, 5)
    ax1.set_yticks(map(int, z))
    ax1.set_yticklabels(map(str, map(int, z_label)), size=8)
    ax1.set_ylabel('n-spacing', fontsize=8)

    #%% Add labels
    bbox_props = dict(boxstyle="circle,pad=0.3", fc="r", ec="k", lw=1)
    ax2.text(0.00,
             1,
             'A',
             transform=ax2.transAxes,
             ha="left",
             va="center",
             size=6,
             bbox=bbox_props)

    bbox_props = dict(boxstyle="circle,pad=0.3", fc="y", ec="k", lw=1)
    ax2.text(0.1,
             1,
             'M',
             transform=ax2.transAxes,
             ha="left",
             va="center",
             size=6,
             bbox=bbox_props)

    bbox_props = dict(boxstyle="circle,pad=0.3", fc="g", ec="k", lw=1)
    ax2.text(0.2,
             1,
             'N',
             transform=ax2.transAxes,
             ha="left",
             va="center",
             size=6,
             bbox=bbox_props)

    bbox_props = dict(boxstyle="circle,pad=0.3", fc="g", ec="k", lw=1)
    ax1.text(0.00,
             1,
             'N',
             transform=ax1.transAxes,
             ha="left",
             va="center",
             size=6,
             bbox=bbox_props)

    bbox_props = dict(boxstyle="circle,pad=0.3", fc="y", ec="k", lw=1)
    ax1.text(0.1,
             1,
             'M',
             transform=ax1.transAxes,
             ha="left",
             va="center",
             size=6,
             bbox=bbox_props)

    bbox_props = dict(boxstyle="circle,pad=0.3", fc="r", ec="k", lw=1)
    ax1.text(0.2,
             1,
             'A',
             transform=ax1.transAxes,
             ha="left",
             va="center",
             size=6,
             bbox=bbox_props)

    survey = IP2D_full

    # Export data file
    DC.writeUBC_DCobs(inv_dir + dsep + ipfile2d,
                      survey,
                      '2D',
                      'SIMPLE',
                      iptype=1)

    fid = open(inv_dir + dsep + inp_file, 'w')
    fid.write('OBS LOC_X %s \n' % ipfile2d)
    fid.write('MESH FILE %s \n' % mshfile2d)
    fid.write('CHIFACT 4 \n')
    fid.write('COND FILE dcinv2d.con\n')
    fid.write('TOPO DEFAULT \n')
    fid.write('INIT_MOD VALUE %e\n' % ini_mod)
    fid.write('REF_MOD VALUE 0.0\n')
    fid.write('ALPHA VALUE %f %f %F\n' % (1. / dx**4., 1, 1))
    fid.write('WEIGHT DEFAULT\n')
    fid.write('STORE_ALL_MODELS FALSE\n')
    fid.write('INVMODE CG\n')
    #fid.write('CG_PARAM 200 1e-4\n')
    fid.write('USE_MREF FALSE\n')
    #fid.write('BOUNDS VALUE 1e-4 1e+2\n')
    fid.close()

    os.chdir(inv_dir)
    os.system('ipinv2d ' + inp_file)

    #%% Load model and predicted data
    minv = DC.readUBC_DC2DModel(inv_dir + dsep + 'ipinv2d.chg')
    minv = np.reshape(minv, (mesh2d.nCy, mesh2d.nCx))

    Mesh.TensorMesh.writeModelUBC(
        mesh3d, home_dir + dsep + 'Model' + str(id_lbe) + '.chg', minv.T)

    dpre = DC.readUBC_DC2Dpre(inv_dir + dsep + 'ipinv2d.pre')
    DCpre = dpre['DCsurvey']

    DCtemp = IP2D_l
    DCtemp.dobs = DCpre.dobs[obs_l == 1]

    ax5 = plt.subplot(3, 2, 3)
    DC.plot_pseudoSection(DCtemp,
                          ax5,
                          stype='pdp',
                          dtype='volt',
                          clim=(ph[0].get_clim()[0], ph[0].get_clim()[1]),
                          colorbar=False)
    ax5.set_title('Predicted', fontsize=10)
    plt.xlim([xmin, xmax])
    plt.ylim([zmin, zmax])
    plt.gca().set_aspect('equal', adjustable='box')
    ax5.set_xticklabels([])
    z = np.linspace(np.min(ph[2]), np.max(ph[2]), 5)
    z_label = np.linspace(20, 1, 5)
    ax5.set_yticks(map(int, z))
    ax5.set_yticklabels(map(str, map(int, z_label)), size=8)
    ax5.set_ylabel('n-spacing', fontsize=8)

    DCtemp = IP2D_r
    DCtemp.dobs = DCpre.dobs[obs_r == 1]

    ax6 = plt.subplot(3, 2, 4)
    DC.plot_pseudoSection(DCtemp,
                          ax6,
                          stype='pdp',
                          dtype='volt',
                          clim=(ph[0].get_clim()[0], ph[0].get_clim()[1]),
                          colorbar=False)
    ax6.set_title('Predicted', fontsize=10)
    plt.xlim([xmin, xmax])
    plt.ylim([zmin, zmax])
    plt.gca().set_aspect('equal', adjustable='box')
    ax6.set_xticklabels([])
    ax6.set_yticklabels([])

    pos = ax6.get_position()
    cbarax = fig.add_axes([
        pos.x0 + 0.325, pos.y0 + 0.2, pos.width * 0.1, pos.height * 0.5
    ])  ## the parameters are the specified position you set
    cb = fig.colorbar(ph[0],
                      cax=cbarax,
                      orientation="vertical",
                      ax=ax6,
                      ticks=np.linspace(ph[0].get_clim()[0],
                                        ph[0].get_clim()[1], 4),
                      format="$10^{%.1f}$")
    cb.set_label("App. Charg.", size=8)

    ax3 = plt.subplot(3, 1, 3)
    ax3.set_title('2-D Model (S/m)', fontsize=10)
    ax3.set_xticks(map(int, x))
    ax3.set_xticklabels(map(str, map(int, x)))
    ax3.set_xlabel('Easting (m)', fontsize=8)
    ax3.set_yticks(map(int, z))
    ax3.set_yticklabels(map(str, map(int, z)), rotation='vertical')
    ax3.set_ylabel('Depth (m)', fontsize=8)

    plt.xlim([xmin, xmax])
    plt.ylim([zmin / 2, zmax])
    plt.gca().set_aspect('equal', adjustable='box')

    ph2 = plt.pcolormesh(mesh2d.vectorNx,
                         mesh2d.vectorNy, (minv),
                         vmin=vmin,
                         vmax=vmax)
    plt.gca().tick_params(axis='both', which='major', labelsize=8)

    plt.draw()

    for ss in range(survey.nSrc):
        Tx = survey.srcList[ss].loc[0]
        plt.scatter(Tx[0], mesh2d.vectorNy[-1] + 10, s=10)

    pos = ax3.get_position()
    ax3.set_position([pos.x0 + 0.025, pos.y0, pos.width, pos.height])
    pos = ax3.get_position()
    cbarax = fig.add_axes([
        pos.x0 + 0.65, pos.y0 + 0.01, pos.width * 0.05, pos.height * 0.75
    ])  ## the parameters are the specified position you set
    cb = fig.colorbar(ph2,
                      cax=cbarax,
                      orientation="vertical",
                      ax=ax3,
                      ticks=np.linspace(vmin, vmax, 4),
                      format="%4.1f")
    cb.set_label("Chargeability", size=8)

    pos = ax1.get_position()
    ax1.set_position([pos.x0 + 0.03, pos.y0, pos.width, pos.height])

    pos = ax5.get_position()
    ax5.set_position([pos.x0 + 0.03, pos.y0, pos.width, pos.height])

    pos = ax2.get_position()
    ax2.set_position([pos.x0 - 0.03, pos.y0, pos.width, pos.height])

    pos = ax6.get_position()
    ax6.set_position([pos.x0 - 0.03, pos.y0, pos.width, pos.height])

    #%% Add the extra

    bbox_props = dict(boxstyle="rarrow,pad=0.3", fc="w", ec="k", lw=2)
    ax2.text(0.01, (float(ii) + 1.) / (len(uniqueID) + 2),
             'N: ' + str(id_lbe),
             transform=fig.transFigure,
             ha="left",
             va="center",
             size=8,
             bbox=bbox_props)

    mrk_props = dict(boxstyle="square,pad=0.3", fc="w", ec="k", lw=2)
    ax2.text(0.01,
             0.9,
             'Line ID#',
             transform=fig.transFigure,
             ha="left",
             va="center",
             size=8,
             bbox=mrk_props)

    mrk_props = dict(boxstyle="square,pad=0.3", fc="b", ec="k", lw=2)

    for jj in range(len(uniqueID)):
        ax2.text(0.1, (float(jj) + 1.) / (len(uniqueID) + 2),
                 ".",
                 transform=fig.transFigure,
                 ha="right",
                 va="center",
                 size=8,
                 bbox=mrk_props)

    mrk_props = dict(boxstyle="square,pad=0.3", fc="r", ec="k", lw=2)

    ax2.text(0.1, (float(ii) + 1.) / (len(uniqueID) + 2),
             ".",
             transform=fig.transFigure,
             ha="right",
             va="center",
             size=8,
             bbox=mrk_props)
Exemple #4
0
def plot_pseudoSection(DCsurvey, axs, stype='dpdp', dtype="appc", clim=None):
    """
        Read list of 2D tx-rx location and plot a speudo-section of apparent
        resistivity.

        Assumes flat topo for now...

        Input:
        :param d2D, z0
        :switch stype -> Either 'pdp' (pole-dipole) | 'dpdp' (dipole-dipole)
        :switch dtype=-> Either 'appr' (app. res) | 'appc' (app. con) | 'volt' (potential)
        Output:
        :figure scatter plot overlayed on image

        Edited Feb 17th, 2016

        @author: dominiquef

    """
    from SimPEG import np
    from scipy.interpolate import griddata
    import pylab as plt

    # Set depth to 0 for now
    z0 = 0.

    # Pre-allocate
    midx = []
    midz = []
    rho = []
    LEG = []
    count = 0 # Counter for data
    for ii in range(DCsurvey.nSrc):

        Tx = DCsurvey.srcList[ii].loc
        Rx = DCsurvey.srcList[ii].rxList[0].locs

        nD = DCsurvey.srcList[ii].rxList[0].nD

        data = DCsurvey.dobs[count:count+nD]
        count += nD

        # Get distances between each poles A-B-M-N
        if stype == 'pdp':
            MA = np.abs(Tx[0] - Rx[0][:,0])
            NA = np.abs(Tx[0] - Rx[1][:,0])
            MN = np.abs(Rx[1][:,0] - Rx[0][:,0])

            # Create mid-point location
            Cmid = Tx[0]
            Pmid = (Rx[0][:,0] + Rx[1][:,0])/2
            if DCsurvey.mesh.dim == 2:
                zsrc = Tx[1]
            elif DCsurvey.mesh.dim ==3:
                zsrc = Tx[2]

        elif stype == 'dpdp':
            MA = np.abs(Tx[0][0] - Rx[0][:,0])
            MB = np.abs(Tx[1][0] - Rx[0][:,0])
            NA = np.abs(Tx[0][0] - Rx[1][:,0])
            NB = np.abs(Tx[1][0] - Rx[1][:,0])

            # Create mid-point location
            Cmid = (Tx[0][0] + Tx[1][0])/2
            Pmid = (Rx[0][:,0] + Rx[1][:,0])/2
            if DCsurvey.mesh.dim == 2:
                zsrc = (Tx[0][1] + Tx[1][1])/2
            elif DCsurvey.mesh.dim ==3:
                zsrc = (Tx[0][2] + Tx[1][2])/2

        # Change output for dtype
        if dtype == 'volt':

            rho = np.hstack([rho,data])

        else:

            # Compute pant leg of apparent rho
            if stype == 'pdp':

                leg =  data * 2*np.pi  * MA * ( MA + MN ) / MN

            elif stype == 'dpdp':

                leg = data * 2*np.pi / ( 1/MA - 1/MB + 1/NB - 1/NA )
                LEG.append(1./(2*np.pi) *( 1/MA - 1/MB + 1/NB - 1/NA ))
            else:
                print("""dtype must be 'pdp'(pole-dipole) | 'dpdp' (dipole-dipole) """)
                break


            if dtype == 'appc':

                leg = np.log10(abs(1./leg))
                rho = np.hstack([rho,leg])

            elif dtype == 'appr':

                leg = np.log10(abs(leg))
                rho = np.hstack([rho,leg])

            else:
                print("""dtype must be 'appr' | 'appc' | 'volt' """)
                break


        midx = np.hstack([midx, ( Cmid + Pmid )/2 ])
        if DCsurvey.mesh.dim==3:
            midz = np.hstack([midz, -np.abs(Cmid-Pmid)/2 + zsrc ])
        elif DCsurvey.mesh.dim==2:
            midz = np.hstack([midz, -np.abs(Cmid-Pmid)/2 + zsrc ])
    ax = axs

    # Grid points
    grid_x, grid_z = np.mgrid[np.min(midx):np.max(midx), np.min(midz):np.max(midz)]
    grid_rho = griddata(np.c_[midx,midz], rho.T, (grid_x, grid_z), method='linear')

    if clim == None:
        vmin, vmax = rho.min(), rho.max()
    else:
        vmin, vmax = clim[0], clim[1]

    grid_rho = np.ma.masked_where(np.isnan(grid_rho), grid_rho)
    ph = plt.pcolormesh(grid_x[:,0],grid_z[0,:],grid_rho.T, clim=(vmin, vmax), vmin=vmin, vmax=vmax)
    cbar = plt.colorbar(format="$10^{%.1f}$",fraction=0.04,orientation="horizontal")

    cmin,cmax = cbar.get_clim()
    ticks = np.linspace(cmin,cmax,3)
    cbar.set_ticks(ticks)
    cbar.ax.tick_params(labelsize=10)

    if dtype == 'appc':
        cbar.set_label("App.Cond",size=12)
    elif dtype == 'appr':
        cbar.set_label("App.Res.",size=12)
    elif dtype == 'volt':
        cbar.set_label("Potential (V)",size=12)

    # Plot apparent resistivity
    ax.scatter(midx,midz,s=10,c=rho.T, vmin =vmin, vmax = vmax, clim=(vmin, vmax))

    #ax.set_xticklabels([])
    #ax.set_yticklabels([])

    plt.gca().set_aspect('equal', adjustable='box')



    return ph, LEG
Exemple #5
0
def plot_pseudoSection(DCsurvey, axs, stype):
    """
        Read list of 2D tx-rx location and plot a speudo-section of apparent
        resistivity.

        Assumes flat topo for now...

        Input:
        :param d2D, z0
        :switch stype -> Either 'pdp' (pole-dipole) | 'dpdp' (dipole-dipole)

        Output:
        :figure scatter plot overlayed on image

        Edited Feb 17th, 2016

        @author: dominiquef

    """
    from SimPEG import np
    from scipy.interpolate import griddata
    import pylab as plt

    # Set depth to 0 for now
    z0 = 0.

    # Pre-allocate
    midx = []
    midz = []
    rho = []
    count = 0 # Counter for data
    for ii in range(DCsurvey.nSrc):

        Tx = DCsurvey.srcList[ii].loc
        Rx = DCsurvey.srcList[ii].rxList[0].locs

        nD = DCsurvey.srcList[ii].rxList[0].nD

        data = DCsurvey.dobs[count:count+nD]
        count += nD

        # Get distances between each poles A-B-M-N
        MA = np.abs(Tx[0][0] - Rx[0][:,0])
        MB = np.abs(Tx[1][0] - Rx[0][:,0])
        NB = np.abs(Tx[1][0] - Rx[1][:,0])
        NA = np.abs(Tx[0][0] - Rx[1][:,0])
        MN = np.abs(Rx[1][:,0] - Rx[0][:,0])

        # Create mid-point location
        Cmid = (Tx[0][0] + Tx[1][0])/2
        Pmid = (Rx[0][:,0] + Rx[1][:,0])/2

        # Compute pant leg of apparent rho
        if stype == 'pdp':
            leg =  data * 2*np.pi  * MA * ( MA + MN ) / MN

            leg = np.log10(abs(1/leg))

        elif stype == 'dpdp':
            leg = data * 2*np.pi / ( 1/MA - 1/MB - 1/NB + 1/NA )


        midx = np.hstack([midx, ( Cmid + Pmid )/2 ])
        midz = np.hstack([midz, -np.abs(Cmid-Pmid)/2 + z0 ])
        rho = np.hstack([rho,leg])


    ax = axs

    # Grid points
    grid_x, grid_z = np.mgrid[np.min(midx):np.max(midx), np.min(midz):np.max(midz)]
    grid_rho = griddata(np.c_[midx,midz], rho.T, (grid_x, grid_z), method='linear')


    plt.imshow(grid_rho.T, extent = (np.min(midx),np.max(midx),np.min(midz),np.max(midz)), origin='lower', alpha=0.8, vmin = np.min(rho), vmax = np.max(rho))
    cbar = plt.colorbar(format = '%.2f',fraction=0.04,orientation="horizontal")

    cmin,cmax = cbar.get_clim()
    ticks = np.linspace(cmin,cmax,3)
    cbar.set_ticks(ticks)

    # Plot apparent resistivity
    plt.scatter(midx,midz,s=50,c=rho.T)

    ax.set_xticklabels([])

    ax.set_ylabel('Z')
    ax.yaxis.tick_right()
    ax.yaxis.set_label_position('right')
    plt.gca().set_aspect('equal', adjustable='box')


    return ax
Exemple #6
0
    dataID[count:count + nD] = ii
    count += nD

# Find 2D data correspondance
IPdataID = np.zeros(IPdobs2D.nD)
count = 0
for ii in range(IPdobs2D.nSrc):
    nD = IPdobs2D.srcList[ii].rxList[0].nD
    IPdataID[count:count + nD] = ii
    count += nD

#
#%% Create dcin2d inversion files and run
dx = 20.

dl_len = np.max(srcMat[lineID == 0, 0, 0]) - np.min(srcMat[lineID == 0, 0, 0])
nc = np.ceil(dl_len / dx) + 10

padx = dx * np.power(1.4, range(1, padc))

# Creating padding cells
hx = np.r_[padx[::-1], np.ones(nc) * dx, padx]
hz = np.r_[padx[::-1], np.ones(int(nc / 5)) * dx]

# Create mesh with 0 coordinate centerer on the ginput points in cell center
mesh2d = Mesh.TensorMesh([hx, hz],
                         x0=(-np.sum(padx) + np.min(srcMat[0][:, 0]),
                             np.ceil(np.max(srcMat[0][0, 2])) - np.sum(hz)))

inv_dir = home_dir + '\Inv2D'
if not os.path.exists(inv_dir):
Exemple #7
0
                              actvMap * np.ones(len(actv)))

# Load in observation file
survey = PF.Magnetics.readUBCmagObs(obsfile)

rxLoc = survey.srcField.rxList[0].locs
d = None

#rxLoc[:,2] += 5 # Temporary change for test
ndata = rxLoc.shape[0]

#%% Subdivide the forward data locations into tiles
PF.Magnetics.plot_obs_2D(rxLoc)

xmin = np.min(rxLoc[:, 0])
xmax = np.max(rxLoc[:, 0])

ymin = np.min(rxLoc[:, 1])
ymax = np.max(rxLoc[:, 1])

var = np.c_[np.r_[xmin, ymin], np.r_[xmax, ymin], np.r_[xmin, ymax]]
var = np.c_[var.T, np.ones(3) * mesh.vectorCCz[-1]]

# First put a tile on both corners of the mesh
indx = Utils.closestPoints(mesh, var)
endl = np.c_[mesh.gridCC[indx, 0], mesh.gridCC[indx, 1]]

dx = np.median(mesh.hx)

# Add intermediate tiles until the min_Olap is respected
# First in the x-direction
Exemple #8
0
 def branchdepth(self):
     return np.max([node.branchdepth for node in self.children.flatten('F')])
Exemple #9
0
 def branchdepth(self):
     if self.isleaf:
         return self.depth
     else:
         return np.max([node.branchdepth for node in self.children.flatten('F')])
Exemple #10
0
    model = np.zeros(mesh.nC)
    model[indx] = chibkg

    Utils.meshutils.writeUBCTensorModel('VTKout' + str(ii) + '.dat', mesh,
                                        model)

    Utils.meshutils.writeUBCTensorMesh('Mesh_temp' + str(ii) + '.msh', mesh)

    start_time = tm.time()

    d_temp = PF.Magnetics.Intgrl_Fwr_Data(mesh, B, M, rxLoc, model, actv,
                                          'tmi')

    timer = (tm.time() - start_time)

    ddata = np.max(abs(d - d_temp))

    d = d_temp

    #%% Plot data
    plt.figure()
    ax = plt.subplot()
    plt.imshow(np.reshape(d, X.shape),
               interpolation="bicubic",
               extent=[xr.min(), xr.max(),
                       yr.min(), yr.max()],
               origin='lower')
    plt.clim(0, 25)
    plt.colorbar(fraction=0.02)
    plt.contour(X, Y, np.reshape(d, X.shape), 10)
    plt.scatter(X, Y, c=np.reshape(d, X.shape), s=20)
Exemple #11
0
    os.chdir(inv_dir)
    os.system('dcinv2d ' + inp_file)
    
    #%%
    #Load model
    minv = DC.readUBC_DC2DModel(inv_dir + dsep + 'dcinv2d.con')
    #plt.figure()
    axs = plt.subplot(2,1,2)
    
    plt.xlim([0,nc*dx])
    plt.ylim([mesh2d.vectorNy[-1]-dl_len/2,mesh2d.vectorNy[-1]])
    plt.gca().set_aspect('equal', adjustable='box')
    
    minv = np.reshape(minv,(mesh2d.nCy,mesh2d.nCx))
    plt.pcolormesh(mesh2d.vectorNx,mesh2d.vectorNy,np.log10(m2D),alpha=0.5, cmap='gray')
    plt.pcolormesh(mesh2d.vectorNx,mesh2d.vectorNy,np.log10(minv),alpha=0.5, clim=(np.min(np.log10(m2D)),np.max(np.log10(m2D))))
    cbar = plt.colorbar(format = '%.2f',fraction=0.02)
    cmin,cmax = cbar.get_clim()
    ticks = np.linspace(cmin,cmax,3)
    cbar.set_ticks(ticks)

#%% Othrwise it is a gradient array, plot surface of apparent resisitivty
elif re.match(stype,'gradient'):
    
    rC1P1 = np.sqrt( np.sum( (npm.repmat(Tx[0][0:2,0],Rx[0].shape[0], 1) - Rx[0][:,0:2])**2, axis=1 ))
    rC2P1 = np.sqrt( np.sum( (npm.repmat(Tx[0][0:2,1],Rx[0].shape[0], 1) - Rx[0][:,0:2])**2, axis=1 ))
    rC1P2 = np.sqrt( np.sum( (npm.repmat(Tx[0][0:2,0],Rx[0].shape[0], 1) - Rx[0][:,3:5])**2, axis=1 ))
    rC2P2 = np.sqrt( np.sum( (npm.repmat(Tx[0][0:2,1],Rx[0].shape[0], 1) - Rx[0][:,3:5])**2, axis=1 )) 
    
    rC1C2 = np.sqrt( np.sum( (npm.repmat(Tx[0][0:2,0]-Tx[0][0:2,1],Rx[0].shape[0], 1) )**2, axis=1 ))
    rP1P2 = np.sqrt( np.sum( (Rx[0][:,0:2] - Rx[0][:,3:5])**2, axis=1 ))