Background
Background
- class apav.analysis.background.Background(fit_interval, include_interval=(), model=<lmfit.Model: Model(power_law)>)[source]
Defines a background model through a specified range of a mass spectrum.
A background is fit on the provided fit_interval(s). Intervals provided to include_interval define ranges where mass spectrum ranges will use the background model for background subtraction. For example:
>>> bkg = Background((10, 12), (13, 20), models.PowerLawShiftModel())
Fits a shifted power law on the interval from 10 -> 12 Da. The background will be subtracted and applied to any mass ranges that begin in the interval from 13 -> 20 Da.
>>> bkg = Background([(10, 12), (15, 16)], [(13, 20), (22, 24)], models.PowerLawShiftModel())
Will fit the same power law model on 2 intervals from 10 -> 12 and 15 -> 16 Da. This background will be subtracted and applied to any mass ranges that begin in either of the intervals 13 ->20 Da or 22 -> 24 Da. This allows simple control over which background applies to which mass ranges, without being too explicit.
- Parameters:
fit_interval (
Union
[Tuple
[Number
,Number
],Sequence
[Tuple
[Number
,Number
]]]) – single or multiple intervals on the x to fit the background modelinclude_interval (
Union
[Tuple
[Number
,Number
],Sequence
[Tuple
[Number
,Number
]]]) – mass ranges to apply the background subtraction tomodel (
Type
[Model
]) – the background model to be used
- add_fit_interval(minmax)[source]
Add fit interval to the background :type minmax:
Tuple
[Number
,Number
] :param minmax: the new fit interval
- add_include_interval(minmax)[source]
Add a specified interval through which any containing mass ranges will be matched. This will occur if the lower bound of a given mass range is contained within rng. Overlapping ranges are allowed.
- property area: Number
Get the area of the fit
- contains_mass(value)[source]
Determine if this background contains the mass/charge ratio in any include range interval [min-max)
- Return type:
bool
- contains_range(rng)[source]
Determine if a Range falls within this Background’s include range :type rng:
Range
:param rng: Range instance- Return type:
bool
- eval(x)[source]
Compute the background curve on the given interval x :rtype:
ndarray
:return: the background estimate on the given range
- fit(spec_x, spec_y)[source]
Fit the background to the spectrum (spec_x, spec_y) :type spec_x:
ndarray
:param spec_x: array of x axis :type spec_y:ndarray
:param spec_y: array of y axis
- property fit_intervals: List[Tuple[Number, Number]]
Get the fit intervals assigned to this background
- property fit_results: MinimizerResult
Get the fit results of the background
- property include_intervals: List[Tuple[Number, Number]]
Get the list of intervals that assign ranges (
Range
) to the background
- property lower: Number
Get the lower value of the fit interval
- property upper: Number
Get the upper value of the fit interval
BackgroundCollection
- class apav.analysis.background.BackgroundCollection(backgrounds=())[source]
Handles operate on a collection of Backgrounds
This class is used to contain all backgrounds that operate on a spectrum/ROI.
>>> bkgs = BackgroundCollection() >>> bkg1 = Background((10, 12), (13, 14)) >>> bkgs.add(bkg1)
or
>>> bkgs = BackgroundCollection() >>> bkgs.add(Background((10, 12), (13, 14)), models.ExponentialModel) >>> bkgs.add(Background((48, 52), (60, 65)), models.PowerLawShiftModel)
This will fit the first background model on the interval 10 -> 12 Da and apply to mass ranges begining from 13 -> 14 Da using an exponential decay model. The second background is fit from 48 -> 52 Da and is applied to mass ranges beginning between 60 -> 65 Da, using a Power Law model.
- add(newbkg)[source]
Add a new
Background
to the collection :type newbkg:Background
:param newbkg: the new background- Return type:
- property backgrounds: List[Background]
Get a list of backgrounds (
Background
) in the collection :return:
- find_background(rng)[source]
Find a background whos included mass ranges intersects a Range’s mass range. If no background is found return None
- fit(spec_x, spec_y)[source]
Do the calculation of each background with respect the provided mass spectrum :type spec_x:
ndarray
:param spec_x: array of x axis :type spec_y:ndarray
:param spec_y: array of y axis
- classmethod from_bkg(fpath)[source]
Load background information from file (see BackgroundCollection.export)