def find_dominant(seg):
    """Finds the dominant frequency of a given ThinkDSP Wave object
    by Meg
    
    Arguments
    ---------
    seg: ThinkDSP Wave Obj
	a segment of Wave
    
    Returns
    -------
    dominant_freq: a Number
	the dominant frequency, relative to the framerate parameter specified in        the Wave.
    """
    lags, corrs = autocorr(seg)
    #argmax() gedom_freq_index = numpy.argmax(corrs[1:len(corrs)])+1
    dom_freq_index = argmax(corrs[1:len(corrs)])+1
    period = dom_freq_index/seg.framerate
    dom_freq = 1/period
    return dom_freq
示例#2
0
def dfluct_auto(energy, eels):
    """
    Computes the charge-density autocorrelation function using the eels
    spectrum

    Args
    ----
    energy : array-like
        energy scale

    eels : array-like
        electron energy-loss spectrum

    Returns
    -------
    array-like
        real part of autocorrelation function associated with charge-density
        fluctuations

    """
    # Following prefactor has to do with units in equation, i.e. converting
    # to eV and incorporating Planck constant
    return float(6.582118487e-16) * autocorr(dfluct_spectrum(energy, eels),
                                             method="pow").real
示例#3
0
            nTlp[l,:] = np.real(Tlp[l,:])/np.sqrt(cl[l])
    else:
        nTlp[l,:] = np.real(Tlp[l,:])/np.sqrt(cl[l])
nTlp = nTlp[2:,:]

t1 = time.time()-t0
ftxt.write(' - CPU time for computing normalized T_{l,p}: %.4f\n' % t1)
    
# Autocorrelation and AC discrepancy
thres = 2/np.sqrt(L-1); # threshold for autocorrelation
# compute autocorrelation and AC discrepancy
acf = np.zeros((lag_acd+1,Npix_acd),dtype='float64')
acd = np.zeros(Npix_acd,dtype='float64')
t0 = time.time()
for i in range(Npix_acd):
    acf[:,i] = autocorr(nTlp[:,i],lag_acd)
    acd[i] = np.sum(np.maximum(np.absolute(acf[1:,i])-thres,0))
t2 = time.time()-t0
ftxt.write(' - CPU time for computing AC discrepancy: %.4f\n' % t2)
# find max AC discrepancy
jmax = np.argmax(acd)
nTlp_mx = nTlp[:,jmax]
acd_mx = acd[jmax]
mx_coor = hp.pix2vec(Nside_acd,jmax)

ftxt.write(' - total CPU time for computing AC discrepancy: %.4f\n' % (t1+t2))

#%% save data
ftxt.write(' - saving data: acd,jmax,nalp_mx,mx_coor\n')
sio.savemat(sv_acd, mdict={'acd':acd,'jmax':jmax,'nTlp_mx':nTlp_mx,'mx_coor':mx_coor})
示例#4
0
import numpy as np
import autocorr

print "Sandvik:"
print autocorr.autocorr(autocorr.readfromfile('Sand.csv'))
print "ABB: "
print autocorr.autocorr(autocorr.readfromfile('ABB.csv'))
print "Fing: "
print autocorr.autocorr(autocorr.readfromfile('Fing.csv'))
print "HM: "
print autocorr.autocorr(autocorr.readfromfile('HM.csv'))

print autocorr.smallchanges(autocorr.readfromfile('Sand.csv'))

def n_best_slice_widths(image,n):
  xcor_signal = autocorr(abs(diff(abs(array(column_distances(image))))))
  indexes = range(len(xcor_signal))
  return nlargest(n,indexes[1:],key=lambda i: xcor_signal[i])
示例#6
0
 def test_autoccorr_output_type_method_pos(self):
     """autocorr should return type np.ndarray
     """
     self.assertIsInstance(autocorr(self.input_data, method="pow"),
                           np.ndarray)