#NEWLINE# @ ValidateLarchPlugin #NEWLINE# def fit_peak( x , y , model , dy = None , background = None , step = None , negative = False , use_gamma = False , _larch = None ) : #NEWLINE# #INDENT# "fit peak to one a selection of simple 1d models\n\n    out = fit_peak(x, y, model, dy=None,\n                   background='linear', step='linear')\n\n    arguments:\n    ---------\n    x           array of values at which to calculate model\n    y           array of values for model to try to match\n    dy          array of values for uncertainty in y data to be matched.\n    model       name of model to use.  One of (case insensitive)\n                     'linear', 'quadratic', 'step', 'rectangle',\n                      'gaussian', 'lorentzian', 'voigt', 'exponential'\n    background  name of background model to use. One of (case insensitive)\n                     None, 'constant', 'linear', or 'quadratic'\n                this is ignored when model is 'linear' or 'quadratic'\n    step        name of step model to use for 'step' and 'rectangle' models.\n                One of (case insensitive):\n                    'linear', 'erf', or 'atan'\n    negative    True/False for whether peak or steps are expected to go down.\n    use_gamma   True/False for whether to use separate gamma parameter for\n                voigt model.\n    output:\n    -------\n    Group with fit parameters, and more...\n    " #NEWLINE# out = Group ( x = ( x * 1.0 ) , y = ( y * 1.0 ) , dy = 1.0 , model = model , background = background , step = step ) #NEWLINE# if ( dy is not None ) : #NEWLINE# #INDENT# out . dy = ( 1.0 * dy ) #NEWLINE# #UNINDENT# if ( model . lower ( ) not in MODELS ) : #NEWLINE# #INDENT# _larch . writer . write ( ( 'Unknown fit model: %s ' % model ) ) #NEWLINE# return None #NEWLINE# #UNINDENT# kwargs = dict ( negative = negative , background = background , step = step , _larch = _larch ) #NEWLINE# fitclass = MODELS [ model . lower ( ) ] #NEWLINE# if ( fitclass == VoigtModel ) : #NEWLINE# #INDENT# kwargs [ 'use_gamma' ] = use_gamma #NEWLINE# #UNINDENT# mod = fitclass ( ** kwargs ) #NEWLINE# mod . guess_starting_values ( out . y , out . x ) #NEWLINE# out . fit_init = mod . model ( x = out . x ) #NEWLINE# if ( background is not None ) : #NEWLINE# #INDENT# out . bkg_init = mod . calc_background ( out . x ) #NEWLINE# out . fit_init += out . bkg_init #NEWLINE# #UNINDENT# mod . fit ( out . y , x = out . x , dy = out . dy , _larch = _larch ) #NEWLINE# out . fit = mod . model ( x = out . x ) #NEWLINE# if ( background is not None ) : #NEWLINE# #INDENT# out . bkg = mod . calc_background ( out . x ) #NEWLINE# out . fit += out . bkg #NEWLINE# #UNINDENT# out . params = mod . params #NEWLINE# return out