def run(plotIt=False): 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.RxDipole(xyz_rxP, xyz_rxN) src = DC.SrcDipole([rx], [-200, 0, -12.5], [+200, 0, -12.5]) survey = DC.SurveyDC([src]) problem = DC.ProblemDC_CC(mesh) problem.pair(survey) try: from pymatsolver import MumpsSolver problem.Solver = MumpsSolver except Exception, e: pass
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.RxDipole(np.c_[temp[:, 2] * aspacing, e, e], np.c_[temp[:, 3] * aspacing, e, e]) srctemp = DC.SrcDipole([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.SurveyDC(srcList) survey.dobs = DAT_src[:, -1] survey.height_water = height_water survey.height_dam = height_dam return survey
def test_IPforward(self): cs = 12.5 nc = 200 / cs + 1 hx = [(cs, 7, -1.3), (cs, nc), (cs, 7, 1.3)] hy = [(cs, 7, -1.3), (cs, int(nc / 2 + 1)), (cs, 7, 1.3)] hz = [(cs, 7, -1.3), (cs, int(nc / 2 + 1))] mesh = Mesh.TensorMesh([hx, hy, hz], 'CCN') sighalf = 1e-2 sigma = np.ones(mesh.nC) * sighalf p0 = np.r_[-50., 50., -50.] p1 = np.r_[50., -50., -150.] blk_ind = Utils.ModelBuilder.getIndicesBlock(p0, p1, mesh.gridCC) sigma[blk_ind] = 1e-3 eta = np.zeros_like(sigma) eta[blk_ind] = 0.1 sigmaInf = sigma.copy() sigma0 = sigma * (1 - eta) nElecs = 11 x_temp = np.linspace(-100, 100, nElecs) aSpacing = x_temp[1] - x_temp[0] y_temp = 0. xyz = Utils.ndgrid(x_temp, np.r_[y_temp], np.r_[0.]) srcList = DC.Utils.WennerSrcList(nElecs, aSpacing) survey = DC.SurveyDC(srcList) imap = Maps.IdentityMap(mesh) problem = DC.ProblemDC_CC(mesh, mapping=imap) try: from pymatsolver import MumpsSolver solver = MumpsSolver except ImportError, e: solver = SolverLU
def setUp(self): cs = 12.5 nc = 500 / cs + 1 hx = [(cs, 0, -1.3), (cs, nc), (cs, 0, 1.3)] hy = [(cs, 0, -1.3), (cs, int(nc / 2 + 1)), (cs, 0, 1.3)] hz = [(cs, 0, -1.3), (cs, int(nc / 2 + 1))] mesh = Mesh.TensorMesh([hx, hy, hz], 'CCN') sighalf = 1e-2 sigma = np.ones(mesh.nC) * sighalf p0 = np.r_[-50., 50., -50.] p1 = np.r_[50., -50., -150.] blk_ind = Utils.ModelBuilder.getIndicesBlock(p0, p1, mesh.gridCC) sigma[blk_ind] = 1e-3 eta = np.zeros_like(sigma) eta[blk_ind] = 0.1 nElecs = 5 x_temp = np.linspace(-250, 250, nElecs) aSpacing = x_temp[1] - x_temp[0] y_temp = 0. xyz = Utils.ndgrid(x_temp, np.r_[y_temp], np.r_[0.]) srcList = DC.Utils.WennerSrcList(nElecs, aSpacing) survey = DC.SurveyIP(srcList) imap = Maps.IdentityMap(mesh) problem = DC.ProblemIP(mesh, sigma=sigma, mapping=imap) problem.pair(survey) try: from pymatsolver import MumpsSolver problem.Solver = MumpsSolver except ImportError, e: problem.Solver = SolverLU
class IPforwardTests(unittest.TestCase): def test_IPforward(self): cs = 12.5 nc = 200 / cs + 1 hx = [(cs, 7, -1.3), (cs, nc), (cs, 7, 1.3)] hy = [(cs, 7, -1.3), (cs, int(nc / 2 + 1)), (cs, 7, 1.3)] hz = [(cs, 7, -1.3), (cs, int(nc / 2 + 1))] mesh = Mesh.TensorMesh([hx, hy, hz], 'CCN') sighalf = 1e-2 sigma = np.ones(mesh.nC) * sighalf p0 = np.r_[-50., 50., -50.] p1 = np.r_[50., -50., -150.] blk_ind = Utils.ModelBuilder.getIndicesBlock(p0, p1, mesh.gridCC) sigma[blk_ind] = 1e-3 eta = np.zeros_like(sigma) eta[blk_ind] = 0.1 sigmaInf = sigma.copy() sigma0 = sigma * (1 - eta) nElecs = 11 x_temp = np.linspace(-100, 100, nElecs) aSpacing = x_temp[1] - x_temp[0] y_temp = 0. xyz = Utils.ndgrid(x_temp, np.r_[y_temp], np.r_[0.]) srcList = DC.Utils.WennerSrcList(nElecs, aSpacing) survey = DC.SurveyDC(srcList) imap = Maps.IdentityMap(mesh) problem = DC.ProblemDC_CC(mesh, mapping=imap) try: from pymatsolver import MumpsSolver solver = MumpsSolver except ImportError, e: solver = SolverLU problem.Solver = solver problem.pair(survey) phi0 = survey.dpred(sigma0) phiInf = survey.dpred(sigmaInf) phiIP_true = phi0 - phiInf surveyIP = DC.SurveyIP(srcList) problemIP = DC.ProblemIP(mesh, sigma=sigma) problemIP.pair(surveyIP) problemIP.Solver = solver phiIP_approx = surveyIP.dpred(eta) err = np.linalg.norm(phiIP_true - phiIP_approx) / np.linalg.norm(phiIP_true) self.assertTrue(err < 0.02)
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.SurveyDC(srcList) problem = DC.ProblemDC_CC(mesh) 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
def WennerSrcList(nElecs, aSpacing, in2D=False, plotIt=False): import SimPEG.DCIP as DC elocs = np.arange(0,aSpacing*nElecs,aSpacing) elocs -= (nElecs*aSpacing - aSpacing)/2 space = 1 WENNER = np.zeros((0,),dtype=int) for ii in range(nElecs): for jj in range(nElecs): test = np.r_[jj,jj+space,jj+space*2,jj+space*3] if np.any(test >= nElecs): break WENNER = np.r_[WENNER, test] space += 1 WENNER = WENNER.reshape((-1,4)) if plotIt: for i, s in enumerate('rbkg'): plt.plot(elocs[WENNER[:,i]],s+'.') plt.show() # Create sources and receivers i = 0 if in2D: getLoc = lambda ii, abmn: np.r_[elocs[WENNER[ii,abmn]],0] else: getLoc = lambda ii, abmn: np.r_[elocs[WENNER[ii,abmn]],0, 0] srcList = [] for i in range(WENNER.shape[0]): rx = DC.RxDipole(getLoc(i,1),getLoc(i,2)) src = DC.SrcDipole([rx], getLoc(i,0),getLoc(i,3)) srcList += [src] return srcList
mod_file = 'Model_2D.con' obs_file = 'FWR_data3D.dat' dsep = '\\' # Forward solver slvr = 'BiCGStab' #'LU' # Preconditioner pcdr = 'Jacobi' #'Gauss-Seidel'# # Number of padding cells to remove from plotting padc = 15 # Load UBC mesh 2D mesh = DC.readUBC_DC2DMesh(home_dir + dsep + msh_file) # Load model model = DC.readUBC_DC2DModel(home_dir + dsep + mod_file) # load obs file dcfile = DC.readUBC_DC3Dobs(home_dir + dsep + obs_file) survey = dcfile['DCsurvey'] survey2D = DC.convertObs_DC3D_to_2D(survey, np.ones(survey.nSrc), 'Xloc') #%% Create system #Set boundary conditions mesh.setCellGradBC('neumann') Div = mesh.faceDiv Grad = mesh.cellGrad
def animate(ii): # Grab current line and indx = np.where(lineID==ii)[0] srcLeft = [] obs_l = [] std_l = [] srcRight = [] obs_r = [] std_r = [] # Split the obs file into left and right for jj in range(len(indx)): # Grab corresponding data obs = dobs2D.dobs[dataID==indx[jj]] std = dobs2D.std[dataID==indx[jj]] Tx = dobs2D.srcList[indx[jj]].loc Rx = dobs2D.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 if np.any(ileft): rx = DC.RxDipole(Rx[0][ileft,:],Rx[1][ileft,:]) srcLeft.append( DC.SrcDipole( [rx], Tx[0],Tx[1] ) ) obs_l = np.hstack([obs_l,obs[ileft]]) 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,obs[iright]]) std_r = np.hstack([std_r,std[iright]]) DC2D_l = DC.SurveyDC(srcLeft) DC2D_l.dobs = np.asarray(obs_l) DC2D_l.std = np.asarray(std_l) DC2D_r = DC.SurveyDC(srcRight) DC2D_r.dobs = np.asarray(obs_r) DC2D_r.std = np.asarray(std_r) removeFrame() #DC.plot_pseudoSection(dobs2D,lineID, np.r_[0,1],'pdp') id_lbe = int(DCsurvey.srcList[indx[jj]].loc[0][1]) global ax1, ax2, fig ax1 = plt.subplot(2,1,1) ph = DC.plot_pseudoSection(DC2D_l,ax1,stype = 'pdp', dtype = 'volt', colorbar=False) ax1.set_title('Observed DP-P', fontsize=10) ax1.set_xticklabels([]) plt.xlim([xmin,xmax]) plt.ylim([zmin,zmax]) plt.gca().set_aspect('equal', adjustable='box') 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 colorbar pos = ax1.get_position() cbarax = fig.add_axes([pos.x0 + 0.72 , pos.y0 + 0.05, pos.width*0.05, pos.height*0.5]) ## the parameters are the specified position you set cb = fig.colorbar(ph[0],cax=cbarax, orientation="vertical", ticks=np.linspace(ph[0].get_clim()[0],ph[0].get_clim()[1], 3), format="%4.1f") cb.set_label("App. Charg.",size=8) ax2 = plt.subplot(2,1,2) ph = DC.plot_pseudoSection(DC2D_r,ax2,stype = 'pdp', dtype = 'volt', colorbar=False, clim = (ph[0].get_clim()[0],ph[0].get_clim()[1])) pos = ax2.get_position() ax2.set_position([pos.x0 , pos.y0, pos.width, pos.height]) plt.xlim([xmin,xmax]) plt.ylim([zmin,zmax]) plt.gca().set_aspect('equal', adjustable='box') ax2.set_title('Observed P-DP', fontsize=10) ax2.set_xlabel('Easting (m)', fontsize=8) z = np.linspace(np.min(ph[2]),np.max(ph[2]), 5) z_label = np.linspace(20,1, 5) ax2.set_yticks(map(int, z)) ax2.set_yticklabels(map(str, map(int, z_label)),size=8) ax2.set_ylabel('n-spacing',fontsize=8) # Add colorbar pos = ax2.get_position() cbarax = fig.add_axes([pos.x0 + 0.72 , pos.y0 + 0.05, pos.width*0.05, pos.height*0.5]) ## the parameters are the specified position you set cb = fig.colorbar(ph[0],cax=cbarax, orientation="vertical", ticks=np.linspace(ph[0].get_clim()[0],ph[0].get_clim()[1], 3), format="%4.1f") cb.set_label("App. Charg.",size=8) 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) #ax2.labelsize(fontsize=10) #============================================================================== # ax2.annotate(str(id_lbe), xy=(0.0, float(ii)/len(uniqueID)), xycoords='figure fraction', # xytext=(0.01, float(ii)/len(uniqueID)), textcoords='figure fraction', # arrowprops=dict(facecolor='black'),rotation=90) #============================================================================== 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.125, (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.125, (float(ii)+1.)/(len(uniqueID)+2), ".", transform=fig.transFigure, ha="right", va="center", size=8, bbox=mrk_props)
def animate(ii): removeFrame2() global ax1, ax2, fig minv = mout[ii] dpre = dout[ii] #airind = minv==1e-8 #minv[airind] = np.nan ax1 = plt.subplot(1, 2, 1) ax1.set_title('2D Conductivity (S/m)', fontsize=10) plt.xlim([mesh2d.vectorNx[padc], mesh2d.vectorNx[-padc]]) plt.ylim([mesh2d.vectorNy[-1] - dl_len / 3, mesh2d.vectorNy[-1] + 60]) 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), vmin=-4, vmax=2) plt.gca().tick_params(axis='both', which='major', labelsize=8) ax1.yaxis.tick_right() cbar = plt.colorbar(format='%.2f', fraction=0.03, orientation="horizontal") cmin, cmax = cbar.get_clim() ticks = np.linspace(cmin, cmax, 3) cbar.set_ticks(ticks) cbar.ax.tick_params(labelsize=10) ax2 = plt.subplot(1, 2, 2) ax2 = DC.plot_pseudoSection( dpre, ax2, 'pdp' ) #axs.pcolormesh(mesh_sub.vectorCCx,mesh_sub.vectorCCy,Q_sub, alpha=0.75,vmin=-1e-2, vmax=1e-2) ax2.set_title('App Cond (S/m)', fontsize=10) plt.draw() bbox_props = dict(boxstyle="rarrow,pad=0.3", fc="w", ec="k", lw=2) ax1.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="b", ec="k", lw=2) for jj in range(len(uniqueID)): ax1.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) ax1.text(0.1, (float(ii) + 1.) / (len(uniqueID) + 2), ".", transform=fig.transFigure, ha="right", va="center", size=8, bbox=mrk_props)
def run(loc=None, sig=None, radi=None, param=None, stype='dpdp', plotIt=True): """ DC Forward Simulation ===================== Forward model conductive spheres in a half-space and plot a pseudo-section Created by @fourndo on Mon Feb 01 19:28:06 2016 """ assert stype in [ 'pdp', 'dpdp' ], "Source type (stype) must be pdp or dpdp (pole dipole or dipole dipole)" if loc is None: loc = np.c_[[-50., 0., -50.], [50., 0., -50.]] if sig is None: sig = np.r_[1e-2, 1e-1, 1e-3] if radi is None: radi = np.r_[25., 25.] if param is None: param = np.r_[30., 30., 5] # First we need to create a mesh and a model. # This is our mesh dx = 5. hxind = [(dx, 15, -1.3), (dx, 75), (dx, 15, 1.3)] hyind = [(dx, 15, -1.3), (dx, 10), (dx, 15, 1.3)] hzind = [(dx, 15, -1.3), (dx, 15)] mesh = Mesh.TensorMesh([hxind, hyind, hzind], 'CCN') # Set background conductivity model = np.ones(mesh.nC) * sig[0] # First anomaly ind = Utils.ModelBuilder.getIndicesSphere(loc[:, 0], radi[0], mesh.gridCC) model[ind] = sig[1] # Second anomaly ind = Utils.ModelBuilder.getIndicesSphere(loc[:, 1], radi[1], mesh.gridCC) model[ind] = sig[2] # Get index of the center indy = int(mesh.nCy / 2) # Plot the model for reference # Define core mesh extent xlim = 200 zlim = 125 # Specify the survey type: "pdp" | "dpdp" # Then specify the end points of the survey. Let's keep it simple for now and survey above the anomalies, top of the mesh ends = [(-175, 0), (175, 0)] ends = np.c_[np.asarray(ends), np.ones(2).T * mesh.vectorNz[-1]] # Snap the endpoints to the grid. Easier to create 2D section. indx = Utils.closestPoints(mesh, ends) locs = np.c_[mesh.gridCC[indx, 0], mesh.gridCC[indx, 1], np.ones(2).T * mesh.vectorNz[-1]] # We will handle the geometry of the survey for you and create all the combination of tx-rx along line # [Tx, Rx] = DC.gen_DCIPsurvey(locs, mesh, stype, param[0], param[1], param[2]) survey, Tx, Rx = DC.gen_DCIPsurvey(locs, mesh, stype, param[0], param[1], param[2]) # Define some global geometry dl_len = np.sqrt(np.sum((locs[0, :] - locs[1, :])**2)) dl_x = (Tx[-1][0, 1] - Tx[0][0, 0]) / dl_len dl_y = (Tx[-1][1, 1] - Tx[0][1, 0]) / dl_len azm = np.arctan(dl_y / dl_x) #Set boundary conditions mesh.setCellGradBC('neumann') # Define the differential operators needed for the DC problem Div = mesh.faceDiv Grad = mesh.cellGrad Msig = Utils.sdiag(1. / (mesh.aveF2CC.T * (1. / model))) A = Div * Msig * Grad # Change one corner to deal with nullspace A[0, 0] = 1 A = sp.csc_matrix(A) # We will solve the system iteratively, so a pre-conditioner is helpful # This is simply a Jacobi preconditioner (inverse of the main diagonal) dA = A.diagonal() P = sp.spdiags(1 / dA, 0, A.shape[0], A.shape[0]) # Now we can solve the system for all the transmitters # We want to store the data data = [] # There is probably a more elegant way to do this, but we can just for-loop through the transmitters for ii in range(len(Tx)): start_time = time.time() # Let's time the calculations #print("Transmitter %i / %i\r" % (ii+1,len(Tx))) # Select dipole locations for receiver rxloc_M = np.asarray(Rx[ii][:, 0:3]) rxloc_N = np.asarray(Rx[ii][:, 3:]) # For usual cases "dpdp" or "gradient" if stype == 'pdp': # Create an "inifinity" pole tx = np.squeeze(Tx[ii][:, 0:1]) tinf = tx + np.array([dl_x, dl_y, 0]) * dl_len * 2 inds = Utils.closestPoints(mesh, np.c_[tx, tinf].T) RHS = mesh.getInterpolationMat(np.asarray(Tx[ii]).T, 'CC').T * ([-1] / mesh.vol[inds]) else: inds = Utils.closestPoints(mesh, np.asarray(Tx[ii]).T) RHS = mesh.getInterpolationMat(np.asarray(Tx[ii]).T, 'CC').T * ([-1, 1] / mesh.vol[inds]) # Iterative Solve Ainvb = sp.linalg.bicgstab(P * A, P * RHS, tol=1e-5) # We now have the potential everywhere phi = Utils.mkvc(Ainvb[0]) # Solve for phi on pole locations P1 = mesh.getInterpolationMat(rxloc_M, 'CC') P2 = mesh.getInterpolationMat(rxloc_N, 'CC') # Compute the potential difference dtemp = (P1 * phi - P2 * phi) * np.pi data.append(dtemp) print '\rTransmitter {0} of {1} -> Time:{2} sec'.format( ii, len(Tx), time.time() - start_time), print 'Transmitter {0} of {1}'.format(ii, len(Tx)) print 'Forward completed' # Let's just convert the 3D format into 2D (distance along line) and plot # [Tx2d, Rx2d] = DC.convertObs_DC3D_to_2D(survey, np.ones(survey.nSrc)) survey2D = DC.convertObs_DC3D_to_2D(survey, np.ones(survey.nSrc)) survey2D.dobs = np.hstack(data) # Here is an example for the first tx-rx array if plotIt: import matplotlib.pyplot as plt fig = plt.figure() ax = plt.subplot(2, 1, 1, aspect='equal') mesh.plotSlice(np.log10(model), ax=ax, normal='Y', ind=indy, grid=True) ax.set_title('E-W section at ' + str(mesh.vectorCCy[indy]) + ' m') plt.gca().set_aspect('equal', adjustable='box') plt.scatter(Tx[0][0, :], Tx[0][2, :], s=40, c='g', marker='v') plt.scatter(Rx[0][:, 0::3], Rx[0][:, 2::3], s=40, c='y') plt.xlim([-xlim, xlim]) plt.ylim([-zlim, mesh.vectorNz[-1] + dx]) ax = plt.subplot(2, 1, 2, aspect='equal') # Plot the location of the spheres for reference circle1 = plt.Circle((loc[0, 0] - Tx[0][0, 0], loc[2, 0]), radi[0], color='w', fill=False, lw=3) circle2 = plt.Circle((loc[0, 1] - Tx[0][0, 0], loc[2, 1]), radi[1], color='k', fill=False, lw=3) ax.add_artist(circle1) ax.add_artist(circle2) # Add the speudo section DC.plot_pseudoSection(survey2D, ax, stype) # plt.scatter(Tx2d[0][:],Tx[0][2,:],s=40,c='g', marker='v') # plt.scatter(Rx2d[0][:],Rx[0][:,2::3],s=40,c='y') # plt.plot(np.r_[Tx2d[0][0],Rx2d[-1][-1,-1]],np.ones(2)*mesh.vectorNz[-1], color='k') plt.ylim([-zlim, mesh.vectorNz[-1] + dx]) plt.show() return fig, ax
def run(loc=None, sig=None, radi=None, param=None, stype='dpdp', plotIt=True): """ DC Forward Simulation ===================== Forward model conductive spheres in a half-space and plot a pseudo-section Created by @fourndo on Mon Feb 01 19:28:06 2016 """ assert stype in ['pdp', 'dpdp'], "Source type (stype) must be pdp or dpdp (pole dipole or dipole dipole)" if loc is None: loc = np.c_[[-50.,0.,-50.],[50.,0.,-50.]] if sig is None: sig = np.r_[1e-2,1e-1,1e-3] if radi is None: radi = np.r_[25.,25.] if param is None: param = np.r_[30.,30.,5] # First we need to create a mesh and a model. # This is our mesh dx = 5. hxind = [(dx,15,-1.3), (dx, 75), (dx,15,1.3)] hyind = [(dx,15,-1.3), (dx, 10), (dx,15,1.3)] hzind = [(dx,15,-1.3),(dx, 15)] mesh = Mesh.TensorMesh([hxind, hyind, hzind], 'CCN') # Set background conductivity model = np.ones(mesh.nC) * sig[0] # First anomaly ind = Utils.ModelBuilder.getIndicesSphere(loc[:,0],radi[0],mesh.gridCC) model[ind] = sig[1] # Second anomaly ind = Utils.ModelBuilder.getIndicesSphere(loc[:,1],radi[1],mesh.gridCC) model[ind] = sig[2] # Get index of the center indy = int(mesh.nCy/2) # Plot the model for reference # Define core mesh extent xlim = 200 zlim = 125 # Specify the survey type: "pdp" | "dpdp" # Then specify the end points of the survey. Let's keep it simple for now and survey above the anomalies, top of the mesh ends = [(-175,0),(175,0)] ends = np.c_[np.asarray(ends),np.ones(2).T*mesh.vectorNz[-1]] # Snap the endpoints to the grid. Easier to create 2D section. indx = Utils.closestPoints(mesh, ends ) locs = np.c_[mesh.gridCC[indx,0],mesh.gridCC[indx,1],np.ones(2).T*mesh.vectorNz[-1]] # We will handle the geometry of the survey for you and create all the combination of tx-rx along line # [Tx, Rx] = DC.gen_DCIPsurvey(locs, mesh, stype, param[0], param[1], param[2]) survey, Tx, Rx = DC.gen_DCIPsurvey(locs, mesh, stype, param[0], param[1], param[2]) # Define some global geometry dl_len = np.sqrt( np.sum((locs[0,:] - locs[1,:])**2) ) dl_x = ( Tx[-1][0,1] - Tx[0][0,0] ) / dl_len dl_y = ( Tx[-1][1,1] - Tx[0][1,0] ) / dl_len azm = np.arctan(dl_y/dl_x) #Set boundary conditions mesh.setCellGradBC('neumann') # Define the differential operators needed for the DC problem Div = mesh.faceDiv Grad = mesh.cellGrad Msig = Utils.sdiag(1./(mesh.aveF2CC.T*(1./model))) A = Div*Msig*Grad # Change one corner to deal with nullspace A[0,0] = 1 A = sp.csc_matrix(A) # We will solve the system iteratively, so a pre-conditioner is helpful # This is simply a Jacobi preconditioner (inverse of the main diagonal) dA = A.diagonal() P = sp.spdiags(1/dA,0,A.shape[0],A.shape[0]) # Now we can solve the system for all the transmitters # We want to store the data data = [] # There is probably a more elegant way to do this, but we can just for-loop through the transmitters for ii in range(len(Tx)): start_time = time.time() # Let's time the calculations #print("Transmitter %i / %i\r" % (ii+1,len(Tx))) # Select dipole locations for receiver rxloc_M = np.asarray(Rx[ii][:,0:3]) rxloc_N = np.asarray(Rx[ii][:,3:]) # For usual cases "dpdp" or "gradient" if stype == 'pdp': # Create an "inifinity" pole tx = np.squeeze(Tx[ii][:,0:1]) tinf = tx + np.array([dl_x,dl_y,0])*dl_len*2 inds = Utils.closestPoints(mesh, np.c_[tx,tinf].T) RHS = mesh.getInterpolationMat(np.asarray(Tx[ii]).T, 'CC').T*( [-1] / mesh.vol[inds] ) else: inds = Utils.closestPoints(mesh, np.asarray(Tx[ii]).T ) RHS = mesh.getInterpolationMat(np.asarray(Tx[ii]).T, 'CC').T*( [-1,1] / mesh.vol[inds] ) # Iterative Solve Ainvb = sp.linalg.bicgstab(P*A,P*RHS, tol=1e-5) # We now have the potential everywhere phi = Utils.mkvc(Ainvb[0]) # Solve for phi on pole locations P1 = mesh.getInterpolationMat(rxloc_M, 'CC') P2 = mesh.getInterpolationMat(rxloc_N, 'CC') # Compute the potential difference dtemp = (P1*phi - P2*phi)*np.pi data.append( dtemp ) print '\rTransmitter {0} of {1} -> Time:{2} sec'.format(ii,len(Tx),time.time()- start_time), print 'Transmitter {0} of {1}'.format(ii,len(Tx)) print 'Forward completed' # Let's just convert the 3D format into 2D (distance along line) and plot # [Tx2d, Rx2d] = DC.convertObs_DC3D_to_2D(survey, np.ones(survey.nSrc)) survey2D = DC.convertObs_DC3D_to_2D(survey, np.ones(survey.nSrc)) survey2D.dobs =np.hstack(data) # Here is an example for the first tx-rx array if plotIt: import matplotlib.pyplot as plt fig = plt.figure() ax = plt.subplot(2,1,1, aspect='equal') mesh.plotSlice(np.log10(model), ax =ax, normal = 'Y', ind = indy,grid=True) ax.set_title('E-W section at '+str(mesh.vectorCCy[indy])+' m') plt.gca().set_aspect('equal', adjustable='box') plt.scatter(Tx[0][0,:],Tx[0][2,:],s=40,c='g', marker='v') plt.scatter(Rx[0][:,0::3],Rx[0][:,2::3],s=40,c='y') plt.xlim([-xlim,xlim]) plt.ylim([-zlim,mesh.vectorNz[-1]+dx]) ax = plt.subplot(2,1,2, aspect='equal') # Plot the location of the spheres for reference circle1=plt.Circle((loc[0,0]-Tx[0][0,0],loc[2,0]),radi[0],color='w',fill=False, lw=3) circle2=plt.Circle((loc[0,1]-Tx[0][0,0],loc[2,1]),radi[1],color='k',fill=False, lw=3) ax.add_artist(circle1) ax.add_artist(circle2) # Add the speudo section DC.plot_pseudoSection(survey2D,ax,stype) # plt.scatter(Tx2d[0][:],Tx[0][2,:],s=40,c='g', marker='v') # plt.scatter(Rx2d[0][:],Rx[0][:,2::3],s=40,c='y') # plt.plot(np.r_[Tx2d[0][0],Rx2d[-1][-1,-1]],np.ones(2)*mesh.vectorNz[-1], color='k') plt.ylim([-zlim,mesh.vectorNz[-1]+dx]) plt.show() return fig, ax
from scipy.interpolate import NearestNDInterpolator #%% home_dir = 'C:\\Users\\dominiquef.MIRAGEOSCIENCE\\ownCloud\\Research\\MtIsa\\Data' obs_file = 'ip3d_all_QC.ip' topo_file = 'MIM_SRTM_Local.topo' dsep = '\\' outfile = 'ip3d_all_QC.ip' topo = np.genfromtxt(home_dir + dsep + topo_file,skip_header=1) Ftopo = NearestNDInterpolator(topo[:,:2], topo[:,2]) dtype = 'volt' plt.close('all') #%% load obs file 3D survey3D = DC.readUBC_DC3Dobs(home_dir + dsep + obs_file, rtype = 'IP') DCsurvey = survey3D['DCsurvey'] # Data convertion to Chargeability #DCsurvey.dobs = DCsurvey.dobs*100. #DCsurvey.std = DCsurvey.std*100. # Assign Z-value from topo for ii in range(DCsurvey.nSrc): DCsurvey.srcList[ii].loc[0][2] = Ftopo(DCsurvey.srcList[ii].loc[0][0:2]) DCsurvey.srcList[ii].loc[1][2] = Ftopo(DCsurvey.srcList[ii].loc[1][0:2]) rx_x = DCsurvey.srcList[ii].rxList[0].locs[0][:,0] rx_y = DCsurvey.srcList[ii].rxList[0].locs[0][:,1] DCsurvey.srcList[ii].rxList[0].locs[0][:,2] = Ftopo(rx_x,rx_y)
#============================================================================== # if not gin: # print 'SimPED - Simulation has ended with return' # break #============================================================================== # Add z coordinate to all survey... assume flat nz = mesh.vectorNz var = np.c_[np.asarray(gin), np.ones(2).T * nz[-1]] # Snap the endpoints to the grid. Easier to create 2D section. indx = Utils.closestPoints(mesh, var) endl = np.c_[mesh.gridCC[indx, 0], mesh.gridCC[indx, 1], np.ones(2).T * nz[-1]] [survey, Tx, Rx] = DC.gen_DCIPsurvey(endl, mesh, stype, a, b, n) dl_len = np.sqrt(np.sum((endl[0, :] - endl[1, :])**2)) dl_x = (Tx[-1][0, 1] - Tx[0][0, 0]) / dl_len dl_y = (Tx[-1][1, 1] - Tx[0][1, 0]) / dl_len azm = np.arctan(dl_y / dl_x) # Plot stations along line plt.scatter(Tx[0][0, :], Tx[0][1, :], s=20, c='g') plt.scatter(Rx[0][:, 0::3], Rx[0][:, 1::3], s=20, c='y') #%% Forward model data data = [] #np.zeros( nstn*nrx ) unct = [] problem = DC.ProblemDC_CC(mesh)
dsep = '\\' # Forward solver # Number of padding cells to remove from plotting padc = 15 # Plotting parameters xmin, xmax = 10500, 13000 zmin, zmax = -600, 600 vmin, vmax = -4, 2 z = np.linspace(zmin, zmax, 4) x = np.asarray([11000, 11750, 12500]) #%% load obs file 3D dobs = DC.readUBC_DC3Dobs(home_dir + dsep + obs_file) DCsurvey = dobs['DCsurvey'] # Assign line ID to the survey lineID = DC.xy_2_lineID(DCsurvey) uniqueID = np.unique(lineID) # Convert 3D locations to 2D survey dobs2D = DC.convertObs_DC3D_to_2D(DCsurvey, lineID, 'Xloc') srcMat = DC.getSrc_locs(DCsurvey) #DCdata[src0, src0.rxList[0]] # Find 2D data correspondance dataID = np.zeros(dobs2D.nD) count = 0
#msh_file = 'Mesh_2D.msh' #mod_file = 'Model_2D.con' obs_file = 'data_Z.txt' topofile = 'MIM_SRTM_Local.topo' dsep = '\\' # Forward solver # Number of padding cells to remove from plotting padc = 15 # Load UBC-topo file topo = np.genfromtxt(home_dir + dsep + topofile, skip_header=1) # load obs file 3D dobs = DC.readUBC_DC3Dobs(home_dir + dsep + obs_file) DCsurvey = dobs['DCsurvey'] # Assign line ID to the survey lineID = DC.xy_2_lineID(DCsurvey) uniqueID = np.unique(lineID) # Convert 3D locations to 2D survey dobs2D = DC.convertObs_DC3D_to_2D(DCsurvey, lineID, 'Xloc') srcMat = DC.getSrc_locs(dobs2D) #DCdata[src0, src0.rxList[0]] # Find 2D data correspondance dataID = np.zeros(dobs2D.nD) count = 0
def animate(ii): removeFrame() # Grab current line and indx = np.where(lineID == ii)[0] srcLeft = [] obs_l = [] srcRight = [] obs_r = [] obs = [] srcList = [] # Split the obs file into left and right for jj in range(len(indx)): # Grab corresponding data obs = np.hstack([obs, dobs2D.dobs[dataID == indx[jj]]]) #std = dobs2D.std[dataID==indx[jj]] srcList.append(dobs2D.srcList[indx[jj]]) Tx = dobs2D.srcList[indx[jj]].loc Rx = dobs2D.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 #DC.plot_pseudoSection(dobs2D,lineID, np.r_[0,1],'pdp') id_lbe = int(DCsurvey.srcList[indx[jj]].loc[0][1]) mesh3d = Mesh.TensorMesh([hx, 1, hz], x0=(-np.sum(padx) + np.min(srcMat[0][:, 0]), id_lbe, 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(DC2D_r, ax2, stype='pdp', 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(DC2D_l, ax1, stype='pdp', 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) # Run both left and right survey seperately 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 SVD\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 model and predicted data minv = DC.readUBC_DC2DModel(inv_dir + dsep + 'dcinv2d.con') minv = np.reshape(minv, (mesh2d.nCy, mesh2d.nCx)) Mesh.TensorMesh.writeModelUBC( mesh3d, home_dir + dsep + 'Model' + str(id_lbe) + '.con', minv.T) dpre = DC.readUBC_DC2Dpre(inv_dir + dsep + 'dcinv2d.pre') DCpre = dpre['DCsurvey'] DCtemp = DC2D_l DCtemp.dobs = DCpre.dobs[obs_l == 1] ax5 = plt.subplot(3, 2, 3) DC.plot_pseudoSection(DCtemp, ax5, stype='pdp', 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 = DC2D_r DCtemp.dobs = DCpre.dobs[obs_r == 1] ax6 = plt.subplot(3, 2, 4) DC.plot_pseudoSection(DCtemp, ax6, stype='pdp', 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. Cond. (S/m)", 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, np.log10(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=ax4, ticks=np.linspace(vmin, vmax, 4), format="$10^{%.1f}$") cb.set_label("Conductivity (S/m)", 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)
# Forward solver # Number of padding cells to remove from plotting padc = 15 # Plotting parameters xmin, xmax = 10500, 13000 zmin, zmax = -600, 600 vmin, vmax = 0, 75 z = np.linspace(zmin, zmax, 4) #%% load obs file 3D dobs = DC.readUBC_DC3Dobs(home_dir + dsep + obs_file, rtype='IP') DCsurvey = dobs['DCsurvey'] # Assign line ID to the survey lineID = DC.xy_2_lineID(DCsurvey) uniqueID = np.unique(lineID) # Convert 3D locations to 2D survey dobs2D = DC.convertObs_DC3D_to_2D(DCsurvey, lineID,'Xloc') srcMat = DC.getSrc_locs(DCsurvey) #DCdata[src0, src0.rxList[0]] # Find 2D data correspondance dataID = np.zeros(dobs2D.nD) count = 0
cfm1.activateWindow() plt.sca(ax_prim) # Takes two points from ginput and create survey #gin = plt.ginput(2, timeout = 0) # Add z coordinate to all survey... assume flat nz = mesh.vectorNz var = np.c_[np.asarray(srvy_end),np.ones(2).T*nz[-1]] # Snap the endpoints to the grid. Easier to create 2D section. indx = Utils.closestPoints(mesh, var ) endl = np.c_[mesh.gridCC[indx,0],mesh.gridCC[indx,1],np.ones(2).T*nz[-1]] [survey2D, Tx, Rx] = DC.gen_DCIPsurvey(endl, mesh, stype, a, b, n) dl_len = np.sqrt( np.sum((endl[0,:] - endl[1,:])**2) ) dl_x = ( Tx[-1][0,1] - Tx[0][0,0] ) / dl_len dl_y = ( Tx[-1][1,1] - Tx[0][1,0] ) / dl_len azm = np.arctan(dl_y/dl_x) #%% Create a 2D mesh along axis of Tx end points and keep z-discretization dx = np.min( [ np.min(mesh.hx), np.min(mesh.hy), dx_in ]) ncx = np.ceil(dl_len/dx)+3 ncz = np.ceil( depth / dx ) padx = dx*np.power(1.4,range(1,padc)) # Creating padding cells hx = np.r_[padx[::-1], np.ones(ncx)*dx , padx]
#============================================================================== # if not gin: # print 'SimPED - Simulation has ended with return' # break #============================================================================== # Add z coordinate to all survey... assume flat nz = mesh.vectorNz var = np.c_[np.asarray(gin), np.ones(2).T * nz[-1]] # Snap the endpoints to the grid. Easier to create 2D section. indx = Utils.closestPoints(mesh, var) endl = np.c_[mesh.gridCC[indx, 0], mesh.gridCC[indx, 1], np.ones(2).T * nz[-1]] [survey2D, Tx, Rx] = DC.gen_DCIPsurvey(endl, mesh, stype, a, b, n) dl_len = np.sqrt(np.sum((endl[0, :] - endl[1, :])**2)) dl_x = (Tx[-1][0, 1] - Tx[0][0, 0]) / dl_len dl_y = (Tx[-1][1, 1] - Tx[0][1, 0]) / dl_len azm = np.arctan(dl_y / dl_x) #%% Create a 2D mesh along axis of Tx end points and keep z-discretization dx = np.min([np.min(mesh.hx), np.min(mesh.hy), dx_in]) ncx = np.ceil(dl_len / dx) + 3 ncz = np.ceil(depth / dx) padx = dx * np.power(1.4, range(1, padc)) # Creating padding cells hx = np.r_[padx[::-1], np.ones(ncx) * dx, padx]
import os from SimPEG import * import SimPEG.DCIP as DC import pylab as plt from matplotlib import animation from JSAnimation import HTMLWriter #%% home_dir = 'C:\\Users\\dominiquef.MIRAGEOSCIENCE\\ownCloud\\Research\\MtIsa\\Data' obs_file = 'IP_Obs_QC_v5.dat' dsep = '\\' #%% load obs file 3D survey3D = DC.readUBC_DC3Dobs(home_dir + dsep + obs_file, dtype='IP') DCsurvey = survey3D['DCsurvey'] # Assign line ID to the survey lineID = DC.xy_2_lineID(DCsurvey) uniqueID = np.unique(lineID) # Convert 3D locations to 2D survey dobs2D = DC.convertObs_DC3D_to_2D(DCsurvey, lineID, 'Xloc') srcMat = DC.getSrc_locs(DCsurvey) # Find 2D data correspondance dataID = np.zeros(dobs2D.nD) count = 0 for ii in range(dobs2D.nSrc): nD = dobs2D.srcList[ii].rxList[0].nD