Full API documentation for curve fitting

analysis.curvefits module

class scan_framework.analysis.curvefits.AtomLine[source]

Wrapper class for fitting to pulsed lineshape for atomic resonances vs probe frequency: A * (2*pi*Omega0)^2/Omega^2 * sin^2(Omega*T/2) + y0 - Omega0 is Rabi frequency on resonance in Hz (not angular frequency) - f0 is resonance frequency in Hz (not angular frequency) - Omega = 2*pi*sqrt(Omega0^2 + (f-f0)^2) (angular frequency) - T is pulse duration in sec. - A and y0 are scaling factor and offset

__module__ = 'scan_framework.analysis.curvefits'
classmethod autoguess(x, y, hold={}, man_guess={}, man_bounds={}, man_scale={})[source]

Returns automated guesses for fit parameter starting points and bounds for parameter search. Manual guesses, bounds, and scales provided in dictionaries will override automatic values unless named parameter is being held. Valid keyword names are in cls.names()

static jacobian(fdata, A, Omega0, T, f0, y0)[source]

Returns Jacobian matrix of partial derivatives of A * Omega0^2/Omega^2 * sin^2(Omega*T/2) + y0, where Omega = sqrt(Omega0^2 + (2*pi*f-2*pi*f0)^2). Derivatives are evaluated for all values f in fdata, which can be a 1d array or a scalar. Rows are separate values of f, columns are partial derivatives w.r.t. different parameters

classmethod names()[source]

Valid parameter names for this function type, in order for value() method arguments

static value(f, A, Omega0, T, f0, y0)[source]

Value of lineshape at f

class scan_framework.analysis.curvefits.Exp[source]

Wrapper class for fitting to A * exp(x*b) + y0. Note that putting an offset (x-x0) in the exponent is mathematically equivalent to rescaling A, so no x offset is provided in this function.

__module__ = 'scan_framework.analysis.curvefits'
classmethod autoguess(x, y, hold={}, man_guess={}, man_bounds={}, man_scale={})[source]

Returns automated guesses for fit parameter starting points and bounds for parameter search. Manual guesses, bounds, and scales provided in dictionaries will override automatic values unless named parameter is being held. Valid keyword names are in cls.names()

static jacobian(xdata, A, b, y0)[source]

Returns Jacobian matrix of partial derivatives of A * exp(x*b) + y0, evaluated for all values x in xdata, which can be a 1d array or a scalar. Rows are separate values of x, columns are partial derivatives w.r.t. different parameters

classmethod names()[source]

Valid parameter names for this function type, in order for value() method arguments

static value(x, A, b, y0)[source]

Value of exponential at x

class scan_framework.analysis.curvefits.Exp2Sine[source]

Class for fitting to Gaussian decaying sine of form A * sin(2pi*f*t + phi) * exp(-(t/tau)^2) + y0

__module__ = 'scan_framework.analysis.curvefits'
classmethod autoguess(t, y, hold={}, man_guess={}, man_bounds={}, man_scale={})[source]

Returns automated guesses for fit parameter starting points and bounds for parameter search. Manual guesses, bounds, and scales provided in dictionaries will override automatic values unless named parameter is being held. Valid keyword names are in cls.names()

static jacobian(tdata, A, f, tau, phi, y0)[source]

Returns Jacobian matrix of partial derivatives of A * sin(2pi*f*t + phi) * exp(-(t/tau)^2) + y0, evaluated for all values t in tdata, which can be a 1d array or a scalar. Rows are separate values of t, columns are partial derivatives w.r.t. different params

classmethod names()[source]

Valid parameter names for this function type, in order for value() method arguments

static value(t, A, f, tau, phi, y0)[source]

Value of Gaussian decaying sine at time t

class scan_framework.analysis.curvefits.ExpSine[source]

Class for fitting to exponentially decaying sine of form A * sin(2pi*f*t + phi) * exp(-t/tau) + y0 A and f are defined to be always positive numbers.

__module__ = 'scan_framework.analysis.curvefits'
classmethod autoguess(t, y, hold={}, man_guess={}, man_bounds={}, man_scale={})[source]

Returns automated guesses for fit parameter starting points and bounds for parameter search. Manual guesses, bounds, and scales provided in dictionaries will override automatic values unless named parameter is being held. Valid keyword names are in cls.names()

static jacobian(tdata, A, f, tau, phi, y0)[source]

Returns Jacobian matrix of partial derivatives of A * sin(2pi*f*t + phi) * exp(-t/tau) + y0, evaluated for all values t in tdata, which can be a 1d array or a scalar. Rows are separate values of t, columns are partial derivatives w.r.t. different parameters

classmethod names()[source]

Valid parameter names for this function type, in order for value() method arguments

static value(t, A, f, tau, phi, y0)[source]

Value of exponentially decaying sine at time t

class scan_framework.analysis.curvefits.Fit(x, y, func, yerr=None, polydeg=4, knots=7)[source]

Class for fitting curves and storing/calculating results.

ExpSine : exponentially decaying sine, [A, f, tau, phi, y0] Exp2Sine : Gaussian decaying sine, [A, f, tau, phi, y0] Sine : sine wave, [A, f, phi, y0] Sin4 : sin^4, [A, f, phi, y0] Poly : N-degree polynomial, [p0, p1, …., pN] Lor : Lorentzian lineshape [A, Gamma, x0, y0] Gauss : Gaussian lineshape [A, sigma, x0, y0] AtomLine : lineshape for pulsed atomic transition [A, Omega0, T, f0, y0] Exp : exponential decay/rise, [A, b, y0] Power : power law, [A, alpha, y0] Spline : smoothing spline fit to data, variable knot number

Instantiate a Fit() object with the data to fit and the function to use, then call fit_data() to perform the fitting. For example, fitting to (x,y) data pairs, with one-standard-deviation uncertainties yerr (these are optional, and you can fit without providing yerr), using an exponentially decaying sine wave:

>>> fitobj = Fit(x, y, ExpSine, yerr)
>>> fitobj.fit_data()

Any data points where x, y, and/or yerr (if given) are NaN or inf are removed from the data prior to fitting. In addition, the data are sorted in ascending order in x. This only affects the internal data stored as attributes of fitobj; the original arrays from the user code are not modified. The cleaned, sorted data can be accessed as follows:

>>> fitobj.x
>>> fitobj.y
>>> fitobj.yerr

If provided, the values in yerr will be used to perform a weighted fit. If any of the values in yerr are zero or negative, a warning will be printed and an unweighted fit will be performed instead. If yerr is not provided, the fit defaults to an unweighted fit.

There are different lines of best fit calculated automatically. The first is calculated at all values in the cleaned, sorted fitobj.x, the second is calculated over the full range of fitobj.x but with 10 times as many points (finer spacing). This more finely spaced x data is stored as the attribute x_fine of the Fit() object. Lines of best fit can be accessed as follows:

>>> fitline = fitobj.fitline  # line of best fit at values x
>>> fitline = fitobj.fitline_fine  # line of best fit at 10x density

To plot these fitlines, it is recommended to plot them against the cleaned, sorted x values in the attributes fitobj.x and fitobj.x_fine, which may be in a different order than the original input x to the Fit() constructor:

>>> plot(fitobj.x, fitobj.fitline)
>>> plot(fitobj.x_fine, fitobj.fitline_fine)

Alternatively, you can calculate the value of the best fit line at any point or array of points xi with the value() method:

>>> yi = fitobj.value(xi)

This can be used to calculate a line of best fit to the original input x, rather than the cleaned, sorted fitobj.x, if for example the original input x is not given in ascending order.

The values of the fitted parameters can be accessed in different ways. For example, with an ExpSine, the time constant tau and its uncertainty can be found in the following ways:

>>> fitobj.params.tau
>>> fitobj.errs.tau_err
>>> fitobj.tau
>>> fitobj.tau_err

Fitted parameter values, errors, and a variety of other relevant output data (such as covariance matrices) are stored as attributes of the Fit() object. All of these attributes are also stored in a dictionary called fitresults, which is itself an attribute of the Fit() object. This dictionary can be saved in ARTIQ as a dataset in HDF5 format (since the Fit() object itself cannot be). For further details on the fitresults dictionary and a full listing of the attributes of the Fit() object, see the docstrings for the fit_data() and fitline_conf() methods.

If you would like to hold certain parameters fixed during a fit, this can be done by listing those parameters and their fixed values with the hold argument, which is a dictionary where keys are names of parameters to hold fixed and values are those values at which they should be held. Dictionary keys which do not correspond to a valid fit parameter name will be ignored (in the second line, “foobar” will be ignored).

>>> fitobj.fit_data(hold={'A': 0.7, 'tau': 25e-5})
>>> fitobj.fit_data(hold={'A': 0.7, 'tau': 25e-5, 'foobar': 2367234})

The fitting routines automatically calculate initial guesses for the fit parameters, and these are generally fairly robust. However, if the fit is not converging properly, it is possible to supply manual guesses for any fit parameter as a dictionary called man_guess to fit_data(). Order is unimportant, and manual guesses for nonexistent fit parameters will be ignored. For example, with an ExpSine fit, one could provide the following manual guesses (in the second line, “foobar” will be ignored).

>>> fitobj.fit_data(man_guess={'tau': 25e-6, 'f': 300e5})
>>> fitobj.fit_data(man_guess={'tau': 25e-6, 'f': 300e5, 'foobar': -91})

The default bounds for parameter values can be changed by passing the man_bounds argument, while the default scale factors for parameters (which are used to give more robust fitting, see the documentation for scipy.curve_fit parameter x_scale) can be changed with the man_scale argument. Usage is similar to man_guess, except that for man_bounds a 2-item tuple or list giving higher and lower bounds must be passed, rather than a single value. As with man_guess and hold, invalid parameter names are ignored.

>>> fitobj.fit_data(man_bounds={'A': (0,1)}, man_scale={'tau':1e-4})

Manual guesses, bounds, and scale are all ignored for parameters which are being held fixed with hold.

Confidence intervals for fit lines can also be calculated from the fit results. The fitline_conf() method calculates confidence bands at a specified confidence level at all points x. This method takes two optional arguments, which specify the confidence level (default is 0.95) and whether to calculate a confidence band for the more finely spaced fitline_fine (mentioned above) as well:

>>> fitobj.fitline_conf()
>>> fitobj.fitline_conf(conf=0.68, fine=True)

The conf_band() method allows the calculation of confidence bands for any point or array of points xi, with an optional argument for the confidence level (default 0.95), which returns the standard deviation plus upper and lower confidence levels for each point in xi:

>>> ysigma, yupper, ylower = fitobj.conf_band(xi, conf=0.68)

A full listing of the attributes of the Fit() object which you can access is given in the documentation for the fit_data() and fitline_conf() methods.

__dict__ = mappingproxy({'fit_data': <function Fit.fit_data>, '__annotations__': {}, '_make_hold_vector': <function Fit._make_hold_vector>, '__dict__': <attribute '__dict__' of 'Fit' objects>, 'conf_band': <function Fit.conf_band>, '__module__': 'scan_framework.analysis.curvefits', '__init__': <function Fit.__init__>, '__weakref__': <attribute '__weakref__' of 'Fit' objects>, 'value': <function Fit.value>, '__doc__': 'Class for fitting curves and storing/calculating results.\n\n    Fit types\n    ---------------------\n    ExpSine : exponentially decaying sine, [A, f, tau, phi, y0]\n    Exp2Sine : Gaussian decaying sine, [A, f, tau, phi, y0]\n    Sine : sine wave, [A, f, phi, y0]\n    Sin4 : sin^4, [A, f, phi, y0]\n    Poly : N-degree polynomial, [p0, p1, ...., pN]\n    Lor : Lorentzian lineshape [A, Gamma, x0, y0]\n    Gauss : Gaussian lineshape [A, sigma, x0, y0]\n    AtomLine : lineshape for pulsed atomic transition [A, Omega0, T, f0, y0]\n    Exp : exponential decay/rise, [A, b, y0]\n    Power : power law, [A, alpha, y0]\n    Spline : smoothing spline fit to data, variable knot number\n\n    Usage\n    ---------------------\n    Instantiate a `Fit()` object with the data to fit and the function to use,\n    then call `fit_data()` to perform the fitting.  For example, fitting to\n    (x,y) data pairs, with one-standard-deviation uncertainties yerr (these are\n    optional, and you can fit without providing yerr), using an exponentially\n    decaying sine wave:\n\n    >>> fitobj = Fit(x, y, ExpSine, yerr)\n    >>> fitobj.fit_data()\n\n    Any data points where x, y, and/or yerr (if given) are NaN or inf are\n    removed from the data prior to fitting.  In addition, the data are sorted\n    in ascending order in x.  This only affects the internal data stored as\n    attributes of fitobj; the original arrays from the user code are not\n    modified.  The cleaned, sorted data can be accessed as follows:\n\n    >>> fitobj.x\n    >>> fitobj.y\n    >>> fitobj.yerr\n\n    If provided, the values in yerr will be used to perform a weighted fit.  If\n    any of the values in yerr are zero or negative, a warning will be printed\n    and an unweighted fit will be performed instead.  If yerr is not provided,\n    the fit defaults to an unweighted fit.\n\n    There are different lines of best fit calculated automatically.  The first\n    is calculated at all values in the cleaned, sorted fitobj.x, the second is\n    calculated over the full range of fitobj.x but with 10 times as many points\n    (finer spacing).  This more finely spaced x data is stored as the attribute\n    x_fine of the Fit() object.  Lines of best fit can be accessed as follows:\n\n    >>> fitline = fitobj.fitline  # line of best fit at values x\n    >>> fitline = fitobj.fitline_fine  # line of best fit at 10x density\n\n    To plot these fitlines, it is recommended to plot them against the cleaned,\n    sorted x values in the attributes fitobj.x and fitobj.x_fine, which may be\n    in a different order than the original input x to the Fit() constructor:\n\n    >>> plot(fitobj.x, fitobj.fitline)\n    >>> plot(fitobj.x_fine, fitobj.fitline_fine)\n\n    Alternatively, you can calculate the value of the best fit line at any\n    point or array of points xi with the `value()` method:\n\n    >>> yi = fitobj.value(xi)\n\n    This can be used to calculate a line of best fit to the original input x,\n    rather than the cleaned, sorted fitobj.x, if for example the original input\n    x is not given in ascending order.\n\n    The values of the fitted parameters can be accessed in different ways.  For\n    example, with an ExpSine, the time constant tau and its uncertainty can be\n    found in the following ways:\n\n    >>> fitobj.params.tau\n    >>> fitobj.errs.tau_err\n    >>> fitobj.tau\n    >>> fitobj.tau_err\n\n    Fitted parameter values, errors, and a variety of other relevant output\n    data (such as covariance matrices) are stored as attributes of the `Fit()`\n    object.  All of these attributes are also stored in a dictionary called\n    `fitresults`, which is itself an attribute of the `Fit()` object.  This\n    dictionary can be saved in ARTIQ as a dataset in HDF5 format (since the\n    `Fit()` object itself cannot be).  For further details on the `fitresults`\n    dictionary and a full listing of the attributes of the `Fit()` object, see\n    the docstrings for the `fit_data()` and `fitline_conf()` methods.\n\n    If you would like to hold certain parameters fixed during a fit, this can\n    be done by listing those parameters and their fixed values with the `hold`\n    argument, which is a dictionary where keys are names of parameters to hold\n    fixed and values are those values at which they should be held.  Dictionary\n    keys which do not correspond to a valid fit parameter name will be ignored\n    (in the second line, "foobar" will be ignored).\n\n    >>> fitobj.fit_data(hold={\'A\': 0.7, \'tau\': 25e-5})\n    >>> fitobj.fit_data(hold={\'A\': 0.7, \'tau\': 25e-5, \'foobar\': 2367234})\n\n    The fitting routines automatically calculate initial guesses for the fit\n    parameters, and these are generally fairly robust.  However, if the fit is\n    not converging properly, it is possible to supply manual guesses for any\n    fit parameter as a dictionary called `man_guess` to `fit_data()`.  Order is\n    unimportant, and manual guesses for nonexistent fit parameters will be\n    ignored.  For example, with an ExpSine fit, one could provide the following\n    manual guesses (in the second line, "foobar" will be ignored).\n\n    >>> fitobj.fit_data(man_guess={\'tau\': 25e-6, \'f\': 300e5})\n    >>> fitobj.fit_data(man_guess={\'tau\': 25e-6, \'f\': 300e5, \'foobar\': -91})\n\n    The default bounds for parameter values can be changed by passing the\n    `man_bounds` argument, while the default scale factors for parameters\n    (which are used to give more robust fitting, see the documentation for\n    scipy.curve_fit parameter `x_scale`) can be changed with the `man_scale`\n    argument.  Usage is similar to `man_guess`, except that for `man_bounds`\n    a 2-item tuple or list giving higher and lower bounds must be passed,\n    rather than a single value.  As with `man_guess` and `hold`, invalid\n    parameter names are ignored.\n\n    >>> fitobj.fit_data(man_bounds={\'A\': (0,1)}, man_scale={\'tau\':1e-4})\n\n    Manual guesses, bounds, and scale are all ignored for parameters which are\n    being held fixed with `hold`.\n\n    Confidence intervals for fit lines can also be calculated from the fit\n    results.  The `fitline_conf()` method calculates confidence bands at a\n    specified confidence level at all points x.  This method takes two optional\n    arguments, which specify the confidence level (default is 0.95) and whether\n    to calculate a confidence band for the more finely spaced `fitline_fine`\n    (mentioned above) as well:\n\n    >>> fitobj.fitline_conf()\n    >>> fitobj.fitline_conf(conf=0.68, fine=True)\n\n    The `conf_band()` method allows the calculation of confidence bands for any\n    point or array of points xi, with an optional argument for the confidence\n    level (default 0.95), which returns the standard deviation plus upper and\n    lower confidence levels for each point in xi:\n\n    >>> ysigma, yupper, ylower = fitobj.conf_band(xi, conf=0.68)\n\n    A full listing of the attributes of the `Fit()` object which you can\n    access is given in the documentation for the `fit_data()` and\n    `fitline_conf()` methods.\n    ', 'fitline_conf': <function Fit.fitline_conf>})
__init__(x, y, func, yerr=None, polydeg=4, knots=7)[source]

Constructor for Fit() class Does not perform any fitting – for that call fit_data()

x : 1-d array of independent variable y : 1-d array of dependent variable (to fit), same shape as x func : class of fit function to use. fit to y = f(x). yerr : 1-d array of std. deviations of y, for fit weighting, optional polydeg : degree of polynomial fit, optional knots : number of knots to use in spline fit, optional

Knots will be evenly spaced over the range of x. If knots is larger than len(x)/2, it will be rounded down to len(x)/2. This prevents undesirable “spikes” from appearing in the fitted spline.

The constructor stores deep copies of x, y, and yerr (if given) as attributes of the Fit() object. Before doing so, it checks for and discards any data points where x, y, and/or yerr (if given) is NaN or inf. In addition, it sorts all the data in order of increasing x before storing as object attributes.

__module__ = 'scan_framework.analysis.curvefits'
__weakref__

list of weak references to the object (if defined)

_make_hold_vector()[source]

Look up all parameters in hold dictionary, create arrays for masking and providing values of held parameters as appropriate for func

conf_band(x, conf=0.95)[source]

Calculates confidence bands on line of best fit at locations x with specified confidence interval.

See Tellinghuisen, J. Phys. Chem. A 105, 3917 (2001) http://dx.doi.org/10.1021/jp003484u

NIST Engineering Statistics Handbook Section 2.5.5 http://www.itl.nist.gov/div898/handbook/mpc/section5/mpc55.htm

xvalues of independent variable x at which to evaluate confidence

interval. Can be scalar or 1-d array.

conf : confidence level for confidence bands, between 0 and 1

ysigma : standard deviation in list of best fit at location(s) x yupper : upper confidence band for line of best fit at specified

confidence level.

ylowerlower confidence band for line of best fit at specified

confidence level.

fit_data(hold={}, man_guess={}, man_bounds={}, man_scale={})[source]

Fit data x and y to function f, y = f(x). Calculates optimal fit parameters and their associated uncertainties, including full covariance matrix. By default, function makes automatic guesses for initial parameter values. Optional manual initial guesses can be given to override the autoguess function. If desired, user can specify fixed values for some parameters, and these will be held at the specified value and not fitted for. Optional manual parameter bounds or scaling factors can be specified to override default values as well.

Parameters
  • hold (dictionary of fit parameters to hold fixed, with their values) – The named parameters will not be fitted for, but will be held constant at the given values while the remaining parameters are varied to fit the data. Not for Poly or Spline. If a key in the dictionary does not correspond to a valid fit parameter, it is ignored and a warning is printed.

  • man_guess (dict of parameter name/value pairs, optional) – Initial guesses for the fit values of the named parameters will be taken from the corresponding values. Not for Poly or Spline. If a key in the dictionary does not correspond to a valid fit parameter, it is ignored and a warning is printed. If a parameter is being held with “hold”, manual guesses for that parameter are ignored and a warning is printed.

  • man_bounds (dict of parameter names/lists of upper/lower bounds,) – optional. Manual bounds (overriding the default bounds) for the named parameters will be taken from the corresponding lists. Each list of bounds must have exactly two elements: [lower, upper]. Not for Poly or Spline. If a key in the dictionary does not correspond to a valid fit parameter, it is ignored and a warning is printed. If a parameter is being held with “hold”, manual bounds for that parameter are ignored and a warning is printed.

  • man_scale (dict of parameter name/value pairs, optional) – Values are natural scale factors for the named parameters, passed to x_scale of scipy.curve_fit. Not for Poly or Spline. If a key in the dictionary does not correspond to a valid fit parameter, it is ignored and a warning is printed. If a parameter is being held with “hold”, manual scale for that parameter is ignored and a warning is printed.

  • results of the fit are stored as attributes of the instance of (The) –

  • Fit() class (the) –

  • well as key-value pairs in the dictionary (as) –

  • fitresults (dictionary representation of all attributes of the class) –

  • is an attribute of Fit() This dictionary enables (which) –

  • in ARTIQ/HDF5. This dictionary is also returned by fit_data() (saving) –

  • set by fit_data() (Attributes) –

  • ---------------------

  • bounds (tuple of lists of constraints on parameter values (see) – documentation for scipy.optimize.curve_fit)

  • c0 (polynomial fit coefficients for Poly fit. Form is) – c0 + c1*x + c2*x^2 + …

  • c1 (polynomial fit coefficients for Poly fit. Form is) – c0 + c1*x + c2*x^2 + …

  • c2 (polynomial fit coefficients for Poly fit. Form is) – c0 + c1*x + c2*x^2 + …

  • .. (errors (one std. dev.) for Poly fit coefficients) – c0 + c1*x + c2*x^2 + …

  • c0_err (errors (one std. dev.) for Poly fit coefficients) –

  • c1_err (errors (one std. dev.) for Poly fit coefficients) –

  • ..

  • covmat (covariance matrix from fit (not for Spline)) –

  • errs (namedtuple of errors (one std. dev.) on optimal fit parameters) –

  • extrema_locs (x locations of extremal points (zero deriv.) of Spline) –

  • extrema_vals (y values at these x locations of Spline fit) –

  • fit_good (Boolean, indicates successful fitting) –

  • fitline (line of best fit, evaluated at all locations x) –

  • fitline_fine (line of best fit, evaluated at all locations in x_fine) –

  • fitresults – instance.

  • guess (initial guess for fitting routine (not for Poly or Spline)) –

  • hold

  • max (maximum y value of Spline fit) –

  • maxloc (x location of maximum y value of Spline fit) –

  • min (minimum y value of Spline fit) –

  • minloc (x location of minimum y value of Spline fit) –

  • params (namedtuple of optimal fit parameters) –

  • popt (array of optimal fit parameters (duplicates params, used as) – a quicker way of accessing a list of the parameters if desired)

  • splobj (scipy spline object representing Spline fit) –

  • x_fine (evenly spaced list of x values between x[0] and x[-1],) – 10 times more points than x

  • x_scale (rough scaling factor for parameter values (helps convergence)) –

  • attributes are created for each of the named parameters (Individual) –

  • the specific fit function. Individual attributes are also created (of) –

  • their errors (for) –

  • the suffix '_err'. Thus for an ExpSine fit (with) –

:param : :param the following attributes will be created: A

A_err f f_err tau tau_err phi phi_err y0 y0_err

fitline_conf(conf=0.95, fine=False)[source]

Calculates confidence bands for lines of best fit. The user should be careful that if parameters are held during fitting, the confidence bands assume there is no uncertainty in these parameters and no covariance with other parameters, which may not be a valid assumption.

conf - confidence level for fit error bars, between 0 and 1. fine - Boolean, make confidence bands on the fine fit line as well

ysigma - 1-d numpy array of standard deviations in y values of line of

best fit

ysigma_fine - same as ysigma for for fitline_fine yupper - upper error bar for best fit line at specified confidence yupper_fine - same as yupper for for fitline_fine ylower - lower error bar for best fit line at specified confidence ylower_fine - same as lower for for fitline_fine

value(x)[source]

Calculate value of fitted function at x. Will raise an exception if there are no calculated fit parameters yet.

class scan_framework.analysis.curvefits.Gauss[source]

Class for fitting to Gaussian A * exp(-(x-x0)^2/(2*sigma^2)) + y0

__module__ = 'scan_framework.analysis.curvefits'
classmethod autoguess(x, y, hold={}, man_guess={}, man_bounds={}, man_scale={})[source]

Returns automated guesses for fit parameter starting points and bounds for parameter search. Manual guesses, bounds, and scales provided in dictionaries will override automatic values unless named parameter is being held. Valid keyword names are in cls.names()

static jacobian(xdata, A, sigma, x0, y0)[source]

Returns Jacobian matrix of partial derivatives of A * exp(-(x-x0)^2/(2*sigma^2)) + y0, evaluated for all values x in xdata, which can be a 1d array or a scalar. Rows are separate values of x, columns are partial derivatives w.r.t. different parameters

classmethod names()[source]

Valid parameter names for this function type, in order for value() method arguments

static value(x, A, sigma, x0, y0)[source]

Value of Gaussian at x

class scan_framework.analysis.curvefits.Lor[source]

Class for fitting to Lorentzian A * Gamma^2/((x-x0)^2+Gamma^2) + y0 As defined here Gamma is the HWHM of the Lorentzian.

__module__ = 'scan_framework.analysis.curvefits'
classmethod autoguess(x, y, hold={}, man_guess={}, man_bounds={}, man_scale={})[source]

Returns automated guesses for fit parameter starting points and bounds for parameter search. Manual guesses, bounds, and scales provided in dictionaries will override automatic values unless named parameter is being held. Valid keyword names are in cls.names()

static jacobian(xdata, A, Gamma, x0, y0)[source]

Returns Jacobian matrix of partial derivatives of A * Gamma^2/((x-x0)^2+Gamma^2) + y0, evaluated for all values x in xdata, which can be a 1d array or a scalar. Rows are separate values of x, columns are partial derivatives w.r.t. different parameters

classmethod names()[source]

Valid parameter names for this function type, in order for value() method arguments

static value(x, A, Gamma, x0, y0)[source]

Value of Lorentzian at x

class scan_framework.analysis.curvefits.Poly[source]

Class for fitting to polynomial functions Coefficients ci are numbered as below:

f(x) = c0 + (c1 * x) + (c2 * x^2) + … + (cn * x^n)

List of fit parameters is in order [cn, …. , c1, c0]

__module__ = 'scan_framework.analysis.curvefits'
static jacobian(x, *args)[source]

Jacobian for polynomial is x**n for the coefficient cn.

static value(x, pcoeff)[source]
class scan_framework.analysis.curvefits.Power[source]

Wrapper class for fitting to power law A * x^alpha + y0 Only works for positive values of A, and positive values of x. If data has A<0, fit to (x, -y) instead of (x,y).

__module__ = 'scan_framework.analysis.curvefits'
classmethod autoguess(x, y, hold={}, man_guess={}, man_bounds={}, man_scale={})[source]

Returns automated guesses for fit parameter starting points and bounds for parameter search. Manual guesses, bounds, and scales provided in dictionaries will override automatic values unless named parameter is being held. Valid keyword names are in cls.names()

static jacobian(xdata, A, alpha, y0)[source]

Returns Jacobian matrix of partial derivatives of A * x^alpha + y0, evaluated for all values x in xdata, which can be a 1d array or a scalar. Rows are separate values of x, columns are partial derivatives w.r.t. different parameters

classmethod names()[source]

Valid parameter names for this function type, in order for value() method arguments

static value(x, A, alpha, y0)[source]

Value of power law at x

class scan_framework.analysis.curvefits.Sin4[source]

Class for fitting to sin^4: A * (sin(2pi*f*t + phi))^4 + y0

__module__ = 'scan_framework.analysis.curvefits'
classmethod autoguess(t, y, hold={}, man_guess={}, man_bounds={}, man_scale={})[source]

Returns automated guesses for fit parameter starting points and bounds for parameter search. Manual guesses, bounds, and scales provided in dictionaries will override automatic values unless named parameter is being held. Valid keyword names are in cls.names()

static jacobian(tdata, A, f, phi, y0)[source]

Returns Jacobian matrix of partial derivatives of A * (sin(2pi*f*t + phi))^4 + y0, evaluated for all values t in tdata, which can be a 1d array or a scalar. Rows are separate values of t, columns are partial derivatives w.r.t. different parameters

classmethod names()[source]

Valid parameter names for this function type, in order for value() method arguments

static value(t, A, f, phi, y0)[source]

Value of sine^4 at time t

class scan_framework.analysis.curvefits.Sine[source]

Class for fitting to sine wave A * sin(2pi*f*t + phi) + y0

__module__ = 'scan_framework.analysis.curvefits'
classmethod autoguess(t, y, hold={}, man_guess={}, man_bounds={}, man_scale={})[source]

Returns automated guesses for fit parameter starting points and bounds for parameter search. Manual guesses, bounds, and scales provided in dictionaries will override automatic values unless named parameter is being held. Valid keyword names are in cls.names()

static jacobian(tdata, A, f, phi, y0)[source]

Returns Jacobian matrix of partial derivatives of A * sin(2pi*f*t + phi) + y0, evaluated for all values t in tdata, which can be a 1d array or a scalar. Rows are separate values of t, columns are partial derivatives w.r.t. different parameters

classmethod names()[source]

Valid parameter names for this function type, in order for value() method arguments

static value(t, A, f, phi, y0)[source]

Value of sine at time t

class scan_framework.analysis.curvefits.Spline[source]

Class for smoothing spline fit with n knots. This is a dummy, just used as a name to pass in. All the “guts” are handled by scipy spline routines.

__init__()[source]

Initialize self. See help(type(self)) for accurate signature.

__module__ = 'scan_framework.analysis.curvefits'