def plotSingleArrayAparentResistivity(self): if self.singleArray : survey2D = DCUtils.convertObs_DC3D_to_2D(self.survey, numpy.ones(self.survey.nSrc), 'Xloc') survey2D.dobs = numpy.hstack(self.survey.dobs) fig = plt.figure(figsize=(5, 8), num = self.title + ': Apparent resistivity') ax1 = plt.subplot(2, 1, 1, aspect="equal") clim = [self.mesh.tunnelParams.log_sigmaRock - 1, self.mesh.tunnelParams.log_sigmaDis] slice = int(self.coreMesh.nCy / 2) dat1 = self.coreMesh.plotSlice(((self.givenModelOnCoreMesh)), ax=ax1, normal='Y', clim=clim, grid=False, ind=slice) ax1.scatter(self.allSurveyPoints[:, 0], self.allSurveyPoints[:, 2], s=5, c='w') ax2 = plt.subplot(2, 1, 2, aspect="equal") dat2 = DCUtils.plot_pseudoSection( survey2D, ax2, survey_type='dipole-dipole', data_type='appConductivity', space_type='whole-space', scale="log", data_location=True ) #plt.gca().set_aspect('equal', adjustable='box') plt.xlim([self.coreMesh.vectorNx[0], self.coreMesh.vectorNx[-1]]) plt.ylim([-25, 0]) ax2.scatter(self.allSurveyPoints[:, 0], self.allSurveyPoints[:, 2]* (-1), s=5, c='k') else: pass pass
def setUp(self): url = 'https://storage.googleapis.com/simpeg/tests/dc_utils/' cloudfiles = [ 'dPred_fullspace.txt', 'AB_GIF_fullspace.txt', 'MN_GIF_fullspace.txt', 'AM_GIF_fullspace.txt', 'AN_GIF_fullspace.txt', 'BM_GIF_fullspace.txt', 'BN_GIF_fullspace.txt', 'RhoApp_GIF_fullspace.txt' ] self.basePath = os.path.expanduser('~/Downloads/TestDCUtilsFullSpace') self.files = io_utils.download( [url+f for f in cloudfiles], folder=self.basePath, overwrite=True ) survey_file = os.path.sep.join([self.basePath, 'dPred_fullspace.txt']) DCsurvey = DCUtils.readUBC_DC3Dobs(survey_file) DCsurvey = DCsurvey['dc_survey'] self.survey = DCsurvey
def test_apparent_resistivity(self): # Compute apparent resistivity from survey rhoapp = DCUtils.apparent_resistivity( self.survey, dobs=self.survey.dobs, survey_type='dipole-dipole', space_type='whole-space', eps=1e-16 ) # Load benchmarks files from UBC-GIF codes rhoappfile = os.path.sep.join( [self.basePath, 'RhoApp_GIF_fullspace.txt'] ) rhogif = np.loadtxt(rhoappfile) # remove value with almost null geometric factor idx = rhoapp < 1e8 # Assert agreements between the two codes passed = np.allclose(rhoapp[idx], rhogif[idx]) self.assertTrue(passed) # Clean up the working directory shutil.rmtree(self.basePath)
def test_ElecSep(self): # Compute dipoles distances from survey elecSepDict = DCUtils.electrode_separations(self.survey) AM = elecSepDict['AM'] BM = elecSepDict['BM'] AN = elecSepDict['AN'] BN = elecSepDict['BN'] MN = elecSepDict['MN'] AB = elecSepDict['AB'] # Load benchmarks files from UBC-GIF codes AB_file = os.path.sep.join([self.basePath, 'AB_GIF_fullspace.txt']) MN_file = os.path.sep.join([self.basePath, 'MN_GIF_fullspace.txt']) AM_file = os.path.sep.join([self.basePath, 'AM_GIF_fullspace.txt']) AN_file = os.path.sep.join([self.basePath, 'AN_GIF_fullspace.txt']) BM_file = os.path.sep.join([self.basePath, 'BM_GIF_fullspace.txt']) BN_file = os.path.sep.join([self.basePath, 'BN_GIF_fullspace.txt']) AB_GIF = np.loadtxt(AB_file) MN_GIF = np.loadtxt(MN_file) AM_GIF = np.loadtxt(AM_file) AN_GIF = np.loadtxt(AN_file) BM_GIF = np.loadtxt(BM_file) BN_GIF = np.loadtxt(BN_file) # Assert agreements between the two codes test_AB = np.allclose(AB_GIF, AB) test_MN = np.allclose(MN_GIF, MN) test_AM = np.allclose(AM_GIF, AM) test_AN = np.allclose(AN_GIF, AN) test_BM = np.allclose(BM_GIF, BM) test_BN = np.allclose(BN_GIF, BN) passed = np.all([test_AB, test_MN, test_AM, test_AN, test_BM, test_BN]) self.assertTrue(passed)
bottomHalf = bottomHalf[0:-1, :] cylinderPoints = np.vstack([topHalf, bottomHalf]) cylinderPoints = np.vstack([cylinderPoints, topHalf[0, :]]) return cylinderPoints # Setup a synthetic Dipole-Dipole Survey # Line 1 xmin, xmax = -15., 15. ymin, ymax = 0., 0. zmin, zmax = 0, 0 endl = np.array([[xmin, ymin, zmin], [xmax, ymax, zmax]]) survey1 = DCUtils.gen_DCIPsurvey(endl, "dipole-dipole", dim=mesh.dim, a=3, b=3, n=8) # Line 2 xmin, xmax = -15., 15. ymin, ymax = 5., 5. zmin, zmax = 0, 0 endl = np.array([[xmin, ymin, zmin], [xmax, ymax, zmax]]) survey2 = DCUtils.gen_DCIPsurvey(endl, "dipole-dipole", dim=mesh.dim, a=3, b=3, n=8)
axs.scatter(tx[0, 1], tx[1, 2], c='b', s=75, marker='v') else: axs.scatter(tx[0], tx[2], c='r', s=75, marker='v') #cfm1=get_current_fig_manager().window #%% # 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]] survey = StaticUtils.gen_DCIPsurvey(endl, mesh, stype, a, b, n) #survey = DC.SurveyDC.Survey(srcList) Tx = StaticUtils.getSrc_locs(survey) dl_len = np.sqrt(np.sum((endl[0, :] - endl[1, :])**2)) dl_x = (Tx[-1][0] - Tx[0][0]) / dl_len dl_y = (Tx[-1][1] - Tx[0][1]) / dl_len azm = np.arctan(dl_y / dl_x) # Plot stations along line if stype == 'gradient': Rx = survey.srcList[0].rxList[0].locs plt.scatter(Tx[0][0::3], Tx[0][1::3], s=40, c='r') plt.scatter(np.c_[Rx[0][:, 0], Rx[1][:, 0]], np.c_[Rx[0][:, 1], Rx[1][:, 1]],
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 = DCUtils.gen_DCIPsurvey(endl, mesh, stype, a, b, n) Tx = DCUtils.getSrc_locs(survey2D) Rx = survey2D.srcList[0].rxList[0].locs dl_len = np.sqrt(np.sum((endl[0, :] - endl[1, :])**2)) dl_x = (Tx[-1][0] - Tx[0][0]) / dl_len dl_y = (Tx[-1][1] - Tx[0][1]) / 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))
# Model: ln_sigback = -5. mtrue_2 = ln_sigback * np.ones(mesh_2d.nC) mtrue_3 = ln_sigback * np.ones(mesh_3d.nC) # Survey: # Setup a Dipole-Dipole Survey xmin, xmax = -20., 20. ymin, ymax = -9., -9., zmin, zmax = mesh_2d.vectorCCy[-1], mesh_2d.vectorCCy[-1] endl = np.array([[xmin, ymin, zmin], [xmax, ymax, zmax]]) survey_2 = DCUtils.gen_DCIPsurvey(endl, "dipole-dipole", dim=mesh_2d.dim, a=10, b=10, n=1, d2flag='2D') # Line 1 xmin, xmax = -20., 20. ymin, ymax = 0., 0. zmin, zmax = -9., -9. endl = np.array([[xmin, ymin, zmin], [xmax, ymax, zmax]]) survey_3 = DCUtils.gen_DCIPsurvey(endl, "dipole-dipole", dim=mesh_3d.dim, a=10, b=10, n=1)
bottomHalf = bottomHalf[0:-1, :] cylinderPoints = np.vstack([topHalf, bottomHalf]) cylinderPoints = np.vstack([cylinderPoints, topHalf[0, :]]) return cylinderPoints # Setup a Dipole-Dipole Survey xmin, xmax = -15., 15. ymin, ymax = 0., 0. zmin, zmax = mesh.vectorCCy[-1], mesh.vectorCCy[-1] endl = np.array([[xmin, ymin, zmin], [xmax, ymax, zmax]]) survey = DCUtils.gen_DCIPsurvey(endl, "dipole-dipole", dim=mesh.dim, a=1, b=1, n=10, d2flag='2D') # Setup Problem with exponential mapping and Active cells only in the core mesh expmap = Maps.ExpMap(mesh) mapactive = Maps.InjectActiveCells(mesh=mesh, indActive=actind, valInactive=-5.) mapping = expmap * mapactive problem = DC.Problem3D_CC(mesh, sigmaMap=mapping) problem.pair(survey) problem.Solver = Solver survey.dpred(mtrue[actind])
topHalf = np.vstack([xLoc1, zLoc1]).T topHalf = topHalf[0:-1, :] bottomHalf = np.vstack([xLoc2, zLoc2]).T bottomHalf = bottomHalf[0:-1, :] cylinderPoints = np.vstack([topHalf, bottomHalf]) cylinderPoints = np.vstack([cylinderPoints, topHalf[0, :]]) return cylinderPoints # Setup a Dipole-Dipole Survey xmin, xmax = -15., 15. ymin, ymax = 0., 0. zmin, zmax = 0, 0 endl = np.array([[xmin, ymin, zmin], [xmax, ymax, zmax]]) survey = DCUtils.gen_DCIPsurvey(endl, mesh, "dipole-dipole", a=1, b=1, n=10, d2flag='2D') # Setup Problem with exponential mapping and Active cells only in the core mesh expmap = Maps.ExpMap(mesh) mapactive = Maps.InjectActiveCells(mesh=mesh, indActive=actind, valInactive=-5.) mapping = expmap*mapactive problem = DC.Problem3D_CC(mesh, sigmaMap=mapping) problem.pair(survey) problem.Solver = Solver survey.dpred(mtrue[actind]) survey.makeSyntheticData(mtrue[actind], std=0.05, force=True) ######################
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 = Utils.readUBC_DC3Dobs(home_dir + dsep + obs_file) DCsurvey = dobs['DCsurvey'] srcMat = Utils.getSrc_locs(DCsurvey) # Assign line ID to the survey lineID = Utils.xy_2_lineID(DCsurvey) uniqueID = np.unique(lineID) # Convert 3D locations to 2D survey survey2D = Utils.convertObs_DC3D_to_2D(DCsurvey, lineID, 'Xloc') srcMat = Utils.getSrc_locs(survey2D) #DCdata[src0, src0.rxList[0]]
# Takes two points from ginput and create survey #if re.match(stype,'gradient'): #gin = [(423230. , 546440.), (423715. , 546440.)] #else: #gin = plt.ginput(2, timeout = 0) #gin = [(370, 12155), (2000, 12155)] # 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]] srcList = StaticUtils.gen_DCIPsurvey(endl, mesh, stype, a, b, n) survey = DC.SurveyDC.Survey(srcList) Tx = StaticUtils.getSrc_locs(srcList) dl_len = np.sqrt( np.sum((endl[0,:] - endl[1,:])**2) ) dl_x = ( Tx[-1][0] - Tx[0][0] ) / dl_len dl_y = ( Tx[-1][1] - Tx[0][1] ) / dl_len azm = np.arctan(dl_y/dl_x) # Plot stations along line if stype == 'gradient': plt.scatter(Tx[0][0::3],Tx[0][1::3],s=40,c='r') plt.scatter(np.c_[Rx[0][:,0],Rx[1][:,0]],np.c_[Rx[0][:,1],Rx[1][:,1]],s=20,c='y') plt.show()
def test_dipole_dipole(self): # Setup a dipole-dipole Survey survey = DCUtils.gen_DCIPsurvey( self.xyz, survey_type="dipole-dipole", dim=self.mesh.dim, a=self.survey_a, b=self.survey_b, n=self.survey_n ) # Setup Problem with exponential mapping expmap = Maps.ExpMap(self.mesh) problem = DC.Problem3D_CC(self.mesh, sigmaMap=expmap) problem.pair(survey) problem.Solver = Solver # Create synthetic data survey.makeSyntheticData(self.model, std=0., force=True) survey.eps = 1e-5 # Testing IO surveyfile = os.path.sep.join( [self.basePath, '2sph_dipole_dipole.obs'] ) DCUtils.writeUBC_DCobs( surveyfile, survey, dim=3, format_type='GENERAL' ) survey = DCUtils.readUBC_DC3Dobs(surveyfile) survey = survey['dc_survey'] DCUtils.writeUBC_DCobs( surveyfile, survey, dim=3, format_type='GENERAL' ) survey = DCUtils.readUBC_DC3Dobs(surveyfile) survey = survey['dc_survey'] if self.plotIt: import matplotlib.pyplot as plt # Test Pseudosections plotting fig, ax = plt.subplots(1, 1, figsize=(15, 3)) ax = DCUtils.plot_pseudoSection( survey, ax, survey_type='dipole-dipole', scale='log', clim=None, data_type='appResistivity', pcolorOpts={"cmap": "viridis"}, data_location=True ) plt.show() # Test the utils functions electrode_separations, # source_receiver_midpoints, geometric_factor, # apparent_resistivity all at once rhoapp = DCUtils.apparent_resistivity( survey, survey_type='dipole-dipole', space_type='half-space', eps=0. ) rhoA_GIF_file = os.path.sep.join([self.basePath, 'rhoA_GIF_dd.txt']) rhoA_GIF_dd = np.loadtxt(rhoA_GIF_file) passed = np.allclose(rhoapp, rhoA_GIF_dd) self.assertTrue(passed)
def plot_pseudoSection(dc_survey, ax=None, survey_type='dipole-dipole', data_type="appConductivity", space_type='half-space', clim=None, scale="linear", sameratio=True, pcolorOpts={}, data_location=False, dobs=None, dim=2): """ Read list of 2D tx-rx location and plot a speudo-section of apparent resistivity. Assumes flat topo for now... Input: :param SimPEG.EM.Static.DC.SurveyDC.Survey dc_survey: DC survey object :param matplotlib.pyplot.axes ax: figure axes on which to plot :param str survey_type: Either 'dipole-dipole' | 'pole-dipole' | 'dipole-pole' | 'pole-pole' :param str data_type: Either 'appResistivity' | 'appConductivity' | 'volt' (potential) :param str space_type: Either 'half-space' (default) or 'whole-space' :param str scale: Either 'linear' (default) or 'log' Output: :return matplotlib.pyplot.figure plot overlayed on image """ import pylab as plt from scipy.interpolate import griddata # Set depth to 0 for now z0 = 0. rho = [] # Use dobs in survey if dobs is None if dobs is None: if dc_survey.dobs is None: raise Exception() else: dobs = dc_survey.dobs rhoApp = DCUtils.apparent_resistivity(dc_survey, dobs=dobs, survey_type=survey_type, space_type=space_type) midx, midz = DCUtils.source_receiver_midpoints(dc_survey, survey_type=survey_type, dim=dim) if data_type == 'volt': if scale == "linear": rho = dobs elif scale == "log": rho = np.log10(abs(dobs)) elif data_type == 'appConductivity': if scale == "linear": rho = 1. / rhoApp elif scale == "log": rho = np.log10(1. / rhoApp) elif data_type == 'appResistivity': if scale == "linear": rho = rhoApp elif scale == "log": rho = np.log10(rhoApp) else: print() raise Exception("""data_type must be 'appResistivity' | 'appConductivity' | 'volt' """ " not {}".format(data_type)) # Grid points grid_x, grid_z = np.meshgrid( np.linspace(np.min(midx), np.max(midx), int(2. * (np.abs(np.max(midx) - np.min(midx))) + 1)), np.linspace(np.min(midz), np.max(midz), int(2. * (np.abs(np.min(midz) - np.max(midz))) + 1)), indexing='xy') grid_x, grid_z = grid_x.T, grid_z.T grid_rho = griddata(np.c_[midx, midz], rho.T, (grid_x, grid_z), method='linear', rescale=True) if clim is None: vmin, vmax = rho.min(), rho.max() else: vmin, vmax = clim[0], clim[1] if ax is None: fig, ax = plt.subplots(1, 1, figsize=(15, 3)) grid_rho = np.ma.masked_where(np.isnan(grid_rho), grid_rho) ph = ax.contourf(grid_x[:, 0], grid_z[0, :], grid_rho.T, vmin=vmin, vmax=vmax, **pcolorOpts) ax.set_xlabel('X(m)', fontsize=16) ax.set_ylabel('n', fontsize=16) ax.tick_params(labelsize=14) if scale == "log": cbar = plt.colorbar(ph, format="$10^{%.1f}$", fraction=0.04, orientation="horizontal") elif scale == "linear": cbar = plt.colorbar(ph, format="%.1f", fraction=0.04, orientation="horizontal") if data_type == 'appConductivity': cbar.set_label("App.Cond", size=16) elif data_type == 'appResistivity': cbar.set_label("Apparent Resistivity (Ohm-m)", size=16) elif data_type == 'volt': cbar.set_label("Potential (V)", size=16) #cmin, cmax = cbar.get_clim() #ticks = np.linspace(cmin, cmax, 5) #cbar.set_ticks(ticks) #cbar.ax.tick_params(labelsize=14) cbar.set_ticks(ph.levels) cbar.ax.tick_params(labelsize=16) # Plot apparent resistivity if data_location: ax.plot(midx, midz, 'k.', ms=2, alpha=0.8, label='data locations') #ax.plot(grid_x, grid_z, 'k.', ms=1, alpha=0.4) ax.legend(fontsize=14) if sameratio: ax.set_aspect('equal', adjustable='box') return ax, midx, midz, grid_x, grid_z, rho
topHalf = topHalf[0:-1, :] bottomHalf = np.vstack([xLoc2, zLoc2]).T bottomHalf = bottomHalf[0:-1, :] cylinderPoints = np.vstack([topHalf, bottomHalf]) cylinderPoints = np.vstack([cylinderPoints, topHalf[0, :]]) return cylinderPoints # Setup a synthetic Dipole-Dipole Survey # Line 1 xmin, xmax = -15., 15. ymin, ymax = 0., 0. zmin, zmax = 0, 0 endl = np.array([[xmin, ymin, zmin], [xmax, ymax, zmax]]) survey1 = DCUtils.gen_DCIPsurvey(endl, "dipole-dipole", dim=mesh.dim, a=3, b=3, n=8) # Line 2 xmin, xmax = -15., 15. ymin, ymax = 5., 5. zmin, zmax = 0, 0 endl = np.array([[xmin, ymin, zmin], [xmax, ymax, zmax]]) survey2 = DCUtils.gen_DCIPsurvey(endl, "dipole-dipole", dim=mesh.dim, a=3, b=3, n=8) # Line 3 xmin, xmax = -15., 15. ymin, ymax = -5., -5. zmin, zmax = 0, 0 endl = np.array([[xmin, ymin, zmin], [xmax, ymax, zmax]]) survey3 = DCUtils.gen_DCIPsurvey(endl, "dipole-dipole", dim=mesh.dim,
topHalf = topHalf[0:-1, :] bottomHalf = np.vstack([xLoc2, zLoc2]).T bottomHalf = bottomHalf[0:-1, :] cylinderPoints = np.vstack([topHalf, bottomHalf]) cylinderPoints = np.vstack([cylinderPoints, topHalf[0, :]]) return cylinderPoints # Setup a synthetic Dipole-Dipole Survey # Line 1 xmin, xmax = -15., 15. ymin, ymax = 0., 0. zmin, zmax = 0, 0 endl = np.array([[xmin, ymin, zmin], [xmax, ymax, zmax]]) survey1 = DCUtils.gen_DCIPsurvey(endl, mesh, "dipole-dipole", a=3, b=3, n=8) # Line 2 xmin, xmax = -15., 15. ymin, ymax = 5., 5. zmin, zmax = 0, 0 endl = np.array([[xmin, ymin, zmin], [xmax, ymax, zmax]]) survey2 = DCUtils.gen_DCIPsurvey(endl, mesh, "dipole-dipole", a=3, b=3, n=8) # Line 3 xmin, xmax = -15., 15. ymin, ymax = -5., -5. zmin, zmax = 0, 0 endl = np.array([[xmin, ymin, zmin], [xmax, ymax, zmax]]) survey3 = DCUtils.gen_DCIPsurvey(endl, mesh, "dipole-dipole", a=3, b=3, n=8)