relief = mesher.PrismRelief(0, gridder.spacing(area, shape), nodes) relief.addprop('density', (2670 for i in xrange(relief.size))) gridarea = (-80, 80, -220, 220) gridshape = (100, 100) xp, yp, zp = gridder.regular(gridarea, gridshape, z=-200) gz = prism.gz(xp, yp, zp, relief) mpl.figure(figsize=(10, 7)) mpl.subplot(1, 2, 1) mpl.title("Synthetic topography") mpl.axis('scaled') mpl.pcolor(x, y, height, shape) cb = mpl.colorbar() cb.set_label("meters") mpl.square(gridarea, label='Computation grid') mpl.legend() mpl.subplot(1, 2, 2) mpl.title("Topographic effect") mpl.axis('scaled') mpl.pcolor(xp, yp, gz, gridshape) cb = mpl.colorbar() cb.set_label("mGal") mpl.show() myv.figure() myv.prisms(relief, prop='density') axes = myv.axes(myv.outline()) myv.wall_bottom(axes.axes.bounds, opacity=0.2) myv.wall_north(axes.axes.bounds) myv.show()
fig = plt.figure() ax = plt.gca() pEXP.plot_xy(mesh, label=label_prop, ax=ax) #, ldg=) pEXP.plot_ridges_harmonic(dfI_f, dfII_f, dfIII_f, ax=ax, label=True) df_fit = dEXP.fit_ridges(df_f, rmvOutliers=True) # fit ridges on filtered data # pEXP.plot_ridges_sources(df_fit, ax=ax, z_max_source=-max_elevation*1.2, # ridge_type=[0,1,2],ridge_nb=None) pEXP.plot_ridges_sources(df_fit, ax=ax, z_max_source=-6000, ridge_type=[0, 1, 2], ridge_nb=None) square([x1, x2, -z1, -z2]) plt.annotate(dens, [(x1 + x2) / 2, -(z1 + z2) / 2]) #%% # ridges analysis z0 = -2000 points, fit, SI, EXTnb = dEXP.scalFUN(dfI_f, EXTnb=[1], z0=z0) pEXP.plot_scalFUN(points, fit, z0=z0) # z0 = -2000 # points, fit, SI, EXTnb = dEXP.scalFUN(dfI_f,EXTnb=[3],z0=z0) # pEXP.plot_scalFUN(points, fit, z0=z0) #%% # ridges analysis
#%% plt.figure() ax = plt.gca() i = 0 pEXP.plot_xy(MESH[i], label=LABEL[i], ax=ax) #, ldg=) dfI_f, dfII_f, dfIII_f = DF_F[i] pEXP.plot_ridges_harmonic(dfI_f, dfII_f, dfIII_f, ax=ax, label=False) pEXP.plot_ridges_sources(DF_FIT[i], ax=ax, z_max_source=-max_elevation * 1.2, ridge_type=[0, 1, 2], ridge_nb=None) x1, x2, z1, z2 = XXZZ[i] square([x1, x2, z1, z2]) plt.annotate(CTm[i], [(x1 + x2) / 2, (z1 + z2) / 2]) plt.figure() ax = plt.gca() i = 1 pEXP.plot_xy(MESH[i], label=LABEL[i], ax=ax) #, ldg=) dfI_f, dfII_f, dfIII_f = DF_F[i] pEXP.plot_ridges_harmonic(dfI_f, dfII_f, dfIII_f, ax=ax, label=False) pEXP.plot_ridges_sources(DF_FIT[i], ax=ax, z_max_source=-max_elevation * 1.2, ridge_type=[0, 1, 2], ridge_nb=None) x1, x2, z1, z2 = XXZZ[i]
ax.set_ylabel('x (km)') # Then plot model slices in the x, y, z directions through the middle of the # model. Also show the outline of the true model for comparison. scale = 0.1*np.abs([image.min(), image.max()]).max() x = mesh.get_xs()/1000 y = mesh.get_ys()/1000 z = mesh.get_zs()/1000 x1, x2, y1, y2, z1, z2 = np.array(model[0].get_bounds())/1000 ax = plt.subplot(2, 2, 2) ax.set_title('Model slice at z={} km'.format(z[len(z)//2])) ax.set_aspect('equal') ax.pcolormesh(y, x, image[mesh.shape[0]//2, :, :], cmap="cubehelix", vmin=-scale, vmax=scale) square([y1, y2, x1, x2]) ax.set_ylim(x.min(), x.max()) ax.set_xlim(y.min(), y.max()) ax.set_xlabel('y (km)') ax.set_ylabel('x (km)') ax = plt.subplot(2, 2, 3) ax.set_title('Model slice at y={} km'.format(y[len(y)//2])) ax.set_aspect('equal') ax.pcolormesh(x, z, image[:, :, mesh.shape[1]//2], cmap="cubehelix", vmin=-scale, vmax=scale) square([x1, x2, z1, z2]) ax.set_ylim(z.max(), z.min()) ax.set_xlim(x.min(), x.max()) ax.set_xlabel('x (km)') ax.set_ylabel('z (km)')
p1 = [(x1 + x2) / 2, min(yp)] p2 = [(x1 + x2) / 2, max(yp)] x_axis = slicedir[1] # direction of p1p2 profil SI = 1.5 else: p1 = [min(xp), (y1 + y2) / 2] p2 = [max(xp), (y1 + y2) / 2] x_axis = slicedir[1] # direction of p1p2 profil SI = 2 #%% # Plot field data over a 2d line crossing the anomalies # pEXP.plot_line(xp, yp, U,p1,p2, interp=False, Xaxis='x') pEXP.plot_line(xp, yp, U, p1, p2, interp=True, Xaxis=x_axis) square([x1, x2, y1, y2]) pEXP.plot_field(xp, yp, U, shape) square([x1, x2, y1, y2]) # Gaussian function to derivate #%% ------------------------------- Plot the derivatives # http://campar.in.tum.de/Chair/HaukeHeibelGaussianDerivatives xderiv = transform.derivx(xp, yp, U, shape, order=qorder) yderiv = transform.derivy(xp, yp, U, shape, order=qorder) zderiv = transform.derivz(xp, yp, U, shape, order=qorder) # # plt.plot(xderiv) # # plt.plot(yderiv)
fig = plt.figure() ax = plt.gca() pEXP.plot_xy(mesh, label=label_prop, ax=ax) #, ldg=) pEXP.plot_ridges_harmonic(dfI_f, dfII_f, dfIII_f, ax=ax, label=True) df_fit = dEXP.fit_ridges(df_f, rmvOutliers=True) # fit ridges on filtered data # pEXP.plot_ridges_sources(df_fit, ax=ax, z_max_source=-max_elevation*1.2, # ridge_type=[0,1,2],ridge_nb=None) pEXP.plot_ridges_sources(df_fit, ax=ax, z_max_source=-6000, ridge_type=[0, 1, 2], ridge_nb=None) square([x1, x2, -z1, -z2]) plt.annotate(dens, [(x1 + x2) / 2, -(z1 + z2) / 2]) #%% # ridges analysis: scaling function to determine the SI index z0 = -(z1 + z2) / 2 + 100 # choose an estimate of the depth of the anomaly # z0 = -100 # choose an estimate of the depth of the anomaly df_height = D_f[3:6] ncol = 0 for r_type in range(len(df_height)): # loop over ridges type I, II, III ncol = ncol + df_f[r_type].shape[1] - 1 fig, axs = plt.subplots(1, ncol, figsize=(15, 6), facecolor='w', edgecolor='k') # fig.subplots_adjust(hspace = .5, wspace=.001)
#plt.savefig(pathFig+ strname + '_ExempleFig_prof' + str(za) + str(zb) + '.png') # ------------------------------- Plot the data plt.figure() plt.axis('scaled') mpl.contourf(yp, xp, gz, shape, 30) plt.colorbar() plt.xlabel('East (km)') plt.ylabel('North (km)') mpl.m2km() plt.show() #plt.title(strname +'ztop' + str(za) +'_zbot'+ str(zb) + '_data', fontsize=20) #plt.savefig(pathFig+strname + '_ExempleFig_z' + str(za) + str(zb) + '_data' + '.png') #x1, x2, y1, y2, z1, z2 = np.array(model[0].get_bounds()) square([y1, y2, x1, x2]) # %% ------------------------------- derivatives xderiv = transform.derivx(xp, yp, gz, shape, order=1) yderiv = transform.derivy(xp, yp, gz, shape) zderiv = transform.derivz(xp, yp, gz, shape, order=1) plt.subplots_adjust() levels = 30 cbargs = dict(orientation='horizontal') ax = plt.subplot(1, 3, 1) plt.axis('scaled') plt.title('x derivative') mpl.contourf(yp, xp, xderiv, shape, levels, cmap=plt.cm.RdBu_r)
""" GravMag: Calculate the gravity gradient tensor invariants """ import numpy from fatiando import mesher, gridder from fatiando.gravmag import polyprism, tensor from fatiando.vis import mpl print "Draw the polygons one by one" area = [-10000, 10000, -10000, 10000] dataarea = [-5000, 5000, -5000, 5000] model = [] for depth in [5000, 5000]: fig = mpl.figure() mpl.axis('scaled') mpl.square(dataarea) for p in model: mpl.polygon(p, '.-k', xy2ne=True) mpl.set_area(area) model.append( mesher.PolygonalPrism( mpl.draw_polygon(area, fig.gca(), xy2ne=True), 0, depth, {'density':500})) # Calculate the effect shape = (100, 100) xp, yp, zp = gridder.regular(dataarea, shape, z=-500) data = [ polyprism.gxx(xp, yp, zp, model), polyprism.gxy(xp, yp, zp, model), polyprism.gxz(xp, yp, zp, model), polyprism.gyy(xp, yp, zp, model),
""" Gridding: Cut a section from a grid """ from fatiando import gridder, utils from fatiando.vis import mpl # Generate some synthetic data on a regular grid x, y = gridder.regular((-10, 10, -10, 10), (100,100)) # Using a 2D Gaussian z = utils.gaussian2d(x, y, 1, 1) subarea = [-2, 2, -3, 3] subx, suby, subscalar = gridder.cut(x, y, [z], subarea) mpl.figure(figsize=(12, 5)) mpl.subplot(1, 2, 1) mpl.title("Whole grid") mpl.axis('scaled') mpl.pcolor(x, y, z, (100,100)) mpl.square(subarea, 'k', linewidth=2, label='Cut this region') mpl.legend(loc='lower left') mpl.subplot(1, 2, 2) mpl.title("Cut grid") mpl.axis('scaled') mpl.pcolor(subx, suby, subscalar[0], (40,60), interp=True) mpl.show()
relief = mesher.PrismRelief(0, gridder.spacing(area,shape), nodes) relief.addprop('density', (2670 for i in xrange(relief.size))) gridarea = (-80, 80, -220, 220) gridshape = (100, 100) xp, yp, zp = gridder.regular(gridarea, gridshape, z=-200) gz = gravmag.prism.gz(xp, yp, zp, relief) mpl.figure(figsize=(10,7)) mpl.subplot(1, 2, 1) mpl.title("Synthetic topography") mpl.axis('scaled') mpl.pcolor(x, y, height, shape) cb = mpl.colorbar() cb.set_label("meters") mpl.square(gridarea, label='Computation grid') mpl.legend() mpl.subplot(1, 2, 2) mpl.title("Topographic effect") mpl.axis('scaled') mpl.pcolor(xp, yp, gz, gridshape) cb = mpl.colorbar() cb.set_label("mGal") mpl.show() myv.figure() myv.prisms(relief, prop='density') axes = myv.axes(myv.outline()) myv.wall_bottom(axes.axes.bounds, opacity=0.2) myv.wall_north(axes.axes.bounds) myv.show()
import numpy from fatiando import logger, mesher, gridder, gravmag from fatiando.vis import mpl log = logger.get() log.info(logger.header()) log.info(__doc__) log.info("Draw the polygons one by one") area = [-10000, 10000, -10000, 10000] dataarea = [-5000, 5000, -5000, 5000] prisms = [] for depth in [5000, 5000]: fig = mpl.figure() mpl.axis('scaled') mpl.square(dataarea) for p in prisms: mpl.polygon(p, '.-k', xy2ne=True) mpl.set_area(area) prisms.append( mesher.PolygonalPrism(mpl.draw_polygon(area, fig.gca(), xy2ne=True), 0, depth, {'density': 500})) # Calculate the effect shape = (100, 100) xp, yp, zp = gridder.regular(dataarea, shape, z=-500) tensor = [ gravmag.polyprism.gxx(xp, yp, zp, prisms), gravmag.polyprism.gxy(xp, yp, zp, prisms), gravmag.polyprism.gxz(xp, yp, zp, prisms), gravmag.polyprism.gyy(xp, yp, zp, prisms), gravmag.polyprism.gyz(xp, yp, zp, prisms),
plt, cmap = pEXP.plot_xy(mesh_dexp, label=label_dexp, markerMax=True, qratio=str(qratio), Vminmax=[0, 0.075], p1p2=np.array([p1_s, p2_s]), ax=ax, Xaxis=x_axis) #, ldg=) # plt, cmap = pEXP.plot_xy(mesh_dexp, label=label_dexp, # markerMax=True,qratio=str(qratio) # ax=ax, Xaxis=x_axis) #, ldg=) cbar = plt.colorbar(cmap, shrink=0.25, pad=0.04) cbar.set_label('ratio voltage (V)') if x_axis == 'y': square([xA_r_new[0], xA_r_new[1], -z1, -z2]) else: square([yA_r[0], yA_r[1], -z1, -z2]) plt.xlim([200, 600]) plt.savefig('ratios_' + str(file) + '.png', dpi=450) # %% ridges identification dEXP.ridges_minmax_plot(Xs, Ys, mesh, p1_s, p2_s, label=label_prop, interp=interp, x_resolution=interp_size,
ax = plt.gca() plt, cmap = pEXP.plot_xy(mesh_dexp, scaled=0, label=label_dexp, markerMax=True, qratio=str(qratio), p1p2=np.array([p1_s, p2_s]), ax=ax, Xaxis=x_axis) #, ldg=) # plt, cmap = pEXP.plot_xy(mesh_dexp, label=label_dexp, # markerMax=True,qratio=str(qratio) # ax=ax, Xaxis=x_axis) #, ldg=) plt.colorbar(cmap) if x_axis == 'y': square([xA_r[0], xA_r[1], -z1, -z2]) # plt.annotate('\Omega',[x1, -(z1+z2)/2]) else: square([yA_r[0], yA_r[1], -z1, -z2]) # plt.annotate('\Omega',[(y1 + y2)/2, -(z1+z2)/2]) # p1p2=np.array([p1_r,p2_r]) # p_xaxis = [] # for i in p1p2[0]: # if(i in p1p2[1]): # p_xaxis.append(i) #%% ------------------------------- ridges identification # import Find_peaks_Du_et_al_2006 as fpeak # from Find_peaks_Du_et_al_2006 import _boolrelextrema, _identify_ridge_lines, _filter_ridge_lines
scale = 0.1 * np.abs([image.min(), image.max()]).max() x = mesh.get_xs() / 1000 y = mesh.get_ys() / 1000 z = mesh.get_zs() / 1000 x1, x2, y1, y2, z1, z2 = np.array(model[0].get_bounds()) / 1000 ax = plt.subplot(2, 2, 2) ax.set_title('Model slice at z={} km'.format(z[len(z) // 2])) ax.set_aspect('equal') ax.pcolormesh(y, x, image[mesh.shape[0] // 2, :, :], cmap="cubehelix", vmin=-scale, vmax=scale) square([y1, y2, x1, x2]) ax.set_ylim(x.min(), x.max()) ax.set_xlim(y.min(), y.max()) ax.set_xlabel('y (km)') ax.set_ylabel('x (km)') ax = plt.subplot(2, 2, 3) ax.set_title('Model slice at y={} km'.format(y[len(y) // 2])) ax.set_aspect('equal') ax.pcolormesh(x, z, image[:, :, mesh.shape[1] // 2], cmap="cubehelix", vmin=-scale, vmax=scale) square([x1, x2, z1, z2])
""" Gridding: Cut a section from a grid """ from fatiando import gridder, utils from fatiando.vis import mpl # Generate some synthetic data on a regular grid x, y = gridder.regular((-10, 10, -10, 10), (100, 100)) # Using a 2D Gaussian z = utils.gaussian2d(x, y, 1, 1) subarea = [-2, 2, -3, 3] subx, suby, subscalar = gridder.cut(x, y, [z], subarea) mpl.figure(figsize=(12, 5)) mpl.subplot(1, 2, 1) mpl.title("Whole grid") mpl.axis('scaled') mpl.pcolor(x, y, z, (100, 100)) mpl.square(subarea, 'k', linewidth=2, label='Cut this region') mpl.legend(loc='lower left') mpl.subplot(1, 2, 2) mpl.title("Cut grid") mpl.axis('scaled') mpl.pcolor(subx, suby, subscalar[0], (40, 60), interp=True) mpl.show()