Example #1
0
def leastsq_integrate(ts, peak_list, f='gaussian'):
    #FIXME: transition from t0, t1, params to params (containing 't0'/'t1'
    # lookup the peak model function to use for fitting
    f = {f.__name__: f for f in peak_models}[f]

    peaks = []
    for w, peak_list in _get_windows(peak_list):
        tr = ts.trace(twin=w)
        # if there's location info, we can use this for
        # our inital params
        if 'x' in peak_list[0][2]:
            #TODO: should fill in other values?
            #TODO: should do something with y0 and y1?
            initc = [i[2] for i in peak_list]
        else:
            #TODO: should find peak maxima for rts?
            rts = [0.5 * (i[0] + i[1]) for i in peak_list]
            initc = guess_initc(tr, f, rts)
        params, _ = fit(tr, [f] * len(initc), initc)
        for p in params:
            pk_ts = AstonSeries(f(tr.times, **p), tr.times)
            info = {'name': '{:.2f}'.format(p['x'])}
            info['p-create'] = peak_list[0][2].get('pf', '') + \
                    ',' + 'leastsq_integrate'
            pk = PeakComponent(info, pk_ts)
            peaks.append(pk)
    return peaks
Example #2
0
    def refit(self, peak_model=None):
        #TODO: needs to work with PeakComponents containing DataFrames?
        self.info['p-model'] = peak_model
        if peak_model is None:
            #TODO: remove parameters from self.info?
            #del self.info['p-model-fit']
            return
        model = peak_models[peak_model]

        # remove the baseline and create a new series
        t = self._trace.index
        d = self._trace.values - self.baseline._retime(t)
        ts = AstonSeries(d, t)

        # fit the peak
        initc = guess_initc(ts, model, [t[d.argmax()]])
        params, res = fit(ts, [model], initc)
        self.info.update(params[0])
        self.info['p-model-fit'] = res['r^2']