def sigmoid(*columns): """Fit a Sigmoid through the data of the last scan. The return value is a pair of tuples:: ((a, b, x0, c), (d_a, d_b, d_x0, d_c)) where the elemets of the second tuple the estimated standard errors of the fit parameters. The fit parameters are: * a - amplitude of the Sigmoid * b - steepness of the curve * x0 - center * c - background if the fit failed, the result is ``(None, None)``. Example:: cscan(...) values, stderr = sigmoid('h', 'adet') """ xs, ys, dys, _, ds = _getData(columns) fit = SigmoidFit() res = fit.run(xs, ys, dys) if res._failed: return None, None session.notifyFitCurve(ds, 'sigmoid', res.curve_x, res.curve_y) descrs = ['amplitude', 'steepness', 'center', 'background'] vals = [] for par, err, descr in zip(res._pars[1], res._pars[2], descrs): vals.append((descr, '%.4f' % par, '%.4f' % err)) printTable(('parameter', 'value', 'error'), vals, session.log.info) return CommandLineFitResult((tuple(res._pars[1]), tuple(res._pars[2])))
def fit(fitclass, *columns, **kwargs): xs, ys, dys, _, ds = _getData(columns, dataset=kwargs.pop('dataset', None)) fit = fitclass(**kwargs) res = fit.run(xs, ys, dys) if res._failed: session.log.info('Fit failed.') return CommandLineFitResult((None, None)) session.notifyFitCurve(ds, fit.fit_title, res.curve_x, res.curve_y) descrs = fit.fit_p_descr vals = [] for par, err, descr in zip(res._pars[1], res._pars[2], descrs): vals.append((descr, '%.5g' % par, '+/- %.5g' % err, '+/- {:.1%}'.format(err / par) if par else '-')) printTable(('parameter', 'value', 'error', 'rel. error'), vals, session.log.info) return CommandLineFitResult((tuple(res._pars[1]), tuple(res._pars[2])))
def doStart(self): positions = [[p] for p in self.positions] ds = Scan([session.getDevice(self.scandev)], positions, None, detlist=[self._attached_detector], preset=self._preset, subscan=True).run() xs, ys, dys, _, ds = _getData() fit = self.fitcls() res = fit.run(xs, ys, dys) if res._failed: self.log.warning('Fit failed: %s.' % res._message) self.readresult = [0] * (self._nparams * 2) else: session.notifyFitCurve(ds, fit.fit_title, res.curve_x, res.curve_y) readres = [] for par, err in zip(res._pars[1], res._pars[2]): readres.append(par) readres.append(err) self.readresult = readres