def coarsen_data(x, y, ey=None, ex=None, level=<NUM_LIT:2>, exponential=False):
<EOL>if not exponential:<EOL><INDENT>xc  = coarsen_array(x, level, '<STR_LIT>')<EOL>yc  = coarsen_array(y, level, '<STR_LIT>')<EOL>if not ey is None:<EOL><INDENT>if not is_iterable(ey): ey = [ey]*len(y)<EOL>eyc = _n.sqrt(coarsen_array(_n.power(ey,<NUM_LIT:2>)/level, level, '<STR_LIT>'))<EOL><DEDENT>if not ex is None:<EOL><INDENT>if not is_iterable(ey): ex = [ex]*len(x)<EOL>exc = _n.sqrt(coarsen_array(_n.power(ex,<NUM_LIT:2>)/level, level, '<STR_LIT>'))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>x = _n.array(x)<EOL>y = _n.array(y)<EOL>xc = []<EOL>yc = []<EOL>if not ey is None: <EOL><INDENT>if not is_iterable(ey): ey = _n.array([ey]*len(y))<EOL>eyc = []<EOL><DEDENT>if not ex is None:<EOL><INDENT>if not is_iterable(ex): ex = _n.array([ex]*len(x))<EOL>exc = []<EOL><DEDENT>x0 = x[x><NUM_LIT:0>][<NUM_LIT:0>]<EOL>n  = <NUM_LIT:0><EOL>while x0*level**n < x[-<NUM_LIT:1>]:<EOL><INDENT>mask = _n.logical_and(x0*level**n <= x, x < x0*level**(n+<NUM_LIT:1>))<EOL>if len(x[mask]):<EOL><INDENT>xc.append(_n.average(x[mask]))<EOL>yc.append(_n.average(y[mask]))<EOL>if not ey is None: eyc.append(_n.sqrt(_n.average((ey**<NUM_LIT:2>)[mask])/len(ey[mask])))<EOL>if not ex is None: exc.append(_n.sqrt(_n.average((ex**<NUM_LIT:2>)[mask])/len(ex[mask])))<EOL><DEDENT>n += <NUM_LIT:1><EOL><DEDENT><DEDENT>if   ey is None and ex is None: return _n.array(xc), _n.array(yc)<EOL>elif ex is None               : return _n.array(xc), _n.array(yc), _n.array(eyc)<EOL>elif ey is None               : return _n.array(xc), _n.array(yc), _n.array(exc)<EOL>else                          : return _n.array(xc), _n.array(yc), _n.array(eyc), _n.array(exc)<EOL>
Coarsens the supplied data set. Returns coarsened arrays of x, y, along with
quadrature-coarsened arrays of ey and ex if specified.

Parameters
----------
x, y
    Data arrays. Can be lists (will convert to numpy arrays).
    These are coarsened by taking an average.
ey=None, ex=None
    y and x uncertainties. Accepts arrays, lists, or numbers. 
    These are coarsened by averaging in quadrature.
level=2
    For linear coarsening (default, see below), every n=level points will
    be averaged together (in quadrature for errors). For exponential
    coarsening, bins will be spaced by the specified scaling=level factor;
    for example, level=1.4 will group points within 40% of each other's x
    values. This is a great option for log-x plots, as the outcome will be
    evenly spaced.
exponential=False
    If False, coarsen using linear spacing. If True, the bins will be 
    exponentially spaced by the specified level.