• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python numpy.bartlett函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中numpy.bartlett函数的典型用法代码示例。如果您正苦于以下问题:Python bartlett函数的具体用法?Python bartlett怎么用?Python bartlett使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了bartlett函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_perform

 def test_perform(self):
     x = tensor.lscalar()
     f = function([x], self.op(x))
     M = numpy.random.random_integers(3, 50, size=())
     assert numpy.allclose(f(M), numpy.bartlett(M))
     assert numpy.allclose(f(0), numpy.bartlett(0))
     assert numpy.allclose(f(-1), numpy.bartlett(-1))
     b = numpy.array([17], dtype='uint8')
     assert numpy.allclose(f(b[0]), numpy.bartlett(b[0]))
开发者ID:jsalvatier,项目名称:Theano-1,代码行数:9,代码来源:test_extra_ops.py


示例2: smooth

def smooth(x, windowLen, windowType="boxcar"):
    """Smooth a numpy array, returning the smoothed values
    
    Adapted from http://www.scipy.org/Cookbook/SignalSmooth"""
    if x.ndim != 1:
        raise ValueError("smooth only accepts 1 dimension arrays.")
 
    if x.size < windowLen:
        raise ValueError("Input vector needs to be bigger than window size.")

    if windowLen < 3:
        return x

    if windowType == "boxcar":
        w = np.ones(windowLen,'d')
    elif windowType == "hamming":
        w = np.hamming(windowLen)
    elif windowType == "hanning":
        w = np.hanning(windowLen)
    elif windowType == "bartlett":
        w = np.bartlett(windowLen)
    elif windowType == "blackman":
        w = np.blackman(windowLen)
    else:
        raise ValueError("windowType %s is not one of 'boxcar', 'hanning', 'hamming', 'bartlett', 'blackman'"
                         % windowType)

    s = np.r_[x[windowLen-1:0:-1],x,x[-1:-windowLen:-1]]

    y = np.convolve(w/w.sum(), s, mode='valid')

    return y[windowLen//2:-windowLen//2 + 1]
开发者ID:lsst-dm,项目名称:fe55,代码行数:32,代码来源:fe55.py


示例3: power_spectrum

def power_spectrum(trace, time_window=1000, overlap_window=None, enforce_pow2=True, freq_range=None):
# -----------------------------------------------------------------------------
    '''
    Returns the power spectrum of trace. Parameters set to fit with what Paolo 
    does within his project.
    '''
    from matplotlib.mlab import psd
    from matplotlib.pylab import detrend_linear, detrend_mean, detrend_none
    from neurovivo.common import nextpow2
        
    dt = (trace._time[1]-trace._time[0]).rescale(pq.ms).item()
    Fs = 1000./dt
    NFFT=int(time_window/dt)
    if enforce_pow2:
        NFFT=nextpow2(NFFT)
        time_window = 1.*time_window*NFFT/int(time_window/dt)
    if overlap_window == None:
        overlap_window = 0.75 * time_window
    noverlap=int(overlap_window/dt)
    window = np.bartlett(NFFT)
    #print dt, Fs, NFFT, noverlap
    pows, freqs = psd(detrend_mean(trace._data), NFFT=NFFT, Fs=Fs, noverlap=noverlap, window=window, detrend=detrend_none)
    if freq_range == None:
        return pows, freqs
    else:
        freqs, pows = cmn.splice_two_vectors(freqs, pows, freq_range)
        return pows, freqs
开发者ID:mpelko,项目名称:neurovivo,代码行数:27,代码来源:trace_analysis.py


示例4: plotWindowFunc

def plotWindowFunc():
	plt.clf()
	plt.plot(np.arange(20), np.kaiser(20,3.5))
	plt.plot(np.arange(20), np.bartlett(20))
	plt.plot(np.arange(20), np.blackman(20))
	plt.plot(np.arange(20), np.hamming(20))
	plt.plot(np.arange(20), np.hanning(20))
开发者ID:beevageeva,项目名称:tcomp,代码行数:7,代码来源:f3d.py


示例5: apply_filter

 def apply_filter(self, array):
     if len(array.shape)!=1:
         return False # need 2D data
     nx = array.shape[0]
     # Apodization function
     if self.type == 1:
         ft = np.bartlett(nx)
     elif self.type == 2:
         ft = np.blackman(nx)
     elif self.type == 3:
         ft = np.hamming(nx)
     elif self.type == 4:
         ft = np.hanning(nx)
     elif self.type == 5:
         # Blackman-Harris window
         a0 = 0.35875
         a1 = 0.48829
         a2 = 0.14128
         a3 = 0.01168
         x = np.linspace(0,1,nx)
         ft = a0 - a1*np.cos(2*np.pi*x) + a2*np.cos(4*np.pi*x) + a3*np.cos(6*np.pi*x) 
     elif self.type == 6:
         # Lanczos window
         x = np.linspace(-1,1,nx)
         ft = np.sinc(x)
     elif self.type == 7:
         x = np.linspace(-1,1,nx)
         exec('x='+self.custom)
         ft = x
     else:
         ft = np.ones(nx)
     
     array.data = array.data*ft
     return True
开发者ID:vpaeder,项目名称:terapy,代码行数:34,代码来源:apodization.py


示例6: single_taper_spectrum

def single_taper_spectrum(data, delta, taper_name=None):
    """
    Returns the spectrum and the corresponding frequencies for data with the
    given taper.
    """
    length = len(data)
    good_length = length // 2 + 1
    # Create the frequencies.
    # XXX: This might be some kind of hack
    freq = abs(np.fft.fftfreq(length, delta)[:good_length])
    # Create the tapers.
    if taper_name == 'bartlett':
        taper = np.bartlett(length)
    elif taper_name == 'blackman':
        taper = np.blackman(length)
    elif taper_name == 'boxcar':
        taper = np.ones(length)
    elif taper_name == 'hamming':
        taper = np.hamming(length)
    elif taper_name == 'hanning':
        taper = np.hanning(length)
    elif 'kaiser' in taper_name:
        taper = np.kaiser(length, beta=14)
    # Should never happen.
    else:
        msg = 'Something went wrong.'
        raise Exception(msg)
    # Detrend the data.
    data = detrend(data)
    # Apply the taper.
    data *= taper
    spec = abs(np.fft.rfft(data)) ** 2
    return spec, freq
开发者ID:aminkhalil,项目名称:HtoV-Toolbox,代码行数:33,代码来源:utils.py


示例7: estimate_unbnd_conc_in_region

def estimate_unbnd_conc_in_region(
        motif, score_cov, atacseq_cov, chipseq_rd_cov,
        frag_len, max_chemical_affinity_change):
    # trim the read coverage to account for the motif length
    trimmed_atacseq_cov = atacseq_cov[len(motif)+1:]
    chipseq_rd_cov = chipseq_rd_cov[len(motif)+1:]

    # normalzie the atacseq read coverage
    atacseq_weights = trimmed_atacseq_cov/trimmed_atacseq_cov.max()
    
    # build the smoothing window
    sm_window = np.ones(frag_len, dtype=float)/frag_len
    sm_window = np.bartlett(2*frag_len)
    sm_window = sm_window/sm_window.sum()

    def build_occ(log_tf_conc):
        raw_occ = logistic(log_tf_conc + score_cov/(R*T))
        occ = raw_occ*atacseq_weights
        smoothed_occ = np.convolve(sm_window, occ/occ.sum(), mode='same')

        return raw_occ, occ, smoothed_occ

    def calc_lhd(log_tf_conc):
        raw_occ, occ, smoothed_occ = build_occ(-log_tf_conc)
        #diff = (100*smoothed_occ - 100*rd_cov/rd_cov.sum())**2
        lhd = -(np.log(smoothed_occ + 1e-12)*chipseq_rd_cov).sum()
        #print log_tf_conc, diff.sum()
        return lhd

    res = brute(calc_lhd, ranges=(
        slice(0, max_chemical_affinity_change, 1.0),))[0]
    log_tf_conc = max(0, min(max_chemical_affinity_change, res))
                      
    return -log_tf_conc
开发者ID:csfoo,项目名称:TF_binding,代码行数:34,代码来源:motif_tools.py


示例8: smooth

def smooth(input_data, nth_octave = 6, window_type='hamming'):
    """ Smooth input data over 1/n octave """

    f_min = 30
    f_max = 20e3

    number_of_octaves = math.log(f_max / f_min, 2)

    # ideally, this should be computed from the display resolution
    number_of_points = 4048
    points_per_octave = number_of_points / number_of_octaves

    log_data = _distribute_over_log(input_data, f_min, f_max, 
                                                 number_of_points)

    window_length = points_per_octave / nth_octave

    if window_type == 'hamming':
        window = np.hamming(window_length)
    elif window_type == 'bartlett':
        window = np.bartlett(window_length)
    elif window_type == 'blackman':
        window = np.blackman(window_length)
    elif window_type == 'hanning':
        window = np.hanning(window_length)

    output = np.convolve(window / window.sum(), log_data, mode='same')
    return output
开发者ID:Psirus,项目名称:kuray,代码行数:28,代码来源:smoothing.py


示例9: bartlett_window

	def bartlett_window(self, show=0):
		apod = N.bartlett(self.data_points)
		for i in range(2):
			self.the_result.y[i] = self.the_result.y[i]*apod
		if show == 1:
			return self.the_result
		return self
开发者ID:BackupTheBerlios,项目名称:damaris-svn,代码行数:7,代码来源:DaFFT.py


示例10: mdist_curves

def mdist_curves(mdist_real):
    """
    fit curve comparing median location error to the actual location error
    """
    CHUNKS = 10
    dists_ = np.array(list(mdist_real))
    dists = dists_[dists_[:,0].argsort()]

    dist_count = dists.shape[0]
    # cut off the start to make even chunks
    chunks = np.split(dists[(dist_count%CHUNKS):,:],CHUNKS)
    bins = utils.dist_bins(30)

    for index,chunk in enumerate(chunks):
        row = chunk[:,1]
        hist,b = np.histogram(row,bins)

        bin_mids = (b[:-1]+b[1:])/2
        bin_areas = np.pi*(b[1:]**2 - b[:-1]**2)
        scaled_hist = hist/(bin_areas*len(row))
        window = np.bartlett(5)
        smooth_hist=np.convolve(scaled_hist,window,mode='same')/sum(window)
        coeffs = np.polyfit(
                    np.log(bin_mids[1:121]),
                    np.log(smooth_hist[1:121]),
                    3)

        yield dict(
                coeffs = list(coeffs),
                cutoff = 0 if index==0 else chunk[0,0],
                local = scaled_hist[0],
                )
开发者ID:JeffAMcGee,项目名称:friendloc,代码行数:32,代码来源:prep.py


示例11: SelectWindowsFun

    def SelectWindowsFun(self, index):
        #global window
		x = {0: np.ones(self.CHUNK), 
				1:  np.hamming(self.CHUNK), 
				2: np.hanning(self.CHUNK), 
				3: np.bartlett(self.CHUNK), 
				4: np.blackman(self.CHUNK)}
		self.window = x[index]
开发者ID:rlegnain,项目名称:PySpectrumAnalyzer,代码行数:8,代码来源:spectrumAnalyzer.py


示例12: nonlinear

def nonlinear(x):
    """
    Nonlinear energy operator for spike detection
    """
    xo = np.int32(x)
    y = [xo[n] ** 2 + xo[n - 1] * xo[n + 1] for n in range(1, len(x) - 1)]
    window = np.bartlett(12)
    return np.convolve(y, window)
开发者ID:jniediek,项目名称:combinato,代码行数:8,代码来源:filters.py


示例13: PowerSpectrum2

def PowerSpectrum2(im, win=2, n1=1, n2=0):
    """2D spectrum estimation using the modified periodogram.
    This one includes a window function to decrease variance in \
    the estimate.
    
    :param x: input sequence
    :type x: numpy.array
    :param n1: starting index, x(n1)
    :type n1: int
    :param n2: ending index, x(n2)
    :type n2: int
    :param win: The window type \n
                1 = Rectangular \n
                2 = Hamming \n
                3 = Hanning \n
                4 = Bartlett \n
                5 = Blackman \n
    :type win: int
    
    :returns: spectrum estimate.
    :rtype: numpy.array
            
    .. note:: 
       If n1 and n2 are not specified the periodogram of the entire 
       sequence is computed.
    
    """
    
    if n2 == 0:
        n2 = len(im[:,1])
    
    N  = n2 - n1 + 1
    w  = np.ones((N))
    
    if (win == 2):
        w = np.hamming(N)
    elif (win == 3):
        w = np.hanning(N)
    elif (win == 4):
        w = np.bartlett(N)
    elif (win == 5): 
        w = np.blackman(N);
    
    
    
    xs, ys = im.shape
    if xs/ys != 1:
        raise ValueError('Dimensions must be equal')
    
    
    m = w[:] * w[:][np.newaxis,:]
    
    U  = np.linalg.norm(w)**2.0 / N**2.0
    
    fftim = np.abs(np.fft.fftshift(np.fft.fft2(((im) * m)))) / ( (N**2.0) * U)
    
    return fftim
开发者ID:bps10,项目名称:base,代码行数:57,代码来源:image.py


示例14: fid_to_spec

    def fid_to_spec(self, window_f = ' ', beta = 2, t_start = 0., t_end = 100.0):
        '''
        FFT with zero-padding of the FID.
        Saves the result in self.spec
        
        Parameters
        ----------
        window_f: is the applied window function. The following window functions are
        applicable: hanning, hamming, blackman, bartlett, kaiser (beta (float) is only used
        by the kaiser window)
        t_start (float): specifies the beginning of the FID. The corresponding data points
        will be cut away.
        t_end (float): specifies the end of the FID. The corresponding data points
        will be cut away.
                
        Returns
        -------
        none
        
        Notes
        -----
        none
        '''
        if len(self.fid) != 0:

            fid = slice_fid(self.fid, t_start, t_end)
            window_f = window_f.lower()   # Choose the window function (default: rect / none)    
            
            if window_f == 'hanning':
                fid[:,1] = fid[:,1] * np.hanning(len(fid))
                
            elif window_f == 'hamming':
                fid[:,1] = fid[:,1] * np.hamming(len(fid))
                
            elif window_f == 'blackman':
                fid[:,1] = fid[:,1] * np.blackman(len(fid))
            
            elif window_f == 'bartlett':
                fid[:,1] = fid[:,1] * np.bartlett(len(fid))
                
            elif window_f == 'kaiser':
                fid[:,1] = fid[:,1] * np.kaiser(len(fid), beta)
            
            h = (int(np.sqrt(len(fid))) + 1) ** 2   # Zero padding to n**2 length to enhance computing speed
            spec = np.absolute(np.fft.rfft(fid[:,1], h)) ** 2 / h
            spec = spec[0:int(h/2)]
            freq = np.fft.fftfreq(h, np.abs(fid[2,0] - fid[1,0])) / 1.E6
            freq = freq[0:int(h/2)]  # Combine FFT and frequencies

            self.spec = np.column_stack([freq, spec])
            
            self.spec_params['npoints'] = len(spec)
            self.spec_params['max_f'] = np.max(freq)
            self.spec_params['min_f'] = np.min(freq)
            self.spec_params['delta_f'] = np.abs(freq[1]-freq[0])
开发者ID:chasquiwan,项目名称:RotSpecPy,代码行数:55,代码来源:spec.py


示例15: applyWindow

    def applyWindow(self, samples, window='hanning'):

        if window == 'bartlett':
            return samples*np.bartlett(len(samples))
        elif window == 'blackman':
            return samples*np.hanning(len(samples))
        elif window == 'hamming':
            return samples*np.hamming(len(samples))
        elif window == 'kaiser':
            return samples*np.kaiser(len(samples))
        else:
            return samples*np.hanning(len(samples))
开发者ID:spectralliaisons,项目名称:Spectrum,代码行数:12,代码来源:Spectrum.py


示例16: SelectWindowsFun

 def SelectWindowsFun(self, index):
     global window
     if   index == 0:
         window = np.ones(CHUNK)
     elif index == 1:
         window = np.hamming(CHUNK)
     elif index == 2:
         window = np.hanning(CHUNK)
     elif index == 3:
         window = np.bartlett(CHUNK)
     elif index == 4:
          window = np.blackman(CHUNK)
开发者ID:rlegnain,项目名称:PySpectrumAnalyzer,代码行数:12,代码来源:main.bkp.py


示例17: removeGating

    def removeGating(self, view=False):
        self.info("Removing gating gain (gating freq.: %.2f Hz)..." % self.gatefreq)
        N = int(1.0 / (self.gatefreq * self.deltaT))  # samples for one gating gain cycle
        maxN = int(self.Nfft / 2)  # max number of samples
        gategain = np.ones((maxN, 1))  # vector with length=Nfft/2
        n = int(np.floor(maxN / N))  # how many gating cycles are included in time window
        rest = maxN - (n * N)  # how many samples are left after n full cycles?
        for i in range(n):
            gategain[i * N:(i + 1) * N, 0] = np.bartlett(N)  # creates one triangle for full cycle
        gategain[n * N:, 0] = np.bartlett(N)[:rest]  # creates part of triangle for incomplete cycle
        self.gategain = 1.0 / gategain[self.samplendx]

        if view == True:
            from pylab import show, plot, xlabel, ylabel

            plot(self.t[:len(self.samplendx)], 10 * np.log10(1.0 / gategain[self.samplendx]))
            xlabel("Time [ns]")
            ylabel("Gating Gain [dB]")
            show()

        self.data = self.data * self.gategain
        self.done()
开发者ID:kmunve,项目名称:processgpr,代码行数:22,代码来源:hubra.py


示例18: pickWinType

def pickWinType(winType, N):
	""" Allow the user to pick a window type"""
	# Select window type
	if winType is "bartlett":
		window = np.bartlett(N)
	elif winType is "blackman":
		window = np.blackman(N)
	elif winType is "hamming":
		window = np.hamming(N)
	elif winType is "hanning":
		window = np.hanning(N)
	else:
		window = None

		return window
开发者ID:Alexander-Attar,项目名称:dsp,代码行数:15,代码来源:barkAnalyzer.py


示例19: get_window

 def get_window(self, n=None):
     if not n:
         n = self.lframes
     assert self.window in ['rectangular',
                            'bartlett', 'blackman', 'hamming', 'hanning']
     if self.window == 'rectangular':
         return np.ones(n)
     elif self.window == 'bartlett':
         return np.bartlett(n)
     elif self.window == 'blackman':
         return np.blackman(n)
     elif self.window == 'hamming':
         return np.hamming(n)
     else:
         return np.hanning(n)
开发者ID:xaratustrah,项目名称:iq_suite,代码行数:15,代码来源:iqbase.py


示例20: bartlett1d

def bartlett1d(data, M, **kwargs):
    """Bartlett 1D filter

    :Params:

        - **data**: A :mod:`MV2` variable.
        - **M**: Size of the Bartlett window.
        - Keywords are passed to :func:`generic1d`.

    :Return:

        - A :mod:`MV2` variable
    """
    weights = N.bartlett(M).astype(data.dtype.char)
    return generic1d(data, weights, **kwargs)
开发者ID:jfleroux,项目名称:vacumm,代码行数:15,代码来源:filters.py



注:本文中的numpy.bartlett函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python numpy.binary_repr函数代码示例发布时间:2022-05-27
下一篇:
Python numpy.average函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap