def int_data(): ''' Integrate data in given area ''' bg_mod = PolynomialModel(vPolynomial.get(), prefix='bg_') # Background if vDelimiter.get() == 'space': delimiter = None elif vDelimiter.get() == 'comma': delimiter = ',' data = np.loadtxt(filename, skiprows=vSkipRows.get(), delimiter=delimiter) original_data = np.vstack((data[:, vColumnX.get()-1], data[:, vColumnY.get()-1])).T selectionRange = (vStartLeftX.get(), vStartRightX.get(), vEndLeftX.get(), vEndRightX.get()) x_bg, y_bg = select_bg_data(original_data, selectionRange) pars = bg_mod.guess(y_bg, x=x_bg) mod = bg_mod init = mod.eval(pars, x=x_bg) out = mod.fit(y_bg, pars, x=x_bg) x, y = data[:, vColumnX.get()-1], data[:, vColumnY.get()-1] comp = out.eval_components(x=x) out_param = out.params y_bg_fit = bg_mod.eval(params=out_param, x=x) y_bg_remove = y - y_bg_fit startLine, endLine = None, None for i in xrange(np.size(x)): if x[i] >= vIntLeftX.get() and startLine is None: startLine = i if startLine != None and endLine is None and x[i] >= vIntRightX.get(): endLine = i x_int = x[startLine:endLine] y_int = y_bg_remove[startLine:endLine] y_bg_fit_ = y_bg_fit[startLine:endLine] y_orig = y[startLine:endLine] integration = np.trapz(y_int, x_int) # plot axe.cla() axe.plot(x, y, 'b.') axe.plot(x_bg, out.best_fit, 'r-') # Background plotting # axe.xlim([x[0], x[-1]]) axe.fill_between(x_int, y_orig, y_bg_fit_, facecolor='green') figWindowNew, canvasNew, toolbarNew = createFigWindow(fig) canvasNew.show() toolbarNew.update() # canvas._tkcanvas.pack(side=Tk.TOP, fill=Tk.BOTH, expand=1) figWindowNew.wm_attributes('-topmost') # Activate the plotting window # report reportWindow = Tk.Tk() report = 'Integration area = ' + repr(integration) reportText = Tk.Text(reportWindow) reportText.insert(Tk.INSERT, report) reportText.pack() reportWindow.wm_attributes('-topmost')
# exit() # Stop here? ##### Integration ##### if BG_FITTING_MODE == 't': startInt = head0 # Integration range endInt = end0 elif BG_FITTING_MODE == 'z': startInt = head2 endInt = end1 # Background subtraction comp = out.eval_components(x=x) out_param = out.params y_bg_fit = bg_mod.eval(params=out_param, x=x) y_bg_remove = y - y_bg_fit startLine, endLine = None, None for i in xrange(np.size(x)): if x[i] >= startInt and startLine is None: startLine = i if startLine != None and endLine is None and x[i] >= endInt: endLine = i x_int = x_original[startLine:endLine] y_int = y_bg_remove[startLine:endLine] y_bg_fit_ = y_bg_fit[startLine:endLine] y_orig = y_original[startLine:endLine] if INT_METHOD == 't':