Example #1
0
def find_peaks(coefs,peak,cs_threshold=0.40,mask=None):
    gws = get_gws(coefs,mask)
#   find all extrema in the gws
    gws_extrema=generic.find_extrema(gws,mode='all')
    if gws_extrema.shape[0] == 0:
        print 'trying close'
        gws_extrema=generic.find_extrema(gws,mode='close',adj=1)

    if gws_extrema.shape[0] != 0:
#       look for extrema and zero crossings at particular scale
        cs_scale_extrema=generic.find_extrema(coefs[gws_extrema[peak],:],mode='all')
        cs_scale_zero_crossings=generic.find_zero_crossings(coefs[gws_extrema[peak],:],mode='all')
    #   threshold for calling an event as CS event - 100*cs_threshold% of peak coefficient
        threshold=np.abs(coefs[gws_extrema[peak],cs_scale_extrema]).max()*cs_threshold
    #   find start/stop indicies for cs events
        start=[]
        stop=[]
    #   for scale in extrema along peak in gws
        for i in range(1,len(cs_scale_extrema)):
    #       print coefs[gws_extrema[peak],cs_scale_extrema[i]]>threshold,coefs[gws_extrema[peak],cs_scale_extrema[i-1]]<0
    #       if coef at extrema is larger than threshold and coef at previous extrema is negative
            if (coefs[gws_extrema[peak],cs_scale_extrema[i]]>threshold) & (coefs[gws_extrema[peak],cs_scale_extrema[i-1]]<0):
                try:
    #               stop indicated by zero crossing following extrema of interest
                    stop.append(cs_scale_zero_crossings[cs_scale_zero_crossings>cs_scale_extrema[i]][0])
    #               start indicated by extrema previous to zero crossing
                    start.append(cs_scale_extrema[i-1])
                except IndexError:
                    pass

        return start,stop,gws_extrema
    else:
        print 'no extrema found'
        return 0,0,0
Example #2
0
def gws_plot(c,
             ax,
             max_period=None,
             min_time=0,
             max_time=None,
             xlabs=None,
             ylabs=None,
             peak=-1):

    scales = np.arange(1, max_period + 1)
    T = scales * np.pi / np.sqrt(2.)  #(eq 22 Collineau and Brunet 1993a)
    time = np.arange(min_time, max_time - 1)

    gws = get_gws(c[0:max_period - 1, min_time:max_time - 1])

    ax.semilogx(gws[0:max_period - 1], T[0:max_period - 1], '+')
    ax.set_ylim(T[0], T[max_period - 2])
    ax.grid(b=True, color='k', linestyle='-', linewidth=1)
    if xlabs != None: ax.set_xlabel(xlabs)
    if ylabs != None: ax.set_ylabel(ylabs)
    if peak > 0:
        gws_extrema = generic.find_extrema(gws, mode='all')
        ax.text(gws[gws_extrema[peak]], T[gws_extrema[peak]], 'x')
        ax.text(gws[gws_extrema[peak]] + 2,
                T[gws_extrema[peak]], ` np.round(T[gws_extrema[peak]], 1) `,
                fontsize=16,
                backgroundcolor='white',
                bbox=dict(facecolor='white', alpha=1.0))
Example #3
0
def find_peaks(coefs, peak, cs_threshold=0.40, mask=None):
    gws = get_gws(coefs, mask)
    #   find all extrema in the gws
    gws_extrema = generic.find_extrema(gws, mode='all')
    if gws_extrema.shape[0] == 0:
        print 'trying close'
        gws_extrema = generic.find_extrema(gws, mode='close', adj=1)

    if gws_extrema.shape[0] != 0:
        #       look for extrema and zero crossings at particular scale
        cs_scale_extrema = generic.find_extrema(coefs[gws_extrema[peak], :],
                                                mode='all')
        cs_scale_zero_crossings = generic.find_zero_crossings(
            coefs[gws_extrema[peak], :], mode='all')
        #   threshold for calling an event as CS event - 100*cs_threshold% of peak coefficient
        threshold = np.abs(coefs[gws_extrema[peak],
                                 cs_scale_extrema]).max() * cs_threshold
        #   find start/stop indicies for cs events
        start = []
        stop = []
        #   for scale in extrema along peak in gws
        for i in range(1, len(cs_scale_extrema)):
            #       print coefs[gws_extrema[peak],cs_scale_extrema[i]]>threshold,coefs[gws_extrema[peak],cs_scale_extrema[i-1]]<0
            #       if coef at extrema is larger than threshold and coef at previous extrema is negative
            if (coefs[gws_extrema[peak], cs_scale_extrema[i]] > threshold) & (
                    coefs[gws_extrema[peak], cs_scale_extrema[i - 1]] < 0):
                try:
                    #               stop indicated by zero crossing following extrema of interest
                    stop.append(cs_scale_zero_crossings[
                        cs_scale_zero_crossings > cs_scale_extrema[i]][0])
                    #               start indicated by extrema previous to zero crossing
                    start.append(cs_scale_extrema[i - 1])
                except IndexError:
                    pass

        return start, stop, gws_extrema
    else:
        print 'no extrema found'
        return 0, 0, 0
Example #4
0
def gws_plot(c,ax,max_period=None,min_time=0,max_time=None,
            xlabs=None,ylabs=None,peak=-1):

    scales = np.arange(1,max_period+1)
    T = scales*np.pi/np.sqrt(2.) #(eq 22 Collineau and Brunet 1993a)
    time = np.arange(min_time,max_time-1)

    gws = get_gws(c[0:max_period-1,min_time:max_time-1])

    ax.semilogx(gws[0:max_period-1],T[0:max_period-1],'+')
    ax.set_ylim(T[0],T[max_period-2])
    ax.grid(b=True,color='k',linestyle='-',linewidth=1)
    if xlabs!=None: ax.set_xlabel(xlabs)
    if ylabs!=None: ax.set_ylabel(ylabs)
    if peak > 0:
        gws_extrema=generic.find_extrema(gws,mode='all')
        ax.text(gws[gws_extrema[peak]],T[gws_extrema[peak]],'x')
        ax.text(gws[gws_extrema[peak]]+2,T[gws_extrema[peak]],`np.round(T[gws_extrema[peak]],1)`,
            fontsize=16,backgroundcolor='white',bbox=dict(facecolor='white', alpha=1.0))