當前位置: 首頁>>代碼示例>>Python>>正文


Python Group.dy方法代碼示例

本文整理匯總了Python中larch.Group.dy方法的典型用法代碼示例。如果您正苦於以下問題:Python Group.dy方法的具體用法?Python Group.dy怎麽用?Python Group.dy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在larch.Group的用法示例。


在下文中一共展示了Group.dy方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: fit_peak

# 需要導入模塊: from larch import Group [as 別名]
# 或者: from larch.Group import dy [as 別名]
def fit_peak(x, y, model, dy=None, background=None, step=None,
             negative=False, use_gamma=False, _larch=None):
    """fit peak to one a selection of simple 1d models

    out = fit_peak(x, y, model, dy=None,
                   background='linear', step='linear')

    arguments:
    ---------
    x           array of values at which to calculate model
    y           array of values for model to try to match
    dy          array of values for uncertainty in y data to be matched.
    model       name of model to use.  One of (case insensitive)
                     'linear', 'quadratic', 'step', 'rectangle',
                      'gaussian', 'lorentzian', 'voigt', 'exponential'
    background  name of background model to use. One of (case insensitive)
                     None, 'constant', 'linear', or 'quadratic'
                this is ignored when model is 'linear' or 'quadratic'
    step        name of step model to use for 'step' and 'rectangle' models.
                One of (case insensitive):
                    'linear', 'erf', or 'atan'
    negative    True/False for whether peak or steps are expected to go down.
    use_gamma   True/False for whether to use separate gamma parameter for
                voigt model.
    output:
    -------
    Group with fit parameters, and more...
    """
    out = Group(x=x*1.0, y=y*1.0, dy=1.0, model=model,
                background=background, step=step)
    if dy is not None:
        out.dy = 1.0*dy
    if model.lower() not in MODELS:
        _larch.writer.write('Unknown fit model: %s ' % model)
        return None

    kwargs = dict(negative=negative, background=background,
                  step=step, _larch=_larch)

    fitclass = MODELS[model.lower()]
    if fitclass == VoigtModel:
        kwargs['use_gamma'] = use_gamma

    mod = fitclass(**kwargs)
    mod.guess_starting_values(out.y, out.x)

    out.fit_init = mod.model(x=out.x)
    if background is not None:
        out.bkg_init = mod.calc_background(out.x)
        out.fit_init += out.bkg_init

    mod.fit(out.y, x=out.x, dy=out.dy, _larch=_larch)

    out.fit = mod.model(x=out.x)
    if background is not None:
        out.bkg = mod.calc_background(out.x)
        out.fit += out.bkg
    out.params = mod.params
    return out
開發者ID:Henry0422,項目名稱:xraylarch,代碼行數:61,代碼來源:fitpeak.py

示例2: fit_peak

# 需要導入模塊: from larch import Group [as 別名]
# 或者: from larch.Group import dy [as 別名]
def fit_peak(x, y, model, dy=None, background=None, form=None, step=None,
             negative=False, use_gamma=False, _larch=None):
    """fit peak to one a selection of simple 1d models

    out = fit_peak(x, y, model, dy=None,
                   background='linear', form='linear')

    arguments:
    ---------
    x           array of values at which to calculate model
    y           array of values for model to try to match
    dy          array of values for uncertainty in y data to be matched.
    model       name of model to use.  One of (case insensitive)
                     'linear', 'quadratic', 'step', 'rectangle',
                      'gaussian', 'lorentzian', 'voigt', 'exponential'
    background  name of background model to use. One of (case insensitive)
                     None, 'constant', 'linear', or 'quadratic'
                this is ignored when model is 'linear' or 'quadratic'
    form        name of form to use for 'step' and 'rectangle' models.
                One of (case insensitive):
                    'linear', 'erf', or 'atan'
    negative    True/False for whether peak or steps are expected to go down.
    use_gamma   True/False for whether to use separate gamma parameter for
                voigt model.
    output:
    -------
    Group with fit parameters, and more...
    """
    if form is None and step is not None:
        form = step
    out = Group(name='fit_peak result', x=x*1.0, y=y*1.0, dy=1.0,
                model=model, background=background, form=form)

    weight = None
    if dy is not None:
        out.dy = 1.0*dy
        weight = 1.0/max(1.e-16, abs(dy))

    if model.lower() not in MODELS:
        _larch.writer.write('Unknown fit model: %s ' % model)
        return None

    kwargs = dict(negative=negative, background=background,
                  form=form, weight=weight, _larch=_larch)

    fitclass = MODELS[model.lower()]
    if fitclass == VoigtModel:
        kwargs['use_gamma'] = use_gamma

    mod = fitclass(**kwargs)
    pars = mod.guess(out.y, out.x)

    if background is not None:
        bkg = MODELS[background.lower()](prefix='bkg_')
        bpars = bkg.guess(out.y, x=out.x)
        for p, par  in bpars.items():
            par.value = 0.
            par.vary = True
        pars += bpars
        mod += bkg

    out.init_params = pars

    result = mod.fit(out.y, params=pars, x=out.x) # , dy=out.dy)
    out.fit = mod.eval(result.params, x=out.x)
    out.fit_init = mod.eval(pars, x=out.x)

    out.fit_details = result
    out.chi_square  = result.chisqr
    out.chi_reduced = result.redchi

    for attr in ('aic', 'bic', 'covar', 'rfactor', 'params', 'nvarys',
                 'nfree', 'ndata', 'var_names', 'nfev', 'success',
                 'errorbars', 'message', 'lmdif_message', 'residual'):
        setattr(out, attr, getattr(result, attr, None))

    if background is not None:
        comps = mod.eval_components(x=out.x)
        out.bkg = comps['bkg_']
    return out
開發者ID:maurov,項目名稱:xraylarch,代碼行數:82,代碼來源:fitpeak.py


注:本文中的larch.Group.dy方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。