This model provides a class for fitting multichannel data
(MultiFitter
) and a series of predefined functions for common
models used to fit E or S histograms.
Contents
fretbursts.mfit.
MultiFitter
(data_list, skip_ch=None)¶A class handling a list of 1D datasets for histogramming, KDE, fitting.
This class takes a list of 1D arrays of samples (such as E values
per burst). The list contains one 1D array for each channel in
a multispot experiment. In singlespot experiments the list contains only
one array of samples.
For each dataset in the list, this class compute histograms, KDEs and
fits (both histogram fit and KDE maximum). The list of datasets is
stored in the attribute data_list
.
The histograms can be fitted with an arbitrary model (lmfit.Model).
From KDEs the peak position in a range can be estimated.
Optionally weights can be assigned to each element in a dataset.
To assign weights a user can assign the .weights
attribute with a list
of arrays; corresponding arrays in .weights
and .data_list
must have
the same size.
Alternatively a function returning the weights can be used. In this case,
the method .set_weights_func
allows to set the function to be called
to generate weights.
calc_kde
(bandwidth=0.03)¶Compute the list of kde functions and save it in .kde
.
find_kde_max
(x_kde, xmin=None, xmax=None)¶Finds the peak position of kde functions between xmin
and xmax
.
Results are saved in the list .kde_max_pos
.
fit_histogram
(model=None, pdf=True, **fit_kwargs)¶Fit the histogram of each channel using the same lmfit model.
A list of lmfit.Minimizer
is stored in .fit_res
.
The fitted values for all the parameters and all the channels are
save in a Pandas DataFrame .params
.
Parameters: 


histogram
(binwidth=0.03, bins=None, verbose=False, **kwargs)¶Compute the histogram of the data for each channel.
If bins
is None, binwidth
determines the bins array (saved in
self.hist_bins
). If bins
is not None, binwidth
is ignored and
self.hist_binwidth
is computed from self.hist_bins
.
The kwargs and bins
are passed to numpy.histogram
.
set_weights_func
(weight_func, weight_kwargs=None)¶Setup of the function returning the weights for each dataset.
To compute the weights for each dataset the weight_func
is called
multiple times. Keys in weight_kwargs
are arguments of
weight_func
. Values in weight_kwargs
are either scalars, in which
case they are passed to weight_func
, or lists. When an argument
is a list, only one element of the list is passed each time.
Parameters: 


In this section you find the documentation for the factoryfunctions that return preinitialized models for fitting E and S data.
fretbursts.mfit.
factory_gaussian
(center=0.1, sigma=0.1, amplitude=1)¶Return an lmfit Gaussian model that can be used to fit data.
Arguments are initial values for the model parameters.
lmfit.Model
object with all the parameters already initialized.fretbursts.mfit.
factory_asym_gaussian
(center=0.1, sigma1=0.1, sigma2=0.1, amplitude=1)¶Return a lmfit Asymmetric Gaussian model that can be used to fit data.
For the definition of asymmetric Gaussian see asym_gaussian()
.
Arguments are initial values for the model parameters.
lmfit.Model
object with all the parameters already initialized.fretbursts.mfit.
factory_two_gaussians
(add_bridge=False, p1_center=0.1, p2_center=0.9, p1_sigma=0.03, p2_sigma=0.03)¶Return a 2Gaussian + (optional) bridge model that can fit data.
The optional “bridge” component (i.e. a plateau between the two peaks)
is a function that is nonzero only between p1_center
and p2_center
and is defined as:
br_amplitude * (1  g(x, p1_center, p1_sigma)  g(x, p1_center, p2_sigma))
where g
is a gaussian function with amplitude = 1 and br_amplitude
is the height of the plateau and the only additional parameter introduced
by the bridge. Note that both centers and sigmas parameters in the bridge
are the same ones of the adjacent Gaussian peaks. Therefore a
2Gaussian + bridge model has 7 free parameters: 3 for each Gaussian and
an additional one for the bridge.
The bridge function is implemented in bridge_function()
.
Parameters: 


lmfit.Model
object with all the parameters already initialized.fretbursts.mfit.
factory_two_asym_gaussians
(add_bridge=False, p1_center=0.1, p2_center=0.9, p1_sigma=0.03, p2_sigma=0.03)¶Return a 2AsymGaussians + (optional) bridge model that can fit data.
The AsymGaussian function is asym_gaussian()
.
Parameters:  add_bridge (bool) – if True adds a bridge function between the two gaussian peaks. If False the model has only two AsymGaussians. 

The other arguments are initial values for the model parameters.
lmfit.Model
object with all the parameters already initialized.fretbursts.mfit.
factory_three_gaussians
(p1_center=0.0, p2_center=0.5, p3_center=1, sigma=0.05)¶Return a 3Gaussian model that can fit data.
The other arguments are initial values for the center
for each
Gaussian component plus an single sigma
argument that is used
as initial sigma for all the Gaussians. Note that during the fitting
the sigma of each Gaussian is varied independently.
lmfit.Model
object with all the parameters already initialized.The following functions are utility functions used to build the the model functions (i.e. the “factory functions”) for the fitting.
fretbursts.mfit.
bridge_function
(x, center1, center2, sigma1, sigma2, amplitude)¶A “bridge” function, complementary of two gaussian peaks.
Let g
be a Gaussian function (with amplitude = 1), the bridge function
is defined as:
amplitude * (1  g(x, center1, sigma1)  g(x, center2, sigma2))
for center1 < x < center2
. The function is 0 otherwise.
Parameters: 


Returns:  An array (same shape as 
fretbursts.mfit.
asym_gaussian
(x, center, sigma1, sigma2, amplitude)¶A asymmetric gaussian function composed by two gaussian halves.
This function is composed from two gaussians joined at their peak, so that the left and right side decay with different sigmas.
Parameters: 


Returns:  An array (same shape as 