def csv_to_constant_volume(filepath,weight_column,V_max,has_header=False,delim=',',quotechar='"',lower_bound=None,upper_bound=None):

    data, weight_column, header = load_csv(filepath,weight_column,has_header=has_header,delim=',',quotechar='"')

    bins = to_constant_volume(data,V_max,weight_pos=weight_column,lower_bound=lower_bound,upper_bound=upper_bound)
    print_binsizes(bins,weight_column)

    save_csvs(bins,filepath,header,delim=delim,quotechar=quotechar)
def csv_to_constant_volume(filepath,weight_column,V_max,has_header=False,delim=',',quotechar='"',lower_bound=None,upper_bound=None):

    data, weight_column, header = load_csv(filepath,weight_column,has_header=has_header,delim=',',quotechar='"')

    bins = to_constant_volume(data,V_max,weight_pos=weight_column,lower_bound=lower_bound,upper_bound=upper_bound)
    print_binsizes(bins,weight_column)

    save_csvs(bins,filepath,header,delim=delim,quotechar=quotechar)
                new_bins[b].append(new_dict[key])
        return new_bins

         
if __name__=="__main__":

    a = np.random.power(0.01,size=10000)
    V_max = 1.

    bins = to_constant_volume(a,V_max)

    a = np.sort(a)[::-1]
    print(a[:10])
    print([ np.sum(b) for b in bins ])
    print(a.sum(), sum([ np.sum(b) for b in bins ]))

    w = [ np.sum(b) for b in bins ]

    import pylab as pl
    pl.plot(np.arange(len(w)),w)
    pl.show()


    b = { 'a': 10, 'b': 10, 'c':11, 'd':1, 'e': 2,'f':7 }
    V_max = max(b.values())

    bins = to_constant_volume(b,V_max)
    print_binsizes(bins)