def integrate_data(xdata, ydata, xmin=None, xmax=None, autozero=<NUM_LIT:0>):
<EOL>[xdata, ydata] = sort_matrix([xdata,ydata],<NUM_LIT:0>)<EOL>xdata = _n.array(xdata)<EOL>ydata = _n.array(ydata)<EOL>if xmin is None: xmin = min(xdata)<EOL>if xmax is None: xmax = max(xdata)<EOL>imin = xdata.searchsorted(xmin)<EOL>imax = xdata.searchsorted(xmax)<EOL>xint = [xdata[imin]]<EOL>yint = [<NUM_LIT:0>]<EOL>if autozero >= <NUM_LIT:1>:<EOL><INDENT>zero = _n.average(ydata[imin:imin+int(autozero)])<EOL>ydata = ydata-zero<EOL><DEDENT>for n in range(imin+<NUM_LIT:1>,imax):<EOL><INDENT>if len(yint):<EOL><INDENT>xint.append(xdata[n])<EOL>yint.append(yint[-<NUM_LIT:1>]+<NUM_LIT:0.5>*(xdata[n]-xdata[n-<NUM_LIT:1>])*(ydata[n]+ydata[n-<NUM_LIT:1>]))<EOL><DEDENT>else:<EOL><INDENT>xint.append(xdata[n])<EOL>yint.append(<NUM_LIT:0.5>*(xdata[n]-xdata[n-<NUM_LIT:1>])*(ydata[n]+ydata[n-<NUM_LIT:1>]))<EOL><DEDENT><DEDENT>return _n.array(xint), _n.array(yint)<EOL>
Numerically integrates up the ydata using the trapezoid approximation.
estimate the bin width (scaled by the specified amount).
Returns (xdata, integrated ydata).

autozero is the number of data points to use as an estimate of the background
(then subtracted before integrating).