Пример #1
0
 def getpeaks(self, sample):
     from numarray import nonzero
     from numarray.fft import real_fft
     fft = abs(real_fft(sample))
     # We compare each point to the point on either side - we must be
     # greater than both.
     # To do this, we left-shift and right-shift the array by one to
     # compare.
     peaks = nonzero((fft[1:-1] > fft[:-2]) * (fft[1:-1] > fft[2:]))
     if not len(peaks) or not len(peaks[0]):
         return ()
     # Avoiding 'zip; sort; reverse' will give a big speedup.
     try:
         peakvals = zip(fft[1:-1].take(peaks)[0], peaks[0])
     except:
         print("pppp", peaks)
         raise
     peakvals.sort(); peakvals.reverse()
     if len(peakvals) > 2:
         (val1,ind1),(val2,ind2),(val3,ind3) = peakvals[:3]
         # Peak 3 should be no more than 2/3 the size of peak 2
         # For GSM/Speex mangled audio, peak3 is about 0.55 * peak2
         # at the worst case.
         if val2 > 1.5*val3:
             # Add one to the index because we took [1:-1] before
             return (ind2+1,ind1+1)
         else:
             return ()
     elif len(peakvals) == 2:
         (val2,ind2),(val1,ind1) = peakvals
         # Add one to the index because we took [1:-1] before
         return (ind2+1,ind1+1)
     else:
         (val1,ind1), = peakvals
         return (ind1,0)
Пример #2
0
 def getpeaks(self, sample):
     from numarray import nonzero
     from numarray.fft import real_fft
     fft = abs(real_fft(sample))
     # We compare each point to the point on either side - we must be
     # greater than both.
     # To do this, we left-shift and right-shift the array by one to
     # compare.
     peaks = nonzero((fft[1:-1] > fft[:-2]) * (fft[1:-1] > fft[2:]))
     if not len(peaks) or not len(peaks[0]):
         return ()
     # Avoiding 'zip; sort; reverse' will give a big speedup.
     try:
         peakvals = zip(fft[1:-1].take(peaks)[0], peaks[0])
     except:
         print "pppp", peaks
         raise
     peakvals.sort(); peakvals.reverse()
     if len(peakvals) > 2:
         (val1,ind1),(val2,ind2),(val3,ind3) = peakvals[:3]
         # Peak 3 should be no more than 2/3 the size of peak 2
         # For GSM/Speex mangled audio, peak3 is about 0.55 * peak2
         # at the worst case.
         if val2 > 1.5*val3:
             # Add one to the index because we took [1:-1] before
             return (ind2+1,ind1+1)
         else:
             return ()
     elif len(peakvals) == 2:
         (val2,ind2),(val1,ind1) = peakvals
         # Add one to the index because we took [1:-1] before
         return (ind2+1,ind1+1)
     else:
         (val1,ind1), = peakvals
         return (ind1,0)
Пример #3
0
def complement(ind_arr, n):
    """
    Find the complement of the set of indices in ind_arr from
    arange(n)
    """

    mat = numarray.ones(n)
    numarray.put(mat, ind_arr, 0)
    out = numarray.nonzero(mat)
    return out[0]
Пример #4
0
 def locate(self, P1, P2, C):
     # Find location that triggered testfunc and initialize testfunc to that index
     val1 = (P1[0]-self.testfuncs[0].lower)*(self.testfuncs[0].upper-P1[0])
     val2 = (P2[0]-self.testfuncs[0].lower)*(self.testfuncs[0].upper-P2[0])
     ind = nonzero(val1*val2 < 0)
     self.testfuncs[0].ind = ind
     self.testfuncs[0].func = self.testfuncs[0].one
     
     X, V = BifPoint.locate(self, P1, P2, C)
     
     # Set testfunc back to monitoring all
     self.testfuncs[0].ind = None
     self.testfuncs[0].func = self.testfuncs[0].all
     
     return X, V
Пример #5
0
#Fig.set_figsize_inches( (5.75, 4.3) )
Fig.set_size_inches( (8, 6) )
##print pylab.gca().get_position()
ax.set_position([0.13,
                 0.14,
                 0.775,
                 0.77])
Fig.savefig(outfilename+".eps")
Fig.savefig(outfilename+".png", dpi=300)

pylab.show()

### find the amount of time value exceeded 6
Threshold = 6.0

Exceed = len(N.nonzero(Etotal > Threshold)[0])
print "Number of hours Energy greater than %f : %i"%(Threshold, Exceed )
print "Fraction of total: %f"%(float(Exceed) / len(Etotal) )


### Rob Naim's numbers:

## Hs(m)/Tp(s)/peak orbital velocity (cm/s)
## 2/6/33
## 2/9/57
## 4/6/66
## 4/9/115

##data = [(2, 6),
##        (2, 9),
##        (4, 6),