Exemplo n.º 1
0
def Prism(dx, dy, dz, depth, pinc, pdec, npts2D, xylim, rx_h, View_elev,
          View_azim):
    #p = definePrism(dx, dy, dz, depth,pinc=pinc, pdec=pdec, susc = 1., Einc=90., Edec=0., Bigrf=1e-6)
    p = definePrism()
    p.dx, p.dy, p.dz, p.z0 = dx, dy, dz, -depth
    p.pinc, p.pdec = pinc, pdec

    srvy = MAG.survey()
    srvy.rx_h, srvy.npts2D, srvy.xylim = rx_h, npts2D, xylim

    # Create problem
    prob = MAG.problem()
    prob.prism = p
    prob.survey = srvy

    return plotObj3D(p, rx_h, View_elev, View_azim, npts2D, xylim,
                     profile="X"), prob
Exemplo n.º 2
0
def animate(ii):

    removePlt()
#ii=1
    if ii<18:
        dec = 90
        inc = 0. + ii*5.

    elif ii < 36:

        dec = 270.
        inc = 90. - (ii-18)*5.
        
    elif ii < 54:
        
        dec = 270.
        inc = 0.+ (ii-36)*5.
        
    else:
        
        dec = 90
        inc = 90. - (ii-54)*5.



    ax1.axis('equal')
    block_xyz = np.asarray([[-.2, -.2, .2, .2, 0],
                           [-.25, -.25, -.25, -.25, 0.5],
                           [-.2, .2, .2, -.2, 0]])*10.

    block_xyz[1][:] -=20.
    # rot = Utils.mkvc(Utils.dipazm_2_xyz(pinc, pdec))

    # xyz = Utils.rotatePointsFromNormals(block_xyz.T, np.r_[0., 1., 0.], rot,
    #                                     np.r_[p.xc, p.yc, p.zc])

    R = Utils.rotationMatrix(inc, dec)

    xyz = R.dot(block_xyz).T
    xyz[:,2] -= depth + dz/2.
    #print xyz
    # Face 1
    ax1.add_collection3d(Poly3DCollection([zip(xyz[:4, 0],
                                               xyz[:4, 1],
                                               xyz[:4, 2])], facecolors='b'))

    ax1.add_collection3d(Poly3DCollection([zip(xyz[[1, 2, 4], 0],
                                               xyz[[1, 2, 4], 1],
                                               xyz[[1, 2, 4], 2])], facecolors='b'))

    ax1.add_collection3d(Poly3DCollection([zip(xyz[[0, 1, 4], 0],
                                               xyz[[0, 1, 4], 1],
                                               xyz[[0, 1, 4], 2])], facecolors='b'))

    ax1.add_collection3d(Poly3DCollection([zip(xyz[[2, 3, 4], 0],
                                               xyz[[2, 3, 4], 1],
                                               xyz[[2, 3, 4], 2])], facecolors='b'))

    ax1.add_collection3d(Poly3DCollection([zip(xyz[[0, 3, 4], 0],
                                           xyz[[0, 3, 4], 1],
                                           xyz[[0, 3, 4], 2])], facecolors='b'))
    ax1.w_yaxis.set_ticklabels('')
    ax1.w_yaxis.set_label_text('')
    ax1.w_zaxis.set_ticklabels('')
    ax1.w_zaxis.set_label_text('')
#    block_xyz[1][:] +=20.
#    # rot = Utils.mkvc(Utils.dipazm_2_xyz(pinc, pdec))
#
#    # xyz = Utils.rotatePointsFromNormals(block_xyz.T, np.r_[0., 1., 0.], rot,
#    #                                     np.r_[p.xc, p.yc, p.zc])
#
#    R = Utils.rotationMatrix(rinc, rdec)
#
#    xyz = R.dot(block_xyz).T
#    xyz[:,2] -= depth + dz/2.
#
#    #print xyz
#    # Face 1
#    ax1.add_collection3d(Poly3DCollection([zip(xyz[:4, 0],
#                                               xyz[:4, 1],
#                                               xyz[:4, 2])], facecolors='y'))
#
#    ax1.add_collection3d(Poly3DCollection([zip(xyz[[1, 2, 4], 0],
#                                               xyz[[1, 2, 4], 1],
#                                               xyz[[1, 2, 4], 2])], facecolors='y'))
#
#    ax1.add_collection3d(Poly3DCollection([zip(xyz[[0, 1, 4], 0],
#                                               xyz[[0, 1, 4], 1],
#                                               xyz[[0, 1, 4], 2])], facecolors='y'))
#
#    ax1.add_collection3d(Poly3DCollection([zip(xyz[[2, 3, 4], 0],
#                                               xyz[[2, 3, 4], 1],
#                                               xyz[[2, 3, 4], 2])], facecolors='y'))
#
#    ax1.add_collection3d(Poly3DCollection([zip(xyz[[0, 3, 4], 0],
#                                           xyz[[0, 3, 4], 1],
#                                           xyz[[0, 3, 4], 2])], facecolors='y'))

    MAG.plotObj3D(p, rx_h, View_elev, View_azim, npts2D, xylim, profile="X", fig= fig, axs = ax1, plotSurvey=False)
    # Create problem
    prob = PFlocal.problem()
    prob.prism = p
    prob.survey = srvy

    prob.Bdec, prob.Binc, prob.Bigrf = dec, inc, Bigrf
    prob.Q, prob.rinc, prob.rdec = Q, rinc, rdec
    prob.uType, prob.mType = comp, 'total'
    prob.susc = susc

    # Compute fields from prism
    b_ind, b_rem = prob.fields()

    if irt == 'total':
        out = b_ind + b_rem

    elif irt == 'induced':
        out = b_ind

    else:
        out = b_rem

    #out = plogMagSurvey2D(prob, susc, Einc, Edec, Bigrf, x1, y1, x2, y2, comp, irt,  Q, rinc, rdec, fig=fig, axs1=ax2, axs2=ax3)

    #dat = axs1.contourf(X,Y, np.reshape(out, (X.shape)).T
    global im1
    im1 = ax1.contourf(X,Y,np.reshape(out, (X.shape)).T,20,zdir='z',offset=rx_h+5., clim=clim, vmin=clim[0],vmax=clim[1], cmap = 'RdBu_r')

    ax5 = fig.add_axes([pos.x0 , pos.y0+0.25,  pos.height*0.02, pos.height*0.4])
    cb = plt.colorbar(im1,cax=ax5, orientation="vertical", ax = ax1, ticks=np.linspace(im1.vmin,im1.vmax, 4), format="${%.0f}$")
    cb.set_label("$B^{TMI}\;(nT)$",size=12)
    cb.ax.yaxis.set_ticks_position('left')
    cb.ax.yaxis.set_label_position('left')

    global im5
    im5 = ax1.text(0,0,-60,'$B_0, I: ' + str(inc) + '^\circ, D: ' + str(dec) + '^\circ$', horizontalalignment='center')


    H0 = (Bigrf,inc,dec)


    actv = np.ones(mesh.nC)==1
    # Create active map to go from reduce space to full
    actvMap = Maps.InjectActiveCells(mesh, actv, -100)
    nC = len(actv)

    # Create a MAGsurvey
    rxLoc = np.c_[Utils.mkvc(X), Utils.mkvc(Y), Utils.mkvc(Z)]
    rxLoc = PF.BaseMag.RxObs(rxLoc)
    srcField = PF.BaseMag.SrcField([rxLoc],param = H0)
    survey = PF.BaseMag.LinearSurvey(srcField)

    # We can now create a susceptibility model and generate data
    # Lets start with a simple block in half-space
#    model = np.zeros((mesh.nCx,mesh.nCy,mesh.nCz))
#    model[(midx-2):(midx+2),(midy-2):(midy+2),-6:-2] = 0.02
#    model = mkvc(model)
#    model = model[actv]

    # Create active map to go from reduce set to full
    actvMap = Maps.InjectActiveCells(mesh, actv, -100)

    # Creat reduced identity map
    idenMap = Maps.IdentityMap(nP = nC)

    # Create the forward model operator
    probinv = PF.Magnetics.MagneticIntegral(mesh, mapping = idenMap, actInd = actv)

    # Pair the survey and problem
    survey.pair(probinv)

    # Compute linear forward operator and compute some data
#    d = probinv.fields(model)

    # Plot the model
#    m_true = actvMap * model
#    m_true[m_true==-100] = np.nan
    #plt.figure()
    #ax = plt.subplot(212)
    #mesh.plotSlice(m_true, ax = ax, normal = 'Y', ind=midy, grid=True, clim = (0., model.max()/3.), pcolorOpts={'cmap':'viridis'})
    #plt.title('A simple block model.')
    #plt.xlabel('x'); plt.ylabel('z')
    #plt.gca().set_aspect('equal', adjustable='box')

    # We can now generate data
    data = out + np.random.randn(len(out)) # We add some random Gaussian noise (1nT)
    wd = np.ones(len(data))*1. # Assign flat uncertainties

    # Create distance weights from our linera forward operator
    wr = np.sum(probinv.G**2.,axis=0)**0.5
    wr = ( wr/np.max(wr) )

    #survey.makeSyntheticData(data, std=0.01)
    survey.dobs= data
    survey.std = wd
    survey.mtrue = model

    # Create a regularization
    reg = Regularization.Sparse(mesh, indActive=actv, mapping=idenMap)
    reg.cell_weights = wr

    dmis = DataMisfit.l2_DataMisfit(survey)
    dmis.Wd = 1/wd

    # Add directives to the inversion
    opt = Optimization.ProjectedGNCG(maxIter=100 ,lower=0.,upper=1., maxIterLS = 20, maxIterCG= 10, tolCG = 1e-3)
    invProb = InvProblem.BaseInvProblem(dmis, reg, opt)
    betaest = Directives.BetaEstimate_ByEig()

    # Here is where the norms are applied
    # Use pick a treshold parameter empirically based on the distribution of model
    # parameters (run last cell to see the histogram before and after IRLS)
    IRLS = Directives.Update_IRLS( norms=([2,2,2,2]),  eps=(2e-3,2e-3), f_min_change = 1e-3, minGNiter=3,beta_tol=1e-2)
    update_Jacobi = Directives.Update_lin_PreCond()
    inv = Inversion.BaseInversion(invProb, directiveList=[IRLS,betaest,update_Jacobi])

    m0 = np.ones(nC)*1e-4

    mrec = inv.run(m0)

    # Here is the recovered susceptibility model
    ypanel = midx
    zpanel = -4
    m_l2 = actvMap * reg.l2model
    m_l2[m_l2==-100] = np.nan

    m_lp = actvMap * mrec
    m_lp[m_lp==-100] = np.nan

#    m_true = actvMap * model
#    m_true[m_true==-100] = np.nan

    #Plot L2 model
    #global im2

    xx, zz = mesh.gridCC[:,0].reshape(mesh.vnC, order="F"), mesh.gridCC[:,2].reshape(mesh.vnC, order="F")
    yy = mesh.gridCC[:,1].reshape(mesh.vnC, order="F")

    temp = m_lp.reshape(mesh.vnC, order='F')
    ptemp = temp[:,:,indz].T
    #ptemp = ma.array(ptemp ,mask=np.isnan(ptemp))
    global im2
    im2 = ax2.contourf(xx[:,:,indz].T,yy[:,:,indz].T,ptemp,20, vmin = vmin, vmax= vmax, clim=[vmin,vmax])
    ax2.plot(([mesh.vectorCCx[0],mesh.vectorCCx[-1]]),([mesh.vectorCCy[indy],mesh.vectorCCy[indy]]),color='w')
    ax2.set_aspect('equal')
    ax2.xaxis.set_visible(False)
    ax2.set_xlim(-60,60)
    ax2.set_ylim(-60,60)
    ax2.set_title('Induced Model')
    ax2.set_ylabel('Northing (m)',size=14)


    ptemp = temp[:,indy,:].T
    global im3
    im3 = ax3.contourf(xx[:,indy,:].T,zz[:,indy,:].T,ptemp,20, vmin = vmin, vmax= vmax, clim=[vmin,vmax])
    ax3.set_aspect('equal')
    ax3.set_xlim(-60,60)
    ax3.set_ylim(-60,0)
    ax3.set_title('EW Section')
    ax3.set_xlabel('Easting (m)',size=14)
    ax3.set_ylabel('Elevation (m)',size=14)


    ax4 = fig.add_axes([pos.x0 + 0.75, pos.y0+0.25,  pos.height*0.02, pos.height*0.4])
    cb = plt.colorbar(im3,cax=ax4, orientation="vertical", ax = ax1, ticks=np.linspace(im3.vmin,im3.vmax, 4), format="${%.3f}$")
    cb.set_label("Susceptibility (SI)",size=12)
Exemplo n.º 3
0
susc = 0.25

vmin, vmax = 0., 0.015

ax1.axis('equal')
ax1.set_title('Forward Simulation')
# Define the problem interactively
p = MAG.definePrism()
p.dx, p.dy, p.dz, p.z0 = dx, dy, dz, -depth
p.pinc, p.pdec = pinc, pdec

srvy = PFlocal.survey()
srvy.rx_h, srvy.npts2D, srvy.xylim = rx_h, npts2D, xylim

# Create problem
prob = PFlocal.problem()
prob.prism = p
prob.survey = srvy

X, Y = np.meshgrid(prob.survey.xr, prob.survey.yr)
Z = np.ones(X.shape)*rx_h
x, y = MAG.linefun(x1, x2, y1, y2, prob.survey.npts2D)
xyz_line = np.c_[x, y, np.ones_like(x)*prob.survey.rx_h]

# Create a mesh
dx    = 5.

hxind = [(dx,5,-1.3), (dx, 10), (dx,5,1.3)]
hyind = [(dx,5,-1.3), (dx, 10), (dx,5,1.3)]
hzind = [(dx,5,-1.3),(dx, 10)]
Exemplo n.º 4
0
def animate(ii):

    removePlt()
    #ii=1
    #inc = 45
    #dec = 90
    if ii < 18:
        dec = 90
        inc = 0. + ii * 5.

    elif ii < 36:

        dec = 270.
        inc = 90. - (ii - 18) * 5.

    elif ii < 54:

        dec = 270.
        inc = 0. + (ii - 36) * 5.

    else:

        dec = 90
        inc = 90. - (ii - 54) * 5.

    ax1.axis('equal')
    block_xyz = np.asarray([[-.2, -.2, .2, .2, 0], [
        -.25, -.25, -.25, -.25, 0.5
    ], [-.2, .2, .2, -.2, 0]]) * 10.

    block_xyz[1][:] -= 20.
    # rot = Utils.mkvc(Utils.dipazm_2_xyz(pinc, pdec))

    # xyz = Utils.rotatePointsFromNormals(block_xyz.T, np.r_[0., 1., 0.], rot,
    #                                     np.r_[p.xc, p.yc, p.zc])

    R = Utils.rotationMatrix(inc, dec)

    xyz = R.dot(block_xyz).T
    xyz[:, 2] -= depth + dz / 2.
    #print xyz
    # Face 1
    ax1.add_collection3d(
        Poly3DCollection([zip(xyz[:4, 0], xyz[:4, 1], xyz[:4, 2])],
                         facecolors='b'))

    ax1.add_collection3d(
        Poly3DCollection(
            [zip(xyz[[1, 2, 4], 0], xyz[[1, 2, 4], 1], xyz[[1, 2, 4], 2])],
            facecolors='b'))

    ax1.add_collection3d(
        Poly3DCollection(
            [zip(xyz[[0, 1, 4], 0], xyz[[0, 1, 4], 1], xyz[[0, 1, 4], 2])],
            facecolors='b'))

    ax1.add_collection3d(
        Poly3DCollection(
            [zip(xyz[[2, 3, 4], 0], xyz[[2, 3, 4], 1], xyz[[2, 3, 4], 2])],
            facecolors='b'))

    ax1.add_collection3d(
        Poly3DCollection(
            [zip(xyz[[0, 3, 4], 0], xyz[[0, 3, 4], 1], xyz[[0, 3, 4], 2])],
            facecolors='b'))

    block_xyz[1][:] += 20.
    # rot = Utils.mkvc(Utils.dipazm_2_xyz(pinc, pdec))

    # xyz = Utils.rotatePointsFromNormals(block_xyz.T, np.r_[0., 1., 0.], rot,
    #                                     np.r_[p.xc, p.yc, p.zc])

    R = Utils.rotationMatrix(rinc, rdec)

    xyz = R.dot(block_xyz).T
    xyz[:, 2] -= depth + dz / 2.

    #print xyz
    # Face 1
    ax1.add_collection3d(
        Poly3DCollection([zip(xyz[:4, 0], xyz[:4, 1], xyz[:4, 2])],
                         facecolors='y'))

    ax1.add_collection3d(
        Poly3DCollection(
            [zip(xyz[[1, 2, 4], 0], xyz[[1, 2, 4], 1], xyz[[1, 2, 4], 2])],
            facecolors='y'))

    ax1.add_collection3d(
        Poly3DCollection(
            [zip(xyz[[0, 1, 4], 0], xyz[[0, 1, 4], 1], xyz[[0, 1, 4], 2])],
            facecolors='y'))

    ax1.add_collection3d(
        Poly3DCollection(
            [zip(xyz[[2, 3, 4], 0], xyz[[2, 3, 4], 1], xyz[[2, 3, 4], 2])],
            facecolors='y'))

    ax1.add_collection3d(
        Poly3DCollection(
            [zip(xyz[[0, 3, 4], 0], xyz[[0, 3, 4], 1], xyz[[0, 3, 4], 2])],
            facecolors='y'))

    MAG.plotObj3D(p,
                  rx_h,
                  View_elev,
                  View_azim,
                  npts2D,
                  xylim,
                  profile="X",
                  fig=fig,
                  axs=ax1,
                  plotSurvey=False)

    ax1.w_yaxis.set_ticklabels('')
    ax1.w_yaxis.set_label_text('')
    ax1.w_zaxis.set_ticklabels('')
    ax1.w_zaxis.set_label_text('')

    # Create problem
    prob = PFlocal.problem()
    prob.prism = p
    prob.survey = srvy

    prob.Bdec, prob.Binc, prob.Bigrf = dec, inc, Bigrf
    prob.Q, prob.rinc, prob.rdec = Q, rinc, rdec
    prob.uType, prob.mType = 'tf', 'total'
    prob.susc = susc

    # Compute fields from prism
    b_ind, b_rem = prob.fields()
    out = b_ind + b_rem

    #out = plogMagSurvey2D(prob, susc, Einc, Edec, Bigrf, x1, y1, x2, y2, comp, irt,  Q, rinc, rdec, fig=fig, axs1=ax2, axs2=ax3)

    #dat = axs1.contourf(X,Y, np.reshape(out, (X.shape)).T
    global im1
    im1 = ax1.contourf(X,
                       Y,
                       np.reshape(out, (X.shape)).T,
                       20,
                       zdir='z',
                       offset=rx_h + 5.,
                       clim=clim,
                       vmin=clim[0],
                       vmax=clim[1],
                       cmap='RdBu_r')

    ax5 = fig.add_axes(
        [pos.x0, pos.y0 + 0.25, pos.height * 0.02, pos.height * 0.4])
    cb = plt.colorbar(im1,
                      cax=ax5,
                      orientation="vertical",
                      ax=ax1,
                      ticks=np.linspace(im1.vmin, im1.vmax, 4),
                      format="${%.0f}$")
    cb.set_label("$B^{TMI}\;(nT)$", size=12)
    cb.ax.yaxis.set_ticks_position('left')
    cb.ax.yaxis.set_label_position('left')

    global im5
    im5 = ax1.text(0,
                   0,
                   -60,
                   '$B_0, I: ' + str(inc) + '^\circ, D: ' + str(dec) +
                   '^\circ$',
                   horizontalalignment='center')

    H0 = (Bigrf, inc, dec)

    actv = np.ones(mesh.nC) == 1
    # Create active map to go from reduce space to full
    actvMap = Maps.InjectActiveCells(mesh, actv, -100)
    nC = len(actv)

    # Create a MAGsurvey
    rxLoc = np.c_[Utils.mkvc(X), Utils.mkvc(Y), Utils.mkvc(Z)]
    rxLoc = PF.BaseMag.RxObs(rxLoc)
    srcField = PF.BaseMag.SrcField([rxLoc], param=H0)
    survey = PF.BaseMag.LinearSurvey(srcField)

    # Create active map to go from reduce set to full
    actvMap = Maps.InjectActiveCells(mesh, actv, -100)

    # Creat reduced identity map
    idenMap = Maps.IdentityMap(nP=3 * nC)

    # Create the forward model operator
    #probinv = PF.Magnetics.MagneticIntegral(mesh, mapping = idenMap, actInd = actv)
    probinv = PF.Magnetics.MagneticVector(mesh, mapping=idenMap, actInd=actv)

    # Pair the survey and problem
    survey.pair(probinv)

    # We can now generate data
    data = out + np.random.randn(
        len(out))  # We add some random Gaussian noise (1nT)
    wd = np.ones(len(data)) * 1.  # Assign flat uncertainties

    # Create distance weights from our linera forward operator
    wr = np.sum(probinv.G**2., axis=0)**0.5
    wr = (wr / np.max(wr))

    #survey.makeSyntheticData(data, std=0.01)
    survey.dobs = data
    survey.std = wd
    survey.mtrue = model

    # Create a regularization
    reg = Regularization.Sparse(mesh,
                                indActive=actv,
                                mapping=idenMap,
                                nModels=3)
    reg.cell_weights = wr
    reg.mref = np.zeros(3 * nC)

    dmis = DataMisfit.l2_DataMisfit(survey)
    dmis.Wd = 1 / wd

    # Add directives to the inversion
    opt = Optimization.ProjectedGNCG(maxIter=100,
                                     lower=-1,
                                     upper=1.,
                                     maxIterLS=20,
                                     maxIterCG=10,
                                     tolCG=1e-3)
    invProb = InvProblem.BaseInvProblem(dmis, reg, opt)
    betaest = Directives.BetaEstimate_ByEig()

    # Here is where the norms are applied
    # Use pick a treshold parameter empirically based on the distribution of model
    # parameters (run last cell to see the histogram before and after IRLS)
    IRLS = Directives.Update_IRLS(norms=([2, 2, 2, 2]),
                                  eps=(1e-4, 1e-4),
                                  f_min_change=1e-2,
                                  minGNiter=3,
                                  beta_tol=1e-2)

    update_Jacobi = Directives.Update_lin_PreCond()

    inv = Inversion.BaseInversion(invProb,
                                  directiveList=[update_Jacobi, IRLS, betaest])

    mrec = inv.run(np.ones(3 * len(actv)) * 1e-4)

    # Here is the recovered susceptibility model
    ypanel = midx
    zpanel = -4
    m_lpx = actvMap * mrec[0:nC]
    m_lpy = actvMap * mrec[nC:2 * nC]
    m_lpz = actvMap * -mrec[2 * nC:]

    m_lpx[m_lpx == -100] = np.nan
    m_lpy[m_lpy == -100] = np.nan
    m_lpz[m_lpz == -100] = np.nan

    amp = np.sqrt(m_lpx**2. + m_lpy**2. + m_lpz**2.)

    m_lpx = (m_lpx / amp).reshape(mesh.vnC, order='F')
    m_lpy = (m_lpy / amp).reshape(mesh.vnC, order='F')
    m_lpz = (m_lpz / amp).reshape(mesh.vnC, order='F')
    amp = amp.reshape(mesh.vnC, order='F')
    sub = 2

    #    m_true = actvMap * model
    #    m_true[m_true==-100] = np.nan

    #Plot L2 model
    #    global im2

    xx, zz = mesh.gridCC[:, 0].reshape(
        mesh.vnC, order="F"), mesh.gridCC[:, 2].reshape(mesh.vnC, order="F")
    yy = mesh.gridCC[:, 1].reshape(mesh.vnC, order="F")

    #ptemp = ma.array(ptemp ,mask=np.isnan(ptemp))
    global im2
    im2 = ax2.contourf(xx[:, :, zpanel].T,
                       yy[:, :, zpanel].T,
                       amp[:, :, zpanel].T,
                       40,
                       vmin=vmin,
                       vmax=vmax,
                       clim=[vmin, vmax])
    global im4
    im4 = ax2.quiver(mkvc(xx[::sub, ::sub, zpanel].T),
                     mkvc(yy[::sub, ::sub, zpanel].T),
                     mkvc(m_lpx[::sub, ::sub, zpanel].T),
                     mkvc(m_lpy[::sub, ::sub, zpanel].T),
                     pivot='mid',
                     units="xy",
                     scale=0.2,
                     linewidths=(1, ),
                     edgecolors=('k'),
                     headaxislength=0.1,
                     headwidth=10,
                     headlength=30)
    ax2.set_aspect('equal')
    ax2.xaxis.set_visible(False)
    ax2.set_xlim(-60, 60)
    ax2.set_ylim(-60, 60)
    ax2.set_title('Effective Susceptibility')
    ax2.set_ylabel('Northing (m)', size=14)

    global im3
    im3 = ax3.contourf(xx[:, ypanel, :].T,
                       zz[:, ypanel, :].T,
                       amp[:, ypanel, :].T,
                       40,
                       vmin=vmin,
                       vmax=vmax,
                       clim=[vmin, vmax])

    global im6
    im6 = ax3.quiver(mkvc(xx[::sub, ypanel, ::sub].T),
                     mkvc(zz[::sub, ypanel, ::sub].T),
                     mkvc(m_lpx[::sub, ypanel, ::sub].T),
                     mkvc(m_lpz[::sub, ypanel, ::sub].T),
                     pivot='mid',
                     units="xy",
                     scale=0.2,
                     linewidths=(1, ),
                     edgecolors=('k'),
                     headaxislength=0.1,
                     headwidth=10,
                     headlength=30)
    ax3.set_aspect('equal')
    ax3.set_xlim(-60, 60)
    ax3.set_ylim(-60, 0)
    ax3.set_title('EW Section')
    ax3.set_xlabel('Easting (m)', size=14)
    ax3.set_ylabel('Elevation (m)', size=14)

    ax4 = fig.add_axes(
        [pos.x0 + 0.75, pos.y0 + 0.25, pos.height * 0.02, pos.height * 0.4])
    cb = plt.colorbar(im3,
                      cax=ax4,
                      orientation="vertical",
                      ax=ax1,
                      ticks=np.linspace(im3.vmin, im3.vmax, 4),
                      format="${%.3f}$")
    cb.set_label("$\kappa_{e}$ (SI)", size=12)
Exemplo n.º 5
0
def plotProfile(p, data, Binc, Bdec, Bigrf, susc, Q, rinc, rdec):
    if data is 'MonSt':
        filename = "data/StudentData2015_Monday.csv"
    elif data is 'WedSt':
        filename = "data/StudentData2015_Wednesday.csv"
    elif data is 'WedTA':
        filename = "data/TAData2015_Wednesday.csv"

    dat = pd.DataFrame(pd.read_csv(filename, header=0))
    tf = dat["Corrected Total Field Data (nT)"].values
    std = dat["Standard Deviation (nT)"].values
    loc = dat["Location (m)"].values
    teams = dat["Team"].values

    tfa = tf - Bigrf

    nx, ny = 100, 1
    shape = (nx, ny)
    xLoc = np.linspace(xlim[0], xlim[1], nx)

    zLoc = np.ones(np.shape(xLoc)) * rx_h
    yLoc = np.zeros(np.shape(xLoc))

    #xpl, ypl, zpl = fatiandoGridMesh.regular(surveyArea,shape, z=z)
    rxLoc = np.c_[Utils.mkvc(xLoc), Utils.mkvc(yLoc), Utils.mkvc(zLoc)]

    prob1D = MAG.problem()
    srvy1D = MAG.survey()
    srvy1D._rxLoc = rxLoc

    prob1D.prism = p
    prob1D.survey = srvy1D

    prob1D.Bdec, prob1D.Binc, prob1D.Bigrf = Bdec, Binc, Bigrf
    prob1D.Q, prob1D.rinc, prob1D.rdec = Q, rinc, rdec
    prob1D.uType, prob1D.mType = 'tf', 'total'
    prob1D.susc = susc

    # Compute fields from prism
    magi, magr = prob1D.fields()

    #out_linei, out_liner = getField(p, xyz_line, comp, 'total')
    #out_linei = getField(p, xyz_line, comp,'induced')
    #out_liner = getField(p, xyz_line, comp,'remanent')

    # distance = np.sqrt((x-x1)**2.+(y-y1)**2.)

    f = plt.figure(figsize=(10, 5))
    gs = gridspec.GridSpec(2, 1, height_ratios=[2, 1])

    ax0 = plt.subplot(gs[0])
    ax1 = plt.subplot(gs[1])

    ax1.plot(p.x0, p.z0, 'ko')
    ax1.text(p.x0 + 0.5, p.z0, 'Rebar', color='k')
    ax1.text(xlim[0] + 1., -1.2, 'Magnetometer height (1.9 m)', color='b')
    ax1.plot(xlim, np.r_[-rx_h, -rx_h], 'b--')

    # magi,magr = getField(p, rxLoc, 'bz', 'total')

    ax1.plot(xlim, np.r_[0., 0.], 'k--')
    ax1.set_xlim(xlim)
    ax1.set_ylim(-2.5, 2.5)

    ax0.scatter(loc, tfa, c=teams)
    ax0.errorbar(loc, tfa, yerr=std, linestyle="None", color="k")
    ax0.set_xlim(xlim)
    ax0.grid(which="both")

    ax0.plot(xLoc, magi, 'b', label='induced')
    ax0.plot(xLoc, magr, 'r', label='remnant')
    ax0.plot(xLoc, magi + magr, 'k', label='total')
    ax0.legend(loc=2)
    # ax[1].plot(loc-8, magnT[::-1], )

    ax1.set_xlabel("Northing (m)")
    ax1.set_ylabel("Depth (m)")

    ax0.set_ylabel("Total field anomaly (nT)")

    ax0.grid(True)
    ax0.set_xlabel("Northing (m)")

    ax1.grid(True)
    ax1.set_xlabel("Northing (m)")

    ax1.invert_yaxis()

    plt.tight_layout()
    plt.show()

    return True
Exemplo n.º 6
0
def plogMagSurvey2D(prob2D,
                    susc,
                    Einc,
                    Edec,
                    Bigrf,
                    x1,
                    y1,
                    x2,
                    y2,
                    comp,
                    irt,
                    Q,
                    rinc,
                    rdec,
                    fig=None,
                    axs1=None,
                    axs2=None):

    import matplotlib.gridspec as gridspec

    # The MAG problem created is stored in result[1]
    # prob2D = Box.result[1]

    if fig is None:
        fig = plt.figure(figsize=(18 * 1.5, 3.4 * 1.5))

        plt.rcParams.update({'font.size': 14})
        gs1 = gridspec.GridSpec(2, 7)
        gs1.update(left=0.05, right=0.48, wspace=0.05)

    if axs1 is None:
        axs1 = plt.subplot(gs1[:2, :3])

    if axs2 is None:
        axs2 = plt.subplot(gs1[0, 4:])

    axs1.axis("equal")

    prob2D.Bdec, prob2D.Binc, prob2D.Bigrf = Edec, Einc, Bigrf
    prob2D.Q, prob2D.rinc, prob2D.rdec = Q, rinc, rdec
    prob2D.uType, prob2D.mType = comp, 'total'
    prob2D.susc = susc

    # Compute fields from prism
    b_ind, b_rem = prob2D.fields()

    if irt == 'total':
        out = b_ind + b_rem

    elif irt == 'induced':
        out = b_ind

    else:
        out = b_rem

    X, Y = np.meshgrid(prob2D.survey.xr, prob2D.survey.yr)

    dat = axs1.contourf(X, Y, np.reshape(out, (X.shape)).T, 25)
    cb = plt.colorbar(dat, ax=axs1, ticks=np.linspace(out.min(), out.max(), 5))
    cb.set_label("nT")

    axs1.plot(X, Y, '.k')

    # Compute fields on the line by creating a similar mag problem
    x, y = linefun(x1, x2, y1, y2, prob2D.survey.npts2D)
    xyz_line = np.c_[x, y, np.ones_like(x) * prob2D.survey.rx_h]
    # Create problem
    prob1D = MAG.problem()
    srvy1D = MAG.survey()
    srvy1D._rxLoc = xyz_line

    prob1D.prism = prob2D.prism
    prob1D.survey = srvy1D

    prob1D.Bdec, prob1D.Binc, prob1D.Bigrf = Edec, Einc, Bigrf
    prob1D.Q, prob1D.rinc, prob1D.rdec = Q, rinc, rdec
    prob1D.uType, prob1D.mType = comp, 'total'
    prob1D.susc = susc

    # Compute fields from prism
    out_linei, out_liner = prob1D.fields()

    #out_linei, out_liner = getField(p, xyz_line, comp, 'total')
    #out_linei = getField(p, xyz_line, comp,'induced')
    #out_liner = getField(p, xyz_line, comp,'remanent')

    out_linet = out_linei + out_liner

    distance = np.sqrt((x - x1)**2. + (y - y1)**2.)

    axs1.plot(x, y, 'w.', ms=3)

    axs1.text(x[0], y[0], 'A', fontsize=16, color='w')
    axs1.text(x[-1],
              y[-1],
              'B',
              fontsize=16,
              color='w',
              horizontalalignment='right')

    axs1.set_xlabel('Easting (X; m)')
    axs1.set_ylabel('Northing (Y; m)')
    axs1.set_xlim(X.min(), X.max())
    axs1.set_ylim(Y.min(), Y.max())
    axs1.set_title(irt + ' ' + comp)

    axs2.plot(distance, out_linei, 'b.-')
    axs2.plot(distance, out_liner, 'r.-')
    axs2.plot(distance, out_linet, 'k.-')
    axs2.set_xlim(distance.min(), distance.max())

    axs2.set_xlabel("Distance (m)")
    axs2.set_ylabel("Magnetic field (nT)")

    axs2.text(distance.min(), out_linei.max() * 0.8, 'A', fontsize=16)
    axs2.text(distance.max() * 0.97, out_linei.max() * 0.8, 'B', fontsize=16)
    axs2.legend(("induced", "remanent", "total"), bbox_to_anchor=(0.5, -0.3))
    axs2.grid(True)
    plt.show()

    return True