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


Python Filter.median_filter方法代码示例

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


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

示例1: tesana

# 需要导入模块: import Filter [as 别名]
# 或者: from Filter import median_filter [as 别名]

#.........这里部分代码省略.........
            elif method == "cs":
                print "%s: %.2f +/- %.2f eV @ Ec%+.2f eV (Red. chi^2 = %.1f/%d = %.2f)" \
                    % (line, width, width_error, dE, chi_squared, dof, chi_squared/dof)

            return dE, width, width_error
    
        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')
    
        ## Ka
        ka = Analysis.ka(lc_pha_p, sigma=sigma)
        dE, width, width_error = _line_fit(ka, ka_min, "%sKa" % atom)
        _line_spectrum(ka, ka_min, "%sKa" % atom, dE, width, width_error)

        ## Kb
        kb = Analysis.kb(lc_pha_p, sigma=sigma)
        if kbfit:
            dE, width, width_error = _line_fit(kb, kb_min, "%sKb" % atom)
        else:
            width_error = None
        _line_spectrum(kb, kb_min, "%sKb" % atom, dE, width, width_error)

        ## Baseline
        f_pha_n = lc_pha_n[Filter.median_filter(lc_pha_n, sigma=sigma)]
        baseline = Analysis.sigma2fwhm(np.std(f_pha_n))
        print "Baseline resolution: %.2f eV" % baseline

        n, bins = Analysis.histogram(f_pha_n, binsize=binsize)
    
        if savedat:
            np.savetxt('%s-baseline.dat' % session, np.vstack(((bins[1:]+bins[:-1])/2, n)).T,
                header='Energy (keV), Count', delimiter='\t')

        if plotting:
            figure()
            label = 'FWHM$=%.2f$ eV' % baseline
            hist(f_pha_n, bins=bins, weights=np.ones(len(f_pha_n))/binsize, histtype='step', ec='k', label=label)
            mu, sigma = norm.fit(f_pha_n)
            E = np.linspace(bins.min(), bins.max(), 1000)
            plot(E, norm.pdf(E, loc=mu, scale=sigma)*len(f_pha_n), 'r-')
        
            xlabel('Energy$\quad$(eV)')
            ylabel('Normalized Count$\quad$(count/eV)')
        
            legend(frameon=False)
        
            tight_layout()
        
            savefig('%s-baseline.pdf' % session)
开发者ID:robios,项目名称:PyTES,代码行数:104,代码来源:Util.py


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