from fatiando import gridder, utils from fatiando.vis import mpl # Generate random points x, y = gridder.scatter((-2, 2, -2, 2), n=300, seed=1) # And calculate 2D Gaussians on these points as sample data def data(x, y): return (utils.gaussian2d(x, y, -0.6, -1) - utils.gaussian2d(x, y, 1.5, 1.5)) d = data(x, y) # Extract a profile along the diagonal p1, p2 = [-1.5, 0], [1.5, 1.5] xp, yp, distance, dp = gridder.profile(x, y, d, p1, p2, 100) dp_true = data(xp, yp) mpl.figure() mpl.subplot(2, 1, 2) mpl.title("Irregular grid") mpl.plot(xp, yp, '-k', label='Profile', linewidth=2) mpl.contourf(x, y, d, (100, 100), 50, interp=True) mpl.colorbar(orientation='horizontal') mpl.legend(loc='lower right') mpl.subplot(2, 1, 1) mpl.title('Profile') mpl.plot(distance, dp, '.b', label='Extracted') mpl.plot(distance, dp_true, '-k', label='True') mpl.xlim(distance.min(), distance.max()) mpl.legend(loc='lower right')
def slice_mesh(x, y, mesh, label, p1, p2, ax=None, interp=True, **kwargs): """ Get vertical xy section of the mesh at max/2 and plot it Parameters: * mesh Fatiando mesh type * scaled Txt here * label Txt here Txt here * markerMax Txt here """ if ax == None: fig = plt.subplots() ax = plt.gca() Xaxis = [] for key, value in kwargs.items(): if key == 'Xaxis': Xaxis = value image = mesh.props[label] toslice = np.reshape(image, [mesh.shape[0], mesh.shape[1] * mesh.shape[2]]) depths = mesh.get_zs()[:-1] x_resolution = 1000 Z = [] X = [] Y = [] DIST = [] IMG = [] z = 0 * np.ones_like(x) interp = True for i, depth in enumerate(depths - z[0]): # Loop for RII extremas u_layer = toslice[ i, :] # analysing extrema layers by layers from top to bottom if interp == True: xx, yy, distance, u_layer_p1p2 = gridder.profile( x, y, u_layer, p1, p2, x_resolution) else: xx, yy, distance, u_layer_p1p2, u_layer_p1p2_smooth = profile_noInter( x, y, u_layer, p1, p2, x_resolution) zz = depth * np.ones(len(u_layer_p1p2)) Z.append(zz) X.append(xx) Y.append(yy) DIST.append(distance) IMG.append(u_layer_p1p2) if 'dist' in Xaxis: xaxis = DIST else: xaxis = X cmap = ax.pcolormesh(np.array(xaxis), np.array(Z), np.array(IMG)) # if 'upwc' in label: # plt.gca().invert_yaxis() # ax.set_ylim(np.max(Z), np.min(Z)) # ax.set_xlim(np.max(xaxis), np.min(xaxis)) ax.set_xlabel('x (m)') ax.set_ylabel('z (m)') ax.set_title(label) ax.set_aspect('equal') return plt, cmap
def plot_line(x, y, data, p1, p2, ax=None, interp=True, **kwargs): Xaxis = [] Vminmax = [] smooth_type = False showfig = False vmin = min(data) vmax = max(data) limx = None limy = None x_resolution = None for key, value in kwargs.items(): if key == 'Xaxis': Xaxis = value if key == 'smooth': smooth_type = value if key == 'showfig': showfig = value if key == 'Vminmax': Vminmax = value vmin = Vminmax[0] vmax = Vminmax[1] if key == 'limx': limx = value if key == 'limy': limy = value if key == 'x_resolution': x_resolution = value # Extract a profile between points 1 and 2 if interp == False: xx, yy, distance, profile, vp_smooth_dict = dEXP.profile_noInter( x, y, data, p1, p2, size=x_resolution, showfig=showfig) # xx, yy, distance, profile, profile_smooth = dEXP.profile_extra(x, y, data, p1, p2, 1000) else: xx, yy, distance, profile = gridder.profile(x, y, data, p1, p2, 1000, 'nearest') if Xaxis is 'dist': xaxis = distance elif Xaxis is 'y': xaxis = xx else: xaxis = yy if smooth_type is not False: if smooth_type == True: profile = vp_smooth_dict['Lowpass'] else: profile = vp_smooth_dict[smooth_type] # Plot the profile and the original map data plt.figure() ax = ax or plt.gca() plt.subplot(1, 2, 1) # plt.title(strname + '_data' + str(ZZ), fontsize=15) plt.plot(xaxis, profile, '.k') # plt.xlim(xaxis.min(), xaxis.max()) plt.grid() if Xaxis is 'dist': plt.xlabel('distance (m)') elif Xaxis is 'y': plt.xlabel('x (m)') else: plt.xlabel('y (m)') plt.ylabel('voltage (V)') plt.subplot(1, 2, 2) plt.title("Original data") plt.plot(xx, yy, '-k', label='Profile', linewidth=2) # scale = np.abs([data.min(), data.max()]).max() # plt.tricontourf(x, y, data, 50, cmap='RdBu_r', vmin=min(data), vmax=max(data)) plt.scatter(x, y, c=data, cmap='RdBu_r', vmin=vmin, vmax=vmax) plt.colorbar(orientation='vertical', aspect=50) plt.legend(loc='lower right') plt.xlabel('x (m)') plt.ylabel('y (m)') plt.axis('square') if limx is not None: plt.xlim(limx[0], limx[1]) if limx is not None: plt.ylim(limy[0], limy[1]) # plt.tight_layout() for key, value in kwargs.items(): # print("{0} = {1}".format(key, value)) if key == 'title': plt.title(value, fontsize=15) if key == 'suptitle': plt.suptitle(value, fontsize=15) if key == 'savefig': if value == True: # plt.savefig(pathFig+ strname + '_data' + str(ZZ) + '.png') plt.savefig('fig2d.png', r=400) plt.show() return xx, yy, distance, profile, ax, plt
# remove B return electrode effects B = [-104.16666666666667, -104.16666666666667, 0] gz_cor = dEXP.cor_field_B(x, y, z, gz, B, rho=100) gz_cor = gz xp, yp, gz = gridder.interp(x, y, gz, shape) xp, yp, gz_cor = gridder.interp(x, y, gz_cor, shape) zp = 0 # # ------------------------------- Export for CWT analysis # # Extract a profile between points 1 and 2 p1, p2 = [min(xp), 0], [max(xp), 0] # p1, p2 = [0, min(xp)], [0, max(xp)] xx, yy, distance, profile = gridder.profile(xp, yp, gz, p1, p2, 1000) # xx, yy, distance, profile_cor = gridder.profile(xp, yp, gz_cor, p1, p2, 1000) # ------------------------------- Export for CWT analysis ## Extract a profile between points 1 and 2 #p1, p2 = [0.1, 0.1], [12000, 0.1] #xx, yy, distance, profile = gridder.profile(xp, yp, gz, p1, p2, 1000) # Plot the profile and the original map data plt.figure() plt.subplot(2, 1, 1) #plt.title(strname + '_ztop' + str(za) +'_zbot'+ str(zb), fontsize=15) plt.plot(distance, profile, '.k') # plt.plot(distance, profile_cor, '.r') plt.xlim(distance.min(), distance.max())
# remove B return electrode effects using :mod:`uEXP.cor_field_B` using a resistivity of 1 Ohm.m U_cor = uEXP.cor_field_B(xyzs[:-3, 0], xyzs[:-3, 1], xyzs[:-3, 2], uT_elecs, Bpos, rho=model_prop['SoilR']) #%% # Compare the voltage seen by the surface electrode using 2d plot over a line p1_elecs = [min(xyzs[:-3, 0]), (max(xyzs[:-3, 0]) + min(xyzs[:-3, 0])) / 2] p2_elecs = [max(xyzs[:-3, 0]), (max(xyzs[:-3, 0]) + min(xyzs[:-3, 0])) / 2] xx, yy, distance, profile = gridder.profile(xyzs[:-3, 0], xyzs[:-3, 1], uT_elecs, p1_elecs, p2_elecs, 1000) plt.figure() # plt.title(strname + '_data' + str(ZZ), fontsize=15) plt.plot(xx, profile, '.k', label='Raw') xx, yy, distance, profile = gridder.profile(xyzs[:-3, 0], xyzs[:-3, 1], U_cor, p1_elecs, p2_elecs, 1000) plt.plot(xx, profile, '.r', label='Corrected') plt.grid() plt.xlabel('x (m)') plt.ylabel('u (V)') plt.legend()
# Generate random points x, y = gridder.scatter((-2, 2, -2, 2), n=300, seed=1) # And calculate 2D Gaussians on these points as sample data def data(x, y): return (utils.gaussian2d(x, y, -0.6, -1) - utils.gaussian2d(x, y, 1.5, 1.5)) d = data(x, y) # Extract a profile along the diagonal p1, p2 = [-1.5, 0], [1.5, 1.5] xp, yp, distance, dp = gridder.profile(x, y, d, p1, p2, 100) dp_true = data(xp, yp) mpl.figure() mpl.subplot(2, 1, 2) mpl.title("Irregular grid") mpl.plot(xp, yp, '-k', label='Profile', linewidth=2) mpl.contourf(x, y, d, (100, 100), 50, interp=True) mpl.colorbar(orientation='horizontal') mpl.legend(loc='lower right') mpl.subplot(2, 1, 1) mpl.title('Profile') mpl.plot(distance, dp, '.b', label='Extracted') mpl.plot(distance, dp_true, '-k', label='True') mpl.xlim(distance.min(), distance.max()) mpl.legend(loc='lower right')
The function :func:`fatiando.gridder.profile` can be used to extract a profile of data from a map. It interpolates the data onto the profile points so you can specify the profile in any direction and use irregular point data as input. """ import matplotlib.pyplot as plt import numpy as np from fatiando import gridder, utils # Generate random points x, y = gridder.scatter((-2, 2, -2, 2), n=1000, seed=1) # And calculate 2D Gaussians on these points as sample data data = 2*utils.gaussian2d(x, y, -0.6, -1) - utils.gaussian2d(x, y, 1.5, 1.5) # Extract a profile between points 1 and 2 p1, p2 = [-1.5, -0.5], [1.5, 1.5] xp, yp, distance, profile = gridder.profile(x, y, data, p1, p2, 100) # Plot the profile and the original map data plt.figure() plt.subplot(2, 1, 1) plt.title('Extracted profile points') plt.plot(distance, profile, '.k') plt.xlim(distance.min(), distance.max()) plt.grid() plt.subplot(2, 1, 2) plt.title("Original data") plt.plot(xp, yp, '-k', label='Profile', linewidth=2) scale = np.abs([data.min(), data.max()]).max() plt.tricontourf(x, y, data, 50, cmap='RdBu_r', vmin=-scale, vmax=scale) plt.colorbar(orientation='horizontal', aspect=50) plt.legend(loc='lower right')
The function :func:`fatiando.gridder.profile` can be used to extract a profile of data from a map. It interpolates the data onto the profile points so you can specify the profile in any direction and use irregular point data as input. """ import matplotlib.pyplot as plt import numpy as np from fatiando import gridder, utils # Generate random points x, y = gridder.scatter((-2, 2, -2, 2), n=1000, seed=1) # And calculate 2D Gaussians on these points as sample data data = 2 * utils.gaussian2d(x, y, -0.6, -1) - utils.gaussian2d(x, y, 1.5, 1.5) # Extract a profile between points 1 and 2 p1, p2 = [-1.5, -0.5], [1.5, 1.5] xp, yp, distance, profile = gridder.profile(x, y, data, p1, p2, 100) # Plot the profile and the original map data plt.figure() plt.subplot(2, 1, 1) plt.title('Extracted profile points') plt.plot(distance, profile, '.k') plt.xlim(distance.min(), distance.max()) plt.grid() plt.subplot(2, 1, 2) plt.title("Original data") plt.plot(xp, yp, '-k', label='Profile', linewidth=2) scale = np.abs([data.min(), data.max()]).max() plt.tricontourf(x, y, data, 50, cmap='RdBu_r', vmin=-scale, vmax=scale) plt.colorbar(orientation='horizontal', aspect=50) plt.legend(loc='lower right')