See fittheories and fittheory for additional information.

bgtheories: Background theories for fitmanager

This modules defines a set of background model functions and associated estimation functions in a format that can be imported into a silx.math.fit.FitManager object.

A background function is a function that you want to add to a regular fit function prior to fitting the sum of both functions. This is useful, for instance, if you need to fit multiple gaussian peaks in an array of measured data points when the measurement is polluted by a background signal.

The models include common background models such as a constant value or a linear background.

It also includes background computation filters - strip and snip - that can extract a more complex low-curvature background signal from a signal with peaks having higher curvatures.

The source code of this module can serve as a template for defining your own fit background theories. The minimal skeleton of such a theory definition file is:

from silx.math.fit.fittheory import FitTheory

def bgfunction1(x, y0, …):
    bg_signal = …
    return bg_signal

def estimation_function1(x, y):
    …
    estimated_params = …
    constraints = …
    return estimated_params, constraints

THEORY = {
    'bg_theory_name1': FitTheory(
                        description='Description of theory 1',
                        function=bgfunction1,
                        parameters=('param name 1', 'param name 2', …),
                        estimate=estimation_function1,
                        configure=configuration_function1,
                        derivative=derivative_function1,
                        is_background=True),
    'theory_name_2': …,
}
strip_bg(x, y0, width, niter)[source]

Extract and return the strip bg from y0.

Use anchors coordinates in CONFIG[“AnchorsList”] if flag CONFIG[“AnchorsFlag”] is True. Convert anchors from x coordinate to array index prior to passing it to silx.math.fit.filters.strip

Parameters:
  • x – Abscissa array
  • x – Ordinate array (data values at x positions)
  • width – strip width
  • niter – strip niter
snip_bg(x, y0, width)[source]

Compute the snip bg for y0

estimate_linear(x, y)[source]

Estimate the linear parameters (constant, slope) of a y signal.

Strip peaks, then perform a linear regression.

estimate_strip(x, y)[source]

Estimation function for strip parameters.

Return parameters as defined in CONFIG dict, set constraints to FIXED.

estimate_snip(x, y)[source]

Estimation function for snip parameters.

Return parameters as defined in CONFIG dict, set constraints to FIXED.

poly(x, y, *pars)[source]

Order n polynomial. The order of the polynomial is defined by the number of coefficients (*pars).

estimate_poly(x, y, deg=2)[source]

Estimate polynomial coefficients.

estimate_quadratic_poly(x, y)[source]

Estimate quadratic polynomial coefficients.

estimate_cubic_poly(x, y)[source]

Estimate cubic polynomial coefficients.

estimate_quartic_poly(x, y)[source]

Estimate degree 4 polynomial coefficients.

estimate_quintic_poly(x, y)[source]

Estimate degree 5 polynomial coefficients.

configure(**kw)[source]

Update the CONFIG dict