Calculates the three number summary for a variable.

    The three number summary is the minimum, maximum and the mean
    of the data. Traditionally one would summerise data with the
    five number summary: max, min, 1st, 2nd (median), 3rd quartile.
    But quantiles are hard to calculate without sorting the data
    which hard to do out-of-core.

def threenum(h5file, var, post_col='mult'):
    """ Calculates the three number summary for a variable.

    The three number summary is the minimum, maximum and the mean
    of the data. Traditionally one would summerise data with the
    five number summary: max, min, 1st, 2nd (median), 3rd quartile.
    But quantiles are hard to calculate without sorting the data
    which hard to do out-of-core.
    """
    f = h5py.File(h5file, 'r')
    d = f[var]
    w = f[post_col]
    s = d.chunks[0]

    n = d.shape[0]
    maxval = -np.abs(d[0])
    minval = np.abs(d[0])
    total = 0
    wsum = 0

    for x in range(0, n, s):

        aN = ~np.logical_or(np.isnan(d[x:x+s]), np.isinf(d[x:x+s]))

        d_c = d[x:x+s][aN]
        w_c = w[x:x+s][aN]

        chunk_max = np.max(d_c)
        chunk_min = np.min(d_c)

        maxval = chunk_max if chunk_max > maxval else maxval
        minval = chunk_min if chunk_min < minval else minval

        total += np.sum(w_c*d_c)
        wsum  += np.sum(w_c)
    f.close()

    mean = total/float(wsum)

    return (minval, maxval, mean)