Пример #1
0
def main():
    """Illustrate workflow for fitting a mono-exponential decay.

    Example of fitting a convolved mono-exponential fluorescence
    decay to a single measurement using iterative least squares
    with Chi2 Statistic and Pearson variance approximation.

    """
    file = np.loadtxt('../decay_1exp_5ns.txt', skiprows=1)
    time, irf, decay = file[:, 0], file[:, 1], file[:, 2]
    model_kwargs_e1 = {
        'model_components': 1,
        'model_parameters': {
            'amplitude1': {'value': 0.06, 'vary': True},
            'offset': {'value': 0.1, 'vary': True},
            'tau1': {'value': 5, 'vary': True},
        },
        'fit_start': 2,
        'fit_stop': None
    }
    # ConvolutionFitter C Statistic for comparison
    cstat_fitter = \
    make_lifetime_fitter(
        model_kwargs_e1,
        time,
        decay,
        instrument_response=irf,
        fit_statistic='c_statistic'
        )
    cstat_fit = cstat_fitter.fit()
    # ConvolutionFitter Chi2 Statistic for initialization
    chi2stat_fitter = \
    make_lifetime_fitter(
        model_kwargs_e1,
        time,
        decay,
        instrument_response=irf,
        fit_statistic='chi_square_statistic'
        )
    n_iter = 20
    fits = iterative_least_squares(chi2stat_fitter, n_iter)
    # plot
    plt.plot(time, decay, 'bo', label='decay')
    plt.plot(time, irf, 'go', label='irf')
    plt.plot(
        cstat_fitter.independent_var['time'],
        cstat_fit.best_fit,
        label='C stat',
        color='k'
        )
    for ith, fit in enumerate(fits):
        plt.plot(
            chi2stat_fitter.independent_var['time'],
            fit.best_fit,
            label='{}-ith iter'.format(ith),
            color=CMAP(ith / n_iter)
            )
    plt.legend(loc='best')
    plt.yscale('log')
    plt.show()
Пример #2
0
def main():
    """Illustrate workflow for fitting a mono-exponential decay.

    Example of fitting a convolved mono-exponential fluorescence
    decay to a single measurement using C Statistic.

    """
    file = np.loadtxt('../decay_1exp_5ns.txt', skiprows=1)
    time, irf, decay = file[:, 0], file[:, 1], file[:, 2]
    model_kwargs_e1 = {
        'model_components': 1,
        'model_parameters': {
            'amplitude1': {
                'value': 0.06,
                'vary': True
            },
            'offset': {
                'value': 0.1,
                'vary': True
            },
            'tau1': {
                'value': 5,
                'vary': True
            },
        },
        'fit_start': 2,
        'fit_stop': None
    }
    # Convolution fit with Chi2 Statistic
    cstat_fitter = \
    make_lifetime_fitter(
        model_kwargs_e1,
        time,
        decay,
        instrument_response=irf,
        fit_statistic='c_statistic'
        )
    cstat_fit = cstat_fitter.fit(report=True)
    # exit(1)
    # plot
    plt.plot(time, decay, 'bo', label='decay')
    plt.plot(time, irf, 'go', label='irf')
    plt.plot(cstat_fitter.independent_var['time'],
             cstat_fit.best_fit,
             'r-',
             label='fit')
    plt.legend(loc='best')
    plt.yscale('log')
    plt.show()
Пример #3
0
def main():
    """Illustrate workflow for tail-fitting a mono-exponential decay.

    Example of tail-fitting a mono-exponential fluorescence
    decay to a single measurement using Chi2 Statistic.

    """
    file = np.loadtxt('../decay_1exp_5ns.txt', skiprows=1)
    time, irf, decay = file[:, 0], file[:, 1], file[:, 2]
    model_kwargs_e1_tail = {
        'model_components': 1,
        'model_parameters': {
            'amplitude1': {
                'value': 7000,
                'vary': True
            },
            'offset': {
                'value': 0.1,
                'vary': True
            },
            'tau1': {
                'value': 5,
                'vary': True
            },
        },
        'fit_start': 12,
        'fit_stop': None
    }
    # Tail fit with Chi2 Statistic
    chi2stat_tail_fitter = \
    make_lifetime_fitter(
        model_kwargs_e1_tail,
        time,
        decay,
        fit_statistic='chi_square_statistic'
        )
    chi2stat_tail_fit = chi2stat_tail_fitter.fit(report=True)
    # plot
    plt.plot(time, decay, 'bo', label='decay')
    plt.plot(chi2stat_tail_fitter.independent_var['time'],
             chi2stat_tail_fit.best_fit,
             'r-',
             label='fit')
    plt.legend(loc='best')
    plt.yscale('log')
    plt.show()
Пример #4
0
def main():
    """Illustrate workflow for fitting a bi-exponential decay.

    Example of fitting a convolved bi-exponential fluorescence
    decay to a single measurement using Chi2 Statistic.

    """
    file = np.loadtxt('../decay_2exp_1ns_02_4ns_08.txt', skiprows=1)
    time, irf, decay = file[:, 0], file[:, 1], file[:, 2]
    model_kwargs_e2 = {
        'model_components': 2,
        'model_parameters': {
            'amplitude1': {
                'value': 0.1,
                'vary': True,
                'min': 1E-6
            },
            'amplitude2': {
                'value': 0.1,
                'vary': True,
                'min': 1E-6
            },
            'tau1': {
                'value': 1,
                'vary': True,
                'min': 1E-6
            },
            'tau2': {
                'value': 4,
                'vary': True,
                'min': 1E-6
            },
            'offset': {
                'value': 0.1,
                'vary': True,
                'min': 1E-6
            },
            'shift': {
                'value': 0.5,
                'vary': True
            }
        },
        'fit_start': 2,
        'fit_stop': None
    }
    # Convolution fit with Chi2 Statistic
    chi2stat_fitter = \
    make_lifetime_fitter(
        model_kwargs_e2,
        time,
        decay,
        instrument_response=irf,
        fit_statistic='chi_square_statistic'
        )
    chi2stat_fit = chi2stat_fitter.fit(report=True)
    # plot
    plt.plot(time, decay, 'bo', label='decay')
    plt.plot(time, irf, 'go', label='irf')
    plt.plot(chi2stat_fitter.independent_var['time'],
             chi2stat_fit.best_fit,
             'r-',
             label='fit')
    plt.legend(loc='best')
    plt.yscale('log')
    plt.show()