Пример #1
0
def az_section(st, phase, **kwargs):
    '''
    Plot traces as a function of azimuthal change
    '''
    window_tuple = kwargs.get('window_tuple',(-40,40))
    tr_list = []
    for tr in st:
        d = data.phase_window(tr,['S'],window_tuple).normalize().data
        az = round(tr.stats.sac['az'],3)
        tr_list.append((az,d))


    fig, ax = plt.subplots(figsize=(10,15))
    ax.set_ylabel('Source-reciever azimuth')
    ax.set_xlabel('Seconds after PREM predicted {} phase'.format(phase[0]))
    ax.set_title('{} \n Channel: {}, Depth: {} km'.format(
                 st[10].stats.starttime,
                 st[10].stats.channel,
                 round(st[10].stats.sac['evdp'],3)))
    ax.grid()

    for ii in tr_list:
        time = np.linspace(window_tuple[0],window_tuple[1],
                           num=len(ii[1]))
        ax.plot(time,ii[0]+ii[1],'k',alpha=0.5)
    plt.show()
Пример #2
0
def vespagram(st_in,**kwargs):
    '''
    make vespagram of stream object. Recommended to pass stream object
    through remove_dirty
    '''

    window_tuple = kwargs.get('x_lim',(-10,230))
    window_phase = kwargs.get('window_phase',['P'])
    window_slowness = kwargs.get('window_slowness',(-1.5,1.5))
    slowness_tick = kwargs.get('slowness_tick',-0.1)
    phase_list = kwargs.get('phase_list',False)
    plot_line = kwargs.get('plot_line',False)
    n_root = kwargs.get('n_root',2.0)
    save = kwargs.get('save',False)
    clim = kwargs.get('clim',(-3,0))
    cmap = kwargs.get('cmap','gnuplot')
    font = kwargs.get('font',paper_font)
    plot = kwargs.get('plot',True)
    title = kwargs.get('title',False)
    ax_grab = kwargs.get('ax_grab',False)

    st = obspy.core.Stream()
    for idx, tr in enumerate(st_in):
        st += phase_window(tr,window_phase,window_tuple)

    def mean_range(st):
        a = []
        for tr in st:
            a.append(tr.stats.sac['gcarc'])
        mn_r = np.mean(a)
        return mn_r

    def roll_zero(array,n):
        if n < 0:
            array = np.roll(array,n)
            array[n::] = 0
        else:
            array = np.roll(array,n)
            array[0:n] = 0
        return array

    def slant_stack(st,mn_range,slowness,n):
        d = st[0].stats.delta
        R = np.zeros(st[0].data.shape[0])
        for tr in st:
            az = tr.stats.sac['gcarc']-mn_range
            shift_in_sec = slowness*az
            shift_in_bin = int(shift_in_sec/d)
            x = roll_zero(tr.data,shift_in_bin)
            R += np.sign(x)*pow(np.abs(x),1./n)
        R = R/float(len(st))
        yi = R*pow(abs(R),n-1)
        hil = scipy.fftpack.hilbert(yi)
        yi = pow(hil**2+R**2,1/2.)
        return yi,R

    def phase_plot(ax,evdp,degree,phases,text_color):
        P_arrivals = model.get_travel_times(distance_in_degree = degree,
        source_depth_in_km = evdp,
        phase_list = ['P'])

        P_slowness = P_arrivals[0].ray_param_sec_degree
        P_time = P_arrivals[0].time

        arrivals = model.get_travel_times(distance_in_degree=degree,
        source_depth_in_km=evdp,
        phase_list = phases)
        if len(arrivals) != 0:
            colors = ['b','g','r','c','m','y','k']
            name = []
            for idx, ii in enumerate(arrivals):
                if ii.name in name:
                    continue
                else:
                    name.append(ii.name)
                    p = ii.ray_param_sec_degree-P_slowness
                    time = ii.time-P_time
                    ax.scatter(time,p,s=300,marker='D',zorder=20,
                           facecolors='None',lw=1,edgecolor=text_color)
                #ax.text(time,p,ii.name,fontsize=16,color=text_color)

    mn_r = mean_range(st)
    evdp = st[0].stats.sac['evdp']

    #st.normalize()

    vesp_y = np.linspace(0,0,num=st[0].data.shape[0])
    vesp_R = np.linspace(0,0,num=st[0].data.shape[0])
    for ii in np.arange(window_slowness[0],window_slowness[1],-1*slowness_tick):
        yi,R = slant_stack(st,mn_r,ii,1.0)
        vesp_y= np.vstack((vesp_y,yi))
        vesp_R= np.vstack((vesp_R,R))
    vesp_y = vesp_y[1::,:]
    vesp_R1 = vesp_R[1::,:]*2
    if plot == False:
        return vesp_R
    vesp_y = vesp_y/ vesp_y.max()

    if ax_grab != False:
        ax = ax_grab
        image_0 = ax.imshow(np.log10(vesp_y),aspect='auto',interpolation='lanczos',
           extent=[window_tuple[0],window_tuple[1],window_slowness[0],window_slowness[1]],
           cmap=cmap,vmin=clim[0],vmax=clim[1])
        return image_0

    fig, ax = plt.subplots(2,sharex=True,figsize=(15,10))

    image_0 = ax[0].imshow(np.log10(vesp_y),aspect='auto',interpolation='lanczos',
           extent=[window_tuple[0],window_tuple[1],window_slowness[0],window_slowness[1]],
           cmap=cmap,vmin=clim[0],vmax=clim[1])
    one_stack = vesp_y

    vesp_y = np.linspace(0,0,num=st[0].data.shape[0])
    vesp_R = np.linspace(0,0,num=st[0].data.shape[0])
    for ii in np.arange(window_slowness[0],window_slowness[1],-1*slowness_tick):
        yi,R = slant_stack(st,mn_r,ii,n_root)
        vesp_y= np.vstack((vesp_y,yi))
        vesp_R= np.vstack((vesp_R,R))
    vesp_y = vesp_y[1::,:]
    vesp_R = vesp_R[1::,:]
    vesp_y = vesp_y/ vesp_y.max()

    image_1 = ax[1].imshow(np.log10(vesp_y), aspect='auto',
         interpolation='lanczos', extent=[window_tuple[0],
         window_tuple[1],window_slowness[0],window_slowness[1]],cmap=cmap, vmin=clim[0],vmax=clim[1])

    two_stack = vesp_y

    cbar_0 = fig.colorbar(image_0,ax=ax[0])
    cbar_0.set_label('Log(Seismic energy)',fontdict=font)
    cbar_1 = fig.colorbar(image_1,ax=ax[1])
    cbar_1.set_label('Log(Seismic energy)',fontdict=font)
    ax[0].set_xlim(window_tuple)
    ax[1].set_xlim(window_tuple)
    ax[1].xaxis.set(ticks=range(window_tuple[0],window_tuple[1],10))
    ax[0].xaxis.set(ticks=range(window_tuple[0],window_tuple[1],10))
    ax[0].set_ylim([window_slowness[0],window_slowness[1]])
    ax[1].set_ylim([window_slowness[0],window_slowness[1]])
    ax[0].grid(color='w',lw=2,alpha=0.9)
    ax[1].grid(color='w',lw=2,alpha=0.9)
    ax[1].set_ylabel('Slowness (s/deg)',fontdict=font)
    ax[0].set_ylabel('Slowness (s/deg)',fontdict=font)
    ax[1].set_xlabel('Seconds after {}'.format(window_phase[0]),fontdict=font)
    if title == True:
        ax[0].set_title('Start: {} \n Source Depth: {} km, Ref_dist: {} deg, {} \
                     \n Bottom : N-root = {} Top: N-root = 1'
                  .format(st[0].stats.starttime,
                  round(st[0].stats.sac['evdp'],3),
                  round(mn_r,3), os.getcwd().split('-')[3],
                  str(n_root)))

    if phase_list:
        phase_plot(ax[0],evdp,mn_r,phase_list,text_color='white')
        phase_plot(ax[1],evdp,mn_r,phase_list,text_color='white')

    if save != False:
        plt.savefig(save+'/vespagram.pdf',format='pdf')

    time_vec = np.linspace(window_tuple[0], window_tuple[1],
               num=vesp_R.shape[1])

    figR, axR= plt.subplots(1,figsize=(14,7))

    #vesp_R *= 2
    for idx, ii in enumerate(np.arange(window_slowness[1],window_slowness[0],
                             slowness_tick)):
        vesp_R1[idx,:] += ii
        axR.fill_between(time_vec,ii,vesp_R1[idx,:],where=vesp_R1[idx,:] >= ii,
                         facecolor='goldenrod',alpha=0.8,lw=0.5)
        axR.fill_between(time_vec,ii,vesp_R1[idx,:],where=vesp_R1[idx,:] <= ii,
                         facecolor='blue',alpha=0.8,lw=0.5)
        #axR.plot(time_vec,vesp_R[idx,:])
        if phase_list:
            phase_plot(axR,evdp,mn_r,phase_list,text_color='black')

    axR.set_xlim(window_tuple)
    axR.set_ylim([window_slowness[0],window_slowness[1]])
    axR.set_ylabel('Slowness (s/deg)')
    axR.set_xlabel('Seconds after P')
    if title == True:
        axR.set_title('Start: {} \n Source Depth: {} km, Ref_dist: {} deg, {}'
                  .format(st[0].stats.starttime,
                   round(st[0].stats.sac['evdp'],3),round(mn_r,3),
                   os.getcwd().split('-')[3]))
    axR.set_xticks(np.arange(window_tuple[0],window_tuple[1],10))
    axR.grid()


    if save != False:
        plt.savefig(save+'/wave.pdf',format='pdf')
    else:
        plt.show()

    return vesp_R1