def run_script(args): # ## Make a new string buffer # in_buf = StringIO.StringIO() # ## Write the decoded string into the buffer # buf.write(base64.b64decode(args.wireframe)) # ## Move to the start of the buffer # in_buf.seek(0) ## Open the image in PIL #image = Image.open(buf) processed_data = image_segment(args.wireframe) #plt.imshow(processed_data) #image = get_figure_data() dt = .01 t = 1.0 f = 1. wave = ricker(t, dt, f) seismic = [ np.convolve(wave, i, mode='same') for i in np.transpose(processed_data) ] plt.imshow(seismic) image = get_figure_data() return (image, )
def run_script(args): # ## Make a new string buffer # in_buf = StringIO.StringIO() # ## Write the decoded string into the buffer # buf.write(base64.b64decode(args.wireframe)) # ## Move to the start of the buffer # in_buf.seek(0) ## Open the image in PIL #image = Image.open(buf) processed_data = image_segment(args.wireframe) #plt.imshow(processed_data) #image = get_figure_data() dt = .01 t = 1.0 f= 1. wave = ricker(t,dt,f) seismic = [np.convolve(wave, i, mode='same') for i in np.transpose(processed_data)] plt.imshow(seismic) image = get_figure_data() return (image,)
def run_script(earth_model, seismic_model, args): fig =plt.figure() gs = gridspec.GridSpec(1, 2,width_ratios=[4,1]) axarr = [plt.subplot(gs[0]), plt.subplot(gs[1])] seismic_model.go(earth_model, theta=args.theta) seismic_data = seismic_model.seismic t = seismic_model.dt * np.arange(seismic_data.shape[0]) axarr[0].imshow(seismic_data[:,:, 0, 0],aspect='auto', extent=[0, seismic_data.shape[1], t[-1], t[0]], cmap='Greys') axarr[0].axvline(x=args.trace, lw=3, color='b') axarr[0].set_title('spatial cross-section') axarr[1].plot(seismic_data[:,args.trace,0,0], t) plt.gca().invert_yaxis() axarr[1].axis('tight') """ seismic_model.go(earth_model, traces=[args.trace]) seismic_data = seismic_model.seismic axarr[1].imshow(seismic_data[:, 0, :, 0], aspect='auto') axarr[1].axvline(x=args.theta, lw=3, color='b') axarr[1].set_title('angle cross-section') seismic_model.go(earth_model, theta=args.theta, traces=[args.trace]) seismic_data = seismic_model.seismic """ """ axarr[2].imshow(seismic_data[:,0, 0, :], aspect='auto') axarr[2].axvline(x=args.f, lw=3, color='b') axarr[2].set_title('wavelet cross-section') """ fig.tight_layout() return get_figure_data()
def run_script(args): matplotlib.interactive(False) args.plot_type = 'dashboard' Rprop0 = args.Rock0 Rprop1 = args.Rock1 theta = np.arange(0,90) vp0, vs0, rho0 = make_normal_dist( Rprop0, args.iterations ) vp1, vs1, rho1 = make_normal_dist( Rprop1, args.iterations ) reflect = [] hist_titles = [[r'$V_\mathrm{P}$' , r'$m/s$'], [r'$V_\mathrm{S}$' , r'$m/s$'], [r'$\rho$' , r'$kg / m^3$']] nbins = 15 vp_lim = ( np.amin((Rprop1.vp - ( 3.* Rprop1.vp_sig ), Rprop0.vp - ( 3.* Rprop1.vp_sig ) ) ), np.amax((Rprop1.vp + ( 3.* Rprop1.vp_sig ), Rprop0.vp + ( 3.* Rprop1.vp_sig ) ) ) ) vs_lim = ( np.amin((Rprop1.vs - ( 3.* Rprop1.vs_sig ), Rprop0.vs - ( 3.* Rprop1.vs_sig ) ) ), np.amax((Rprop1.vs + ( 3.* Rprop1.vs_sig ), Rprop0.vs + ( 3.* Rprop1.vs_sig ) ) ) ) rho_lim = ( np.amin((Rprop1.rho - ( 3.* Rprop1.rho_sig ), Rprop0.rho - ( 3.* Rprop1.rho_sig ) ) ), np.amax((Rprop1.rho + ( 3.* Rprop1.rho_sig ), Rprop0.rho + ( 3.* Rprop1.rho_sig ) ) ) ) limits = np.array([[ vp_lim, vs_lim, rho_lim ], [ vp_lim, vs_lim, rho_lim ] ]) for i in range( args.iterations ): reflect.append(args.reflectivity_method(vp0[i], vs0[i], rho0[i], vp1[i], vs1[i], rho1[i], theta)) reflect = np.array(reflect) reflect = np.nan_to_num(reflect) #temp = np.concatenate( (vp0, rho0, vs0, vp1, rho1, vs1,), axis=0) temp = np.concatenate((vp0, vs0, rho0, vp1, vs1, rho1), axis=0) prop_samples = np.reshape(temp, (6, args.iterations)) ave_reflect = np.mean(reflect,axis=0) nbins = 15 # DO PLOTTING plt.figure(figsize = (5,13)) plt.subplots_adjust(bottom=0.1, left=0.1, top = 1, right=0.9) plt.hold(True) if args.plot_type == 'dashboard': G = matplotlib.gridspec.GridSpec(9,2, hspace=0.5) shift=3 else: G = matplotlib.gridspec.GridSpec(2,6) shift=0 # histogram plots (ax_3, ax_4, ax_5, ax_6, ax_7, ax_8) hist_max = 0 for k in np.arange(len(prop_samples)): # find the max bar height of the histogram for scaling the plots hist_max = max(hist_max,max(np.histogram(prop_samples[k], density=True)[0])) for j in np.arange(2): upper_color = 'blue' #color of upper histogram lower_color = 'green' #color of lower histogram for i in np.arange(3): plt.subplot(G[3+i+shift,0]) plt.hist( prop_samples[i], nbins, facecolor = upper_color, histtype='stepfilled', alpha = 0.25 ,normed = True ) plt.hist( prop_samples[i+(3)], nbins, facecolor = lower_color, histtype='stepfilled', alpha = 0.25 ,normed = True ) temp = plt.gca() # Annotation and making it look nice plt.axis([limits[j][i][0], limits[j][i][1], temp.axis()[2], hist_max ]) plt.yticks([]) plt.xticks( rotation=90,horizontalalignment='left' ) ax = plt.gca() ax.spines['right'].set_color('none') ax.spines['left'].set_color('none') ax.spines['top'].set_color('none') ax.spines['bottom'].set_alpha(0.5) for label in ax.get_xticklabels() + ax.get_yticklabels(): label.set_fontsize(6) label.set_alpha(0.5) for tick in ax.xaxis.get_major_ticks(): tick.tick1On = True tick.tick2On = False # upper text label mean_props = [ [ Rprop0.vp, Rprop1.vp ], [ Rprop0.vs, Rprop1.vs ], [ Rprop0.rho, Rprop1.rho ] ] which_label = ['upper','lower'] # Main label ax.text( x = limits[0,i,1], y = hist_max * 0.5, s = hist_titles[i][0], color='black', fontsize=14, alpha=0.75, horizontalalignment = 'left', verticalalignment = 'center' ) # Label for units ax.text( x = limits[0,i,1], y = hist_max * 0.25, s = hist_titles[i][1], color='black', fontsize=10, alpha=0.75, horizontalalignment = 'left', verticalalignment = 'center' ) ax.text( x=float(mean_props[i][0]), y=hist_max / 5.0, s = which_label[0], alpha=0.75, color=upper_color, fontsize = '9', horizontalalignment = 'center', verticalalignment = 'center', ) #lower text label ax.text( x = float(mean_props[i][1]), y = hist_max / 5.0, s = which_label[1], alpha=0.75, color=lower_color, fontsize = '9', horizontalalignment = 'center', verticalalignment = 'center' ) # # ax_1 the AVO plot # plt.subplot(G[0:3,:]) plt.hold(True) critical_angles = [] for i in range( args.iterations -1): # Do the AVO template as an underlay # HERE # Do the plots --> This step might not need to be in a loop plt.plot( theta, reflect[i] ,color = 'grey', lw = 1.0, alpha = np.min((30./args.iterations, 0.08))) if vp1[i] > vp0[i]: theta_crit = arcsin( vp0[i] / vp1[i] )*180/np.pi plt.axvline( x= theta_crit , color='black', lw = 1.0, alpha = np.min((30./args.iterations, 0.5))) critical_angles.append(theta_crit) if len(critical_angles) > 0: critical_angle = np.mean(critical_angles) else: critical_angle = 'N/A' plt.plot( theta, ave_reflect, color='black', alpha = 0.5, lw= 1.5 ) plt.grid() # Annotation and making it look nice ax = plt.gca() ax.spines['right'].set_color('none') ax.spines['top'].set_color('none') ax.xaxis.set_ticks_position('bottom') ax.spines['bottom'].set_position(('data',0)) ax.spines['bottom'].set_alpha(0.5) ax.yaxis.set_ticks_position('left') ax.spines['left'].set_position(('data',0)) ax.spines['left'].set_alpha(0.5) for label in ax.get_xticklabels() + ax.get_yticklabels(): label.set_fontsize(6) label.set_alpha(0.5) plt.grid() plt.ylim((-.5,.5)) ax.text(0.95, 0.45, 'angle', verticalalignment='top', horizontalalignment='right', transform=ax.transAxes, color='black', fontsize=8, alpha=0.5) ax.text(0.05, 0.95, 'amplitude', verticalalignment='top', horizontalalignment='right', transform=ax.transAxes, rotation=90, color='black', fontsize=8, alpha=0.5) # # Patches for the Background template AVO plot STARTS here # a1 = 0.10 # transparency for AVO background template patches rangex = 90 band = 0.04 # thickness of Class 2 band # CLASS 1 Path1 = mpath.Path path_data1 = [ (Path1.MOVETO, (rangex * 0, 0.04)), (Path1.CURVE4, (rangex *0.4, 0.05)), (Path1.CURVE4, (rangex *0.6, -0.015)), (Path1.CURVE4, (rangex *1.0, -band)), (Path1.LINETO, (rangex *1.0, 1.0)), (Path1.LINETO, (rangex *0.0, 1.0)), (Path1.CLOSEPOLY, (rangex *0.0, 1.0)), ] codes1, verts1 = zip(*path_data1) path1 = mpath.Path(verts1, codes1) patch1 = mpatches.PathPatch(path1, facecolor='r', alpha=a1, ec = 'none') ax.add_patch(patch1) # plot control points and connecting lines x1, y1 = zip(*path1.vertices) #line1, = ax.plot(x1, y1, 'go-') # CLASS 2p Path2P = mpath.Path path_data2P = [ (Path2P.MOVETO, (rangex * 0, band)), (Path2P.CURVE4, (rangex * 0.4, 0.05)), (Path2P.CURVE4, (rangex * 0.6, -0.015)), (Path2P.CURVE4, (rangex * 1.0, - band)), (Path2P.LINETO, (rangex * 1.0, - (band + band) )), (Path2P.CURVE4, (rangex * 0.6, -(0.015 + band))), (Path2P.CURVE4, (rangex * 0.4, 0.05 - band)), (Path2P.CURVE4, (rangex * 0.0, 0.0)), (Path2P.CLOSEPOLY, (rangex * 0.0, 0.0)), ] codes2P, verts2P = zip(*path_data2P) path2P = mpath.Path(verts2P, codes2P) patch2P = mpatches.PathPatch(path2P, facecolor='yellow', alpha=a1, ec = 'none') ax.add_patch(patch2P) # plot control points and connecting lines x2, y2 = zip(*path2P.vertices) #line2, = ax.plot(x2, y2, 'ro-') # CLASS 2 Path2 = mpath.Path path_data2 = [ (Path2.MOVETO, (rangex * 0.0, 0.0)), (Path2.CURVE4, (rangex * 0.4, 0.05 - band)), (Path2.CURVE4, (rangex * 0.6, -(0.015 + band))), (Path2.CURVE4, (rangex * 1.0, - (band + band))), (Path2.LINETO, (rangex * 1.0, - (3 * band))), (Path2.CURVE4, (rangex * 0.6, - (0.015 + 2*band))), (Path2.CURVE4, (rangex * 0.4, 0.05 - (0.0 + 2*band))), (Path2.CURVE4, (rangex * 0.0, - band)), (Path2.CLOSEPOLY, (rangex * 0.0, 0.0)), ] codes2, verts2 = zip(*path_data2) path2 = mpath.Path(verts2, codes2) patch2 = mpatches.PathPatch(path2, facecolor='green', alpha=a1, ec = 'none') ax.add_patch(patch2) # plot control points and connecting lines x2, y2 = zip(*path2.vertices) #line2, = ax.plot(x2, y2, 'ro-') # CLASS 3 Path3 = mpath.Path path_data3 = [ (Path3.MOVETO, (rangex * 0.0, - band)), (Path3.CURVE4, (rangex * 0.4, 0.05 - (0.0 + 2*band))), (Path3.CURVE4, (rangex * 0.6, - (0.015 + 2*band))), (Path3.CURVE4, (rangex * 1.0, - (3 * band))), (Path3.LINETO, (rangex * 1.0, -1.0)), (Path3.LINETO, (rangex * 0.0, -1.0)), (Path3.CLOSEPOLY, (rangex * 0.0, -1.0)), ] codes3, verts3 = zip(*path_data3) path3 = mpath.Path(verts3, codes3) patch3 = mpatches.PathPatch(path3, facecolor='blue', alpha=a1, ec = 'none') ax.add_patch(patch3) # plot control points and connecting lines x3, y3 = zip(*path3.vertices) #line2, = ax.plot(x2, y2, 'ro-') ax.grid() ax.text(0.98, 0.98, 'Amplitude vs angle', verticalalignment='top', horizontalalignment='right', transform=ax.transAxes, color='black', fontsize=9, fontweight = 'bold', alpha=0.5) ax.spines['right'].set_color('none') ax.spines['top'].set_color('none') ax.xaxis.set_ticks_position('bottom') ax.spines['bottom'].set_position(('data',0)) ax.yaxis.set_ticks_position('left') ax.spines['left'].set_position(('data',0)) for label in ax.get_xticklabels() + ax.get_yticklabels(): label.set_fontsize(8) label.set_alpha(0.5) plt.grid() # Class 1 label # y-values for class labels 1,2p, 2, 3, and 4 respectively ylabelcntrs = [ 0.35, 0.025, -0.025, -0.4, -0.2 ] xctrs = 10 fs = 10 # fontsize a2 = 0.4 # transparency value for Gradient vs Intercept text ax.text( xctrs, ylabelcntrs[0], 'CLASS 1', verticalalignment='center', horizontalalignment='left', color='red', fontsize=fs, fontweight = 'bold', alpha=a2) # Class 2p label ax.text( xctrs, ylabelcntrs[1], 'CLASS 2p', verticalalignment='center', horizontalalignment='left', rotation = -3, color='#EEC900', fontsize=fs, fontweight = 'bold', alpha=a2 * 1.5) # Class 2 label ax.text( xctrs, ylabelcntrs[2], 'CLASS 2', verticalalignment='center', horizontalalignment='left', rotation = -3, color='green', fontsize=fs, fontweight = 'bold', alpha=a2) # Class 3 label ax.text( xctrs, ylabelcntrs[3], 'CLASS 3', verticalalignment='center', horizontalalignment='left', rotation = -15, color='blue', fontsize=fs, fontweight = 'bold', alpha=a2) # Class 4 label ax.text( xctrs, ylabelcntrs[4], 'CLASS 4', verticalalignment='center', horizontalalignment='left', rotation = 15, color='#B048B5', fontsize=fs, fontweight = 'bold', alpha=a2) # # Patches for background template AVO plot ENDS here # # ax_2 the AB plot plt.subplot(G[0+shift:3+shift,:]) plt.hold(True) max_ang = args.max_angle # Max ang for computing gradient for i in range( args.iterations -1): plt.scatter( reflect[i,0], (reflect[i,max_ang]-reflect[i,0] ), color = 'grey' , s = 20, alpha = np.max((30./args.iterations, 0.2)) ) # Plot the average of the dots plt.scatter( ave_reflect[0], ave_reflect[max_ang]- ave_reflect[0], color = 'black' , s = 40, alpha= 0.5 ) # Annotation and making it nice plt.xticks([]), plt.yticks([]) ax = plt.gca() ax.spines['right'].set_color('none') ax.spines['top'].set_color('none') ax.xaxis.set_ticks_position('bottom') ax.spines['bottom'].set_position(('data',0)) ax.spines['bottom'].set_alpha(0.5) ax.yaxis.set_ticks_position('left') ax.spines['left'].set_position(('data',0)) ax.spines['left'].set_alpha(0.5) plt.grid() # axis limits ylimits = (np.amin((-.3,np.nanmin(reflect[:,50]-reflect[:,0]))), np.amax((.3,np.nanmax(reflect[:,50]-reflect[:,0])))) xlimits = (np.amin((-.3,np.nanmin(reflect[:,0]))), np.amax((.3,np.nanmax(reflect[:,0])))) plt.ylim( ylimits ) plt.xlim( xlimits ) # axis labels ax.text(xlimits[1]-0.05, 0.025, 'intercept', verticalalignment='center', horizontalalignment='right', #transform=ax.transAxes, color='black', fontsize=8, alpha=0.5) ax.text( 0.025, ylimits[1]-0.05, 'gradient', rotation=90, verticalalignment='top', horizontalalignment='center', #transform=ax.transAxes, color='black', fontsize=8, alpha=0.5) # # Patches for background Gradient vs Intercept template STARTS here # x = np.arange(xlimits[0], xlimits[1], 0.01) y = np.arange(ylimits[0], ylimits[1], 0.01) s0 = -x shift2 = 0.04 #width for class2 width in plot height_ellipse = 0.05 width_ellipse = 3.0 # Plot background trend (diagonal line) ax.plot(x, s0, color='black', alpha = a1) # add a rectangle for class 2 neg lowleft2 = (-shift2,-1.0) class2neg = mpatches.Rectangle( lowleft2, width = abs(lowleft2[0]), height = 1.0, color = 'green', alpha = a1, ec = "white", lw = 4) ax.add_patch(class2neg) # add a rectange for class 2 pos lowleft2pos = (0.0, 0.0) class2pos = mpatches.Rectangle( lowleft2pos, width = abs(lowleft2[0]), height = 1.0, color = 'green', alpha = a1, ec="white", lw = 4) ax.add_patch(class2pos) # add a rectange for class 2p pos lowleft2Ppos = (-shift2, 0.0) class2Ppos = mpatches.Rectangle( lowleft2Ppos, width = abs(lowleft2[0]), height = 1.0, color = 'yellow', alpha = a1, ec="white", lw = 4) ax.add_patch(class2Ppos) # add a rectange for class 2p neg lowleft2Pneg = (0.0, -1.0) class2Ppos = mpatches.Rectangle( lowleft2Pneg, width = abs(lowleft2[0]), height = 1.0, color = 'yellow', alpha = a1, ec="white", lw = 4) ax.add_patch(class2Ppos) # add rectangle for lower left quadrant class 3 lowleft3neg = (-1.0, -1.0) class3neg = mpatches.Rectangle(lowleft3neg, width = 1.0 + lowleft2[0], height = 1.0, color = 'blue', alpha = a1, ec = 'none') ax.add_patch(class3neg) # add rectange for upper right quadrant class 3 lowleft3pos = (shift2, 0) class3pos = mpatches.Rectangle(lowleft3pos, width = 1.0 + lowleft2[0], height = 1.0, color = 'blue', alpha = a1, ec = 'none') ax.add_patch(class3pos) # add a Polygon for Class 4 upper left quadrant # add a path patch Path4u = mpath.Path path_data4u = [ (Path4u.MOVETO, [ -1.0, 0.0 ]), (Path4u.LINETO, [-1.0, 1.0]), (Path4u.LINETO, [ -shift2, shift2]), (Path4u.LINETO, [ -shift2, 0]), (Path4u.CLOSEPOLY, [-shift2, 0.0]) ] codes4u, verts4u = zip(*path_data4u) path4u = mpath.Path(verts4u, codes4u) patch4u = mpatches.PathPatch(path4u, facecolor = '#B048B5', # purple alpha = a1, ec = 'none') ax.add_patch(patch4u) # add a Polygon for Class 4 lower right quadrant Path4l = mpath.Path path_data4l = [ (Path4l.MOVETO, [ shift2, 0.0 ]), (Path4l.LINETO, [ 1.0, 0.0]), (Path4l.LINETO, [ 1.0, -1.0]), (Path4l.LINETO, [ shift2, -shift2 ]), (Path4l.CLOSEPOLY, [shift2, -shift2]) ] codes4l, verts4l = zip(*path_data4l) path4l = mpath.Path(verts4l, codes4l) patch4l = mpatches.PathPatch(path4l, facecolor = '#B048B5', # purple alpha = a1, ec = 'none') ax.add_patch(patch4l) # Add a Polygon for the Class 1 upper right quadrant Path1u = mpath.Path path_data1u = [ (Path1u.MOVETO, [ -shift2, shift2 ]), (Path1u.LINETO, [ -1.0, 1.0]), (Path1u.LINETO, [ -shift2, 1.0]), (Path1u.CLOSEPOLY, [-shift2, shift2]) ] codes1u, verts1u = zip(*path_data1u) path1u = mpath.Path(verts1u, codes1u) patch1u = mpatches.PathPatch(path1u, facecolor = 'red', alpha = a1, ec = 'none') ax.add_patch(patch1u) # Add a Polygone for the Class 1 lower left quadrant Path1l = mpath.Path path_data1l = [ (Path1l.MOVETO, [ shift2, -shift2 ]), (Path1l.LINETO, [ shift2, -1.0]), (Path1l.LINETO, [ 1.0, -1.0]), (Path1l.CLOSEPOLY, [shift2, -shift2]) ] codes1l, verts1l = zip(*path_data1l) path1l = mpath.Path(verts1l, codes1l) patch1l = mpatches.PathPatch(path1l, facecolor = 'red', alpha = a1, ec = 'none') ax.add_patch(patch1l) # Draw ellipse xy = np.hstack((0,0)) bkgd = collections.EllipseCollection( widths = width_ellipse, heights = height_ellipse, angles = 135, units = 'xy', offsets = xy, transOffset = ax.transData, facecolor = 'grey', edgecolor = 'none', alpha = 0.15 ) ax.add_collection(bkgd) #Get rid of axes spines ax.spines['right'].set_color('none') ax.spines['top'].set_color('none') ax.xaxis.set_ticks_position('bottom') ax.spines['bottom'].set_position(('data',0)) ax.spines['bottom'].set_alpha(0.5) ax.yaxis.set_ticks_position('left') ax.spines['left'].set_position(('data',0)) ax.spines['left'].set_alpha(0.5) # Annotation for Gradient vs Intercept annotation ax.text(0.98, 0.98, 'Gradient vs intercept', verticalalignment='top', horizontalalignment='right', transform=ax.transAxes, color='black', fontsize=9, fontweight = 'bold', alpha=0.50) for label in ax.get_xticklabels() + ax.get_yticklabels(): label.set_fontsize(8) label.set_alpha(0.5) # Class 1 label ax.text(3 * shift2, ylimits[0]+shift2, 'CLASS 1', verticalalignment='center', horizontalalignment='center', color='red', fontsize=fs, fontweight = 'bold', alpha=a2) # Class 2 label ax.text( -0.5 * shift2, ylimits[0] + 0.5 * shift2, 'CLASS 2', verticalalignment='bottom', horizontalalignment='center', rotation = 90, color='green', fontsize=fs, fontweight = 'bold', alpha=a2) # Class 2P label ax.text( 0.5 * shift2, ylimits[0] + 0.5 * shift2, 'CLASS 2p', verticalalignment='bottom', horizontalalignment='center', rotation = 90, color='#EEC900', fontsize=fs, fontweight = 'bold', alpha=a2 * 1.5) # Class 3 label ax.text(- 3 * shift2, ylimits[0]+shift2, 'CLASS 3', verticalalignment='center', horizontalalignment='right', color='blue', fontsize=fs, fontweight = 'bold', alpha=a2) # Class 4 label ax.text(-3 * shift2, shift2, 'CLASS 4', verticalalignment='center', horizontalalignment='right', color='#B048B5', fontsize=fs, fontweight = 'bold', alpha=a2) # Background label angle = -45 ax.text( 0.1 * height_ellipse, 0.1 * height_ellipse, 'background', verticalalignment='center', horizontalalignment='center', rotation = angle, transform=ax.transData, color='black', fontsize=fs, fontweight = 'bold', alpha=a2/2.0) return get_figure_data(), {"mean critical angle": critical_angle}
def run_script(earth_model, seismic_model, args): matplotlib.interactive(False) cmap = 'seismic_r' #max/min amplitude for plot and colorbar scaling extr1 = 1 / (10.0 * (args.gain + 0.0001) / 1000.0) # Define the figure layout fig = plt.figure(figsize=[15,10], facecolor = 'white') width_ratios = [3,1,1] gs = gridspec.GridSpec(2, 3, width_ratios = width_ratios, height_ratios = [2,1]) # Make the array of subplot ax11 = plt.subplot(gs[0]) ax12 = plt.subplot(gs[1]) ax13 = plt.subplot(gs[2]) ax21 = plt.subplot(gs[3]) ax22 = plt.subplot(gs[4]) ax23 = plt.subplot(gs[5]) axarr = [[ax11, ax12, ax13],[ax21, ax22, ax23]] # spatial seismic_model.go(earth_model, theta=args.theta) seismic_data = np.nan_to_num(seismic_model.seismic) seis_ratios = [ seismic_data.shape[1], seismic_data.shape[2] , seismic_data.shape[3] ] dec = 5 # number of traces to skip, hack for decimation of jitteryness im = axarr[0][0].imshow(seismic_data[:,::dec, 0, 0], aspect='auto', cmap=cmap, extent =[0, seismic_data.shape[1], 1000*seismic_model.dt*seismic_data.shape[0], 0], vmin = -extr1, vmax = extr1, interpolation='spline16') axarr[0][0].set_xlim(left=0, right=seismic_data.shape[1]) axarr[0][0].set_ylim(top=0, bottom=1000*seismic_model.dt*seismic_data.shape[0]) axarr[0][0].axvline(x=args.trace, lw=3, color='k', alpha=0.25) axarr[0][0].axhline(y=args.time*seismic_model.dt*1000, lw=3, color='g') axarr[0][0].set_title('spatial cross-section') axarr[0][0].set_ylabel('time [ms]') axarr[0][0].set_xticklabels(' ') axarr[0][0].grid() # Put wiggle trace on seismic cross-section trace1 = seismic_data[:,args.trace, 0, 0] x = np.arange(seismic_data.shape[0]) * seismic_model.dt * 1000.0 c = 20 # fractional denominator of cross section width gain1 = float(seismic_data.shape[1]/c) axarr[0][0].plot(args.trace + gain1 * trace1, x, 'k', alpha = 0.9) axarr[0][0].fill_betweenx(x, args.trace+gain1 * trace1, args.trace, gain1 * trace1 >= 0.01, color = 'k', alpha = 0.5) # Put colorbar legend on spatial cross section colorbar_ax = fig.add_axes([0.565,0.825,0.010,0.08]) fig.colorbar(im, cax=colorbar_ax) colorbar_ax.text( 0.5, -0.1, '%3.1f' % -1, transform=colorbar_ax.transAxes, horizontalalignment='center', verticalalignment='top') colorbar_ax.text(0.5, 1.1, '%3.1f' % 1, transform=colorbar_ax.transAxes, horizontalalignment='center') colorbar_ax.set_axis_off() if args.time > (seismic_data.shape[0]-1): args.time = seismic_data.shape[0]-1 axarr[1][0].plot(seismic_data[args.time,:, 0, 0], 'g', lw = 3) axarr[1][0].set_ylim(-extr1,extr1) axarr[1][0].set_xlim(0,seismic_data.shape[1]) axarr[1][0].set_ylabel('amplitude') axarr[1][0].set_xlabel('trace') axarr[1][0].grid() # angle column seismic_model.go(earth_model, traces=args.trace) seismic_data = seismic_model.seismic axarr[0][1].imshow(seismic_data[:, 0, :, 0], aspect='auto', cmap=cmap, extent=[0, seismic_data.shape[2], 1000*seismic_model.dt*seismic_data.shape[0], 0], vmin = -extr1, vmax = extr1, interpolation='spline16' ) axarr[0][1].set_xlim(left=0, right=seismic_data.shape[1]) axarr[0][1].set_ylim(top=0, bottom=1000*seismic_model.dt*seismic_data.shape[0]) axarr[0][1].axvline(x=args.theta, lw=3, color='r', alpha = 0.25) axarr[0][1].axhline(y=args.time*seismic_model.dt*1000, lw=3, color='g') axarr[0][1].set_title('angle gather') axarr[0][1].set_yticklabels(' ') axarr[0][1].set_xticklabels(' ') axarr[0][1].grid() # Put wiggle trace on AVO cross-section trace2 = seismic_data[:,0, args.theta, 0] x = np.arange(seismic_data.shape[0]) * 1000.0 * seismic_model.dt gain2 = (float(width_ratios[0])/width_ratios[1]) * (seismic_data.shape[2] / gain1) axarr[0][1].plot(args.theta + gain2 * trace2, x, 'k', alpha = 0.9) axarr[0][1].fill_betweenx(x, args.theta + gain2 * trace2, args.theta, gain2 * trace2 >= -0.01, color = 'k', alpha = 0.5) axarr[0][1].set_xlim(left=0, right=seismic_data.shape[2]) # line plot data2 = seismic_data[args.time, 0,:, 0] axarr[1][1].plot(data2, 'g', lw = 3) axarr[1][1].set_ylim(-extr1,extr1) axarr[1][1].set_xlim(0,seismic_data.shape[2]) axarr[1][1].set_xlabel(r'$\theta$'+' '+r'$^{\circ}$') axarr[1][1].set_yticklabels(' ') axarr[1][1].set_xticks([10,20,30,40]) axarr[1][1].grid() # wavelet f = seismic_model.f seismic_model.f = np.arange(0,50) freq = seismic_model.wavelet_cf()[f] seismic_model.go(earth_model, traces=args.trace, theta=args.theta) seismic_data = seismic_model.seismic axarr[0][2].imshow(seismic_data[:, 0, 0, :], aspect='auto', cmap=cmap, extent = [seismic_model.wavelet_cf()[0], seismic_model.wavelet_cf()[-1], seismic_data.shape[0]*seismic_model.dt*1000, 0], vmin = -extr1, vmax = extr1, interpolation='spline16') axarr[0][2].set_xlim(left=0, right=seismic_data.shape[3]) axarr[0][2].set_ylim(top=0, bottom=1000*seismic_model.dt*seismic_data.shape[0]) axarr[0][2].axvline(x=freq-1, lw=3, color='m', alpha = 0.25) axarr[0][2].axhline(y=args.time*seismic_model.dt*1000.0, lw=3, color='g') axarr[0][2].set_xscale('log', basex=2) axarr[0][2].set_title('wavelet gather') axarr[0][2].set_yticklabels(' ') axarr[0][2].set_xticklabels(' ') axarr[0][2].set_xticks((16,32,64)) # Put wiggle trace on wavelet cross-section trace3 = seismic_data[:,0, 0, f] x = np.arange(seismic_data.shape[0]) * seismic_model.dt * 1000.0 gain3 = 2*(float(width_ratios[0])/width_ratios[2]) * (seismic_data.shape[3] / gain1) freq = seismic_model.wavelet_cf()[f] axarr[0][2].plot(freq -1 + gain3 * trace3, x, 'k', alpha = 0.9) axarr[0][2].fill_betweenx(x, freq -1 + gain3 * trace3, freq -1, gain3 * trace3 -1 >= -1, color = 'k', alpha = 0.5) # axarr[0][2].set_xlim(left = 8, right = 99) axarr[0][2].grid() #line plot data3 = seismic_data[args.time, 0, 0, :] axarr[1][2].plot(seismic_model.wavelet_cf(), data3, 'g', lw = 3) axarr[1][2].set_ylim(-extr1,extr1) axarr[1][2].set_xlabel('centre frequency ' + 'Hz') axarr[1][2].set_xscale('log', basex=2) axarr[1][2].set_xlim(seismic_model.wavelet_cf()[0], seismic_model.wavelet_cf()[-1]) axarr[1][2].set_yticklabels(' ') axarr[1][2].grid() # remove some whitespace between the axes gs.update(hspace=0.05,wspace=0.05) seismic_model.start_f = 8 seismic_model.end_f = 100 fig.subplots_adjust(left=0.05, right=0.98, top=0.95, bottom=0.07) return get_figure_data()
def run_script(earth_model, seismic_model, args): matplotlib.interactive(False) cmap = 'seismic_r' #max/min amplitude for plot and colorbar scaling extr1 = 1 / (10.0 * (args.gain + 0.0001) / 1000.0) # Define the figure layout fig = plt.figure(figsize=[15, 10], facecolor='white') width_ratios = [3, 1, 1] gs = gridspec.GridSpec(2, 3, width_ratios=width_ratios, height_ratios=[2, 1]) # Make the array of subplot ax11 = plt.subplot(gs[0]) ax12 = plt.subplot(gs[1]) ax13 = plt.subplot(gs[2]) ax21 = plt.subplot(gs[3]) ax22 = plt.subplot(gs[4]) ax23 = plt.subplot(gs[5]) axarr = [[ax11, ax12, ax13], [ax21, ax22, ax23]] # spatial seismic_model.go(earth_model, theta=args.theta) seismic_data = np.nan_to_num(seismic_model.seismic) seis_ratios = [ seismic_data.shape[1], seismic_data.shape[2], seismic_data.shape[3] ] dec = 5 # number of traces to skip, hack for decimation of jitteryness im = axarr[0][0].imshow(seismic_data[:, ::dec, 0, 0], aspect='auto', cmap=cmap, extent=[ 0, seismic_data.shape[1], 1000 * seismic_model.dt * seismic_data.shape[0], 0 ], vmin=-extr1, vmax=extr1, interpolation='spline16') axarr[0][0].set_xlim(left=0, right=seismic_data.shape[1]) axarr[0][0].set_ylim(top=0, bottom=1000 * seismic_model.dt * seismic_data.shape[0]) axarr[0][0].axvline(x=args.trace, lw=3, color='k', alpha=0.25) axarr[0][0].axhline(y=args.time * seismic_model.dt * 1000, lw=3, color='g') axarr[0][0].set_title('spatial cross-section') axarr[0][0].set_ylabel('time [ms]') axarr[0][0].set_xticklabels(' ') axarr[0][0].grid() # Put wiggle trace on seismic cross-section trace1 = seismic_data[:, args.trace, 0, 0] x = np.arange(seismic_data.shape[0]) * seismic_model.dt * 1000.0 c = 20 # fractional denominator of cross section width gain1 = float(seismic_data.shape[1] / c) axarr[0][0].plot(args.trace + gain1 * trace1, x, 'k', alpha=0.9) axarr[0][0].fill_betweenx(x, args.trace + gain1 * trace1, args.trace, gain1 * trace1 >= 0.01, color='k', alpha=0.5) # Put colorbar legend on spatial cross section colorbar_ax = fig.add_axes([0.565, 0.825, 0.010, 0.08]) fig.colorbar(im, cax=colorbar_ax) colorbar_ax.text(0.5, -0.1, '%3.1f' % -1, transform=colorbar_ax.transAxes, horizontalalignment='center', verticalalignment='top') colorbar_ax.text(0.5, 1.1, '%3.1f' % 1, transform=colorbar_ax.transAxes, horizontalalignment='center') colorbar_ax.set_axis_off() if args.time > (seismic_data.shape[0] - 1): args.time = seismic_data.shape[0] - 1 axarr[1][0].plot(seismic_data[args.time, :, 0, 0], 'g', lw=3) axarr[1][0].set_ylim(-extr1, extr1) axarr[1][0].set_xlim(0, seismic_data.shape[1]) axarr[1][0].set_ylabel('amplitude') axarr[1][0].set_xlabel('trace') axarr[1][0].grid() # angle column seismic_model.go(earth_model, traces=args.trace) seismic_data = seismic_model.seismic axarr[0][1].imshow(seismic_data[:, 0, :, 0], aspect='auto', cmap=cmap, extent=[ 0, seismic_data.shape[2], 1000 * seismic_model.dt * seismic_data.shape[0], 0 ], vmin=-extr1, vmax=extr1, interpolation='spline16') axarr[0][1].set_xlim(left=0, right=seismic_data.shape[1]) axarr[0][1].set_ylim(top=0, bottom=1000 * seismic_model.dt * seismic_data.shape[0]) axarr[0][1].axvline(x=args.theta, lw=3, color='r', alpha=0.25) axarr[0][1].axhline(y=args.time * seismic_model.dt * 1000, lw=3, color='g') axarr[0][1].set_title('angle gather') axarr[0][1].set_yticklabels(' ') axarr[0][1].set_xticklabels(' ') axarr[0][1].grid() # Put wiggle trace on AVO cross-section trace2 = seismic_data[:, 0, args.theta, 0] x = np.arange(seismic_data.shape[0]) * 1000.0 * seismic_model.dt gain2 = (float(width_ratios[0]) / width_ratios[1]) * (seismic_data.shape[2] / gain1) axarr[0][1].plot(args.theta + gain2 * trace2, x, 'k', alpha=0.9) axarr[0][1].fill_betweenx(x, args.theta + gain2 * trace2, args.theta, gain2 * trace2 >= -0.01, color='k', alpha=0.5) axarr[0][1].set_xlim(left=0, right=seismic_data.shape[2]) # line plot data2 = seismic_data[args.time, 0, :, 0] axarr[1][1].plot(data2, 'g', lw=3) axarr[1][1].set_ylim(-extr1, extr1) axarr[1][1].set_xlim(0, seismic_data.shape[2]) axarr[1][1].set_xlabel(r'$\theta$' + ' ' + r'$^{\circ}$') axarr[1][1].set_yticklabels(' ') axarr[1][1].set_xticks([10, 20, 30, 40]) axarr[1][1].grid() # wavelet f = seismic_model.f seismic_model.f = np.arange(0, 50) freq = seismic_model.wavelet_cf()[f] seismic_model.go(earth_model, traces=args.trace, theta=args.theta) seismic_data = seismic_model.seismic axarr[0][2].imshow(seismic_data[:, 0, 0, :], aspect='auto', cmap=cmap, extent=[ seismic_model.wavelet_cf()[0], seismic_model.wavelet_cf()[-1], seismic_data.shape[0] * seismic_model.dt * 1000, 0 ], vmin=-extr1, vmax=extr1, interpolation='spline16') axarr[0][2].set_xlim(left=0, right=seismic_data.shape[3]) axarr[0][2].set_ylim(top=0, bottom=1000 * seismic_model.dt * seismic_data.shape[0]) axarr[0][2].axvline(x=freq - 1, lw=3, color='m', alpha=0.25) axarr[0][2].axhline(y=args.time * seismic_model.dt * 1000.0, lw=3, color='g') axarr[0][2].set_xscale('log', basex=2) axarr[0][2].set_title('wavelet gather') axarr[0][2].set_yticklabels(' ') axarr[0][2].set_xticklabels(' ') axarr[0][2].set_xticks((16, 32, 64)) # Put wiggle trace on wavelet cross-section trace3 = seismic_data[:, 0, 0, f] x = np.arange(seismic_data.shape[0]) * seismic_model.dt * 1000.0 gain3 = 2 * (float(width_ratios[0]) / width_ratios[2]) * (seismic_data.shape[3] / gain1) freq = seismic_model.wavelet_cf()[f] axarr[0][2].plot(freq - 1 + gain3 * trace3, x, 'k', alpha=0.9) axarr[0][2].fill_betweenx(x, freq - 1 + gain3 * trace3, freq - 1, gain3 * trace3 - 1 >= -1, color='k', alpha=0.5) # axarr[0][2].set_xlim(left=8, right=99) axarr[0][2].grid() #line plot data3 = seismic_data[args.time, 0, 0, :] axarr[1][2].plot(seismic_model.wavelet_cf(), data3, 'g', lw=3) axarr[1][2].set_ylim(-extr1, extr1) axarr[1][2].set_xlabel('centre frequency ' + 'Hz') axarr[1][2].set_xscale('log', basex=2) axarr[1][2].set_xlim(seismic_model.wavelet_cf()[0], seismic_model.wavelet_cf()[-1]) axarr[1][2].set_yticklabels(' ') axarr[1][2].grid() # remove some whitespace between the axes gs.update(hspace=0.05, wspace=0.05) seismic_model.start_f = 8 seismic_model.end_f = 100 fig.subplots_adjust(left=0.05, right=0.98, top=0.95, bottom=0.07) return get_figure_data()
def run_script(earth_model, seismic_model, args): # Hard code colormap cmap='seismic_r' # min / max scaling for colormap and wiggles extr1 = 1.0 / (10.0 * args.gain / 1000.0) # decimate number of columns in synthetic dec = 5 # Create figure fig =plt.figure(figsize=[15,10], facecolor = 'white') # Create two axes within figure gs = gridspec.GridSpec(1, 2,width_ratios=[19,1]) axarr = [plt.subplot(gs[0]), plt.subplot(gs[1])] seismic_model.go(earth_model, theta=args.theta) seismic_data = seismic_model.seismic t = seismic_model.dt * np.arange(seismic_data.shape[0]) img = seismic_data[:,:, 0, 0] # synthetic cross section im = axarr[0].imshow(img[:,::dec], aspect='auto', cmap=cmap, extent =[0, seismic_data.shape[1], 1000*seismic_model.dt*seismic_data.shape[0],0], vmin = -extr1, vmax = extr1, interpolation='spline16') axarr[0].set_xlim(left=0, right=seismic_data.shape[1]) axarr[0].set_ylim(top=0, bottom=1000*seismic_model.dt*seismic_data.shape[0]) axarr[0].grid() axarr[0].axvline(x=args.trace, lw=1, color='k', alpha=0.25) axarr[0].set_title('spatial cross-section') axarr[0].set_ylabel('time [ms]') axarr[0].set_xlabel('trace') # Put colorbar legend on spatial cross section colorbar_ax = fig.add_axes([0.85,0.825,0.010,0.08]) fig.colorbar(im, cax=colorbar_ax) colorbar_ax.invert_yaxis() colorbar_ax.text( 0.5, -0.1, '%3.1f' % -1, transform=colorbar_ax.transAxes, horizontalalignment='center', verticalalignment='top') colorbar_ax.text(0.5, 1.1, '%3.1f' % 1, transform=colorbar_ax.transAxes, horizontalalignment='center') colorbar_ax.set_axis_off() # find max and min of section slice ampmin = np.amin(img) ampmax = np.amax(img) biggest = max(abs(ampmin),abs(ampmax)) # Put wiggle trace on seismic cross-section trace1 = seismic_data[:,args.trace-1, 0, 0] tt = np.arange(seismic_data.shape[0]) * seismic_model.dt * 1000.0 c = 20 # fractional denominator of cross section width gain1 = float(seismic_data.shape[1]/c) axarr[0].plot(args.trace + gain1 * trace1, tt, 'k',alpha = 0.9) axarr[0].fill_betweenx(tt, args.trace + gain1 * trace1, args.trace, gain1 * trace1 > 0.01, color = 'k', alpha = 0.5) # Put wiggle in right panel #get y-axis limits, so can reverse y-axis of wiggle plot a1ymin, a1ymax = axarr[1].get_ylim() axarr[1].plot(trace1,tt,'k') axarr[1].fill_betweenx(tt, trace1, 0, trace1 > 0.01, color = 'k', alpha = 0.5) axarr[1].axvline(x=0, lw=1, color='k', alpha=0.25) axarr[1].yaxis.tick_right() axarr[1].set_xticks([-1.0, 0, 1.0]) #axarr[1].get_xaxis().set_visible(False) axarr[1].set_ylim((a1ymax, a1ymin)) axarr[1].set_xlim((-biggest, biggest)) axarr[1].set_ylabel('time [ms]') axarr[1].yaxis.set_label_position("right") axarr[1].grid() axarr[1].axis('tight') plt.gca().invert_yaxis() fig.tight_layout() # set the frequency options (need to do this more elegantly) seismic_model.f = np.arange(0,50) return get_figure_data()
def run_script(earth_model, seismic_model, args): # Hard code colormap cmap = 'seismic_r' # min / max scaling for colormap and wiggles extr1 = 1.0 / (10.0 * args.gain / 1000.0) # decimate number of columns in synthetic dec = 5 # Create figure fig = plt.figure(figsize=[15, 10], facecolor='white') # Create two axes within figure gs = gridspec.GridSpec(1, 2, width_ratios=[19, 1]) axarr = [plt.subplot(gs[0]), plt.subplot(gs[1])] seismic_model.go(earth_model, theta=args.theta) seismic_data = seismic_model.seismic t = seismic_model.dt * np.arange(seismic_data.shape[0]) img = seismic_data[:, :, 0, 0] # synthetic cross section im = axarr[0].imshow(img[:, ::dec], aspect='auto', cmap=cmap, extent=[ 0, seismic_data.shape[1], 1000 * seismic_model.dt * seismic_data.shape[0], 0 ], vmin=-extr1, vmax=extr1, interpolation='spline16') axarr[0].set_xlim(left=0, right=seismic_data.shape[1]) axarr[0].set_ylim(top=0, bottom=1000 * seismic_model.dt * seismic_data.shape[0]) axarr[0].grid() axarr[0].axvline(x=args.trace, lw=1, color='k', alpha=0.25) axarr[0].set_title('spatial cross-section') axarr[0].set_ylabel('time [ms]') axarr[0].set_xlabel('trace') # Put colorbar legend on spatial cross section colorbar_ax = fig.add_axes([0.85, 0.825, 0.010, 0.08]) fig.colorbar(im, cax=colorbar_ax) colorbar_ax.invert_yaxis() colorbar_ax.text(0.5, -0.1, '%3.1f' % -1, transform=colorbar_ax.transAxes, horizontalalignment='center', verticalalignment='top') colorbar_ax.text(0.5, 1.1, '%3.1f' % 1, transform=colorbar_ax.transAxes, horizontalalignment='center') colorbar_ax.set_axis_off() # find max and min of section slice ampmin = np.amin(img) ampmax = np.amax(img) biggest = max(abs(ampmin), abs(ampmax)) # Put wiggle trace on seismic cross-section trace1 = seismic_data[:, args.trace - 1, 0, 0] tt = np.arange(seismic_data.shape[0]) * seismic_model.dt * 1000.0 c = 20 # fractional denominator of cross section width gain1 = float(seismic_data.shape[1] / c) axarr[0].plot(args.trace + gain1 * trace1, tt, 'k', alpha=0.9) axarr[0].fill_betweenx(tt, args.trace + gain1 * trace1, args.trace, gain1 * trace1 > 0.01, color='k', alpha=0.5) # Put wiggle in right panel #get y-axis limits, so can reverse y-axis of wiggle plot a1ymin, a1ymax = axarr[1].get_ylim() axarr[1].plot(trace1, tt, 'k') axarr[1].fill_betweenx(tt, trace1, 0, trace1 > 0.01, color='k', alpha=0.5) axarr[1].axvline(x=0, lw=1, color='k', alpha=0.25) axarr[1].yaxis.tick_right() axarr[1].set_xticks([-1.0, 0, 1.0]) #axarr[1].get_xaxis().set_visible(False) axarr[1].set_ylim((a1ymax, a1ymin)) axarr[1].set_xlim((-biggest, biggest)) axarr[1].set_ylabel('time [ms]') axarr[1].yaxis.set_label_position("right") axarr[1].grid() axarr[1].axis('tight') plt.gca().invert_yaxis() fig.tight_layout() # set the frequency options (need to do this more elegantly) seismic_model.f = np.arange(0, 50) return get_figure_data()
def run_script(args): matplotlib.interactive(False) args.plot_type = 'dashboard' Rprop0 = args.Rock0 Rprop1 = args.Rock1 theta = np.arange(0, 90) vp0, vs0, rho0 = make_normal_dist(Rprop0, args.iterations) vp1, vs1, rho1 = make_normal_dist(Rprop1, args.iterations) reflect = [] hist_titles = [[r'$V_\mathrm{P}$', r'$m/s$'], [r'$V_\mathrm{S}$', r'$m/s$'], [r'$\rho$', r'$kg / m^3$']] nbins = 15 vp_lim = (np.amin( (Rprop1.vp - (3. * Rprop1.vp_sig), Rprop0.vp - (3. * Rprop1.vp_sig))), np.amax((Rprop1.vp + (3. * Rprop1.vp_sig), Rprop0.vp + (3. * Rprop1.vp_sig)))) vs_lim = (np.amin( (Rprop1.vs - (3. * Rprop1.vs_sig), Rprop0.vs - (3. * Rprop1.vs_sig))), np.amax((Rprop1.vs + (3. * Rprop1.vs_sig), Rprop0.vs + (3. * Rprop1.vs_sig)))) rho_lim = (np.amin((Rprop1.rho - (3. * Rprop1.rho_sig), Rprop0.rho - (3. * Rprop1.rho_sig))), np.amax((Rprop1.rho + (3. * Rprop1.rho_sig), Rprop0.rho + (3. * Rprop1.rho_sig)))) limits = np.array([[vp_lim, vs_lim, rho_lim], [vp_lim, vs_lim, rho_lim]]) for i in range(args.iterations): reflect.append( args.reflectivity_method(vp0[i], vs0[i], rho0[i], vp1[i], vs1[i], rho1[i], theta)) reflect = np.array(reflect) reflect = np.nan_to_num(reflect) #temp = np.concatenate( (vp0, rho0, vs0, vp1, rho1, vs1,), axis=0) temp = np.concatenate((vp0, vs0, rho0, vp1, vs1, rho1), axis=0) prop_samples = np.reshape(temp, (6, args.iterations)) ave_reflect = np.mean(reflect, axis=0) nbins = 15 # DO PLOTTING plt.figure(figsize=(5, 13)) plt.subplots_adjust(bottom=0.1, left=0.1, top=1, right=0.9) plt.hold(True) if args.plot_type == 'dashboard': G = matplotlib.gridspec.GridSpec(9, 2, hspace=0.5) shift = 3 else: G = matplotlib.gridspec.GridSpec(2, 6) shift = 0 # histogram plots (ax_3, ax_4, ax_5, ax_6, ax_7, ax_8) hist_max = 0 for k in np.arange(len(prop_samples)): # find the max bar height of the histogram for scaling the plots hist_max = max(hist_max, max(np.histogram(prop_samples[k], density=True)[0])) for j in np.arange(2): upper_color = 'blue' #color of upper histogram lower_color = 'green' #color of lower histogram for i in np.arange(3): plt.subplot(G[3 + i + shift, 0]) plt.hist(prop_samples[i], nbins, facecolor=upper_color, histtype='stepfilled', alpha=0.25, normed=True) plt.hist(prop_samples[i + (3)], nbins, facecolor=lower_color, histtype='stepfilled', alpha=0.25, normed=True) temp = plt.gca() # Annotation and making it look nice plt.axis( [limits[j][i][0], limits[j][i][1], temp.axis()[2], hist_max]) plt.yticks([]) plt.xticks(rotation=90, horizontalalignment='left') ax = plt.gca() ax.spines['right'].set_color('none') ax.spines['left'].set_color('none') ax.spines['top'].set_color('none') ax.spines['bottom'].set_alpha(0.5) for label in ax.get_xticklabels() + ax.get_yticklabels(): label.set_fontsize(6) label.set_alpha(0.5) for tick in ax.xaxis.get_major_ticks(): tick.tick1On = True tick.tick2On = False # upper text label mean_props = [[Rprop0.vp, Rprop1.vp], [Rprop0.vs, Rprop1.vs], [Rprop0.rho, Rprop1.rho]] which_label = ['upper', 'lower'] # Main label ax.text(x=limits[0, i, 1], y=hist_max * 0.5, s=hist_titles[i][0], color='black', fontsize=14, alpha=0.75, horizontalalignment='left', verticalalignment='center') # Label for units ax.text(x=limits[0, i, 1], y=hist_max * 0.25, s=hist_titles[i][1], color='black', fontsize=10, alpha=0.75, horizontalalignment='left', verticalalignment='center') ax.text( x=float(mean_props[i][0]), y=hist_max / 5.0, s=which_label[0], alpha=0.75, color=upper_color, fontsize='9', horizontalalignment='center', verticalalignment='center', ) #lower text label ax.text(x=float(mean_props[i][1]), y=hist_max / 5.0, s=which_label[1], alpha=0.75, color=lower_color, fontsize='9', horizontalalignment='center', verticalalignment='center') # # ax_1 the AVO plot # plt.subplot(G[0:3, :]) plt.hold(True) critical_angles = [] for i in range(args.iterations - 1): # Do the AVO template as an underlay # HERE # Do the plots --> This step might not need to be in a loop plt.plot(theta, reflect[i], color='grey', lw=1.0, alpha=np.min((30. / args.iterations, 0.08))) if vp1[i] > vp0[i]: theta_crit = arcsin(vp0[i] / vp1[i]) * 180 / np.pi plt.axvline(x=theta_crit, color='black', lw=1.0, alpha=np.min((30. / args.iterations, 0.5))) critical_angles.append(theta_crit) if len(critical_angles) > 0: critical_angle = np.mean(critical_angles) else: critical_angle = 'N/A' plt.plot(theta, ave_reflect, color='black', alpha=0.5, lw=1.5) plt.grid() # Annotation and making it look nice ax = plt.gca() ax.spines['right'].set_color('none') ax.spines['top'].set_color('none') ax.xaxis.set_ticks_position('bottom') ax.spines['bottom'].set_position(('data', 0)) ax.spines['bottom'].set_alpha(0.5) ax.yaxis.set_ticks_position('left') ax.spines['left'].set_position(('data', 0)) ax.spines['left'].set_alpha(0.5) for label in ax.get_xticklabels() + ax.get_yticklabels(): label.set_fontsize(6) label.set_alpha(0.5) plt.grid() plt.ylim((-.5, .5)) ax.text(0.95, 0.45, 'angle', verticalalignment='top', horizontalalignment='right', transform=ax.transAxes, color='black', fontsize=8, alpha=0.5) ax.text(0.05, 0.95, 'amplitude', verticalalignment='top', horizontalalignment='right', transform=ax.transAxes, rotation=90, color='black', fontsize=8, alpha=0.5) # # Patches for the Background template AVO plot STARTS here # a1 = 0.10 # transparency for AVO background template patches rangex = 90 band = 0.04 # thickness of Class 2 band # CLASS 1 Path1 = mpath.Path path_data1 = [ (Path1.MOVETO, (rangex * 0, 0.04)), (Path1.CURVE4, (rangex * 0.4, 0.05)), (Path1.CURVE4, (rangex * 0.6, -0.015)), (Path1.CURVE4, (rangex * 1.0, -band)), (Path1.LINETO, (rangex * 1.0, 1.0)), (Path1.LINETO, (rangex * 0.0, 1.0)), (Path1.CLOSEPOLY, (rangex * 0.0, 1.0)), ] codes1, verts1 = zip(*path_data1) path1 = mpath.Path(verts1, codes1) patch1 = mpatches.PathPatch(path1, facecolor='r', alpha=a1, ec='none') ax.add_patch(patch1) # plot control points and connecting lines x1, y1 = zip(*path1.vertices) #line1, = ax.plot(x1, y1, 'go-') # CLASS 2p Path2P = mpath.Path path_data2P = [ (Path2P.MOVETO, (rangex * 0, band)), (Path2P.CURVE4, (rangex * 0.4, 0.05)), (Path2P.CURVE4, (rangex * 0.6, -0.015)), (Path2P.CURVE4, (rangex * 1.0, -band)), (Path2P.LINETO, (rangex * 1.0, -(band + band))), (Path2P.CURVE4, (rangex * 0.6, -(0.015 + band))), (Path2P.CURVE4, (rangex * 0.4, 0.05 - band)), (Path2P.CURVE4, (rangex * 0.0, 0.0)), (Path2P.CLOSEPOLY, (rangex * 0.0, 0.0)), ] codes2P, verts2P = zip(*path_data2P) path2P = mpath.Path(verts2P, codes2P) patch2P = mpatches.PathPatch(path2P, facecolor='yellow', alpha=a1, ec='none') ax.add_patch(patch2P) # plot control points and connecting lines x2, y2 = zip(*path2P.vertices) #line2, = ax.plot(x2, y2, 'ro-') # CLASS 2 Path2 = mpath.Path path_data2 = [ (Path2.MOVETO, (rangex * 0.0, 0.0)), (Path2.CURVE4, (rangex * 0.4, 0.05 - band)), (Path2.CURVE4, (rangex * 0.6, -(0.015 + band))), (Path2.CURVE4, (rangex * 1.0, -(band + band))), (Path2.LINETO, (rangex * 1.0, -(3 * band))), (Path2.CURVE4, (rangex * 0.6, -(0.015 + 2 * band))), (Path2.CURVE4, (rangex * 0.4, 0.05 - (0.0 + 2 * band))), (Path2.CURVE4, (rangex * 0.0, -band)), (Path2.CLOSEPOLY, (rangex * 0.0, 0.0)), ] codes2, verts2 = zip(*path_data2) path2 = mpath.Path(verts2, codes2) patch2 = mpatches.PathPatch(path2, facecolor='green', alpha=a1, ec='none') ax.add_patch(patch2) # plot control points and connecting lines x2, y2 = zip(*path2.vertices) #line2, = ax.plot(x2, y2, 'ro-') # CLASS 3 Path3 = mpath.Path path_data3 = [ (Path3.MOVETO, (rangex * 0.0, -band)), (Path3.CURVE4, (rangex * 0.4, 0.05 - (0.0 + 2 * band))), (Path3.CURVE4, (rangex * 0.6, -(0.015 + 2 * band))), (Path3.CURVE4, (rangex * 1.0, -(3 * band))), (Path3.LINETO, (rangex * 1.0, -1.0)), (Path3.LINETO, (rangex * 0.0, -1.0)), (Path3.CLOSEPOLY, (rangex * 0.0, -1.0)), ] codes3, verts3 = zip(*path_data3) path3 = mpath.Path(verts3, codes3) patch3 = mpatches.PathPatch(path3, facecolor='blue', alpha=a1, ec='none') ax.add_patch(patch3) # plot control points and connecting lines x3, y3 = zip(*path3.vertices) #line2, = ax.plot(x2, y2, 'ro-') ax.grid() ax.text(0.98, 0.98, 'Amplitude vs angle', verticalalignment='top', horizontalalignment='right', transform=ax.transAxes, color='black', fontsize=9, fontweight='bold', alpha=0.5) ax.spines['right'].set_color('none') ax.spines['top'].set_color('none') ax.xaxis.set_ticks_position('bottom') ax.spines['bottom'].set_position(('data', 0)) ax.yaxis.set_ticks_position('left') ax.spines['left'].set_position(('data', 0)) for label in ax.get_xticklabels() + ax.get_yticklabels(): label.set_fontsize(8) label.set_alpha(0.5) plt.grid() # Class 1 label # y-values for class labels 1,2p, 2, 3, and 4 respectively ylabelcntrs = [0.35, 0.025, -0.025, -0.4, -0.2] xctrs = 10 fs = 10 # fontsize a2 = 0.4 # transparency value for Gradient vs Intercept text ax.text(xctrs, ylabelcntrs[0], 'CLASS 1', verticalalignment='center', horizontalalignment='left', color='red', fontsize=fs, fontweight='bold', alpha=a2) # Class 2p label ax.text(xctrs, ylabelcntrs[1], 'CLASS 2p', verticalalignment='center', horizontalalignment='left', rotation=-3, color='#EEC900', fontsize=fs, fontweight='bold', alpha=a2 * 1.5) # Class 2 label ax.text(xctrs, ylabelcntrs[2], 'CLASS 2', verticalalignment='center', horizontalalignment='left', rotation=-3, color='green', fontsize=fs, fontweight='bold', alpha=a2) # Class 3 label ax.text(xctrs, ylabelcntrs[3], 'CLASS 3', verticalalignment='center', horizontalalignment='left', rotation=-15, color='blue', fontsize=fs, fontweight='bold', alpha=a2) # Class 4 label ax.text(xctrs, ylabelcntrs[4], 'CLASS 4', verticalalignment='center', horizontalalignment='left', rotation=15, color='#B048B5', fontsize=fs, fontweight='bold', alpha=a2) # # Patches for background template AVO plot ENDS here # # ax_2 the AB plot plt.subplot(G[0 + shift:3 + shift, :]) plt.hold(True) max_ang = args.max_angle # Max ang for computing gradient for i in range(args.iterations - 1): plt.scatter(reflect[i, 0], (reflect[i, max_ang] - reflect[i, 0]), color='grey', s=20, alpha=np.max((30. / args.iterations, 0.2))) # Plot the average of the dots plt.scatter(ave_reflect[0], ave_reflect[max_ang] - ave_reflect[0], color='black', s=40, alpha=0.5) # Annotation and making it nice plt.xticks([]), plt.yticks([]) ax = plt.gca() ax.spines['right'].set_color('none') ax.spines['top'].set_color('none') ax.xaxis.set_ticks_position('bottom') ax.spines['bottom'].set_position(('data', 0)) ax.spines['bottom'].set_alpha(0.5) ax.yaxis.set_ticks_position('left') ax.spines['left'].set_position(('data', 0)) ax.spines['left'].set_alpha(0.5) plt.grid() # axis limits ylimits = (np.amin((-.3, np.nanmin(reflect[:, 50] - reflect[:, 0]))), np.amax((.3, np.nanmax(reflect[:, 50] - reflect[:, 0])))) xlimits = (np.amin( (-.3, np.nanmin(reflect[:, 0]))), np.amax((.3, np.nanmax(reflect[:, 0])))) plt.ylim(ylimits) plt.xlim(xlimits) # axis labels ax.text( xlimits[1] - 0.05, 0.025, 'intercept', verticalalignment='center', horizontalalignment='right', #transform=ax.transAxes, color='black', fontsize=8, alpha=0.5) ax.text( 0.025, ylimits[1] - 0.05, 'gradient', rotation=90, verticalalignment='top', horizontalalignment='center', #transform=ax.transAxes, color='black', fontsize=8, alpha=0.5) # # Patches for background Gradient vs Intercept template STARTS here # x = np.arange(xlimits[0], xlimits[1], 0.01) y = np.arange(ylimits[0], ylimits[1], 0.01) s0 = -x shift2 = 0.04 #width for class2 width in plot height_ellipse = 0.05 width_ellipse = 3.0 # Plot background trend (diagonal line) ax.plot(x, s0, color='black', alpha=a1) # add a rectangle for class 2 neg lowleft2 = (-shift2, -1.0) class2neg = mpatches.Rectangle(lowleft2, width=abs(lowleft2[0]), height=1.0, color='green', alpha=a1, ec="white", lw=4) ax.add_patch(class2neg) # add a rectange for class 2 pos lowleft2pos = (0.0, 0.0) class2pos = mpatches.Rectangle(lowleft2pos, width=abs(lowleft2[0]), height=1.0, color='green', alpha=a1, ec="white", lw=4) ax.add_patch(class2pos) # add a rectange for class 2p pos lowleft2Ppos = (-shift2, 0.0) class2Ppos = mpatches.Rectangle(lowleft2Ppos, width=abs(lowleft2[0]), height=1.0, color='yellow', alpha=a1, ec="white", lw=4) ax.add_patch(class2Ppos) # add a rectange for class 2p neg lowleft2Pneg = (0.0, -1.0) class2Ppos = mpatches.Rectangle(lowleft2Pneg, width=abs(lowleft2[0]), height=1.0, color='yellow', alpha=a1, ec="white", lw=4) ax.add_patch(class2Ppos) # add rectangle for lower left quadrant class 3 lowleft3neg = (-1.0, -1.0) class3neg = mpatches.Rectangle(lowleft3neg, width=1.0 + lowleft2[0], height=1.0, color='blue', alpha=a1, ec='none') ax.add_patch(class3neg) # add rectange for upper right quadrant class 3 lowleft3pos = (shift2, 0) class3pos = mpatches.Rectangle(lowleft3pos, width=1.0 + lowleft2[0], height=1.0, color='blue', alpha=a1, ec='none') ax.add_patch(class3pos) # add a Polygon for Class 4 upper left quadrant # add a path patch Path4u = mpath.Path path_data4u = [(Path4u.MOVETO, [-1.0, 0.0]), (Path4u.LINETO, [-1.0, 1.0]), (Path4u.LINETO, [-shift2, shift2]), (Path4u.LINETO, [-shift2, 0]), (Path4u.CLOSEPOLY, [-shift2, 0.0])] codes4u, verts4u = zip(*path_data4u) path4u = mpath.Path(verts4u, codes4u) patch4u = mpatches.PathPatch( path4u, facecolor='#B048B5', # purple alpha=a1, ec='none') ax.add_patch(patch4u) # add a Polygon for Class 4 lower right quadrant Path4l = mpath.Path path_data4l = [(Path4l.MOVETO, [shift2, 0.0]), (Path4l.LINETO, [1.0, 0.0]), (Path4l.LINETO, [1.0, -1.0]), (Path4l.LINETO, [shift2, -shift2]), (Path4l.CLOSEPOLY, [shift2, -shift2])] codes4l, verts4l = zip(*path_data4l) path4l = mpath.Path(verts4l, codes4l) patch4l = mpatches.PathPatch( path4l, facecolor='#B048B5', # purple alpha=a1, ec='none') ax.add_patch(patch4l) # Add a Polygon for the Class 1 upper right quadrant Path1u = mpath.Path path_data1u = [(Path1u.MOVETO, [-shift2, shift2]), (Path1u.LINETO, [-1.0, 1.0]), (Path1u.LINETO, [-shift2, 1.0]), (Path1u.CLOSEPOLY, [-shift2, shift2])] codes1u, verts1u = zip(*path_data1u) path1u = mpath.Path(verts1u, codes1u) patch1u = mpatches.PathPatch(path1u, facecolor='red', alpha=a1, ec='none') ax.add_patch(patch1u) # Add a Polygone for the Class 1 lower left quadrant Path1l = mpath.Path path_data1l = [(Path1l.MOVETO, [shift2, -shift2]), (Path1l.LINETO, [shift2, -1.0]), (Path1l.LINETO, [1.0, -1.0]), (Path1l.CLOSEPOLY, [shift2, -shift2])] codes1l, verts1l = zip(*path_data1l) path1l = mpath.Path(verts1l, codes1l) patch1l = mpatches.PathPatch(path1l, facecolor='red', alpha=a1, ec='none') ax.add_patch(patch1l) # Draw ellipse xy = np.hstack((0, 0)) bkgd = collections.EllipseCollection(widths=width_ellipse, heights=height_ellipse, angles=135, units='xy', offsets=xy, transOffset=ax.transData, facecolor='grey', edgecolor='none', alpha=0.15) ax.add_collection(bkgd) #Get rid of axes spines ax.spines['right'].set_color('none') ax.spines['top'].set_color('none') ax.xaxis.set_ticks_position('bottom') ax.spines['bottom'].set_position(('data', 0)) ax.spines['bottom'].set_alpha(0.5) ax.yaxis.set_ticks_position('left') ax.spines['left'].set_position(('data', 0)) ax.spines['left'].set_alpha(0.5) # Annotation for Gradient vs Intercept annotation ax.text(0.98, 0.98, 'Gradient vs intercept', verticalalignment='top', horizontalalignment='right', transform=ax.transAxes, color='black', fontsize=9, fontweight='bold', alpha=0.50) for label in ax.get_xticklabels() + ax.get_yticklabels(): label.set_fontsize(8) label.set_alpha(0.5) # Class 1 label ax.text(3 * shift2, ylimits[0] + shift2, 'CLASS 1', verticalalignment='center', horizontalalignment='center', color='red', fontsize=fs, fontweight='bold', alpha=a2) # Class 2 label ax.text(-0.5 * shift2, ylimits[0] + 0.5 * shift2, 'CLASS 2', verticalalignment='bottom', horizontalalignment='center', rotation=90, color='green', fontsize=fs, fontweight='bold', alpha=a2) # Class 2P label ax.text(0.5 * shift2, ylimits[0] + 0.5 * shift2, 'CLASS 2p', verticalalignment='bottom', horizontalalignment='center', rotation=90, color='#EEC900', fontsize=fs, fontweight='bold', alpha=a2 * 1.5) # Class 3 label ax.text(-3 * shift2, ylimits[0] + shift2, 'CLASS 3', verticalalignment='center', horizontalalignment='right', color='blue', fontsize=fs, fontweight='bold', alpha=a2) # Class 4 label ax.text(-3 * shift2, shift2, 'CLASS 4', verticalalignment='center', horizontalalignment='right', color='#B048B5', fontsize=fs, fontweight='bold', alpha=a2) # Background label angle = -45 ax.text(0.1 * height_ellipse, 0.1 * height_ellipse, 'background', verticalalignment='center', horizontalalignment='center', rotation=angle, transform=ax.transData, color='black', fontsize=fs, fontweight='bold', alpha=a2 / 2.0) return get_figure_data(), {"mean critical angle": critical_angle}