当前位置: 首页>>代码示例>>Python>>正文


Python Analysis.histogram方法代码示例

本文整理汇总了Python中Analysis.histogram方法的典型用法代码示例。如果您正苦于以下问题:Python Analysis.histogram方法的具体用法?Python Analysis.histogram怎么用?Python Analysis.histogram使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Analysis的用法示例。


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

示例1: _line_spectrum

# 需要导入模块: import Analysis [as 别名]
# 或者: from Analysis import histogram [as 别名]
        def _line_spectrum(data, min, line, dE, width, width_error):

            # Draw histogram
            n, bins = Analysis.histogram(data, binsize=binsize)

            if method in ("cs"):
                gn, gbins = Analysis.group_bin(n, bins, min=min)
            else:
                # No grouping in mle and ls
                gn, gbins = n, bins

            ngn = gn/(np.diff(gbins))
            ngn_sigma = np.sqrt(gn)/(np.diff(gbins))
            cbins = (gbins[1:]+gbins[:-1])/2

            if plotting:
                figure()

                if width_error is not None:
                    label = 'FWHM$=%.2f\pm %.2f$ eV' % (width, width_error)
                else:
                    label = 'FWHM$=%.2f$ eV (Fixed)' % width

                if method == "cs":
                    errorbar(cbins, ngn, yerr=ngn_sigma, xerr=np.diff(gbins)/2, capsize=0, ecolor='k', fmt=None, label=label)
                else:
                    hist(data, bins=gbins, weights=np.ones(len(data))/binsize, histtype='step', ec='k', label=label)

                E = np.linspace(bins.min(), bins.max(), 1000)

                model = Analysis.normalization(ngn, gbins, dE, width, line=line, shift=shift) \
                            * Analysis.line_model(E, dE, width, line=line, shift=shift, full=True)

                # Plot theoretical model
                plot(E, model[0], 'r-')

                # Plot fine structures
                for m in model[1:]:
                    plot(E, m, 'b--')

                xlabel('Energy$\quad$(eV)')
                ylabel('Normalized Count$\quad$(count/eV)')
                legend(frameon=False)

                ymin, ymax = ylim()
                ylim(ymin, ymax*1.1)
                tight_layout()

                savefig("%s-%s.pdf" % (session, line))

            if savedat:
                np.savetxt('%s-%s.dat' % (session, line), np.vstack((cbins, gn)).T,
                    header='Energy (keV), Count', delimiter='\t')
开发者ID:robios,项目名称:PyTES,代码行数:55,代码来源:Util.py

示例2: tesana

# 需要导入模块: import Analysis [as 别名]
# 或者: from Analysis import histogram [as 别名]
def tesana(t, p, n, lpfc=None, hpfc=None, binsize=1, max_shift=10,
            thre=0.4, filt=None, nulldc=False, offset=False, center=False, sigma=3,
            gain=None, dsr=None, shift=False, ocmethod="ols", flip=False, atom="Mn",
            kbfit=False, ignorekb=False, method="mle",
            rshunt=None, tbias=None, ites=None, ka_min=80, kb_min=40,
            tex=False, plotting=True, savedat=False, session="Unnamed"):
    """
    Perform TES Analysis
    
    Parameters (and their default values):
        t:          time data (array-like)
        p:          pulse data (array-like)
        n:          noise data (array-like)
        lpfc:       low-pass filter cut-off frequency in bins (Default: None)
        hpfc:       high-pass filter cut-off frequency in bins (Default: None)
        binsize:    energy bin size for histograms and fittings (only for ls ans cs) in eV (Default: 1)
        max_shift:  maximum allowed shifts to calculate maximum cross correlation (Default: 10)
        thre:       correlation threshold for offset correction (Default: 0.4)
        filt:       window function (hanning/hamming/blackman/tukey) (Default: None)
        nulldc:     nullify the DC bin when template generation (Default: False)
        offset:     subtract DC offset (Default: False)
        center:     centering pulse rise (Default: False)
        sigma:      sigmas for median filter (Default: 3)
        gain:       feedback gain for current-space conversion (Default: None)
        dsr:        down-sampling rate (Default: None)
        shift:      treat dE as energy shift instead of scaling (Default: False)
        ocmethod:   offset correction fitting method (ols/odr) (Default: ols)
        flip:       flip x and y when offset correction fitting (Default: False)
        atom:       atom to fit (Default: Mn)
        kbfit:      fit Kb line (Default: False)
        ignorekb:   ignore Kb line when linearity correction (Default: False)
        method:     fitting method (mle/ls/cs) (Default: mle)
        rshunt:     shunt resistance value for r-space conversion (Default: None)
        tbias:      TES bias current for r-space conversion (Default: None)
        ites:       TES current for r-space conversion (Default: None)
        ka_min:     minimum counts to group bins for Ka line (valid only for ls/cs fittings) (Default: 80)
        ka_min:     minimum counts to group bins for Kb line (valid only for ls/cs fittings) (Default: 20)
        tex:        use TeX for plots (Default: False)
        plotting:   generate and save plots (Default: True)
        savedat:    save data to files (Default: False)
        session:    session name for plots and data files (Default: Unnamed)
        
    Note:
        - Use offset option when using filt option
        - Consider using center option when using filt option
    """

    if plotting:
        # Import matplotlib
        import matplotlib
        matplotlib.use('Agg')
        matplotlib.rcParams['text.usetex'] = str(tex)
        from pylab import figure, plot, errorbar, hist, axvline, xlim, ylim, loglog, xlabel, ylabel, legend, tight_layout, savefig
        
        print "Session: %s" % session
    
    # Preparation
    p = np.asarray(p)
    n = np.asarray(n)
    t = np.asarray(t)
    dt = np.diff(t)[0]
    df = (dt * t.shape[-1])**-1
    
    # Subtract offset
    if offset:
        ofs = np.median(n)
        p -= ofs
        n -= ofs
    
    # Convert to current-space if needed
    if gain:
        print "Converting to current-space"
        p /= gain
        n /= gain
    
    # Convert to resistance-space
    Rspace = False
    if gain and rshunt and tbias and ites:
        print "Converting to resistance-space"
        ofs = np.median(n)
        p += (ites - ofs)
        n += (ites - ofs)
        
        # Convert to resistance
        p = (tbias - p) * rshunt / p
        n = (tbias - n) * rshunt / n
        
        Rspace = True
    
    # Down-sample
    if dsr > 1:
        p = p[:,:p.shape[-1]/dsr*dsr].reshape(p.shape[0], -1, dsr).mean(axis=-1)
        n = n[:,:n.shape[-1]/dsr*dsr].reshape(n.shape[0], -1, dsr).mean(axis=-1)
        dt *= dsr
        t = t[::dsr]

    # Pulse centering (for filtering)
    if center:
        # Roll pulse to the center
        r = p.shape[-1] / 2 - np.median(abs(p - Filter.offset(p)[:, np.newaxis]).argmax(axis=-1))
#.........这里部分代码省略.........
开发者ID:robios,项目名称:PyTES,代码行数:103,代码来源:Util.py


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